Jack.Peng
2021-03-25 e5bd758158da36fc8068cb6d686d8affc7f29639
1.读取文件全部单独拆分来读取,易于后期维护。
2个文件已添加
3个文件已修改
872 ■■■■ 已修改文件
P066.Data/Form1.cs 400 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
P066.Data/P066.Data.csproj 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
P066.Data/P066RunParam.cs 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
P066.Data/ReadFile.cs 258 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
P066.Data/WriteFile.cs 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
P066.Data/Form1.cs
@@ -19,8 +19,10 @@
        DirectoryInfo directoryInfo1;
        DirectoryInfo directoryInfo2;
        private P066RunParam runparam = new P066RunParam();
        private ReadFile readfile = new ReadFile();
        private WriteFile writefile = new WriteFile();
        public Form1()
        {
            InitializeComponent();
@@ -49,10 +51,9 @@
        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            var fileinfos11 = directoryInfo1.GetFiles().ToList().FindAll(a => a.Extension == ".csv");
            #region 读取文件夹下的所有文件,并将文件按照上下进行区分;上表格为fileInfo1,下表格为fileInfo2
            ;
            var fileinfos11 = directoryInfo1.GetFiles().ToList().FindAll(a => a.Extension == ".csv");
            List<FileInfo> fileInfo1 = new List<FileInfo>();
            List<FileInfo> fileInfo2 = new List<FileInfo>();
            for (int i = 0; i < fileinfos11.Count; i++)
@@ -66,7 +67,7 @@
                    fileInfo2.Add(fileinfos11[i]);
                }
            }
            #endregion
            List<ResultData> DataListMerge = new List<ResultData>();
            var listSum = new List<ResultData>();
            var JudgeListSum = new List<ResultData>();
@@ -79,16 +80,11 @@
            int ChuNum = 0;
            int FuNum = 0;
            int GuaNum = 0;
            #region//获取时间戳并排序
            var allLines1 = File.ReadAllLines(fileInfo1[0].FullName, Encoding.Default);
            List<ResultData> dataList1 = new List<ResultData>();
            if (allLines1.Length > 1)
            {
                dataList1 = GetData(allLines1,GetDefactType(fileInfo1[0]));
            }
            var dataGroup111 = dataList1.GroupBy(a => a.TimeTip);
            #region 读取一个表格中所有时间戳并排序
            var dataList = GetFileData(fileInfo1[0]);
            var dataGroup = dataList.GroupBy(a => a.TimeTip);
            var dataListSum22 = new List<string>();
            foreach (var item in dataGroup111)
            foreach (var item in dataGroup)
            {
                dataListSum22.Add(item.Key);
            }
@@ -96,14 +92,14 @@
            dataListSum22.Sort();
            #endregion
            #region 读取划伤、镀膜破损文件夹文件
            if (directoryInfo2 != null)
            {
                var fileinfos22 = directoryInfo2.GetFiles().ToList().FindAll(a=>a.Extension==".csv");
                for (int i = 0; i < fileinfos22.Count; i++)
            for (int i = 0; i < fileinfos22.Count; i++)
            {
                var allLines = File.ReadAllLines(fileinfos22[i].FullName, Encoding.Default);
                var list = GetData(allLines, GetDefactType(fileinfos22[i])).FindAll(a=>!a.Result);      /*CompareFile(fileInfo1[i], fileInfo2[i],dataListSum22)*/
               var list = GetFileData(fileinfos22[i]);
                GetMaxSize(list);
                if (fileinfos22[i].Name.Contains("划伤"))
                {
@@ -123,15 +119,11 @@
                directoryInfo2 = null;
            }
            #endregion
            for (int i = 0; i < fileInfo1.Count; i++)
             {
                CompareFile(fileInfo1[i], fileInfo2[i], dataListSum22, out DataListMerge);
                var list = DataListMerge;      /*CompareFile(fileInfo1[i], fileInfo2[i],dataListSum22)*/
                var list= CompareFile(fileInfo1[i], fileInfo2[i], dataListSum22);
                if (fileInfo1[i].Name.Contains("白点"))
                {
                    WhiteI++;
@@ -146,8 +138,9 @@
                }
                string currPath = "";
                #region//判断是初检文件夹还是复检文件夹
                string currPath = "";
                if (fileInfo1[i].Name.Contains("初检中框"))
                {
                    ChuNum++;
@@ -231,14 +224,14 @@
            foreach (var item in dataListSum22)
            {
                var Lens1 = listSum.FindAll(a => a.TimeTip == item&&a.Lensnumber==1);
                WriteJR(Lens1,item,1,file12);
                writefile.WriteJR(Lens1,item,1,file12);
                var Lens2 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 2);
                WriteJR(Lens2,"",2,file12);
                writefile.WriteJR(Lens2,"",2,file12);
                var Lens3 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 3);
                WriteJR(Lens3,"",3,file12);
                writefile.WriteJR(Lens3,"",3,file12);
                var Lens4 = listSum.FindAll(a => a.TimeTip == item && a.Lensnumber == 4);
                WriteJR(Lens4,"",4,file12);
                writefile.WriteJR(Lens4,"",4,file12);
            }
            #endregion
@@ -283,25 +276,11 @@
        }
        private void CompareFile(FileInfo fileInfo1, FileInfo fileInfo2,List<string> DataTipsor,out List<ResultData> DataListMerger)
        #region 两个表格进行比较,如果两个表格中有设备判断标准不统一,将该点变为NG,删除两个表格中NG点相近的最小尺寸点.
        private List<ResultData> CompareFile(FileInfo fileInfo1, FileInfo fileInfo2,List<string> DataTipsor)
        {
            var allLines1 = File.ReadAllLines(fileInfo1.FullName, Encoding.Default);
            var allLines2 = File.ReadAllLines(fileInfo2.FullName, Encoding.Default);
            List<ResultData> dataList1 = new List<ResultData>();
            List<ResultData> dataList2 = new List<ResultData>();
            string defectType1 = "";
            string defectType2 = "";
            defectType1 = GetDefactType(fileInfo1);
            defectType2 = GetDefactType(fileInfo2);
            if (allLines1.Length>1)
            {
                dataList1 = GetData(allLines1,defectType1);
            }
            if (allLines2.Length > 1)
            {
                dataList2 = GetData(allLines2,defectType2);
            }
            var dataList1 = GetFileData(fileInfo1);
            var dataList2 = GetFileData(fileInfo2);
            var dataList = new List<ResultData>();
            foreach (var item in DataTipsor)
            {
@@ -314,14 +293,11 @@
                GetMaxSize(list2);
                for (int i = 0; i < list1.Count; i++)
                {
                    for (int j = 0; j < list2.Count; j++)
                    {
                        if (list1[i].JudgmentResult != list2[j].JudgmentResult)
                        {
                            list1[i].JudgmentResult = "NG";
                            list2[j].JudgmentResult = "NG";
                            list1[i].JudgmentResult = list2[j].JudgmentResult = "NG";
                        }
                        if (list1[i].PostTreatmentResults.Length<list2[j].PostTreatmentResults.Length)
                        {
@@ -331,7 +307,6 @@
                        {
                            list2[j].PostTreatmentResults = list1[i].PostTreatmentResults;
                        }
                        var distance = GetDistance(list1[i].X, list1[i].Y, list2[j].X, list2[j].Y);
                        if (distance < 20)
                        {
@@ -344,13 +319,9 @@
                            {
                                itemToRemove.Add(list1[i]);
                            }
                        }
                    }
                }
                dataList.AddRange(list1);
                dataList.AddRange(list2);
                for (int i = 0; i < itemToRemove.Count; i++)
@@ -358,14 +329,13 @@
                    dataList.Remove(itemToRemove[i]);
                }
            }
            DataListMerger=dataList;
            return dataList;
        }
        #endregion
        //获取中框角度和位置
        #region   获取中框角度和位置
        private List<ResultData> GetMidLocation(List<ResultData> list)
        {
            var group = list.GroupBy(a => a.TimeTip);
@@ -478,7 +448,8 @@
            }
            return list;
        }
        //获取中框刮白角度和位置
        #endregion
        #region 获取中框刮白角度和位置
        private List<ResultData> GetWhiteLocation(List<ResultData> list)
        {
            var group = list.GroupBy(a => a.TimeTip);
@@ -607,7 +578,9 @@
            }
            return list;
        }
        //获取背板角度和位置
        #endregion
        #region 获取背板角度和位置
        private List<ResultData> GetBkLocation(List<ResultData> list)
        {
            var group = list.GroupBy(a => a.TimeTip);
@@ -706,113 +679,20 @@
            }
            return list;
        }
        //写入设备判断结果报表
        private void WriteJR(List<ResultData> Lens,string item,int LensNumb, string file12)
        {
            if (Lens.Count == 0)
            {
                var content11 = $"{item},{LensNumb},{"OK"}";
                File.AppendAllText(file12, content11, Encoding.UTF8);
                File.AppendAllText(file12, "\r\n");
            }
            else
            {
                if (Lens[0].DefectType == "镀膜破损")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "镀膜破损")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{"-"},{"-"},{"-"},{"-"},{"-"},{"-"}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else if (Lens[0].DefectType == "划伤"|| Lens[0].DefectType == "脏污")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "划伤"|| Lens[i].DefectType == "脏污")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else if (Lens[0].DefectType == "刮白")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "刮白")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType},{Lens[0].PostTreatmentResults}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                        File.AppendAllText(file12, content111, Encoding.UTF8);
                        File.AppendAllText(file12, "\r\n");
                    }
                }
            }
        }
        //计算两点之间距离
        #endregion
        #region  计算两点之间距离
        private double GetDistance(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
        }
        //计算角度
        #endregion
          #region 计算角度
        private double GetAngle(double x1, double y1,double size)
        {
            return Math.Atan2((y1 - size), (x1 - size)) * (180 / Math.PI);
        }
        //计算最大尺寸
        #endregion
         #region 计算最大尺寸
        private List<ResultData> GetMaxSize(List<ResultData> list)
        {
            for (int i = 0; i < list.Count; i++)
@@ -829,9 +709,8 @@
            }
            return list;
        }
        //获取文件名称并确定缺陷类型
        #endregion
        #region 获取文件名称并确定缺陷类型
        private string GetDefactType(FileInfo fileinfo)
        {
            string defatType="";
@@ -857,181 +736,34 @@
            return defatType;
        }
        private List<ResultData> GetData(string[] allLines,string defectType)
        #endregion
        private List <ResultData> GetFileData(FileInfo fileInfos)
        {
            var dataList = new List<ResultData>();
            var nametemp = allLines[1].Split(',')[0];
            var resulttemp = allLines[1].Split(',')[1];
            string Ptr = "";
            string deTy = "";
            for (int i = 1; i < allLines.Length; i++)
            var allLines = File.ReadAllLines(fileInfos.FullName, Encoding.Default);
            List<ResultData> dataList = new List<ResultData>();
            if (allLines.Length > 1)
            {
                var data = allLines[i].Split(',');
                if (data[0] == "")
                switch (GetDefactType(fileInfos))
                {
                    data[0] = nametemp;
                    data[1] = resulttemp;
                    if (defectType == "白点")
                    {
                        data[10] = Ptr;
                        deTy = "白点";
                    }
                    case "白点":
                        dataList = readfile.GetWhiteFile(allLines);
                        break;
                    case "刮白":
                        dataList = readfile.GetWhiteningFile(allLines);
                        break;
                    case "划伤":
                        dataList = readfile.GetScratchPartFile(allLines);
                        break;
                    case "镀膜破损":
                        dataList = readfile.GetZoomPartFile(allLines);
                        break;
                    //default:
                    //    dataList1 = null;
                    //    break;
                }
                if (defectType == "刮白")
                {
                    Ptr = "刮白";
                    deTy = "刮白";
                }
                else if (defectType == "划伤")
                {
                    Ptr = "";
                    if (data[3]!="OK")
                    {
                        deTy = data[3];
                    }
                    else
                    {
                        deTy = "";
                    }
                }
                else if (defectType == "白点")
                {
                    Ptr = data[10];
                    deTy = "白点";
                }
                if (defectType== "镀膜破损")
                {
                    dataList.Add(new ResultData()
                    {
                        TimeTip = data[0].Split('-')[0],
                        ImageFileName = data[0],
                        JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                        Result = data[1] == "OK",
                        DefectType = defectType,
                    }); ; ;
                    continue;
                }
                if (data[6] == "-")
                {
                    dataList.Add(new ResultData()
                    {
                        TimeTip = data[0].Split('-')[0],
                        ImageFileName = data[0],
                        JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                        Result = data[3] == "OK",
                    }); ; ;
                    continue;
                }
               else if (data.Length<5)
                {
                    dataList.Add(new ResultData()
                    {
                        TimeTip = data[0].Split('-')[0],
                        ImageFileName = data[0],
                        JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                        Result = data[3] == "OK",
                    }); ; ;
                    continue;
                }
                var data6 = data[6].Split('#').ToList();
                data6.Remove("");
                var temp6 = Convert.ToInt32(data6[0]);
                for (int a6 = 0; a6 < data6.Count; a6++)
                {
                    if (Convert.ToInt32(data6[a6]) > temp6)
                    {
                        temp6 = Convert.ToInt32(data6[a6]);
                    }
                }
                data[6] = Convert.ToString(temp6);
                var data7 = data[7].Split('#').ToList();
                data7.Remove("");
                var temp7 = Convert.ToInt32(data7[0]);
                for (int a7 = 0; a7 < data7.Count; a7++)
                {
                    if (Convert.ToInt32(data7[a7]) > temp7)
                    {
                        temp7 = Convert.ToInt32(data7[a7]);
                    }
                }
                data[7] = Convert.ToString(temp7);
                dataList.Add(new ResultData()
                {
                    TimeTip = data[0].Split('-')[0],
                    ImageFileName = data[0],
                    JudgmentResult = data[1]== "OK" ? "OK" :"NG",
                    Result = data[3] == "OK",
                    Probability = Convert.ToDouble(data[4]),
                    Uncertainty = Convert.ToDouble(data[5]),
                    //Height = Convert.ToDouble(data[6].Replace("#", "").Replace("-", "")),
                    //Width = Convert.ToDouble(data[7].Replace("#", "").Replace("-", "")),
                    Height = Convert.ToDouble(data[6]),
                    Width = Convert.ToDouble(data[7]),
                    X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
                    Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
                    DefectType = deTy,
                    PostTreatmentResults = Ptr,
                }); ; ;
                nametemp = data[0];
                resulttemp = data[1];
                //Ptr = data[10];
            }
            return dataList;
        }
    }
    public class ResultData
    {
        public string TimeTip = "";
        public string JudgmentResult = "";
        public string ImageFileName = "";
        public bool Result = true;
        public int Lensnumber = 0;
        public double Probability = 0;
        public double Uncertainty = 0;
        public double Height = 0;
        public double Width = 0;
        public double X = 0;
        public double Y = 0;
        public double ex = 0;
        public string location = "";
        public double angle = 0;
        public double R = 0;
        public string DefectType = "";
        public string PostTreatmentResults = "";
    }
P066.Data/P066.Data.csproj
@@ -47,6 +47,7 @@
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="ReadFile.cs" />
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
@@ -56,6 +57,7 @@
    <Compile Include="P066RunParam.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="WriteFile.cs" />
    <EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
    </EmbeddedResource>
P066.Data/P066RunParam.cs
@@ -26,109 +26,5 @@
        public double BkLens4R1;
        //public double BkLens4R2;
    }
    public class P066ReadFile
    {
        public List<ResultData1> GetWhiteFile(string[] allLines)
        {
            var dataList = new List<ResultData1>();
            var nametemp = allLines[1].Split(',')[0];
            var resulttemp = allLines[1].Split(',')[1];
            string Ptr = "";
            string deTy = "";
            for (int i = 1; i < allLines.Length; i++)
            {
                var data = allLines[i].Split(',');
                if (data[0] == "")
                {
                    data[0] = nametemp;
                    data[1] = resulttemp;
                }
                if (data[6] == "-")
                {
                    dataList.Add(new ResultData1()
                    {
                        TimeTip = data[0].Split('-')[0],
                        ImageFileName = data[0],
                        JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                        Result = data[3] == "OK",
                    }); ; ;
                    continue;
                }
                //将地7、8列中选最大像素点
                data[6] = SelectMaxPiont(data[6]);
                data[7] = SelectMaxPiont(data[7]);
                dataList.Add(new ResultData1()
                {
                    TimeTip = data[0].Split('-')[0],
                    ImageFileName = data[0],
                    JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                    Result = data[3] == "OK",
                    Probability = Convert.ToDouble(data[4]),
                    Uncertainty = Convert.ToDouble(data[5]),
                    //Height = Convert.ToDouble(data[6].Replace("#", "").Replace("-", "")),
                    //Width = Convert.ToDouble(data[7].Replace("#", "").Replace("-", "")),
                    Height = Convert.ToDouble(data[6]),
                    Width = Convert.ToDouble(data[7]),
                    X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
                    Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
                    DefectType = deTy,
                    PostTreatmentResults = Ptr,
                }); ; ;
                nametemp = data[0];
                resulttemp = data[1];
            }
            return dataList;
        }
        private string SelectMaxPiont(string Data)
        {
            var data = Data.Split('#').ToList();
            data.Remove("");
            var temp = Convert.ToInt32(data[0]);
            for (int i = 0; i < data.Count; i++)
            {
                if (Convert.ToInt32(data[i]) > temp)
                {
                    temp = Convert.ToInt32(data[i]);
                }
            }
            return Convert.ToString(temp);
        }
    }
    public class ResultData1
    {
        public string TimeTip = "";
        public string JudgmentResult = "";
        public string ImageFileName = "";
        public bool Result = true;
        public int Lensnumber = 0;
        public double Probability = 0;
        public double Uncertainty = 0;
        public double Height = 0;
        public double Width = 0;
        public double X = 0;
        public double Y = 0;
        public double ex = 0;
        public string location = "";
        public double angle = 0;
        public double R = 0;
        public string DefectType = "";
        public string PostTreatmentResults = "";
    }
}
   }
P066.Data/ReadFile.cs
New file
@@ -0,0 +1,258 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace P066.Data
{
    class ReadFile
    {
            #region 读取白点表格
            public List<ResultData> GetWhiteFile(string[] allLines)
            {
                var dataList = new List<ResultData>();
                var nametemp = allLines[1].Split(',')[0];
                var resulttemp = allLines[1].Split(',')[1];
                string Ptr = "";
                for (int i = 1; i < allLines.Length; i++)
                {
                    var data = allLines[i].Split(',');
                    if (data[0] == "")
                    {
                        data[0] = nametemp;
                        data[1] = resulttemp;
                        data[10] = Ptr;
                    }
                    try
                    {
                        //将地7、8列中选最大像素点
                        data[6] = SelectMaxPiont(data[6]);
                        data[7] = SelectMaxPiont(data[7]);
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                            Result = data[3] == "OK",
                            Probability = Convert.ToDouble(data[4]),
                            Uncertainty = Convert.ToDouble(data[5]),
                            Height = Convert.ToDouble(data[6]),
                            Width = Convert.ToDouble(data[7]),
                            X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
                            Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
                            DefectType = data[3] == "OK" ? "OK" : "白点",
                            PostTreatmentResults = data[10],
                        }); ; ;
                        nametemp = data[0];
                        resulttemp = data[1];
                        Ptr = data[10];
                    }
                    catch (Exception)
                    {
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                            Result = data[3] == "OK",
                        }); ; ;
                    }
                }
                return dataList;
            }
            #endregion
            #region 读取刮白表格
            public List<ResultData> GetWhiteningFile(string[] allLines)
            {
                var dataList = new List<ResultData>();
                var nametemp = allLines[1].Split(',')[0];
                var resulttemp = allLines[1].Split(',')[1];
                for (int i = 1; i < allLines.Length; i++)
                {
                    var data = allLines[i].Split(',');
                    if (data[0] == "")
                    {
                        data[0] = nametemp;
                        data[1] = resulttemp;
                    }
                    try
                    {
                        //将地7、8列中选最大像素点
                        data[6] = SelectMaxPiont(data[6]);
                        data[7] = SelectMaxPiont(data[7]);
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                            Result = data[3] == "OK",
                            Probability = Convert.ToDouble(data[4]),
                            Uncertainty = Convert.ToDouble(data[5]),
                            Height = Convert.ToDouble(data[6]),
                            Width = Convert.ToDouble(data[7]),
                            X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
                            Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
                            DefectType = data[3] == "OK" ? "OK" : "刮白",
                            PostTreatmentResults = "刮白",
                        }); ; ;
                        nametemp = data[0];
                        resulttemp = data[1];
                    }
                    catch (Exception)
                    {
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                            Result = data[3] == "OK",
                            PostTreatmentResults = "刮白",
                        }); ; ;
                    }
                }
                return dataList;
            }
            #endregion
            #region 读取划伤表格
            public List<ResultData> GetScratchPartFile(string[] allLines)
            {
                var dataList = new List<ResultData>();
                var nametemp = allLines[1].Split(',')[0];
                var resulttemp = allLines[1].Split(',')[1];
                for (int i = 1; i < allLines.Length; i++)
                {
                    var data = allLines[i].Split(',');
                    if (data[0] == "")
                    {
                        data[0] = nametemp;
                        data[1] = resulttemp;
                    }
                    try
                    {
                    if (data[1]!="OK")
                    {
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = "NG",
                            Result = data[3] == "OK",
                            Probability = Convert.ToDouble(data[4]),
                            Uncertainty = Convert.ToDouble(data[5]),
                            Height = Convert.ToDouble(data[6]),
                            Width = Convert.ToDouble(data[7]),
                            X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")),
                            Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")),
                            DefectType = data[3],
                            PostTreatmentResults = "划伤",
                        }); ; ;
                        nametemp = data[0];
                        resulttemp = data[1];
                    }
                    }
                    catch (Exception)
                    {
                        dataList.Add(new ResultData()
                        {
                            TimeTip = data[0].Split('-')[0],
                            ImageFileName = data[0],
                            JudgmentResult = data[1] == "OK" ? "OK" : "NG",
                            Result = data[3] == "OK",
                        }); ; ;
                    }
                }
                return dataList;
            }
            #endregion
            #region 读取镀膜破损表格
            public List<ResultData> GetZoomPartFile(string[] allLines)
            {
                var dataList = new List<ResultData>();
                for (int i = 1; i < allLines.Length; i++)
                {
                    var data = allLines[i].Split(',');
                if (data[1]!="OK")
                {
                    dataList.Add(new ResultData()
                    {
                        TimeTip = data[0].Split('-')[0],
                        ImageFileName = data[0],
                        JudgmentResult = "NG",
                        DefectType = data[1],
                        PostTreatmentResults = "镀膜破损",
                    }); ; ;
                }
                }
                return dataList;
            }
            #endregion
            ////将地7、8列中选最大像素点
            private string SelectMaxPiont(string Data)
            {
                var data = Data.Split('#').ToList();
                data.Remove("");
                var temp = Convert.ToInt32(data[0]);
                for (int i = 0; i < data.Count; i++)
                {
                    if (Convert.ToInt32(data[i]) > temp)
                    {
                        temp = Convert.ToInt32(data[i]);
                    }
                }
                return Convert.ToString(temp);
            }
    }
    public class ResultData
    {
        public string TimeTip = "";
        public string JudgmentResult = "";
        public string ImageFileName = "";
        public bool Result = true;
        public int Lensnumber = 0;
        public double Probability = 0;
        public double Uncertainty = 0;
        public double Height = 0;
        public double Width = 0;
        public double X = 0;
        public double Y = 0;
        public double ex = 0;
        public string location = "";
        public double angle = 0;
        public double R = 0;
        public string DefectType = "";
        public string PostTreatmentResults = "";
    }
}
P066.Data/WriteFile.cs
New file
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace P066.Data
{
    class WriteFile
    {
        #region 写入设备判断结果报表
        public void WriteJR(List<ResultData> Lens, string item, int LensNumb, string file12)
        {
            if (Lens.Count == 0)
            {
                var content11 = $"{item},{LensNumb},{"OK"}";
                File.AppendAllText(file12, content11, Encoding.UTF8);
                File.AppendAllText(file12, "\r\n");
            }
            else
            {
                if (Lens[0].DefectType == "镀膜破损")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "镀膜破损")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{"-"},{"-"},{"-"},{"-"},{"-"},{"-"}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else if (Lens[0].DefectType == "划伤" || Lens[0].DefectType == "脏污")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "划伤" || Lens[i].DefectType == "脏污")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else if (Lens[0].DefectType == "刮白")
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        if (Lens[i].DefectType == "刮白")
                        {
                            var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                        else
                        {
                            var content111 = $"{""},{""},{""},{Lens[i].DefectType},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                            File.AppendAllText(file12, content111, Encoding.UTF8);
                            File.AppendAllText(file12, "\r\n");
                        }
                    }
                }
                else
                {
                    var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType},{Lens[0].PostTreatmentResults}";
                    File.AppendAllText(file12, content11, Encoding.UTF8);
                    File.AppendAllText(file12, "\r\n");
                    for (int i = 0; i < Lens.Count; i++)
                    {
                        var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}";
                        File.AppendAllText(file12, content111, Encoding.UTF8);
                        File.AppendAllText(file12, "\r\n");
                    }
                }
            }
        }
        #endregion
    }
}