using ESRI.ArcGIS.Geodatabase;
using Kingo.RuleCheck.XJRuleCheck;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Kingo.RuleCheck
{
public class RuleCheckOpertion
{
///
/// 省级单图斑建库和审核任务包检查
///
///
///
///
/// 系统设置-需执行规则
///
public static List StartSJSHCheck(string dbPath, Dictionary workspace, string primityKey = "", List> excuteRules = null)
{
if (!System.IO.File.Exists(dbPath) || workspace == null)
{
throw new Exception("输入参数错误");
}
//解密DB包
CheckHelper.DBToMDBHelper dBToMDBHelper = new CheckHelper.DBToMDBHelper();
DataTable dt = dBToMDBHelper.SJDecryptDB(dbPath, primityKey,out string tempDBPath);
List result = new List();
List ruleTypes = new List()
{
RuleType.地类属性与举证照片逻辑性检查,
RuleType.数学基础规范性检查,
RuleType.图形属性规范性检查,
RuleType.通用类表内逻辑性检查,
RuleType.通用类表间逻辑性检查,
RuleType.单图斑建库人工检查,
};
DLParams.Init();
foreach (var item in ruleTypes)
{
//循环外业任务TBBSM检查
foreach (DataRow row in dt.Rows)
{
List rules = StartCheck(row[0] + string.Empty, tempDBPath, workspace, item, excuteRules);
if (rules != null && rules.Count > 0)
{
result.AddRange(rules);
}
}
}
return result;
}
///
/// 开始检查
///
///
///
///
/// 系统设置-需执行规则
/// 不执行规则
///
public static List StartCheck(string tbbsm, string sourcePath, Dictionary workspace, RuleType ruleType, List> excuteRules = null, List disExecuteRules = null)
{
List checkRst = new List();
RuleCheckBase_DTB ruleCheck = null;
switch (ruleType)
{
case RuleType.地类属性与举证照片逻辑性检查:
ruleCheck = new DLSXYJZZPCheck_DTB();
break;
case RuleType.数学基础规范性检查:
ruleCheck = new SJJCCheck_DTB();
break;
case RuleType.图形属性规范性检查:
ruleCheck = new TXSXCheck_DTB();
break;
case RuleType.通用类表内逻辑性检查:
ruleCheck = new TYLBBNLJXCheck_DTB();
break;
case RuleType.通用类表间逻辑性检查:
ruleCheck = new TYLBJLJXCheck_DTB();
break;
case RuleType.单图斑建库人工检查:
ruleCheck = new RGJCCheck();
break;
}
if (ruleCheck != null)
{
ruleCheck.TBBSM = tbbsm;
ruleCheck.ExcuteRules = excuteRules;
ruleCheck.DisExecuteRules = disExecuteRules;
checkRst = ruleCheck.ExcuteCheck(tbbsm, sourcePath, workspace);
if (ruleType == RuleType.单图斑建库人工检查)
checkRst = ruleCheck.AllRGError;
}
return checkRst;
}
///
/// 获取所有规则(20210721添加省级审核单图斑规则设置)
///
///
public static List> GetAllRules()
{
List> lisRules = new List>();
Type trypInfo = typeof(DLSXYJZZPCheck_DTB);// Program为类名 地类属性与举证照片逻辑性检查
//获得方法名
MethodInfo[] methodInfo = trypInfo.GetMethods();
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.地类属性与举证照片逻辑性检查.ToString())));
trypInfo = typeof(SJJCCheck_DTB);// Program为类名 数学基础规范性检查
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.数学基础规范性检查.ToString())));
trypInfo = typeof(TXSXCheck_DTB);// Program为类名 图形属性规范性检查
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.图形属性规范性检查.ToString())));
trypInfo = typeof(TYLBBNLJXCheck_DTB);// Program为类名 通用类表内逻辑性检查
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.通用类表内逻辑性检查.ToString())));
trypInfo = typeof(TYLBJLJXCheck_DTB);// Program为类名 通用类表间逻辑性检查
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.通用类表间逻辑性检查.ToString())));
trypInfo = typeof(RGJCCheck);// Program为类名 单图斑建库人工检查
trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.单图斑建库人工检查.ToString())));
//trypInfo = typeof(JZZPCheck);// Program为类名 举证照片规范性检查
//trypInfo.GetMethods().Select(m => m.Name).ToList().ForEach(x => lisRules.Add(new Tuple(x, RuleType.举证照片规范性检查.ToString())));
trypInfo = typeof(RuleCheckBase_DTB);// Program为类名
var rules = lisRules.Where(x => !trypInfo.GetMethods().Select(m => m.Name).Contains(x.Item1)).Distinct().ToList();
rules.Sort((x, y) => x.Item2 == y.Item2 ? x.Item1.CompareTo(y.Item1) : x.Item2.CompareTo(y.Item2));
return rules;
}
///
/// 县级预处理重叠检查
///
///
///
///
public static List StartYCLCheck(string dbPath, string primityKey = "")
{
try
{
if (!System.IO.File.Exists(dbPath))
{
throw new Exception("输入参数错误");
}
return YCLOverlapCheck.YCLCheck(dbPath);
}
catch (Exception ex)
{
throw ex;
}
}
#region 弃用
/////
///// 开始检查
/////
/////
/////
/////
///// 是否为首轮执行
///// 过程数据路径
///// 系统设置-需执行规则
///// 不执行规则
/////
//public static List StartCheck(string sourcePath, Dictionary workspace, RuleType ruleType, bool bFirstRun = true, string sProcessDataPath = "", List> excuteRules = null, List disExecuteRules = null)
//{
// List checkRst = new List();
// RuleCheckBase ruleCheck = null;
// switch (ruleType)
// {
// case RuleType.举证照片规范性检查:
// ruleCheck = new JZZPCheck();
// break;
// case RuleType.地类属性与举证照片逻辑性检查:
// ruleCheck = new DLSXYJZZPCheck();
// break;
// case RuleType.数学基础规范性检查:
// ruleCheck = new SXJCCheck();
// break;
// case RuleType.图形属性规范性检查:
// ruleCheck = new TXSXCheck();
// break;
// case RuleType.通用类表内逻辑性检查:
// ruleCheck = new TYLBBNLJXCheck();
// break;
// case RuleType.通用类表间逻辑性检查:
// ruleCheck = new TYLBJLJXCheck();
// break;
// case RuleType.数据库业务类逻辑检查:
// break;
// case RuleType.单图斑建库人工检查:
// //ruleCheck = new RGJCCheck();
// break;
// case RuleType.数据库成果人工检查:
// break;
// case RuleType.内业预审处理检查:
// break;
// default:
// break;
// }
// if (ruleCheck != null)
// {
// ruleCheck.ExcuteRules = excuteRules;
// ruleCheck.DisExecuteRules = disExecuteRules;
// ruleCheck.ProcessDataPath = sProcessDataPath;
// ruleCheck.FirstRun = bFirstRun;
// checkRst = ruleCheck.ExcuteCheck(sourcePath, workspace);
// if (ruleType == RuleType.单图斑建库人工检查)
// checkRst = ruleCheck.AllRGError;
// }
// return checkRst;
//}
//public static List StartCheck(string sourcePath, Dictionary workspace, List ruleTypes)
//{
// if (!System.IO.File.Exists(sourcePath) || workspace == null)
// {
// throw new Exception("输入参数错误");
// }
// DLParams.Init();
// List result = new List();
// foreach (var item in ruleTypes)
// {
// List rules = StartCheck(sourcePath, workspace, item);
// if (rules != null && rules.Count > 0)
// {
// result.AddRange(rules);
// }
// }
// return result;
//}
/////
///// 县级单图斑建库和审核任务包检查
/////
/////
/////
///// 参考数据dicReferenceData = new Dictionary {{ "JCK_DLTB", @"F:\KINGO\基础数据下发\基础数据库\(4401)广州市\(440103)荔湾区\440103\XYBASE.gdb\DLTB" },};
///// 过程数据路径
/////
///// 系统设置-需执行规则
/////
//public static List StartXJSHCheck(string dbPath, Dictionary workspace, Dictionary dicReferenceData, out string sProcessDataPath, string primityKey = "", List> excuteRules = null)
//{
// if (!System.IO.File.Exists(dbPath) || workspace == null)
// {
// throw new Exception("输入参数错误");
// }
// CheckHelper.DBToMDBHelper dBToMDBHelper = new CheckHelper.DBToMDBHelper();
// List mdbPaths = dBToMDBHelper.DBToMdb(dbPath, out sProcessDataPath, primityKey);
// dBToMDBHelper.CreateProcessData(dicReferenceData, sProcessDataPath);
// List result = new List();
// List ruleTypes = new List()
// {
// RuleType.地类属性与举证照片逻辑性检查,
// RuleType.数学基础规范性检查,
// RuleType.图形属性规范性检查,
// RuleType.通用类表内逻辑性检查,
// RuleType.通用类表间逻辑性检查,
// };
// DLParams.Init();
// //过程MDB可创建表
// var mdbHelper = new CheckHelper.MDBHelper(sProcessDataPath);
// mdbHelper.connOpen();
// mdbHelper.ExecuteNonQuery("CREATE TABLE ErrorRecords(XH INTEGER,RuleCode TEXT,CheckObject TEXT,RuleName TEXT,RuleContent TEXT,ErrorType TEXT,ErrorId TEXT,ErrorTip TEXT)");
// bool bFirstRun = true;
// if (mdbPaths != null && mdbPaths.Count > 0)
// {
// foreach (var mdbPath in mdbPaths)
// {
// foreach (var item in ruleTypes)
// {
// List rules = StartCheck(mdbPath, workspace, item, bFirstRun, sProcessDataPath, excuteRules, new List { "JZ005", "JZ007" });
// if (rules != null && rules.Count > 0)
// {
// result.AddRange(rules);
// //错误记录插入mdb
// foreach (var ru in rules)
// {
// mdbHelper.ExecuteNonQuery($"insert into ErrorRecords(XH,RuleCode,CheckObject,RuleName,RuleContent,ErrorType,ErrorId,ErrorTip) " +
// $"values ({ru.XH},'{ru.RuleCode}','{ru.CheckObject}','{ru.RuleName}','{ru.RuleContent}','{ru.ErrorType}','{ru.ErrorTip}')");
// }
// }
// }
// bFirstRun = false;
// }
// }
// mdbHelper.DisConn();
// return result;
//}
/////
///// 县级单图斑建库和审核任务包检查
/////
/////
/////
/////
///// 系统设置-需执行规则
/////
//public static List StartXJSHCheck(string dbPath, Dictionary workspace, string primityKey = "", List> excuteRules = null)
//{
// if (!System.IO.File.Exists(dbPath) || workspace == null)
// {
// throw new Exception("输入参数错误");
// }
// CheckHelper.DBToMDBHelper dBToMDBHelper = new CheckHelper.DBToMDBHelper();
// List mdbPaths = dBToMDBHelper.DBToMdb(dbPath, out string sProcessDataPath, primityKey);
// List result = new List();
// List ruleTypes = new List()
// {
// RuleType.地类属性与举证照片逻辑性检查,
// RuleType.数学基础规范性检查,
// RuleType.图形属性规范性检查,
// RuleType.通用类表内逻辑性检查,
// RuleType.通用类表间逻辑性检查,
// };
// DLParams.Init();
// bool bFirstRun = true;
// if (mdbPaths != null && mdbPaths.Count > 0)
// {
// foreach (var mdbPath in mdbPaths)
// {
// foreach (var item in ruleTypes)
// {
// List rules = StartCheck(mdbPath, workspace, item, bFirstRun, sProcessDataPath, excuteRules, new List { "JZ005", "JZ007", "TX021", "TX022", "TX023", "TX024", "LNGD001", "LNGD002", "LNGD003", "LNGD004", "HFSX001", "HFSX002", "HFSX003" });
// if (rules != null && rules.Count > 0)
// {
// result.AddRange(rules);
// }
// }
// bFirstRun = false;
// }
// }
// return result;
//}
/////
///// 省级单图斑建库和审核任务包检查
/////
/////
/////
/////
///// 系统设置-需执行规则
/////
//public static List StartSJSHCheckOld(string dbPath, Dictionary workspace, string primityKey = "", List> excuteRules = null)
//{
// if (!System.IO.File.Exists(dbPath) || workspace == null)
// {
// throw new Exception("输入参数错误");
// }
// CheckHelper.DBToMDBHelper dBToMDBHelper = new CheckHelper.DBToMDBHelper();
// List mdbPaths = dBToMDBHelper.DBToMdb(dbPath, out string sProcessDataPath, primityKey);
// List result = new List();
// List ruleTypes = new List()
// {
// RuleType.地类属性与举证照片逻辑性检查,
// RuleType.数学基础规范性检查,
// RuleType.图形属性规范性检查,
// RuleType.通用类表内逻辑性检查,
// RuleType.通用类表间逻辑性检查,
// RuleType.单图斑建库人工检查
// };
// DLParams.Init();
// bool bFirstRun = true;
// if (mdbPaths != null && mdbPaths.Count > 0)
// {
// foreach (var mdbPath in mdbPaths)
// {
// foreach (var item in ruleTypes)
// {
// List rules = StartCheck(mdbPath, workspace, item, bFirstRun, sProcessDataPath, excuteRules);
// if (rules != null && rules.Count > 0)
// {
// result.AddRange(rules);
// }
// }
// bFirstRun = false;
// }
// }
// return result;
//}
/////
///// 省级单图斑建库和审核任务包检查
/////
/////
/////
///// 参考数据dicReferenceData = new Dictionary {{ "JCK_DLTB", @"F:\KINGO\基础数据下发\基础数据库\(4401)广州市\(440103)荔湾区\440103\XYBASE.gdb\DLTB" },};
///// 过程数据路径
/////
///// 系统设置-需执行规则
/////
//public static List StartSJSHCheck(string dbPath, Dictionary workspace, Dictionary dicReferenceData, out string sProcessDataPath, string primityKey = "", List> excuteRules = null)
//{
// if (!System.IO.File.Exists(dbPath) || workspace == null)
// {
// throw new Exception("输入参数错误");
// }
// CheckHelper.DBToMDBHelper dBToMDBHelper = new CheckHelper.DBToMDBHelper();
// List mdbPaths = dBToMDBHelper.DBToMdb(dbPath, out sProcessDataPath, primityKey);
// dBToMDBHelper.CreateProcessData(dicReferenceData, sProcessDataPath);
// List result = new List();
// List ruleTypes = new List()
// {
// RuleType.地类属性与举证照片逻辑性检查,
// RuleType.数学基础规范性检查,
// RuleType.图形属性规范性检查,
// RuleType.通用类表内逻辑性检查,
// RuleType.通用类表间逻辑性检查,
// RuleType.单图斑建库人工检查
// };
// DLParams.Init();
// //过程MDB可创建表
// var mdbHelper = new CheckHelper.MDBHelper(sProcessDataPath);
// mdbHelper.connOpen();
// mdbHelper.ExecuteNonQuery("CREATE TABLE ErrorRecords(XH INTEGER,RuleCode TEXT,CheckObject TEXT,RuleName TEXT,RuleContent TEXT,ErrorType TEXT,ErrorId TEXT,ErrorTip TEXT)");
// bool bFirstRun = true;
// if (mdbPaths != null && mdbPaths.Count > 0)
// {
// foreach (var mdbPath in mdbPaths)
// {
// foreach (var item in ruleTypes)
// {
// List rules = StartCheck(mdbPath, workspace, item, bFirstRun, sProcessDataPath, excuteRules);
// if (rules != null && rules.Count > 0)
// {
// result.AddRange(rules);
// //错误记录插入mdb
// foreach (var ru in rules)
// {
// mdbHelper.ExecuteNonQuery($"insert into ErrorRecords(XH,RuleCode,CheckObject,RuleName,RuleContent,ErrorType,ErrorId,ErrorTip) " +
// $"values ({ru.XH},'{ru.RuleCode}','{ru.CheckObject}','{ru.RuleName}','{ru.RuleContent}','{ru.ErrorType}','{ru.ErrorId}','{ru.ErrorTip}')");
// }
// }
// }
// bFirstRun = false;
// }
// }
// mdbHelper.DisConn();
// return result;
//}
#endregion
}
}