ParticlesSizeGrid.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. using DevExpress.Utils;
  2. using DevExpress.XtraCharts;
  3. using DevExpress.XtraRichEdit.Layout;
  4. using OTSIncAReportApp._1_UI.Control_DEVCharts;
  5. using OTSIncAReportApp.OTSRstMgrFunction;
  6. using OTSIncAReportApp.OTSSampleReportInfo;
  7. using OTSIncAReportApp.SysMgrTools;
  8. using OTSIncAReportGraph.Class;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. namespace OTSIncAReportGrids
  17. {
  18. /// <summary>
  19. /// 颗粒尺寸分布表 颗粒尺寸表
  20. /// </summary>
  21. public partial class ParticlesSizeGrid : UserControl
  22. {
  23. #region 设置变量
  24. //设置模拟数据表
  25. public DataTable m_dt = new DataTable();
  26. //国际化
  27. Language lan;
  28. Hashtable table;
  29. //测量结果
  30. ResultFile resultFile = null;
  31. OTSIncAReportApp.OTSSampleReportInfo.ReportCondition reportCondition;
  32. OTSIncAReportApp.frmReportApp m_ReportApp;
  33. int gridheight = 0;
  34. int gridwidth = 0;
  35. public string condition = "";
  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. #endregion
  41. #region 自定义方法
  42. private string getWhere(string max, string min, string col, string partic)
  43. {
  44. if (col == "Area")
  45. {
  46. return col + ">=" + ((Convert.ToDouble(min)/2) * (Convert.ToDouble(min)/2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max)/2) * (Convert.ToDouble(max)/2) * Math.PI).ToString() + " and TypeId=" + partic;
  47. }
  48. else
  49. {
  50. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  51. }
  52. }
  53. /// <summary>
  54. /// 绑定datagridview数据
  55. /// </summary>
  56. public void UpdateDataGrid(string path, int num, string filename)
  57. {
  58. List<string> colid = new List<string>() { "rowid", "pname", "color", "TypeId", "Largest", "Total" };
  59. List<string> colname = new List<string>() { table["str1"].ToString(), table["str8"].ToString(), table["str9"].ToString(), "TypeId", table["str10"].ToString(), table["str11"].ToString() };
  60. OTSGridView gridView = new OTSGridView();
  61. gridView.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(Gview_ColumnHeaderMouseClick);
  62. gridView.Sorted += Gview_gz_Sorted;
  63. OTSIncAReportApp.DataOperation.DataAccess.ParticleData particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(path);
  64. DataTable dtp = particledata.GetParticleAll("");
  65. string sizestr = null;
  66. string con = "";
  67. if (condition != "")
  68. {
  69. con = condition;
  70. }
  71. else
  72. {
  73. con = reportCondition.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  74. }
  75. string po = "";
  76. switch (con)
  77. {
  78. case "DMAX":
  79. po = "DMAX";
  80. break;
  81. case "DMIN":
  82. po = "DMIN";
  83. break;
  84. case "ECD":
  85. po = "Area";
  86. break;
  87. case "FERET":
  88. po = "DFERET";
  89. break;
  90. }
  91. //获取粒级表
  92. if (m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile == "AUTO.psf")
  93. {
  94. double dn = 99999;
  95. string sou = reportCondition.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  96. if (sou.Contains("+"))
  97. {
  98. for (int i = 0; i < sou.Split('+').Length; i++)
  99. {
  100. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  101. if (resultFile != null)
  102. {
  103. if(dn> resultFile.GetParticleMINECD())
  104. {
  105. dn = resultFile.GetParticleMINECD();
  106. }
  107. }
  108. }
  109. }
  110. else
  111. {
  112. ResultFile resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  113. dn = resultFile.GetParticleMINECD();
  114. }
  115. sizestr = dn.ToString()+",";
  116. for(double p= dn; p<50;p=p * Math.Sqrt(2))
  117. {
  118. if(p > dn&& p <= 50.5)
  119. {
  120. double dd = Math.Round(p);
  121. sizestr += dd.ToString() + ",";
  122. }
  123. }
  124. sizestr = sizestr.Remove(sizestr.Length - 1, 1);
  125. }
  126. else
  127. {
  128. string path1 = m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  129. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  130. sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  131. }
  132. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  133. {
  134. if (sizestr.Split(',')[i].Length > 0)
  135. {
  136. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  137. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  138. colid.Add(d1.ToString() + "~" + d2.ToString());
  139. colname.Add(d1.ToString() + "~" + d2.ToString());
  140. }
  141. }
  142. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  143. colid.Add(d.ToString() + "~MAX");
  144. colname.Add(d.ToString() + "~MAX");
  145. //创建Grid的列 创建Datatable的列
  146. for (int i = 0; i < colid.Count; i++)
  147. {
  148. gridView.Columns.Add(colid[i], colname[i]);
  149. if (!m_dt.Columns.Contains(colid[i]))
  150. m_dt.Columns.Add(colid[i]);
  151. gridView.Columns[i].ValueType = typeof(System.Int32);
  152. }
  153. if (!m_dt.Columns.Contains("Class"))
  154. m_dt.Columns.Add("Class");
  155. //设置grid默认值的样式,防止图像为空时有红x
  156. for (int i = 0; i < gridView.Columns.Count; i++)
  157. {
  158. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  159. }
  160. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  161. List<string> NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() };
  162. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  163. string filedAndParticl = "";
  164. DataTable dt;
  165. dt = particledata.GetParticleListForParticlSize("area", filedAndParticl);
  166. gridView.MergeColumnNames.Add(filename);
  167. gridView.AddSpanHeader(1, gridView.Columns.Count - 1, filename);
  168. for (int i = 0; i < dt.Rows.Count; i++)
  169. {
  170. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  171. {
  172. continue;
  173. }
  174. int add_rowindex = gridView.Rows.Add();
  175. gridView.Rows[add_rowindex].Tag = "Statistics";
  176. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  177. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  178. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  179. string color = dt.Rows[i]["TypeColor"].ToString();
  180. if (!color.Contains("#"))
  181. {
  182. color = "#" + dt.Rows[i]["TypeColor"].ToString();
  183. }
  184. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  185. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  186. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  187. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  188. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  189. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  190. m_dt.Rows.Add();
  191. m_dt.Rows[add_rowindex]["pname"]= dt.Rows[i]["TypeName"];
  192. m_dt.Rows[add_rowindex]["TypeId"]=dt.Rows[i]["TypeId"];
  193. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  194. m_dt.Rows[add_rowindex]["Total"]= dt.Rows[i]["con"];
  195. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  196. }
  197. for (int i = 0; i < dt.Rows.Count; i++)
  198. {
  199. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  200. {
  201. continue;
  202. }
  203. int add_rowindex = gridView.Rows.Add();
  204. gridView.Rows[add_rowindex].Tag = "Statistics";
  205. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  206. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  207. if (index == -1)
  208. {
  209. index = 7;
  210. }
  211. string name = NameList[index];
  212. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  213. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  214. string color = "#000000";
  215. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  216. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  217. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  218. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  219. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  220. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  221. m_dt.Rows.Add();
  222. m_dt.Rows[add_rowindex]["pname"] = dt.Rows[i]["TypeName"];
  223. m_dt.Rows[add_rowindex]["TypeId"] = dt.Rows[i]["TypeId"];
  224. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  225. m_dt.Rows[add_rowindex]["Total"] = dt.Rows[i]["con"];
  226. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  227. }
  228. for (int i = 0; i < gridView.Rows.Count - 1; i++)
  229. {
  230. for (int j = 6; j < colid.Count; j++)
  231. {
  232. string d1 = colid[j].Split('~')[0];
  233. string d2 = colid[j].Split('~')[1];
  234. if (d2 == "MAX")
  235. {
  236. d2 = "999";
  237. }
  238. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, gridView.Rows[i].Cells[3].Value.ToString()));
  239. gridView.Rows[i].Cells[j].Value = datas.Count();
  240. gridView.Rows[i].Cells[j].Style.BackColor = Color.Azure;
  241. m_dt.Rows[i][colid[j]]= datas.Count();
  242. }
  243. }
  244. gridView.Columns[3].Visible = false;
  245. //设置grid默认值的样式,防止图像为空时有红x
  246. for (int i = 0; i < gridView.Columns.Count; i++)
  247. {
  248. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  249. }
  250. gridView.Name = "gridView" + num.ToString();
  251. list_table_Point.Add(SetDataGridViewStyle(gridView));
  252. AddSumRow(gridView);
  253. panel1.Controls.Add(gridView);
  254. list_table_data.Add(m_dt);
  255. }
  256. void AddSumRow(OTSGridView gridView)
  257. {
  258. if (gridView.Rows == null || gridView.Rows.Count <1)
  259. return;
  260. int a1 = gridView.Rows.Add();
  261. gridView.Rows[a1].Tag = "Sum";
  262. gridView.Rows[a1].Cells[1].Value = "Sum";
  263. for (int j = 0; j < gridView.Rows.Count - 1; j++)
  264. {
  265. for (int k = 5; k < gridView.Columns.Count; k++)
  266. {
  267. if (gridView.Rows[a1].Cells[k].Value == null)
  268. gridView.Rows[a1].Cells[k].Value = 0;
  269. if (k == 5)
  270. {
  271. gridView.Rows[a1].Cells[k].Value = Convert.ToInt64(gridView.Rows[a1].Cells[k].Value) + Convert.ToInt64(gridView.Rows[j].Cells[k].Value);
  272. }
  273. else
  274. {
  275. gridView.Rows[a1].Cells[k].Value = Convert.ToInt32(gridView.Rows[a1].Cells[k].Value) + Convert.ToInt32(gridView.Rows[j].Cells[k].Value);
  276. }
  277. }
  278. }
  279. gridView.Rows[a1].DefaultCellStyle.BackColor = Color.Azure;
  280. gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30);
  281. }
  282. /// <summary>
  283. /// 设置DataGridView样式
  284. /// </summary>
  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. int gridView_Width = 0;
  315. for (int i = 0; i < gridView.ColumnCount-1; i++)
  316. {
  317. gridView_Width = gridView_Width + gridView.Columns[i].Width;
  318. }
  319. gridView.Size = new System.Drawing.Size(gridView_Width, gridViewHeight);
  320. int gridheight = gridViewHeight + 7;
  321. gridheight = gridheight + gridViewHeight + 2;
  322. gridwidth = gridwidth + gridView.ColumnCount * 100 + 80;
  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_Width, (gridView.RowCount + 2) * 30));
  333. gridView.Location = new System.Drawing.Point(gridwidth - (gridView.ColumnCount * 100 + 80), 0);
  334. return new Point(gridwidth - (gridView.ColumnCount * 100 + 80), 0);
  335. }
  336. #endregion
  337. #region 窗体加载及初始化
  338. public ParticlesSizeGrid()
  339. {
  340. InitializeComponent();
  341. }
  342. /// <summary>
  343. /// 成份分布表,构造函数
  344. /// </summary>
  345. /// <param name="in_sec">传入,委托类对象</param>
  346. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  347. public ParticlesSizeGrid(OTSIncAReportApp.frmReportApp ReportApp)
  348. {
  349. m_ReportApp = ReportApp;
  350. resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  351. reportCondition = m_ReportApp.m_conditionChoose.m_conditionData;
  352. InitializeComponent();
  353. //国际化
  354. lan = new Language(this);
  355. table = lan.GetNameTable(this.Name);
  356. }
  357. private void ParticlesSizeGrid_Load(object sender, EventArgs e)
  358. {
  359. list_table_data.Clear();
  360. list_table_size.Clear();
  361. list_table_Point.Clear();
  362. list_fileName.Clear();
  363. string sou = reportCondition.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  364. if (sou.Contains("+"))
  365. {
  366. for (int i = 0; i < sou.Split('+').Length; i++)
  367. {
  368. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  369. if (resultFile != null)
  370. {
  371. UpdateDataGrid(resultFile.FilePath, i, resultFile.anotherFileName);
  372. list_fileName.Add(resultFile.anotherFileName);
  373. }
  374. }
  375. }
  376. else
  377. {
  378. for (int i=0;i< m_ReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
  379. {
  380. if (sou == m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
  381. {
  382. UpdateDataGrid(m_ReportApp.m_rstDataMgr.ResultFilesList[i].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  383. list_fileName.Add(m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  384. }
  385. }
  386. }
  387. }
  388. public void SetGraphicType(ReportCondition sourceGridData)
  389. {
  390. string stdId = "";
  391. int stdIdIndex = 0;
  392. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  393. if (STDIdItm != null)
  394. {
  395. stdId = STDIdItm.itemDisplayVal.ToString();
  396. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  397. }
  398. int high = 0;
  399. for (int i = 0; i < list_table_size.Count; i++)
  400. {
  401. if (high < list_table_size[i].Y)
  402. {
  403. high = list_table_size[i].Y;
  404. }
  405. }
  406. for (int i = 0; i < list_table_data.Count; i++)
  407. {
  408. Graphics_Stacking(list_table_data[i], stdId, list_table_size[i],list_table_Point[i], high);
  409. }
  410. }
  411. /// <summary>
  412. /// chart图创建
  413. /// </summary>
  414. /// <param name="dt"></param>
  415. /// <param name="stdId"></param>
  416. private void Graphics_Stacking(DataTable dt, string stdId, Point a_size ,Point a_Location,int location_hig)
  417. {
  418. ChartControl chartControl1 = new ChartControl();
  419. chartControl1.Series.Clear();
  420. chartControl1.Size = new Size(a_size.X, location_hig);
  421. chartControl1.Location = new Point(a_Location.X, location_hig + 20);
  422. DataTable dataTable = new DataTable();
  423. dataTable.Columns.Add("name");
  424. dataTable.Columns.Add("size");
  425. if (stdId != "All")
  426. {
  427. for (int i = 0; i < dt.Rows.Count; i++)
  428. {
  429. if (dt.Rows[i]["pname"].ToString() == stdId)
  430. {
  431. for (int a = 7; a < dt.Columns.Count-1; a++)
  432. {
  433. DataRow dr = dataTable.NewRow();
  434. dr["name"] = dt.Columns[a].ColumnName;
  435. dr["size"] = Convert.ToInt16(dt.Rows[i][a]);
  436. dataTable.Rows.Add(dr);
  437. }
  438. }
  439. }
  440. }
  441. if (stdId == "All")
  442. {
  443. List<Series> seriesList = new List<Series>();
  444. DataTable data = new DataTable();
  445. data.Columns.Add("name");
  446. data.Columns.Add("range");
  447. data.Columns.Add("num");
  448. for (int i = 0; i < dt.Rows.Count; i++)
  449. {
  450. if (dt.Rows[i]["pname"].ToString() != "")
  451. {
  452. for (int a = 6; a < dt.Columns.Count - 1; a++)
  453. {
  454. DataRow dr = data.NewRow();
  455. dr["name"] = dt.Rows[i]["pname"].ToString();
  456. dr["range"] = dt.Columns[a].ColumnName;
  457. dr["num"] = dt.Rows[i][a].ToString();
  458. data.Rows.Add(dr);
  459. }
  460. }
  461. }
  462. foreach (DataRow dr in data.DefaultView.ToTable(true, "name").Rows)
  463. {
  464. Series s = new Series(dr["name"].ToString(), ViewType.StackedBar)
  465. {
  466. LegendTextPattern = dr["name"].ToString(),
  467. ArgumentScaleType = ScaleType.Qualitative,
  468. };
  469. foreach (DataRow drl in data.Select("name='" + dr["name"].ToString() + "'"))
  470. s.Points.Add(new SeriesPoint(drl["range"].ToString(), int.Parse(drl["num"].ToString())));
  471. s.LabelsVisibility = DefaultBoolean.False;
  472. seriesList.Add(s);
  473. }
  474. foreach (Series sr in seriesList.ToArray())
  475. chartControl1.Series.Add(sr);
  476. }
  477. else
  478. {
  479. // 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
  480. Series series = new Series(stdId, ViewType.Bar);
  481. for (int a = 0; a < dataTable.Rows.Count; a++)
  482. {
  483. string name = dataTable.Rows[a]["name"].ToString();
  484. double Cunt = Convert.ToDouble(dataTable.Rows[a]["size"]);
  485. series.Points.Add(new SeriesPoint(name, Cunt));
  486. }
  487. series.LabelsVisibility = DefaultBoolean.True;
  488. chartControl1.Series.Add(series);
  489. }
  490. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "";
  491. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Text = "";
  492. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visibility = DefaultBoolean.True;
  493. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Visibility = DefaultBoolean.True;
  494. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("Tahoma", 9);
  495. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Font = new Font("Tahoma", 9);
  496. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Alignment = System.Drawing.StringAlignment.Far;
  497. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Alignment = System.Drawing.StringAlignment.Far;
  498. //图例的位置定义
  499. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  500. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  501. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  502. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  503. //十字准线光标
  504. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  505. chartControl1.CrosshairOptions.ShowValueLine = true;
  506. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  507. panel1.Controls.Add(chartControl1);
  508. }
  509. #endregion
  510. #region 相关事件
  511. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  512. {
  513. //复制整个表
  514. CopyAll();
  515. }
  516. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  517. {
  518. CopySelected();
  519. }
  520. /// <summary>
  521. /// 复制选择区域
  522. /// </summary>
  523. public void CopySelected()
  524. {
  525. foreach (var item in panel1.Controls)
  526. {
  527. if (item.GetType().ToString() == "OTSGridView")
  528. {
  529. //复制选择区域
  530. object oo = ((OTSGridView)item).GetClipboardContent();
  531. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  532. }
  533. }
  534. }
  535. /// <summary>
  536. /// 复制所有
  537. /// </summary>
  538. public void CopyAll()
  539. {
  540. foreach (var item in panel1.Controls)
  541. {
  542. if (item.GetType().ToString() == "OTSGridView")
  543. {
  544. ((OTSGridView)item).SelectAll();
  545. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  546. }
  547. }
  548. }
  549. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  550. {
  551. foreach (var item in panel1.Controls)
  552. {
  553. if (item.GetType().ToString() == "OTSGridView")
  554. {
  555. panel1.Controls.Remove((OTSGridView)item);
  556. }
  557. }
  558. gridheight = 0;
  559. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  560. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  561. string sou = reportCondition.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  562. if (sou.Contains("+"))
  563. {
  564. for (int i = 0; i < sou.Split('+').Length; i++)
  565. {
  566. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  567. if (resultFile != null)
  568. {
  569. UpdateDataGrid(resultFile.FilePath, i, resultFile.anotherFileName);
  570. }
  571. }
  572. }
  573. else
  574. {
  575. UpdateDataGrid(m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].anotherFileName);
  576. }
  577. }
  578. private void Gview_gz_Sorted(object sender, EventArgs e)
  579. {
  580. if (((OTSGridView)sender).Rows == null || ((OTSGridView)sender).Rows.Count == 0)
  581. return;
  582. for (int i = 0; i < ((OTSGridView)sender).Rows.Count; i++)
  583. {
  584. if (((OTSGridView)sender).Rows[i].Tag.ToString() == "Sum")
  585. { ((OTSGridView)sender).Rows.RemoveAt(i); break; }
  586. }
  587. //排序完成,重新设置序号
  588. for (int i = 0; i < ((OTSGridView)sender).Rows.Count; i++)
  589. {
  590. ((OTSGridView)sender).Rows[i].Cells[0].Value = (i+1).ToString();
  591. }
  592. ((OTSGridView)sender).Refresh();
  593. }
  594. void Gview_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  595. {
  596. if (((OTSGridView)sender).Rows == null || ((OTSGridView)sender).Rows.Count == 0)
  597. return;
  598. AddSumRow((OTSGridView)sender);
  599. }
  600. #endregion
  601. #region 获取向导出模块提供的DataTable和GridView对象
  602. /// <summary>
  603. /// 获取到该模块输出后形成的DataTable,和GridView
  604. /// </summary>
  605. /// <param name="out_dt"></param>
  606. /// <param name="out_dg"></param>
  607. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  608. {
  609. out_dt = m_dt;
  610. out_dg = null;
  611. foreach (var item in panel1.Controls)
  612. {
  613. if (item.GetType().ToString() == "OTSGridView")
  614. {
  615. out_dg = ((OTSGridView)item);
  616. }
  617. }
  618. }
  619. #endregion
  620. }
  621. }