DMCtrl.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using DevExpress.XtraEditors;
  6. using DevExpress.XtraGrid.Columns;
  7. using DevExpress.XtraGrid.Views.Grid;
  8. using Uninpho.Tools.components.DataManager;
  9. using Uninpho.DBOperation.Operation;
  10. using Uninpho.DBOperation.Model;
  11. using DevExpress.XtraGrid.Localization;
  12. using Uninpho.Tools.components;
  13. using Uninpho.Railway.Waveform;
  14. using System.Linq;
  15. namespace Uninpho.Tools
  16. {
  17. public partial class DMCtrl : DevExpress.XtraEditors.XtraUserControl
  18. {
  19. List<GridColumn> colums = new List<GridColumn>();
  20. object dataSource = null;
  21. bool Init = false;
  22. Dictionary<string, decimal> filterCondition = new Dictionary<string, decimal>();
  23. public GridView gridView { get { return this.dmGrid1.gridView; } }
  24. public DMCtrl()
  25. {
  26. InitializeComponent();
  27. }
  28. #region 事件
  29. /// <summary>
  30. /// 趋势分析
  31. /// </summary>
  32. /// <param name="sender"></param>
  33. /// <param name="e"></param>
  34. private void simpleButton1_Click(object sender, EventArgs e)
  35. {
  36. if (this.gridView.SelectedRowsCount >= 2)
  37. {
  38. int[] idx = this.gridView.GetSelectedRows();
  39. List<object> rows = new List<object>();
  40. foreach (var item in idx)
  41. {
  42. //string rq = this.gridView.GetRowCellDisplayText(item, "jcrq");
  43. //if (string.IsNullOrEmpty(rq))
  44. //{
  45. // XtraMessageBox.Show("检测日期为空", "提示");
  46. // return;
  47. //}
  48. //else
  49. rows.Add(this.gridView.GetRow(item));
  50. }
  51. List<PZClass> pzlgl = new List<PZClass>();
  52. List<PZClass> pzjh = new List<PZClass>();
  53. var lglMeta = MetaDataCtrl.GetMetaData("t_lunguili_account");
  54. var jhfxMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account");
  55. List<CoorListClass> listarr = new List<CoorListClass>();
  56. List<CoorListClass> listarr1 = new List<CoorListClass>();
  57. fillDataqs(lglMeta, rows, ref pzlgl, ref listarr);
  58. fillDataqs(jhfxMeta, rows,ref pzjh,ref listarr1);
  59. listarr = listarr.Union(listarr1).ToList();
  60. //var pzda = pzlgl.Union(pzjh).ToList();
  61. List<PZClass> pzda = null;
  62. QSFXForm frm = new QSFXForm(ConvDict(listarr), pzda);
  63. frm.StartPosition = FormStartPosition.CenterParent;
  64. frm.ShowDialog();
  65. //FrmAnalyze frm = new FrmAnalyze("趋势分析");
  66. //frm.LoadQSFXData(rows);
  67. //frm.StartPosition = FormStartPosition.CenterParent;
  68. //frm.ShowDialog(this);
  69. }
  70. else
  71. {
  72. XtraMessageBox.Show("请选择两条以上需要分析的数据", "提示");
  73. }
  74. }
  75. /// <summary>
  76. /// 把List<CoorListClass>转为Dictionary<>
  77. /// </summary>
  78. private Dictionary<string,CoorListClass> ConvDict(List<CoorListClass> listdata)
  79. {
  80. Dictionary<string, CoorListClass> dict = new Dictionary<string, CoorListClass>();
  81. for (int i = 0; i < listdata.Count; i++)
  82. {
  83. if (!dict.ContainsKey(listdata[i].ListId))
  84. {
  85. dict.Add(listdata[i].ListId, listdata[i]);
  86. }
  87. }
  88. return dict;
  89. }
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <param name="dataMeta"></param>
  94. /// <param name="rows"></param>
  95. private void fillDataqs(List<T_metadata_account> dataMeta, List<object> rows,ref List<PZClass> pzdada ,ref List<CoorListClass> coorlist)
  96. {
  97. List<CoorListClass> listarr = new List<CoorListClass>();
  98. List<PZClass> pzda = new List<PZClass>();
  99. dataMeta.ForEach(column =>
  100. {
  101. if (column.ttype == "number" && column.chname != "序号")
  102. {
  103. CoorListClass newlist = new CoorListClass();
  104. newlist.ListId = column.name;
  105. newlist.ListName = column.chname;
  106. pzda.Add(new PZClass()
  107. {
  108. Id= newlist.ListId,
  109. Name = newlist.ListName
  110. });
  111. newlist.Scale = 1;
  112. newlist.Width = 5;
  113. newlist.Offset = 0.001;
  114. newlist.RGBA = new int[] { 0, 200, 255, 255 };
  115. newlist.CoorList = new List<PointF>();
  116. newlist.qsfxXstring = new List<string>();
  117. float i = 1.0F;
  118. foreach (var row in rows)
  119. {
  120. string riqi = getRowData(row, "jcrq").ToString();
  121. newlist.qsfxXstring.Add(riqi);
  122. object objVal = getRowData(row, column.name);
  123. if (objVal != null && objVal.ToString() != "")
  124. {
  125. newlist.CoorList.Add(new PointF(i, (float)Convert.ToDecimal(objVal.ToString())));
  126. }
  127. i = i + 1.0F;
  128. }
  129. if (newlist.CoorList.Count != 0)
  130. {
  131. listarr.Add(newlist);
  132. }
  133. }
  134. });
  135. coorlist = listarr;
  136. pzdada = pzda;
  137. }
  138. private object getRowData(object row, string column)
  139. {
  140. object val = "";
  141. foreach (var item in (IDictionary<string, object>)row)
  142. {
  143. if (column.ToLower() == item.Key.ToLower())
  144. {
  145. val = item.Value;
  146. break;
  147. }
  148. }
  149. return val;
  150. }
  151. private bool isEqual(int[] rowIds, string name)
  152. {
  153. bool isEqual = false;
  154. for (int i=0;i< rowIds.Length-1;i++)
  155. {
  156. isEqual = this.gridView.GetRowCellDisplayText(rowIds[i], name) == this.gridView.GetRowCellDisplayText(rowIds[i + 1], name);
  157. }
  158. return isEqual;
  159. }
  160. /// <summary>
  161. /// 查看波形图
  162. /// </summary>
  163. /// <param name="sender"></param>
  164. /// <param name="e"></param>
  165. private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
  166. {
  167. int[] rowhandles = this.gridView.GetSelectedRows();
  168. int rowhandle = this.gridView.FocusedRowHandle;
  169. String yswjm_lgl = this.gridView.GetRowCellDisplayText(rowhandle, "yswjm");
  170. String yswjm_jhfx = this.gridView.GetRowCellDisplayText(rowhandle, "yswjm_jhfx");
  171. if (string.IsNullOrEmpty(yswjm_lgl) && string.IsNullOrEmpty(yswjm_lgl))
  172. {
  173. XtraMessageBox.Show("波形数据为空!", "提示");
  174. return;
  175. }
  176. else
  177. {
  178. FrmAnalyze anaFrm = new FrmAnalyze("波形查看");
  179. anaFrm.StartPosition = FormStartPosition.CenterParent;
  180. anaFrm.LoadBXZSData(new List<string>() { yswjm_lgl }, new List<string>() { yswjm_jhfx });
  181. anaFrm.ShowDialog(this);
  182. }
  183. }
  184. /// <summary>
  185. /// 波形分析
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void simpleButton3_Click(object sender, EventArgs e)
  190. {
  191. if (this.gridView.SelectedRowsCount == 2)
  192. {
  193. int[] idx = this.gridView.GetSelectedRows();
  194. List<string> yswjm_jhfx = new List<string>();
  195. List<string> yswjm_lgl = new List<string>();
  196. //string rq1 = this.gridView.GetRowCellDisplayText(idx[0], "jcrq");
  197. //string rq2 = this.gridView.GetRowCellDisplayText(idx[1], "jcrq");
  198. //if (string.IsNullOrEmpty(rq1)|| string.IsNullOrEmpty(rq2))
  199. //{
  200. // XtraMessageBox.Show("提示", "检测日期为空");
  201. // return;
  202. //}
  203. string jcrq="";
  204. if (isEqual(idx, "xlm") && isEqual(idx, "xingbie") && isEqual(idx, "dcbh"))
  205. {
  206. foreach (int id in idx)
  207. {
  208. string val = this.gridView.GetRowCellDisplayText(id, "yswjm_jhfx");
  209. if (!string.IsNullOrEmpty(val))
  210. yswjm_jhfx.Add(val);
  211. val = this.gridView.GetRowCellDisplayText(id, "yswjm");
  212. if (!string.IsNullOrEmpty(val))
  213. {
  214. yswjm_lgl.Add(val);
  215. }
  216. else
  217. {
  218. }
  219. if (string.IsNullOrEmpty(jcrq))
  220. jcrq += this.gridView.GetRowCellDisplayText(id, "jcrq");
  221. else
  222. jcrq += " , " + this.gridView.GetRowCellDisplayText(id, "jcrq");
  223. }
  224. if (yswjm_jhfx.Count == 2 || yswjm_lgl.Count == 2)
  225. {
  226. BXDBFrom frm = new BXDBFrom(yswjm_lgl, yswjm_jhfx);
  227. frm.StartPosition = FormStartPosition.CenterParent;
  228. frm.ShowDialog();
  229. //FrmAnalyze frm = new FrmAnalyze("波形分析");
  230. //frm.LoadBXZSData(yswjm_lgl, yswjm_jhfx);
  231. //frm.SetJCRQ(string.Format("检测日期:{0}",jcrq));
  232. //frm.StartPosition = FormStartPosition.CenterParent;
  233. //frm.ShowDialog(this);
  234. }
  235. else
  236. {
  237. XtraMessageBox.Show( "波形数据为空,请重新选择两条需要分析的数据", "提示");
  238. }
  239. }
  240. else
  241. {
  242. XtraMessageBox.Show("线路名 行别 道岔编号不一致,请重新选择两条需要分析的数据", "提示");
  243. }
  244. }
  245. else
  246. {
  247. XtraMessageBox.Show("选择的数据不符合分析条件,请重新选择两条需要分析的数据", "提示");
  248. }
  249. }
  250. /// <summary>
  251. /// 阈值设置
  252. /// </summary>
  253. /// <param name="sender"></param>
  254. /// <param name="e"></param>
  255. private void btn_dm_settting_Click(object sender, EventArgs e)
  256. {
  257. FrmSetting frm = new FrmSetting(filterCondition);
  258. frm.StartPosition = FormStartPosition.CenterParent;
  259. if (frm.ShowDialog(this) == DialogResult.OK)
  260. {
  261. this.FilterData(frm.Condition);
  262. }
  263. }
  264. /// <summary>
  265. /// 导出Excel
  266. /// </summary>
  267. /// <param name="sender"></param>
  268. /// <param name="e"></param>
  269. private void simpleButton2_Click(object sender, EventArgs e)
  270. {
  271. int[] rowhandles = this.gridView.GetSelectedRows();
  272. if (rowhandles.Length > 0)
  273. {
  274. SaveFileDialog saveFileDialog = new SaveFileDialog();
  275. saveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
  276. if (saveFileDialog.ShowDialog() == DialogResult.OK)
  277. {
  278. this.gridView.OptionsPrint.PrintSelectedRowsOnly = true;
  279. DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
  280. this.gridView.ExportToXls(saveFileDialog.FileName, options);
  281. XtraMessageBox.Show("导出成功");
  282. this.gridView.OptionsPrint.PrintSelectedRowsOnly = false;
  283. }
  284. }
  285. else
  286. {
  287. XtraMessageBox.Show("请勾选数据");
  288. }
  289. }
  290. /// <summary>
  291. /// 查询
  292. /// </summary>
  293. /// <param name="sender"></param>
  294. /// <param name="e"></param>
  295. private void btn_dm_query_Click(object sender, EventArgs e)
  296. {
  297. this.dmGrid1.FilterDate(this.dateEdit1.DateTime, this.dateEdit2.DateTime);
  298. }
  299. /// <summary>
  300. /// 重置
  301. /// </summary>
  302. /// <param name="sender"></param>
  303. /// <param name="e"></param>
  304. private void simpleButton4_Click(object sender, EventArgs e)
  305. {
  306. this.dateEdit1.EditValue = null;
  307. this.dateEdit2.EditValue = null;
  308. this.dmGrid1.resetTable();
  309. }
  310. /// <summary>
  311. /// 数据阈值过滤
  312. /// </summary>
  313. /// <param name="condition"></param>
  314. private void FilterData(Dictionary<string,decimal> condition)
  315. {
  316. string strSQL = "";
  317. filterCondition = condition;
  318. foreach (KeyValuePair<string, decimal> kvp in condition)
  319. {
  320. if (string.IsNullOrEmpty(strSQL))
  321. strSQL = string.Format("[{0}] <= {1} or [{0}] >= {2}", kvp.Key, kvp.Value - 2 * kvp.Value, kvp.Value);
  322. else
  323. {
  324. strSQL += string.Format(" And [{0}] <= {1} or [{0}] >= {2}", kvp.Key, kvp.Value - 2 * kvp.Value, kvp.Value);
  325. }
  326. }
  327. this.gridView.ActiveFilterString = strSQL;// "[cxsd] != 30.0m";
  328. }
  329. private void InverseSelection()
  330. {
  331. int count = this.gridView.RowCount;
  332. for (int i = 0; i < count; i++)
  333. {
  334. this.gridView.InvertRowSelection(i);
  335. }
  336. }
  337. private void checkEdit1_CheckedChanged(object sender, EventArgs e)
  338. {
  339. if (checkEdit1.Checked)
  340. {
  341. this.gridView.SelectAll();
  342. }
  343. else
  344. {
  345. this.gridView.SelectRows(0, 0);
  346. }
  347. }
  348. private void checkEdit2_CheckedChanged(object sender, EventArgs e)
  349. {
  350. InverseSelection();
  351. }
  352. #endregion
  353. private void dmGrid1_Load(object sender, EventArgs e)
  354. {
  355. }
  356. private void btn_dm_ref_Click(object sender, EventArgs e)
  357. {
  358. this.dmGrid1.LoadData();
  359. }
  360. /// <summary>
  361. /// 删除
  362. /// </summary>
  363. private void delBtn_Click(object sender, EventArgs e)
  364. {
  365. if (UserInform.userinf.Pow == 0)
  366. {
  367. XtraMessageBox.Show("您无权删除数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  368. }
  369. else
  370. {
  371. int[] rowhandles = this.gridView.GetSelectedRows();
  372. if (rowhandles.Length == 0)
  373. {
  374. XtraMessageBox.Show("请选中删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  375. }
  376. else
  377. {
  378. if (XtraMessageBox.Show("是否删除所选?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  379. {
  380. foreach (int item in rowhandles)
  381. {
  382. string jhbxids = this.gridView.GetRowCellDisplayText(item, "yswjm_jhfx");
  383. string lglbxids = this.gridView.GetRowCellDisplayText(item, "yswjm");
  384. string xlm = this.gridView.GetRowCellDisplayText(item, "xlm");
  385. string hangbie = this.gridView.GetRowCellDisplayText(item, "xingbie");
  386. string jgjlc = this.gridView.GetRowCellDisplayText(item, "jgjlc");
  387. //string glgid = this.gridView.GetRowCellDisplayText(item, "lgl_id");
  388. //string jhid = this.gridView.GetRowCellDisplayText(item, "jhfx_id");
  389. DataAnalysisToPG.DelSJZS(lglbxids, jhbxids, xlm, hangbie, jgjlc);
  390. }
  391. this.dmGrid1.LoadData();
  392. XtraMessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  393. }
  394. }
  395. }
  396. }
  397. }
  398. }