CompositionDistributionGrid.cs 25 KB

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