CompositionDistributionGrid.cs 25 KB

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