CheckedDB.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using System;
  2. using System.Collections.Generic;
  3. using Uninpho.DBOperation.Model;
  4. using Uninpho.DBOperation.Operation;
  5. using System.IO;
  6. namespace ZDHscript
  7. {
  8. /// <summary>
  9. /// 检查数据库
  10. /// </summary>
  11. class CheckedDB
  12. {
  13. /// <summary>
  14. /// CheckedDataBase主函数
  15. /// </summary>
  16. public static void DBCheckedFun()
  17. {
  18. // 1.检查
  19. CheckedGeo();
  20. CheckedBny();
  21. // 2.往t_file_account新增数据
  22. Add2fileAccount();
  23. // 3.并记录到Store中
  24. RecordNewData();
  25. }
  26. /// <summary>
  27. /// 往t_file_account新增数据
  28. /// </summary>
  29. public static void Add2fileAccount()
  30. {
  31. //1.先删除t_file_account表内相关数据
  32. foreach (var item in Store.newGeofiles)
  33. {
  34. DataAnalysisToPG.DelToPG1(new T_file_account() { Yswjm = Path.GetFileName(item) });
  35. }
  36. foreach (var item in Store.newBnyfiles)
  37. {
  38. DataAnalysisToPG.DelToPG1(new T_file_account() { Yswjm = Path.GetFileName(item) });
  39. }
  40. //2.统一再添加一次
  41. saveTfileName(Store.newGeofiles,"几何分析");
  42. saveTfileName(Store.newBnyfiles,"轮轨力分析");
  43. }
  44. /// <summary>
  45. /// 检查geo
  46. /// </summary>
  47. public static void CheckedGeo()
  48. {
  49. try
  50. {
  51. //1.检查T_file_account表
  52. foreach (string file in Store.geoList)
  53. {
  54. List<T_file_account> acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List<T_file_account>;
  55. if (acc.Count == 0)
  56. {
  57. Store.newGeofiles.Add(file);
  58. ColorClass.Console_AddColor("新增数据:" + file);
  59. }
  60. else
  61. {
  62. //2.若之前执行过文件,则再检查T_jihefenxi_account表内数据是否存在
  63. List<T_jihefenxi_account> jhacc = DataAnalysisToPG.QueryToPGByName(acc[0].Id.ToString()) as List<T_jihefenxi_account>;
  64. //不存在也当没执行过算法,加入执行列表
  65. if (jhacc.Count == 0)
  66. {
  67. Store.newGeofiles.Add(file);
  68. ColorClass.Console_AddColor("新增数据:" + file);
  69. }
  70. }
  71. }
  72. }
  73. catch (Exception ex)
  74. {
  75. ColorClass.Console_EorrColor(ex.Message);
  76. throw;
  77. }
  78. }
  79. /// <summary>
  80. /// 检查bny
  81. /// </summary>
  82. public static void CheckedBny()
  83. {
  84. try
  85. {
  86. //1.检查T_file_account表
  87. foreach (string file in Store.bnyList)
  88. {
  89. List<T_file_account> acc = DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(file)) as List<T_file_account>;
  90. if (acc.Count == 0)
  91. {
  92. Store.newBnyfiles.Add(file);
  93. ColorClass.Console_AddColor("新增数据:" + file);
  94. }
  95. else
  96. {
  97. //2.若之前执行过文件,则再检查T_lunguili_account表内数据是否存在
  98. List<T_lunguili_account> jhacc = DataAnalysisToPG.QueryToPGByNameL(acc[0].Id.ToString()) as List<T_lunguili_account>;
  99. if (jhacc.Count == 0)
  100. {
  101. Store.newBnyfiles.Add(file);
  102. ColorClass.Console_AddColor("新增数据:" + file);
  103. }
  104. }
  105. }
  106. }
  107. catch (Exception ex)
  108. {
  109. ColorClass.Console_EorrColor(ex.Message);
  110. throw;
  111. }
  112. }
  113. /// <summary>
  114. /// 往数据库T_file_account表新插入的数据
  115. /// </summary>
  116. /// <param name="file"></param>
  117. public static void saveTfileName(List<string> file,string str)
  118. {
  119. if (file.Count != 0)
  120. {
  121. try
  122. {
  123. List<T_file_account> filelist = new List<T_file_account>();
  124. for (int i = 0; i < file.Count; i++)
  125. {
  126. T_file_account tfa = new T_file_account();
  127. if (Path.GetExtension(file[i]).ToLower() == ".geo")
  128. {
  129. tfa = JXSJ.FileNameSplit(file[i]);
  130. }
  131. else if (Path.GetExtension(file[i]).ToLower() == ".bny")
  132. {
  133. tfa = JXSJ.FileNameSplit1(file[i]);
  134. }
  135. filelist.Add(tfa);
  136. }
  137. DataAnalysisToPG.InsertToPG(filelist);
  138. ColorClass.Console_AddColor("文件入库成功");
  139. }
  140. catch (Exception ex)
  141. {
  142. ColorClass.Console_EorrColor("文件入库失败:" + ex.Message);
  143. throw;
  144. }
  145. }
  146. else
  147. {
  148. ColorClass.Console_AddColor(str + "没有新增文件");
  149. }
  150. }
  151. /// <summary>
  152. /// 记录T_file_account表新插入的数据
  153. /// </summary>
  154. public static void RecordNewData()
  155. {
  156. for (int i = 0; i < Store.newGeofiles.Count; i++)
  157. {
  158. Store.GeofileAccount.Add((DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(Store.newGeofiles[i])) as List<T_file_account>)[0]);
  159. }
  160. for (int i = 0; i < Store.newBnyfiles.Count; i++)
  161. {
  162. Store.BnyfileAccount.Add((DataAnalysisToPG.QueryToPGByNameFile(Path.GetFileName(Store.newBnyfiles[i])) as List<T_file_account>)[0]);
  163. }
  164. }
  165. }
  166. public class JXSJ
  167. {
  168. /// <summary>
  169. /// 解析几何分析数据
  170. /// </summary>
  171. /// <param name="filename"></param>
  172. /// <returns></returns>
  173. public static T_file_account FileNameSplit(string filename)
  174. {
  175. string ysname = Path.GetFileName(filename);
  176. var filearr = ysname.Split('-');
  177. string[] xlbh = HBXLSplit(filearr[0]);
  178. string jcsj = getYMDHMS(filearr[3], filearr[4]);
  179. string FX = getZF(filearr[5]);//0反向、1正向
  180. string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0 / 1024.0) + " MB";
  181. T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
  182. return new T_file_account()
  183. {
  184. Xlm = xlpg.Xlm,
  185. Xlbh = xlpg.Xldj,
  186. Hangbie = xlbh[1],
  187. Jcsj = jcsj,
  188. Daxiao = wjdx,
  189. Yswjm = ysname,
  190. Houzhui = Path.GetExtension(filename).Remove(0, 1),
  191. Fangxiang = FX,
  192. Wjzt = "正常",
  193. Srlj = filename,
  194. Rwzt = "算法未执行",
  195. Jccxx = "轨检车"
  196. };
  197. }
  198. /// <summary>
  199. /// 解析轮轨力数据
  200. /// </summary>
  201. /// <param name="filename"></param>
  202. /// <returns></returns>
  203. public static T_file_account FileNameSplit1(string filename)
  204. {
  205. string ysname = Path.GetFileName(filename);
  206. var filearr = ysname.Split('_');
  207. string[] xlbh = HBXLSplit(filearr[2].Split('.')[0]);
  208. string jcsj = getYMDHMS(filearr[1]);
  209. string FX = getZF(filearr[2]);//0反向、1正向
  210. string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0 / 1024.0) + " MB";
  211. T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
  212. return new T_file_account()
  213. {
  214. Xlm = xlpg.Xlm,
  215. Xlbh = xlpg.Xldj,
  216. Hangbie = xlbh[1],
  217. Jcsj = jcsj,
  218. Daxiao = wjdx,
  219. Yswjm = ysname,
  220. Fangxiang = FX,
  221. Houzhui = Path.GetExtension(filename).Remove(0, 1),
  222. Wjzt = "正常",
  223. Srlj = filename,
  224. Jccxx = "轨检车",
  225. Rwzt = "算法未执行"
  226. };
  227. }
  228. /// <summary>
  229. /// 解析方向
  230. /// </summary>
  231. public static string getZF(string ZF)
  232. {
  233. string zf = ZF.Split('_')[0];
  234. if (zf == "0")
  235. {
  236. return "反向";
  237. }
  238. else
  239. {
  240. return "正向";
  241. }
  242. }
  243. /// <summary>
  244. /// 解析时间
  245. /// </summary>
  246. public static string getYMDHMS(string ymd, string hms)
  247. {
  248. //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
  249. Char[] ymdcha = ymd.ToCharArray();//年月日
  250. Char[] hmscha = hms.ToCharArray();//时分秒
  251. string year = ymdcha[4].ToString() + ymdcha[5].ToString() + ymdcha[6].ToString() + ymdcha[7].ToString();
  252. string mouth = ymdcha[2].ToString() + ymdcha[3].ToString();
  253. string day = ymdcha[0].ToString() + ymdcha[1].ToString();
  254. string hour = hmscha[0].ToString() + hmscha[1].ToString();
  255. string minite = hmscha[2].ToString() + hmscha[3].ToString();
  256. string second = hmscha[4].ToString() + hmscha[5].ToString();
  257. return year + "年" + mouth + "月" + day + "日" + hour + "时" + minite + "分" + second + "秒";
  258. }
  259. public static string getYMDHMS(string ymd)
  260. {
  261. //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
  262. Char[] ymdcha = ymd.ToCharArray();//年月日
  263. string year = ymdcha[0].ToString() + ymdcha[3].ToString();
  264. string mouth = ymdcha[6].ToString() + ymdcha[7].ToString();
  265. string day = ymdcha[4].ToString() + ymdcha[5].ToString();
  266. return year + "年" + mouth + "月" + day + "日";
  267. }
  268. /// <summary>
  269. /// 解析行别和线路编号
  270. /// </summary>
  271. public static string[] HBXLSplit(string arr0)
  272. {
  273. Char[] cha = arr0.ToCharArray();
  274. string hb = "", xl = "";
  275. for (int i = 0; i < cha.Length; i++)
  276. {
  277. if (i != cha.Length - 1)
  278. {
  279. xl += cha[i];
  280. }
  281. else
  282. {
  283. if (cha[i] == 'X')
  284. {
  285. hb = "下";
  286. }
  287. else if (cha[i] == 'S')
  288. {
  289. hb = "上";
  290. }
  291. else
  292. {
  293. hb = "未知";
  294. }
  295. }
  296. }
  297. return new string[] { xl, hb };
  298. }
  299. }
  300. }