DetailDialog.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using PaintDotNet.Base.CommTool;
  12. namespace PaintDotNet.GeneralAnalysis.Countometer
  13. {
  14. public class DetailDialog : PdnBaseForm
  15. {
  16. #region
  17. /// <summary>
  18. /// Required designer variable.
  19. /// </summary>
  20. private System.ComponentModel.IContainer components = null;
  21. /// <summary>
  22. /// Clean up any resources being used.
  23. /// </summary>
  24. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  25. protected override void Dispose(bool disposing)
  26. {
  27. if (disposing && (components != null))
  28. {
  29. components.Dispose();
  30. }
  31. base.Dispose(disposing);
  32. }
  33. #region Windows Form Designer generated code
  34. private void InitializeLanguageText()
  35. {
  36. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  37. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  38. this.btnExport.Text = PdnResources.GetString("Menu.Imagement.Bitmapanalysis.exportdata.text");
  39. this.groupBox2.Text = PdnResources.GetString("Menu.Organizationinformation.text");
  40. this.name.HeaderText = PdnResources.GetString("Menu.name.text");
  41. this.hotKey.HeaderText = PdnResources.GetString("Menu.Keyname.Text");
  42. this.color.HeaderText = PdnResources.GetString("Menu.color.text");
  43. this.count.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.Quantity.text");
  44. this.ratio.HeaderText = PdnResources.GetString("Menu.proportion.text");
  45. this.groupBox3.Text = PdnResources.GetString("Menu.Thepiechart.Text");
  46. this.lblTotal.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.total.text") + ":0";
  47. this.Text = PdnResources.GetString("Menu.GeneralAnalysis.Countometer.Text");
  48. }
  49. /// <summary>
  50. /// Required method for Designer support - do not modify
  51. /// the contents of this method with the code editor.
  52. /// </summary>
  53. private void InitializeComponent()
  54. {
  55. System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
  56. System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend();
  57. System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
  58. this.groupBox1 = new System.Windows.Forms.GroupBox();
  59. this.btnClose = new System.Windows.Forms.Button();
  60. this.btnExport = new System.Windows.Forms.Button();
  61. this.groupBox2 = new System.Windows.Forms.GroupBox();
  62. this.dgvInfo = new System.Windows.Forms.DataGridView();
  63. this.name = new System.Windows.Forms.DataGridViewTextBoxColumn();
  64. this.hotKey = new System.Windows.Forms.DataGridViewTextBoxColumn();
  65. this.color = new System.Windows.Forms.DataGridViewTextBoxColumn();
  66. this.count = new System.Windows.Forms.DataGridViewTextBoxColumn();
  67. this.ratio = new System.Windows.Forms.DataGridViewTextBoxColumn();
  68. this.groupBox3 = new System.Windows.Forms.GroupBox();
  69. this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
  70. this.lblTotal = new System.Windows.Forms.Label();
  71. this.groupBox1.SuspendLayout();
  72. this.groupBox2.SuspendLayout();
  73. ((System.ComponentModel.ISupportInitialize)(this.dgvInfo)).BeginInit();
  74. this.groupBox3.SuspendLayout();
  75. ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
  76. this.SuspendLayout();
  77. //
  78. // groupBox1
  79. //
  80. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  81. | System.Windows.Forms.AnchorStyles.Right)));
  82. this.groupBox1.Controls.Add(this.btnClose);
  83. this.groupBox1.Controls.Add(this.btnExport);
  84. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  85. this.groupBox1.Name = "groupBox1";
  86. this.groupBox1.Size = new System.Drawing.Size(684, 80);
  87. this.groupBox1.TabIndex = 0;
  88. this.groupBox1.TabStop = false;
  89. this.groupBox1.Text = "操作";
  90. //
  91. // btnClose
  92. //
  93. this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  94. this.btnClose.Location = new System.Drawing.Point(577, 28);
  95. this.btnClose.Name = "btnClose";
  96. this.btnClose.Size = new System.Drawing.Size(84, 31);
  97. this.btnClose.TabIndex = 3;
  98. this.btnClose.Text = "关闭";
  99. this.btnClose.UseVisualStyleBackColor = true;
  100. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  101. //
  102. // btnExport
  103. //
  104. this.btnExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  105. this.btnExport.Location = new System.Drawing.Point(475, 28);
  106. this.btnExport.Name = "btnExport";
  107. this.btnExport.Size = new System.Drawing.Size(84, 31);
  108. this.btnExport.TabIndex = 2;
  109. this.btnExport.Text = "导出数据";
  110. this.btnExport.UseVisualStyleBackColor = true;
  111. this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
  112. //
  113. // groupBox2
  114. //
  115. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  116. | System.Windows.Forms.AnchorStyles.Right)));
  117. this.groupBox2.Controls.Add(this.dgvInfo);
  118. this.groupBox2.Location = new System.Drawing.Point(12, 98);
  119. this.groupBox2.Name = "groupBox2";
  120. this.groupBox2.Size = new System.Drawing.Size(684, 266);
  121. this.groupBox2.TabIndex = 1;
  122. this.groupBox2.TabStop = false;
  123. this.groupBox2.Text = "组织信息";
  124. //
  125. // dgvInfo
  126. //
  127. this.dgvInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  128. | System.Windows.Forms.AnchorStyles.Right)));
  129. this.dgvInfo.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  130. this.dgvInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  131. this.dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  132. this.name,
  133. this.hotKey,
  134. this.color,
  135. this.count,
  136. this.ratio});
  137. this.dgvInfo.Enabled = false;
  138. this.dgvInfo.Location = new System.Drawing.Point(13, 23);
  139. this.dgvInfo.Name = "dgvInfo";
  140. this.dgvInfo.RowHeadersVisible = false;
  141. this.dgvInfo.RowHeadersWidth = 51;
  142. this.dgvInfo.RowTemplate.Height = 27;
  143. this.dgvInfo.Size = new System.Drawing.Size(660, 233);
  144. this.dgvInfo.TabIndex = 0;
  145. //
  146. // name
  147. //
  148. this.name.DataPropertyName = "name";
  149. this.name.MinimumWidth = 6;
  150. this.name.Name = "name";
  151. this.name.ReadOnly = true;
  152. //
  153. // hotKey
  154. //
  155. this.hotKey.DataPropertyName = "hot_key";
  156. this.hotKey.MinimumWidth = 6;
  157. this.hotKey.Name = "hotKey";
  158. this.hotKey.ReadOnly = true;
  159. //
  160. // color
  161. //
  162. this.color.DataPropertyName = "color";
  163. this.color.MinimumWidth = 6;
  164. this.color.Name = "color";
  165. this.color.ReadOnly = true;
  166. //
  167. // count
  168. //
  169. this.count.DataPropertyName = "count";
  170. this.count.MinimumWidth = 6;
  171. this.count.Name = "count";
  172. this.count.ReadOnly = true;
  173. //
  174. // ratio
  175. //
  176. this.ratio.DataPropertyName = "ratio";
  177. this.ratio.MinimumWidth = 6;
  178. this.ratio.Name = "ratio";
  179. this.ratio.ReadOnly = true;
  180. //
  181. // groupBox3
  182. //
  183. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
  184. | System.Windows.Forms.AnchorStyles.Right)));
  185. this.groupBox3.Controls.Add(this.chart1);
  186. this.groupBox3.Location = new System.Drawing.Point(12, 370);
  187. this.groupBox3.Name = "groupBox3";
  188. this.groupBox3.Size = new System.Drawing.Size(684, 251);
  189. this.groupBox3.TabIndex = 2;
  190. this.groupBox3.TabStop = false;
  191. this.groupBox3.Text = "饼状图";
  192. //
  193. // chart1
  194. //
  195. this.chart1.BackColor = System.Drawing.SystemColors.Control;
  196. chartArea5.BackColor = System.Drawing.SystemColors.Control;
  197. chartArea5.Name = "ChartArea1";
  198. this.chart1.ChartAreas.Add(chartArea5);
  199. legend5.BackColor = System.Drawing.SystemColors.Control;
  200. legend5.Name = "Legend1";
  201. this.chart1.Legends.Add(legend5);
  202. this.chart1.Location = new System.Drawing.Point(74, 24);
  203. this.chart1.Name = "chart1";
  204. series5.ChartArea = "ChartArea1";
  205. series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
  206. series5.Color = System.Drawing.SystemColors.Control;
  207. series5.LabelBackColor = System.Drawing.SystemColors.Control;
  208. series5.Legend = "Legend1";
  209. series5.Name = "Series1";
  210. this.chart1.Series.Add(series5);
  211. this.chart1.Size = new System.Drawing.Size(524, 221);
  212. this.chart1.TabIndex = 1;
  213. this.chart1.Text = "chart1";
  214. //
  215. // lblTotal
  216. //
  217. this.lblTotal.AutoSize = true;
  218. this.lblTotal.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  219. this.lblTotal.Location = new System.Drawing.Point(9, 633);
  220. this.lblTotal.Name = "lblTotal";
  221. this.lblTotal.Size = new System.Drawing.Size(0, 16);
  222. this.lblTotal.TabIndex = 3;
  223. //
  224. // DetailDialog
  225. //
  226. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  227. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  228. this.ClientSize = new System.Drawing.Size(708, 663);
  229. this.Controls.Add(this.lblTotal);
  230. this.Controls.Add(this.groupBox3);
  231. this.Controls.Add(this.groupBox2);
  232. this.Controls.Add(this.groupBox1);
  233. this.MaximizeBox = false;
  234. this.MinimizeBox = false;
  235. this.Name = "DetailDialog";
  236. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  237. this.Controls.SetChildIndex(this.groupBox1, 0);
  238. this.Controls.SetChildIndex(this.groupBox2, 0);
  239. this.Controls.SetChildIndex(this.groupBox3, 0);
  240. this.Controls.SetChildIndex(this.lblTotal, 0);
  241. this.groupBox1.ResumeLayout(false);
  242. this.groupBox2.ResumeLayout(false);
  243. ((System.ComponentModel.ISupportInitialize)(this.dgvInfo)).EndInit();
  244. this.groupBox3.ResumeLayout(false);
  245. ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
  246. this.ResumeLayout(false);
  247. this.PerformLayout();
  248. }
  249. #endregion
  250. private System.Windows.Forms.GroupBox groupBox1;
  251. private System.Windows.Forms.Button btnClose;
  252. private System.Windows.Forms.Button btnExport;
  253. private System.Windows.Forms.GroupBox groupBox2;
  254. private System.Windows.Forms.DataGridView dgvInfo;
  255. private System.Windows.Forms.GroupBox groupBox3;
  256. private System.Windows.Forms.Label lblTotal;
  257. private System.Windows.Forms.DataGridViewTextBoxColumn name;
  258. private System.Windows.Forms.DataGridViewTextBoxColumn hotKey;
  259. private System.Windows.Forms.DataGridViewTextBoxColumn color;
  260. private System.Windows.Forms.DataGridViewTextBoxColumn count;
  261. private System.Windows.Forms.DataGridViewTextBoxColumn ratio;
  262. private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
  263. #endregion
  264. private string m_id;
  265. private SQLiteHelper m_sqlHelper;
  266. private int m_total = 0;
  267. private DataTable m_history;
  268. private DataTable m_history_info;
  269. public DetailDialog(string id)
  270. {
  271. m_id = id;
  272. InitializeComponent();
  273. InitializeLanguageText();
  274. InitializeData();
  275. }
  276. private void InitializeData()
  277. {
  278. dgvInfo.DefaultCellStyle.SelectionBackColor = dgvInfo.DefaultCellStyle.BackColor;
  279. dgvInfo.DefaultCellStyle.SelectionForeColor = dgvInfo.DefaultCellStyle.ForeColor;
  280. dgvInfo.AutoGenerateColumns = false;
  281. dgvInfo.AllowUserToAddRows = false;
  282. m_sqlHelper = new SQLiteHelper(); //连接数据库
  283. m_sqlHelper.Connect();
  284. string select_sql = "select * from mic_assay_history where delete_flag = 0 and id ='"+ m_id + "'"; //查询的SQL语句
  285. m_history = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  286. select_sql = "select * from mic_assay_history_info where history_id ='" + m_id + "'"; //查询的SQL语句
  287. m_history_info = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  288. if (m_history_info == null || m_history_info.Rows.Count <= 0)
  289. {
  290. return;
  291. }
  292. dgvInfo.Rows.Clear();
  293. dgvInfo.Rows.Add(m_history_info.Rows.Count);
  294. for (int i = 0; i < m_history_info.Rows.Count; ++i)
  295. {
  296. m_total += int.Parse(m_history_info.Rows[i]["count"].ToString());
  297. dgvInfo.Rows[i].Cells["name"].Value = m_history_info.Rows[i]["name"].ToString();
  298. dgvInfo.Rows[i].Cells["hotKey"].Value = m_history_info.Rows[i]["hot_key"].ToString();
  299. dgvInfo.Rows[i].Cells["color"].Value = m_history_info.Rows[i]["color"].ToString();
  300. dgvInfo.Rows[i].Cells["color"].Style.BackColor = ColorTranslator.FromHtml(m_history_info.Rows[i]["color"].ToString());
  301. dgvInfo.Rows[i].Cells["color"].Style.ForeColor = Color.White;
  302. dgvInfo.Rows[i].Cells["color"].Style.SelectionBackColor = ColorTranslator.FromHtml(m_history_info.Rows[i]["color"].ToString());
  303. dgvInfo.Rows[i].Cells["color"].Style.SelectionForeColor = Color.White;
  304. dgvInfo.Rows[i].Cells["count"].Value = m_history_info.Rows[i]["count"].ToString();
  305. dgvInfo.Rows[i].Cells["ratio"].Value = m_history_info.Rows[i]["ratio"].ToString();
  306. }
  307. lblTotal.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.total.text")+":" + m_total;
  308. // 饼图
  309. List<string> xData = new List<string>();
  310. List<decimal> yData = new List<decimal>();
  311. DataRow[] dr = m_history_info.Select("ratio <> '0'");
  312. for (int i=0; i< dr.Length; ++i)
  313. {
  314. string name = dr[i]["name"].ToString();
  315. decimal count = decimal.Parse(dr[i]["count"].ToString());
  316. xData.Add(name + "(" + dr[i]["ratio"].ToString() + ")");
  317. yData.Add(count);
  318. }
  319. chart1.Series[0]["PieLabelStyle"] = "Disabled";//将文字移到外侧Outside Inside
  320. chart1.Series[0].Points.DataBindXY(xData, yData);
  321. for (int i = 0; i < dr.Length; ++i)
  322. {
  323. chart1.Series[0].Points[i].Color = ColorTranslator.FromHtml(dr[i]["color"].ToString());
  324. }
  325. }
  326. /// <summary>
  327. /// 导出
  328. /// </summary>
  329. /// <param name="sender"></param>
  330. /// <param name="e"></param>
  331. private void btnExport_Click(object sender, EventArgs e)
  332. {
  333. string fileName = m_history.Rows[0]["file_name"].ToString();
  334. SaveFileDialog exe = new SaveFileDialog();
  335. exe.Filter = "Execl files (*.xls)|*.xls";
  336. exe.FilterIndex = 0;
  337. exe.RestoreDirectory = true;
  338. //exe.CreatePrompt = true;
  339. exe.Title = "Export Excel File";
  340. exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
  341. exe.FileName = fileName;
  342. DialogResult dr = exe.ShowDialog();
  343. if (dr != DialogResult.OK)
  344. {
  345. return;
  346. }
  347. //List<DataTable> list = new List<DataTable>();
  348. //list.Add(m_history_info/*dtb*/);
  349. //OfficeFileHandleHelper.ExportDataToExcelWithProgress(list, exe.FileName);
  350. Stream ms;
  351. StreamWriter sw;
  352. try
  353. {
  354. ms = exe.OpenFile();
  355. sw = new StreamWriter(ms, System.Text.Encoding.GetEncoding(-0));
  356. string title = PdnResources.GetString("Menu.name.text") + "\t" + PdnResources.GetString("Menu.Keyname.Text") + "\t" + PdnResources.GetString("Menu.color.text") + "\t" + PdnResources.GetString("Menu.Generalanalysis.Integrator.Quantity.text") + "\t" + PdnResources.GetString("Menu.proportion.text");
  357. sw.WriteLine(title);
  358. for (int j = 0; j < m_history_info.Rows.Count; j++)
  359. {
  360. string temp = "";
  361. for (int k = 2; k < m_history_info.Columns.Count; k++)
  362. {
  363. if (k > 2)
  364. {
  365. temp += "\t";
  366. }
  367. string cell = m_history_info.Rows[j][k].ToString();
  368. cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
  369. temp += cell;
  370. }
  371. sw.WriteLine(temp);
  372. }
  373. sw.Close();
  374. ms.Close();
  375. if (OfficeFileHandleHelper.ConvertWorkbook(exe.FileName, fileName))
  376. {
  377. if (System.IO.File.Exists(exe.FileName))
  378. System.IO.File.Delete(exe.FileName);
  379. }
  380. }
  381. catch (Exception ex)
  382. {
  383. MessageBox.Show(ex.Message);
  384. return;
  385. }
  386. }
  387. private void btnClose_Click(object sender, EventArgs e)
  388. {
  389. this.Close();
  390. }
  391. }
  392. }