private void CheckData() { var info = string.Empty; if (Dict.Count == 0) { info = "未获取数据库相关核对数据"; _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } if (ExcelDict.Count == 0) { info = "未获取Excel文件中的相关数据"; _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } foreach (var entry in Dict) { var xzc = entry.Key; if (!ExcelDict.ContainsKey(xzc)) { info = string.Format("表格:{0}中不存在乡镇代码【{1}】乡镇名称【{2}】的汇总数据,请核对", ExcelName, xzc.XZCDM, xzc.XZCMC); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, Project = CheckProject.汇总表与数据库图层逻辑一致性, TableName = ExcelName, Description = info }); continue; } var access = entry.Value; var excels = ExcelDict[xzc]; foreach (var value in access) { var excel = excels.FirstOrDefault(e => e.Index == value.Index); if (excel == null) { info = string.Format("检验乡镇代码【{0}】乡镇名称【{1}】对应{2}的统计值时,未在Excel表格中找到,请核对", xzc.XZCDM, xzc.XZCMC, value.Title); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, Project = CheckProject.汇总表与数据库图层逻辑一致性, TableName = ExcelName, BSM = value.Title, Description = info }); continue; } switch (value.Type) { case ExcelType.Double: if (Math.Abs((double)value.Val - (double)excel.Val) > 0.001) { info = string.Format("乡镇代码【{0}】乡镇名称【{1}】中{2}的值在数据库中合计值与表格中填写的值容差率超过0.0001,请核对", xzc.XZCDM, xzc.XZCMC, value.Title); _paralleQuestions.Add(new Question { Code = "6102", Name = Name, TableName = ExcelName, Project = CheckProject.表格汇总面积和数据库汇总面积一致性, Description = info }); } break; case ExcelType.Int: if ((int)value.Val != (int)excel.Val) { info = string.Format("乡镇代码【{0}】乡镇名称【{1}】中{2}的值在数据库中合计值【{3}】与表格中填写的值【{4}】不相等,请核对", xzc.XZCDM, xzc.XZCMC, (int)value.Val, (int)excel.Val); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } break; } } } }
private void CheckData() { var info = string.Empty; var dou = .0; if (Dict.Count == 0) { info = "未获取数据库相关核对数据"; _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } if (ExcelDict.Count == 0) { info = "未获取Excel文件中的相关数据"; _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } foreach (var entry in Dict) { var xzc = entry.Key; var access = entry.Value; if (!access.Any(e => e.Val != null && !string.IsNullOrEmpty(e.Val.ToString()))) { continue; } var sum = access.Where(e => e.Val != null && !string.IsNullOrEmpty(e.Val.ToString())).Sum(e => double.TryParse(e.Val.ToString(), out dou)?dou:.0); if (sum > 0) { } else { continue; } if (!ExcelDict.ContainsKey(xzc)) { info = string.Format("表格:{0}中不存在乡镇代码【{1}】的汇总数据,请核对", ExcelName, xzc); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, Project = CheckProject.汇总表与数据库图层逻辑一致性, TableName = ExcelName, Description = info }); continue; } var excels = ExcelDict[xzc]; foreach (var value in access) { var excel = excels.FirstOrDefault(e => e.Index == value.Index); if (excel == null) { info = string.Format("检验乡镇代码【{0}]对应{1}的统计值时,未在Excel表格中找到,请核对", xzc, value.Title); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, Project = CheckProject.汇总表与数据库图层逻辑一致性, TableName = ExcelName, BSM = value.Title, Description = info }); continue; } switch (value.Type) { case ExcelType.Double: var a = .0; var b = .0; double.TryParse(value.Val.ToString(), out a); double.TryParse(excel.Val.ToString(), out b); if (Math.Abs(a - b) > 0.001) { info = string.Format("乡镇代码【{0}】中{1}的值在数据库中合计值【{2}】与表格中填写的值【{3}】容差率超过0.0001,请核对", xzc, value.Title, a, b); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.表格汇总面积和数据库汇总面积一致性, Description = info }); } break; case ExcelType.Int: var l = 0; var m = 0; int.TryParse(value.Val.ToString(), out l); int.TryParse(excel.Val.ToString(), out m); if (l != m) { info = string.Format("乡镇代码【{0}】中{1}的值在数据库中合计值【{2}】与表格中填写的值【{3}】不相等,请核对", xzc, value.Title, l, m); _paralleQuestions.Add(new Question { Code = "6101", Name = Name, TableName = ExcelName, Project = CheckProject.汇总表与数据库图层逻辑一致性, Description = info }); } break; } } } }