123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- using OTSIncAReportApp;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using OTSCommon.Model;
- using OTSIncAReportApp.OTSSampleReportInfo;
- using OTSIncAReportApp.SysMgrTools;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows.Forms;
- namespace OTSIncAReportGrids
- {
- public partial class ResultGrid : UserControl
- {
- #region 变量定义
- //测量结果
- frmReportApp m_frmReportApp = null;
- //国际化
- Language lan;
- public Hashtable table;
- frmReportConditionChoose m_condition;
- #endregion
- #region 窗体加载及构造函数
- public ResultGrid(frmReportApp frmReportApp)
- {
- m_frmReportApp = frmReportApp;
- m_condition = frmReportApp.m_conditionChoose;
- InitializeComponent();
- //国际化
- lan = new Language(this);
- table = lan.GetNameTable(this.Name);
- }
- private void ResultGrid_Load(object sender, EventArgs e)
- {
- BindGrid();
- SetDataGridViewStyleIncLib();
- }
- #endregion
- #region 绑定数据
- private void BindGrid()
- {
- string str1 = table["str1"].ToString();
- string str8 = table["str8"].ToString();
- Gview_gz.Rows.Clear();
- Gview_gz.Columns.Clear();
- //创建列
- Gview_gz.Columns.Add(str1, str1);
- Gview_gz.Columns.Add(str8, str8);
- //自适应列宽
- if (this.Width > 0)
- {
- //再对不同的列宽度进行设置
- Gview_gz.Columns[0].Width = this.Width / 2;
- Gview_gz.Columns[1].Width = this.Width / 2;
- }
- //先设置一下头的高度,否则会太矮不好看
- Gview_gz.ColumnHeadersVisible = false;
- Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
- Gview_gz.ColumnHeadersHeight = 30;
-
- string sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
- if (sou.Contains("+"))
- {
- for (int i = 0; i < sou.Split('+').Length; i++)
- {
- ResultFile resultFile = m_frmReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
- if (resultFile != null)
- {
- addGrid(resultFile);
- }
- }
- }
- else
- {
- for (int i=0;i< m_frmReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
- {
- if(sou== m_frmReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
- addGrid(m_frmReportApp.m_rstDataMgr.ResultFilesList[i]);
- }
- }
- }
- /// <summary>
- /// 获取测量结果概况信息数据
- /// </summary>
- /// <returns></returns>
- public Dictionary<string, string> GetData_ResultGrid(ResultFile resultFile)
- {
- ResultFile resfile = resultFile;
-
- Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
- keyValues.Add(table["col1"].ToString(), resfile.anotherFileName);
- string path = resfile.FilePath;
- FieldData fielddata = new FieldData(path);
- DataTable dt = fielddata.GetGeneralInfo();
- DateTime star = new DateTime();
- DateTime end = new DateTime();
- System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
- dtFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["name"].ToString() == "TimeStart")
- {
- star = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
- }
- if (dt.Rows[i]["name"].ToString() == "TimeEnd")
- {
- end = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
- }
- }
- }
- TimeSpan timeSpan = end - star;
- int filedCount = fielddata.GetFiledCount();
- double scanFieldSize = resfile.GetScanFieldSizeX();
- double wide = resfile.GetImageWidth();
- double high = resfile.GetImageHeight();
-
- double filedsArea = scanFieldSize * (scanFieldSize * high / wide) * filedCount;
- double particleArea = fielddata.GetparticleArea();
-
- double Magnification= resfile.GetMeasurementMagnification();
- //报告参数文件
- string xmlpath = Application.StartupPath + RptConfigFile.m_ReportMgrParamFile;
- DataSet ds = XMLoperate.GetXmlData(xmlpath, "XMLData");
- DataTable dt1 = ds.Tables["Member"];
- string sizestr = "1000";
- for (int i = 0; i < dt1.Rows.Count; i++)
- {
- if (dt1.Rows[i]["RegName"].ToString() == "Scale")
- {
- sizestr = dt1.Rows[i]["strValue"].ToString();
- break;
- }
- }
- double ratio = Math.Round(particleArea / filedsArea*double.Parse(sizestr),3);
- keyValues.Add(table["col2"].ToString(), star.ToString("yyyy-MM-dd HH:mm:ss"));
- keyValues.Add(table["col3"].ToString(), end.ToString("yyyy-MM-dd HH:mm:ss"));
- keyValues.Add(table["col4"].ToString(), Math.Round(timeSpan.TotalMinutes, 2).ToString() + "mins");
- keyValues.Add(table["col5"].ToString(), filedCount.ToString());
- keyValues.Add(table["col12"].ToString(), Math.Round(Magnification, 2).ToString());
- string LibraryName = "";
- string rstSTD = resfile.GetSTDName();
- if ("NoSTDDB"== rstSTD ||
- "NoSTDDB.db" == rstSTD)
- {
- LibraryName = "OTSIncASysSTD";
- }
- else
- {
- LibraryName = rstSTD;
- }
- keyValues.Add(table["col6"].ToString(), LibraryName);
- keyValues.Add(table["col7"].ToString(), fielddata.GetparticleCount().ToString());
- keyValues.Add(table["col8"].ToString() + "\x00B2)", filedsArea.ToString());
- keyValues.Add(table["col9"].ToString()+ "\x00B2)", String.Format("{0:f2}", particleArea));
- keyValues.Add(table["col10"].ToString(), ratio.ToString());
- //keyValues.Add(table["col11"].ToString(), sizestr);
- return keyValues;
- }
- public Dictionary<string, string> GetData_ResultGrid_Report()
- {
- ResultFile resfile = m_frmReportApp.m_rstDataMgr.ResultFilesList[m_frmReportApp.m_rstDataMgr.getSelectedIndex()];
- Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
- keyValues.Add(table["col1"].ToString(), resfile.anotherFileName);
- string path = resfile.FilePath;
- FieldData fielddata = new FieldData(path);
- DataTable dt = fielddata.GetGeneralInfo();
- DateTime star = new DateTime();
- DateTime end = new DateTime();
- System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
- dtFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["name"].ToString() == "TimeStart")
- {
- star = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
- }
- if (dt.Rows[i]["name"].ToString() == "TimeEnd")
- {
- end = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
- }
- }
- }
- TimeSpan timeSpan = end - star;
- double Magnification = resfile.GetMeasurementMagnification();
- int filedCount = fielddata.GetFiledCount();
- double wide = resfile.GetImageWidth();
- double high = resfile.GetImageHeight();
- double pixelSize = resfile.GetPixelSize();
- double filedsArea = Math.Round(high * wide * pixelSize * pixelSize * filedCount, 2);
- double particleArea = fielddata.GetparticleArea();
- //double ratio = particleArea / filedsArea;
- //报告参数文件
- string xmlpath = Application.StartupPath + RptConfigFile.m_ReportMgrParamFile;
- DataSet ds = XMLoperate.GetXmlData(xmlpath, "XMLData");
- DataTable dt1 = ds.Tables["Member"];
- string sizestr = "1000";
- for (int i = 0; i < dt1.Rows.Count; i++)
- {
- if (dt1.Rows[i]["RegName"].ToString() == "Scale")
- {
- sizestr = dt1.Rows[i]["strValue"].ToString();
- break;
- }
- }
- double ratio = Math.Round(particleArea / filedsArea * double.Parse(sizestr), 3);
- keyValues.Add(table["col2"].ToString(), star.ToString("yyyy-MM-dd HH:mm:ss"));
- keyValues.Add(table["col3"].ToString(), end.ToString("yyyy-MM-dd HH:mm:ss"));
- keyValues.Add(table["col4"].ToString(), Math.Round(timeSpan.TotalMinutes, 2).ToString() + "mins");
- keyValues.Add(table["col5"].ToString(), filedCount.ToString());
- string LibraryName = "";
- string rstSTD = resfile.GetSTDName();
- if ("NoSTDDB" == rstSTD||
- "NoSTDDB.db" == rstSTD)
- {
- LibraryName = "OTSIncASysSTD";
- }
- else
- {
- LibraryName = rstSTD;
- }
- keyValues.Add(table["col6"].ToString(), LibraryName);
- keyValues.Add(table["col7"].ToString(), fielddata.GetparticleCount().ToString());
- keyValues.Add(table["col8"].ToString(), filedsArea.ToString());
- keyValues.Add(table["col9"].ToString(), particleArea.ToString());
- keyValues.Add(table["col10"].ToString(), ratio.ToString());
- keyValues.Add(table["col11"].ToString(), sizestr);
- keyValues.Add("Magnification", Math.Round(Magnification,2).ToString());
-
- return keyValues;
- }
- /// <summary>
- /// 绑定GridView显示
- /// </summary>
- /// <param name="resultFile"></param>
- private void addGrid(ResultFile resultFile)
- {
- Dictionary<string, string> keyValues = GetData_ResultGrid(resultFile);
- Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
- for (int irow = 0; irow < keyValues.Count; irow++)
- {
- if (en.MoveNext())
- {
- //add row
- int add_rowindex = 0;
- add_rowindex = Gview_gz.Rows.Add();
- if (irow == 0)
- {
- //set title style
- Gview_gz.Rows[add_rowindex].Cells[0].Style.BackColor = System.Drawing.Color.PowderBlue;
- Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = System.Drawing.Color.PowderBlue;
- }
- else
- {
- //set row style
- Gview_gz.Rows[add_rowindex].Cells[0].Style.BackColor = System.Drawing.Color.LightCyan;
- }
- //set value
- Gview_gz.Rows[add_rowindex].Cells[0].Value = en.Current.Key;
- Gview_gz.Rows[add_rowindex].Cells[1].Value = en.Current.Value;
- }
- }
- //将左侧第一列,全部设置成System.Drawing.Color.PowderBlue; 当标题头不错
- for (int i = 0; i < Gview_gz.Rows.Count; i++)
- {
- Gview_gz.Rows[i].Cells[0].Style.Font = new System.Drawing.Font("黑体", 10, System.Drawing.FontStyle.Bold);
- Gview_gz.Rows[i].Cells[1].Style.Font = new System.Drawing.Font("黑体", 10, System.Drawing.FontStyle.Bold);
- }
- }
- #endregion
- #region 设置Grid样式
- /// <summary>
- /// 设置夹杂物列表DataGridView样式
- /// </summary>
- private void SetDataGridViewStyleIncLib()
- {
- //用户不能调整标题的高度
- Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //用户不能调整 行高
- Gview_gz.AllowUserToResizeRows = false;
- //再次重覆禁用拖动表头高度,居然有效果了
- Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
- //设置grid可以复制
- Gview_gz.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
- //设置每列的宽度
- // dgV_IncALib.Columns[1].Width = 40;
- Gview_gz.Columns[0].Width = 300;
- //设置序号列不排序
- Gview_gz.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
- //设置序号列不可以设置宽度
- Gview_gz.Columns[0].Resizable = DataGridViewTriState.False;
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
- System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
- dataGridViewCellStyle1.BackColor = System.Drawing.Color.LightCyan;
- Gview_gz.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
- Gview_gz.BackgroundColor = System.Drawing.Color.White;
- Gview_gz.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- Gview_gz.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
- dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
- dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240)))));
- dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy;
- dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
- dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
- Gview_gz.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
- Gview_gz.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- Gview_gz.EnableHeadersVisualStyles = false;
- Gview_gz.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
- Gview_gz.ReadOnly = true;
- Gview_gz.RowHeadersVisible = false; //建议改为true;为了以后显示序号。
- Gview_gz.RowTemplate.Height = 23;
- Gview_gz.RowTemplate.ReadOnly = true;
- //居中
- Gview_gz.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
- }
- #endregion
- #region 得到向word中插入Table所需要使用的,该模块结合后的对象数组
- /// <summary>
- /// 获取到该模块输出后形成的DataTable,和GridView
- /// </summary>
- /// <param name="out_dt"></param>
- /// <param name="out_dg"></param>
- public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
- {
- out_dt = null;
- out_dg = this.Gview_gz;
- }
- #endregion
- #region 相关事件
- /// <summary>
- /// 复制选择区域
- /// </summary>
- public void CopySelected()
- {
- //复制选择区域
- object oo = Gview_gz.GetClipboardContent();
- Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
- }
- /// <summary>
- /// 复制所有
- /// </summary>
- public void CopyAll()
- {
- Gview_gz.SelectAll();
- Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
- }
- //复制整个表
- private void ToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- CopyAll();
- }
- //复制选择区域
- private void ToolStripMenuItem2_Click(object sender, EventArgs e)
- {
- CopySelected();
- }
- //恢复初始状态
- private void ToolStripMenuItem3_Click(object sender, EventArgs e)
- {
- }
- #endregion
- }
- }
|