DMCtrl.cs 16 KB

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