DWCommon.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. public static string lj;
  19. public static List<T_dwfile_account> filelist = new List<T_dwfile_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_dwfile_account tfa = GLFileNameSplit1(file[i], xianluming, chezhan);
  35. //获取数据后
  36. var isfile = DataAnalysisToPG.DWQueryToPGByNameFile(tfa.Filename) as List<T_dwfile_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.GLInsertToPG(filelist);
  56. filelist.Clear();
  57. }
  58. public static void CancelAddFile()
  59. {
  60. filelist.Clear();
  61. }
  62. /// 清理数据库同名数据
  63. private static void filejiancedel(T_dwfile_account file)
  64. {
  65. //清除算法表
  66. List<T_dwfile_account> whichupdata = (List<T_dwfile_account>)DataAnalysisToPG.DWQueryToPGByNameFile(file.Filename);
  67. DataAnalysisToPG.DelToDWGL(file);
  68. DataAnalysisToPG.DelToDW(file);//清除功率表
  69. }
  70. /// 解析电务功率数据
  71. private static T_dwfile_account GLFileNameSplit1(string filename, string xianluming, string chezhan)
  72. {
  73. string ysname = Path.GetFileName(filename);
  74. string wjdx = Math.Round((new FileInfo(filename).Length / 1024.0 / 1024.0),2) + " MB";//文件大小
  75. //T_luxianming_sf xlpg = DataAnalysisToPG.QueryToXlm(xlbh[0]) as T_luxianming_sf;//获取线路名
  76. string lj = filename;//路径
  77. string minStartTime = null;//日期
  78. string maxStartTime = null;
  79. //解析文件
  80. using (StreamReader reader = new StreamReader(filename))
  81. {
  82. string line;
  83. while ((line = reader.ReadLine()) != null)
  84. {
  85. string[] parts = line.Split('$');
  86. if (parts.Length >= 9)
  87. {
  88. string quxianxuhao = parts[2];//曲线序号
  89. string caijikaishishijian = parts[3];//采集开始时间
  90. string caijihaoqianshijian = parts[4];//采集毫秒时间
  91. string fangxiabiaoji = parts[5];//点数
  92. string dianshu = parts[6]; //点数
  93. string gonglv = parts[7];//功率
  94. string fangcha = parts[8];//方差
  95. string quxianleixing = parts[9];//曲线类型
  96. DateTime startTime;
  97. if (DateTime.TryParseExact(caijikaishishijian, "yyyy-MM-dd HH:mm:ss", null, System.Globalization.DateTimeStyles.None, out startTime))
  98. {
  99. string formattedStartTime = startTime.ToString("yyyy-MM-dd HH:mm:ss");
  100. if (minStartTime == null || string.Compare(formattedStartTime, minStartTime) < 0)
  101. {
  102. minStartTime = formattedStartTime;
  103. }
  104. if (maxStartTime == null || string.Compare(formattedStartTime, maxStartTime) > 0)
  105. {
  106. maxStartTime = formattedStartTime;
  107. }
  108. }
  109. }
  110. }
  111. }
  112. return new T_dwfile_account()
  113. {
  114. //下次把车站线路写活
  115. Xianlu = xianluming,
  116. Chezhan = chezhan,
  117. Starttime = minStartTime,
  118. Endtime = maxStartTime,
  119. Filename = ysname,
  120. Filesize = wjdx,
  121. Filestatus = "正常",
  122. Taskstatus = "算法未执行",
  123. Srlj = lj,
  124. };
  125. }
  126. /// <summary>
  127. /// 刷新后恢复选中
  128. /// </summary>
  129. /// <param name="gv"></param>
  130. /// <param name="selectid"></param>
  131. public static void repushSFZT(GridView gv,List<int> selectid)
  132. {
  133. for (int i = 0; i < gv.RowCount; i++)
  134. {
  135. for (int j = 0; j < selectid.Count; j++)
  136. {
  137. if (gv.GetRowCellValue(i, "Id").ToString() == selectid[j].ToString())
  138. {
  139. gv.SelectRow(i);
  140. break;
  141. }
  142. }
  143. }
  144. }
  145. /// <summary>
  146. /// 获取刷新前id和状态
  147. /// </summary>
  148. /// <param name="gv"></param>
  149. /// <param name="selectid"></param>
  150. /// <param name="selectrowzt"></param>
  151. public static void getSFZT(GridView gv,ref List<int> selectid,ref List<string> selectrowzt)
  152. {
  153. var sele = gv.GetSelectedRows();
  154. foreach (var i in sele)
  155. {
  156. selectid.Add(Convert.ToInt32(gv.GetRowCellValue(i, "Id").ToString()));
  157. selectrowzt.Add(gv.GetRowCellValue(i, "Taskstatus").ToString());
  158. }
  159. }
  160. }
  161. }