|
|
@@ -13,7 +13,6 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
|
|
|
public MaCodeSearchTextBox()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- TextBox.KeyDown += TextBox_KeyDown;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
@@ -227,11 +226,12 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
|
|
|
|
|
|
private void TextBox_TextChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- Console.WriteLine(TextBox.Text);
|
|
|
- Console.WriteLine(db.SuccessReturnData);
|
|
|
- if (db.SuccessReturnData) {
|
|
|
- LockCheckBox.Checked = true;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (db.SuccessReturnData)
|
|
|
+ LockCheckBox.Checked = true;
|
|
|
}
|
|
|
+ catch (Exception) { }
|
|
|
UserControlTextChanged?.Invoke(sender, new EventArgs());
|
|
|
}
|
|
|
|
|
|
@@ -239,54 +239,60 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
|
|
|
//Key先发起失去焦点事件,在执行用户自定义的事件
|
|
|
private void TextBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
{
|
|
|
- if (e.KeyCode == Keys.Enter)
|
|
|
+ if (e.KeyCode == Keys.Enter) {
|
|
|
+ GetData();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetLockCheckBox(CheckBox ctl)
|
|
|
+ {
|
|
|
+ LockCheckBox = ctl;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void GetData()
|
|
|
+ {
|
|
|
+ if (TextBox.Text != "")
|
|
|
{
|
|
|
- if (TextBox.Text != "")
|
|
|
+ DataHelper dh = new DataHelper();
|
|
|
+ List<string> fields = new List<string>();
|
|
|
+ //获取查询的字段
|
|
|
+ string[] field = selectField.Replace(",", "#").Trim().Split('#');
|
|
|
+ for (int i = 0; i < field.Length; i++)
|
|
|
{
|
|
|
- DataHelper dh = new DataHelper();
|
|
|
- List<string> fields = new List<string>();
|
|
|
- //获取查询的字段
|
|
|
- string[] field = selectField.Replace(",", "#").Trim().Split('#');
|
|
|
- for (int i = 0; i < field.Length; i++)
|
|
|
- {
|
|
|
- if (i % 2 == 0)
|
|
|
- fields.Add(field[i]);
|
|
|
- }
|
|
|
- //将查询到的结果返回界面
|
|
|
- string sql = "select " + BaseUtil.AddField(fields.ToArray()) + " from " + tableName + " where " + Tag + "='" + TextBox.Text + "'";
|
|
|
- if (condition != null)
|
|
|
- {
|
|
|
- sql += " and " + condition;
|
|
|
- }
|
|
|
- DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
|
|
|
- FormCollection fmCollection = Application.OpenForms;
|
|
|
- if (dt.Rows.Count > 0)
|
|
|
+ if (i % 2 == 0)
|
|
|
+ fields.Add(field[i]);
|
|
|
+ }
|
|
|
+ //将查询到的结果返回界面
|
|
|
+ string sql = "select " + BaseUtil.AddField(fields.ToArray()) + " from " + tableName + " where " + Tag + "='" + TextBox.Text.ToUpper() + "'";
|
|
|
+ if (condition != null)
|
|
|
+ {
|
|
|
+ sql += " and " + condition;
|
|
|
+ }
|
|
|
+ DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
|
|
|
+ FormCollection fmCollection = Application.OpenForms;
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
{
|
|
|
- for (int i = 0; i < dt.Columns.Count; i++)
|
|
|
+ for (int j = 0; j < SetValueField.Length; j++)
|
|
|
{
|
|
|
- for (int j = 0; j < SetValueField.Length; j++)
|
|
|
+ //利用字段的Tag属性来和列名进行比对
|
|
|
+ object tag = fmCollection[FormName].Controls[SetValueField[j]].Tag;
|
|
|
+ if (SetValueField[j] == dt.Columns[i].ColumnName.ToLower() || (tag != null && tag == dt.Columns[i].ColumnName.ToLower()))
|
|
|
{
|
|
|
- //利用字段的Tag属性来和列名进行比对
|
|
|
- object tag = fmCollection[FormName].Controls[SetValueField[j]].Tag;
|
|
|
- if (SetValueField[j] == dt.Columns[i].ColumnName.ToLower() || (tag != null && tag == dt.Columns[i].ColumnName.ToLower()))
|
|
|
- {
|
|
|
- fmCollection[FormName].Controls[SetValueField[j]].Text = dt.Rows[0][dt.Columns[i].ColumnName].ToString();
|
|
|
- }
|
|
|
+ fmCollection[FormName].Controls[SetValueField[j]].Text = dt.Rows[0][dt.Columns[i].ColumnName].ToString();
|
|
|
}
|
|
|
}
|
|
|
- LeaveFindData = true;
|
|
|
- LockCheckBox.Checked = true;
|
|
|
}
|
|
|
- else
|
|
|
- LeaveFindData = false;
|
|
|
+ LeaveFindData = true;
|
|
|
}
|
|
|
+ else
|
|
|
+ LeaveFindData = false;
|
|
|
+ //不允许工单号为空的情况
|
|
|
+ LockCheckBox.Checked = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void SetLockCheckBox(CheckBox ctl) {
|
|
|
- LockCheckBox = ctl;
|
|
|
- }
|
|
|
-
|
|
|
private void Search_Icon_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
SearchIconClick?.Invoke(sender, new EventArgs());
|
|
|
@@ -321,6 +327,7 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
|
|
|
public void TextBox_Leave(object sender, EventArgs e)
|
|
|
{
|
|
|
TextBox.BackColor = System.Drawing.Color.White;
|
|
|
+ GetData();
|
|
|
}
|
|
|
|
|
|
private void SearchTextBox_Load(object sender, EventArgs e)
|
|
|
@@ -332,7 +339,7 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
|
|
|
|
|
|
private void SearchTextBox_SizeChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- TextBox.Width = this.Width - Search_Icon.Width-3;
|
|
|
+ TextBox.Width = this.Width - Search_Icon.Width - 3;
|
|
|
}
|
|
|
}
|
|
|
}
|