using OTSIncAReportApp.DataOperation.DataAccess; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using static OTSIncAReportApp.OTSReport_Export; namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration { /// /// 夹杂物占比 /// class InclusionProportion { /// /// 夹杂物数据表 /// /// /// public DataTable GetINCAtable(BasicData basicData, string str, c_TemplateClass m_mbszclass) { //根据sql条件,查询获取颗粒信息数据 //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序 List ClassName = new List(); DataTable getClass_dt = basicData.GetAllClass(); bool bl = false; for (int i = 0; i < getClass_dt.Rows.Count; i++) { if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid" && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified") if (getClass_dt.Rows[i]["GroupName"].ToString() == "") { if (!bl) { ClassName.Add("Default"); bl = true; } } else { if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default") { ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString()); } } } //夹杂物面积比添加大类 DataTable RawParticleData = InclusionAreaRatio_2(str, basicData, m_mbszclass); //夹杂物面积比计算大类占比 ProportionOfParticleArea(RawParticleData, ClassName, str, out DataTable dt); return dt; } /// /// 夹杂物大分类chart数据 /// /// /// /// /// public DataTable Get_incaPIC_classify(string str ,c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export) { ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath); DataTable m_bt_DBData = fielddata.GetAreaByAllIncA("");//获取所有分类面积和数量信息 DataTable data; if (m_mbszclass.list_str_MainPriority_Serial.Count==0) { data = m_bt_DBData.Copy(); } else { data = m_bt_DBData.Clone(); for (int i = 0; i < m_bt_DBData.Rows.Count; i++) { for (int a = 0; a < m_mbszclass.list_str_MainPriority_Serial.Count; a++) { if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[a]) { data.Rows.Add(m_bt_DBData.Rows[i].ItemArray); continue; } } } } //去除物质分类(非夹杂物分类) for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++) { for (int i = data.Rows.Count - 1; i >= 0; i--) { if (data.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString()) { data.Rows.RemoveAt(i); } } } 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"]); if (AreaInformationOfAllElements.Rows[i]["GroupName"].ToString() == "") dr2["Class"] = "Default"; else dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString(); //dr2["Class"] = AreaInformationOfAllElements.Rows[i]["GroupName"].ToString(); AllAnalysisDetails.Rows.Add(dr2); } //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序 List ClassName = new List(); DataTable getClass_dt = fielddata.GetAllClass(); bool bl = false; for (int i = 0; i < getClass_dt.Rows.Count; i++) { if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid" && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified") if (getClass_dt.Rows[i]["GroupName"].ToString() == "") { if (!bl) { ClassName.Add("Default"); bl = true; } } else { if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default") { ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString()); } } } DataTable AreaRatio = new DataTable(); AreaRatio.TableName = "InclusionAreaRatio"; AreaRatio.Columns.Add("Class"); AreaRatio.Columns.Add("Name"); AreaRatio.Columns.Add("Area", typeof(double)); AreaRatio.Columns.Add("inca_proportion"); AreaRatio.Columns.Add("inca_FieldRatio"); AreaRatio.Columns.Add("Cunt", typeof(int)); //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一) double totalInclusionArea = Convert.ToDouble(decimal.Parse(AllAnalysisDetails.Compute("sum(Area)", "").ToString())); for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++) { DataRow dr2 = AreaRatio.NewRow(); dr2["Class"] = AllAnalysisDetails.Rows[i]["Class"].ToString(); dr2["Name"] = AllAnalysisDetails.Rows[i]["Name"].ToString(); dr2["Area"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]); dr2["inca_proportion"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / totalInclusionArea) * 100, 2); dr2["inca_FieldRatio"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str)) * 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]["Class"].ToString() == ClassName[i].ToString()) { dt.Rows.Add(AreaRatio.Rows[a].ItemArray); } } DataView dv = dt.DefaultView; dv.Sort = "Area 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]["Class"].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(Area)", "").ToString())); double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(Area)", "").ToString())); int cunt = Convert.ToInt32(decimal.Parse(dt.Compute("sum(Cunt)", "").ToString())); DataRow dr3 = AllAnalysisDetails1.NewRow(); dr3["Class"] = ClassName[i].ToString(); dr3["Area"] = Math.Round(Area, 2); dr3["inca_proportion"] = Math.Round((Convert.ToDouble(dt.Rows[0]["Area"]) / totalInclusionArea2) * 100, 2); dr3["inca_FieldRatio"] = Math.Round((Convert.ToDouble(dt.Rows[0]["Area"]) / Convert.ToDouble(str)) * 100, 4); dr3["Cunt"] = cunt; AllAnalysisDetails1.Rows.Add(dr3); } } return AllAnalysisDetails1; } /// /// 夹杂物细分类chart数据 /// /// /// /// public DataTable Get_incaPIC_subdivision(c_TemplateClass m_mbszclass,OTSReport_Export m_otsreport_export) { ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath); DataTable m_bt_DBData = fielddata.GetAreaByAllIncA("");//获取所有分类面积和数量信息 //按照list列表进行物质类排序,物质类中的元素分类按照面积的大小进行排序 List ClassName = new List(); DataTable getClass_dt = fielddata.GetAllClass(); bool bl = false; for (int i = 0; i < getClass_dt.Rows.Count; i++) { if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid" && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified") if (getClass_dt.Rows[i]["GroupName"].ToString() == "") { if (!bl) { ClassName.Add("Default"); bl = true; } } else { if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default") { ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString()); } } } DataTable dataTable = m_bt_DBData.Clone(); for (int i=0;i< m_bt_DBData.Rows.Count;i++) { for (int a=0;a< ClassName.Count;a++) { if (m_bt_DBData.Rows[i]["GroupName"].ToString()== ClassName[a].ToString()) { dataTable.Rows.Add(m_bt_DBData.Rows[i].ItemArray); } } } if (m_mbszclass.list_str_MainPriority_Serial.Count==0) { return ConSolidateInvalid(dataTable); } DataTable data = m_bt_DBData.Clone(); for (int i = 0; i < m_bt_DBData.Rows.Count; i++) { for (int a = 0; a < m_mbszclass.list_str_MainPriority_Serial.Count; a++) { if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[a]) { data.Rows.Add(m_bt_DBData.Rows[i].ItemArray); continue; } } } return ConSolidateInvalid(dataTable); } 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 DataTable InclusionAreaRatio_2(string str, BasicData basicData, c_TemplateClass m_mbszclass) { //根据sql条件,查询获取颗粒信息数据 //ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.getSelectedIndex()].FilePath); DataTable m_bt_DBData = InvalidRemoval(basicData.getParticleData().GetAreaByAllIncA("")); DataTable AreaInformationOfAllElements; if (m_mbszclass.list_str_MainPriority_Serial.Count==0) { AreaInformationOfAllElements = m_bt_DBData.Copy(); } else { AreaInformationOfAllElements = m_bt_DBData.Clone(); for (int i = 0; i < m_bt_DBData.Rows.Count; i++) { for (int a = 0; a < m_mbszclass.list_str_MainPriority_Serial.Count; a++) { if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.list_str_MainPriority_Serial[a]) { AreaInformationOfAllElements.Rows.Add(m_bt_DBData.Rows[i].ItemArray); continue; } } } } //去除物质分类(非夹杂物分类) for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++) { for (int i = AreaInformationOfAllElements.Rows.Count - 1; i >= 0; i--) { if (AreaInformationOfAllElements.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString()) { AreaInformationOfAllElements.Rows.RemoveAt(i); } } } 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 ClassName = new List(); DataTable getClass_dt = basicData.GetAllClass(); bool bl = false; for (int i = 0; i < getClass_dt.Rows.Count; i++) { if (getClass_dt.Rows[i]["GroupName"].ToString() != "NOT_INCLUTION" && getClass_dt.Rows[i]["GroupName"].ToString() != "Invalid" && getClass_dt.Rows[i]["GroupName"].ToString() != "Not Identified") if (getClass_dt.Rows[i]["GroupName"].ToString() == "") { if (!bl) { ClassName.Add("Default"); bl = true; } } else { if (getClass_dt.Rows[i]["GroupName"].ToString() != "Default") { ClassName.Add(getClass_dt.Rows[i]["GroupName"].ToString()); } } } DataTable AreaRatio = new DataTable(); AreaRatio.TableName = "InclusionAreaRatio"; AreaRatio.Columns.Add("Class"); AreaRatio.Columns.Add("subdivision"); AreaRatio.Columns.Add("Area", typeof(double)); AreaRatio.Columns.Add("inca_proportion"); AreaRatio.Columns.Add("inca_FieldRatio"); //获取夹杂物的总面积用于计算夹杂物类别的占比(gridview最后一个固定是未识别颗粒,要排除未识别颗粒所以for循环至grid view长度减一) int sumArea = 0; for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++) { sumArea = sumArea + Convert.ToInt32(AllAnalysisDetails.Rows[i]["Area"]); } for (int i = 0; i < AllAnalysisDetails.Rows.Count; i++) { DataRow dr = AreaRatio.NewRow(); //dr["Class"] = AllAnalysisDetails.Rows[i]["Class"].ToString(); if (AllAnalysisDetails.Rows[i]["Class"].ToString() == "") dr["Class"] = "Default"; else dr["Class"] = AllAnalysisDetails.Rows[i]["Class"].ToString(); dr["subdivision"] = AllAnalysisDetails.Rows[i]["Name"].ToString(); dr["Area"] = Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]); dr["inca_proportion"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / sumArea) * 100, 2); dr["inca_FieldRatio"] = Math.Round((Convert.ToDouble(AllAnalysisDetails.Rows[i]["Area"]) / Convert.ToDouble(str)) * 100, 4); AreaRatio.Rows.Add(dr); } 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]["Class"].ToString() == ClassName[i].ToString()) { dt.Rows.Add(AreaRatio.Rows[a].ItemArray); } } DataView dv = dt.DefaultView; dv.Sort = "Area 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); } } return AreaRatio_dt; } private bool ProportionOfParticleArea(DataTable dataTable, List ClassName, string str, out DataTable dt_out) { DataTable AllAnalysisDetails = dataTable.Copy(); AllAnalysisDetails.Clear(); AllAnalysisDetails.TableName = "InclusionAreaRatio"; for (int i = 0; i < ClassName.Count; i++) { DataTable dt = dataTable.Copy(); dt.Clear(); for (int a = 0; a < dataTable.Rows.Count; a++) { if (dataTable.Rows[a]["Class"].ToString() == ClassName[i].ToString()) { dt.Rows.Add(dataTable.Rows[a].ItemArray); } } if (dt.Rows.Count > 0) { double totalInclusionArea = Convert.ToDouble(decimal.Parse(dataTable.Compute("sum(Area)", "").ToString())); double Area = Convert.ToDouble(decimal.Parse(dt.Compute("sum(Area)", "").ToString())); DataRow dr = AllAnalysisDetails.NewRow(); dr["Class"] = ClassName[i].ToString(); dr["Area"] = Math.Round(Area, 2); //Convert.ToDouble(decimal.Parse(dt.Compute("sum(e3)", "").ToString())); dr["inca_proportion"] = Math.Round((Convert.ToDouble(Area) / totalInclusionArea) * 100, 2); dr["inca_FieldRatio"] = Math.Round((Convert.ToDouble(Area) / Convert.ToDouble(str)) * 100, 4); AllAnalysisDetails.Rows.Add(dr); DataView dv = dt.DefaultView; dv.Sort = "Area DESC"; DataTable dt_Area = dv.ToTable(); for (int a = 0; a < dt_Area.Rows.Count; a++) { dt_Area.Rows[a]["Class"] = ""; dt_Area.Rows[a]["Area"] = Math.Round(Convert.ToDouble(dt_Area.Rows[a]["Area"]), 2); AllAnalysisDetails.Rows.Add(dt_Area.Rows[a].ItemArray); } } } dt_out = AllAnalysisDetails.Copy(); return true; } private DataTable InvalidRemoval(DataTable dt) { DataTable dataTable = dt.Copy(); dataTable.Clear(); for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 10) { dataTable.Rows.Add(dt.Rows[i].ItemArray); } } return dataTable; } } }