using OTSIncAReportApp;
using OTSIncAReportApp.DataOperation.DataAccess;
using OTSIncAReportApp.OTSSampleReportInfo;
using OTSIncAReportApp.SysMgrTools;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using OTSIncAReportApp.OTSRstMgrFunction;
using static DevExpress.Utils.MVVM.Internal.ILReader;
using System.Text.RegularExpressions;
using DevExpress.XtraReports.UI;
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]);
}
}
}
///
/// 获取测量结果概况信息数据
///
///
public Dictionary GetData_ResultGrid(ResultFile resultFile)
{
ResultFile resfile = resultFile;
Dictionary keyValues = new Dictionary() { };
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= resfile.GetTotalArea();
if (filedsArea == -1)
{
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 * 1000000) *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 strSTDType = resfile.GetSTDEngineType();
string rstSTD = resfile.GetSTDName();
string[] result = Regex.Split(strSTDType, ":");
if (result[0] == "-1")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = rstSTD;
}
}
else
if (result[0] == "0")
{
LibraryName = "OTSIncASysSTD";
}
else if (result[0] == "1")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = rstSTD;
}
}
else if (result[0] == "2")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = "OTSIncASysSTD+" + rstSTD;
}
}
else if (result[0] == "3")
{
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)",Math.Round(filedsArea,2).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 GetData_ResultGrid_Report()
{
ResultFile resfile = m_frmReportApp.m_rstDataMgr.ResultFilesList[m_frmReportApp.m_rstDataMgr.GetWorkingResultId()];
Dictionary keyValues = new Dictionary() { };
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 filedsArea = resfile.GetTotalArea();
//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 * 1000000) * 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 strSTDType = resfile.GetSTDEngineType();
string rstSTD = resfile.GetSTDName();
string[] result = Regex.Split(strSTDType, ":");
if (result[0] == "-1")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = rstSTD;
}
}
else
if (result[0] == "0")
{
LibraryName = "OTSIncASysSTD";
}
else if (result[0] == "1")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = rstSTD;
}
}
else if (result[0] == "2")
{
if ("NoSTDDB" == rstSTD ||
"NoSTDDB.db" == rstSTD)
{
LibraryName = "OTSIncASysSTD";
}
else
{
LibraryName = "OTSIncASysSTD+" + rstSTD;
}
}
else if (result[0] == "3")
{
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(), Math.Round(filedsArea, 2).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;
}
///
/// 绑定GridView显示
///
///
private void addGrid(ResultFile resultFile)
{
Dictionary keyValues = GetData_ResultGrid(resultFile);
Dictionary.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样式
///
/// 设置夹杂物列表DataGridView样式
///
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所需要使用的,该模块结合后的对象数组
///
/// 获取到该模块输出后形成的DataTable,和GridView
///
///
///
public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
{
out_dt = null;
out_dg = this.Gview_gz;
}
#endregion
#region 相关事件
///
/// 复制选择区域
///
public void CopySelected()
{
//复制选择区域
object oo = Gview_gz.GetClipboardContent();
Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
}
///
/// 复制所有
///
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
}
}