CompositionDistributionGrid.cs 25 KB

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