From bf5c6e039b650e98916a4c52543ea9a42371f5a4 Mon Sep 17 00:00:00 2001 From: yangle <admin@YINMOU> Date: 星期五, 01 十二月 2023 13:46:31 +0800 Subject: [PATCH] 读取数据 --- WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs | 85 +++++++++++++ WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs | 238 ++++++++++++++++++++++++++++++--------- WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx | 3 WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache | 0 WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo | 0 WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb | 0 WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe | 0 WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe | 0 WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb | 0 9 files changed, 269 insertions(+), 57 deletions(-) diff --git a/WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo b/WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo index a51e9e9..f267ced 100644 --- a/WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo +++ b/WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo Binary files differ diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs index f6d512d..9a28e7d 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs @@ -29,12 +29,20 @@ /// </summary> private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.btnReadData = new System.Windows.Forms.Button(); + this.yg = new System.Windows.Forms.Label(); + this.HEmpCode = new System.Windows.Forms.TextBox(); + this.HEmpCodeName = new System.Windows.Forms.TextBox(); + this.btnSelect = new System.Windows.Forms.Button(); + this.ListSelect = new System.Windows.Forms.ListBox(); + this.label1 = new System.Windows.Forms.Label(); + this.timer1 = new System.Windows.Forms.Timer(this.components); this.SuspendLayout(); // // btnReadData // - this.btnReadData.Location = new System.Drawing.Point(55, 47); + this.btnReadData.Location = new System.Drawing.Point(47, 47); this.btnReadData.Name = "btnReadData"; this.btnReadData.Size = new System.Drawing.Size(114, 35); this.btnReadData.TabIndex = 1; @@ -42,21 +50,94 @@ this.btnReadData.UseVisualStyleBackColor = true; this.btnReadData.Click += new System.EventHandler(this.btnReadData_Click); // + // yg + // + this.yg.AutoSize = true; + this.yg.Location = new System.Drawing.Point(348, 47); + this.yg.Name = "yg"; + this.yg.Size = new System.Drawing.Size(44, 18); + this.yg.TabIndex = 2; + this.yg.Text = "鍛樺伐"; + // + // HEmpCode + // + this.HEmpCode.Location = new System.Drawing.Point(398, 44); + this.HEmpCode.Name = "HEmpCode"; + this.HEmpCode.Size = new System.Drawing.Size(118, 28); + this.HEmpCode.TabIndex = 3; + this.HEmpCode.KeyDown += new System.Windows.Forms.KeyEventHandler(this.HEmpCode_KeyDown); + // + // HEmpCodeName + // + this.HEmpCodeName.Location = new System.Drawing.Point(522, 44); + this.HEmpCodeName.Name = "HEmpCodeName"; + this.HEmpCodeName.ReadOnly = true; + this.HEmpCodeName.Size = new System.Drawing.Size(82, 28); + this.HEmpCodeName.TabIndex = 4; + // + // btnSelect + // + this.btnSelect.Location = new System.Drawing.Point(611, 39); + this.btnSelect.Name = "btnSelect"; + this.btnSelect.Size = new System.Drawing.Size(78, 38); + this.btnSelect.TabIndex = 5; + this.btnSelect.Text = "鏇存崲"; + this.btnSelect.UseVisualStyleBackColor = true; + this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click); + // + // ListSelect + // + this.ListSelect.FormattingEnabled = true; + this.ListSelect.ItemHeight = 18; + this.ListSelect.Location = new System.Drawing.Point(22, 124); + this.ListSelect.Name = "ListSelect"; + this.ListSelect.Size = new System.Drawing.Size(766, 310); + this.ListSelect.TabIndex = 6; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(19, 103); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(116, 18); + this.label1.TabIndex = 7; + this.label1.Text = "璇诲彇鏁版嵁鏄剧ず"; + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Interval = 10000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // // ReadyDataForm // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.label1); + this.Controls.Add(this.ListSelect); + this.Controls.Add(this.btnSelect); + this.Controls.Add(this.HEmpCodeName); + this.Controls.Add(this.HEmpCode); + this.Controls.Add(this.yg); this.Controls.Add(this.btnReadData); this.Name = "ReadyDataForm"; - this.Text = "Form1"; + this.Text = "璇诲彇鏁版嵁"; this.ResumeLayout(false); + this.PerformLayout(); } #endregion private System.Windows.Forms.Button btnReadData; + private System.Windows.Forms.Label yg; + private System.Windows.Forms.TextBox HEmpCode; + private System.Windows.Forms.TextBox HEmpCodeName; + private System.Windows.Forms.Button btnSelect; + private System.Windows.Forms.ListBox ListSelect; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Timer timer1; } } diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs index 9556088..7ce3e9f 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs @@ -21,76 +21,204 @@ InitializeComponent(); } + //璇诲彇鏁版嵁 private void btnReadData_Click(object sender, EventArgs e) { - int year = DateTime.Now.Year; - string month = DateTime.Now.Month.ToString(); - string day = DateTime.Now.Day.ToString(); + if (this.HEmpCode.Text == "") { - string dataTime = DateTime.Now.ToString("yyyyMMdd"); - ////鍒ゆ柇鏄惁鏈夎繖涓枃浠� - //bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt"); - bool flag = File.Exists($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt"); - - if (flag) + MessageBox.Show("璇疯緭鍏ュ憳宸ョ紪鐮�"); + } + else { - //StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312")); - StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt", Encoding.GetEncoding("gb2312")); + int year = DateTime.Now.Year; + string month = DateTime.Now.Month.ToString(); + string day = DateTime.Now.Day.ToString(); - string FileData = stream.ReadToEnd(); - stream.Close(); - FileData = FileData.Substring(0, FileData.Length - 1); - FileData = "[" + FileData + "]"; - //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚� - List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); - List<object> DataList = JsonConvert.DeserializeObject<List<object>>(FileData); - foreach (JObject item in DataList) + string dataTime = DateTime.Now.ToString("yyyyMMdd"); + ////鍒ゆ柇鏄惁鏈夎繖涓枃浠� + //bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt"); + bool flag = File.Exists($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt"); + + if (flag) { - Dictionary<string, string> dic = new Dictionary<string, string>(); - foreach (var itm in item.Properties()) + //StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312")); + StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt", Encoding.GetEncoding("gb2312")); + + string FileData = stream.ReadToEnd(); + stream.Close(); + FileData = FileData.Substring(0, FileData.Length - 1); + FileData = "[" + FileData + "]"; + //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚� + List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); + List<object> DataList = JsonConvert.DeserializeObject<List<object>>(FileData); + foreach (JObject item in DataList) { - dic.Add(itm.Name, itm.Value.ToString()); - } - list.Add(dic); - } - //鑾峰彇褰撳墠鏃堕棿 - DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")); - DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00")); - //寰幆闆嗗悎 - for (int i = 0; i < list.Count; i++) - { - DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString()); - if (NowTime >= ActionTime && NowTime < EndTime) - { - - string HSourceCode = list[i]["HSouceNumber"].ToString(); - //string HEmpCode = list[i]["HEmpCode"].ToString(); - string HEmpCode = ""; - string HType = list[i]["HBadReason"].ToString(); - string HBarCode = list[i]["HBadCodeSN"].ToString(); - int HCount = 1; - string HCreateTime = list[i]["HDate"].ToString(); - string HDate = DateTime.Parse(list[i]["HDate"].ToString()).ToString("yyyy-MM-dd"); - string HResult = list[i]["HResult"].ToString(); - string HProcNumber = list[i]["HProcNumber"].ToString(); - int HFlag = 0; - - DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN"); - - if (ds.Tables[0].Rows.Count == 0) + Dictionary<string, string> dic = new Dictionary<string, string>(); + foreach (var itm in item.Properties()) { - string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag) -values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')"; - oCN.RunProc(sql); + dic.Add(itm.Name, itm.Value.ToString()); } + list.Add(dic); } - else + //鑾峰彇褰撳墠鏃堕棿 + DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")); + DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00")); + //寰幆闆嗗悎 + for (int i = 0; i < list.Count; i++) { - //CustomWriteLog("鏃堕棿涓嶅湪淇濆瓨鑼冨洿鍐�", DateTime.Now.ToString("yyyy-MM-dd")); + DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString()); + if (NowTime >= ActionTime && NowTime < EndTime) + { + string HSourceCode = list[i]["HSouceNumber"].ToString(); + string HEmpCode = this.HEmpCode.Text; + //string HEmpCode = ""; + string HType = list[i]["HBadReason"].ToString(); + string HBarCode = list[i]["HBadCodeSN"].ToString(); + int HCount = 1; + string HCreateTime = list[i]["HDate"].ToString(); + string HDate = DateTime.Parse(list[i]["HDate"].ToString()).ToString("yyyy-MM-dd"); + string HResult = list[i]["HResult"].ToString(); + string HProcNumber = list[i]["HProcNumber"].ToString(); + int HFlag = 0; + + DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN"); + + if (ds.Tables[0].Rows.Count == 0) + { + string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag) +values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')"; + oCN.RunProc(sql); + ListSelect.Items.Add("鏉$爜:" + HBarCode + ",鏃ユ湡:" + HCreateTime + ",缁撴灉:" + HResult); + } + } + else + { + //CustomWriteLog("鏃堕棿涓嶅湪淇濆瓨鑼冨洿鍐�", DateTime.Now.ToString("yyyy-MM-dd")); + } } } } } + //杈撳叆鍛樺伐缂栫爜 + private void HEmpCode_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) { + SelectHEmpCode(this.HEmpCode.Text); + } + } + + //鏌ヨ鍛樺伐 + public void SelectHEmpCode(string HNumber) + { + try + { + DataSet ds = oCN.RunProcReturn("select * from Gy_Employee where HNumber='" + HNumber + "' ", "Gy_Employee"); + if (ds.Tables[0].Rows.Count == 0) + { + MessageBox.Show("鏌ユ棤鏁版嵁!"); + } + else + { + string HEmpCodeName = ds.Tables[0].Rows[0]["HName"].ToString(); + string HEmpCodeNumber = ds.Tables[0].Rows[0]["HNumber"].ToString(); + this.HEmpCodeName.Text = HEmpCodeName; + this.HEmpCode.Text = HEmpCodeNumber; + this.HEmpCode.ReadOnly = true; + } + } + catch (Exception e) + { + MessageBox.Show(this, e.Message, "鎻愮ず"); + } + } + + //鏇存崲鍛樺伐 + private void btnSelect_Click(object sender, EventArgs e) + { + this.HEmpCode.ReadOnly = false; + this.HEmpCode.Focus(); + this.HEmpCode.Text = ""; + this.HEmpCodeName.Text = ""; + } + + private void timer1_Tick(object sender, EventArgs e) + { + if (this.HEmpCode.Text == "") + { + + MessageBox.Show("璇疯緭鍏ュ憳宸ョ紪鐮�"); + } + else + { + int year = DateTime.Now.Year; + string month = DateTime.Now.Month.ToString(); + string day = DateTime.Now.Day.ToString(); + + string dataTime = DateTime.Now.ToString("yyyyMMdd"); + ////鍒ゆ柇鏄惁鏈夎繖涓枃浠� + //bool flag = File.Exists($@"D:\{year}\{month}\{day}\{dataTime}.txt"); + bool flag = File.Exists($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt"); + + if (flag) + { + //StreamReader stream = new StreamReader($@"D:\{year}\{month}\{day}\{dataTime}.txt", Encoding.GetEncoding("gb2312")); + StreamReader stream = new StreamReader($@"C:\Users\admin\Desktop\鏂板缓鏂囦欢澶� (2)\20231123.txt", Encoding.GetEncoding("gb2312")); + + string FileData = stream.ReadToEnd(); + stream.Close(); + FileData = FileData.Substring(0, FileData.Length - 1); + FileData = "[" + FileData + "]"; + //JSON搴忓垪鍖栬浆鎹㈠瓧鍏搁泦鍚� + List<Dictionary<string, string>> list = new List<Dictionary<string, string>>(); + List<object> DataList = JsonConvert.DeserializeObject<List<object>>(FileData); + foreach (JObject item in DataList) + { + Dictionary<string, string> dic = new Dictionary<string, string>(); + foreach (var itm in item.Properties()) + { + dic.Add(itm.Name, itm.Value.ToString()); + } + list.Add(dic); + } + //鑾峰彇褰撳墠鏃堕棿 + DateTime ActionTime = DateTime.Parse(DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss")); + DateTime EndTime = DateTime.Parse(DateTime.Now.AddMinutes(1).ToString("yyyy-MM-dd HH:mm:00")); + //寰幆闆嗗悎 + for (int i = 0; i < list.Count; i++) + { + DateTime NowTime = DateTime.Parse(list[i]["HDate"].ToString()); + if (NowTime >= ActionTime && NowTime < EndTime) + { + string HSourceCode = list[i]["HSouceNumber"].ToString(); + string HEmpCode = this.HEmpCode.Text; + //string HEmpCode = ""; + string HType = list[i]["HBadReason"].ToString(); + string HBarCode = list[i]["HBadCodeSN"].ToString(); + int HCount = 1; + string HCreateTime = list[i]["HDate"].ToString(); + string HDate = DateTime.Parse(list[i]["HDate"].ToString()).ToString("yyyy-MM-dd"); + string HResult = list[i]["HResult"].ToString(); + string HProcNumber = list[i]["HProcNumber"].ToString(); + int HFlag = 0; + + DataSet ds = oCN.RunProcReturn(@"select * from Sb_EquipMentCollection_SN where HBarCode='" + HBarCode + "' and HCreateTime='" + HCreateTime + "'", "Sb_EquipMentCollection_SN"); + + if (ds.Tables[0].Rows.Count == 0) + { + string sql = $@"insert into Sb_EquipMentCollection_SN(HSourceCode,HEmpCode,HType,HBarCode,HCount,HCreateTime,HDate,HResult,HProcNumber,HFlag) +values('{HSourceCode}','{HEmpCode}','{HType}','{HBarCode}','{HCount}','{HCreateTime}','{HDate}','{HResult}','{HProcNumber}','{HFlag}')"; + oCN.RunProc(sql); + ListSelect.Items.Add("鏉$爜:" + HBarCode + ",鏃ユ湡:" + HCreateTime + ",缁撴灉:" + HResult); + } + } + else + { + //CustomWriteLog("鏃堕棿涓嶅湪淇濆瓨鑼冨洿鍐�", DateTime.Now.ToString("yyyy-MM-dd")); + } + } + } + } + } } } diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx index 1af7de1..1f666f2 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx @@ -117,4 +117,7 @@ <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>17, 17</value> + </metadata> </root> \ No newline at end of file diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe b/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe index d520dac..f3e4243 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe Binary files differ diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb b/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb index 5152593..21602df 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb Binary files differ diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache index 14fe904..cb9dea9 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache Binary files differ diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe index d520dac..f3e4243 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe Binary files differ diff --git a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb index 5152593..21602df 100644 --- a/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb +++ b/WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb Binary files differ -- Gitblit v1.9.1