using DevExpress.Utils;
using DevExpress.XtraCharts;
using NPOI.Util;
using OTSIncAReportApp.OTSRstMgrFunction;
using OTSIncAReportApp.OTSSampleReportInfo;
using OTSIncAReportApp.SysMgrTools;
using OTSIncAReportGrids;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Windows.Forms;
namespace OTSIncAReportApp.Control_ECharts
{
///
/// 各图char相关模块
///
public partial class DEVChart_ParticlesComposition : UserControl
{
Hashtable table;
#region 图表相关变量
//y轴名称
public string m_str_AxisY { get; set; }
//数据图类型:常用夹杂物分类CommonlyUsedClassify ,颗粒成分PComponent,元素成分EComponent,颗粒尺寸分布PSize
string ComSel { get; set; }
public bool Report { get; set; }
frmReportApp m_ReportApp;
private frmReportConditionChoose m_conditionChoose;
private ResultDataMgr m_DataMgr;
private List prListData = new List();
private List prListString = new List();
#endregion
#region 窗体加载及构造函数
public DEVChart_ParticlesComposition(frmReportApp ReportApp, string comsel)
{
ComSel = comsel;
m_ReportApp = ReportApp;
m_conditionChoose = ReportApp.m_conditionChoose;
m_DataMgr = ReportApp.m_rstDataMgr;
InitializeComponent();
//国际化
Language lan = new Language();
table = lan.GetNameTable("CompositionDistributionGrid");
}
private void EChart_ParticlesComposition_Load(object sender, EventArgs e)
{
string sou = "";
int sel = 0;//选择颗粒范围(0为全部颗粒1为选择颗粒)
if (Report)
{
sou = m_DataMgr.ResultFilesList[m_DataMgr.GetWorkingResultId()].anotherFileName.ToString();
sel = 0;
}
else
{
sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
}
Report = false;
if (m_ReportApp.more)
{
m_ReportApp.trans = false;
}
else
{
m_ReportApp.trans = true;
}
m_ReportApp.more = true;
List list_dt = GetListJsonStr();
bool bl = false;
for (int i=0;i< list_dt.Count;i++)
{
if (list_dt[i].Rows.Count>0)
{
bl = true;
}
}
if(!bl)
{
checkButton1.Visible = false;
checkButton2.Visible = false;
checkButton3.Visible = false;
return;
}
List listDt = new List();
for (int i=0;i< list_dt.Count;i++)
{
DataTable dt = list_dt[i].Clone();
for (int a=0;a< list_dt[i].Rows.Count;a++)
{
if (list_dt[i].Rows[a]["name"].ToString() != "")
{
dt.Rows.Add(list_dt[i].Rows[a].ItemArray);
}
}
listDt.Add(dt);
}
prListData = listDt.Copy();
prListString.Clear();
for (int i = 0; i < list_dt.Count; i++)
{
ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
string str = resultFile.anotherFileName;
prListString.Add(str);
// 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
//string str = prListString[i];
Series series = new Series(str, ViewType.Pie);
for (int a = 0; a < prListData[i].Rows.Count; a++)
{
string name = prListData[i].Rows[a]["name"].ToString();
double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
series.Points.Add(new SeriesPoint(name, Cunt));
}
series.LabelsVisibility = DefaultBoolean.True;
series.Label.TextPattern = "{A}";
chartControl1.Series.Add(series);
}
chartControl1.Legend.Visibility = DefaultBoolean.False;
chartControl1.Refresh();
panel1.Dock = DockStyle.Fill;
chartControl1.Dock = DockStyle.Fill;
checkButton1.Checked = false;
checkButton2.Checked = false;
checkButton3.Checked = true;
}
#endregion
#region 获取单数据源
private DataTable ClassificationIntegration(string path, int sel)
{
//------------------加载模块,获取数据-------------------------------------------------
ResultGrid ls_resultgrid = new ResultGrid(m_ReportApp);
Dictionary keyValues_ResultGrid = ls_resultgrid.GetData_ResultGrid_Report();
//------------------加载模块,获取数据结束----------------------------------------------
Dictionary.Enumerator en = keyValues_ResultGrid.GetEnumerator();
string str_SCZS = "";
keyValues_ResultGrid.TryGetValue(ls_resultgrid.table["col5"].ToString(), out str_SCZS);//视场总数
DataOperation.DataAccess.ParticleData particledata = new DataOperation.DataAccess.ParticleData(path);
DataTable data = new DataTable();
data = particledata.GetAreaByAllIncA("");//获取所有分类面积和数量信息
if (data.Rows.Count == 0)
{
return data;
}
DataTable AreaInformationOfAllElements = ConSolidateInvalid(data);
DataTable AllAnalysisDetails = new DataTable();
AllAnalysisDetails.Columns.Add("Name");
AllAnalysisDetails.Columns.Add("TypeId");
AllAnalysisDetails.Columns.Add("Area", typeof(double));
AllAnalysisDetails.Columns.Add("Class");
AllAnalysisDetails.Columns.Add("Cunt", typeof(double));
for (int i = 0; i < AreaInformationOfAllElements.Rows.Count; i++)
{
DataRow dr2 = AllAnalysisDetails.NewRow();
dr2["Name"] = AreaInformationOfAllElements.Rows[i]["TypeName"].ToString();
dr2["Area"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["ar"]);
dr2["TypeId"] = AreaInformationOfAllElements.Rows[i]["TypeId"].ToString();
dr2["Cunt"] = Convert.ToDouble(AreaInformationOfAllElements.Rows[i]["con"]);
dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString();
AllAnalysisDetails.Rows.Add(dr2);
}
//按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序
List ClassName = new List();
DataTable getClass_dt = particledata.GetAllClass();
for (int i = 0; i < getClass_dt.Rows.Count; i++)
{
ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString());
}
DataTable AreaRatio = new DataTable();
AreaRatio.TableName = "InclusionAreaRatio";
AreaRatio.Columns.Add("e1");
AreaRatio.Columns.Add("e2");
AreaRatio.Columns.Add("e3", typeof(double));
AreaRatio.Columns.Add("e4");
AreaRatio.Columns.Add("e5");
AreaRatio.Columns.Add("Cunt", typeof(int));
//获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一)
double totalInclusionArea = 0;
totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString()));
for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++)
{
DataRow dr2 = AreaRatio.NewRow();
dr2["e1"] = AllAnalysisDetails.Rows[i]["Class"].ToString();
dr2["e2"] = AllAnalysisDetails.Rows[i]["Name"].ToString();
dr2["e3"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]);
dr2["e4"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2);
dr2["e5"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
dr2["Cunt"] = AllAnalysisDetails.Rows[i]["Cunt"].ToString();
AreaRatio.Rows.Add(dr2);
}
DataTable AreaRatio_dt = AreaRatio.Copy();
AreaRatio_dt.Clear();
for (int i = 0; i < ClassName.Count(); i++)
{
DataTable dt = AreaRatio.Copy();
dt.Clear();
for (int a = 0; a < AreaRatio.Rows.Count; a++)
{
if (AreaRatio.Rows[a]["e1"].ToString() == ClassName[i].ToString())
{
dt.Rows.Add(AreaRatio.Rows[a].ItemArray);
}
}
DataView dv = dt.DefaultView;
dv.Sort = "e3 DESC";
DataTable dt_Element = dv.ToTable();
for (int a = 0; a < dt_Element.Rows.Count; a++)
{
AreaRatio_dt.Rows.Add(dt_Element.Rows[a].ItemArray);
}
}
DataTable AllAnalysisDetails1 = AreaRatio_dt.Copy();
AllAnalysisDetails1.Clear();
for (int i = 0; i < ClassName.Count; i++)
{
DataTable dt = AreaRatio_dt.Copy();
dt.Clear();
for (int a = 0; a < AreaRatio_dt.Rows.Count; a++)
{
if (AreaRatio_dt.Rows[a]["e1"].ToString() == ClassName[i].ToString())
{
dt.Rows.Add(AreaRatio_dt.Rows[a].ItemArray);
}
}
if (dt.Rows.Count > 0)
{
double totalInclusionArea2 = Convert.ToDouble(decimal.Parse(AreaRatio_dt.Compute("sum(e3)", "").ToString()));
double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString()));
int cunt = Convert.ToInt32(decimal.Parse(dt.Compute("sum(Cunt)", "").ToString()));
DataRow dr3 = AllAnalysisDetails1.NewRow();
dr3["e1"] = ClassName[i].ToString();
dr3["e3"] = Math.Round(Area, 2);
dr3["e4"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / totalInclusionArea2) * 100, 2);
dr3["e5"] = Math.Round((Convert.ToDouble(dt.Rows[0]["e3"]) / Convert.ToDouble(str_SCZS)) * 100, 4);
dr3["Cunt"] = cunt;
AllAnalysisDetails1.Rows.Add(dr3);
}
}
return AllAnalysisDetails1;
}
private DataTable ConSolidateInvalid(DataTable dt)
{
DataTable dt_invalid = dt.Clone();
DataTable dt_no_invalid = dt.Clone();
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["TypeName"].ToString() == "Invalid")
{
dt_invalid.Rows.Add(dt.Rows[i].ItemArray);
}
else
{
dt_no_invalid.Rows.Add(dt.Rows[i].ItemArray);
}
}
return dt_no_invalid;
}
private string getWhere(string max, string min, string col)
{
return col + ">=" + min + " and " + col + "<" + max;
}
#endregion
#region echarts
///
/// 通过m_list_chartstruct,组合json数据格式
///
///
private List GetListJsonStr()
{
int sel = m_conditionChoose.m_conditionData.ProItemProIndex();
string filedAndParticl = "";
DataOperation.DataAccess.ParticleData particledata = null;
DataTable dt = new DataTable();
List ListData = new List();
string sou = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
for (int i = 0; i < sou.Split('+').Length; i++)
{
ResultFile resultFile = m_DataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
if (resultFile == null)
{
continue;
}
particledata = new DataOperation.DataAccess.ParticleData(resultFile.FilePath);
switch (ComSel)
{
case "InclusionareaRatio":
dt = particledata.GetAreaByAllIncA("");
DataTable dtInclusionareaRatio = new DataTable();
dtInclusionareaRatio.Columns.Add("name");
dtInclusionareaRatio.Columns.Add("Cunt");
for (int k = 0; k < dt.Rows.Count; k++)
{
string str = dt.Rows[k]["ar"].ToString();
string name = dt.Rows[k]["TypeName"].ToString();
if (Convert.ToInt32(dt.Rows[k]["TypeId"]) < 100)
{
continue;
}
DataRow dr = dtInclusionareaRatio.NewRow();
dr["name"] = name;
dr["Cunt"] = decimal.Round(decimal.Parse(dt.Rows[k]["ar"].ToString()), 2).ToString();
dtInclusionareaRatio.Rows.Add(dr);
}
ListData.Add(dtInclusionareaRatio);
break;
case "CommonlyUsedClassify":
//计算分类整个表的数据
dt = ClassificationIntegration(resultFile.FilePath, sel);
DataTable data = new DataTable();
data.Columns.Add("name");
data.Columns.Add("Cunt");
for (int a = 0; a < dt.Rows.Count; a++)
{
DataRow dr = data.NewRow();
dr["name"] = dt.Rows[a]["e1"].ToString();
dr["Cunt"] = dt.Rows[a]["Cunt"].ToString();
data.Rows.Add(dr);
}
ListData.Add(data);
break;
case "PComponent":
//创建新的图形数据源
dt = particledata.GetParticleListByIncA("area");
DataTable dtPComponent = new DataTable();
dtPComponent.Columns.Add("name");
dtPComponent.Columns.Add("Cunt");
for (int a = 0; a < dt.Rows.Count; a++)
{
if (Convert.ToInt32(dt.Rows[a]["TypeId"]) < 100)
{
continue;
}
DataRow dr = dtPComponent.NewRow();
dr["name"] = dt.Rows[a]["TypeName"].ToString();
dr["Cunt"] = dt.Rows[a]["con"].ToString();
dtPComponent.Rows.Add(dr);
}
ListData.Add(dtPComponent);
break;
case "EComponent":
//创建新的图形数据源
dt = particledata.GetElementForArea(filedAndParticl);
DataTable dtEComponent = new DataTable();
dtEComponent.Columns.Add("name");
dtEComponent.Columns.Add("Cunt");
for (int k = 0; k < dt.Rows.Count; k++)
{
string str = dt.Rows[k]["earea"].ToString();
try
{
DataRow dr = dtEComponent.NewRow();
dr["name"] = dt.Rows[k]["name"].ToString();
dr["Cunt"] = decimal.Round(decimal.Parse(str), 2).ToString();
dtEComponent.Rows.Add(dr);
}
catch
{
DataRow dr = dtEComponent.NewRow();
dr["name"] = dt.Rows[k]["name"].ToString();
dr["Cunt"] = str;
dtEComponent.Rows.Add(dr);
}
}
ListData.Add(dtEComponent);
break;
case "PSize":
//获取粒级表
string pathe = m_DataMgr.m_RptConfigFile.PartSizeFileFolder + m_DataMgr.m_RptConfigFile.PartSizeFile;
DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(pathe);
string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
List temp = new List();
for (int j = 0; j < sizestr.Split(',').Length - 1; j++)
{
if (sizestr.Split(',')[j].Length > 0)
{
double d1 = Convert.ToDouble(sizestr.Split(',')[j]);
double d2 = Convert.ToDouble(sizestr.Split(',')[j + 1]);
string name = d1.ToString() + "~" + d2.ToString();
temp.Add(name);
}
}
double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
string name1 = d.ToString() + "~MAX";
temp.Add(name1);
string con = m_conditionChoose.m_conditionData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
string po = "";
switch (con)
{
case "DMAX":
po = "DMAX";
break;
case "DMIN":
po = "DMIN";
break;
case "ECD":
po = "Area";
break;
case "FERET":
po = "DFERET";
break;
}
DataTable dtp = particledata.GetParticleAll(filedAndParticl);
DataTable dtPSize = new DataTable();
dtPSize.Columns.Add("name");
dtPSize.Columns.Add("Cunt");
for (int k = 0; k < temp.Count; k++)
{
string str = temp[k];
string d1 = str.Split('~')[0];
string d2 = str.Split('~')[1];
if (d2 == "MAX")
{
d2 = "999";
}
DataRow[] datas = dtp.Select(getWhere(d2, d1, po));
DataRow dr = dtPSize.NewRow();
dr["name"] = str;
dr["Cunt"] = datas.Count().ToString();
dtPSize.Rows.Add(dr);
}
ListData.Add(dtPSize);
break;
}
}
return ListData;
}
#endregion
///
/// 折线图
///
///
///
private void checkButton2_CheckedChanged(object sender, EventArgs e)
{
if(checkButton2.Checked)
{
checkButton1.Checked = false;
checkButton3.Checked = false;
chartControl1.Series.Clear();
for (int i=0;i< prListData.Count;i++)
{
string str = prListString[i];
// 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
Series series = new Series(str, ViewType.Line);
for (int a = 0; a < prListData[i].Rows.Count; a++)
{
string name = prListData[i].Rows[a]["name"].ToString();
double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
series.Points.Add(new SeriesPoint(name, Cunt));
}
series.LabelsVisibility = DefaultBoolean.True;
series.Label.TextPattern = "{V}";
chartControl1.Series.Add(series);
}
chartControl1.Legend.Visibility = DefaultBoolean.False;
chartControl1.Refresh();
}
else
{
if (!checkButton1.Checked && !checkButton3.Checked)
{
checkButton2.Checked = false;
}
}
}
///
/// 柱状图
///
///
///
private void checkButton1_CheckedChanged(object sender, EventArgs e)
{
if (checkButton1.Checked)
{
checkButton2.Checked = false;
checkButton3.Checked = false;
chartControl1.Series.Clear();
for (int i = 0; i < prListData.Count; i++)
{
string str = prListString[i];
// 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
Series series = new Series(str, ViewType.Bar);
for (int a = 0; a < prListData[i].Rows.Count; a++)
{
string name = prListData[i].Rows[a]["name"].ToString();
double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
series.Points.Add(new SeriesPoint(name, Cunt));
}
series.LabelsVisibility = DefaultBoolean.True;
series.Label.TextPattern = "{V}";
chartControl1.Series.Add(series);
}
chartControl1.Legend.Visibility = DefaultBoolean.False;
chartControl1.Refresh();
}
else
{
if (!checkButton2.Checked && !checkButton3.Checked)
{
checkButton1.Checked = true;
}
}
}
private void checkButton3_CheckedChanged(object sender, EventArgs e)
{
if (checkButton3.Checked)
{
checkButton1.Checked = false;
checkButton2.Checked = false;
chartControl1.Series.Clear();
for (int i = 0; i < prListData.Count; i++)
{
string str = prListString[i];
Series series = new Series(str, ViewType.Pie);
for (int a = 0; a < prListData[i].Rows.Count; a++)
{
string name = prListData[i].Rows[a]["name"].ToString();
double Cunt = Convert.ToDouble(prListData[i].Rows[a]["Cunt"]);
series.Points.Add(new SeriesPoint(name, Cunt));
}
series.LabelsVisibility = DefaultBoolean.True;
series.Label.TextPattern = "{A}";
chartControl1.Series.Add(series);
}
chartControl1.Legend.Visibility = DefaultBoolean.False;
chartControl1.Refresh();
}
else
{
if (!checkButton1.Checked && !checkButton2.Checked)
{
checkButton3.Checked = true;
}
}
}
}
}