using DevExpress.Office.Drawing; using NPOI.Util; using OTSCommon.DBOperate; using OTSIncAReportApp.DataOperation.DataAccess; using OTSIncAReportApp.OTSRstMgrFunction; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using static OTSDataType.otsdataconst; using static OTSIncAReportApp.OTSReport_Export; namespace OTSIncAReportApp._1_UI.OTSReportExport.DataIntegration { public class BasicData { ParticleData fielddata; private string SizeChart = ""; List colid = new List(); List colid_Below7 = new List(); List GroupInformation = new List(); private List BData = new List(); private List Measurements = new List();//测量结果数据列队 private DataTable AllClass = new DataTable(); private DataTable AllElement = new DataTable(); private bool IsShereAClassificationGroup = false; private ResultFile resfile; private string FilePath = ""; /// /// 获取粒级表 /// public void SetParticlesizeTable(OTSReport_Export m_otsreport_export) { colid_Below7.Clear(); //获取粒级表 string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile; DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1); SizeChart = ds.Tables[0].Rows[0]["Sizes"].ToString(); for (int i = 0; i < SizeChart.Split(',').Length; i++) { if (SizeChart.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(SizeChart.Split(',')[i]); //double d2 = Convert.ToDouble(SizeChart.Split(',')[i + 1]); colid.Add("≥"+ d1.ToString() /*+ "~" + d2.ToString()*/); } } for (int i = 0; i < SizeChart.Split(',').Length - 1; i++) { if (SizeChart.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(SizeChart.Split(',')[i]); double d2 = Convert.ToDouble(SizeChart.Split(',')[i + 1]); colid_Below7.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(SizeChart.Split(',')[SizeChart.Split(',').Length - 1]); colid_Below7.Add(d.ToString() + "~MAX"); //double d = Convert.ToDouble(SizeChart.Split(',')[SizeChart.Split(',').Length - 1]); //colid.Add(d.ToString() + "~MAX"); } /// /// 获取粒级表 /// /// public List GetParticlesizeTable() { if(colid.Count>7) { return colid; }else { return colid_Below7; } } public void SetDBData(c_TemplateClass m_mbszclass, OTSReport_Export m_otsreport_export, string ComputeMode) { DataTable m_bt_DBData = new DataTable(); ParticleData fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath); List colid = new List() { "TypeName", "ar", "TypeId", "Largest", "Class", "GroupId", "con" }; //获取粒级表 string path1 = m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_otsreport_export.m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile; DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); bool blBelow7 = false; if (sizestr.Split(',').Length>7) { for (int i = 0; i < sizestr.Split(',').Length; i++) { if (sizestr.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[i]); //double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]); colid.Add("≥" + d1.ToString() /*+ "~" + d2.ToString()*/); } } blBelow7 = true; } else { for (int i = 0; i < sizestr.Split(',').Length - 1; i++) { if (sizestr.Split(',')[i].Length > 0) { double d1 = Convert.ToDouble(sizestr.Split(',')[i]); double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]); colid.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); colid.Add(d.ToString() + "~MAX"); blBelow7 = false; } for (int i = 0; i < colid.Count; i++) { m_bt_DBData.Columns.Add(colid[i].ToString()); } DataTable dt = InvalidRemoval(fielddata.GetParticleListForParticlSize("area", "")); DataTable AreaInformationOfAllElements = InvalidRemoval(fielddata.GetAreaByAllIncA("")); DataTable dtp = InvalidRemoval(fielddata.GetParticleAll("")); string po = ComputeMode; switch (po) { case "DMAX": po = "DMAX"; break; case "DMIN": po = "DMIN"; break; case "ECD": po = "Area"; break; case "FERET": po = "DFERET"; break; } for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = m_bt_DBData.NewRow(); dr["TypeName"] = dt.Rows[i]["TypeName"].ToString(); dr["TypeId"] = dt.Rows[i]["TypeId"].ToString(); dr["con"] = dt.Rows[i]["con"].ToString(); dr["GroupId"] = dt.Rows[i]["GroupId"].ToString(); if (dt.Rows[i]["GroupName"].ToString() == "") dr["Class"] = "Default"; else dr["Class"] = dt.Rows[i]["GroupName"].ToString(); //continue; dr["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2); if(blBelow7) { for (int a = 7; a < colid.Count; a++) { string d1 = colid[a].Split('≥')[1]; string d2; if (a == colid.Count - 1) { d2 = "9999999999999"; } else { d2 = colid[a + 1].Split('≥')[1]; } DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString())); dr[colid[a]] = datas.Count(); } } else { for (int a = 7; a < colid.Count; a++) { string d1 = colid[a].Split('~')[0]; string d2 = colid[a].Split('~')[1]; if (d2 == "MAX") { d2 = "999"; } DataRow[] datas = dtp.Select(getWhere(d2, d1, po, dt.Rows[i]["TypeId"].ToString())); dr[colid[a]] = datas.Count(); } } for (int a = 0; a < AreaInformationOfAllElements.Rows.Count; a++) { if (dt.Rows[i]["TypeId"].ToString() == AreaInformationOfAllElements.Rows[a]["TypeId"].ToString()) { dr["ar"] = AreaInformationOfAllElements.Rows[a]["ar"]; } } m_bt_DBData.Rows.Add(dr); } //去除物质分类(非夹杂物分类) for (int a = 0; a < m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial.Count; a++) { for (int i = m_bt_DBData.Rows.Count - 1; i >= 0; i--) { if (m_bt_DBData.Rows[i]["TypeId"].ToString() == m_mbszclass.M_KLLBXX.list_str_kllb_DeleteClass_Serial[a].ToString()) { m_bt_DBData.Rows.RemoveAt(i); } } } GroupInformation = new List(); for (int i = 0; i < m_bt_DBData.Rows.Count; i++) { bool bl = false; for (int a = 0; a < GroupInformation.Count; a++) { if (GroupInformation[a] == m_bt_DBData.Rows[i]["Class"].ToString()) { bl = true; } } if (!bl) { GroupInformation.Add(m_bt_DBData.Rows[i]["Class"].ToString()); } } if (m_otsreport_export.m_ReportApp.m_RptConfigFile.Systype == OTS_SysType_ID.IncA) { Measurements = new List(); for (int i = 0; i < GroupInformation.Count; i++) { DataTable table = m_bt_DBData.Clone(); for (int a = 0; a < m_bt_DBData.Rows.Count; a++) { if (GroupInformation[i] == m_bt_DBData.Rows[a]["Class"].ToString()) { table.Rows.Add(m_bt_DBData.Rows[a].ItemArray); } } BData.Add(table); } //Measurements = BData.Copy(); for (int i = 0; i < GroupInformation.Count; i++) { DataTable table = dtp.Clone(); for (int a = 0; a < dtp.Rows.Count; a++) { if (GroupInformation[i] == dtp.Rows[a]["GroupName"].ToString()) { table.Rows.Add(dtp.Rows[a].ItemArray); } } Measurements.Add(table); } return; } #region 判断是否使用指定选择组和规则 bool bl1 = false; for (int i = 0; i < m_otsreport_export.m_mbszclass.RuleGroup.Rows.Count; i++) { if (m_otsreport_export.m_mbszclass.RuleGroup.Rows[i]["GroupId"].ToString() == "0") { bl1 = true; } } #endregion if (!bl1) { #region 筛选现有组 List strings = new List(); for (int i = 0; i < m_bt_DBData.Rows.Count; i++) { bool bl2 = false; for (int a = 0; a < strings.Count; a++) { if (m_bt_DBData.Rows[i]["GroupId"].ToString() == strings[a]) { bl2 = true; } } if (!bl2) { strings.Add(m_bt_DBData.Rows[i]["GroupId"].ToString()); } } #endregion List OutData = new List(); for (int i = 0; i < strings.Count(); i++) { DataTable data = m_bt_DBData.Clone(); for (int a = 0; a < m_bt_DBData.Rows.Count; a++) { if (strings[i] == m_bt_DBData.Rows[a]["GroupId"].ToString()) { data.Rows.Add(m_bt_DBData.Rows[a].ItemArray); } } OutData.Add(data); } BData = OutData.Copy(); Measurements = new List(); for (int i = 0; i < GroupInformation.Count; i++) { DataTable table = dtp.Clone(); for (int a = 0; a < dtp.Rows.Count; a++) { string strGroupId = "Default"; if (dtp.Rows[a]["GroupName"].ToString() != "") { strGroupId = dtp.Rows[a]["GroupName"].ToString(); } if (GroupInformation[i] == strGroupId) { table.Rows.Add(dtp.Rows[a].ItemArray); } } Measurements.Add(table); } return; } List SpecifyGroup = new List(); for (int i = 0; i < m_otsreport_export.m_mbszclass.List_data.Count; i++) { DataTable data= m_bt_DBData.Clone(); bool b3 = false; string str_class = ""; for (int a = 0; a < m_otsreport_export.m_mbszclass.RuleGroup.Rows.Count; a++) { if (m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["GroupId"].ToString() == m_otsreport_export.m_mbszclass.List_data[i].TableName) { if (m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["display"].ToString() == "1") { str_class = m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["GroupName"].ToString(); b3 = true; } } } data.TableName = m_otsreport_export.m_mbszclass.List_data[i].TableName; if (b3) { for (int a = 0; a < m_otsreport_export.m_mbszclass.List_data[i].Rows.Count; a++) { if (m_otsreport_export.m_mbszclass.List_data[i].Rows[a]["display"].ToString() == "1") { DataTable data1 = m_bt_DBData.Clone(); DataRow row = data.NewRow(); row["TypeName"] = m_otsreport_export.m_mbszclass.List_data[i].Rows[a]["StrName"]; row["ar"] = 0; row["TypeId"] = m_otsreport_export.m_mbszclass.List_data[i].Rows[a]["STDId"]; row["GroupId"] = m_otsreport_export.m_mbszclass.List_data[i].Rows[a]["GroupId"]; row["con"] = 0; row["Largest"] = 0; row["Class"] = str_class; for (int j = 7; j < data.Columns.Count; j++) { row[j] = 0; } bool b2 = false; for (int j = 0; j < m_bt_DBData.Rows.Count; j++) { if (m_otsreport_export.m_mbszclass.List_data[i].Rows[a]["STDId"].ToString() == m_bt_DBData.Rows[j]["TypeId"].ToString()) { data1.Rows.Add(m_bt_DBData.Rows[j].ItemArray); b2 = true; } } if (b2) { data.Rows.Add(data1.Rows[0].ItemArray); } else { data.Rows.Add(row); } } } } SpecifyGroup.Add(data); } BData = SpecifyGroup.Copy(); #region 测量结果颗粒组队列 List datas1 = new List(); List stringsa = fielddata.ObtainParticleCategory(m_otsreport_export, this); for (int i = 0; i < stringsa.Count; i++) { DataTable data = dtp.Clone(); for (int a = 0; a < dtp.Rows.Count; a++) { if (Convert.ToInt64(dtp.Rows[i]["TypeId"]) > 10) { string strGroupName = "Default"; if (dtp.Rows[a]["GroupName"].ToString() != "") { strGroupName = dtp.Rows[a]["GroupName"].ToString(); } if (stringsa[i].ToString() == strGroupName) { data.Rows.Add(dtp.Rows[a].ItemArray); } } } datas1.Add(data); } Measurements = new List(); for (int i = 0; i < m_otsreport_export.m_mbszclass.List_data.Count; i++) { bool b3 = false; string str_class = ""; for (int a = 0; a < m_otsreport_export.m_mbszclass.RuleGroup.Rows.Count; a++) { if (m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["GroupId"].ToString() == m_otsreport_export.m_mbszclass.List_data[i].TableName) { if (m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["display"].ToString() == "1") { str_class = m_otsreport_export.m_mbszclass.RuleGroup.Rows[a]["GroupName"].ToString(); b3 = true; } } } if (b3) { DataTable table = datas1[i].Clone(); for (int a = 0; a < datas1[i].Rows.Count; a++) { for (int b = 0; b < m_otsreport_export.m_mbszclass.List_data[i].Rows.Count; b++) { if (m_otsreport_export.m_mbszclass.List_data[i].Rows[b]["display"].ToString() == "1") { if (datas1[i].Rows[a]["TypeId"].ToString() == m_otsreport_export.m_mbszclass.List_data[i].Rows[b]["STDId"].ToString()) { table.Rows.Add(datas1[i].Rows[a].ItemArray); } } } } Measurements.Add(table); } } #endregion } /// /// 获取夹杂物组信息 /// /// public List GetGroupInformation() { return GroupInformation; } /// /// 获取读取数据库并过滤颗粒 /// /// public List GetDBData() { return BData; } /// /// 获取读取数据库并过滤颗粒 /// /// public List etDBData() { return BData; } public void SetAllClass() { AllClass = fielddata.GetAllClass(); } /// /// 获取全部大类 /// /// public DataTable GetAllClass() { return AllClass; } /// ///测量结果数据列队 /// /// public List GetMeasurements() { return Measurements; } /// /// 定义ParticleData类 /// public void newParticleData(OTSReport_Export m_otsreport_export) { fielddata = new ParticleData(m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath); } public ParticleData getParticleData() { return fielddata; } public void SetAllElement() { AllElement = fielddata.GetAllElement(); } /// /// 获取全部元素 /// /// public DataTable GetAllElement() { return AllElement; } /// /// 判断是否有大分类,有为true /// /// /// public void IsThereAMajorClassification(BasicData basicData, OTSReport_Export m_otsreport_export) { //List ClassName = ObtainParticleCategory(m_otsreport_export, basicData); List ClassName = new List(); for (int i = 0; i < BData.Count; i++) { if (BData[i].Rows.Count != 0) { ClassName.Add(i.ToString()); } } if (ClassName.Count < 2) { IsShereAClassificationGroup= false; } else { IsShereAClassificationGroup= true; } } public bool GetIsThereAMajorClassification() { return IsShereAClassificationGroup; } public void IsResultFilesList(OTSReport_Export m_otsreport_export) { resfile = m_otsreport_export.m_ReportApp.m_rstDataMgr.ResultFilesList[m_otsreport_export.m_ReportApp.m_rstDataMgr.GetWorkingResultId()]; } /// /// 获取标准库名称 /// /// public string GetResfile() { string str_libraryName = ""; bool endsWithDb = resfile.GetSTDName().EndsWith(".db", StringComparison.OrdinalIgnoreCase); if (endsWithDb) { str_libraryName = resfile.GetSTDName(); } else { str_libraryName = resfile.GetSTDName() + ".db"; } return str_libraryName; } public void IsFilePath(OTSReport_Export m_otsreport_export) { FilePath= m_otsreport_export.m_ReportApp.m_rstDataMgr.CurResultFile.FilePath; } /// /// 得到文件路径 /// /// public string GetFilePath() { return FilePath; } #region 内部函数 private string getWhere(string max, string min, string col, string partic) { if (col == "Area") { return col + ">=" + ((Convert.ToDouble(min) / 2) * (Convert.ToDouble(min) / 2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max) / 2) * (Convert.ToDouble(max) / 2) * Math.PI).ToString() + " and TypeId=" + partic; } else { return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic; } } 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; } #endregion } }