public static void ins() { ResultUserControl resultUserControl = new ResultUserControl(); resultUserControl.Results(); //errorPers = resultUserControl.errorPer(); }
private void ResultDetection_Click(object sender, EventArgs e) { PanWindow.Controls.Clear(); ResultUserControl resultUserControl = new ResultUserControl(); resultUserControl.Dock = DockStyle.Fill; PanWindow.Controls.Add(resultUserControl); }
/// <summary> /// 本来将UI逻辑写在公共类里面不符合模块化松耦合的设计理念,但巡检和手动的检测的功能是一样的,涉及到对UI的操作, /// 还是需要UI逻辑。所以采用灵活的方式将检测的操作封装到公共类里面,作为一个组件单元供检测和巡检调用, /// 可以统一维护。实现了检测逻辑的统一性与通用性、模块化。因为涉及到UI的交互, /// 但控件是作为窗体的保护成员出现的,而交互的控件相对固定且数量可以接受,所以将控件作为参数传入方法 /// </summary> /// <param name="label">描述当前操作的Label</param> /// <param name="textBox">进度详细信息</param> /// <param name="progressBar">进度条</param> public static void Test(Label label, TextBox textBox, ProgressBar progressBar, params NotifyIcon[] notifyIcon) { List <ErrorlistAll> errorList = new List <ErrorlistAll>(); List <ErrorLogList> repeatErrorList = new List <ErrorLogList>(); List <ErrorLogList> whiteErrorList = new List <ErrorLogList>(); List <ErrorLogList> DPIErrorList = new List <ErrorLogList>(); List <ErrorLogList> ItalicErrorList = new List <ErrorLogList>(); List <ErrorLogList> paperdis = new List <ErrorLogList>(); string errorPath = ""; if (notifyIcon.Length > 0) { notifyIcon[0].ShowBalloonTip(10000); } Dictionary <string, string> settings = UIUtil.ReadSettings(); string folder = UIUtil.GetDictionaryValue(settings, "Folder"), fileName; label.Text = "检测中..."; label.Refresh(); textBox.Text = "开始检测"; textBox.Refresh(); progressBar.Value = 0; progressBar.Refresh(); string str = progressBar.Value.ToString() + "%"; progressBar.Value = 0; Dictionary <string, object> testResult = Index.TestResult; testResult.Clear(); Index.TestResultStr = ""; //空白页检测 bool whiteTest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateWhite"); //重复文件检测 bool repeatTest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateRepeat"); //重复文件(MD5)检测 bool repeatMD5Test = UIUtil.GetDictionaryBooleanVal(settings, "ValidateRepeatMD5"); //挂接检测 bool hookTest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateHook"); //条目检测 bool directoriesTest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateDirectories"); //DPI检测 bool DPITest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateDPI"); //倾斜度检测 bool ItalicTest = UIUtil.GetDictionaryBooleanVal(settings, "ValidateItalic"); //图幅检测 bool boolTufu = UIUtil.GetDictionaryBooleanVal(settings, "tufu"); decimal DPI, Italic; decimal whitePercent = 0; if (whiteTest) { whitePercent = UIUtil.GetDictionaryDecimalVal(settings, "WhitePercent"); } bool result, whiteResult, repeatResult, repeatMD5Result, DPIResult, ItalicResult; if (!String.IsNullOrWhiteSpace(folder) && Directory.Exists(folder)) { List <string> repeatFiles = new List <string>(); List <string> repeatFilesMD5 = new List <string>(); List <FileInfo> repeatTestedFiles = new List <FileInfo>(); List <FileInfo> repeatMD5TestedFiles = new List <FileInfo>(); DirectoryInfo directoryInfo = new DirectoryInfo(folder); DirectoryInfo[] archiveDis = directoryInfo.GetDirectories(); FileInfo[] fileInfos; FileInfo fileInfo; int count = 0, passedCount = 0, failCount = 0, nullpage = 0, dpitestpage = 0, italicpage = 0, archiveCount = archiveDis.Length, length, counts = 0, AFei = 0, AZero = 0, AOne = 0, ATwo = 0, AThree = 0, AFour = 0, i, j;//archiceCount文件夹数量 double PassRateNum = 1; long passedLength = 0, failLength = 0; int a = 0; //子文件总数的参数 int b = 0; //进度条参数 System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(folder); counts = GetFilesCount(dirInfo); /// for (i = 0; i < archiveCount; i++) { textBox.Text += "\r\n\r\n检测文件夹:\"" + archiveDis[i].Name + "\""; textBox.Refresh(); fileInfos = archiveDis[i].GetFiles(); length = fileInfos.Length;//子文件见图片数量 count += length; for (j = 0; j < length; j++) { b = b + 1; progressBar.Value = ((b * 100 / counts)) % 100; progressBar.Refresh(); fileInfo = fileInfos[j]; fileName = fileInfo.Name; if (fileName != "Thumbs.db") { textBox.Text += "\r\n检测文件:\"" + fileName + "\""; textBox.Refresh(); result = true; //空白页检测 if (whiteTest) { textBox.Text += "\r\n空白页检测"; textBox.Refresh(); whiteResult = Tests.WhiteTest(fileInfo, Convert.ToDouble(whitePercent)); result = result && whiteResult; textBox.Text += "\t" + UIUtil.BooleanResultToString(whiteResult); if (!whiteResult) { errorPath += "空白页检测失败,路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "空白页", Status = "待解决" }; whiteErrorList.Add(errorLogList); nullpage++; } } //重复文件检测 if (repeatTest) { textBox.Text += "\r\n重复性检测"; textBox.Refresh(); repeatResult = true; foreach (FileInfo compareFile in repeatTestedFiles) { repeatResult = repeatResult && Tests.RepeatTest(compareFile, fileInfo); } if (!repeatResult) { repeatFiles.Add(fileInfo.Name); errorPath += "重复性检测失败,路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "重复文件", Status = "待解决" }; repeatErrorList.Add(errorLogList); } result = result && repeatResult; textBox.Text += "\t" + UIUtil.BooleanResultToString(repeatResult); repeatTestedFiles.Add(fileInfo); } //重复文件检测(MD5) if (repeatMD5Test) { textBox.Text += "\r\n重复性检测"; textBox.Refresh(); repeatMD5Result = true; foreach (FileInfo compareFile in repeatMD5TestedFiles) { repeatMD5Result = repeatMD5Result && Tests.RepeatTestMD5(compareFile, fileInfo); } if (!repeatMD5Result) { repeatFilesMD5.Add(fileInfo.Name); errorPath += "重复性检测失败,路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "重复文件", Status = "待解决" }; repeatErrorList.Add(errorLogList); } result = result && repeatMD5Result; textBox.Text += "\t" + UIUtil.BooleanResultToString(repeatMD5Result); repeatMD5TestedFiles.Add(fileInfo); } //DPI检测 if (DPITest) { DPI = UIUtil.GetDictionaryDecimalVal(settings, "DPI"); textBox.Text += "\r\nDPI检测"; textBox.Refresh(); DPIResult = Tests.ItalicTests(fileInfo, Convert.ToInt32(DPI)); result = result && DPIResult; textBox.Text += "\t" + UIUtil.BooleanResultToString(DPIResult); if (!DPIResult) { errorPath += "DPI低于" + DPI + ",路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "DPI", Status = "待解决" }; DPIErrorList.Add(errorLogList); dpitestpage++; } } //图幅检测 if (boolTufu) { textBox.Text += "\r\n图幅检测"; textBox.Refresh(); string papers = Tests.Azhi(fileInfo.FullName); textBox.Text += "\t" + papers; if (papers == "不是A纸规格" || papers == "图片异常") { errorPath += "不是A纸规格,路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "A纸规格", Status = "待解决" }; paperdis.Add(errorLogList); AFei++; } if (papers == "A0") { AZero++; } if (papers == "A1") { AOne++; } if (papers == "A2") { ATwo++; } if (papers == "A3") { AThree++; } if (papers == "A4") { AFour++; } } //倾斜度检测 if (ItalicTest) { Italic = UIUtil.GetDictionaryDecimalVal(settings, "ItalicDegree"); textBox.Text += "\r\n图像倾斜度检测"; textBox.Refresh(); ItalicResult = Tests.ItalicTests(fileInfo, Convert.ToInt32(Italic)); result = result && ItalicResult; textBox.Text += "\t" + UIUtil.BooleanResultToString(ItalicResult); if (!ItalicResult) { errorPath += "图像倾斜度大于" + Italic + ",路径:" + fileInfo.FullName + "\r\n"; ErrorLogList errorLogList = new ErrorLogList { ErrorPath = fileInfo.FullName, ErrorType = "倾斜度", Status = "待解决" }; ItalicErrorList.Add(errorLogList); italicpage++; } } //返回结果 if (result) { passedCount++; passedLength += fileInfo.Length; } else { failCount++; failLength += fileInfo.Length; } } else { count--; } } } //检测结果 testResult.Add("Count", count); testResult.Add("PassedCount", passedCount); testResult.Add("FailCount", failCount); testResult.Add("Length", passedLength + failLength); testResult.Add("PassedLength", passedLength); testResult.Add("FailLength", failLength); PassRateNum = (Convert.ToDouble(count) - Convert.ToDouble(failCount)) / Convert.ToDouble(count); //string.Format("{0:#.00%}", PassRateNum); PassRate = string.Format("{0:#.00%}", PassRateNum); ErrorlistAll errorlistAll = new ErrorlistAll { TestCount = count, ErrorCount = failCount, PassedCount = passedCount, PassedRate = PassRate }; errorList.Add(errorlistAll); if (whiteTest) { testResult.Add("nullpagenum", nullpage); } if (repeatTest) { testResult.Add("RepeatFiles", repeatFiles); } if (repeatMD5Test) { testResult.Add("RepeatFilesMD5", repeatFilesMD5); } if (DPITest) { testResult.Add("DpiNum", dpitestpage); } if (ItalicTest) { testResult.Add("ItalicNum", italicpage); } if (boolTufu) { testResult.Add("afei", AFei); testResult.Add("azero", AZero); testResult.Add("aone", AOne); testResult.Add("atwo", ATwo); testResult.Add("athree", AThree); testResult.Add("afour", AFour); } //缺少页数 if (hookTest) { string hookDirectoriesFile = UIUtil.GetDictionaryValue(settings, "HookDirectoriesFile"); decimal hookSheet = UIUtil.GetDictionaryDecimalVal(settings, "HookSheet"); decimal archiveIdField = UIUtil.GetDictionaryDecimalVal(settings, "ArchiveIdField"); decimal pageField = UIUtil.GetDictionaryDecimalVal(settings, "PageField"); if (!String.IsNullOrWhiteSpace(hookDirectoriesFile) && File.Exists(hookDirectoriesFile) && hookSheet >= 0 && pageField >= 0) { textBox.Text += "\r\n挂接缺漏页检测"; textBox.Refresh(); try { Dictionary <string, List <int> > archiveShortOfPages = Tests.ShortOfPagesTest(folder, hookDirectoriesFile, Convert.ToInt32(hookSheet), Convert.ToInt32(archiveIdField), Convert.ToInt32(pageField)); List <int> shortOfPages; foreach (string archiveId in archiveShortOfPages.Keys) { shortOfPages = archiveShortOfPages[archiveId]; if (shortOfPages != null && shortOfPages.Count > 0) { textBox.Text += "\r\n档号为" + archiveId + "的案卷缺少第"; for (int k = 0; k < shortOfPages.Count; k++) { textBox.Text += shortOfPages[k] + ","; } textBox.Text = textBox.Text.TrimEnd(',') + "页"; textBox.Refresh(); } } testResult.Add("ShortOfPages", archiveShortOfPages); } catch (IOException exp) { MessageBox.Show("您已打开了挂接条目Excel文件,系统无法访问,请关闭后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { textBox.Text += "\r\n已选择挂接检测,但设置不正确,已跳过挂接检测"; textBox.Refresh(); } } if (failCount > 0) { IndexWindow.erroNum++; } } else { textBox.Text += "\r\n未选择检测文件夹或检测文件夹不存在,已跳过文件检测!"; textBox.Refresh(); } if (directoriesTest) { string directoriesFile = UIUtil.GetDictionaryValue(settings, "DirectoriesFile"); decimal directoriesSheet = UIUtil.GetDictionaryDecimalVal(settings, "DirectoriesSheet"); Dictionary <string, string> filerule = new Dictionary <string, string>(); Dictionary <string, string> orderrule = new Dictionary <string, string>(); foreach (string item in settings.Keys) { if (item.StartsWith("FieldRule_")) { string sFieldIndex = item.Replace("FieldRule_", ""); string rulesetting = settings[item]; filerule.Add(item, rulesetting); } } if (!String.IsNullOrWhiteSpace(directoriesFile) && File.Exists(directoriesFile) && directoriesSheet >= 0) { textBox.Text += "\r\n条目检测"; textBox.Refresh(); try { Dictionary <string, Dictionary <string, Dictionary <string, string> > > directoriesErrors = Tests.DirectoriesTest(directoriesFile, Convert.ToInt32(directoriesSheet), filerule, orderrule); Dictionary <string, Dictionary <string, string> > directoryErrors; Dictionary <string, string> fieldErrors; object error; foreach (string rowIndex in directoriesErrors.Keys) { directoryErrors = directoriesErrors[rowIndex]; if (directoryErrors != null && directoryErrors.Count > 0) { if (rowIndex != "排序检测") { textBox.Text += "\r\n第" + rowIndex + "行条目错误:"; } else { textBox.Text += "\r\n排序检测:"; } textBox.Refresh(); //foreach (int field in directoryErrors.Keys) //{ // fieldErrors = directoryErrors[field]; // if (fieldErrors != null && fieldErrors.Count > 0) // { // textBox.Text += "\r\n第" + (field + 1) + "列:"; // textBox.Refresh(); // foreach (string rule in fieldErrors.Keys) // { // error = fieldErrors[rule]; // if (error != null) // textBox.Text += "[" + rule + ":" + error + "];"; // } // textBox.Text = textBox.Text.TrimEnd(';'); // textBox.Refresh(); // } //} } } testResult.Add("DirectoriesErrors", directoriesErrors); } catch (IOException exp) { MessageBox.Show("您已打开了需要检测的条目Excel文件,系统无法访问,请关闭后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { textBox.Text += "\r\n已选择条目检测,但设置不正确,已跳过条目检测"; textBox.Refresh(); } } progressBar.Value = 100; progressBar.Refresh(); textBox.Text += "\r\n检测结束"; textBox.Refresh(); Index.TestResultStr = textBox.Text; label.Text = "检测完成!"; CommonSettings.loads(); ResultUserControl.ins(); //打印报表文件 //logpaths = WriteLogs(CommonSettings.LogsPath, Index.TestResults + "\r\n\r\n详细日志:\r\n" + errorPath + "\r\n"); logpaths = Logs(CommonSettings.LogsPath, errorList, repeatErrorList, whiteErrorList, DPIErrorList, ItalicErrorList, paperdis); label.Refresh(); IndexWindow.testNum++; }