callm 4 недель назад
Родитель
Сommit
ff38760562

+ 113 - 75
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.Designer.cs

@@ -41,11 +41,6 @@ namespace UAS_MES_NEW.Query
             this.SendSop = new System.Windows.Forms.Button();
             this.JPG = new System.Windows.Forms.RadioButton();
             this.SendDGV = new System.Windows.Forms.DataGridView();
-            this.CheckColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
-            this.fp_name = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.fp_path = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.psd_iskey = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.issend = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ChooseALL = new System.Windows.Forms.Button();
             this.GetSOP = new System.Windows.Forms.Button();
             this.ChoosePrint = new System.Windows.Forms.Button();
@@ -63,13 +58,20 @@ namespace UAS_MES_NEW.Query
             this.VaildDate = new System.Windows.Forms.CheckBox();
             this.RowCount = new System.Windows.Forms.NumericUpDown();
             this.label9 = new System.Windows.Forms.Label();
+            this.PDF = new System.Windows.Forms.RadioButton();
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.dataGridViewTextBoxColumn1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.dataGridViewTextBoxColumn2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.ps_prodcode = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SearchTextBox();
-            this.PDF = new System.Windows.Forms.RadioButton();
+            this.CheckColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+            this.fp_name = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.fp_path = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.psd_iskey = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.issend = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.label10 = new System.Windows.Forms.Label();
+            this.pr_code = new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SearchTextBox();
             ((System.ComponentModel.ISupportInitialize)(this.SendDGV)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.X)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.Y)).BeginInit();
@@ -92,7 +94,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label1.Location = new System.Drawing.Point(19, 448);
+            this.label1.Location = new System.Drawing.Point(17, 520);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(146, 41);
             this.label1.TabIndex = 6;
@@ -101,14 +103,14 @@ namespace UAS_MES_NEW.Query
             // FilePath
             // 
             this.FilePath.Enabled = false;
-            this.FilePath.Location = new System.Drawing.Point(218, 453);
+            this.FilePath.Location = new System.Drawing.Point(216, 525);
             this.FilePath.Name = "FilePath";
             this.FilePath.Size = new System.Drawing.Size(582, 35);
             this.FilePath.TabIndex = 7;
             // 
             // ChooseFile
             // 
-            this.ChooseFile.Location = new System.Drawing.Point(216, 613);
+            this.ChooseFile.Location = new System.Drawing.Point(214, 685);
             this.ChooseFile.Name = "ChooseFile";
             this.ChooseFile.Size = new System.Drawing.Size(160, 42);
             this.ChooseFile.TabIndex = 8;
@@ -118,7 +120,7 @@ namespace UAS_MES_NEW.Query
             // 
             // UploadSOP
             // 
-            this.UploadSOP.Location = new System.Drawing.Point(422, 613);
+            this.UploadSOP.Location = new System.Drawing.Point(420, 685);
             this.UploadSOP.Name = "UploadSOP";
             this.UploadSOP.Size = new System.Drawing.Size(160, 42);
             this.UploadSOP.TabIndex = 9;
@@ -149,7 +151,7 @@ namespace UAS_MES_NEW.Query
             // 
             // SendSop
             // 
-            this.SendSop.Location = new System.Drawing.Point(638, 613);
+            this.SendSop.Location = new System.Drawing.Point(636, 685);
             this.SendSop.Name = "SendSop";
             this.SendSop.Size = new System.Drawing.Size(160, 42);
             this.SendSop.TabIndex = 13;
@@ -161,7 +163,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.JPG.AutoSize = true;
             this.JPG.Checked = true;
-            this.JPG.Location = new System.Drawing.Point(251, 534);
+            this.JPG.Location = new System.Drawing.Point(249, 606);
             this.JPG.Name = "JPG";
             this.JPG.Size = new System.Drawing.Size(89, 28);
             this.JPG.TabIndex = 18;
@@ -189,47 +191,6 @@ namespace UAS_MES_NEW.Query
             this.SendDGV.TabIndex = 22;
             this.SendDGV.CellPainting += new System.Windows.Forms.DataGridViewCellPaintingEventHandler(this.SendDGV_CellPainting);
             // 
-            // CheckColumn
-            // 
-            this.CheckColumn.DataPropertyName = "CheckColumn";
-            this.CheckColumn.HeaderText = "勾选";
-            this.CheckColumn.MinimumWidth = 100;
-            this.CheckColumn.Name = "CheckColumn";
-            this.CheckColumn.Width = 200;
-            // 
-            // fp_name
-            // 
-            this.fp_name.DataPropertyName = "fp_name";
-            this.fp_name.HeaderText = "文件名";
-            this.fp_name.MinimumWidth = 10;
-            this.fp_name.Name = "fp_name";
-            this.fp_name.Width = 200;
-            // 
-            // fp_path
-            // 
-            this.fp_path.DataPropertyName = "fp_path";
-            this.fp_path.HeaderText = "路径";
-            this.fp_path.MinimumWidth = 10;
-            this.fp_path.Name = "fp_path";
-            this.fp_path.Width = 200;
-            // 
-            // psd_iskey
-            // 
-            this.psd_iskey.DataPropertyName = "psd_iskey";
-            this.psd_iskey.HeaderText = "是否关键工序";
-            this.psd_iskey.MinimumWidth = 10;
-            this.psd_iskey.Name = "psd_iskey";
-            this.psd_iskey.Width = 200;
-            // 
-            // issend
-            // 
-            this.issend.DataPropertyName = "issend";
-            this.issend.HeaderText = "是否成功发送";
-            this.issend.MinimumWidth = 10;
-            this.issend.Name = "issend";
-            this.issend.Visible = false;
-            this.issend.Width = 200;
-            // 
             // ChooseALL
             // 
             this.ChooseALL.Location = new System.Drawing.Point(865, 61);
@@ -252,7 +213,7 @@ namespace UAS_MES_NEW.Query
             // 
             // ChoosePrint
             // 
-            this.ChoosePrint.Location = new System.Drawing.Point(649, 726);
+            this.ChoosePrint.Location = new System.Drawing.Point(647, 798);
             this.ChoosePrint.Name = "ChoosePrint";
             this.ChoosePrint.Size = new System.Drawing.Size(160, 42);
             this.ChoosePrint.TabIndex = 27;
@@ -263,7 +224,7 @@ namespace UAS_MES_NEW.Query
             // PrintPath
             // 
             this.PrintPath.Enabled = false;
-            this.PrintPath.Location = new System.Drawing.Point(216, 732);
+            this.PrintPath.Location = new System.Drawing.Point(214, 804);
             this.PrintPath.Name = "PrintPath";
             this.PrintPath.Size = new System.Drawing.Size(416, 35);
             this.PrintPath.TabIndex = 28;
@@ -272,7 +233,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label3.AutoSize = true;
             this.label3.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label3.Location = new System.Drawing.Point(10, 726);
+            this.label3.Location = new System.Drawing.Point(8, 798);
             this.label3.Name = "label3";
             this.label3.Size = new System.Drawing.Size(178, 41);
             this.label3.TabIndex = 29;
@@ -282,7 +243,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label4.AutoSize = true;
             this.label4.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label4.Location = new System.Drawing.Point(10, 807);
+            this.label4.Location = new System.Drawing.Point(8, 879);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(178, 41);
             this.label4.TabIndex = 30;
@@ -292,7 +253,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label6.AutoSize = true;
             this.label6.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label6.Location = new System.Drawing.Point(209, 807);
+            this.label6.Location = new System.Drawing.Point(207, 879);
             this.label6.Name = "label6";
             this.label6.Size = new System.Drawing.Size(39, 41);
             this.label6.TabIndex = 31;
@@ -302,7 +263,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label7.AutoSize = true;
             this.label7.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label7.Location = new System.Drawing.Point(403, 807);
+            this.label7.Location = new System.Drawing.Point(401, 879);
             this.label7.Name = "label7";
             this.label7.Size = new System.Drawing.Size(37, 41);
             this.label7.TabIndex = 32;
@@ -310,7 +271,7 @@ namespace UAS_MES_NEW.Query
             // 
             // X
             // 
-            this.X.Location = new System.Drawing.Point(256, 813);
+            this.X.Location = new System.Drawing.Point(254, 885);
             this.X.Maximum = new decimal(new int[] {
             5,
             0,
@@ -327,12 +288,12 @@ namespace UAS_MES_NEW.Query
             // 
             // Y
             // 
-            this.Y.Location = new System.Drawing.Point(462, 813);
+            this.Y.Location = new System.Drawing.Point(460, 885);
             this.Y.Name = "Y";
             this.Y.Size = new System.Drawing.Size(120, 35);
             this.Y.TabIndex = 34;
             this.Y.Value = new decimal(new int[] {
-            7,
+            25,
             0,
             0,
             0});
@@ -358,7 +319,7 @@ namespace UAS_MES_NEW.Query
             // 
             // DateCode
             // 
-            this.DateCode.Location = new System.Drawing.Point(216, 905);
+            this.DateCode.Location = new System.Drawing.Point(214, 977);
             this.DateCode.Name = "DateCode";
             this.DateCode.Size = new System.Drawing.Size(200, 35);
             this.DateCode.TabIndex = 37;
@@ -367,7 +328,7 @@ namespace UAS_MES_NEW.Query
             // 
             this.label5.AutoSize = true;
             this.label5.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label5.Location = new System.Drawing.Point(10, 899);
+            this.label5.Location = new System.Drawing.Point(8, 971);
             this.label5.Name = "label5";
             this.label5.Size = new System.Drawing.Size(178, 41);
             this.label5.TabIndex = 38;
@@ -376,7 +337,7 @@ namespace UAS_MES_NEW.Query
             // VaildDate
             // 
             this.VaildDate.AutoSize = true;
-            this.VaildDate.Location = new System.Drawing.Point(451, 911);
+            this.VaildDate.Location = new System.Drawing.Point(449, 983);
             this.VaildDate.Name = "VaildDate";
             this.VaildDate.Size = new System.Drawing.Size(162, 28);
             this.VaildDate.TabIndex = 39;
@@ -385,7 +346,7 @@ namespace UAS_MES_NEW.Query
             // 
             // RowCount
             // 
-            this.RowCount.Location = new System.Drawing.Point(218, 985);
+            this.RowCount.Location = new System.Drawing.Point(216, 1057);
             this.RowCount.Name = "RowCount";
             this.RowCount.Size = new System.Drawing.Size(120, 35);
             this.RowCount.TabIndex = 40;
@@ -399,12 +360,22 @@ namespace UAS_MES_NEW.Query
             // 
             this.label9.AutoSize = true;
             this.label9.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label9.Location = new System.Drawing.Point(19, 979);
+            this.label9.Location = new System.Drawing.Point(17, 1051);
             this.label9.Name = "label9";
             this.label9.Size = new System.Drawing.Size(146, 41);
             this.label9.TabIndex = 41;
             this.label9.Text = "截取行数";
             // 
+            // PDF
+            // 
+            this.PDF.AutoSize = true;
+            this.PDF.Location = new System.Drawing.Point(366, 606);
+            this.PDF.Name = "PDF";
+            this.PDF.Size = new System.Drawing.Size(77, 28);
+            this.PDF.TabIndex = 42;
+            this.PDF.Text = "PDF";
+            this.PDF.UseVisualStyleBackColor = true;
+            // 
             // dataGridViewCheckBoxColumn1
             // 
             this.dataGridViewCheckBoxColumn1.DataPropertyName = "CheckColumn";
@@ -465,21 +436,86 @@ namespace UAS_MES_NEW.Query
             this.ps_prodcode.TextBoxEnable = false;
             this.ps_prodcode.UserControlTextChanged += new UAS_MES_NEW.CustomControl.TextBoxWithIcon.SearchTextBox.OnTextChange(this.ps_prodcode_UserControlTextChanged);
             // 
-            // PDF
+            // CheckColumn
             // 
-            this.PDF.AutoSize = true;
-            this.PDF.Location = new System.Drawing.Point(368, 534);
-            this.PDF.Name = "PDF";
-            this.PDF.Size = new System.Drawing.Size(77, 28);
-            this.PDF.TabIndex = 42;
-            this.PDF.Text = "PDF";
-            this.PDF.UseVisualStyleBackColor = true;
+            this.CheckColumn.DataPropertyName = "CheckColumn";
+            this.CheckColumn.HeaderText = "勾选";
+            this.CheckColumn.MinimumWidth = 100;
+            this.CheckColumn.Name = "CheckColumn";
+            this.CheckColumn.Width = 200;
+            // 
+            // fp_name
+            // 
+            this.fp_name.DataPropertyName = "fp_name";
+            this.fp_name.HeaderText = "文件名";
+            this.fp_name.MinimumWidth = 10;
+            this.fp_name.Name = "fp_name";
+            this.fp_name.Width = 200;
+            // 
+            // fp_path
+            // 
+            this.fp_path.DataPropertyName = "fp_path";
+            this.fp_path.HeaderText = "路径";
+            this.fp_path.MinimumWidth = 10;
+            this.fp_path.Name = "fp_path";
+            this.fp_path.Width = 200;
+            // 
+            // psd_iskey
+            // 
+            this.psd_iskey.DataPropertyName = "psd_iskey";
+            this.psd_iskey.HeaderText = "是否关键工序";
+            this.psd_iskey.MinimumWidth = 10;
+            this.psd_iskey.Name = "psd_iskey";
+            this.psd_iskey.Width = 200;
+            // 
+            // issend
+            // 
+            this.issend.DataPropertyName = "issend";
+            this.issend.HeaderText = "是否成功发送";
+            this.issend.MinimumWidth = 10;
+            this.issend.Name = "issend";
+            this.issend.Visible = false;
+            this.issend.Width = 200;
+            // 
+            // label10
+            // 
+            this.label10.AutoSize = true;
+            this.label10.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label10.Location = new System.Drawing.Point(17, 444);
+            this.label10.Margin = new System.Windows.Forms.Padding(6, 0, 6, 0);
+            this.label10.Name = "label10";
+            this.label10.Size = new System.Drawing.Size(146, 41);
+            this.label10.TabIndex = 242;
+            this.label10.Text = "产品编号";
+            // 
+            // pr_code
+            // 
+            this.pr_code.AllPower = "ifall";
+            this.pr_code.Caller = null;
+            this.pr_code.Condition = null;
+            this.pr_code.DBTitle = "选择物料";
+            this.pr_code.Font = new System.Drawing.Font("微软雅黑", 9F);
+            this.pr_code.FormName = null;
+            this.pr_code.Location = new System.Drawing.Point(218, 444);
+            this.pr_code.Margin = new System.Windows.Forms.Padding(5);
+            this.pr_code.Name = "pr_code";
+            this.pr_code.Power = "ifspecial";
+            this.pr_code.ReturnData = null;
+            this.pr_code.SelectField = null;
+            this.pr_code.SetValueField = null;
+            this.pr_code.Size = new System.Drawing.Size(580, 44);
+            this.pr_code.TabIndex = 241;
+            this.pr_code.TableName = null;
+            this.pr_code.Tag = "";
+            this.pr_code.TextBoxEnable = false;
             // 
             // Query_SOP
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1945, 1234);
+            this.Controls.Add(this.label10);
+            this.Controls.Add(this.pr_code);
             this.Controls.Add(this.PDF);
             this.Controls.Add(this.label9);
             this.Controls.Add(this.RowCount);
@@ -565,5 +601,7 @@ namespace UAS_MES_NEW.Query
         private System.Windows.Forms.NumericUpDown RowCount;
         private System.Windows.Forms.Label label9;
         private System.Windows.Forms.RadioButton PDF;
+        private System.Windows.Forms.Label label10;
+        private SearchTextBox pr_code;
     }
 }

+ 50 - 44
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.cs

@@ -47,6 +47,13 @@ namespace UAS_MES_NEW.Query
             ps_prodcode.Condition = "";
             ps_prodcode.DbChange += nr_rule_DBChange;
 
+            pr_code.TableName = "product";
+            pr_code.SelectField = "pr_code # 产品编号,pr_detail # 产品名称,pr_spec # 产品规格";
+            pr_code.FormName = Name;
+            pr_code.DBTitle = "物料查询";
+            pr_code.Condition = "pr_code not like '%LX%'";
+            pr_code.SetValueField = new string[] { "pr_code" };
+
             dh = SystemInf.dh;
         }
 
@@ -63,6 +70,11 @@ namespace UAS_MES_NEW.Query
                 MessageBox.Show("文件不能为空!");
                 return;
             }
+            //if (pr_code.Text == "")
+            //{
+            //    MessageBox.Show("产品编号不能为空!");
+            //    return;
+            //}
             if (JPG.Checked)
             {
                 ps_prodcode.Text = FilePath.Text.Substring(FilePath.Text.LastIndexOf(@"\") + 1).Replace(".xls", "").Replace(".xlsx", "");
@@ -74,11 +86,11 @@ namespace UAS_MES_NEW.Query
                     ps_code.Text = code;
                     if (VaildDate.Checked)
                     {
-                        dh.ExecuteSql("insert into productsop(ps_id,ps_code,ps_prodcode,ps_indate,ps_inman,ps_status,ps_statuscode,ps_vailddate)values(productsop_seq.nextval,'" + code + "','" + ps_prodcode.Text + "',sysdate,'" + User.UserName + "','在录入','ENTERING',to_date('" + DateCode.Value.ToString("yyyy-MM-dd") + "','yyyy-mm-dd'))", "insert");
+                        dh.ExecuteSql("insert into productsop(ps_id,ps_code,ps_prodcode,ps_indate,ps_inman,ps_status,ps_statuscode,ps_vailddate,ps_prcode)values(productsop_seq.nextval,'" + code + "','" + ps_prodcode.Text + "',sysdate,'" + User.UserName + "','在录入','ENTERING',to_date('" + DateCode.Value.ToString("yyyy-MM-dd") + "','yyyy-mm-dd'),'" + pr_code.Text + "')", "insert");
                     }
                     else
                     {
-                        dh.ExecuteSql("insert into productsop(ps_id,ps_code,ps_prodcode,ps_indate,ps_inman,ps_status,ps_statuscode)values(productsop_seq.nextval,'" + code + "','" + ps_prodcode.Text + "',sysdate,'" + User.UserName + "','在录入','ENTERING')", "insert");
+                        dh.ExecuteSql("insert into productsop(ps_id,ps_code,ps_prodcode,ps_indate,ps_inman,ps_status,ps_statuscode,ps_prcode)values(productsop_seq.nextval,'" + code + "','" + ps_prodcode.Text + "',sysdate,'" + User.UserName + "','在录入','ENTERING','" + pr_code.Text + "')", "insert");
                     }
                 }
                 else
@@ -116,72 +128,60 @@ namespace UAS_MES_NEW.Query
                             string path = Application.StartupPath + @"\" + ps_prodcode.Text + @"\";
                             Worksheet she = workbook.Worksheets[i];
 
-                            // 1. 获取工作表中的真实内容区域(包括图片)
-                            int lastColIndex = she.Cells.MaxDataColumn+5;
-                            string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex)+5;
+                            // 获取原表的实际数据范围和最大列
                             int totalRows = she.Cells.MaxDataRow + 1;
+                            int lastColIndex = she.Cells.MaxDataColumn;
+                            string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex);
 
-                            // 注意:如果左侧的空白列(如 A列)有白色背景或边框,MaxDataColumn 会包含它们。
-                            // 如果想强行包含左侧列,可以使用 she.Cells.MaxColumn
-
-                            int rowSliceSize = int.Parse(RowCount.Value.ToString()); // 每多少行切片
+                            int rowSliceSize = int.Parse(RowCount.Value.ToString());
                             int imageIndex = 1;
 
-                            // 2. 严格设置打印区域和页面设置(不修改原文件)
-                            she.PageSetup.PrintArea = $"A1:{lastColLetter}{totalRows}";
+                            // 记录原表设置,循环结束后恢复,避免污染原文件
+                            string originalPrintArea = she.PageSetup.PrintArea;
+                            double originalLeftMargin = she.PageSetup.LeftMargin;
+                            double originalRightMargin = she.PageSetup.RightMargin;
+                            double originalTopMargin = she.PageSetup.TopMargin;
+                            double originalBottomMargin = she.PageSetup.BottomMargin;
+
+                            // 设置居中、无边距的打印模式,确保图片紧密贴合
+                            she.PageSetup.CenterHorizontally = true;
+                            she.PageSetup.CenterVertically = true;
                             she.PageSetup.LeftMargin = 0;
                             she.PageSetup.RightMargin = 0;
                             she.PageSetup.TopMargin = 0;
                             she.PageSetup.BottomMargin = 0;
-                            she.PageSetup.Zoom = 100; // 保持原尺寸,不要缩放
 
                             for (int startRow = 0; startRow < totalRows; startRow += rowSliceSize)
                             {
                                 int endRow = Math.Min(startRow + rowSliceSize - 1, totalRows - 1);
 
-                                // 3. 创建图片选项 (核心优化点)
+                                // 1. 动态设置原表的打印区域(模拟切片)
+                                // 注意:这里直接使用原表渲染,虽然旧版本对图片的浮层处理有限,但这能最大程度保留图片
+                                she.PageSetup.PrintArea = $"A{startRow + 1}:{lastColLetter}{endRow + 1}";
+
+                                // 2. 创建渲染选项
                                 ImageOrPrintOptions options = new ImageOrPrintOptions();
                                 options.ImageFormat = ImageFormat.Png;
-                                options.OnePagePerSheet = false; // 允许多行
-                                                                 // options.PrintingPage = PrintingPageType.IgnoreBlank; // ❌ 移除它!这就是左侧消失的元凶
-                                options.PrintingPage = PrintingPageType.Default;       // ✅ 包含所有行列,保留空白区域
+                                options.OnePagePerSheet = true; // 强制在一页内输出,严格限制范围
+                                options.PrintingPage = PrintingPageType.Default; // 禁止忽略空白行列
 
-                                // 4. 仅对 SheetRender 对象设置 PrintArea,不修改原工作表
-                                // 这是一个技巧:我们可以暂时设置,渲染完后再恢复
-                                string originalPrintArea = she.PageSetup.PrintArea;
-                                she.PageSetup.PrintArea = $"A{startRow + 1}:{lastColLetter}{endRow + 1}";
-                                if (File.Exists(PrintPath.Text))
-                                {
-                                    if (startRow == 0)
-                                    {
-                                        she.Pictures.Add(startRow + int.Parse(Y.Value.ToString()), int.Parse(X.Value.ToString()), PrintPath.Text);
-
-                                    }
-                                    else
-                                    {
-                                        she.Pictures.Add(startRow - 4 + int.Parse(Y.Value.ToString()), int.Parse(X.Value.ToString()), PrintPath.Text);
-
-                                    }
-                                }
-                                // 5. 直接渲染图片,不需要手动添加 Picture 或使用 Graphics
+                                // 3. 渲染图片
                                 SheetRender sr = new SheetRender(she, options);
                                 Bitmap bitmap = sr.ToImage(0);
 
-                                // 恢复原打印区域
-                                she.PageSetup.PrintArea = originalPrintArea;
-
-                                // 6. 保存并上传
+                                // 4. 处理并保存图片
                                 string imagename = $"{she.Name}_{imageIndex}.png";
                                 string imagePath = Path.Combine(path, imagename);
                                 bitmap.Save(imagePath, ImageFormat.Png);
 
-                                // 释放资源
+                                // 释放资源,防止内存溢出
                                 bitmap.Dispose();
+                                //sr.Dispose();
 
                                 imageIndex++;
-
-                                // 上传逻辑保留
                                 OperatResult.AppendText("解析图片【" + imagePath + "】" + "\n");
+
+                                // 5. 上传与入库
                                 Dictionary<string, object> dic = new Dictionary<string, object>();
                                 dic.Add("em_name", "管理员");
                                 dic.Add("em_code", "ADMIN");
@@ -189,10 +189,16 @@ namespace UAS_MES_NEW.Query
                                 OperatResult.AppendText("上传文件【" + imagePath + "】\n");
                                 string fp_id = UploadFilesToRemoteUrl("https://mes.lihantech.cn/mes/MEScommon/uploadFiles.action?_noc=1", imagePath, dic);
 
-                                // 获取 ps_id 并入库
                                 string ps_id = dh.getFieldDataByCondition("ProductSOP", "ps_id", "ps_prodcode='" + ps_prodcode.Text + "'").ToString();
                                 dh.ExecuteSql("insert into ProductSOPdetail(psd_id,psd_psid,psd_attach) select ProductSOPdetail_seq.nextval,ps_id,'" + imagename + ";" + fp_id + "' from ProductSOP where ps_prodcode='" + ps_prodcode.Text + "'", "insert");
                             }
+
+                            // 恢复原表设置
+                            she.PageSetup.PrintArea = originalPrintArea;
+                            she.PageSetup.LeftMargin = originalLeftMargin;
+                            she.PageSetup.RightMargin = originalRightMargin;
+                            she.PageSetup.TopMargin = originalTopMargin;
+                            she.PageSetup.BottomMargin = originalBottomMargin;
                         }
                         catch (Exception ex)
                         {
@@ -203,7 +209,7 @@ namespace UAS_MES_NEW.Query
             }
             else if (PDF.Checked)
             {
-                ps_prodcode.Text = FilePath.Text.Substring(FilePath.Text.LastIndexOf(@"\") + 1).Replace(".pdf","");
+                ps_prodcode.Text = FilePath.Text.Substring(FilePath.Text.LastIndexOf(@"\") + 1).Replace(".pdf", "");
                 pr_code_Leave(new object(), new EventArgs());
                 DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where ps_prodcode='" + ps_prodcode.Text + "' ", "select");
                 if (dt.Rows.Count == 0)
@@ -255,7 +261,7 @@ namespace UAS_MES_NEW.Query
         {
             try
             {
-                ServicePointManager.SecurityProtocol =  SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
+                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
                 ServicePointManager.DefaultConnectionLimit = 50;
 
                 string boundary = DateTime.Now.Ticks.ToString("x");

+ 15 - 0
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.resx

@@ -135,4 +135,19 @@
   <metadata name="issend.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
+  <metadata name="CheckColumn.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="fp_name.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="fp_path.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="psd_iskey.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="issend.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
 </root>