|
|
@@ -1,31 +1,67 @@
|
|
|
using System;
|
|
|
+using System.Data;
|
|
|
using System.Windows.Forms;
|
|
|
+using UAS_LabelMachine.PublicMethod;
|
|
|
|
|
|
namespace UAS_LabelMachine.CustomControl
|
|
|
{
|
|
|
public partial class SearchTextBox : UserControl
|
|
|
{
|
|
|
+
|
|
|
+ DataHelper dh = new DataHelper();
|
|
|
+
|
|
|
+ #region 构造函数
|
|
|
public SearchTextBox()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 变量
|
|
|
+ /// <summary>
|
|
|
+ /// 是否通过Leave事件找到数据
|
|
|
+ /// </summary>
|
|
|
+ public bool LeaveFindData;
|
|
|
+ /// <summary>
|
|
|
+ /// DBFind窗体弹出的标题
|
|
|
+ /// </summary>
|
|
|
+ private string DBTitle1;
|
|
|
+ /// <summary>
|
|
|
+ /// 输入框是否可编辑
|
|
|
+ /// </summary>
|
|
|
+ private bool TextBoxEnable1;
|
|
|
+ /// <summary>
|
|
|
+ /// 业务逻辑的标识符
|
|
|
+ /// </summary>
|
|
|
private string caller;
|
|
|
+ /// <summary>
|
|
|
+ /// 发起DbFind的窗体
|
|
|
+ /// </summary>
|
|
|
private string formName;
|
|
|
+ /// <summary>
|
|
|
+ /// 需要赋值的字段
|
|
|
+ /// </summary>
|
|
|
+ private string[] setValueField;
|
|
|
+ /// <summary>
|
|
|
+ /// 初始的筛选条件
|
|
|
+ /// </summary>
|
|
|
+ private string condition;
|
|
|
+ /// <summary>
|
|
|
+ /// 权限标识
|
|
|
+ /// </summary>
|
|
|
+ private string Power1;
|
|
|
+ /// <summary>
|
|
|
+ /// 查询的表名
|
|
|
+ /// </summary>
|
|
|
+ private string tableName;
|
|
|
+ /// <summary>
|
|
|
+ /// 查询的字段
|
|
|
+ /// </summary>
|
|
|
+ private string selectField;
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+ DbFind db;
|
|
|
|
|
|
- //定义委托
|
|
|
- public delegate void OnTextChange(object sender, EventArgs e);
|
|
|
- //定义事件
|
|
|
- public event OnTextChange UserControlTextChanged;
|
|
|
-
|
|
|
- //定义委托
|
|
|
- public delegate void Icon_Click(object sender, EventArgs e);
|
|
|
-
|
|
|
- public event Icon_Click SearchIconClick;
|
|
|
-
|
|
|
- private void TextBox_TextChanged(object sender, EventArgs e)
|
|
|
- {
|
|
|
- UserControlTextChanged?.Invoke(sender, new EventArgs());
|
|
|
- }
|
|
|
+ private DataTable returnData;
|
|
|
|
|
|
public override string Text
|
|
|
{
|
|
|
@@ -39,6 +75,22 @@ namespace UAS_LabelMachine.CustomControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ string AllPower1;
|
|
|
+
|
|
|
+ public string AllPower
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return AllPower1;
|
|
|
+ }
|
|
|
+
|
|
|
+ set
|
|
|
+ {
|
|
|
+ AllPower1 = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public string Caller
|
|
|
{
|
|
|
get
|
|
|
@@ -52,8 +104,6 @@ namespace UAS_LabelMachine.CustomControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string[] setValueField;
|
|
|
-
|
|
|
public string FormName
|
|
|
{
|
|
|
get
|
|
|
@@ -67,8 +117,6 @@ namespace UAS_LabelMachine.CustomControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string condition;
|
|
|
-
|
|
|
public string[] SetValueField
|
|
|
{
|
|
|
get
|
|
|
@@ -121,18 +169,105 @@ namespace UAS_LabelMachine.CustomControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private string tableName;
|
|
|
+ public string Power
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return Power1;
|
|
|
+ }
|
|
|
|
|
|
- private string selectField;
|
|
|
+ set
|
|
|
+ {
|
|
|
+ Power1 = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public string DBTitle
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return DBTitle1;
|
|
|
+ }
|
|
|
+
|
|
|
+ set
|
|
|
+ {
|
|
|
+ DBTitle1 = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool TextBoxEnable
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return TextBoxEnable1;
|
|
|
+ }
|
|
|
+
|
|
|
+ set
|
|
|
+ {
|
|
|
+ TextBoxEnable1 = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public DataTable ReturnData
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return returnData;
|
|
|
+ }
|
|
|
+
|
|
|
+ set
|
|
|
+ {
|
|
|
+ returnData = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 自定义事件
|
|
|
+ public delegate void OnTextChange(object sender, EventArgs e);
|
|
|
+ //定义事件
|
|
|
+ public event OnTextChange UserControlTextChanged;
|
|
|
+ //定义委托
|
|
|
+ public delegate void Icon_Click(object sender, EventArgs e);
|
|
|
+ /// <summary>
|
|
|
+ /// 图标点击事件
|
|
|
+ /// </summary>
|
|
|
+ public event Icon_Click SearchIconClick;
|
|
|
+
|
|
|
+ public delegate void DBSourceChange(object sender, EventArgs e);
|
|
|
+
|
|
|
+ public event DBSourceChange DbChange;
|
|
|
+
|
|
|
+ public delegate void OnTextKeyDown(object sender, KeyEventArgs e);
|
|
|
+
|
|
|
+ public event OnTextKeyDown TextKeyDown;
|
|
|
+ #endregion
|
|
|
+ //定义委托
|
|
|
+
|
|
|
+ private void TextBox_TextChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ UserControlTextChanged?.Invoke(sender, new EventArgs());
|
|
|
+ }
|
|
|
+
|
|
|
+ //Key先发起失去焦点事件,在执行用户自定义的事件
|
|
|
+ private void TextBox_KeyDown(object sender, KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.KeyCode == Keys.Enter)
|
|
|
+ {
|
|
|
+ TextBox_Leave(sender, e);
|
|
|
+ TextKeyDown?.Invoke(sender, new KeyEventArgs(e.KeyCode));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void Search_Icon_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
SearchIconClick?.Invoke(sender, new EventArgs());
|
|
|
-
|
|
|
- DbFind db = new DbFind(Name, tableName, selectField, setValueField, caller, formName, condition);
|
|
|
+ db = new DbFind(Name, tableName, selectField, setValueField, caller, formName, condition);
|
|
|
+ db.Text = DBTitle1;
|
|
|
+ LogManager.DoLog("DbFind查询,发起窗口【" + formName + "】,查询表【" + tableName + "】,字段" + selectField + ",条件" + condition);
|
|
|
if (db.IsAbleDbFind1)
|
|
|
{
|
|
|
db.ShowDialog();
|
|
|
+ GetData();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -140,14 +275,77 @@ namespace UAS_LabelMachine.CustomControl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 触发给界面的
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ public void ReturnDataToForm()
|
|
|
+ {
|
|
|
+ returnData = dt;
|
|
|
+ DbChange?.Invoke(new object(), new EventArgs());
|
|
|
+ }
|
|
|
+
|
|
|
private void TextBox_Enter(object sender, EventArgs e)
|
|
|
{
|
|
|
TextBox.BackColor = System.Drawing.Color.GreenYellow;
|
|
|
}
|
|
|
|
|
|
- private void TextBox_Leave(object sender, EventArgs e)
|
|
|
+ /// <summary>
|
|
|
+ /// 重新刷新数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ public void RefreshDB(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ TextBox_Leave(sender, e);
|
|
|
+ GetData();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void TextBox_Leave(object sender, EventArgs e)
|
|
|
{
|
|
|
TextBox.BackColor = System.Drawing.Color.White;
|
|
|
+ GetData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SearchTextBox_Load(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ if (!TextBoxEnable1)
|
|
|
+ TextBox.BackColor = System.Drawing.Color.White;
|
|
|
+ TextBox.Enabled = TextBoxEnable1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SearchTextBox_SizeChanged(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ TextBox.Width = this.Width - Search_Icon.Width - 3;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void GetData()
|
|
|
+ {
|
|
|
+ string sql = "";
|
|
|
+ //将查询到的结果返回界面
|
|
|
+ if (TextBox.Text != "")
|
|
|
+ {
|
|
|
+ sql = "select " + BaseUtil.AddField(setValueField) + " from " + tableName + " where " + Name + "='" + TextBox.Text + "'";
|
|
|
+ }
|
|
|
+ else if (db != null)
|
|
|
+ {
|
|
|
+ sql = "select " + BaseUtil.AddField(setValueField) + " from " + tableName + " where " + Name + "='" + db.TextBoxValue1 + "'";
|
|
|
+ }
|
|
|
+ if (condition != null)
|
|
|
+ {
|
|
|
+ sql += " and " + condition;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ dt = (DataTable)dh.ExecuteSql(sql, "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ ReturnDataToForm();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ LogManager.DoLog(e.Message);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|