123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using UAS_LabelMachine.CustomControl;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- namespace UAS_LabelMachine
- {
- public partial class DbFind : Form
- {
- bool IsAbleDbFind;
- string BindTable;
- DataHelper dh = SystemInf.dh;
- DataTable dt = new DataTable();
- AutoSizeFormClass asc = new AutoSizeFormClass();
- string TextBoxValue = "";
- Control[] ctl;
-
- string Field;
-
- string[] SetValueField;
-
- string SelectField;
-
- string FormName;
-
- string Caller;
- string Condition;
- public bool IsAbleDbFind1
- {
- get
- {
- return IsAbleDbFind;
- }
- set
- {
- IsAbleDbFind = value;
- }
- }
- public string TextBoxValue1
- {
- get
- {
- return TextBoxValue;
- }
- set
- {
- TextBoxValue = value;
- }
- }
-
-
-
-
-
-
-
- public DbFind(string field, string tablename, string selectfield, string[] setValueField, string caller, string formname, string condition)
- {
- InitializeComponent();
- StartPosition = FormStartPosition.CenterParent;
- Field = field;
- FormName = formname;
- SetValueField = setValueField;
- Caller = caller;
- Condition = condition;
- BindTable = tablename;
- SelectField = selectfield.Replace("#", "as");
-
- dt = (DataTable)dh.ExecuteSql("select " + SelectField + " from " + tablename + " where rownum<20", "select");
-
- selectfield = selectfield.Replace(",", "#");
- string[] NameAndCapation = selectfield.Split('#');
- int index = 0;
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- dt.Columns[i].Caption = NameAndCapation[index].Trim();
- index = index + 1;
- dt.Columns[i].ColumnName = NameAndCapation[index].Trim();
- index = index + 1;
- }
- if (dt != null)
- {
-
- DbFindGridView.DataSource = dt;
- for (int i = 0; i < DbFindGridView.Columns.Count; i++)
- {
- DbFindGridView.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
- }
-
- pagination1.BindDataToNavigator(DbFindGridView, tablename, SelectField, "ID", caller, Condition == null ? "" : Condition);
- IsAbleDbFind = true;
- }
- }
- protected override void WndProc(ref Message m)
- {
-
- if (m.Msg != 0xA3)
- {
- base.WndProc(ref m);
- }
- }
- private void DbFind_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
-
- ctl = new Control[dt.Columns.Count];
-
- for (int i = dt.Columns.Count - 1; i >= 0; i--)
- {
- EnterTextBox etb = new EnterTextBox();
- etb.Dock = DockStyle.Left;
- etb.Location = new Point(DbFindGridView.RowHeadersWidth, DbFindGridView.Columns[i].Width);
- etb.Name = dt.Columns[i].Caption;
- etb.Tag = dt.Columns[i].Caption;
- etb.Size = new Size(DbFindGridView.Columns[i].Width, 22);
- etb.KeyDown += FilterData;
- this.Controls.Add(etb);
-
- ctl[i] = etb;
- }
-
- EnterTextBox Head = new EnterTextBox();
- Head.Enabled = false;
- Head.Dock = DockStyle.Left;
- Head.Location = new Point(0, DbFindGridView.RowHeadersWidth);
- Head.Size = new Size(DbFindGridView.RowHeadersWidth, 22);
- this.Controls.Add(Head);
- }
-
-
-
-
-
- private void FilterData(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- pagination1.BindDataToNavigator(DbFindGridView, BindTable, SelectField, "ID", Caller, BaseUtil.GetScreenSqlCondition(ctl).Replace("where", "") + ((Condition == "" || Condition == null) ? "" : " and " + Condition));
- }
- private void DbFindGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
-
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- for (int j = 0; j < SetValueField.Length; j++)
- {
- if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || dt.Columns[i].Caption.Contains(SetValueField[j]))
- {
- FormCollection fmCollection = Application.OpenForms;
- fmCollection[FormName].Controls[SetValueField[j]].Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
- }
- }
- }
- Dispose();
- Close();
- }
- catch (Exception)
- {
- Dispose();
- Close();
- }
- }
-
- private void DbFindGridView_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Escape)
- {
- Dispose();
- Close();
- }
- }
- private void DbFind_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
-
- private void DbFindGridView_ColumnWidthChanged(object sender, DataGridViewColumnEventArgs e)
- {
- if (ctl != null)
- ctl[DbFindGridView.Columns.IndexOf(e.Column)].Width = e.Column.Width;
- }
- }
- }
|