callm 6 mesiacov pred
rodič
commit
a9b0fc2bfe

+ 60 - 24
FileWatcher/AutoAnalysisXml.cs

@@ -104,7 +104,7 @@ namespace FileWatcher
             {
                 if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
                     dh = new DataHelper();
                 }
             }
@@ -142,7 +142,7 @@ namespace FileWatcher
             {
                 if (Master.Text == DB.Rows[i]["ma_user"].ToString())
                 {
-                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=DGW;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+                    DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
                     dh = new DataHelper();
                     LogicHandler.dh = new DataHelper();
                 }
@@ -183,35 +183,38 @@ namespace FileWatcher
             List<string> badprod = new List<string>();
             if (Device.Text == "AOI设备")
             {
-                StreamReader sR = File.OpenText(FileName);
-
                 DataTable filedt = new DataTable();
-                //文件内的行,用一个DataTable存储
-                int Rowindex = 0;
-                while ((nextLine = sR.ReadLine()) != null)
+                using (StreamReader sR = File.OpenText(FileName))
                 {
-                    //DataTable用第一行的数据作为列名
-                    string[] title = nextLine.Split(',');
-                    DataRow dr = filedt.NewRow();
-                    for (int i = 0; i < title.Length; i++)
+
+                    //文件内的行,用一个DataTable存储
+                    int Rowindex = 0;
+                    while ((nextLine = sR.ReadLine()) != null)
                     {
-                        if (Rowindex == 0)
+                        //DataTable用第一行的数据作为列名
+                        string[] title = nextLine.Split(',');
+                        DataRow dr = filedt.NewRow();
+                        for (int i = 0; i < title.Length; i++)
                         {
-                            filedt.Columns.Add(title[i]);
+                            if (Rowindex == 0)
+                            {
+                                filedt.Columns.Add(title[i]);
+                            }
+                            else
+                            {
+                                dr[filedt.Columns[i].ColumnName] = title[i];
+                            }
                         }
-                        else
+                        //除了第一行,然后添加到表格中
+                        if (Rowindex > 0)
                         {
-                            dr[filedt.Columns[i].ColumnName] = title[i];
+                            filedt.Rows.Add(dr);
                         }
+                        Rowindex = Rowindex + 1;
                     }
-                    //除了第一行,然后添加到表格中
-                    if (Rowindex > 0)
-                    {
-                        filedt.Rows.Add(dr);
-                    }
-                    Rowindex = Rowindex + 1;
+                    sR.Close();
                 }
-                sR.Close();
+
                 string SN = FileName.Substring(FileName.LastIndexOf(@"\") + 1).Replace("-", "/").ToUpper().Replace(".TXT", "");
                 string Result = "OK";
                 string makecode = "";
@@ -324,12 +327,13 @@ namespace FileWatcher
                                     try
                                     {
                                         string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
-                                        ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
+                                        //ftp.UpLoadFile(folderpath, SN + ".txt", ftppath, "");
                                         int num = int.Parse(dh.ExecuteSql("insert into STEPTESTDETAIL (std_id,std_sn,std_makecode,std_indate,std_class)select STEPTESTDETAIL_seq.nextval,ms_sncode,ms_makecode,sysdate,'http://113.98.196.181:8099/ftp" + ftppath + SN + ".txt" + "' from makeserial where substr(ms_sncode,0,12)='" + SN + "'", "insert").ToString());
                                         if (num > 0)
                                         {
                                             OperateResult.AppendText("序列号:" + SN + "上传成功\n");
-                                            File.Delete(FileName);
+                                            SafeDeleteFile(FileName);
+                                            //File.Delete(FileName);
                                         }
                                         else
                                         {
@@ -424,6 +428,38 @@ namespace FileWatcher
                 }
             }
         }
+
+        private void SafeDeleteFile(string filePath)
+        {
+            try
+            {
+                // 先移除只读属性(如果有)
+                File.SetAttributes(filePath, FileAttributes.Normal);
+
+                // 尝试删除
+                File.Delete(filePath);
+            }
+            catch (IOException)
+            {
+                // 文件可能被占用,等待并重试
+                for (int i = 0; i < 3; i++) // 最多重试3次
+                {
+                    try
+                    {
+                        Thread.Sleep(500); // 等待500毫秒
+                        File.Delete(filePath);
+                        return;
+                    }
+                    catch { }
+                }
+                // 如果仍然失败,记录错误
+                OperateResult.AppendText($"无法删除文件: {filePath}\n");
+            }
+            catch (UnauthorizedAccessException ex)
+            {
+                OperateResult.AppendText($"权限不足,无法删除文件: {filePath}\n错误信息: {ex.Message}\n");
+            }
+        }
         /// <summary>
         /// 使用进程处理文件,避免界面假死
         /// </summary>

+ 16 - 3
FileWatcher/DataHelper.cs

@@ -13,10 +13,23 @@ namespace FileWatcher
         ////用户选择的数据库的连接字符串
         //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=YD_CYZZ;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11701)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
-        //HY
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
+        //PNE
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11665)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.81.208)(PORT=11665)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
+
+        ////HG
+        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        ////用户选择的数据库的连接字符串
+        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1520)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+
+
+        ////HY
+        //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        ////用户选择的数据库的连接字符串
+        //public static string DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.253)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
 
         ////KS
         //private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=N_MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.3.7)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";

+ 48 - 1
FileWatcher/FileWatcher.csproj

@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>FileWatcher</RootNamespace>
     <AssemblyName>FileWatcher</AssemblyName>
-    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <PublishUrl>publish\</PublishUrl>
     <Install>true</Install>
@@ -53,6 +53,18 @@
     <Reference Include="Aspose.Cells">
       <HintPath>tool\Aspose.Cells.dll</HintPath>
     </Reference>
+    <Reference Include="EPPlus, Version=8.0.5.0, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
+      <HintPath>..\packages\EPPlus.8.0.5\lib\net35\EPPlus.dll</HintPath>
+    </Reference>
+    <Reference Include="EPPlus.Interfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=a694d7f3b0907a61, processorArchitecture=MSIL">
+      <HintPath>..\packages\EPPlus.Interfaces.8.0.0\lib\net35\EPPlus.Interfaces.dll</HintPath>
+    </Reference>
+    <Reference Include="ExcelNumberFormat, Version=1.1.0.0, Culture=neutral, PublicKeyToken=23c6f5d73be07eca, processorArchitecture=MSIL">
+      <HintPath>..\packages\ExcelNumberFormat.1.1.0\lib\net20\ExcelNumberFormat.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Bcl.HashCode.1.1.1\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.Office.Interop.Excel, Version=10.0.4504.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
       <SpecificVersion>False</SpecificVersion>
       <EmbedInteropTypes>True</EmbedInteropTypes>
@@ -78,8 +90,33 @@
       <HintPath>tool\Oracle.ManagedDataAccess.dll</HintPath>
     </Reference>
     <Reference Include="PresentationCore" />
+    <Reference Include="PresentationFramework" />
+    <Reference Include="RBush, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c77e27b81f4d0187, processorArchitecture=MSIL">
+      <HintPath>..\packages\RBush.Signed.4.0.0\lib\net47\RBush.dll</HintPath>
+    </Reference>
+    <Reference Include="SixLabors.Fonts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13, processorArchitecture=MSIL">
+      <HintPath>..\packages\SixLabors.Fonts.1.0.0\lib\netstandard2.0\SixLabors.Fonts.dll</HintPath>
+    </Reference>
+    <Reference Include="Spire.XLS">
+      <HintPath>tool\Spire.XLS.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
+    <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
+    </Reference>
+    <Reference Include="System.configuration" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Numerics" />
+    <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Security" />
     <Reference Include="System.Web" />
     <Reference Include="System.Web.Extensions" />
     <Reference Include="System.Xml.Linq" />
@@ -94,6 +131,7 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>bin\Debug\UMESDLLService.dll</HintPath>
     </Reference>
+    <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AutoAnalysisDeviceKS.cs">
@@ -108,6 +146,12 @@
     <Compile Include="AutoAnalysisXLSJC.Designer.cs">
       <DependentUpon>AutoAnalysisXLSJC.cs</DependentUpon>
     </Compile>
+    <Compile Include="SOP_PNE.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="SOP_PNE.Designer.cs">
+      <DependentUpon>SOP_PNE.cs</DependentUpon>
+    </Compile>
     <Compile Include="UploadMakePlan.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -297,6 +341,9 @@
       <DependentUpon>AutoAnalysisXLSJC.cs</DependentUpon>
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="SOP_PNE.resx">
+      <DependentUpon>SOP_PNE.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="UploadMakePlan.resx">
       <DependentUpon>UploadMakePlan.cs</DependentUpon>
     </EmbeddedResource>

+ 92 - 11
FileWatcher/Form4.cs

@@ -1,4 +1,7 @@
-using NPOI.HSSF.UserModel;
+using Aspose.Cells;
+using Aspose.Cells.Drawing;
+using Aspose.Cells.Rendering;
+using NPOI.HSSF.UserModel;
 using NPOI.SS.UserModel;
 using NPOI.XSSF.UserModel;
 using System;
@@ -6,6 +9,7 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
+using System.Drawing.Imaging;
 using System.IO;
 using System.Linq;
 using System.Net;
@@ -44,18 +48,95 @@ namespace FileWatcher
         Thread InitDB3;
         DataTable dt;
         //DataHelper dh = new DataHelper();
-       
+
+        public void ConvertExcelToImages(string excelFilePath, string outputFolder)
+        {
+            // 确保输出目录存在
+            if (!Directory.Exists(outputFolder))
+            {
+                Directory.CreateDirectory(outputFolder);
+            }
+
+            // 加载Excel工作簿
+            Workbook workbook = new Workbook(excelFilePath);
+
+            // 处理每个工作表
+            foreach (Worksheet worksheet in workbook.Worksheets)
+            {
+                ProcessWorksheet(worksheet, outputFolder);
+            }
+        }
+
+        private void ProcessWorksheet(Worksheet worksheet, string outputFolder)
+        {
+            // 获取工作表中的所有图片
+            List<Picture> pictures = new List<Picture>();
+            foreach (Picture picture in worksheet.Pictures)
+            {
+                pictures.Add(picture);
+            }
+
+            // 获取使用的行数
+            int totalRows = worksheet.Cells.MaxDataRow + 1;
+            int imageIndex = 1;
+
+            // 每30行生成一张图片
+            for (int startRow = 0; startRow < totalRows; startRow += 30)
+            {
+                int endRow = Math.Min(startRow + 29, totalRows - 1);
+
+                // 创建图片选项
+                ImageOrPrintOptions options = new ImageOrPrintOptions();
+                options.ImageFormat = ImageFormat.Png;
+                options.OnePagePerSheet = false;
+                options.PrintingPage = PrintingPageType.IgnoreBlank;
+
+                worksheet.PageSetup.PrintArea = $"A{startRow + 1}:AC{endRow + 1}";
+                // 设置只渲染指定的行范围
+
+                // 创建SheetRender对象
+                SheetRender sr = new SheetRender(worksheet, options);
+
+                // 获取渲染后的图像
+                Bitmap bitmap = sr.ToImage(0);
+
+                // 如果有图片在当前行范围内,将它们添加到最终图像中
+                if (pictures.Count > 0)
+                {
+                    using (Bitmap finalImage = new Bitmap(bitmap.Width+100, bitmap.Height ))
+                    using (Graphics g = Graphics.FromImage(finalImage))
+                    {
+                        // 绘制Excel内容
+                        g.DrawImage(bitmap, 0, 0);
+
+                        // 绘制原始Excel中的图片
+                        int yOffset = bitmap.Height;
+                        // 保存图像
+                        string imagePath = Path.Combine(outputFolder, $"{worksheet.Name}_{imageIndex}.png");
+                        finalImage.Save(imagePath, ImageFormat.Png);
+                        Console.WriteLine($"Saved: {imagePath}");
+                    }
+                }
+                else
+                {
+                    // 如果没有图片,直接保存渲染的图像
+                    string imagePath = Path.Combine(outputFolder, $"{worksheet.Name}_{imageIndex}.png");
+                    bitmap.Save(imagePath, ImageFormat.Png);
+                    Console.WriteLine($"Saved: {imagePath}");
+                }
+
+                imageIndex++;
+            }
+        }
+
         private void Form4_Load(object sender, EventArgs e)
         {
-            dt = ExcelToDataTable(@"C:\Users\callm\Desktop\Autosave\Vortex-ICC ID数据库1.xlsx", true);
-            InitDB = new Thread(ConnectDB);
-            InitDB.Start();
-            InitDB1 = new Thread(ConnectDB1);
-            InitDB1.Start();
-            InitDB2 = new Thread(ConnectDB2);
-            InitDB2.Start();
-            InitDB3 = new Thread(ConnectDB3);
-            InitDB3.Start();
+            string excelFilePath = @"C:\Users\callm\Desktop\新建文件夹 (4)\P802 作业指导书 .xls";
+            string outputFolder = @"C:\output\images";
+
+            ConvertExcelToImages(excelFilePath, outputFolder);
+            //Console.WriteLine("转换完成。按任意键退出。");
+            //Console.ReadKey();
         }
 
         private void ConnectDB()

+ 2 - 2
FileWatcher/Program.cs

@@ -47,9 +47,9 @@ namespace FileWatcher
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                 {
                     //Application.Run(new AutoAnalysisDeviceKS());
-                    Application.Run(new AutoMakeQTY());
+                    //Application.Run(new Form4());
                     //Application.Run(new AutoAnalysisXmlByStep());
-                    //Application.Run(new SOP("", ""));
+                    Application.Run(new SOP_PNE("", ""));
                     //Application.Run(new AutoMakeQTY());
                 }
                 else

+ 247 - 0
FileWatcher/SOP_PNE.Designer.cs

@@ -0,0 +1,247 @@
+namespace FileWatcher
+{
+    partial class SOP_PNE
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+            this.ChoosePath = new System.Windows.Forms.OpenFileDialog();
+            this.label1 = new System.Windows.Forms.Label();
+            this.FilePath = new System.Windows.Forms.TextBox();
+            this.ChooseFile = new System.Windows.Forms.Button();
+            this.UploadSOP = new System.Windows.Forms.Button();
+            this.pr_code = new System.Windows.Forms.TextBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.OperatResult = new System.Windows.Forms.RichTextBox();
+            this.SendSop = new System.Windows.Forms.Button();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.pr_detail = new System.Windows.Forms.Label();
+            this.JPG = new System.Windows.Forms.RadioButton();
+            this.PDF = new System.Windows.Forms.RadioButton();
+            this.pr_spec = new System.Windows.Forms.RichTextBox();
+            this.SuspendLayout();
+            // 
+            // richTextBox1
+            // 
+            this.richTextBox1.Location = new System.Drawing.Point(-43, -88);
+            this.richTextBox1.Name = "richTextBox1";
+            this.richTextBox1.Size = new System.Drawing.Size(100, 96);
+            this.richTextBox1.TabIndex = 5;
+            this.richTextBox1.Text = "";
+            // 
+            // ChoosePath
+            // 
+            this.ChoosePath.FileName = "ChoosePath";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label1.Location = new System.Drawing.Point(19, 448);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(146, 41);
+            this.label1.TabIndex = 6;
+            this.label1.Text = "SOP文件";
+            // 
+            // FilePath
+            // 
+            this.FilePath.Enabled = false;
+            this.FilePath.Location = new System.Drawing.Point(218, 453);
+            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(218, 611);
+            this.ChooseFile.Name = "ChooseFile";
+            this.ChooseFile.Size = new System.Drawing.Size(160, 42);
+            this.ChooseFile.TabIndex = 8;
+            this.ChooseFile.Text = "选择文件";
+            this.ChooseFile.UseVisualStyleBackColor = true;
+            this.ChooseFile.Click += new System.EventHandler(this.ChooseFile_Click);
+            // 
+            // UploadSOP
+            // 
+            this.UploadSOP.Location = new System.Drawing.Point(424, 611);
+            this.UploadSOP.Name = "UploadSOP";
+            this.UploadSOP.Size = new System.Drawing.Size(160, 42);
+            this.UploadSOP.TabIndex = 9;
+            this.UploadSOP.Text = "上传文件";
+            this.UploadSOP.UseVisualStyleBackColor = true;
+            this.UploadSOP.Click += new System.EventHandler(this.UploadSOP_Click);
+            // 
+            // pr_code
+            // 
+            this.pr_code.Location = new System.Drawing.Point(218, 152);
+            this.pr_code.Name = "pr_code";
+            this.pr_code.Size = new System.Drawing.Size(582, 35);
+            this.pr_code.TabIndex = 11;
+            this.pr_code.KeyDown += new System.Windows.Forms.KeyEventHandler(this.pr_code_KeyDown);
+            this.pr_code.Leave += new System.EventHandler(this.pr_code_Leave);
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label2.Location = new System.Drawing.Point(19, 147);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(146, 41);
+            this.label2.TabIndex = 10;
+            this.label2.Text = "产品编号";
+            // 
+            // OperatResult
+            // 
+            this.OperatResult.Location = new System.Drawing.Point(823, 32);
+            this.OperatResult.Name = "OperatResult";
+            this.OperatResult.Size = new System.Drawing.Size(1110, 874);
+            this.OperatResult.TabIndex = 12;
+            this.OperatResult.Text = "";
+            this.OperatResult.TextChanged += new System.EventHandler(this.OperatResult_TextChanged);
+            // 
+            // SendSop
+            // 
+            this.SendSop.Location = new System.Drawing.Point(640, 611);
+            this.SendSop.Name = "SendSop";
+            this.SendSop.Size = new System.Drawing.Size(160, 42);
+            this.SendSop.TabIndex = 13;
+            this.SendSop.Text = "广播SOP";
+            this.SendSop.UseVisualStyleBackColor = true;
+            this.SendSop.Click += new System.EventHandler(this.SendSop_Click);
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label3.Location = new System.Drawing.Point(19, 240);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(146, 41);
+            this.label3.TabIndex = 14;
+            this.label3.Text = "产品名称";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label4.Location = new System.Drawing.Point(19, 333);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(146, 41);
+            this.label4.TabIndex = 15;
+            this.label4.Text = "产品规格";
+            // 
+            // pr_detail
+            // 
+            this.pr_detail.AutoSize = true;
+            this.pr_detail.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_detail.Location = new System.Drawing.Point(211, 240);
+            this.pr_detail.Name = "pr_detail";
+            this.pr_detail.Size = new System.Drawing.Size(0, 41);
+            this.pr_detail.TabIndex = 16;
+            // 
+            // JPG
+            // 
+            this.JPG.AutoSize = true;
+            this.JPG.Checked = true;
+            this.JPG.Location = new System.Drawing.Point(251, 534);
+            this.JPG.Name = "JPG";
+            this.JPG.Size = new System.Drawing.Size(89, 28);
+            this.JPG.TabIndex = 18;
+            this.JPG.TabStop = true;
+            this.JPG.Text = "图片";
+            this.JPG.UseVisualStyleBackColor = true;
+            // 
+            // PDF
+            // 
+            this.PDF.AutoSize = true;
+            this.PDF.Location = new System.Drawing.Point(382, 534);
+            this.PDF.Name = "PDF";
+            this.PDF.Size = new System.Drawing.Size(77, 28);
+            this.PDF.TabIndex = 18;
+            this.PDF.TabStop = true;
+            this.PDF.Text = "PDF";
+            this.PDF.UseVisualStyleBackColor = true;
+            // 
+            // pr_spec
+            // 
+            this.pr_spec.Enabled = false;
+            this.pr_spec.Location = new System.Drawing.Point(218, 341);
+            this.pr_spec.Name = "pr_spec";
+            this.pr_spec.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
+            this.pr_spec.Size = new System.Drawing.Size(580, 94);
+            this.pr_spec.TabIndex = 19;
+            this.pr_spec.Text = "";
+            // 
+            // SOP
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1945, 934);
+            this.Controls.Add(this.pr_spec);
+            this.Controls.Add(this.PDF);
+            this.Controls.Add(this.JPG);
+            this.Controls.Add(this.pr_detail);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.SendSop);
+            this.Controls.Add(this.OperatResult);
+            this.Controls.Add(this.pr_code);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.UploadSOP);
+            this.Controls.Add(this.ChooseFile);
+            this.Controls.Add(this.FilePath);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.richTextBox1);
+            this.MaximizeBox = false;
+            this.Name = "SOP";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "SOP管理";
+            this.Load += new System.EventHandler(this.Form3_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.RichTextBox richTextBox1;
+        private System.Windows.Forms.OpenFileDialog ChoosePath;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.TextBox FilePath;
+        private System.Windows.Forms.Button ChooseFile;
+        private System.Windows.Forms.Button UploadSOP;
+        private System.Windows.Forms.TextBox pr_code;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.RichTextBox OperatResult;
+        private System.Windows.Forms.Button SendSop;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.Label pr_detail;
+        private System.Windows.Forms.RadioButton JPG;
+        private System.Windows.Forms.RadioButton PDF;
+        private System.Windows.Forms.RichTextBox pr_spec;
+    }
+}

+ 408 - 0
FileWatcher/SOP_PNE.cs

@@ -0,0 +1,408 @@
+using System;
+using System.IO;
+using System.Text;
+using System.Windows.Forms;
+using Spire.Xls;
+using System.Net;
+using System.Collections.Generic;
+using System.Threading;
+using System.Net.Sockets;
+using System.Data;
+using System.Web.Script.Serialization;
+
+namespace FileWatcher
+{
+    public partial class SOP_PNE : Form
+    {
+        DataHelper dh = new DataHelper();
+
+        string usercode;
+        string sourcecode;
+
+        public SOP_PNE(string iUserCode, string iSource)
+        {
+            usercode = iUserCode;
+            sourcecode = iSource;
+            InitializeComponent();
+        }
+
+        private void Form3_Load(object sender, EventArgs e)
+        {
+            CheckForIllegalCrossThreadCalls = false;
+        }
+
+        void uploadfile()
+        {
+            pr_code.Text = FilePath.Text.Substring(FilePath.Text.LastIndexOf(@"\") + 1).Replace(".xls", "").Replace(".xlsx", "");
+            pr_code_Leave(new object(), new EventArgs());
+            DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where instr('" + pr_code.Text + "',ps_prodcode)>0 ", "select");
+            if (dt.Rows.Count == 0)
+            {
+                DataTable dt1 = (DataTable)dh.ExecuteSql("select pr_code from product where instr('" + pr_code.Text + "',pr_code)>0", "select");
+                if (dt1.Rows.Count > 0)
+                {
+                    string code = LogicHandler.GetPiInoutCode("ProductSOP", "1");
+                    pr_code.Text = dt1.Rows[0]["pr_code"].ToString();
+                    dh.ExecuteSql("insert into productsop(ps_id,ps_code,ps_prodcode,ps_indate,ps_inman)values(productsop_seq.nextval,'" + code + "','" + pr_code.Text + "',sysdate,'" + usercode + "')", "insert");
+                }
+                else
+                {
+                    MessageBox.Show("产品编号" + pr_code.Text + "不存在");
+                    return;
+                }
+            }
+            else
+            {
+                pr_code.Text = dt.Rows[0]["ps_prodcode"].ToString();
+            }
+            Workbook workbook = new Workbook();
+            workbook.LoadFromFile(FilePath.Text);
+            workbook.ConverterSetting.JPEGQuality = 100;
+            workbook.ConverterSetting.XDpi = 600;
+            workbook.ConverterSetting.YDpi = 600;
+            List<Worksheet> list = new List<Worksheet>();
+            List<string> filename = new List<string>();
+            dh.ExecuteSql("update ProductSOP set ps_attachsop='' where ps_prodcode='" + pr_code.Text + "'", "update");
+            OperatResult.AppendText("一共Sheet: " + workbook.Worksheets.Count + "\n");
+            try
+            {
+                for (int i = 0; i < workbook.Worksheets.Count; i++)
+                {
+                    for (int k = 0; k < workbook.Worksheets[i].TextBoxes.Count; k++)
+                    {
+                        if (workbook.Worksheets[i].TextBoxes[k].RichText.Text.Length > 1)
+                        {
+                            //OperatResult.AppendText(workbook.Worksheets[i].TextBoxes[k].ID + " " + workbook.Worksheets[i].TextBoxes[k].Name + " " + workbook.Worksheets[i].TextBoxes[k].RichText.GetFont(0).FontName + " " + workbook.Worksheets[i].TextBoxes[k].RichText.GetFont(0).Size);
+                            workbook.Worksheets[i].TextBoxes[k].RichText.Text = workbook.Worksheets[i].TextBoxes[k].RichText.Text;
+                            workbook.Worksheets[i].TextBoxes[k].Width = workbook.Worksheets[i].TextBoxes[k].Width * 2;
+                            workbook.Worksheets[i].TextBoxes[k].Height = workbook.Worksheets[i].TextBoxes[k].Height * 2;
+                            workbook.Worksheets[i].TextBoxes[k].HAlignment = CommentHAlignType.Center;
+                        }
+                    }
+                    Workbook bw = new Workbook();
+                    Worksheet she = bw.CreateEmptySheet();
+                    she.Name = workbook.Worksheets[i].Name;
+                    she.CopyFrom(workbook.Worksheets[i]);
+                    if (JPG.Checked)
+                    {
+                        var myThread = new Thread(() => SaveFileToJPG(she));
+                        myThread.Start();
+                        filename.Add(she.Name + ".jpg");
+                    }
+                    else
+                    {
+                        var myThread = new Thread(() => SaveFileToPDF(she));
+                        myThread.Start();
+                        filename.Add(she.Name + ".pdf");
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                OperatResult.AppendText(ex.Message + "\n");
+            }
+        }
+
+        private void SaveFileToPDF(Worksheet sheet)
+        {
+            if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
+            {
+                Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
+            }
+            sheet.SaveToPdf(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf");
+            OperatResult.AppendText("解析PDF【" + sheet.Name + ".pdf】" + "\n");
+            Dictionary<string, object> dic = new Dictionary<string, object>();
+            dic.Add("em_name", "管理员");
+            dic.Add("em_code", "ADMIN");
+            dic.Add("caller", "ProductSOP");
+            OperatResult.AppendText("上传文件【" + sheet.Name + ".pdf" + "】\n");
+            string fp_id = UploadFilesToRemoteUrl("http://erp.ubtob.net:11773/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf", dic);
+            if (fp_id != "")
+            {
+                dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
+            }
+        }
+
+        private void SaveFileToJPG(Worksheet sheet)
+        {
+            try
+            {
+                if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
+                {
+                    Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
+                }
+                ExcelPicture picture = sheet.Pictures.Add(@"图片\电子受控章.png");
+                picture.Width = 113;
+                picture.Height = 38;
+                picture.LeftColumn = 20;
+                picture.TopRowOffset = 20;
+                ExcelPicture picture1 = sheet.Pictures.Add(@"图片\签名.png");
+                picture1.Width = 100;
+                picture1.Height = 38;
+                picture1.LeftColumn = 15;
+                picture1.TopRowOffset = 600;
+                sheet.SaveToImage(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg");
+                OperatResult.AppendText("解析图片【" + sheet.Name + ".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("上传文件【" + sheet.Name + ".jpg" + "】\n");
+                string fp_id = UploadFilesToRemoteUrl("http://erp.ubtob.net:11773/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg", dic);
+                if (fp_id != "")
+                {
+                    dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 请求上传图片到阿里云
+        /// </summary>
+        /// <param name="url">上传地址</param>
+        /// <param name="filepath">本地文件路径</param>
+        /// <param name="dic">上传的数据信息</param>
+        /// <returns></returns>
+        public string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic)
+        {
+            try
+            {
+                ServicePointManager.DefaultConnectionLimit = 50;
+
+                string boundary = DateTime.Now.Ticks.ToString("x");
+
+                byte[] boundarybytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "\r\n");
+
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url1);
+                request.Method = "POST";
+                request.Timeout = 10 * 10000;
+                request.ContentType = "multipart/form-data; boundary=" + boundary;
+
+                Stream rs = request.GetRequestStream();
+
+                var endBoundaryBytes = Encoding.UTF8.GetBytes("--" + boundary + "--\r\n");
+
+                string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n" + "\r\n" + "{1}" + "\r\n";
+                if (dic != null)
+                {
+                    foreach (string key in dic.Keys)
+                    {
+                        rs.Write(boundarybytes, 0, boundarybytes.Length);
+
+                        string formitem = string.Format(formdataTemplate, key, dic[key]);
+
+                        byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
+
+                        rs.Write(formitembytes, 0, formitembytes.Length);
+                    }
+
+                }
+
+                string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n\r\n";
+                {
+                    rs.Write(boundarybytes, 0, boundarybytes.Length);
+
+                    var header = string.Format(headerTemplate, "file", Path.GetFileName(filepath));
+
+                    var headerbytes = System.Text.Encoding.UTF8.GetBytes(header);
+
+                    rs.Write(headerbytes, 0, headerbytes.Length);
+
+                    using (var fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read))
+                    {
+                        var buffer = new byte[1024];
+
+                        var bytesRead = 0;
+
+                        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
+                        {
+                            rs.Write(buffer, 0, bytesRead);
+                        }
+                    }
+                    var cr = Encoding.UTF8.GetBytes("\r\n");
+
+                    rs.Write(cr, 0, cr.Length);
+                }
+
+                rs.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
+
+                var response = request.GetResponse() as HttpWebResponse;
+
+                StreamReader newReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
+                string Content = newReader.ReadToEnd();
+                Dictionary<string, object> dic1 = new Dictionary<string, object>();
+                List<Dictionary<string, object>> dic2 = null;
+                dic1 = BaseUtil.ToDictionary(Content);
+                dic2 = dic1["data"] as List<Dictionary<string, object>>;
+                string fp_id = "";
+                if (dic2[0]["filepath"] != null)
+                {
+                    fp_id = dic2[0]["filepath"].ToString();
+                }
+                if (response.StatusCode == HttpStatusCode.OK)
+                {
+                    return fp_id;
+                }
+            }
+            catch (Exception e)
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP", "上传失败", pr_code.Text, "");
+                Console.WriteLine(e.Message + e.StackTrace);
+            }
+            return "";
+        }
+
+        private void ChooseFile_Click(object sender, EventArgs e)
+        {
+            ChoosePath.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx";
+            DialogResult result = ChoosePath.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                FilePath.Text = ChoosePath.FileName;
+            }
+        }
+
+        private void UploadSOP_Click(object sender, EventArgs e)
+        {
+            Thread thread = new Thread(uploadfile);
+            SetLoadingWindow stw = new SetLoadingWindow(thread, "上传文件");
+            stw.StartPosition = FormStartPosition.CenterScreen;
+            stw.ShowDialog();
+            if (JPG.Checked)
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【图片格式】", "上传成功", pr_code.Text, "");
+            }
+            else
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【PDF格式】", "上传成功", pr_code.Text, "");
+            }
+        }
+
+        private void OperatResult_TextChanged(object sender, EventArgs e)
+        {
+            //OperatResult.SelectionStart = Text.Length;
+            OperatResult.ScrollToCaret();
+        }
+
+        TcpServer tcpserver = new TcpServer();
+
+        private void SendSop_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
+                string IPAddress = "";
+                for (int i = 0; i < IpEntry.AddressList.Length; i++)
+                {
+                    if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
+                    {
+                        IPAddress = IpEntry.AddressList[i].ToString();
+                    }
+                }
+                dh.ExecuteSql("update SOPSOURCE set SS_BRDIP='" + IPAddress + "'", "update");
+                DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where ps_prodcode='" + pr_code.Text + "'", "select");
+                if (dt.Rows.Count > 0)
+                {
+                    tcpserver.Start();
+                    Thread.Sleep(5000);
+                    List<Dictionary<string, string>> listr = new List<Dictionary<string, string>>();
+                    string PS_ATTACHSOP = dt.Rows[0]["PS_ATTACHSOP"].ToString();
+                    PS_ATTACHSOP = PS_ATTACHSOP.Substring(0, PS_ATTACHSOP.Length - 1).Replace(";", ",");
+                    dt = (DataTable)dh.ExecuteSql("select fp_path, fp_name from filepath where fp_id in (" + PS_ATTACHSOP + ") and nvl(fp_path, ' ') <> ' '", "select");
+                    JavaScriptSerializer jss = new JavaScriptSerializer();
+                    Dictionary<string, object> map1 = new Dictionary<string, object>();
+                    Dictionary<string, object> map = new Dictionary<string, object>();
+                    string path;
+                    string pathroot = dh.GetConfig("filePathUrl", "sys").ToString();
+                    for (int i = 0; i < dt.Rows.Count; i++)
+                    {
+                        Dictionary<string, string> dic1 = new Dictionary<string, string>();
+                        path = dt.Rows[i]["fp_path"].ToString();
+                        path = encryptBASE64(path.Replace("/app/uas/webapps/postattach", pathroot)).Replace("\\s*|\r|\n|\t", "");
+                        dic1.Add("path", path);
+                        dic1.Add("filename", dt.Rows[i]["fp_name"].ToString().Replace(" ", "").Replace("(", "").Replace(")", ""));
+                        dic1.Add("ps_prodcode", pr_code.Text);
+                        listr.Add(dic1);
+                    }
+                    map1.Add("ps_code", "");
+                    map1.Add("url", listr);
+                    map.Add("success", true);
+                    map.Add("data", map1);
+                    tcpserver.Send(jss.Serialize(map));
+                    tcpserver.Stop();
+                    LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播成功", pr_code.Text, "");
+                    MessageBox.Show("产品编号" + pr_code.Text + "广播成功");
+                }
+                else
+                {
+                    MessageBox.Show("产品编号" + pr_code.Text + "未维护SOP文档");
+                    LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播失败,未维护SOP文档", pr_code.Text, "");
+                }
+            }
+            catch (Exception ex)
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播失败", pr_code.Text, "");
+                Console.WriteLine(ex.Message + ex.StackTrace);
+            }
+        }
+
+        public string encryptBASE64(string key)
+        {
+            byte[] bytes = Encoding.Default.GetBytes(key);
+            return Convert.ToBase64String(bytes);
+        }
+
+        public static string EncodeBase64(string code_type, string code)
+        {
+            string encode = "";
+            byte[] bytes = Encoding.GetEncoding(code_type).GetBytes(code);
+            try
+            {
+                encode = Convert.ToBase64String(bytes);
+            }
+            catch
+            {
+                encode = code;
+            }
+            return encode;
+        }
+
+        private void pr_code_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.KeyCode == Keys.Enter)
+            {
+                LoadPrCode();
+            }
+        }
+
+        private void LoadPrCode()
+        {
+            DataTable dt = (DataTable)dh.ExecuteSql("select pr_code,pr_spec,pr_detail from product where instr('" + pr_code.Text + "',pr_code)>0", "select");
+            if (dt.Rows.Count > 0)
+            {
+                pr_spec.Clear();
+                pr_spec.AppendText(dt.Rows[0]["pr_spec"].ToString());
+                pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
+                pr_code.Text = dt.Rows[0]["pr_code"].ToString();
+            }
+            else
+            {
+                MessageBox.Show("产品编号" + pr_code.Text + "不存在");
+            }
+        }
+
+        private void pr_code_Leave(object sender, EventArgs e)
+        {
+            LoadPrCode();
+        }
+
+        private void pr_spec_Click(object sender, EventArgs e)
+        {
+
+        }
+    }
+}

+ 138 - 0
FileWatcher/SOP_PNE.resx

@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="ChoosePath.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</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>

+ 25 - 13
FileWatcher/UploadMakePlan.cs

@@ -138,22 +138,34 @@ namespace FileWatcher
                                     if (!string.IsNullOrEmpty(wccode) && !string.IsNullOrEmpty(orderdetno) && !string.IsNullOrEmpty(ordercode))
                                     {
                                         string day = today.ToString("yyyy-MM-dd");
-                                        if (!dh.CheckExist("MakePlanDetail left join makeplan on mpd_mpid=mp_id ", "trunc(mp_begintime)=to_date('" + day + "','yyyy-mm-dd') and mpd_orderdetno='" + orderdetno + "' and mpd_ordercode='" + ordercode + "' and mpd_wccode='" + wccode + "'"))
+                                        if (dh.CheckExist("MakePlanDetail left join makeplan on mpd_mpid=mp_id ", "trunc(mp_begintime)=to_date('" + day + "','yyyy-mm-dd') and mpd_orderdetno='" + orderdetno + "' and mpd_ordercode='" + ordercode + "' and mpd_wccode='" + wccode + "'"))
                                         {
-                                            string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_detno,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty,mpd_remark) VALUES (" + id + "," + detno + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4,:5)";
-                                            using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
-                                            {
-                                                cmd.Parameters.Add(new OracleParameter(":1", wccode));
-                                                cmd.Parameters.Add(new OracleParameter(":2", orderdetno));
-                                                cmd.Parameters.Add(new OracleParameter(":3", ordercode));
-                                                cmd.Parameters.Add(new OracleParameter(":4", planqty));
-                                                cmd.Parameters.Add(new OracleParameter(":5", remark));
-                                                cmd.ExecuteNonQuery();
-                                            }
+                                            OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "' 工作中心'" + wccode + "' 重复");
+                                            return;
                                         }
-                                        else
+                                        //销售订单+订单序号存在ERP中,才允许上传
+                                        if (dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said", "SD_DETNO='" + orderdetno + "' and sa_code='" + ordercode + "'"))
                                         {
-                                            OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "' 工作中心'" + wccode + "' 重复");
+                                            OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'不存在");
+                                            return;
+                                        }
+                                        if (dh.CheckExist("saledetail@ERP left join sale@ERP on sa_id=sd_said left join (select min(mpd_outqty)mpd_outqty, mpd_ordercode," +
+                                            " mpd_orderdetno  from(select sum(mpd_outqty)mpd_outqty, mpd_ordercode, mpd_orderdetnofrom MakePlanDetail  group by " +
+                                            "mpd_ordercode, mpd_orderdetno, MPD_WCCODE)group by mpd_ordercode, mpd_orderdetno) on sa_code = mpd_ordercode and sd_detno" +
+                                            " = mpd_orderdetno", "sd_qty<mpd_outqty+" + planqty + " and sa_code='" + ordercode + "' and sd_detno='" + orderdetno + "'"))
+                                        {
+                                            OperateResult.AppendText(" 序号'" + orderdetno + "' 销售订单'" + ordercode + "'累计排产数量超出");
+                                            return;
+                                        }
+                                        string insertQuery = "INSERT INTO MakePlanDetail (mpd_mpid,mpd_detno,mpd_id,mpd_wccode, mpd_orderdetno, mpd_ordercode,mpd_outqty,mpd_remark) VALUES (" + id + "," + detno + ",MakePlanDetail_seq.nextval,:1, :2, :3,:4,:5)";
+                                        using (OracleCommand cmd = new OracleCommand(insertQuery, conn))
+                                        {
+                                            cmd.Parameters.Add(new OracleParameter(":1", wccode));
+                                            cmd.Parameters.Add(new OracleParameter(":2", orderdetno));
+                                            cmd.Parameters.Add(new OracleParameter(":3", ordercode));
+                                            cmd.Parameters.Add(new OracleParameter(":4", planqty));
+                                            cmd.Parameters.Add(new OracleParameter(":5", remark));
+                                            cmd.ExecuteNonQuery();
                                         }
                                     }
                                 }

+ 23 - 2
FileWatcher/app.config

@@ -1,3 +1,24 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
+      </dependentAssembly>
+      <dependentAssembly>
+        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
+</configuration>

+ 4 - 1
FileWatcher/ftpOperater.cs

@@ -76,9 +76,12 @@ namespace FileWatcher
                             rs.Close();
                         }
                         fs.Close();
+                        fs.Dispose();
                     }
+                    file.Delete();
                 }
-                Thread.Sleep(1000);
+             
+                //Thread.Sleep(1000);
             }
             catch (Exception ex)
             {

+ 14 - 0
FileWatcher/packages.config

@@ -1,4 +1,18 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
   <package id="Aspose.Cells" version="23.10.0" targetFramework="net40" />
+  <package id="ClosedXML" version="0.105.0" targetFramework="net48" />
+  <package id="ClosedXML.Parser" version="2.0.0" targetFramework="net48" />
+  <package id="DocumentFormat.OpenXml" version="3.1.1" targetFramework="net48" />
+  <package id="DocumentFormat.OpenXml.Framework" version="3.1.1" targetFramework="net48" />
+  <package id="EPPlus" version="8.0.5" targetFramework="net40" requireReinstallation="true" />
+  <package id="EPPlus.Interfaces" version="8.0.0" targetFramework="net40" requireReinstallation="true" />
+  <package id="ExcelNumberFormat" version="1.1.0" targetFramework="net48" />
+  <package id="Microsoft.Bcl.HashCode" version="1.1.1" targetFramework="net48" />
+  <package id="RBush.Signed" version="4.0.0" targetFramework="net48" />
+  <package id="SixLabors.Fonts" version="1.0.0" targetFramework="net48" />
+  <package id="System.Buffers" version="4.5.1" targetFramework="net48" />
+  <package id="System.Memory" version="4.5.5" targetFramework="net48" />
+  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
+  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net48" />
 </packages>