Pārlūkot izejas kodu

调整DBFind赋值

章政 8 gadi atpakaļ
vecāks
revīzija
1d9d74b103

+ 27 - 7
UAS-MES/CustomControl/TextBoxWithIcon/SearchTextBox.cs

@@ -306,23 +306,43 @@ namespace UAS_MES.CustomControl.TextBoxWithIcon
                     sql += " and " + condition;
                 }
                 DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
+                Boolean groupcontains = false;
+                //先判断DataTable里面是否有这个字段,然后从打开的窗口里面去获取到这个Form,从Form中的指定Panel获取到指定字段的控件
                 FormCollection fmCollection = Application.OpenForms;
-                if (dt.Rows.Count > 0)
+                ControlCollection controls = (ControlCollection)fmCollection[FormName].Controls;
+                for (int i = 0; i < dt.Columns.Count; i++)
+                {
+                    for (int k = 0; k < controls.Count; k++)
+                    {
+                        Control ctl = controls[k];
+                        if (ctl.Controls.Count > 0)
+                        {
+                            for (int j = 0; j < SetValueField.Length; j++)
+                            {
+                                Control ct2 = ctl.Controls[SetValueField[j]];
+                                if (ct2 != null)
+                                {
+                                    if (SetValueField[j] == dt.Columns[i].Caption.ToLower() || SetValueField[j] == dt.Columns[i].ColumnName.ToLower() || SetValueField[j].Contains(dt.Columns[i].Caption.ToLower()) || (ct2 != null && ct2.Tag != null && ct2.Tag.ToString() == dt.Columns[i].Caption.ToLower()))
+                                        ct2.Text = dt.Rows[0][dt.Columns[i].ColumnName].ToString();
+                                    groupcontains = true;
+                                }
+                            }
+                        }
+                        break;
+                    }
+                }
+                if (!groupcontains)
                 {
                     for (int i = 0; i < dt.Columns.Count; i++)
                     {
                         for (int j = 0; j < SetValueField.Length; j++)
                         {
-                            object tag = fmCollection[FormName].Controls[SetValueField[j]].Tag;
-                            //利用字段的Tag属性来和列名进行比对
-                            if (SetValueField[j] == dt.Columns[i].ColumnName.ToLower() || (tag != null && tag.ToString() == dt.Columns[i].ColumnName.ToLower()))
+                            Control ctl = fmCollection[FormName].Controls[SetValueField[j]];
+                            if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || SetValueField[j].Contains(dt.Columns[i].Caption) || (ctl != null && ctl.Tag != null && ctl.Tag.ToString() == dt.Columns[i].Caption))
                                 fmCollection[FormName].Controls[SetValueField[j]].Text = dt.Rows[0][dt.Columns[i].ColumnName].ToString();
                         }
                     }
-                    LeaveFindData = true;
                 }
-                else
-                    LeaveFindData = false;
             }
         }
     }

+ 32 - 39
UAS-MES/DbFind.cs

@@ -166,52 +166,45 @@ namespace UAS_MES
                 Boolean groupcontains = false;
                 //先判断DataTable里面是否有这个字段,然后从打开的窗口里面去获取到这个Form,从Form中的指定Panel获取到指定字段的控件
                 FormCollection fmCollection = Application.OpenForms;
-                //SuccessReturnData = true;
-                //ControlCollection controls = (ControlCollection)fmCollection[FormName].Controls;
-                //for (int i = 0; i < dt.Columns.Count; i++)
-                //{
-                //    for (int k = 0; k < controls.Count; k++)
-                //    {
-                //        Control ctl = controls[k];
-                //        if (ctl.Controls.Count > 0)
-                //        {
-                //            for (int j = 0; j < SetValueField.Length; j++)
-                //            {
-                //                Control ct2 = ctl.Controls[SetValueField[j]];
-                //                if (ct2 != null)
-                //                {
-                //                    if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || SetValueField[j].Contains(dt.Columns[i].Caption) || (ct2 != null && ct2.Tag != null && ct2.Tag.ToString() == dt.Columns[i].Caption))
-                //                        ct2.Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
-                //                    groupcontains = true;
-                //                }
-                //            }
-                //        }
-                //        break;
-                //    }
-                //}
-                //if (!groupcontains)
-                //{
-                //    for (int i = 0; i < dt.Columns.Count; i++)
-                //    {
-                //        for (int j = 0; j < SetValueField.Length; j++)
-                //        {
-                //            Control ctl = fmCollection[FormName].Controls[SetValueField[j]];
-                //            if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || SetValueField[j].Contains(dt.Columns[i].Caption) || (ctl != null && ctl.Tag != null && ctl.Tag.ToString() == dt.Columns[i].Caption))
-                //                fmCollection[FormName].Controls[SetValueField[j]].Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
-                //        }
-                //    }
-                //}
-                //发起DBFind的控件
-                SuccessReturnData = true;
+                ControlCollection controls = (ControlCollection)fmCollection[FormName].Controls;
                 MainControl = fmCollection[FormName].Controls[MainField];
                 for (int i = 0; i < dt.Columns.Count; i++)
                 {
-                    if (MainControl.Name == dt.Columns[i].Caption.ToLower() || (MainControl.Tag != null && MainControl.Tag.ToString() == dt.Columns[i].Caption.ToLower()))
+                    for (int k = 0; k < controls.Count; k++)
                     {
-                        MainControl.Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
+                        Control ctl = controls[k];
+                        if (ctl.Controls.Count > 0)
+                        {
+                            for (int j = 0; j < SetValueField.Length; j++)
+                            {
+                                Control ct2 = ctl.Controls[SetValueField[j]];
+                                MainControl = ctl.Controls[MainField];
+                                if (ct2 != null)
+                                {
+                                    if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || SetValueField[j].Contains(dt.Columns[i].Caption) || (ct2 != null && ct2.Tag != null && ct2.Tag.ToString() == dt.Columns[i].Caption))
+                                        ct2.Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
+                                    groupcontains = true;
+                                }
+                            }
+                        }
                         break;
                     }
                 }
+                if (!groupcontains)
+                {
+                    for (int i = 0; i < dt.Columns.Count; i++)
+                    {
+                        for (int j = 0; j < SetValueField.Length; j++)
+                        {
+                            Control ctl = fmCollection[FormName].Controls[SetValueField[j]];
+                            MainControl = fmCollection[FormName].Controls[MainField];
+                            if (SetValueField[j] == dt.Columns[i].Caption || SetValueField[j] == dt.Columns[i].ColumnName || SetValueField[j].Contains(dt.Columns[i].Caption) || (ctl != null && ctl.Tag != null && ctl.Tag.ToString() == dt.Columns[i].Caption))
+                                fmCollection[FormName].Controls[SetValueField[j]].Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
+                        }
+                    }
+                }
+                //发起DBFind的控件
+                SuccessReturnData = true;
                 if (MainControl is MaCodeSearchTextBox)
                 {
                     MaCodeSearchTextBox ctl = (MainControl as MaCodeSearchTextBox);

+ 1 - 1
UAS-MES/Program.cs

@@ -42,7 +42,7 @@ namespace UAS_MES
                 FileStream fs = new FileStream(sysdisc + @":\Log\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                 fs.Close();
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                    Application.Run(new Login());
+                    Application.Run(new Form1());
                 else
                 {
                     //创建启动对象