233
schangxiang@126.com
2024-07-05 b27a2ba1ccbd8e2e7b61a700dde5f891ed6ae35d
DataCapture/iWare_SCADA_DataCapture/iWare_SCADA_FormTest/Form1.cs
@@ -1,4 +1,5 @@
using iWare_SCADA_BusinessLogical.Utils;
using iWare_SCADA_Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -9,6 +10,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace iWare_SCADA_FormTest
{
@@ -43,5 +45,143 @@
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string path = ConfigHelper.GetConfigString("OP60QualityData_Test");
                var newFiles = FileHelper.DetectNewFiles(path, "*.dfq", 300, DateTime.Now.AddDays(-100), DateTime.Now.AddDays(1));
                foreach (System.IO.FileInfo file in newFiles)
                {
                    //MessageBox.Show("找到文件:" + file.FullName);
                    var toPath = file.FullName.Replace("Measuring_Data_df_Test", "Measuring_Data_df_Copy");
                    //MessageBox.Show("要移动到:" + file.FullName);
                    File.Move(file.FullName, toPath);//移动
                }
                MessageBox.Show("成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常:" + ex.Message);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                string path = ConfigHelper.GetConfigString("OP60QualityData_Zhengshi");
                var newFiles = FileHelper.DetectNewFiles(path, "*.dfq", 300, DateTime.Now.AddDays(-100), DateTime.Now.AddDays(1));
                foreach (System.IO.FileInfo source_doFile in newFiles)
                {
                    //MessageBox.Show("找到FullName:" + source_doFile.FullName+ ",Name:" + source_doFile.Name);
                    //目标文件的完整目录
                    string destFileName = source_doFile.FullName.Replace("Measuring_Data_dfq", "Measuring_Data_df_Copy");
                    string source_file_name = source_doFile.Name.Replace(".dfq", "");//不带扩展名的文件名字
                    destFileName = destFileName.Replace(source_file_name, source_file_name + "_" + "_" + DateTime.Now.ToString("yyyyMMddHHmmss"));
                    File.Copy(source_doFile.FullName, destFileName, true);
                    //FileInfo destFile = new FileInfo(destFileName);
                    //MessageBox.Show("新文件找到FullName:" + destFile.FullName + ",Name:" + destFile.Name);
                }
                MessageBox.Show("成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show("异常:" + ex.Message);
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
        }
        private void btn_TongJi_Click(object sender, EventArgs e)
        {
            //统计
            //某段时间的统计
            var str_start = this.dateTimePicker_Start.Value.ToString("yyyy-MM-dd" + " " + "00:00:00");
            var str_end = this.dateTimePicker_End.Value.ToString("yyyy-MM-dd" + " " + "23:59:59");
            var start = Convert.ToDateTime(str_start);
            var end = Convert.ToDateTime(str_end);
            int allPlacesCount = 0;
            List<string> strList = new List<string>() {
                "OP05","OP10","OP20","OP30","OP35","OP40","OP50","OP60","OP70","OP80"
            };
            var q_strList = string.Join(",", strList);
            var str = "";
            str += "时间范围: " + str_start + "至" + str_end + " \r\n";
            using (DbModel edm = new DbModel())
            {
                var allPlaces = edm.WorkPieceLog.Where(x =>
                 (x.CreatedTime >= start && x.CreatedTime <= end)).ToList();
                var groups = allPlaces.GroupBy(x => x.WorkingProcedure).OrderBy(x => x.Key);
                foreach (var gg in groups)
                {
                    var _key = gg.Key;
                    var _list = gg.ToList();
                    var emtype = "                      ";
                    var _list_youzhi = _list.Where(x => x.WorkPieceID.Length > 20 && x.WorkPieceID != emtype).ToList();
                    var _list_empty = _list.Where(x => string.IsNullOrEmpty(x.WorkPieceID) || x.WorkPieceID == emtype).ToList();
                    var _list_other = _list.Where(x => !((x.WorkPieceID.Length > 20 && x.WorkPieceID != emtype) || (string.IsNullOrEmpty(x.WorkPieceID) || x.WorkPieceID == emtype))).ToList();
                    var _list_other_str_list = _list_other.Select(x => x.WorkPieceID).Distinct().ToList();
                    var _list_other_str = string.Join("|", _list_other_str_list);
                    str += $"==================【{_key}】========================= \r\n";
                    str += $"总量: {_list.Count()},正确二维码数:{_list_youzhi.Count()},空值:{_list_empty.Count},其他:{_list_other.Count},分别是{_list_other_str}  \r\n";
                    //再进行分组,统计 二维码不对的数据
                    var _list_qc_error = _list.Where(x => string.IsNullOrEmpty(x.WorkPieceID) || x.WorkPieceID.Length <= 20).ToList();
                    var group_qc_error = _list_qc_error.GroupBy(x => new { x.WorkPieceID, x.CreatedUserName });
                    str += $"二维码不对的数据,总量: {_list_qc_error.Count()}  \r\n";
                    foreach (var item in group_qc_error)
                    {
                        str += $"二维码不对的数据,WorkPieceID: {item.Key.WorkPieceID},CreatedUserName: {item.Key.CreatedUserName},数量:{item.ToList().Count()}  \r\n";
                    }
                    //再进行分组,统计 二维码对的数据
                    var group_qc_ok = _list_youzhi.GroupBy(x => new { x.CreatedUserName });
                    str += $"二维码正确的数据,总量: {_list_youzhi.Count()}  \r\n";
                    foreach (var item in group_qc_ok)
                    {
                        str += $"二维码正确的数据,CreatedUserName: {item.Key.CreatedUserName},数量:{item.ToList().Count()}  \r\n";
                    }
                    //再进行分组,统计 二维码对的数据-去重
                    var _list_youzhi_quchong = _list_youzhi.Select(x => new { x.CreatedUserName }).Distinct().ToList();
                    var group_qc_ok_quchong = _list_youzhi_quchong.GroupBy(x => new { x.CreatedUserName });
                    str += $"(去重后)二维码正确的数据,总量: {_list_youzhi_quchong.Count()}  \r\n";
                    foreach (var item in group_qc_ok_quchong)
                    {
                        str += $"(去重后)二维码正确的数据,CreatedUserName: {item.Key.CreatedUserName},数量:{item.ToList().Count()}  \r\n";
                    }
                    str += "\r\n";
                }
            }
            str += "\r\n";
            this.tb_TongJi.Text = str;
        }
    }
}