DWQKCommon.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 DWQKCommon
  17. {
  18. public static string lj;
  19. public static List<T_dwqkfile_account> filelist = new List<T_dwqkfile_account>();
  20. /// <summary>
  21. /// 打开文件夹公共函数
  22. /// </summary>
  23. public static void OpenFile(string houzhui,GridView GV,string xianluming, string chezhan)
  24. {
  25. var dialog = new OpenFileDialog();
  26. dialog.Multiselect = true;
  27. dialog.Title = "请选择文件夹";
  28. dialog.Filter = houzhui+"文件(*." + houzhui + ")|*." + houzhui;
  29. if (dialog.ShowDialog() == DialogResult.OK)
  30. {
  31. string[] file = dialog.FileNames;
  32. for (int i = 0; i < file.Length; i++)
  33. {
  34. T_dwqkfile_account tfa = GLFileNameSplit1(file[i], xianluming, chezhan);
  35. //获取数据后
  36. var isfile = DataAnalysisToPG.DWQKQueryToPGByNameFile(tfa.Filename) as List<T_dwqkfile_account>;
  37. lj = file[i]; //传路径
  38. if (isfile.Count == 0)
  39. {
  40. filelist.Add(tfa);
  41. }
  42. else
  43. {
  44. if (XtraMessageBox.Show("检测到数据库内存在同名数据:\n" + tfa.Filename + ",\n是否覆盖数据库内数据?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
  45. {
  46. filejiancedel(tfa);
  47. filelist.Add(tfa);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. public static void AddFile()
  54. {
  55. DataAnalysisToPG.QKInsertToPG(filelist);
  56. filelist.Clear();
  57. }
  58. public static void CancelAddFile()
  59. {
  60. filelist.Clear();
  61. }
  62. /// 清理数据库同名数据
  63. private static void filejiancedel(T_dwqkfile_account file)
  64. {
  65. DataAnalysisToPG.DelToDWQK(file);//清除功率表
  66. }
  67. /// 解析电务功率数据
  68. private static T_dwqkfile_account GLFileNameSplit1(string filename,string xianluming, string chezhan)
  69. {
  70. string ysname = Path.GetFileName(filename);
  71. string wjdx = Math.Round((new FileInfo(filename).Length / 1024.0 / 1024.0),2) + " MB";//文件大小
  72. string lj = filename;//路径
  73. string minStartTime = null;//日期
  74. string maxStartTime = null;
  75. //解析文件
  76. using (StreamReader reader = new StreamReader(filename))
  77. {
  78. string line;
  79. while ((line = reader.ReadLine()) != null)
  80. {
  81. string[] parts = line.Split('$');
  82. if (parts.Length >= 9)
  83. {
  84. string caijikaishishijian = parts[2];//采集开始时间
  85. DateTime startTime;
  86. if (DateTime.TryParseExact(caijikaishishijian, "yyyy-MM-dd HH:mm:ss", null, System.Globalization.DateTimeStyles.None, out startTime))
  87. {
  88. string formattedStartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
  89. if (minStartTime == null || string.Compare(formattedStartTime, minStartTime) < 0)
  90. {
  91. minStartTime = formattedStartTime;
  92. }
  93. if (maxStartTime == null || string.Compare(formattedStartTime, maxStartTime) > 0)
  94. {
  95. maxStartTime = formattedStartTime;
  96. }
  97. }
  98. }
  99. }
  100. }
  101. return new T_dwqkfile_account()
  102. {
  103. //下次把车站线路写活
  104. Xianlu = xianluming,
  105. Chezhan = chezhan,
  106. Starttime = minStartTime,
  107. Endtime = maxStartTime,
  108. Filename = ysname,
  109. Filesize = wjdx,
  110. Filestatus = "正常",
  111. Taskstatus = "算法未执行",
  112. Srlj = lj,
  113. };
  114. }
  115. /// <summary>
  116. /// 刷新后恢复选中
  117. /// </summary>
  118. /// <param name="gv"></param>
  119. /// <param name="selectid"></param>
  120. public static void repushSFZT(GridView gv,List<int> selectid)
  121. {
  122. for (int i = 0; i < gv.RowCount; i++)
  123. {
  124. for (int j = 0; j < selectid.Count; j++)
  125. {
  126. if (gv.GetRowCellValue(i, "Id").ToString() == selectid[j].ToString())
  127. {
  128. gv.SelectRow(i);
  129. break;
  130. }
  131. }
  132. }
  133. }
  134. /// <summary>
  135. /// 获取刷新前id和状态
  136. /// </summary>
  137. /// <param name="gv"></param>
  138. /// <param name="selectid"></param>
  139. /// <param name="selectrowzt"></param>
  140. public static void getSFZT(GridView gv,ref List<int> selectid,ref List<string> selectrowzt)
  141. {
  142. var sele = gv.GetSelectedRows();
  143. foreach (var i in sele)
  144. {
  145. selectid.Add(Convert.ToInt32(gv.GetRowCellValue(i, "Id").ToString()));
  146. selectrowzt.Add(gv.GetRowCellValue(i, "Taskstatus").ToString());
  147. }
  148. }
  149. }
  150. }