Browse Source

保存代码

tangs 6 years ago
parent
commit
791bd772ab

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+frequency/.vs
+frequency/bin
+frequency/obj

+ 25 - 0
frequency.sln

@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.26730.12
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "frequency", "frequency\frequency.csproj", "{83796422-99F0-460B-9726-E7E5FB641C5F}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{83796422-99F0-460B-9726-E7E5FB641C5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{83796422-99F0-460B-9726-E7E5FB641C5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{83796422-99F0-460B-9726-E7E5FB641C5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{83796422-99F0-460B-9726-E7E5FB641C5F}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {B5E01C5D-4CF9-4F4C-9180-8DC6DDDB3AC6}
+	EndGlobalSection
+EndGlobal

+ 6 - 0
frequency/App.config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
+    </startup>
+</configuration>

+ 162 - 0
frequency/Form1.Designer.cs

@@ -0,0 +1,162 @@
+namespace frequency
+{
+    partial class Form1
+    {
+        /// <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.originButton = new System.Windows.Forms.Button();
+            this.originText = new System.Windows.Forms.TextBox();
+            this.targetText = new System.Windows.Forms.TextBox();
+            this.targetButton = new System.Windows.Forms.Button();
+            this.calculate = new System.Windows.Forms.Button();
+            this.seeResult = new System.Windows.Forms.Button();
+            this.status = new System.Windows.Forms.Label();
+            this.label1 = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // originButton
+            // 
+            this.originButton.Location = new System.Drawing.Point(257, 38);
+            this.originButton.Name = "originButton";
+            this.originButton.Size = new System.Drawing.Size(75, 23);
+            this.originButton.TabIndex = 0;
+            this.originButton.Text = "源文件";
+            this.originButton.UseVisualStyleBackColor = true;
+            this.originButton.Click += new System.EventHandler(this.SelectOriginButton);
+            // 
+            // originText
+            // 
+            this.originText.Enabled = false;
+            this.originText.Location = new System.Drawing.Point(50, 38);
+            this.originText.Name = "originText";
+            this.originText.Size = new System.Drawing.Size(201, 21);
+            this.originText.TabIndex = 1;
+            this.originText.TextChanged += new System.EventHandler(this.ShowOriginText);
+            // 
+            // targetText
+            // 
+            this.targetText.Enabled = false;
+            this.targetText.Location = new System.Drawing.Point(50, 84);
+            this.targetText.Name = "targetText";
+            this.targetText.Size = new System.Drawing.Size(201, 21);
+            this.targetText.TabIndex = 2;
+            this.targetText.TextChanged += new System.EventHandler(this.ShowTargetText);
+            // 
+            // targetButton
+            // 
+            this.targetButton.Location = new System.Drawing.Point(257, 82);
+            this.targetButton.Name = "targetButton";
+            this.targetButton.Size = new System.Drawing.Size(75, 23);
+            this.targetButton.TabIndex = 3;
+            this.targetButton.Text = "目标文件";
+            this.targetButton.UseVisualStyleBackColor = true;
+            this.targetButton.Click += new System.EventHandler(this.SelectTargetButton);
+            // 
+            // calculate
+            // 
+            this.calculate.Location = new System.Drawing.Point(89, 164);
+            this.calculate.Name = "calculate";
+            this.calculate.Size = new System.Drawing.Size(75, 23);
+            this.calculate.TabIndex = 4;
+            this.calculate.Text = "计算";
+            this.calculate.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText;
+            this.calculate.UseVisualStyleBackColor = true;
+            this.calculate.Click += new System.EventHandler(this.Calculate_Click);
+            // 
+            // seeResult
+            // 
+            this.seeResult.Location = new System.Drawing.Point(203, 164);
+            this.seeResult.Name = "seeResult";
+            this.seeResult.Size = new System.Drawing.Size(75, 23);
+            this.seeResult.TabIndex = 5;
+            this.seeResult.Text = "查看结果";
+            this.seeResult.UseVisualStyleBackColor = true;
+            this.seeResult.Click += new System.EventHandler(this.SeeResult_Click);
+            // 
+            // status
+            // 
+            this.status.AutoSize = true;
+            this.status.Location = new System.Drawing.Point(50, 129);
+            this.status.Name = "status";
+            this.status.Size = new System.Drawing.Size(41, 12);
+            this.status.TabIndex = 7;
+            this.status.Text = "状态:";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(97, 129);
+            this.label1.MinimumSize = new System.Drawing.Size(60, 0);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(65, 12);
+            this.label1.TabIndex = 8;
+            this.label1.Text = "计算未开始";
+            this.label1.Click += new System.EventHandler(this.label1_Click);
+            // 
+            // Form1
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(397, 233);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.status);
+            this.Controls.Add(this.seeResult);
+            this.Controls.Add(this.calculate);
+            this.Controls.Add(this.targetButton);
+            this.Controls.Add(this.targetText);
+            this.Controls.Add(this.originText);
+            this.Controls.Add(this.originButton);
+            this.Name = "Form1";
+            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.Button originButton; // 选择源文件按钮
+        private System.Windows.Forms.TextBox originText; // 显示源文件路径
+        private System.Windows.Forms.TextBox targetText; // 选择目标文件路径
+        private System.Windows.Forms.Button targetButton; // 显示目标文件路径
+
+
+        private string originTextPath; // 源文件路径
+        private string targetTextPath; // 目标文件路径
+        private System.Windows.Forms.Button calculate; // 计算按钮
+        private System.Windows.Forms.Button seeResult; // 查看结果按钮
+        private System.Windows.Forms.Label status;
+        private System.Windows.Forms.Label label1;
+        private string path;
+
+        private long currentIndex;
+        private long totalNum;
+    }
+}
+

+ 450 - 0
frequency/Form1.cs

@@ -0,0 +1,450 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using System.IO;
+using log = Log.Log;
+using Excel = Microsoft.Office.Interop.Excel;
+
+namespace frequency
+{
+    public partial class Form1 : Form
+    {
+        public Form1()
+        {
+            log.Init("frequency.log");
+            path = System.Environment.CurrentDirectory;
+            InitializeComponent();
+        }
+
+        private string[] originTextsOrder;
+        private string[] originTextsInverse;
+        private string[] targetTexts;
+
+        private void SelectOriginButton(object sender, EventArgs e)
+        {
+            var fileDialog = new OpenFileDialog();
+            fileDialog.Multiselect = false;
+            fileDialog.Title = "选择源文件";
+            if (fileDialog.ShowDialog() == DialogResult.OK)
+            {
+                this.originTextPath = fileDialog.FileName;
+                this.originText.Text = originTextPath;
+            }
+        }
+
+        private void ShowOriginText(object sender, EventArgs e)
+        {
+
+        }
+
+        private void SelectTargetButton(object sender, EventArgs e)
+        {
+            var fileDialog = new OpenFileDialog();
+            fileDialog.Multiselect = false;
+            fileDialog.Title = "选择目标文件";
+            if (fileDialog.ShowDialog() == DialogResult.OK)
+            {
+                this.targetTextPath = fileDialog.FileName;
+                this.targetText.Text = this.targetTextPath;
+            }
+        }
+
+        private void ShowTargetText(object sender, EventArgs e)
+        {
+
+        }
+
+        private void Calculate_Click(object sender, EventArgs e)
+        {
+            this.label1.Text = "计算中...";
+            this.label1.Refresh();
+            this.calculate.Enabled = false;
+
+            var code = this.Calculate();
+            if (code != 0)
+            {
+                this.label1.Text = "计算出错";
+                this.label1.Refresh();
+            }
+            else
+            {
+                this.label1.Text = "计算完成";
+                this.label1.Refresh();
+            }
+            Application.DoEvents();
+            this.calculate.Enabled = true;
+        }
+
+        private int Calculate()
+        {
+            int code;
+            // read origin file
+            code = this.ReadOriginText();
+            if (code != 0)
+            {
+                log.E("Calculate_Click read origin file error with code: {0}", code);
+                return 1;
+            }
+
+            // read target file
+            code = this.ReadTargetText();
+            if (code != 0)
+            {
+                log.E("Calculate_Click read target file error with code: {0}", code);
+                return 1;
+            }
+
+            // clear target file
+            this.CleanTarget();
+
+            // look up
+            var result = this.Lookup();
+            log.D("Calculate_Click look up success with length: {0}", result.Count);
+
+            // write data to file
+            this.label1.Text = "导出数据中...";
+            this.label1.Refresh();
+
+            var msg = this.Write2Xlsx(result);
+            if ("" != msg)
+            {
+                log.E("Calculate_Click write data to xlsx error: {0}", msg);
+                return 1;
+            }
+            log.D("Calculate_Click write data to xlsx success");
+            return 0;
+        }
+
+        private void SeeResult_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                System.Diagnostics.Process.Start("explorer.exe", path);
+            }
+            catch (Exception err)
+            {
+                MessageBox.Show(err.ToString());
+            }
+        }
+
+        //  读取原始文件
+        private int ReadOriginText()
+        {
+            string[] texts;
+            try
+            {
+                texts = File.ReadAllLines(this.originTextPath);
+            }
+            catch (Exception err)
+            {
+                log.E("readOriginText with path: {0} error: {1}", this.originTextPath, err.ToString());
+                MessageBox.Show(err.ToString());
+                return 1;
+            }
+            if (texts.Length < 1)
+            {
+                log.E("readOriginText with path: {0}, read file is empty", this.originTextPath);
+                MessageBox.Show("file is empty");
+                return 1;
+            }
+
+            log.D("ReadOriginText received origin text with length: {0}", texts.Length);
+
+            // check
+            int length = 0;
+            for (int i = 0; i < texts.Length; i++)
+            {
+                var val = texts[i].Trim();
+                if (val.Length < 1)
+                {
+                    continue;
+                }
+                length++;
+            }
+            log.D("ReadOriginText received check text with length: {0}", length);
+
+            // append
+            var tempTexts = new string[length];
+            int index = 0;
+            for (int i = 0; i < texts.Length; i++)
+            {
+                var val = texts[i].Trim();
+                if (val.Length < 1)
+                {
+                    continue;
+                }
+                tempTexts[index++] = texts[i];
+            }
+
+            // combine
+            index = 0;
+            this.originTextsOrder = new string[(length * (length - 1)) / 2];
+            for (int i = 0; i < length; i++)
+            {
+                for (int j = i + 1; j < length; j++)
+                {
+                    this.originTextsOrder[index++] = tempTexts[i] + "-" + tempTexts[j];
+                }
+            }
+            index = 0;
+            this.originTextsInverse = new string[(length * (length - 1)) / 2];
+            for (int i = length - 1; i >= 0; i--)
+            {
+                for (int j = i - 1; j >= 0; j--)
+                {
+                    this.originTextsInverse[index++] = tempTexts[i] + "-" + tempTexts[j];
+                }
+            }
+            log.D("ReadOriginText read origin file success with order length: {0}, inverse length; {1}", this.originTextsOrder.Length, this.originTextsInverse.Length);
+            return 0;
+        }
+
+        //  读取目标文件
+        private int ReadTargetText()
+        {
+            string[] texts;
+            try
+            {
+                texts = File.ReadAllLines(this.targetTextPath);
+            }
+            catch (Exception err)
+            {
+                log.E("ReadTargetText with path: {0} error: {1}", this.targetTextPath, err.ToString());
+                MessageBox.Show(err.ToString());
+                return 1;
+            }
+            if (texts.Length < 1)
+            {
+                log.E("ReadTargetText with path: {0}, read file is empty", this.targetTextPath);
+                MessageBox.Show("file is empty");
+                return 1;
+            }
+            log.D("ReadTargetText read texts: {0}", texts);
+            // check
+            int length = 0;
+            for (int i = 0; i < texts.Length; i++)
+            {
+                var val = texts[i].Trim();
+                if (val.Length < 1 || !val.Contains("-"))
+                {
+                    continue;
+                }
+                length++;
+            }
+
+            // append
+            this.targetTexts = new string[length];
+            var index = 0;
+            for (int i = 0; i < texts.Length; i++)
+            {
+                var val = texts[i].Trim();
+                if (val.Length < 1 || !val.Contains("-"))
+                {
+                    continue;
+                }
+                this.targetTexts[index++] = texts[i];
+            }
+
+            return 0;
+        }
+
+        /*
+         * desc
+         *      1. 目标文件中的字符串形如54#01(100#)--54#02,其中括号以及括号的内容清除不计。
+         *      2. 源文件两两组合的后的字符串再到目标文件中查找,所有单个的字符串都可以忽略不计算;如58#01可以忽略不计。
+         */
+        private void CleanTarget()
+        {
+            var originLength = this.targetTexts.Length;
+            string[] tempStrings = new string[this.targetTexts.Length];
+            var index = 0;
+            for (int i = 0; i < this.targetTexts.Length; i++)
+            {
+
+                var val = this.targetTexts[i].Trim();
+                if (val.Length < 1)
+                {
+                    continue;
+                }
+                if (!val.Contains("-"))
+                {
+                    continue;
+                }
+
+                var clearStr = ClearString(val);
+                tempStrings[index++] = clearStr;
+            }
+            this.targetTexts = new string[index];
+            for (int i = 0; i < index; i++)
+            {
+                this.targetTexts[i] = tempStrings[i];
+            }
+            log.D("CleanTarget clean target origin length {0} success with last length: {1}", originLength, this.targetTexts.Length);
+        }
+
+        private string ClearString(string str)
+        {
+            if (!str.Contains("("))
+            {
+                return str;
+            }
+            string result = "";
+            bool had = false;
+            for (int i = 0; i < str.Length; i++)
+            {
+                if (had && str[i] != ')')
+                {
+                    continue;
+                }
+                if (had && str[i] == ')')
+                {
+                    had = false;
+                    continue;
+                }
+                if (str[i] == '(')
+                {
+                    had = true;
+                    continue;
+                }
+                result += str[i];
+            }
+            return ClearString(result);
+        }
+
+
+        private Dictionary<string, int> Lookup()
+        {
+            this.currentIndex = 0;
+            this.totalNum = this.originTextsOrder.Length + this.originTextsInverse.Length;
+            Dictionary<string, int> result = new Dictionary<string, int>();
+            for (int i = 0; i < this.originTextsOrder.Length; i++)
+            {
+                for (int j = 0; j < this.targetTexts.Length; j++)
+                {
+                    this.currentIndex++;
+                    if (judge(this.originTextsOrder[i], this.targetTexts[j]))
+                    {
+                        var key = this.originTextsOrder[i];
+                        if (result.ContainsKey(key))
+                        {
+                            result[key] = result[key] + 1;
+                        }
+                        else
+                        {
+                            result[key] = 1;
+                        }
+                    }
+                }
+            }
+
+            for (int i = 0; i < this.originTextsInverse.Length; i++)
+            {
+                for (int j = 0; j < this.targetTexts.Length; j++)
+                {
+                    this.currentIndex++;
+                    if (judge(this.originTextsInverse[i], this.targetTexts[j]))
+                    {
+                        var key = this.originTextsInverse[i];
+                        if (result.ContainsKey(key))
+                        {
+                            result[key] = result[key] + 1;
+                        }
+                        else
+                        {
+                            result[key] = 1;
+                        }
+                    }
+                }
+            }
+            return result;
+        }
+
+        private bool judge(string origin, string target)
+        {
+            var strs = origin.Split('-');
+            if (strs.Length < 2)
+            {
+                return false;
+            }
+            if ((strs[0] + "-" + strs[1] == target) || (strs[0] + "--" + strs[1] == target))
+            {
+                return true;
+            }
+            return false;
+        }
+
+        private void label1_Click(object sender, EventArgs e)
+        {
+
+        }
+
+
+        private string Write2Xlsx(Dictionary<string, int> data)
+        {
+            var suffix = DateTime.Now.ToString("yyyy-MM-dd-HH-mm") + ".xlsx";
+            var filename = Path.Combine(path, suffix);
+            Excel.Application app = new Excel.Application();
+            Excel.Workbook doc = app.Workbooks.Add(Type.Missing);
+            if (doc.Worksheets.Count < 1)
+            {
+                doc.Worksheets.Add(Type.Missing, Type.Missing, Type.Missing);
+            }
+            Excel.Worksheet sheet = doc.ActiveSheet;
+
+            var index = 1;
+            foreach (var val in data)
+            {
+                sheet.Cells[index, 1] = val.Key;
+                sheet.Cells[index, 2] = val.Value;
+                index++;
+            }
+
+            //sheet.Cells[1, 1] = "Name";
+            //sheet.Cells[1, 2] = "Sex";
+            //for (int i = 2; i < 5; i++)
+            //{
+            //    sheet.Cells[i, 1] = "Name" + i;
+            //    sheet.Cells[i, 2] = "Sex" + i;
+            //}
+
+            try
+            {
+                sheet.SaveAs(filename);
+                doc.Save();
+                doc.Close(Type.Missing, filename, Type.Missing);
+                app.Quit();
+            }
+            catch (Exception err)
+            {
+                log.E("Write2Xlsx write file({0}) error: {1}", filename, err.ToString());
+                return err.ToString();
+            }
+            log.D("Write2Xlsx write file({0}) success", filename);
+            return "";
+        }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            //this.Write2Xlsx();
+        }
+
+        private void Form1_Load(object sender, EventArgs e)
+        {
+
+        }
+
+        private void showProgress()
+        {
+            while (true)
+            {
+                this.label1.Text = this.label1.Text;
+            }
+        }
+    }
+}

+ 120 - 0
frequency/Form1.resx

@@ -0,0 +1,120 @@
+<?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>
+</root>

+ 70 - 0
frequency/Log.cs

@@ -0,0 +1,70 @@
+using System;
+using System.Diagnostics;
+
+namespace Log
+{
+    public static class Log
+    {
+        public static void Init(string logPath)
+        {
+            Debug.Listeners.Clear();
+            Debug.Listeners.Add(new TextWriterTraceListener(logPath));
+            Debug.AutoFlush = true;
+        }
+        public static void D2(string message)
+        {
+            var sf = new StackFrame(1, true);
+            string log = string.Format(
+                "{0} {1} Line:{2} {3} [D]: {4}",
+                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                sf.GetFileName(),
+                sf.GetFileLineNumber(),
+                sf.GetMethod(),
+                message
+            );
+            Debug.WriteLine(log);
+        }
+        public static void D(string message, params object[] args)
+        {
+            string info = String.Format(message, args);
+            var sf = new StackFrame(1, true);
+            string log = string.Format(
+                "{0} {1} Line:{2} {3} [D]: {4}",
+                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                sf.GetFileName(),
+                sf.GetFileLineNumber(),
+                sf.GetMethod(),
+                info
+            );
+            Debug.WriteLine(log);
+        }
+
+        public static void E2(string message)
+        {
+            var sf = new StackFrame(1, true);
+            string log = string.Format(
+                "{0} {1} Line:{2} {3} [E]: {4}",
+                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                sf.GetFileName(),
+                sf.GetFileLineNumber(),
+                sf.GetMethod(),
+                message
+            );
+            Debug.WriteLine(log);
+        }
+        public static void E(string message, params object[] args)
+        {
+            string info = String.Format(message, args);
+            var sf = new StackFrame(1, true);
+            string log = string.Format(
+                "{0} {1} Line:{2} {3} [E]: {4}",
+                System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                sf.GetFileName(),
+                sf.GetFileLineNumber(),
+                sf.GetMethod(),
+                info
+            );
+            Debug.WriteLine(log);
+        }
+    }
+}

+ 22 - 0
frequency/Program.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace frequency
+{
+    static class Program
+    {
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new Form1());
+        }
+    }
+}

+ 36 - 0
frequency/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("frequency")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("frequency")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// 将 ComVisible 设置为 false 会使此程序集中的类型
+//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("83796422-99f0-460b-9726-e7e5fb641c5f")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 71 - 0
frequency/Properties/Resources.Designer.cs

@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     此代码由工具生成。
+//     运行时版本: 4.0.30319.42000
+//
+//     对此文件的更改可能导致不正确的行为,如果
+//     重新生成代码,则所做更改将丢失。
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace frequency.Properties
+{
+
+
+    /// <summary>
+    ///   强类型资源类,用于查找本地化字符串等。
+    /// </summary>
+    // 此类是由 StronglyTypedResourceBuilder
+    // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
+    // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
+    // (以 /str 作为命令选项),或重新生成 VS 项目。
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources
+    {
+
+        private static global::System.Resources.ResourceManager resourceMan;
+
+        private static global::System.Globalization.CultureInfo resourceCulture;
+
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources()
+        {
+        }
+
+        /// <summary>
+        ///   返回此类使用的缓存 ResourceManager 实例。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager
+        {
+            get
+            {
+                if ((resourceMan == null))
+                {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("frequency.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+
+        /// <summary>
+        ///   覆盖当前线程的 CurrentUICulture 属性
+        ///   使用此强类型的资源类的资源查找。
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture
+        {
+            get
+            {
+                return resourceCulture;
+            }
+            set
+            {
+                resourceCulture = value;
+            }
+        }
+    }
+}

+ 117 - 0
frequency/Properties/Resources.resx

@@ -0,0 +1,117 @@
+<?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.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: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" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </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" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 30 - 0
frequency/Properties/Settings.Designer.cs

@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.42000
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace frequency.Properties
+{
+
+
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+    {
+
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+        public static Settings Default
+        {
+            get
+            {
+                return defaultInstance;
+            }
+        }
+    }
+}

+ 7 - 0
frequency/Properties/Settings.settings

@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>

+ 115 - 0
frequency/frequency.csproj

@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{83796422-99F0-460B-9726-E7E5FB641C5F}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>frequency</RootNamespace>
+    <AssemblyName>frequency</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup>
+    <NoWin32Manifest>true</NoWin32Manifest>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Form1.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form1.Designer.cs">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Log.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <EmbeddedResource Include="Form1.resx">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="Microsoft.Office.Core">
+      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
+      <VersionMajor>2</VersionMajor>
+      <VersionMinor>8</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="Microsoft.Office.Interop.Excel">
+      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>9</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="VBIDE">
+      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>5</VersionMajor>
+      <VersionMinor>3</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>