|
問題解決,用gridView的ValidatingEditor事件
[PHP] private void gridView1_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
{
try
{
OracleDataAdapter tmpApt = new OracleDataAdapter(null, pubVariable.pCon);
DataTable tabTmp = new DataTable();
// 檢測數據正確性
switch (gridView1.FocusedColumn.Name)
{
case "colPjf03":
// 料號
tmpApt.SelectCommand.CommandText = "select ima01,ima02,ima021 from ima_file where ima01 = :ima01 and imaacti = 'Y'";
tmpApt.SelectCommand.Parameters.Add("ima01", OracleType.VarChar, 20).Value = e.Value;
tmpApt.Fill(tabTmp);
if (tabTmp.Rows.Count != 1)
{
//gridView1.SetColumnError(gridView1.FocusedColumn, "輸入的[料件品號]不存在,請重新輸入!" ;
e.ErrorText = "輸入的[料件品號]不存在,請重新輸入!";
e.Valid = false;
return;
}
else
{
//gridView1.SetColumnError(gridView1.FocusedColumn, "" ;
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "PJF03", tabTmp.Rows[0]["ima01"].ToString());
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "PJF04", tabTmp.Rows[0]["ima02"].ToString());
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "PJF041", tabTmp.Rows[0]["ima021"].ToString());
e.Valid = true;
}
break;
case "colPjf05":
// 單位
tmpApt.SelectCommand.CommandText = "select gfe01 from gfe_file where gfe01 = :gfe01 and gfeacti = 'Y'";
tmpApt.SelectCommand.Parameters.Add("gfe01", OracleType.VarChar, 4).Value = e.Value;
tmpApt.Fill(tabTmp);
if ( tabTmp.Rows.Count != 1 )
{
//gridView1.SetColumnError(gridView1.FocusedColumn, "輸入的[單位]不存在,請重新輸入!" ;
e.ErrorText = "輸入的[單位]不存在,請重新輸入!";
e.Valid = false;
return;
}
else
{
//gridView1.SetColumnError(gridView1.FocusedColumn, "" ;
gridView1.SetRowCellValue(gridView1.FocusedRowHandle, "PJF05", tabTmp.Rows[0]["gfe01"].ToString());
e.Valid = true;
}
break;
}
}
catch (Exception v_e)
{
MessageBox.Show(v_e.Message);
}
}[/PHP] |
|