ParticlesSizeGrid.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. 
  2. using DevExpress.Utils;
  3. using DevExpress.XtraCharts;
  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 result = null;
  31. OTSIncAReportApp.OTSSampleReportInfo.ReportCondition source;
  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 BindDataGridView(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. OTSIncAReportApp.DataOperation.DataAccess.ParticleData particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(path);
  62. //获取粒级表
  63. string path1 = m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  64. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  65. string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  66. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  67. {
  68. if (sizestr.Split(',')[i].Length > 0)
  69. {
  70. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  71. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  72. colid.Add(d1.ToString() + "~" + d2.ToString());
  73. colname.Add(d1.ToString() + "~" + d2.ToString());
  74. }
  75. }
  76. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  77. colid.Add(d.ToString() + "~MAX");
  78. colname.Add(d.ToString() + "~MAX");
  79. //创建Grid的列 创建Datatable的列
  80. for (int i = 0; i < colid.Count; i++)
  81. {
  82. gridView.Columns.Add(colid[i], colname[i]);
  83. if (!m_dt.Columns.Contains(colid[i]))
  84. m_dt.Columns.Add(colid[i]);
  85. }
  86. if (!m_dt.Columns.Contains("Class"))
  87. m_dt.Columns.Add("Class");
  88. //设置grid默认值的样式,防止图像为空时有红x
  89. for (int i = 0; i < gridView.Columns.Count; i++)
  90. {
  91. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  92. }
  93. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  94. 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() };
  95. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  96. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  97. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  98. string filedAndParticl = "";
  99. DataTable dt;
  100. dt = particledata.GetParticleListForParticlSize("area", filedAndParticl);
  101. gridView.MergeColumnNames.Add(filename);
  102. gridView.AddSpanHeader(1, gridView.Columns.Count - 1, filename);
  103. for (int i = 0; i < dt.Rows.Count; i++)
  104. {
  105. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  106. {
  107. continue;
  108. }
  109. int add_rowindex = gridView.Rows.Add();
  110. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  111. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  112. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  113. string color = dt.Rows[i]["TypeColor"].ToString();
  114. if (!color.Contains("#"))
  115. {
  116. color = "#" + dt.Rows[i]["TypeColor"].ToString();
  117. }
  118. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  119. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  120. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  121. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  122. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  123. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  124. m_dt.Rows.Add();
  125. m_dt.Rows[add_rowindex]["pname"]= dt.Rows[i]["TypeName"];
  126. m_dt.Rows[add_rowindex]["TypeId"]=dt.Rows[i]["TypeId"];
  127. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  128. m_dt.Rows[add_rowindex]["Total"]= dt.Rows[i]["con"];
  129. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  130. }
  131. for (int i = 0; i < dt.Rows.Count; i++)
  132. {
  133. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  134. {
  135. continue;
  136. }
  137. int add_rowindex = gridView.Rows.Add();
  138. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  139. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  140. if (index == -1)
  141. {
  142. index = 7;
  143. }
  144. string name = NameList[index];
  145. //gridView.Rows[add_rowindex].Cells[1].Value = name;
  146. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  147. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  148. string color = "#000000";
  149. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  150. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  151. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  152. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  153. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  154. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  155. m_dt.Rows.Add();
  156. m_dt.Rows[add_rowindex]["pname"] = dt.Rows[i]["TypeName"];
  157. m_dt.Rows[add_rowindex]["TypeId"] = dt.Rows[i]["TypeId"];
  158. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  159. m_dt.Rows[add_rowindex]["Total"] = dt.Rows[i]["con"];
  160. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  161. }
  162. DataTable dtp = particledata.GetParticleAll(filedAndParticl);
  163. string con = "";
  164. if (condition != "")
  165. {
  166. con = condition;
  167. }
  168. else
  169. {
  170. //idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE);
  171. con = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  172. }
  173. string po = "";
  174. switch (con)
  175. {
  176. case "DMAX":
  177. po = "DMAX";
  178. break;
  179. case "DMIN":
  180. po = "DMIN";
  181. break;
  182. case "ECD":
  183. po = "Area";
  184. break;
  185. case "FERET":
  186. po = "DFERET";
  187. break;
  188. }
  189. for (int i = 0; i < gridView.Rows.Count - 1; i++)
  190. {
  191. for (int j = 6; j < colid.Count; j++)
  192. {
  193. string d1 = colid[j].Split('~')[0];
  194. string d2 = colid[j].Split('~')[1];
  195. if (d2 == "MAX")
  196. {
  197. d2 = "999";
  198. }
  199. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, gridView.Rows[i].Cells[3].Value.ToString()));
  200. gridView.Rows[i].Cells[j].Value = datas.Count();
  201. gridView.Rows[i].Cells[j].Style.BackColor = Color.Azure;
  202. m_dt.Rows[i][colid[j]]= datas.Count();
  203. }
  204. }
  205. gridView.Columns[3].Visible = false;
  206. //设置grid默认值的样式,防止图像为空时有红x
  207. for (int i = 0; i < gridView.Columns.Count; i++)
  208. {
  209. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  210. }
  211. gridView.Name = "gridView" + num.ToString();
  212. int a1=gridView.Rows.Add();
  213. gridView.Rows[a1].Cells[1].Value = "Sum";
  214. for(int j=0;j< gridView.Rows.Count-2;j++)
  215. {
  216. for(int k=4;k< gridView.Columns.Count;k++)
  217. {
  218. if (gridView.Rows[a1].Cells[k].Value == null)
  219. gridView.Rows[a1].Cells[k].Value = 0;
  220. gridView.Rows[a1].Cells[k].Value = Convert.ToInt32(gridView.Rows[a1].Cells[k].Value)+ Convert.ToInt32(gridView.Rows[j].Cells[k].Value);
  221. }
  222. }
  223. list_table_Point.Add(SetDataGridViewStyle(gridView));
  224. panel1.Controls.Add(gridView);
  225. list_table_data.Add(m_dt);
  226. }
  227. /// <summary>
  228. /// 设置DataGridView样式
  229. /// </summary>
  230. private Point SetDataGridViewStyle(OTSGridView gridView)
  231. {
  232. //用户不能调整标题的高度
  233. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  234. //用户不能调整 行高
  235. gridView.AllowUserToResizeRows = false;
  236. //改变行的高度;
  237. //gridView.RowTemplate.Height = 20;
  238. //点击选择整行
  239. gridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  240. //居中显示
  241. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  242. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  243. gridView.DefaultCellStyle = dataGridViewCellStyle1;
  244. gridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  245. //再次重覆禁用拖动表头高度,居然有效果了
  246. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  247. //设置grid可以复制
  248. gridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  249. //设置每列的宽度
  250. gridView.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  251. gridView.Columns[1].Width = 200;
  252. //设置序号列不排序
  253. gridView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  254. //设置序号列不可以设置宽度
  255. gridView.Columns[0].Resizable = DataGridViewTriState.False;
  256. gridView.AllowUserToAddRows = false;
  257. gridView.AllowUserToDeleteRows = false;
  258. gridView.AllowUserToResizeRows = false;
  259. gridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
  260. gridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  261. gridView.ContextMenuStrip = this.contextMenuStrip1;
  262. gridView.BorderStyle = 0;
  263. int outpos = gridwidth;
  264. gridView.Location = new System.Drawing.Point(gridwidth, 0);
  265. gridView.Margin = new System.Windows.Forms.Padding(2);
  266. gridView.MergeColumnHeaderBackColor = System.Drawing.SystemColors.ButtonHighlight;
  267. gridView.ReadOnly = true;
  268. gridView.RowHeadersVisible = false;
  269. gridView.RowHeadersWidth = 40;
  270. gridView.RowTemplate.Height = 30;
  271. //gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30 + 30);
  272. int gridView_Width = 0;
  273. for (int i = 0; i < gridView.ColumnCount; i++)
  274. {
  275. gridView_Width = gridView_Width + gridView.Columns[i].Width;
  276. }
  277. gridView.Size = new System.Drawing.Size(gridView_Width, gridView.RowCount * 30);
  278. //gridheight = gridheight + gridView.RowCount * 30 + 80;
  279. gridheight = gridheight + gridView.RowCount * 30 + 5;
  280. gridwidth = gridwidth + gridView.ColumnCount * 100;
  281. gridView.TabIndex = 0;
  282. gridView.SortCompare += Gview_gz_SortCompare;
  283. gridView.Sorted += Gview_gz_Sorted;
  284. //先设置一下头的高度,否则会太矮不好看
  285. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  286. gridView.ColumnHeadersHeight = 40;
  287. gridView.Columns[4].Visible = false;
  288. list_table_size.Add(new Point(gridView.ColumnCount * 100 - 40, gridView.RowCount * 30));
  289. return new Point(outpos, gridheight);
  290. //list_table_Point.Add(new Point(gridwidth, gridheight));
  291. }
  292. #endregion
  293. #region 窗体加载及初始化
  294. public ParticlesSizeGrid()
  295. {
  296. InitializeComponent();
  297. }
  298. /// <summary>
  299. /// 成份分布表,构造函数
  300. /// </summary>
  301. /// <param name="in_sec">传入,委托类对象</param>
  302. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  303. public ParticlesSizeGrid(OTSIncAReportApp.frmReportApp ReportApp)
  304. {
  305. m_ReportApp = ReportApp;
  306. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  307. source = m_ReportApp.m_conditionChoose.m_conditionData;
  308. InitializeComponent();
  309. //国际化
  310. lan = new Language(this);
  311. table = lan.GetNameTable(this.Name);
  312. }
  313. private void ParticlesSizeGrid_Load(object sender, EventArgs e)
  314. {
  315. list_table_data.Clear();
  316. list_table_size.Clear();
  317. list_table_Point.Clear();
  318. list_fileName.Clear();
  319. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  320. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  321. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  322. if (sou.Contains("+"))
  323. {
  324. for (int i = 0; i < sou.Split('+').Length; i++)
  325. {
  326. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  327. if (resultFile != null)
  328. {
  329. BindDataGridView(resultFile.FilePath, i, resultFile.anotherFileName);
  330. list_fileName.Add(resultFile.anotherFileName);
  331. }
  332. }
  333. }
  334. else
  335. {
  336. for (int i=0;i< m_ReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
  337. {
  338. if (sou == m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
  339. {
  340. BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[i].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  341. list_fileName.Add(m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  342. }
  343. }
  344. //BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()].FileName);
  345. }
  346. for (int i = 0; i < list_table_data.Count; i++)
  347. {
  348. }
  349. }
  350. public void SetGraphicType(ReportCondition sourceGridData)
  351. {
  352. string stdId = "";
  353. int stdIdIndex = 0;
  354. //find the stdId condition
  355. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  356. if (STDIdItm != null)
  357. {
  358. stdId = STDIdItm.itemDisplayVal.ToString();
  359. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  360. }
  361. int high = 0;
  362. for (int i = 0; i < list_table_Point.Count; i++)
  363. {
  364. if (high < list_table_Point[i].Y)
  365. {
  366. high = list_table_Point[i].Y;
  367. }
  368. }
  369. for (int i = 0; i < list_table_data.Count; i++)
  370. {
  371. Graphics_Stacking(list_table_data[i], stdId, list_table_size[i],list_table_Point[i], high);
  372. }
  373. }
  374. /// <summary>
  375. /// chart图创建
  376. /// </summary>
  377. /// <param name="dt"></param>
  378. /// <param name="stdId"></param>
  379. private void Graphics_Stacking(DataTable dt, string stdId, Point a_size ,Point a_Location,int location_hig)
  380. {
  381. ChartControl chartControl1 = new ChartControl();
  382. chartControl1.Series.Clear();
  383. chartControl1.Size = new Size(a_size.X, a_size.Y);
  384. chartControl1.Location = new Point(a_Location.X, location_hig);
  385. DataTable dataTable = new DataTable();
  386. dataTable.Columns.Add("name");
  387. dataTable.Columns.Add("size");
  388. if (stdId != "All")
  389. {
  390. for (int i = 0; i < dt.Rows.Count; i++)
  391. {
  392. if (dt.Rows[i]["pname"].ToString() == stdId)
  393. {
  394. for (int a = 7; a < dt.Columns.Count-1; a++)
  395. {
  396. DataRow dr = dataTable.NewRow();
  397. dr["name"] = dt.Columns[a].ColumnName;
  398. dr["size"] = Convert.ToInt16(dt.Rows[i][a]);
  399. dataTable.Rows.Add(dr);
  400. }
  401. }
  402. }
  403. }
  404. if (stdId == "All")
  405. {
  406. List<Series> seriesList = new List<Series>();
  407. DataTable data = new DataTable();
  408. data.Columns.Add("name");
  409. data.Columns.Add("range");
  410. data.Columns.Add("num");
  411. for (int i = 0; i < dt.Rows.Count; i++)
  412. {
  413. for (int a = 6; a < dt.Columns.Count-1; a++)
  414. {
  415. DataRow dr = data.NewRow();
  416. dr["name"] = dt.Rows[i]["pname"].ToString();
  417. dr["range"] = dt.Columns[a].ColumnName;
  418. dr["num"] = dt.Rows[i][a].ToString();
  419. data.Rows.Add(dr);
  420. }
  421. }
  422. foreach (DataRow dr in data.DefaultView.ToTable(true, "name").Rows)
  423. {
  424. Series s = new Series(dr["name"].ToString(), ViewType.StackedBar)
  425. {
  426. LegendTextPattern = dr["name"].ToString(),
  427. ArgumentScaleType = ScaleType.Qualitative,
  428. };
  429. foreach (DataRow drl in data.Select("name='" + dr["name"].ToString() + "'"))
  430. s.Points.Add(new SeriesPoint(drl["range"].ToString(), int.Parse(drl["num"].ToString())));
  431. s.LabelsVisibility = DefaultBoolean.False;
  432. seriesList.Add(s);
  433. }
  434. foreach (Series sr in seriesList.ToArray())
  435. chartControl1.Series.Add(sr);
  436. }
  437. else
  438. {
  439. // 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
  440. Series series = new Series(stdId, ViewType.Bar);
  441. for (int a = 0; a < dataTable.Rows.Count; a++)
  442. {
  443. string name = dataTable.Rows[a]["name"].ToString();
  444. double Cunt = Convert.ToDouble(dataTable.Rows[a]["size"]);
  445. series.Points.Add(new SeriesPoint(name, Cunt));
  446. }
  447. series.LabelsVisibility = DefaultBoolean.True;
  448. chartControl1.Series.Add(series);
  449. }
  450. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "";
  451. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Text = "";
  452. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visibility = DefaultBoolean.True;
  453. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Visibility = DefaultBoolean.True;
  454. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("Tahoma", 9);
  455. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Font = new Font("Tahoma", 9);
  456. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Alignment = System.Drawing.StringAlignment.Far;
  457. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Alignment = System.Drawing.StringAlignment.Far;
  458. //图例的位置定义
  459. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  460. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  461. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  462. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  463. //十字准线光标
  464. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  465. chartControl1.CrosshairOptions.ShowValueLine = true;
  466. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  467. panel1.Controls.Add(chartControl1);
  468. }
  469. #endregion
  470. #region 相关事件
  471. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  472. {
  473. //复制整个表
  474. CopyAll();
  475. }
  476. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  477. {
  478. CopySelected();
  479. }
  480. /// <summary>
  481. /// 复制选择区域
  482. /// </summary>
  483. public void CopySelected()
  484. {
  485. foreach (var item in panel1.Controls)
  486. {
  487. if (item.GetType().ToString() == "OTSGridView")
  488. {
  489. //复制选择区域
  490. object oo = ((OTSGridView)item).GetClipboardContent();
  491. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  492. }
  493. }
  494. }
  495. /// <summary>
  496. /// 复制所有
  497. /// </summary>
  498. public void CopyAll()
  499. {
  500. foreach (var item in panel1.Controls)
  501. {
  502. if (item.GetType().ToString() == "OTSGridView")
  503. {
  504. ((OTSGridView)item).SelectAll();
  505. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  506. }
  507. }
  508. }
  509. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  510. {
  511. foreach (var item in panel1.Controls)
  512. {
  513. if (item.GetType().ToString() == "OTSGridView")
  514. {
  515. panel1.Controls.Remove((OTSGridView)item);
  516. }
  517. }
  518. gridheight = 0;
  519. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  520. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  521. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  522. if (sou.Contains("+"))
  523. {
  524. for (int i = 0; i < sou.Split('+').Length; i++)
  525. {
  526. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  527. if (resultFile != null)
  528. {
  529. BindDataGridView(resultFile.FilePath, i, resultFile.anotherFileName);
  530. }
  531. }
  532. }
  533. else
  534. {
  535. BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].anotherFileName);
  536. }
  537. }
  538. private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  539. {
  540. //排序中
  541. if (((OTSGridView)sender).Rows[e.RowIndex1].Tag != null && ((OTSGridView)sender).Rows[e.RowIndex1].Tag.ToString() == "统计行")
  542. {
  543. //ROW1>ROW2
  544. e.SortResult = 1;
  545. if (((OTSGridView)sender).SortOrder == SortOrder.Descending)
  546. e.SortResult = -1;
  547. e.Handled = true;
  548. return;
  549. }
  550. if (((OTSGridView)sender).Rows[e.RowIndex2].Tag != null && ((OTSGridView)sender).Rows[e.RowIndex2].Tag.ToString() == "统计行")
  551. {
  552. //ROW1<ROW2
  553. e.SortResult = -1;
  554. if (((OTSGridView)sender).SortOrder == SortOrder.Descending)
  555. e.SortResult = 1;
  556. e.Handled = true;
  557. return;
  558. }
  559. }
  560. private void Gview_gz_Sorted(object sender, EventArgs e)
  561. {
  562. //排序完成,重新设置序号
  563. for (int i = 0; i < ((OTSGridView)sender).Rows.Count; i++)
  564. {
  565. if (((OTSGridView)sender).Rows[i].Tag != null && ((OTSGridView)sender).Rows[i].Tag.ToString() == "统计行")
  566. { }
  567. else
  568. {
  569. ((OTSGridView)sender).Rows[i].Cells[0].Value = i.ToString();
  570. }
  571. }
  572. }
  573. #endregion
  574. #region 获取向导出模块提供的DataTable和GridView对象
  575. /// <summary>
  576. /// 获取到该模块输出后形成的DataTable,和GridView
  577. /// </summary>
  578. /// <param name="out_dt"></param>
  579. /// <param name="out_dg"></param>
  580. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  581. {
  582. out_dt = m_dt;
  583. out_dg = null;
  584. foreach (var item in panel1.Controls)
  585. {
  586. if (item.GetType().ToString() == "OTSGridView")
  587. {
  588. out_dg = ((OTSGridView)item);
  589. }
  590. }
  591. }
  592. #endregion
  593. }
  594. }