Browse Source

东创伟测试文件解析

callm 2 years ago
parent
commit
ecdf749e6f

+ 131 - 0
FileWatcher/测试记录解析DCW.Designer.cs

@@ -0,0 +1,131 @@
+namespace FileWatcher
+{
+    partial class 测试记录解析DCW
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.OperateResult = new System.Windows.Forms.RichTextBox();
+            this.timer1 = new System.Windows.Forms.Timer(this.components);
+            this.Start = new System.Windows.Forms.Button();
+            this.ChooseFolder = new System.Windows.Forms.Button();
+            this.FolderPath = new System.Windows.Forms.TextBox();
+            this.label1 = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // OperateResult
+            // 
+            this.OperateResult.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+            this.OperateResult.Location = new System.Drawing.Point(38, 15);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(6);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(1336, 677);
+            this.OperateResult.TabIndex = 0;
+            this.OperateResult.Text = "";
+            // 
+            // timer1
+            // 
+            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
+            // 
+            // Start
+            // 
+            this.Start.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.Start.Location = new System.Drawing.Point(623, 788);
+            this.Start.Name = "Start";
+            this.Start.Size = new System.Drawing.Size(141, 40);
+            this.Start.TabIndex = 1;
+            this.Start.Text = "开始监控";
+            this.Start.UseVisualStyleBackColor = true;
+            this.Start.Click += new System.EventHandler(this.Start_Click);
+            // 
+            // ChooseFolder
+            // 
+            this.ChooseFolder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.ChooseFolder.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.ChooseFolder.Location = new System.Drawing.Point(669, 720);
+            this.ChooseFolder.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.ChooseFolder.Name = "ChooseFolder";
+            this.ChooseFolder.Size = new System.Drawing.Size(156, 48);
+            this.ChooseFolder.TabIndex = 14;
+            this.ChooseFolder.Text = "选择文件夹";
+            this.ChooseFolder.UseVisualStyleBackColor = true;
+            this.ChooseFolder.Click += new System.EventHandler(this.ChooseFolder_Click);
+            // 
+            // FolderPath
+            // 
+            this.FolderPath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.FolderPath.Enabled = false;
+            this.FolderPath.Location = new System.Drawing.Point(201, 726);
+            this.FolderPath.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.FolderPath.Name = "FolderPath";
+            this.FolderPath.Size = new System.Drawing.Size(436, 35);
+            this.FolderPath.TabIndex = 13;
+            // 
+            // label1
+            // 
+            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 10.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(31, 720);
+            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(162, 38);
+            this.label1.TabIndex = 12;
+            this.label1.Text = "监控文件夹";
+            // 
+            // 测试记录解析DCW
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(1402, 845);
+            this.Controls.Add(this.ChooseFolder);
+            this.Controls.Add(this.FolderPath);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.Start);
+            this.Controls.Add(this.OperateResult);
+            this.Margin = new System.Windows.Forms.Padding(6);
+            this.Name = "测试记录解析DCW";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "测试文件监控";
+            this.Load += new System.EventHandler(this.Form1_Load);
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.RichTextBox OperateResult;
+        private System.Windows.Forms.Timer timer1;
+        private System.Windows.Forms.Button Start;
+        private System.Windows.Forms.Button ChooseFolder;
+        private System.Windows.Forms.TextBox FolderPath;
+        private System.Windows.Forms.Label label1;
+    }
+}
+

+ 191 - 0
FileWatcher/测试记录解析DCW.cs

@@ -0,0 +1,191 @@
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Diagnostics;
+using System.IO;
+using System.Net;
+using System.Text;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace FileWatcher
+{
+    public partial class 测试记录解析DCW : Form
+    {
+
+        DataHelper dh = new DataHelper();
+
+        ftpOperater ftp = new ftpOperater();
+
+        public 测试记录解析DCW()
+        {
+            InitializeComponent();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+            timer1.Interval = 1000 * 10;
+            OperateResult.AppendText("连接上服务器\n");
+            //timer1.Start();
+        }
+
+        public void DoLog(string Message)
+        {
+            try
+            {
+                StreamWriter sw = File.AppendText(DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
+                sw.WriteLine("\n【时间】" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + Message + "\n");
+                sw.Close();
+            }
+            catch (Exception) { }
+        }
+
+        /// <summary>
+        /// 私有变量
+        /// </summary>
+        private List<FileInfo> lst = new List<FileInfo>();
+        /// <summary>
+        /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
+        /// </summary>
+        /// <param name="path">文件夹路径</param>
+        /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
+        /// <returns>List<FileInfo></returns>
+        public List<FileInfo> getFile(string path, string extName)
+        {
+            getdir(path, extName);
+            return lst;
+        }
+
+        /// <summary>
+        /// 私有方法,递归获取指定类型文件,包含子文件夹
+        /// </summary>
+        /// <param name="path"></param>
+        /// <param name="extName"></param>
+        private void getdir(string path, string extName)
+        {
+            try
+            {
+                string[] dir = Directory.GetDirectories(path); //文件夹列表   
+                DirectoryInfo fdir = new DirectoryInfo(path);
+                FileInfo[] file = fdir.GetFiles();
+                //FileInfo[] file = Directory.GetFiles(path); //文件列表   
+                if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空                   
+                {
+                    string SN = "";
+                    string folderpath = "";
+                    foreach (FileInfo f in file) //显示当前目录所有文件   
+                    {
+                        string filename = f.FullName;
+                        if (filename.Substring(filename.LastIndexOf(".") + 1).ToUpper() == "TXT")
+                        {
+                            folderpath = f.FullName.Substring(0, f.FullName.LastIndexOf(@"\"));
+                            SN = f.Name.Split('.')[0];
+                            try
+                            {
+                                string ftppath = "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
+                                ftp.UpLoadFile(folderpath, f.Name, ftppath, "");
+                                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://81.71.42.91:8099/ftp" + ftppath + f.Name + "' from makeserial where substr(ms_sncode,0,12)='" + SN + "'", "insert");
+                                OperateResult.AppendText(SN+"获取成功\n");
+                            }
+                            catch (Exception ex)
+                            {
+                                Console.WriteLine(ex.Message);
+                            }
+                        }
+                    }
+                    foreach (FileInfo f in file) //显示当前目录所有文件   
+                    {
+                        try
+                        {
+                            File.Delete(f.FullName);
+                        }
+                        catch (Exception ex)
+                        {
+                            Console.WriteLine(ex.Message);
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+        }
+
+        private void timer1_Tick(object sender, EventArgs e)
+        {
+            try
+            {
+                getFile(FolderPath.Text, ".txt");
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
+        /// </summary>
+        /// <param name="path">文件夹路径</param>
+        /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
+        /// <returns>List<FileInfo></returns>
+        public static List<FileInfo> getFile(string path, string extName, List<FileInfo> lst)
+        {
+            try
+            {
+                string[] dir = Directory.GetDirectories(path); //文件夹列表  
+                DirectoryInfo fdir = new DirectoryInfo(path);
+                FileInfo[] file = fdir.GetFiles();
+                //FileInfo[] file = Directory.GetFiles(path); //文件列表  
+                if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空          
+                {
+                    foreach (FileInfo f in file) //显示当前目录所有文件  
+                    {
+                        if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
+                        {
+                            lst.Add(f);
+                        }
+                    }
+                    foreach (string d in dir)
+                    {
+                        getFile(d, extName, lst);//递归  
+                    }
+                }
+                return lst;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        private void ChooseFolder_Click(object sender, EventArgs e)
+        {
+            FolderBrowserDialog folder = new FolderBrowserDialog();
+            folder.Description = "选择监控文件夹";
+            DialogResult result = folder.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+                FolderPath.Text = folder.SelectedPath;
+            }
+        }
+
+        private void ChooseBackUpFolder_Click(object sender, EventArgs e)
+        {
+            FolderBrowserDialog folder = new FolderBrowserDialog();
+            folder.Description = "选择备份文件夹";
+            DialogResult result = folder.ShowDialog();
+            if (result == DialogResult.OK)
+            {
+               // BackUpFolderPath.Text = folder.SelectedPath;
+            }
+        }
+
+        private void Start_Click(object sender, EventArgs e)
+        {
+            timer1.Start();
+        }
+    }
+}

+ 123 - 0
FileWatcher/测试记录解析DCW.resx

@@ -0,0 +1,123 @@
+<?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="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>228, 17</value>
+  </metadata>
+</root>