DACommon.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. using Uninpho.DBOperation.Model;
  8. using Uninpho.DBOperation.Operation;
  9. using System.IO;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.XtraGrid.Views.Grid;
  12. using DevExpress.XtraGrid;
  13. using DevExpress.XtraBars;
  14. namespace Uninpho.Tools.components.DataAnalysis
  15. {
  16. /// <summary>
  17. /// 轮轨力算法、几何分析算法公共方法类
  18. /// </summary>
  19. class DACommon
  20. {
  21. /// <summary>
  22. /// 高速还是低速
  23. /// 0:高速 1:低速 2:全选
  24. /// </summary>
  25. public static int gdsBool = 0;
  26. /// <summary>
  27. /// 是否进行里程修正
  28. /// </summary>
  29. public static bool xzlcBool = true;
  30. /// <summary>
  31. /// 检测车
  32. /// </summary>
  33. public static List<string> jccList = new List<string>();
  34. /// <summary>
  35. /// 打开文件夹公共函数
  36. /// </summary>
  37. public static void OpenFile(string houzhui,bool ischecked,GridView GV)
  38. {
  39. List<T_file_account> filelist = new List<T_file_account>();
  40. //批量
  41. if (ischecked)
  42. {
  43. var dialog = new FolderBrowserDialog();
  44. if (dialog.ShowDialog() == DialogResult.OK)
  45. {
  46. DirectoryInfo DirInfo = new DirectoryInfo(dialog.SelectedPath);
  47. houzhui = "." + houzhui;
  48. var files = from f in DirInfo.EnumerateFiles()
  49. where houzhui.Contains(f.Extension.ToLower())
  50. select f;
  51. // Show results.
  52. foreach (var f in files)
  53. {
  54. T_file_account tfa;
  55. if (houzhui == ".geo")
  56. {
  57. tfa = FileNameSplit(f.FullName);
  58. }
  59. else
  60. {
  61. tfa = FileNameSplit1(f.FullName);
  62. }
  63. var isfile = DataAnalysisToPG.QueryToPGByNameFile(tfa.Yswjm) as List<T_file_account>;
  64. if (isfile.Count == 0)
  65. {
  66. filelist.Add(tfa);
  67. }
  68. else
  69. {
  70. if (XtraMessageBox.Show("检测到数据库内存在同名数据:\n" + tfa.Yswjm+",\n是否覆盖数据库内数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  71. {
  72. filejiancedel(tfa);
  73. filelist.Add(tfa);
  74. }
  75. }
  76. }
  77. DataAnalysisToPG.InsertToPG(filelist);
  78. }
  79. }
  80. else
  81. {
  82. var dialog = new OpenFileDialog();
  83. dialog.Multiselect = true;
  84. dialog.Title = "请选择文件夹";
  85. dialog.Filter = houzhui+"文件(*." + houzhui + ")|*." + houzhui;
  86. if (dialog.ShowDialog() == DialogResult.OK)
  87. {
  88. string[] file = dialog.FileNames;
  89. for (int i = 0; i < file.Length; i++)
  90. {
  91. T_file_account tfa;
  92. if (houzhui == "geo")
  93. {
  94. tfa = FileNameSplit(file[i]);
  95. }else
  96. {
  97. tfa = FileNameSplit1(file[i]);
  98. }
  99. var isfile = DataAnalysisToPG.QueryToPGByNameFile(tfa.Yswjm) as List<T_file_account>;
  100. if (isfile.Count == 0)
  101. {
  102. filelist.Add(tfa);
  103. }
  104. else
  105. {
  106. if (XtraMessageBox.Show("检测到数据库内存在同名数据:\n" + tfa.Yswjm + ",\n是否覆盖数据库内数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  107. {
  108. filejiancedel(tfa);
  109. filelist.Add(tfa);
  110. }
  111. }
  112. }
  113. DataAnalysisToPG.InsertToPG(filelist);
  114. }
  115. }
  116. }
  117. /// <summary>
  118. /// 清理数据库同名数据
  119. /// </summary>
  120. /// <param name="file"></param>
  121. private static void filejiancedel(T_file_account file)
  122. {
  123. if (file.Houzhui == "geo")
  124. {
  125. List<T_jihefenxi_account> whichupdata = (List<T_jihefenxi_account>)DataAnalysisToPG.QueryToPGByName(file.Yswjm);
  126. DataAnalysisToPG.DelToPGJHBX(whichupdata);
  127. DataAnalysisToPG.DelToPGJH(file);
  128. }
  129. else
  130. {
  131. List<T_lunguili_account> whichupdata = (List<T_lunguili_account>)DataAnalysisToPG.QueryToPGByNameL(file.Yswjm);
  132. DataAnalysisToPG.DelToPGLGLBX(whichupdata);
  133. DataAnalysisToPG.DelToPGLGL(file);
  134. }
  135. DataAnalysisToPG.DelToPG1(file);
  136. }
  137. /// <summary>
  138. /// 解析几何分析数据
  139. /// </summary>
  140. /// <param name="filename"></param>
  141. /// <returns></returns>
  142. private static T_file_account FileNameSplit(string filename)
  143. {
  144. string ysname = Path.GetFileName(filename);
  145. var filearr = ysname.Split('-');
  146. string[] xlbh = HBXLSplit(filearr[0]);
  147. string jcsj = getYMDHMS(filearr[3],filearr[4]);
  148. string FX = getZF(filearr[5]);//0反向、1正向
  149. string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0/1024.0) + " MB";
  150. T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
  151. return new T_file_account()
  152. {
  153. Xlm = xlpg.Xlm,
  154. Xlbh = xlpg.Xldj,
  155. Hangbie = xlbh[1],
  156. Jcsj = jcsj,
  157. Daxiao = wjdx,
  158. Yswjm = ysname,
  159. Houzhui = Path.GetExtension(filename).Remove(0, 1),
  160. Fangxiang = FX,
  161. Wjzt = "正常",
  162. Srlj = filename,
  163. Rwzt = "算法未执行",
  164. Jccxx = " "
  165. };
  166. }
  167. /// <summary>
  168. /// 解析轮轨力数据
  169. /// </summary>
  170. /// <param name="filename"></param>
  171. /// <returns></returns>
  172. private static T_file_account FileNameSplit1(string filename)
  173. {
  174. string ysname = Path.GetFileName(filename);
  175. var filearr = ysname.Split('_');
  176. string[] xlbh = HBXLSplit(filearr[2].Split('.')[0]);
  177. string jcsj = getYMDHMS(filearr[1]);
  178. string FX = getZF(filearr[2]);//0反向、1正向
  179. string wjdx = Math.Ceiling(new FileInfo(filename).Length / 1024.0 / 1024.0) + " MB";
  180. T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;
  181. return new T_file_account()
  182. {
  183. Xlm = xlpg.Xlm,
  184. Xlbh = xlpg.Xldj,
  185. Hangbie = xlbh[1],
  186. Jcsj = jcsj,
  187. Daxiao = wjdx,
  188. Yswjm = ysname,
  189. Fangxiang = FX,
  190. Houzhui = Path.GetExtension(filename).Remove(0, 1),
  191. Wjzt = "正常",
  192. Srlj = filename,
  193. Rwzt = "算法未执行",
  194. Jccxx = " "
  195. };
  196. }
  197. /// <summary>
  198. /// 解析方向
  199. /// </summary>
  200. private static string getZF(string ZF)
  201. {
  202. string zf = ZF.Split('_')[0];
  203. if (zf == "0")
  204. {
  205. return "反向";
  206. }
  207. else
  208. {
  209. return "正向";
  210. }
  211. }
  212. /// <summary>
  213. /// 解析时间
  214. /// </summary>
  215. private static string getYMDHMS(string ymd,string hms)
  216. {
  217. //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
  218. Char[] ymdcha = ymd.ToCharArray();//年月日
  219. Char[] hmscha = hms.ToCharArray();//时分秒
  220. string year = ymdcha[4].ToString() + ymdcha[5].ToString() + ymdcha[6].ToString() + ymdcha[7].ToString();
  221. string mouth = ymdcha[2].ToString() + ymdcha[3].ToString();
  222. string day = ymdcha[0].ToString() + ymdcha[1].ToString();
  223. string hour = hmscha[0].ToString() + hmscha[1].ToString();
  224. string minite = hmscha[2].ToString() + hmscha[3].ToString();
  225. string second = hmscha[4].ToString() + hmscha[5].ToString();
  226. return year+ "年" +mouth + "月" + day + "日" + hour + "时" + minite + "分" + second + "秒";
  227. }
  228. private static string getYMDHMS(string ymd)
  229. {
  230. //如果这里以后修改,轮轨力输入检测日期那块也要改!!!
  231. Char[] ymdcha = ymd.ToCharArray();//年月日
  232. string year = ymdcha[0].ToString() + ymdcha[3].ToString();
  233. string mouth = ymdcha[6].ToString() + ymdcha[7].ToString();
  234. string day = ymdcha[4].ToString() + ymdcha[5].ToString();
  235. return year + "年" + mouth + "月" + day + "日";
  236. }
  237. /// <summary>
  238. /// 解析行别和线路编号
  239. /// </summary>
  240. private static string[] HBXLSplit(string arr0)
  241. {
  242. Char[] cha = arr0.ToCharArray();
  243. string hb = "", xl = "";
  244. for (int i = 0; i < cha.Length; i++)
  245. {
  246. if (i != cha.Length-1)
  247. {
  248. xl += cha[i];
  249. }
  250. else
  251. {
  252. if (cha[i] == 'X')
  253. {
  254. hb = "下";
  255. }
  256. else if (cha[i] == 'S')
  257. {
  258. hb = "上";
  259. }
  260. else
  261. {
  262. hb = "未知";
  263. }
  264. }
  265. }
  266. return new string[] {xl,hb };
  267. }
  268. /// <summary>
  269. /// 表前加序号
  270. /// </summary>
  271. /// <param name="e"></param>
  272. public static void addXuHao(DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
  273. {
  274. if (e.Info.Kind == DevExpress.Utils.Drawing.IndicatorKind.Header)
  275. {
  276. e.Appearance.DrawBackground(e.Cache, e.Bounds);
  277. e.Appearance.DrawString(e.Cache, " 序号", e.Bounds);
  278. e.Handled = true;
  279. }
  280. e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
  281. if (e.Info.IsRowIndicator)
  282. {
  283. if (e.RowHandle >= 0)
  284. {
  285. e.Info.DisplayText = (e.RowHandle + 1).ToString().Trim();
  286. }
  287. else if (e.RowHandle < 0 && e.RowHandle > -1000)
  288. {
  289. e.Info.DisplayText = "G" + e.RowHandle.ToString();
  290. }
  291. }
  292. }
  293. /// <summary>
  294. /// 自动化初始化
  295. /// </summary>
  296. public static void initZDHFun(BarButtonItem barButtonItem)
  297. {
  298. initFile(zdhSetClass.path, zdhSetClass.initStr);
  299. StreamReader sr = new StreamReader(zdhSetClass.path);
  300. while (!sr.EndOfStream)
  301. {
  302. string[] str = sr.ReadLine().Split('灬');
  303. if (str[0] == "Interval")
  304. {
  305. zdhSetClass.Interval = Convert.ToInt32(str[1]);
  306. continue;
  307. }
  308. else if (str[0] == "folder")
  309. {
  310. if (Directory.Exists(str[1]))
  311. {
  312. zdhSetClass.folder = str[1];
  313. }
  314. continue;
  315. }
  316. else if (str[0] == "startdate")
  317. {
  318. zdhSetClass.startdate = str[1];
  319. continue;
  320. }
  321. else if (str[0] == "taskName")
  322. {
  323. zdhSetClass.taskName = str[1];
  324. continue;
  325. }
  326. else if (str[0] == "isStartZDH")
  327. {
  328. zdhSetClass.isStartZDH = Convert.ToInt32(str[1]);
  329. continue;
  330. }
  331. }
  332. DirectoryInitNoDelNoHidde(zdhSetClass.folder + "geoData");
  333. DirectoryInitNoDelNoHidde(zdhSetClass.folder + "bnyData");
  334. if (zdhSetClass.isStartZDH == 0)
  335. {
  336. barButtonItem.ImageUri.Uri = "Prev"; //Refresh // Prev
  337. barButtonItem.Caption = "开启自动化";
  338. }
  339. else
  340. {
  341. barButtonItem.ImageUri.Uri = "Refresh"; //Refresh // Prev
  342. barButtonItem.Caption = "重启自动化";
  343. }
  344. }
  345. /// <summary>
  346. /// 创建文件
  347. /// </summary>
  348. public static void initFile(string path,string data)
  349. {
  350. if (!File.Exists(path))
  351. {
  352. File.WriteAllText(path, data);
  353. }
  354. }
  355. /// <summary>
  356. /// 复制文件
  357. /// </summary>
  358. /// <param name="filename">原始文件路径</param>
  359. /// <param name="newfilename">目的地文件路径</param>
  360. public static void FileCopy(string filename,string newfilename)
  361. {
  362. if (File.Exists(filename))
  363. {
  364. if (File.Exists(newfilename))
  365. {
  366. File.Delete(newfilename);
  367. }
  368. File.Copy(filename, newfilename);
  369. }
  370. }
  371. /// <summary>
  372. /// 按文件夹删除(删除临时文件夹)
  373. /// </summary>
  374. /// <param name="DirectoryPath">文件夹路径</param>
  375. public static void DirectoryInit(string DirectoryPath)
  376. {
  377. if (Directory.Exists(DirectoryPath))
  378. {
  379. Directory.Delete(DirectoryPath, true); //删除文件夹及内容
  380. }
  381. DirectoryInfo di = Directory.CreateDirectory(DirectoryPath);
  382. di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
  383. }
  384. public static void DirectoryInitNoDel(string DirectoryPath)
  385. {
  386. if (!Directory.Exists(DirectoryPath))
  387. {
  388. DirectoryInfo di = Directory.CreateDirectory(DirectoryPath);
  389. di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
  390. }
  391. }
  392. public static void DirectoryInitNoDelNoHidde(string DirectoryPath)
  393. {
  394. if (!Directory.Exists(DirectoryPath))
  395. {
  396. DirectoryInfo di = Directory.CreateDirectory(DirectoryPath);
  397. di.Attributes = FileAttributes.Directory;
  398. }
  399. }
  400. /// <summary>
  401. /// 刷新后恢复选中
  402. /// </summary>
  403. /// <param name="gv"></param>
  404. /// <param name="selectid"></param>
  405. public static void repushSFZT(GridView gv,List<int> selectid)
  406. {
  407. for (int i = 0; i < gv.RowCount; i++)
  408. {
  409. for (int j = 0; j < selectid.Count; j++)
  410. {
  411. if (gv.GetRowCellValue(i, "Id").ToString() == selectid[j].ToString())
  412. {
  413. gv.SelectRow(i);
  414. break;
  415. }
  416. }
  417. }
  418. }
  419. /// <summary>
  420. /// 获取刷新前id和状态
  421. /// </summary>
  422. /// <param name="gv"></param>
  423. /// <param name="selectid"></param>
  424. /// <param name="selectrowzt"></param>
  425. public static void getSFZT(GridView gv,ref List<int> selectid,ref List<string> selectrowzt)
  426. {
  427. var sele = gv.GetSelectedRows();
  428. foreach (var i in sele)
  429. {
  430. selectid.Add(Convert.ToInt32(gv.GetRowCellValue(i, "Id").ToString()));
  431. selectrowzt.Add(gv.GetRowCellValue(i, "Rwzt").ToString());
  432. }
  433. }
  434. }
  435. }