using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PaintDotNet.Base.CommTool;
namespace PaintDotNet.GeneralAnalysis.Countometer
{
public class DetailDialog : PdnBaseForm
{
#region
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
this.btnExport.Text = PdnResources.GetString("Menu.Imagement.Bitmapanalysis.exportdata.text");
this.groupBox2.Text = PdnResources.GetString("Menu.Organizationinformation.text");
this.name.HeaderText = PdnResources.GetString("Menu.name.text");
this.hotKey.HeaderText = PdnResources.GetString("Menu.Keyname.Text");
this.color.HeaderText = PdnResources.GetString("Menu.color.text");
this.count.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.Quantity.text");
this.ratio.HeaderText = PdnResources.GetString("Menu.proportion.text");
this.groupBox3.Text = PdnResources.GetString("Menu.Thepiechart.Text");
this.lblTotal.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.total.text") + ":0";
this.Text = PdnResources.GetString("Menu.GeneralAnalysis.Countometer.Text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea5 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend5 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series5 = new System.Windows.Forms.DataVisualization.Charting.Series();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnClose = new System.Windows.Forms.Button();
this.btnExport = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.dgvInfo = new System.Windows.Forms.DataGridView();
this.name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.hotKey = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.color = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ratio = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();
this.lblTotal = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvInfo)).BeginInit();
this.groupBox3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox1.Controls.Add(this.btnClose);
this.groupBox1.Controls.Add(this.btnExport);
this.groupBox1.Location = new System.Drawing.Point(12, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(684, 80);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// btnClose
//
this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnClose.Location = new System.Drawing.Point(577, 28);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(84, 31);
this.btnClose.TabIndex = 3;
this.btnClose.Text = "关闭";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnExport
//
this.btnExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnExport.Location = new System.Drawing.Point(475, 28);
this.btnExport.Name = "btnExport";
this.btnExport.Size = new System.Drawing.Size(84, 31);
this.btnExport.TabIndex = 2;
this.btnExport.Text = "导出数据";
this.btnExport.UseVisualStyleBackColor = true;
this.btnExport.Click += new System.EventHandler(this.btnExport_Click);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.dgvInfo);
this.groupBox2.Location = new System.Drawing.Point(12, 98);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(684, 266);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "组织信息";
//
// dgvInfo
//
this.dgvInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dgvInfo.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
this.dgvInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.name,
this.hotKey,
this.color,
this.count,
this.ratio});
this.dgvInfo.Enabled = false;
this.dgvInfo.Location = new System.Drawing.Point(13, 23);
this.dgvInfo.Name = "dgvInfo";
this.dgvInfo.RowHeadersVisible = false;
this.dgvInfo.RowHeadersWidth = 51;
this.dgvInfo.RowTemplate.Height = 27;
this.dgvInfo.Size = new System.Drawing.Size(660, 233);
this.dgvInfo.TabIndex = 0;
//
// name
//
this.name.DataPropertyName = "name";
this.name.MinimumWidth = 6;
this.name.Name = "name";
this.name.ReadOnly = true;
//
// hotKey
//
this.hotKey.DataPropertyName = "hot_key";
this.hotKey.MinimumWidth = 6;
this.hotKey.Name = "hotKey";
this.hotKey.ReadOnly = true;
//
// color
//
this.color.DataPropertyName = "color";
this.color.MinimumWidth = 6;
this.color.Name = "color";
this.color.ReadOnly = true;
//
// count
//
this.count.DataPropertyName = "count";
this.count.MinimumWidth = 6;
this.count.Name = "count";
this.count.ReadOnly = true;
//
// ratio
//
this.ratio.DataPropertyName = "ratio";
this.ratio.MinimumWidth = 6;
this.ratio.Name = "ratio";
this.ratio.ReadOnly = true;
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.chart1);
this.groupBox3.Location = new System.Drawing.Point(12, 370);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(684, 251);
this.groupBox3.TabIndex = 2;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "饼状图";
//
// chart1
//
this.chart1.BackColor = System.Drawing.SystemColors.Control;
chartArea5.BackColor = System.Drawing.SystemColors.Control;
chartArea5.Name = "ChartArea1";
this.chart1.ChartAreas.Add(chartArea5);
legend5.BackColor = System.Drawing.SystemColors.Control;
legend5.Name = "Legend1";
this.chart1.Legends.Add(legend5);
this.chart1.Location = new System.Drawing.Point(74, 24);
this.chart1.Name = "chart1";
series5.ChartArea = "ChartArea1";
series5.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
series5.Color = System.Drawing.SystemColors.Control;
series5.LabelBackColor = System.Drawing.SystemColors.Control;
series5.Legend = "Legend1";
series5.Name = "Series1";
this.chart1.Series.Add(series5);
this.chart1.Size = new System.Drawing.Size(524, 221);
this.chart1.TabIndex = 1;
this.chart1.Text = "chart1";
//
// lblTotal
//
this.lblTotal.AutoSize = true;
this.lblTotal.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblTotal.Location = new System.Drawing.Point(9, 633);
this.lblTotal.Name = "lblTotal";
this.lblTotal.Size = new System.Drawing.Size(0, 16);
this.lblTotal.TabIndex = 3;
//
// DetailDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(708, 663);
this.Controls.Add(this.lblTotal);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DetailDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.Controls.SetChildIndex(this.lblTotal, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvInfo)).EndInit();
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnExport;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.DataGridView dgvInfo;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Label lblTotal;
private System.Windows.Forms.DataGridViewTextBoxColumn name;
private System.Windows.Forms.DataGridViewTextBoxColumn hotKey;
private System.Windows.Forms.DataGridViewTextBoxColumn color;
private System.Windows.Forms.DataGridViewTextBoxColumn count;
private System.Windows.Forms.DataGridViewTextBoxColumn ratio;
private System.Windows.Forms.DataVisualization.Charting.Chart chart1;
#endregion
private string m_id;
private SQLiteHelper m_sqlHelper;
private int m_total = 0;
private DataTable m_history;
private DataTable m_history_info;
public DetailDialog(string id)
{
m_id = id;
InitializeComponent();
InitializeLanguageText();
InitializeData();
}
private void InitializeData()
{
dgvInfo.DefaultCellStyle.SelectionBackColor = dgvInfo.DefaultCellStyle.BackColor;
dgvInfo.DefaultCellStyle.SelectionForeColor = dgvInfo.DefaultCellStyle.ForeColor;
dgvInfo.AutoGenerateColumns = false;
dgvInfo.AllowUserToAddRows = false;
m_sqlHelper = new SQLiteHelper(); //连接数据库
m_sqlHelper.Connect();
string select_sql = "select * from mic_assay_history where delete_flag = 0 and id ='"+ m_id + "'"; //查询的SQL语句
m_history = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
select_sql = "select * from mic_assay_history_info where history_id ='" + m_id + "'"; //查询的SQL语句
m_history_info = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
if (m_history_info == null || m_history_info.Rows.Count <= 0)
{
return;
}
dgvInfo.Rows.Clear();
dgvInfo.Rows.Add(m_history_info.Rows.Count);
for (int i = 0; i < m_history_info.Rows.Count; ++i)
{
m_total += int.Parse(m_history_info.Rows[i]["count"].ToString());
dgvInfo.Rows[i].Cells["name"].Value = m_history_info.Rows[i]["name"].ToString();
dgvInfo.Rows[i].Cells["hotKey"].Value = m_history_info.Rows[i]["hot_key"].ToString();
dgvInfo.Rows[i].Cells["color"].Value = m_history_info.Rows[i]["color"].ToString();
dgvInfo.Rows[i].Cells["color"].Style.BackColor = ColorTranslator.FromHtml(m_history_info.Rows[i]["color"].ToString());
dgvInfo.Rows[i].Cells["color"].Style.ForeColor = Color.White;
dgvInfo.Rows[i].Cells["color"].Style.SelectionBackColor = ColorTranslator.FromHtml(m_history_info.Rows[i]["color"].ToString());
dgvInfo.Rows[i].Cells["color"].Style.SelectionForeColor = Color.White;
dgvInfo.Rows[i].Cells["count"].Value = m_history_info.Rows[i]["count"].ToString();
dgvInfo.Rows[i].Cells["ratio"].Value = m_history_info.Rows[i]["ratio"].ToString();
}
lblTotal.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.total.text")+":" + m_total;
// 饼图
List xData = new List();
List yData = new List();
DataRow[] dr = m_history_info.Select("ratio <> '0'");
for (int i=0; i< dr.Length; ++i)
{
string name = dr[i]["name"].ToString();
decimal count = decimal.Parse(dr[i]["count"].ToString());
xData.Add(name + "(" + dr[i]["ratio"].ToString() + ")");
yData.Add(count);
}
chart1.Series[0]["PieLabelStyle"] = "Disabled";//将文字移到外侧Outside Inside
chart1.Series[0].Points.DataBindXY(xData, yData);
for (int i = 0; i < dr.Length; ++i)
{
chart1.Series[0].Points[i].Color = ColorTranslator.FromHtml(dr[i]["color"].ToString());
}
}
///
/// 导出
///
///
///
private void btnExport_Click(object sender, EventArgs e)
{
string fileName = m_history.Rows[0]["file_name"].ToString();
SaveFileDialog exe = new SaveFileDialog();
exe.Filter = "Execl files (*.xls)|*.xls";
exe.FilterIndex = 0;
exe.RestoreDirectory = true;
//exe.CreatePrompt = true;
exe.Title = "Export Excel File";
exe.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
exe.FileName = fileName;
DialogResult dr = exe.ShowDialog();
if (dr != DialogResult.OK)
{
return;
}
//List list = new List();
//list.Add(m_history_info/*dtb*/);
//OfficeFileHandleHelper.ExportDataToExcelWithProgress(list, exe.FileName);
Stream ms;
StreamWriter sw;
try
{
ms = exe.OpenFile();
sw = new StreamWriter(ms, System.Text.Encoding.GetEncoding(-0));
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");
sw.WriteLine(title);
for (int j = 0; j < m_history_info.Rows.Count; j++)
{
string temp = "";
for (int k = 2; k < m_history_info.Columns.Count; k++)
{
if (k > 2)
{
temp += "\t";
}
string cell = m_history_info.Rows[j][k].ToString();
cell = cell.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\r\n", "");
temp += cell;
}
sw.WriteLine(temp);
}
sw.Close();
ms.Close();
if (OfficeFileHandleHelper.ConvertWorkbook(exe.FileName, fileName))
{
if (System.IO.File.Exists(exe.FileName))
System.IO.File.Delete(exe.FileName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}