Эх сурвалжийг харах

DbFind控件赋值逻辑错误修改

Hcsy 8 жил өмнө
parent
commit
6d49f00b89
2 өөрчлөгдсөн 77 нэмэгдсэн , 9 устгасан
  1. 9 9
      UAS-MES/DbFind.cs
  2. 68 0
      f

+ 9 - 9
UAS-MES/DbFind.cs

@@ -166,9 +166,9 @@ namespace UAS_MES
                 //先判断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++)
                 {
-                    ControlCollection controls = (ControlCollection)fmCollection[FormName].Controls;
                     for (int k = 0; k < controls.Count; k++)
                     {
                         Control ctl = controls[k];
@@ -177,17 +177,20 @@ namespace UAS_MES
                             for (int j = 0; j < SetValueField.Length; j++)
                             {
                                 Control ct2 = ctl.Controls[SetValueField[j]];
-                                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();
+                                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;
+                                }
                             }
-                            groupcontains = true;
-
                         }
                         break;
                     }
                 }
                 if (!groupcontains)
                 {
+
                     for (int i = 0; i < dt.Columns.Count; i++)
                     {
                         for (int j = 0; j < SetValueField.Length; j++)
@@ -197,10 +200,8 @@ namespace UAS_MES
                                 fmCollection[FormName].Controls[SetValueField[j]].Text = DbFindGridView.Rows[e.RowIndex].Cells[dt.Columns[i].ColumnName].Value.ToString();
                         }
                     }
-                }
-
+                }   
                 fmCollection[FormName].Controls[MainField].Focus();
-            }
             catch (Exception exa)
             {
                 SuccessReturnData = false;
@@ -208,7 +209,6 @@ namespace UAS_MES
             Dispose();
             Close();
         }
-
         //按下Esc键的时候关闭当前的界面,用于DbFind
         private void DbFindGridView_KeyPress(object sender, KeyPressEventArgs e)
         {

+ 68 - 0
f

@@ -0,0 +1,68 @@
+diff --git a/TestProject/Form1.Designer.cs b/TestProject/Form1.Designer.cs
+index 403a991..5dedabe 100644
+--- a/TestProject/Form1.Designer.cs
++++ b/TestProject/Form1.Designer.cs
+@@ -28,53 +28,13 @@
+         /// </summary>
+         private void InitializeComponent()
+         {
+-            this.button1 = new System.Windows.Forms.Button();
+-            this.button2 = new System.Windows.Forms.Button();
+-            this.qqButton1 = new TestProject.QQButton();
+             this.SuspendLayout();
+             // 
+-            // button1
+-            // 
+-            this.button1.Location = new System.Drawing.Point(632, 124);
+-            this.button1.Margin = new System.Windows.Forms.Padding(4);
+-            this.button1.Name = "button1";
+-            this.button1.Size = new System.Drawing.Size(100, 29);
+-            this.button1.TabIndex = 0;
+-            this.button1.Text = "button1";
+-            this.button1.UseVisualStyleBackColor = true;
+-            this.button1.Click += new System.EventHandler(this.button1_Click);
+-            // 
+-            // button2
+-            // 
+-            this.button2.Location = new System.Drawing.Point(373, 112);
+-            this.button2.Margin = new System.Windows.Forms.Padding(4);
+-            this.button2.Name = "button2";
+-            this.button2.Size = new System.Drawing.Size(100, 29);
+-            this.button2.TabIndex = 1;
+-            this.button2.Text = "button2";
+-            this.button2.UseVisualStyleBackColor = true;
+-            this.button2.Click += new System.EventHandler(this.button2_Click);
+-            // 
+-            // qqButton1
+-            // 
+-            this.qqButton1.ForeColor = System.Drawing.SystemColors.ControlText;
+-            this.qqButton1.IsShowBorder = true;
+-            this.qqButton1.Location = new System.Drawing.Point(159, 112);
+-            this.qqButton1.Name = "qqButton1";
+-            this.qqButton1.Size = new System.Drawing.Size(166, 97);
+-            this.qqButton1.TabIndex = 2;
+-            this.qqButton1.Text = "12312";
+-            this.qqButton1.UseVisualStyleBackColor = true;
+-            this.qqButton1.Click += new System.EventHandler(this.qqButton1_Click);
+-            // 
+             // Form1
+             // 
+             this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+             this.ClientSize = new System.Drawing.Size(1063, 578);
+-            this.Controls.Add(this.qqButton1);
+-            this.Controls.Add(this.button2);
+-            this.Controls.Add(this.button1);
+             this.Margin = new System.Windows.Forms.Padding(4);
+             this.Name = "Form1";
+             this.Text = "Form1";
+@@ -84,9 +44,6 @@
+         }
+ 
+         #endregion
+-
+-        private System.Windows.Forms.Button button1;
+-        private System.Windows.Forms.Button button2;
+         private QQButton qqButton1;
+     }
+ }