using OTSIncAReportApp.OTSSampleReportInfo;
using OTSIncAReportApp.SysMgrTools;
using OTSIncAReportGraph.Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace OTSIncAReportGrids
{
///
/// 颗粒平均元素成分含量表 平均元素含量表
///
public partial class ElementCompositionAvgGrid : UserControl
{
#region 设置变量
//设置模拟数据表
public DataTable m_dt = new DataTable();
//多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
public List m_list_oneresult_columncount;
//国际化
Language lan;
Hashtable table;
//测量结果
OTSIncAReportApp.DataOperation.Model.ResultFile result = null;
OTSIncAReportApp.DataOperation.DataAccess.ParticleData particledata;
OTSIncAReportApp.frmReportApp m_ReportApp;
internal string condition;
#endregion
#region 自定义方法
///
/// 绑定datagridview数据
///
public void BindDataGridView()
{
List colid = new List() { "rowid", "pname", "area", "con" };
List colname = new List() { table["str1"].ToString(), table["str4"].ToString(), table["str3"].ToString(), table["str6"].ToString() };
//创建Grid的列
for (int i = 0; i < colid.Count; i++)
{
Gview_gz.Columns.Add(colid[i], colname[i]);
}
DataTable dte = particledata.GetAllElement();
foreach (DataRow item in dte.Rows)
{
DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
iconColumn.Name = item["name"].ToString();
iconColumn.HeaderText = item["name"].ToString();
Gview_gz.Columns.Add(iconColumn);
}
List FLID = new List() { 0, 1, 2, 4, 6, 7, 8, 9 };
List NameList = new List() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() };
//int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
int sel = m_ReportApp.m_conditionChoose.m_SourceGridData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
string filedAndParticl = "";
DataTable dt;
if (sel == 1)
{
List selectParticles = m_ReportApp.GetSelectedParticles();
foreach (var item in selectParticles)
{
filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
}
if (filedAndParticl != "")
{
filedAndParticl = filedAndParticl + ",";
}
if (selectParticles.Count == 0)
{
dt = new DataTable();
}
else
{
dt = particledata.GetAreaByAllIncA(filedAndParticl);
}
}
else
{
dt = particledata.GetAreaByAllIncA(filedAndParticl);
}
for (int i = 0; i < dt.Rows.Count; i++)
{
if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
{
continue;
}
double total = Convert.ToDouble(dt.Rows[i]["ar"]);
//double small = Convert.ToDouble(dt.Rows[i]["small"]);
int add_rowindex = Gview_gz.Rows.Add();
Gview_gz.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
Gview_gz.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
Gview_gz.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
Gview_gz.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
//Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
//Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
Gview_gz.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
for (int j = 4; j < Gview_gz.Columns.Count; j++)
{
int col = 0;
foreach (DataRow dr in dtp.Rows)
{
if (Gview_gz.Columns[j].Name == dr["name"].ToString())
{
double ar = Convert.ToDouble(dr["pc"]);
double p = Math.Round(ar / total, 2);
Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap((float)p, Color.Azure);
Gview_gz.Rows[add_rowindex].Cells[j].Tag = p;
break;
}
col++;
}
if (col == dtp.Rows.Count)
{
Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap(0, Color.Azure);
Gview_gz.Rows[add_rowindex].Cells[j].Tag = 0;
}
}
}
for (int i = 0; i < dt.Rows.Count; i++)
{
if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
{
continue;
}
int add_rowindex = Gview_gz.Rows.Add();
Gview_gz.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
if (index == -1)
{
index = 7;
}
string name = NameList[index];
double total = Convert.ToDouble(dt.Rows[i]["ar"]);
//double small = Convert.ToDouble(dt.Rows[i]["small"]);
Gview_gz.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
//Gview_gz.Rows[add_rowindex].Cells[1].Value = name;
Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
Gview_gz.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
Gview_gz.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
//Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
Gview_gz.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
//Gview_gz.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
for (int j = 4; j < Gview_gz.Columns.Count; j++)
{
int col = 0;
foreach (DataRow dr in dtp.Rows)
{
if (Gview_gz.Columns[j].Name == dr["name"].ToString())
{
double ar = Convert.ToDouble(dr["pc"]);
double p = Math.Round(ar / total, 2);
Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap((float)p, Color.Azure);
Gview_gz.Rows[add_rowindex].Cells[j].Tag = p;
break;
}
col++;
}
if (col == dtp.Rows.Count)
{
Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap(0, Color.Azure);
Gview_gz.Rows[add_rowindex].Cells[j].Tag = 0;
}
}
}
}
///
/// 设置DataGridView样式
///
private void SetDataGridViewStyle()
{
//用户不能调整标题的高度
//Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//用户不能调整 行高
Gview_gz.AllowUserToResizeRows = false;
//改变行的高度;
//Gview_gz.RowTemplate.Height = 20;
//点击选择整行
Gview_gz.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
//居中显示
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
Gview_gz.DefaultCellStyle = dataGridViewCellStyle1;
Gview_gz.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
//再次重覆禁用拖动表头高度,居然有效果了
//Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
//设置grid可以复制
Gview_gz.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
//设置每列的宽度
Gview_gz.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
Gview_gz.Columns[1].Width = 200;
//设置序号列不排序
Gview_gz.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
//设置序号列不可以设置宽度
Gview_gz.Columns[0].Resizable = DataGridViewTriState.False;
//设置所有行的高度
for (int i = 0; i < Gview_gz.Rows.Count; i++)
{
Gview_gz.Rows[i].Height = 30;
}
}
#endregion
#region 初始化构造函数
///
/// 元素平均含量表,构造函数
///
/// 传入,委托类对象
/// 传入,项目管理类对象
public ElementCompositionAvgGrid(OTSIncAReportApp.frmReportApp ReportApp)
{
m_ReportApp = ReportApp;
result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()];
InitializeComponent();
lan = new Language(this);
table = lan.GetNameTable(this.Name);
}
private void ElementContentGrid_Load(object sender, EventArgs e)
{
particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(result.FilePath);
//创建datatable的列数据,及分栏,及相关行数据
BindDataGridView();
//设置grid风格
SetDataGridViewStyle();
}
#endregion
#region 相关事件
private void ToolStripMenuItem1_Click(object sender, EventArgs e)
{
//复制整个表
CopyAll();
}
private void ToolStripMenuItem2_Click(object sender, EventArgs e)
{
//复制选择区域
CopySelected();
}
///
/// 复制选择区域
///
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 ToolStripMenuItem3_Click(object sender, EventArgs e)
{
//恢复至初始状态
Gview_gz.Rows.Clear();
Gview_gz.Columns.Clear();
BindDataGridView();
SetDataGridViewStyle();
}
private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{
//排序中
if (this.Gview_gz.Rows[e.RowIndex1].Tag != null && this.Gview_gz.Rows[e.RowIndex1].Tag.ToString() == "统计行")
{
//ROW1>ROW2
e.SortResult = 1;
if (this.Gview_gz.SortOrder == SortOrder.Descending)
e.SortResult = -1;
e.Handled = true;
return;
}
if (this.Gview_gz.Rows[e.RowIndex2].Tag != null && this.Gview_gz.Rows[e.RowIndex2].Tag.ToString() == "统计行")
{
//ROW1
/// 获取到该模块输出后形成的DataTable,和GridView
///
///
///
public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
{
out_dt = m_dt;
//out_dt = (this.Gview_gz.DataSource as DataTable);
out_dg = this.Gview_gz;
}
#endregion
}
}