Browse Source

解析程序提交

callm 4 years ago
parent
commit
2fd7554915

+ 1 - 1
FileAnalysis/DataHelper.cs

@@ -11,7 +11,7 @@ namespace FileAnalysis
         //系统默认的的连接字符串
         private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=SHENAI_EDCDATA;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.0.16)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString;
+        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=SHENAI_EDCDATA;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.0.16)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         public static OracleConnection connection = null;
         OracleCommand command = null;
         int ReconnectTime = 0;

+ 31 - 6
FileAnalysis/Form1.Designer.cs

@@ -28,9 +28,11 @@
         /// </summary>
         private void InitializeComponent()
         {
-            this.components = new System.ComponentModel.Container();
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
-            this.提示 = new System.Windows.Forms.NotifyIcon(this.components);
+            this.提示 = new System.Windows.Forms.NotifyIcon();
+            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
+            this.button2 = new System.Windows.Forms.Button();
+            this.timer1 = new System.Windows.Forms.Timer();
             this.SuspendLayout();
             // 
             // 提示
@@ -39,15 +41,35 @@
             this.提示.Text = "提示";
             this.提示.Visible = true;
             // 
+            // richTextBox1
+            // 
+            this.richTextBox1.Location = new System.Drawing.Point(12, 12);
+            this.richTextBox1.Name = "richTextBox1";
+            this.richTextBox1.Size = new System.Drawing.Size(544, 457);
+            this.richTextBox1.TabIndex = 0;
+            this.richTextBox1.Text = "";
+            // 
+            // button2
+            // 
+            this.button2.Location = new System.Drawing.Point(425, 479);
+            this.button2.Name = "button2";
+            this.button2.Size = new System.Drawing.Size(111, 35);
+            this.button2.TabIndex = 2;
+            this.button2.Text = "解析";
+            this.button2.UseVisualStyleBackColor = true;
+            this.button2.Visible = false;
+            this.button2.Click += new System.EventHandler(this.button2_Click);
+            // 
             // Form1
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(284, 261);
+            this.ClientSize = new System.Drawing.Size(568, 522);
+            this.Controls.Add(this.button2);
+            this.Controls.Add(this.richTextBox1);
+            this.Margin = new System.Windows.Forms.Padding(6);
             this.Name = "Form1";
-            this.ShowInTaskbar = false;
             this.Text = "Form1";
-            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
             this.Load += new System.EventHandler(this.Form1_Load);
             this.ResumeLayout(false);
 
@@ -56,6 +78,9 @@
         #endregion
 
         private System.Windows.Forms.NotifyIcon 提示;
+        private System.Windows.Forms.RichTextBox richTextBox1;
+        private System.Windows.Forms.Button button2;
+        private System.Windows.Forms.Timer timer1;
     }
 }
 

+ 171 - 2
FileAnalysis/Form1.cs

@@ -1,8 +1,12 @@
-using System;
+using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
+using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
+using System.Diagnostics;
 using System.Drawing;
+using System.IO;
 using System.Linq;
 using System.Net;
 using System.Net.Sockets;
@@ -24,7 +28,14 @@ namespace FileAnalysis
         private void Form1_Load(object sender, EventArgs e)
         {
             提示.ShowBalloonTip(30, "提示", "程序启动", ToolTipIcon.Info);
+            timer1.Interval = 1000 * 60 * 10;
+            timer1.Tick += Timer1_Tick;
+            timer1.Start();
+            Timer1_Tick(sender, e);
+        }
 
+        private void Timer1_Tick(object sender, EventArgs e)
+        {
             IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
             string IPAddress = "";
             for (int i = 0; i < IpEntry.AddressList.Length; i++)
@@ -32,10 +43,168 @@ namespace FileAnalysis
                 if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
                     IPAddress = IpEntry.AddressList[i].ToString();
             }
-        }
 
+            StringBuilder sql = new StringBuilder();
+            sql.Clear();
+            sql.Append("select * from(select chipcode_,to_char(createdate_,'yymmdd')cer_testdate,substr(ip,0,instr(ip,'/')-1)ip,localdatapath_,");
+            sql.Append("localpath_ from (select A.chipcode_,createdate_,replace(substr(localdatapath_,0,instr(localdatapath_,'$'))");
+            sql.Append(",'smb://@','') IP,localdatapath_,replace(replace(replace(substr(localdatapath_,instr(localdatapath_,'$')-1),'$',':'),'/','\\'),'\\\\','\\')  ");
+            sql.Append("localpath_ from datacenter$chip@SZSI_P A left join datacenter$mestemp@SZSI_P B on A.CHIPCODE_=B.chipcode_ ");
+            sql.Append("where nvl(readstatus_,0)=0) order by createdate_ desc) where ip= '" + IPAddress + "' and rownum<60");
+            DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
+            List<string> insertSQL = new List<string>();
+            for (int i = 0; i < dt.Rows.Count; i++)
+            {
+                FileStream fs = null;
+                IWorkbook workbook = null;
+                ISheet sheet = null;
+                string test = dt.Rows[i]["cer_testdate"].ToString();
+                string chipcode = dt.Rows[i]["chipcode_"].ToString();
+                string filepath = dt.Rows[i]["localpath_"].ToString();
+                //string filepath = @"c:\filewatcher\F20036121#07.xls";
+                try
+                {
+                    richTextBox1.AppendText(test + " " + dt.Rows[i]["localpath_"].ToString() + "\n");
+                    //如果文件不存在则调用转换
+                    if (!File.Exists(filepath))
+                    {
+                        filepath = filepath.Replace("xls", "jdf");
+                        if (!File.Exists(filepath))
+                        {
+                            filepath = filepath.Replace("jdf", "njdf");
+                        }
+                        if (filepath.Substring(filepath.LastIndexOf(".") + 1) == "jdf" || filepath.Substring(filepath.LastIndexOf(".") + 1) == "njdf")
+                        {
+                            if (!filepath.Contains("RECYCLE"))
+                            {
+                                string FullName = filepath;
+                                string Filename = FullName.Substring(FullName.LastIndexOf(@"\") + 1).Split('.')[0];
+                                string StartPath = FullName.Substring(0, FullName.LastIndexOf(@"\") + 1);
+                                if (File.Exists(FullName))
+                                {
+                                    richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.fff") + filepath + "\n");
+                                }
+                                else
+                                {
+                                    richTextBox1.AppendText("不存在文件" + FullName + "\n");
+                                }
+                                //不存在同名的文件则进行转换
+                                if (!File.Exists(StartPath + Filename + ".xls") && File.Exists(FullName))
+                                {
+                                    if (FullName.Substring(FullName.LastIndexOf(".") + 1) == "jdf")
+                                    {
+                                        exec(@"DTS-JDFData2Excel.exe", @"DTS-JDFData2Excel.exe " + FullName);
+                                    }
+                                    else if (FullName.Substring(FullName.LastIndexOf(".") + 1) == "njdf")
+                                    {
+                                        exec(@"DTS-Data2Excel.exe", @"DTS-Data2Excel.exe " + FullName);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                    //如果文件存在
+                    if (File.Exists(filepath))
+                    {
+                        using (fs = File.OpenRead(filepath))
+                        {
+                            workbook = new HSSFWorkbook(fs);
+                            sheet = workbook.GetSheet("Data");
 
+                            List<string> itemname = new List<string>();
+                            List<string> detno = new List<string>();
+                            List<string> bias1 = new List<string>();
+                            List<string> bias2 = new List<string>();
+                            List<string> bias3 = new List<string>();
+                            List<string> minlimit = new List<string>();
+                            List<string> maxlimit = new List<string>();
+                            List<string> avg = new List<string>();
+                            List<string> stdev = new List<string>();
+                            List<string> mindata = new List<string>();
+                            List<string> maxdata = new List<string>();
+                            for (int k = 1; k < sheet.GetRow(13).PhysicalNumberOfCells; k++)
+                            {
+                                itemname.Add(sheet.GetRow(13).GetCell(k + 1).StringCellValue.Split(' ')[1]);
+                                bias1.Add(sheet.GetRow(14).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                bias2.Add(sheet.GetRow(15).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                bias3.Add(sheet.GetRow(16).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                minlimit.Add(sheet.GetRow(17).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                maxlimit.Add(sheet.GetRow(18).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                avg.Add(sheet.GetRow(19).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                stdev.Add(sheet.GetRow(20).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                mindata.Add(sheet.GetRow(21).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                maxdata.Add(sheet.GetRow(22).GetCell(k + 1).StringCellValue.Replace(" ", ""));
+                                detno.Add(k.ToString());
+                            }
+                            //解析前面的范围文件
+                            sql.Clear();
+                            sql.Append("insert into DATACENTER$CHIP_DATAMAIN@SZSI_P(CHIPCODE_,DATE_,ITEM_NAME,DETNO,BIAS1,BIAS2,BIAS3,MINLIMIT,MAXLIMIT,AVG_,STDEV,MIN_,MAX_)");
+                            sql.Append("values('" + chipcode + "',sysdate,:ITEM_NAME,:DETNO,:BIAS1,:BIAS2,:BIAS3,:MINLIMIT,:MAXLIMIT,:AVG_,:STDEV,:MIN_,:MAX_)");
+                            dh.BatchInsert(sql.ToString(), new string[] { "itemname", "detno", "bias1", "bias2", "bias3", "minlimit", "maxlimit", "avg", "stdev", "mindata", "maxdata" }, itemname.ToArray(), detno.ToArray(), bias1.ToArray(), bias2.ToArray(), bias3.ToArray(), minlimit.ToArray(), maxlimit.ToArray(), avg.ToArray(), stdev.ToArray(), mindata.ToArray(), maxdata.ToArray());
+                            for (int j = 24; j <= sheet.LastRowNum; j++)
+                            {
+                                string Filed = "";
+                                string Value = "";
+                                sql.Clear();
+                                sql.Append("insert into RECORD$" + test + "(chipcode,detno,");
+                                for (int k = 1; k < sheet.GetRow(13).PhysicalNumberOfCells; k++)
+                                {
+                                    string CellValue = sheet.GetRow(j).GetCell(k + 1).StringCellValue.Replace(" ", "");
+                                    Filed += "ITEM" + (k) + ",";
+                                    Value += "'" + CellValue + "',";
+                                }
+                                sql.Append(Filed.Substring(0, Filed.Length - 1) + ") values('" + chipcode + "'," + (j - 23) + "," + Value.Substring(0, Value.Length - 1) + ");");
+                                insertSQL.Add(sql.ToString());
+                            }
+                            string[] strarr = insertSQL.ToArray();
+                            string sqlcount = "";
+                            for (int j = 0; j < strarr.Length; j++)
+                            {
+                                sqlcount += strarr[j];
+                                if (j > 0 && (j % 1000 == 0 || j == strarr.Length - 1))
+                                {
+                                    dh.ExecuteSql("begin " + sqlcount + " end;", "insert");
+                                    sqlcount = "";
+                                }
+                            }
+                            insertSQL.Clear();
+                            //更新为失效状态
+                            dh.ExecuteSql("UPDATE CHIPTABLE SET STATUS_=0  WHERE CHIP_CODE='" + chipcode + "'", "insert");
+                            //插入有效
+                            dh.ExecuteSql("INSERT INTO CHIPTABLE (CHIP_CODE,TABLE_NAME,STATUS_) VALUES ('" + chipcode + "','RECORD$" + test + "',-1)", "insert");
 
+                            dh.ExecuteSql("update datacenter$chip@SZSI_P set readstatus_=-1 where chipcode_='" + chipcode + "'", "update");
+                            richTextBox1.AppendText(DateTime.Now.ToString("yyyy/MM/dd h:mm:ss.ff") + chipcode + "\n");
+                        }
+                    }
+                    else
+                    {
+                        dh.ExecuteSql("update datacenter$chip@SZSI_P set readstatus_=-99 where chipcode_='" + chipcode + "'", "update");
+                        dh.ExecuteSql("insert into EDCsyscfaillog@SZSI_P(el_id,el_ip,el_synctime,el_chipcode,el_reason) values(EDCsyscfaillog_seq.nextval@SZSI_P,'" + IPAddress + "',sysdate,'" + chipcode + "','Excel文件不存在,无法解析')", "insert");
+                    }
+                }
+                catch (Exception ex)
+                {
+                    dh.ExecuteSql("update datacenter$chip@SZSI_P set readstatus_=-99 where chipcode_='" + chipcode + "'", "update");
+                    dh.ExecuteSql("insert into EDCsyscfaillog@SZSI_P(el_id,el_ip,el_synctime,el_chipcode,el_reason) values(EDCsyscfaillog_seq.nextval@SZSI_P,'" + IPAddress + "',sysdate,'" + chipcode + "','" + ex.Message + "')", "insert");
+                }
+            }
+        }
 
+        public void exec(string exePath, string parameters)
+        {
+            Process process = new Process();
+            process.StartInfo.FileName = exePath;
+            process.StartInfo.Arguments = parameters;
+            process.StartInfo.UseShellExecute = false;
+            process.StartInfo.CreateNoWindow = true;
+            process.StartInfo.RedirectStandardOutput = true;
+            process.Start();
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            Timer1_Tick(sender, e);
+        }
     }
 }

+ 3 - 0
FileAnalysis/Form1.resx

@@ -2353,4 +2353,7 @@
         AAAAAAAAAAAAAAAAAPAPAADwDwAA8A8AAPAPAAA=
 </value>
   </data>
+  <metadata name="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>138, 17</value>
+  </metadata>
 </root>

+ 16 - 6
FileAnalysis/SQL/SQL.txt

@@ -1,5 +1,4 @@
-创建表结构
-DECLARE 
+DECLARE 
  v_sql  varchar2(2000);
  v_content varchar2(2000);
 begin 
@@ -34,14 +33,25 @@ begin
 	ITEM28 VARCHAR2(50 BYTE), 
 	ITEM29 VARCHAR2(50 BYTE), 
 	ITEM30 VARCHAR2(50 BYTE), 
-	CHIPCODE VARCHAR2(20 BYTE))';
-  for i in 1..365 Loop
-    v_sql:='create table RECORD$'||to_char(sysdate+i,'yymmdd');
+	ITEM31 VARCHAR2(50 BYTE), 
+	ITEM32 VARCHAR2(50 BYTE), 
+	ITEM33 VARCHAR2(50 BYTE), 
+	ITEM34 VARCHAR2(50 BYTE), 
+	ITEM35 VARCHAR2(50 BYTE), 
+	ITEM36 VARCHAR2(50 BYTE), 
+  ITEM37 VARCHAR2(50 BYTE), 
+  ITEM38 VARCHAR2(50 BYTE), 
+	ITEM39 VARCHAR2(50 BYTE), 
+	ITEM40 VARCHAR2(50 BYTE), 
+	CHIPCODE VARCHAR2(20 BYTE),
+  DETNO number)';
+  for i in 1..1000 Loop
+    v_sql:='create table RECORD$'||to_char(sysdate-100+i,'yymmdd');
     v_sql:=v_sql||v_content;
      EXECUTE IMMEDIATE v_sql;
+     EXECUTE IMMEDIATE 'create index index1_'||to_char(sysdate-100+i,'yymmdd')||' on RECORD$'||to_char(sysdate-100+i,'yymmdd')|| ' (chipcode)';
   end loop;
 end;
 
-
 select localdatapath_,replace(replace(replace(substr(localdatapath_,instr(localdatapath_,'$')-1),'$',':'),'/','\'),'\\','\') from chiptable left
 join datacenter$chip@SZSI_P on chiptable.CHIP_CODE=chipcode_ where nvl(status_,0)=0;