Jelajahi Sumber

优化SOP上传

callm 1 Minggu lalu
induk
melakukan
8b56271c9f

+ 109 - 43
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.Designer.cs

@@ -41,6 +41,11 @@ 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();
@@ -59,14 +64,15 @@ namespace UAS_MES_NEW.Query
             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.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.DateCode = new System.Windows.Forms.DateTimePicker();
+            this.label5 = new System.Windows.Forms.Label();
+            this.VaildDate = new System.Windows.Forms.CheckBox();
+            this.RowCount = new System.Windows.Forms.NumericUpDown();
+            this.label9 = new System.Windows.Forms.Label();
             ((System.ComponentModel.ISupportInitialize)(this.SendDGV)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.X)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.Y)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.RowCount)).BeginInit();
             this.SuspendLayout();
             // 
             // richTextBox1
@@ -182,6 +188,47 @@ 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);
@@ -358,52 +405,65 @@ 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);
             // 
-            // 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;
+            // DateCode
+            // 
+            this.DateCode.Location = new System.Drawing.Point(216, 905);
+            this.DateCode.Name = "DateCode";
+            this.DateCode.Size = new System.Drawing.Size(200, 35);
+            this.DateCode.TabIndex = 37;
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label5.Location = new System.Drawing.Point(10, 899);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(178, 41);
+            this.label5.TabIndex = 38;
+            this.label5.Text = "文件有效期";
+            // 
+            // VaildDate
+            // 
+            this.VaildDate.AutoSize = true;
+            this.VaildDate.Location = new System.Drawing.Point(451, 911);
+            this.VaildDate.Name = "VaildDate";
+            this.VaildDate.Size = new System.Drawing.Size(162, 28);
+            this.VaildDate.TabIndex = 39;
+            this.VaildDate.Text = "管控有效期";
+            this.VaildDate.UseVisualStyleBackColor = true;
+            // 
+            // RowCount
+            // 
+            this.RowCount.Location = new System.Drawing.Point(218, 985);
+            this.RowCount.Name = "RowCount";
+            this.RowCount.Size = new System.Drawing.Size(120, 35);
+            this.RowCount.TabIndex = 40;
+            this.RowCount.Value = new decimal(new int[] {
+            40,
+            0,
+            0,
+            0});
             // 
-            // issend
+            // label9
             // 
-            this.issend.DataPropertyName = "issend";
-            this.issend.HeaderText = "是否成功发送";
-            this.issend.MinimumWidth = 10;
-            this.issend.Name = "issend";
-            this.issend.Visible = false;
-            this.issend.Width = 200;
+            this.label9.AutoSize = true;
+            this.label9.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label9.Location = new System.Drawing.Point(19, 979);
+            this.label9.Name = "label9";
+            this.label9.Size = new System.Drawing.Size(146, 41);
+            this.label9.TabIndex = 41;
+            this.label9.Text = "截取行数";
             // 
             // 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.label9);
+            this.Controls.Add(this.RowCount);
+            this.Controls.Add(this.VaildDate);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.DateCode);
             this.Controls.Add(this.ps_code);
             this.Controls.Add(this.label8);
             this.Controls.Add(this.Y);
@@ -436,6 +496,7 @@ namespace UAS_MES_NEW.Query
             ((System.ComponentModel.ISupportInitialize)(this.SendDGV)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.X)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.Y)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.RowCount)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
@@ -476,5 +537,10 @@ namespace UAS_MES_NEW.Query
         private System.Windows.Forms.NumericUpDown Y;
         private System.Windows.Forms.Label label8;
         private System.Windows.Forms.Label ps_code;
+        private System.Windows.Forms.DateTimePicker DateCode;
+        private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.CheckBox VaildDate;
+        private System.Windows.Forms.NumericUpDown RowCount;
+        private System.Windows.Forms.Label label9;
     }
 }

+ 91 - 78
UAS_MES_ZKLH/FunctionCode/Query/Query_SOP.cs

@@ -16,6 +16,7 @@ using UAS_MES_NEW.PublicForm;
 using Aspose.Cells.Drawing;
 using Aspose.Cells.Rendering;
 using System.Web.Script.Serialization;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_NEW.Query
 {
@@ -69,7 +70,14 @@ namespace UAS_MES_NEW.Query
             {
                 string code = LogicHandler.GetPiInoutCode("ProductSOP", "1");
                 ps_code.Text = code;
-                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,'" + usercode + "','在录入','ENTERING')", "insert");
+                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,'" + usercode + "','在录入','ENTERING',to_date('" + DateCode.Value.ToString("yyyy-MM-dd") + "','yyyy-mm-dd'))", "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,'" + usercode + "','在录入','ENTERING')", "insert");
+                }
             }
             else
             {
@@ -84,97 +92,102 @@ namespace UAS_MES_NEW.Query
             OperatResult.AppendText("一共Sheet: " + workbook.Worksheets.Count + "\n");
             for (int i = 0; i < workbook.Worksheets.Count; i++)
             {
-                if (workbook.Worksheets[i].Name != "物料清单")
+                OperatResult.AppendText("正在解析Sheet" + workbook.Worksheets[i].Name + "\n");
+                string path = Application.StartupPath + @"\" + ps_prodcode.Text + @"\";
+                Worksheet she = workbook.Worksheets[i];
+                int lastColIndex = she.Cells.MaxDataColumn;
+                string lastColLetter = CellsHelper.ColumnIndexToName(lastColIndex);
+                she.PageSetup.LeftMargin = 0;
+                she.PageSetup.RightMargin = 0;
+                she.PageSetup.TopMargin = 0;
+                she.PageSetup.BottomMargin = 0;
+                if (JPG.Checked)
                 {
-                    OperatResult.AppendText("正在解析Sheet" + workbook.Worksheets[i].Name + "\n");
-                    string path = Application.StartupPath + @"\" + ps_prodcode.Text + @"\";
-                    Worksheet she = workbook.Worksheets[i];
-                    if (JPG.Checked)
+                    try
                     {
-                        try
+                        if (!Directory.Exists(Application.StartupPath + @"\" + ps_prodcode.Text))
                         {
-                            if (!Directory.Exists(Application.StartupPath + @"\" + ps_prodcode.Text))
-                            {
-                                Directory.CreateDirectory(Application.StartupPath + @"\" + ps_prodcode.Text);
-                            }
-                            string sheetname = she.Name;
+                            Directory.CreateDirectory(Application.StartupPath + @"\" + ps_prodcode.Text);
+                        }
+                        string sheetname = she.Name;
 
-                            // 获取工作表中的所有图片
-                            List<Picture> pictures = new List<Picture>();
-                            foreach (Aspose.Cells.Drawing.Picture picture in she.Pictures)
-                            {
-                                pictures.Add(picture);
-                            }
+                        // 获取工作表中的所有图片
+                        List<Picture> pictures = new List<Picture>();
+                        foreach (Aspose.Cells.Drawing.Picture picture in she.Pictures)
+                        {
+                            pictures.Add(picture);
+                        }
 
-                            // 获取使用的行数
-                            int totalRows = she.Cells.MaxDataRow + 1;
-                            int imageIndex = 1;
+                        // 获取使用的行数
+                        int totalRows = she.Cells.MaxDataRow + 1;
+                        int imageIndex = 1;
 
-                            // 每40行生成一张图片
-                            for (int startRow = 0; startRow < totalRows; startRow += 40)
+                        // 每40行生成一张图片
+                        for (int startRow = 0; startRow < totalRows; startRow += int.Parse(RowCount.Value.ToString()))
+                        {
+                            int endRow = Math.Min(startRow + int.Parse(RowCount.Value.ToString()) - 1, totalRows - 1);
+                            // 创建图片选项
+                            ImageOrPrintOptions options = new ImageOrPrintOptions();
+                            options.ImageFormat = ImageFormat.Png;
+                            options.OnePagePerSheet = false;
+                            options.PrintingPage = PrintingPageType.IgnoreBlank;
+
+                            she.PageSetup.PrintArea = $"A{startRow + 1}:{lastColLetter}{endRow + 1}";
+                            if (File.Exists(PrintPath.Text))
                             {
-                                int endRow = Math.Min(startRow + 39, totalRows - 1);
-                                // 创建图片选项
-                                ImageOrPrintOptions options = new ImageOrPrintOptions();
-                                options.ImageFormat = ImageFormat.Png;
-                                options.OnePagePerSheet = false;
-                                options.PrintingPage = PrintingPageType.IgnoreBlank;
-
-                                she.PageSetup.PrintArea = $"A{startRow + 1}:AH{endRow + 1}";
-                                if (File.Exists(PrintPath.Text))
-                                {
-                                    //she.Pictures.Add(int.Parse(X.Value.ToString()), int.Parse(Y.Value.ToString()), PrintPath.Text);
-                                    she.Pictures.Add(startRow + int.Parse(Y.Value.ToString()), int.Parse(X.Value.ToString()), PrintPath.Text);
-                                }
-                                // 创建SheetRender对象
-                                SheetRender sr = new SheetRender(she, options);
-
-                                string imagename = $"{she.Name}_{imageIndex}.png";
-                                // 获取渲染后的图像
-                                Bitmap bitmap = sr.ToImage(0);
-                                string imagePath = "";
-                                // 如果有图片在当前行范围内,将它们添加到最终图像中
-                                if (pictures.Count > 0)
-                                {
-                                    using (Bitmap finalImage = new Bitmap(bitmap.Width, bitmap.Height))
-                                    using (Graphics g = Graphics.FromImage(finalImage))
-                                    {
-                                        // 绘制Excel内容
-                                        g.DrawImage(bitmap, 0, 0);
-
-                                        // 绘制原始Excel中的图片
-                                        int yOffset = bitmap.Height;
-                                        // 保存图像
-                                        imagePath = Path.Combine(path, $"{she.Name}_{imageIndex}.png");
-                                        finalImage.Save(imagePath, ImageFormat.Png);
-                                        Console.WriteLine($"Saved: {imagePath}");
-                                    }
-                                }
-                                else
+                                //if (startRow == 0)
+                                //{
+                                she.Pictures.Add(startRow + int.Parse(Y.Value.ToString()), int.Parse(X.Value.ToString()), PrintPath.Text);
+                                //}
+                            }
+                            // 创建SheetRender对象
+                            SheetRender sr = new SheetRender(she, options);
+
+                            string imagename = $"{she.Name}_{imageIndex}.png";
+                            // 获取渲染后的图像
+                            Bitmap bitmap = sr.ToImage(0);
+                            string imagePath = "";
+                            // 如果有图片在当前行范围内,将它们添加到最终图像中
+                            if (pictures.Count > 0)
+                            {
+                                using (Bitmap finalImage = new Bitmap(bitmap.Width, bitmap.Height))
+                                using (Graphics g = Graphics.FromImage(finalImage))
                                 {
-                                    // 如果没有图片,直接保存渲染的图像
+                                    // 绘制Excel内容
+                                    g.DrawImage(bitmap, 0, 0);
+
+                                    // 绘制原始Excel中的图片
+                                    int yOffset = bitmap.Height;
+                                    // 保存图像
                                     imagePath = Path.Combine(path, $"{she.Name}_{imageIndex}.png");
-                                    bitmap.Save(imagePath, ImageFormat.Png);
+                                    finalImage.Save(imagePath, ImageFormat.Png);
                                     Console.WriteLine($"Saved: {imagePath}");
                                 }
-                                imageIndex++;
-                                OperatResult.AppendText("解析图片【" + imagePath + ".jpg】" + "\n");
-                                Dictionary<string, object> dic = new Dictionary<string, object>();
-                                dic.Add("em_name", "管理员");
-                                dic.Add("em_code", "ADMIN");
-                                dic.Add("caller", "ProductSOP");
-                                OperatResult.AppendText("上传文件【" + imagePath + ".jpg" + "】\n");
-                                string fp_id = UploadFilesToRemoteUrl("http://172.16.1.80:8099/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + ps_prodcode.Text + @"\" + imagename, dic);
-                                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");
                             }
+                            else
+                            {
+                                // 如果没有图片,直接保存渲染的图像
+                                imagePath = Path.Combine(path, $"{she.Name}_{imageIndex}.png");
+                                bitmap.Save(imagePath, ImageFormat.Png);
+                                Console.WriteLine($"Saved: {imagePath}");
+                            }
+                            imageIndex++;
+                            OperatResult.AppendText("解析图片【" + imagePath + ".jpg】" + "\n");
+                            Dictionary<string, object> dic = new Dictionary<string, object>();
+                            dic.Add("em_name", "管理员");
+                            dic.Add("em_code", "ADMIN");
+                            dic.Add("caller", "ProductSOP");
+                            OperatResult.AppendText("上传文件【" + imagePath + ".jpg" + "】\n");
+                            string fp_id = UploadFilesToRemoteUrl("http://172.16.1.80:8099/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + ps_prodcode.Text + @"\" + imagename, dic);
+                            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");
                         }
-                        catch (Exception ex)
-                        {
-                            OperatResult.AppendText(ex.Message + ex.StackTrace);
-                        }
-                        filename.Add(she.Name + ".jpg");
                     }
+                    catch (Exception ex)
+                    {
+                        OperatResult.AppendText(ex.Message + ex.StackTrace);
+                    }
+                    filename.Add(she.Name + ".jpg");
                 }
             }
         }