CompositionDistributionGrid.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. using DevExpress.Utils;
  2. using DevExpress.XtraCharts;
  3. using OTSCommon.DBOperate.Model;
  4. using OTSIncAReportApp;
  5. using OTSIncAReportApp._1_UI.Control_DEVCharts;
  6. using OTSIncAReportApp.DataOperation.DataAccess;
  7. using OTSIncAReportApp.OTSRstMgrFunction;
  8. using OTSIncAReportApp.OTSSampleReportInfo;
  9. using OTSIncAReportApp.SysMgrTools;
  10. using OTSIncAReportGraph.Class;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.Drawing;
  17. using System.Linq;
  18. using System.Windows.Forms;
  19. namespace OTSIncAReportGrids
  20. {
  21. /// <summary>
  22. /// 成分分布表 颗粒成份分布表
  23. /// </summary>
  24. public partial class CompositionDistributionGrid : UserControl
  25. {
  26. #region settings / fields
  27. // Internationalization
  28. Language lan;
  29. Hashtable table;
  30. // measurement results
  31. ResultFile result = null;
  32. OTSIncAReportApp.OTSSampleReportInfo.ReportCondition source;
  33. OTSIncAReportApp.frmReportApp m_ReportApp;
  34. frmReportConditionChoose m_condition;
  35. List<int> list_gridheight = new List<int>();
  36. //List<DataTable> list_table_data = new List<DataTable>();
  37. //List<Point> list_table_size = new List<Point>();
  38. //List<Point> list_table_Point = new List<Point>();
  39. //List<string> list_fileName = new List<string>();
  40. List<DataTable> list_table_data = new List<DataTable>();
  41. List<Point> list_table_size = new List<Point>();
  42. List<Point> list_table_Point = new List<Point>();
  43. List<string> list_fileName = new List<string>();
  44. int DataNumber = 0; // current dataset index
  45. List<ComboBox> list_ComboBox = new List<ComboBox>();
  46. List<ChartControl> list_ChartControl = new List<ChartControl>();
  47. int gridwidth = 0;
  48. int gridhigh = 0;
  49. int GridPosition = 0;
  50. int chartposition = 0;
  51. int indexGraphicType = 0;
  52. string GraphicType = "柱状图";
  53. // constants for column names used repeatedly
  54. private static readonly string ColRowId = "rowid";
  55. private static readonly string ColTypeName = "TypeName";
  56. private static readonly string ColTypeColor = "TypeColor";
  57. private static readonly string ColCount = "con";
  58. private static readonly string ColAreaRadio = "AreaRadio";
  59. private static readonly string ColAvg = "av";
  60. private static readonly string ColMax = "max";
  61. // list of possible chart types for combo boxes
  62. private static readonly string[] ChartTypes = new string[]
  63. {
  64. "柱状图","折线图","饼图","圆环图","气泡图","簇状条形图","堆积条形图","瀑布图",
  65. "3D柱状图","3D圆环图","3D饼图","3D折线图","3D百分比堆积条形图","3D漏斗图",
  66. "3DManhattan 条形图","3D堆积条形图","3D阶梯线图"
  67. };
  68. #endregion
  69. #region constructor / initialization
  70. public CompositionDistributionGrid(OTSIncAReportApp.frmReportApp ReportApp)
  71. {
  72. m_ReportApp = ReportApp ?? throw new ArgumentNullException(nameof(ReportApp));
  73. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  74. source = m_ReportApp.m_conditionChoose.m_conditionData;
  75. m_condition = ReportApp.m_conditionChoose;
  76. InitializeComponent();
  77. // internationalization
  78. lan = new Language(this);
  79. table = lan.GetNameTable(this.Name);
  80. }
  81. #endregion
  82. #region grid/chart building
  83. /// <summary>
  84. /// Primary method to bind one data source into a grid and optionally create chart controls.
  85. /// Refactored for clarity and reuse.
  86. /// </summary>
  87. public void BindDataGridView(string path, int num, string filename)
  88. {
  89. if (string.IsNullOrWhiteSpace(path)) return;
  90. // load translation strings once
  91. string str1 = table["str1"]?.ToString() ?? "No.";
  92. string str2 = table["str2"]?.ToString() ?? string.Empty;
  93. string str3 = table["str3"]?.ToString() ?? "Area";
  94. string str4 = table["str4"]?.ToString() ?? "Avg";
  95. string str5 = table["str5"]?.ToString() ?? string.Empty;
  96. string str6 = table["str6"]?.ToString() ?? "Max";
  97. string str7 = table["str7"]?.ToString() ?? "Max";
  98. string str8 = table["str8"]?.ToString() ?? "Name";
  99. string str9 = table["str9"]?.ToString() ?? "Color";
  100. string str10 = table["str10"]?.ToString() ?? "Count";
  101. string str11 = table["str11"]?.ToString() ?? string.Empty;
  102. string str13 = table["str13"]?.ToString() ?? "Area%";
  103. // prepare data access objects
  104. var particledata = new ParticleData(path);
  105. FieldData fielddata = new FieldData(path);
  106. // Determine diameter column based on settings
  107. string sizeMethod = m_ReportApp.m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  108. string po;
  109. switch (sizeMethod)
  110. {
  111. case "DMAX":
  112. po = "DMAX";
  113. break;
  114. case "DMIN":
  115. po = "DMIN";
  116. break;
  117. case "FERET":
  118. po = "DFERET";
  119. break;
  120. case "ECD":
  121. po = "Area";
  122. break;
  123. default:
  124. po = "Area";
  125. break;
  126. }
  127. // compute total area used in percentage calculation
  128. double totalArea = ComputeTotalArea(result, fielddata);
  129. // fetch data table
  130. DataTable dt = particledata.GetParticleStatisticDataListByIncA(po) ?? new DataTable();
  131. // create and set up grid
  132. var gridView = new OTSGridView();
  133. CreateGridColumns(gridView, str1, str8, str9, str10, str13, sizeMethod, str3, str4, str6, str7);
  134. gridView.MergeColumnNames.Add(filename);
  135. gridView.AddSpanHeader(1, gridView.Columns.Count - 1, filename);
  136. // populate rows for TypeId >=100 (custom types) and for predefined types TypeId <=100
  137. PopulateGridRows(gridView, dt, totalArea, sizeMethod, filename, true);
  138. PopulateGridRows(gridView, dt, totalArea, sizeMethod, filename, false);
  139. gridView.Name = "gridView" + num.ToString();
  140. Point point = SetDataGridViewStyle(gridView);
  141. list_table_Point.Add(point);
  142. gridView.Location = new Point(point.X, point.Y + (DataNumber * 300));
  143. AddSumRow(gridView);
  144. panel1.Controls.Add(gridView);
  145. list_table_data.Add(dt);
  146. list_fileName.Add(filename);
  147. }
  148. private double ComputeTotalArea(ResultFile resultFile, FieldData fielddata)
  149. {
  150. try
  151. {
  152. if (resultFile == null || fielddata == null) return 0.0;
  153. double scanFieldSize = resultFile.GetScanFieldSizeX();
  154. double wide = resultFile.GetImageWidth();
  155. double high = resultFile.GetImageHeight();
  156. int filedCount = fielddata.GetFiledCount();
  157. double pixelSize = scanFieldSize / wide;
  158. // total scanned area = per-field width*height * number of fields (in OTS coordinates)
  159. // in original code totalArea = high * pixelSize * wide * pixelSize * filedCount;
  160. return high * pixelSize * wide * pixelSize * filedCount;
  161. }
  162. catch (Exception ex)
  163. {
  164. Debug.WriteLine("ComputeTotalArea failed: " + ex);
  165. return 0.0;
  166. }
  167. }
  168. private void CreateGridColumns(OTSGridView gridView, string headerRowId, string headerTypeName, string headerTypeColor, string headerCount, string headerAreaPct, string sizeMethod,
  169. string headerArea, string headerAvg, string headerMaxAlt, string headerMax)
  170. {
  171. gridView.Columns.Clear();
  172. gridView.Columns.Add(ColRowId, headerRowId);
  173. gridView.Columns.Add(ColTypeName, headerTypeName);
  174. gridView.Columns.Add(ColTypeColor, headerTypeColor);
  175. gridView.Columns.Add(ColCount, headerCount);
  176. gridView.Columns.Add(ColAreaRadio, headerAreaPct);
  177. if (sizeMethod == "ECD")
  178. {
  179. gridView.Columns.Add(ColAvg, headerArea);
  180. gridView.Columns.Add(ColMax, headerMaxAlt);
  181. }
  182. else
  183. {
  184. gridView.Columns.Add(ColAvg, headerAvg);
  185. gridView.Columns.Add(ColMax, headerMax);
  186. }
  187. }
  188. private void PopulateGridRows(OTSGridView gridView, DataTable dt, double totalArea, string sizeMethod, string filename, bool customTypesFirst)
  189. {
  190. if (dt == null || gridView == null) return;
  191. // When customTypesFirst == true, process TypeId >= 100 (original code)
  192. for (int i = 0; i < dt.Rows.Count; i++)
  193. {
  194. if (customTypesFirst)
  195. {
  196. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100) continue;
  197. }
  198. else
  199. {
  200. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) >= 100) continue;
  201. }
  202. int addRowIndex = gridView.Rows.Add();
  203. gridView.Rows[addRowIndex].Tag = "Statistics";
  204. gridView.Rows[addRowIndex].Cells[0].Value = addRowIndex + 1;
  205. for (int k = 1; k < gridView.ColumnCount; k++)
  206. {
  207. var colName = gridView.Columns[k].Name;
  208. if (string.Equals(colName, ColTypeColor, StringComparison.OrdinalIgnoreCase) && dt.Rows[i]["TypeColor"] != DBNull.Value && dt.Rows[i]["TypeColor"].ToString() != "")
  209. {
  210. string color = dt.Rows[i]["TypeColor"].ToString();
  211. if (!color.Contains("#")) color = "#" + color;
  212. try
  213. {
  214. gridView.Rows[addRowIndex].Cells[k].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  215. }
  216. catch
  217. {
  218. gridView.Rows[addRowIndex].Cells[k].Style.BackColor = Color.Black;
  219. }
  220. }
  221. else if (string.Equals(colName, ColAvg, StringComparison.OrdinalIgnoreCase) || string.Equals(colName, ColMax, StringComparison.OrdinalIgnoreCase))
  222. {
  223. double value = 0;
  224. double.TryParse(dt.Rows[i][gridView.Columns[k].Name].ToString(), out value);
  225. if (sizeMethod == "ECD")
  226. {
  227. // value interpreted as area -> convert to diameter
  228. double area = value;
  229. gridView.Rows[addRowIndex].Cells[k].Value = Math.Round(Math.Sqrt(area / Math.PI) * 2, 2);
  230. }
  231. else
  232. {
  233. gridView.Rows[addRowIndex].Cells[k].Value = Math.Round(value , 2);
  234. }
  235. gridView.Rows[addRowIndex].Cells[k].Style.BackColor = Color.Azure;
  236. }
  237. else if (string.Equals(colName, ColAreaRadio, StringComparison.OrdinalIgnoreCase))
  238. {
  239. if (totalArea == 0)
  240. {
  241. gridView.Rows[addRowIndex].Cells[k].Value = 0;
  242. }
  243. else
  244. {
  245. double areaVal = 0;
  246. double.TryParse(dt.Rows[i]["Area"].ToString(), out areaVal);
  247. gridView.Rows[addRowIndex].Cells[k].Value = Math.Round(areaVal * 100 / totalArea, customTypesFirst ? 3 : 5);
  248. }
  249. gridView.Rows[addRowIndex].Cells[k].Style.BackColor = Color.Azure;
  250. }
  251. else
  252. {
  253. gridView.Rows[addRowIndex].Cells[k].Value = dt.Rows[i][gridView.Columns[k].Name];
  254. gridView.Rows[addRowIndex].Cells[k].Style.BackColor = Color.Azure;
  255. }
  256. }
  257. }
  258. }
  259. void AddSumRow(OTSGridView gridView)
  260. {
  261. if (gridView == null || gridView.Rows == null || gridView.Rows.Count == 0)
  262. return;
  263. int sumRowIndex = gridView.Rows.Add();
  264. gridView.Rows[sumRowIndex].Tag = "Sum";
  265. gridView.Rows[sumRowIndex].Cells[1].Value = "Sum";
  266. gridView.Refresh();
  267. long totalCount = 0;
  268. double totalArea = 0.0;
  269. for (int j = 0; j < gridView.Rows.Count - 1; j++)
  270. {
  271. if (gridView.Rows[j].Tag == null) continue;
  272. try
  273. {
  274. var cntObj = gridView.Rows[j].Cells[3].Value;
  275. if (cntObj != null && long.TryParse(cntObj.ToString(), out long cntVal))
  276. totalCount += cntVal;
  277. var areaObj = gridView.Rows[j].Cells[4].Value;
  278. if (areaObj != null && double.TryParse(areaObj.ToString(), out double areaVal))
  279. totalArea += areaVal;
  280. }
  281. catch { /* ignore malformed rows */ }
  282. }
  283. // assign sums
  284. gridView.Rows[sumRowIndex].Cells[3].Value = totalCount;
  285. gridView.Rows[sumRowIndex].Cells[4].Value = totalArea;
  286. gridView.Rows[sumRowIndex].Height = gridView.Rows[Math.Max(0, sumRowIndex - 1)].Height;
  287. for (int j = 1; j < gridView.Columns.Count; j++)
  288. {
  289. gridView.Rows[sumRowIndex].DefaultCellStyle.BackColor = Color.Azure;
  290. }
  291. //gridView.Rows[sumRowIndex].Height = 30;
  292. gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30);
  293. }
  294. private Point SetDataGridViewStyle(OTSGridView gridView)
  295. {
  296. // user can't change header height
  297. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  298. // user can't change row height
  299. gridView.AllowUserToResizeRows = false;
  300. gridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  301. var centeredStyle = new DataGridViewCellStyle
  302. {
  303. Alignment = DataGridViewContentAlignment.MiddleCenter
  304. };
  305. gridView.DefaultCellStyle = centeredStyle;
  306. gridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  307. gridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  308. gridView.Columns[0].Width = 40;
  309. gridView.Columns[1].Width = 200;
  310. gridView.Columns[0].Resizable = DataGridViewTriState.False;
  311. gridView.AllowUserToAddRows = false;
  312. gridView.AllowUserToDeleteRows = false;
  313. gridView.AllowUserToResizeRows = false;
  314. gridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
  315. gridView.RowHeadersVisible = false;
  316. gridView.RowHeadersWidth = 40;
  317. gridView.RowTemplate.Height = 30;
  318. int gridViewHeight = 0;
  319. for (int i = 0; i < gridView.Rows.Count; i++)
  320. {
  321. gridViewHeight= gridViewHeight+ gridView.Rows[i].Height;
  322. }
  323. gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridViewHeight);
  324. //gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30);
  325. int gridheight = gridViewHeight + 7;
  326. gridhigh = gridhigh + gridViewHeight+2;
  327. //gridwidth = gridwidth + gridView.ColumnCount * 100 + 60;
  328. chartposition = chartposition + gridView.ColumnCount * 100;
  329. GridPosition = gridView.ColumnCount * 100 + 40;
  330. list_gridheight.Add(gridheight);
  331. gridView.TabIndex = 0;
  332. gridView.ContextMenuStrip = this.contextMenuStrip1;
  333. gridView.BorderStyle = 0;
  334. gridView.ReadOnly = true;
  335. gridView.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(this.Gview_ColumnHeaderMouseClick);
  336. gridView.Sorted += new System.EventHandler(this.Gview_gz_Sorted);
  337. // set header height a bit taller for aesthetics
  338. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  339. gridView.ColumnHeadersHeight = 40;
  340. list_table_size.Add(new Point(gridView.ColumnCount * 100 + 40, gridViewHeight+30 ));
  341. //return new Point(gridwidth - (gridView.ColumnCount * 100 + 60), gridheight + 5);
  342. return new Point(0, gridhigh- gridViewHeight-2);
  343. }
  344. #endregion
  345. #region charts
  346. public void SetGraphicType(ReportCondition sourceGridData)
  347. {
  348. if (sourceGridData == null) return;
  349. string stdId_TYPE = "";
  350. int stdIdIndex = 0;
  351. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.GRAPHIC_TYPE);
  352. if (STDIdItm != null)
  353. {
  354. stdId_TYPE = STDIdItm.itemDisplayVal.ToString();
  355. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId_TYPE);
  356. }
  357. indexGraphicType = stdIdIndex;
  358. GraphicType = stdId_TYPE;
  359. int high = 0;
  360. for (int i = 0; i < list_table_Point.Count; i++)
  361. {
  362. if (high < list_table_Point[i].Y)
  363. {
  364. high = list_table_Point[i].Y;
  365. }
  366. }
  367. for (int i = 0; i < list_table_data.Count; i++)
  368. {
  369. DataNumber = i;
  370. Graphics(list_table_data[i], list_fileName[i], stdId_TYPE, list_table_size[i], list_table_Point[i], high);
  371. }
  372. }
  373. private void Graphics(DataTable data, string filename, string comboBox1Text, Point a_size, Point a_Location, int location_hig)
  374. {
  375. var chartControl1 = new ChartControl();
  376. chartControl1.Series.Clear();
  377. Series series = new Series(filename, ViewType.Bar);
  378. if (data != null)
  379. {
  380. for (int a = 0; a < data.Rows.Count; a++)
  381. {
  382. string name = data.Rows[a]["TypeName"].ToString();
  383. double cnt = 0;
  384. double.TryParse(data.Rows[a]["con"].ToString(), out cnt);
  385. series.Points.Add(new SeriesPoint(name, cnt));
  386. }
  387. }
  388. series.LabelsVisibility = DefaultBoolean.True;
  389. chartControl1.Series.Add(series);
  390. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  391. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  392. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  393. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  394. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  395. chartControl1.CrosshairOptions.ShowValueLine = true;
  396. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  397. DevFunctions.ChangeView2(chartControl1, comboBox1Text);
  398. chartControl1.Location = new Point(a_Location.X+ a_size.X+20, a_Location.Y + 20 + (DataNumber * 300));
  399. chartControl1.Size = new Size(a_size.X, a_size.Y);
  400. var diagram = chartControl1.Diagram as XYDiagram;
  401. if (diagram != null)
  402. {
  403. diagram.AxisX.Title.Text = "种类";
  404. diagram.AxisX.Title.Visibility = DevExpress.Utils.DefaultBoolean.True;
  405. diagram.AxisY.Title.Text = "数量";
  406. diagram.AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.True;
  407. }
  408. // prepare combo box for chart type selection (re-use ChartTypes constant)
  409. var comboBox = new ComboBox();
  410. list_ChartControl.Add(chartControl1);
  411. list_ComboBox.Add(comboBox);
  412. comboBox.Items.AddRange(ChartTypes);
  413. comboBox.Name = Convert.ToString(list_ComboBox.Count - 1);
  414. comboBox.SelectedIndex = 0;
  415. comboBox.Location = new Point(a_Location.X + a_size.X +20+ chartControl1.Size.Width - 100, a_Location.Y + (DataNumber * 300));
  416. comboBox.Size = new Size(100, 25);
  417. comboBox.SelectedIndexChanged += ComboBox_SelectedIndexChanged;
  418. panel1.Controls.Add(chartControl1);
  419. panel1.Controls.Add(comboBox);
  420. }
  421. private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
  422. {
  423. var comboBox = sender as ComboBox;
  424. if (comboBox == null) return;
  425. if (int.TryParse(comboBox.Name, out int idx) && idx >= 0 && idx < list_ChartControl.Count)
  426. {
  427. DevFunctions.ChangeView2(list_ChartControl[idx], comboBox.Text);
  428. }
  429. }
  430. #endregion
  431. #region events / UI actions
  432. private void CompositionDistributionGrid_Load(object sender, EventArgs e)
  433. {
  434. list_table_data.Clear();
  435. list_table_size.Clear();
  436. list_table_Point.Clear();
  437. list_fileName.Clear();
  438. int ii = 0;
  439. string sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  440. if (sou.Contains("+"))
  441. {
  442. foreach (var name in sou.Split('+'))
  443. {
  444. var resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == name);
  445. if (resultFile != null)
  446. {
  447. DataNumber = ii;
  448. BindDataGridView(resultFile.FilePath, list_fileName.Count, resultFile.anotherFileName);
  449. ii++;
  450. }
  451. }
  452. }
  453. else
  454. {
  455. var match = m_ReportApp.m_rstDataMgr.ResultFilesList.FirstOrDefault(r => r.anotherFileName == sou);
  456. if (match != null)
  457. {
  458. BindDataGridView(match.FilePath, 0, match.anotherFileName);
  459. }
  460. }
  461. }
  462. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  463. {
  464. OTSGridView otv = (OTSGridView)((ContextMenuStrip)(sender as ToolStripMenuItem).Owner).SourceControl;
  465. CopyAll(otv);
  466. }
  467. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  468. {
  469. OTSGridView otv = (OTSGridView)((ContextMenuStrip)(sender as ToolStripMenuItem).Owner).SourceControl;
  470. CopySelected(otv);
  471. }
  472. public void CopySelected(OTSGridView in_ogv)
  473. {
  474. if (in_ogv == null) return;
  475. Clipboard.SetDataObject(in_ogv.GetClipboardContent());
  476. }
  477. public void CopySelected()
  478. {
  479. var dgv = panel1.Controls.OfType<DataGridView>().FirstOrDefault();
  480. if (dgv == null) return;
  481. Clipboard.SetDataObject(dgv.GetClipboardContent());
  482. }
  483. public void CopyAll(OTSGridView in_ogv)
  484. {
  485. if (in_ogv == null) return;
  486. in_ogv.SelectAll();
  487. Clipboard.SetDataObject(in_ogv.GetClipboardContent());
  488. }
  489. public void CopyAll()
  490. {
  491. var dgv = panel1.Controls.OfType<DataGridView>().FirstOrDefault();
  492. if (dgv == null) return;
  493. dgv.SelectAll();
  494. Clipboard.SetDataObject(dgv.GetClipboardContent());
  495. }
  496. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  497. {
  498. // remove only OTSGridView controls
  499. var toRemove = panel1.Controls.OfType<OTSGridView>().ToArray();
  500. foreach (var g in toRemove) panel1.Controls.Remove(g);
  501. list_table_data.Clear();
  502. list_table_size.Clear();
  503. list_table_Point.Clear();
  504. list_fileName.Clear();
  505. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  506. if (sou.Contains("+"))
  507. {
  508. int ii = 0;
  509. foreach (var name in sou.Split('+'))
  510. {
  511. var resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == name);
  512. if (resultFile != null)
  513. {
  514. DataNumber = ii;
  515. BindDataGridView(resultFile.FilePath, list_fileName.Count, resultFile.anotherFileName);
  516. ii++;
  517. }
  518. }
  519. }
  520. else
  521. {
  522. var match = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  523. BindDataGridView(match.FilePath, 0, match.anotherFileName);
  524. }
  525. }
  526. void Gview_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  527. {
  528. var grid = sender as OTSGridView;
  529. if (grid == null || grid.Rows == null || grid.Rows.Count == 0) return;
  530. AddSumRow(grid);
  531. }
  532. private void Gview_gz_Sorted(object sender, EventArgs e)
  533. {
  534. var grid = sender as OTSGridView;
  535. if (grid == null || grid.Rows == null || grid.Rows.Count == 0) return;
  536. for (int i = 0; i < grid.Rows.Count; i++)
  537. {
  538. if (grid.Rows[i].Tag != null && grid.Rows[i].Tag.ToString() == "Sum")
  539. {
  540. grid.Rows.RemoveAt(i);
  541. break;
  542. }
  543. }
  544. grid.Refresh();
  545. for (int i = 0; i < grid.Rows.Count; i++)
  546. {
  547. grid.Rows[i].Cells[0].Value = (i + 1).ToString();
  548. }
  549. }
  550. #endregion
  551. }
  552. }