DWCommon.cs 14 KB

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