using OTSCLRINTERFACE; using OTSIncAReportApp.DataOperation.DataAccess; using OTSIncAReportApp.OTSSampleReportInfo; using OTSIncAReportApp.SysMgrTools; using OTSIncAReportGraph.OTSIncAReportGraphFuncation; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Windows.Forms; using OTSCommon.DBOperate.Model; namespace OTSIncAReportApp.OTSRstMgrFunction { /// /// 框架与底层进行交互的操作类 /// public class ResultDataMgr { #region 变量定义 /// /// 报告主进程框架对象 /// public CReportMgrClr m_ReportMgr; private List resultFilesList = new List(); //测量结果列表 private int workingResultId = -1; public RptConfigFile m_RptConfigFile = RptConfigFile.GetRptConfig(); //报表程序的配置文件 #endregion private ResultFile m_curResultFile; public int GetWorkingResultId() { return workingResultId; } public void SetWorkingResultId(int value) { if (resultFilesList.Count > 0) { workingResultId = value; m_curResultFile = resultFilesList[value]; } } public ResultFile GetResultFileObjByName(string rstName) { ResultFile rst = null; foreach (var r in resultFilesList) { if (r.FileName_real == rstName) { rst = r; } } return rst; } public List ResultFilesList { get => resultFilesList; set => resultFilesList = value; } public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; } #region 构造函数 /// /// 构造函数 /// /// public ResultDataMgr() { if (null == m_ReportMgr) { //初始化相关变量 m_ReportMgr = new CReportMgrClr(); } } public bool AddDataResult(string str_path) { //加载测量结果文件 Dictionary suggestions = DataOperation.DataAccess.XMLoperate.GetXMLAllInfo(str_path); string name = System.IO.Path.GetFileName(str_path); int workingid = ResultFilesList.Count + 1; string path = System.IO.Path.GetDirectoryName(str_path); if (ResultFilesList.Find(s => s.FilePath == path) != null) { MessageBox.Show("Already have the same result!"); return false; } string strname = UpdateName(name, ResultFilesList); if (strname == "") { MessageBox.Show("Already have the same result!"); return false; } ResultFile result = new ResultFile() { FileId = workingid.ToString(), anotherFileName = strname, FileName_real=name, FilePath = path, }; result.SetResultInfoDic(suggestions); ResultFilesList.Add(result); SetWorkingResultId(ResultFilesList.IndexOf(result)); FieldData fieldData = new FieldData(path); List fieldlist = fieldData.GetFieldList(); CurResultFile.List_OTSField = fieldlist; return true; } public void RemoveDataResult(string fileName) { ResultFile rst=null; foreach (var r in resultFilesList) { if (r.FileName_real == fileName) { rst = r; } } if (rst != null) { resultFilesList.Remove(rst); workingResultId = 0; } else { workingResultId =-1; } } private string UpdateName(string name, List ResultFilesList) { int reg = 51; if (ResultFilesList.Find(s => s.anotherFileName == name) != null) { for (int i = 1; i < reg; i++) { string str = name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString(); if (ResultFilesList.Find(s => s.anotherFileName == str) == null) { return name.Split('.')[0].ToString() + "(" + i.ToString() + ")" + name.Split('.')[1].ToString(); } } } else { return name; } return ""; } #endregion #region 获取组合项相关方法 /// /// 根据系统设置的默认粒级表路径,获取所有的粒级表文件List /// /// public List GetPartSizeFileList() { List ret_list = new List(); //遍历粒级文件夹 DirectoryInfo theFolder = new DirectoryInfo(m_RptConfigFile.PartSizeFileFolder); if (!theFolder.Exists) return ret_list; //读取遍历粒级文件信息 foreach (FileInfo nextifile in theFolder.GetFiles()) { //找出粒级文件 if (nextifile.Name.Contains(".psf") == true || nextifile.Name.Contains(".PSF") == true) { ret_list.Add(nextifile.Name); } } return ret_list; } public List GetSTDIdList() { HashSet stdSet = new HashSet(); stdSet.Add("All"); foreach (var f in CurResultFile.List_OTSField) { foreach (var p in f.ParticleList) { if (!stdSet.Contains(p.TypeName)) { stdSet.Add(p.TypeName); } } } return stdSet.ToList(); } /// /// 根据系统设置默认的粒级表的路径,获取粒级表List /// /// /// public List GetPartSizeList() { DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(m_RptConfigFile.PartSizeFileFolder + m_RptConfigFile.PartSizeFile); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); List sizeList = new List(); 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]); sizeList.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); sizeList.Add(d.ToString() + "~MAX"); return sizeList; } /// /// 根据传入的粒级表目录,获取粒级表List /// /// public List GetPartSizeList(string path) { DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(path); string sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString(); List sizeList = new List(); 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]); sizeList.Add(d1.ToString() + "~" + d2.ToString()); } } double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]); sizeList.Add(d.ToString() + "~MAX"); return sizeList; } /// /// 获取三元相图模板名称列表 /// /// public List GetTriTemplateNameList() { string pathtpf = m_RptConfigFile.TrigTemplateFileFolder + m_RptConfigFile.TriTempFile; List ret_list = new List(); DataSet ds = DataOperation.DataAccess.XMLoperate.GetXmlData(pathtpf, "XMLData"); DataTable dt = ds.Tables["Member"]; foreach (DataRow item in dt.Rows) { if (item["TemplateName"].ToString() != "") { ret_list.Add(item["TemplateName"].ToString()); } } return ret_list; } /// /// 获取测量结果名称列表 /// /// public string GetDefaultPartSize() { DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile); string sizestr = ds.Tables[1].Rows[3]["name"].ToString(); return sizestr; } public string GetDefaultTRIO_CHART_TYPE() { DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile); string sizestr = ds.Tables[1].Rows[4]["strValue"].ToString(); return sizestr; } public string GetDefaultSIZE_CAL_METHOD_TYPE() { DataSet ds = DataOperation.DataAccess.XMLoperate.GetXml(Application.StartupPath + m_RptConfigFile.ReportMgrParamFile); string sizestr = ds.Tables[1].Rows[5]["strValue"].ToString(); return sizestr; } /// /// 获取计算方法列表 /// /// public List GetSizeCalMethodTypeList() { List ret_list = new List() { "DMAX", "DMIN", "FERET", "ECD" }; return ret_list; } public List ParticleRange() { List pr_str = new List() { "全部颗粒","选择颗粒" }; return pr_str; } public List getTableData() { List strlist = new List() { "Area", "DMAX", "Hardness", "AveGray" }; return strlist; } public List getTableData_INCA() { List strlist = new List() { "Area", "DMAX", "AveGray" }; return strlist; } public List getTableData_CleannessA() { List strlist = new List() { "Area", "DMAX", "Hardness", "AveGray" }; return strlist; } #endregion #region [测量结果treeview]相关封装方法 /// /// 获取测量结果treeview树测量结果名 /// /// public string GetSampleName() { //获取样品名 String sWorkSampleName = ResultFilesList[GetWorkingResultId()].anotherFileName; if (null == sWorkSampleName) { return ""; } return sWorkSampleName; } #endregion } }