yangle
2023-12-01 bf5c6e039b650e98916a4c52543ea9a42371f5a4
读取数据
9个文件已修改
326 ■■■■ 已修改文件
WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.Designer.cs 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.cs 238 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/ReadyDataForm.resx 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb 补丁 | 查看 | 原始文档 | blame | 历史
WFormSynchronizeData_SMR/.vs/WFormSynchronizeData_SMR/v16/.suo
Binary files differ
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;
    }
}
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"));
                        }
                    }
                }
            }
        }
    }
}
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>
WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.exe
Binary files differ
WFormSynchronizeData_SMR/WFormReadData_SMR/bin/Debug/WFormReadData_SMR.pdb
Binary files differ
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.csproj.GenerateResource.cache
Binary files differ
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.exe
Binary files differ
WFormSynchronizeData_SMR/WFormReadData_SMR/obj/Debug/WFormReadData_SMR.pdb
Binary files differ