| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using OTSCLRINTERFACE;
- using OTSIncAReportApp.DataOperation.DataAccess;
- using System;
- using System.Collections.Generic;
- using System.Windows.Forms;
- using OTSCommon.DBOperate.Model;
- namespace OTSIncAReportApp.OTSRstMgrFunction
- {
- /// <summary>
- /// 框架与底层进行交互的操作类
- /// </summary>
- public class ResultDataMgr
- {
- #region 变量定义
- /// <summary>
- /// 报告主进程框架对象
- /// </summary>
- public CReportMgrClr m_ReportMgr;
- private List<ResultFile> resultFilesList = new List<ResultFile>(); //测量结果列表
- 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<ResultFile> ResultFilesList { get => resultFilesList; set => resultFilesList = value; }
- public ResultFile CurResultFile { get => m_curResultFile; set => m_curResultFile = value; }
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="ReportApp"></param>
- public ResultDataMgr()
- {
- if (null == m_ReportMgr)
- {
- m_ReportMgr = new CReportMgrClr();
- }
- }
- public bool AddDataResult(string str_path)
- {
- //加载测量结果文件
- Dictionary<string, object> 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<Field> fieldlist = fieldData.GetFieldList();
- CurResultFile.SetList_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<ResultFile> 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
- public string GetSampleName()
- {
- String sWorkSampleName = ResultFilesList[GetWorkingResultId()].anotherFileName;
- if (null == sWorkSampleName)
- {
- return "";
- }
- return sWorkSampleName;
- }
- }
- }
|