Kaynağa Gözat

优化SOP文件上传

callm 2 ay önce
ebeveyn
işleme
70a105a74f
1 değiştirilmiş dosya ile 28 ekleme ve 3 silme
  1. 28 3
      UAS_MES_YDCY/FunctionCode/Query/Query_SOP_CY.cs

+ 28 - 3
UAS_MES_YDCY/FunctionCode/Query/Query_SOP_CY.cs

@@ -360,21 +360,46 @@ namespace UAS_MES_NEW.Query
             }
         }
 
+        private BindingSource bs = new BindingSource(); // 类成员变量
+
         private void LoadPrCode()
         {
             DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where ps_prodcode='" + ps_prodcode.Text + "'", "select");
             if (dt.Rows.Count > 0)
             {
                 string ps_id = dt.Rows[0]["ps_id"].ToString();
-                dt = (DataTable)dh.ExecuteSql("select fp_name,fp_path,'' issend,psd_iskey from ProductSOPdetail left join " +
-                    "filepath on FP_ID=substr(PSD_ATTACH,instr(PSD_ATTACH,';')+1)  where psd_psid=" + ps_id, "select");
+                dt = (DataTable)dh.ExecuteSql(@"select fp_name,fp_path,'' issend,psd_iskey 
+                                        from ProductSOPdetail 
+                                        left join filepath on FP_ID=substr(PSD_ATTACH,instr(PSD_ATTACH,';')+1)  
+                                        where psd_psid=" + ps_id, "select");
                 if (dt.Rows.Count > 0)
                 {
-                    SendDGV.DataSource = dt;
+                    // 在 UI 线程安全执行(如果已经在 UI 线程则直接调用)
+                    if (SendDGV.InvokeRequired)
+                        SendDGV.Invoke(new Action(() => BindData(dt)));
+                    else
+                        BindData(dt);
                 }
             }
         }
 
+        private void BindData(DataTable dt)
+        {
+            // 使用 BindingSource 避免直接置 null
+            if (SendDGV.DataSource == null)
+            {
+                bs.DataSource = dt;
+                SendDGV.DataSource = bs;
+            }
+            else
+            {
+                bs.DataSource = dt; // 直接替换内部数据,控件不会经历“无数据”状态
+            }
+            // 可选:刷新显示
+            SendDGV.Refresh();
+        }
+
+
         private void pr_code_Leave(object sender, EventArgs e)
         {
             //LoadPrCode();