|
|
@@ -1,6 +1,9 @@
|
|
|
using OTSDataType;
|
|
|
+using OTSModelSharp.DTL;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Drawing;
|
|
|
+using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
@@ -29,51 +32,211 @@ namespace OTSModelSharp
|
|
|
|
|
|
int _CRTDBG_REPORT_FLAG = -1;
|
|
|
|
|
|
- //----------------public--------------------
|
|
|
+ const String SMPL_MSR_RESULT_FILE_EXT = ".rst";
|
|
|
+
|
|
|
+ // fields file sub-directory string
|
|
|
+ const String SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER = "FIELD_FILES";
|
|
|
+
|
|
|
+ public OTS_MSR_SAMPLE_STATUS m_nStatus;
|
|
|
+
|
|
|
+ CIncAFileMgr m_IncAFileMgr = new CIncAFileMgr("");
|
|
|
+ CIncADataDB m_IncADataDB = new CIncADataDB("",null);
|
|
|
+
|
|
|
+ CSQLiteDB m_generalInfoTable;
|
|
|
+
|
|
|
+ private string conStr;
|
|
|
+ //----------------public-----------------
|
|
|
public CSmplMsrResultFileMgr(string workingFolder)
|
|
|
{
|
|
|
m_strWorkingFolder = workingFolder;
|
|
|
m_listAnalysisXray.Clear();
|
|
|
}
|
|
|
- public bool Init(COTSSample a_pSample)
|
|
|
+ //public bool Init(COTSSample a_pSample)
|
|
|
+ //{
|
|
|
+ // if (a_pSample!=null )
|
|
|
+ // {
|
|
|
+ // // invalid sample pointer
|
|
|
+ // logger.Info("Init: failed to create the working directory.");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // // sample name
|
|
|
+ // string strSmplName = a_pSample.GetName();
|
|
|
+ // strSmplName.Trim();
|
|
|
+ // if (strSmplName==null)
|
|
|
+ // {
|
|
|
+ // // the sample name string can't be an empty string
|
|
|
+ // logger.Info(System.IO.Directory.GetCurrentDirectory(), "Init: the sample name string is an empty string.");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // // the working directory string can't be an empty string
|
|
|
+ // if (m_strWorkingFolder==null )
|
|
|
+ // {
|
|
|
+ // // the working directory is empty
|
|
|
+ // logger.Info("Init: the woring folder directory string is an empty string.");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // // check if the working directory is there
|
|
|
+ // //COTSEDSBase.Exists(m_strWorkingFolder);
|
|
|
+ // COTSEDSBase cOTSEDSBase = new COTSEDSBase();
|
|
|
+ // if (!cOTSEDSBase.Exists(m_strWorkingFolder))
|
|
|
+ // {
|
|
|
+ // // field files directory exists not exists, creates it
|
|
|
+ // COTSFileSys cOTSFileSys = new COTSFileSys();
|
|
|
+ // if (!cOTSFileSys.CreateFolder(m_strWorkingFolder))
|
|
|
+ // {
|
|
|
+ // // failed to create the field files directory
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // ok, return TRUE
|
|
|
+ // SetSample(a_pSample);
|
|
|
+ // return true;
|
|
|
+ //}
|
|
|
+
|
|
|
+ public bool Init(COTSSample a_pSample)
|
|
|
{
|
|
|
- if (a_pSample!=null )
|
|
|
- {
|
|
|
- // invalid sample pointer
|
|
|
- logger.Info("Init: failed to create the working directory.");
|
|
|
- return false;
|
|
|
- }
|
|
|
// sample name
|
|
|
- string strSmplName = a_pSample.GetName();
|
|
|
+ String strSmplName = a_pSample.GetName();
|
|
|
strSmplName.Trim();
|
|
|
- if (strSmplName==null)
|
|
|
+ if (strSmplName=="")
|
|
|
{
|
|
|
// the sample name string can't be an empty string
|
|
|
- logger.Info(System.IO.Directory.GetCurrentDirectory(), "Init: the sample name string is an empty string.");
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// the working directory string can't be an empty string
|
|
|
- if (m_strWorkingFolder==null )
|
|
|
+ if (m_strWorkingFolder=="")
|
|
|
{
|
|
|
// the working directory is empty
|
|
|
- logger.Info("Init: the woring folder directory string is an empty string.");
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// check if the working directory is there
|
|
|
- //COTSEDSBase.Exists(m_strWorkingFolder);
|
|
|
- COTSEDSBase cOTSEDSBase = new COTSEDSBase();
|
|
|
- if (!cOTSEDSBase.Exists(m_strWorkingFolder))
|
|
|
+ if (!Exists(m_strWorkingFolder))
|
|
|
+ {
|
|
|
+ // the working directory is not exit, create it
|
|
|
+ if (!CreateFolder(m_strWorkingFolder))
|
|
|
+ {
|
|
|
+ // failed to create the working directory
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // sample measure file pathname
|
|
|
+ String strPathname = m_strWorkingFolder + strSmplName + SMPL_MSR_RESULT_FILE_EXT;
|
|
|
+
|
|
|
+
|
|
|
+ // file not exists, creates it
|
|
|
+ if (!CreateFileMgr(strPathname))
|
|
|
+ {
|
|
|
+ // failed to create the file
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // get field files directory string
|
|
|
+ String strFieldFileSubFolder = GetFieldFileSubFolderStr();
|
|
|
+
|
|
|
+ // check if the field files directory exists
|
|
|
+ if (!Exists(strFieldFileSubFolder))
|
|
|
{
|
|
|
// field files directory exists not exists, creates it
|
|
|
- COTSFileSys cOTSFileSys = new COTSFileSys();
|
|
|
- if (!cOTSFileSys.CreateFolder(m_strWorkingFolder))
|
|
|
+ if (!CreateFolder(strFieldFileSubFolder))
|
|
|
{
|
|
|
// failed to create the field files directory
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- // ok, return TRUE
|
|
|
- SetSample(a_pSample);
|
|
|
+
|
|
|
+ // ok, return TRUE
|
|
|
+ SetSample(a_pSample);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // creates a folder.
|
|
|
+ public bool CreateFolder(string a_strFolder)
|
|
|
+ {
|
|
|
+ // make sure the folder name string are not empty
|
|
|
+ String strFolder = a_strFolder;
|
|
|
+ strFolder.Trim();
|
|
|
+ if (strFolder=="")
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // if the folder exist?
|
|
|
+ if (Exists(strFolder))
|
|
|
+ {
|
|
|
+ // is a real folder?
|
|
|
+ if (IsFolder(strFolder))
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // create folder
|
|
|
+
|
|
|
+ // remove back slash if there
|
|
|
+ String strParentFolder = strFolder;
|
|
|
+ strParentFolder.Trim();
|
|
|
+
|
|
|
+ // find last back slash position
|
|
|
+ int nBackSlashPos = strParentFolder.LastIndexOf('\\');
|
|
|
+ if (nBackSlashPos > 0)
|
|
|
+ {
|
|
|
+ // get the folder name
|
|
|
+ String strFolderName = strParentFolder.PadRight(strParentFolder.Length- nBackSlashPos - 1);
|
|
|
+
|
|
|
+ // separate the folder string
|
|
|
+ strParentFolder = strParentFolder.PadLeft(nBackSlashPos);
|
|
|
+ if (!IsValidFileName(strFolderName))
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // try to create folder from the base folder
|
|
|
+ if (!CreateFolder(strParentFolder))
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // create the folder
|
|
|
+
|
|
|
+ Directory.CreateDirectory(strFolder);
|
|
|
+
|
|
|
+ // return folder create result
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // check if the given string is valid file name or not
|
|
|
+ public bool IsValidFileName(string a_sFileName)
|
|
|
+ {
|
|
|
+ String strFileName = a_sFileName;
|
|
|
+ const String INVALIDFILENAMECHAR="\\/:*?\"<>";
|
|
|
+
|
|
|
+ return strFileName.FindOneOf(INVALIDFILENAMECHAR) == -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ // check if this is an existing folder
|
|
|
+ public bool IsFolder(string a_strFolder)
|
|
|
+ {
|
|
|
+
|
|
|
+ return Directory.Exists(a_strFolder);
|
|
|
+ }
|
|
|
+
|
|
|
+ // check if the file exists or not
|
|
|
+ public bool Exists(string a_sPath)
|
|
|
+ {
|
|
|
+ Directory.Exists(a_sPath);
|
|
|
return true;
|
|
|
}
|
|
|
// Load
|
|
|
@@ -136,46 +299,119 @@ namespace OTSModelSharp
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
- public bool Load(string a_strPathname)
|
|
|
+ //public bool Load(string a_strPathname)
|
|
|
+ //{
|
|
|
+
|
|
|
+ // // get path of the pathname
|
|
|
+ // COTSHelper cOTSHelper = new COTSHelper();
|
|
|
+ // string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
|
|
|
+ // if (strFilePath==null)
|
|
|
+ // {
|
|
|
+ // // file path string is an empty string
|
|
|
+ // logger.Info("Load: file path string is an empty string.");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // // field file sub folder string
|
|
|
+ // CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
|
|
|
+ // string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
|
|
|
+ // // check if the field file sub folder exists
|
|
|
+ // COTSEDSBase cOTSFileSys = new COTSEDSBase();
|
|
|
+ // if (!cOTSFileSys.Exists(strFieldFileSubFolder))
|
|
|
+ // {
|
|
|
+ // // field files folder doesn't exist
|
|
|
+ // logger.Info("Load: field files folder doesn't exist (%s).");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // SetWorkingFolderStr(strFieldFileSubFolder);
|
|
|
+ // // create sample measure result file
|
|
|
+ // CSmplMsrResultFile pSmplMsrResultFile = new CSmplMsrResultFile();
|
|
|
+ // XmlDocument xmlDoc = new XmlDocument();
|
|
|
+ // xmlDoc.LoadXml(a_strPathname);
|
|
|
+ // XmlNode root = xmlDoc.SelectSingleNode("XMLData");
|
|
|
+ // pSmplMsrResultFile.Serialize(false, xmlDoc, root);
|
|
|
+
|
|
|
+ // // file version
|
|
|
+ // CSmplMsrResultFile cSmplMsrResult = new CSmplMsrResultFile();
|
|
|
+ // string strFileVersion = cSmplMsrResult.GetFileVersion();
|
|
|
+ // COTSHelper OTSHelper = new COTSHelper();
|
|
|
+ // System.UInt32 nFileVersion = OTSHelper.GetVersionFromString(strFileVersion);
|
|
|
+ // if (nFileVersion==0)
|
|
|
+ // {
|
|
|
+ // // invalid file
|
|
|
+ // logger.Info("Load: invalid sample measure result file %s");
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // // sample measure result file
|
|
|
+ // m_pSmplMsrResultFile = pSmplMsrResultFile;
|
|
|
+ // SetPathName(a_strPathname);
|
|
|
+ // this.LoadFieldDataFromDB(a_strPathname);
|
|
|
+ // // ok, return TRUE
|
|
|
+ // return true;
|
|
|
+ //}
|
|
|
+
|
|
|
+ // Load
|
|
|
+ public bool Load(String a_strPathname /*= _T("")*/)
|
|
|
{
|
|
|
-
|
|
|
+ int tmpFlag = _CRTDBG_REPORT_FLAG;
|
|
|
+ //tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
|
|
+ // _CrtSetDbgFlag(tmpFlag);
|
|
|
+
|
|
|
+ //_CrtSetBreakAlloc(7415416);
|
|
|
+ // AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
|
+
|
|
|
+ // check the pathname string
|
|
|
+ a_strPathname.Trim();
|
|
|
+ if (a_strPathname=="")
|
|
|
+ {
|
|
|
+ // open
|
|
|
+ //CFileDialog dlg(TRUE, SMPL_MSR_RESULT_FILE_EXT, NULL, OFN_FILEMUSTEXIST, SMPL_MSR_RESULT_FILE_FILTER);
|
|
|
+ //if (dlg.DoModal() != IDOK)
|
|
|
+ //{
|
|
|
+ // // user canceled loading
|
|
|
+
|
|
|
+ // return false;
|
|
|
+ //}
|
|
|
+
|
|
|
+ FolderBrowserDialog FileDialog = new FolderBrowserDialog();//创建一个文件对话框
|
|
|
+ if (FileDialog.ShowDialog() != DialogResult.OK)
|
|
|
+ {
|
|
|
+ // user canceled loading
|
|
|
+ logger.Info("Load: user canceled loading.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ a_strPathname = GetPathName();
|
|
|
+ }
|
|
|
+
|
|
|
// get path of the pathname
|
|
|
- COTSHelper cOTSHelper = new COTSHelper();
|
|
|
- string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
|
|
|
- if (strFilePath==null)
|
|
|
+ String strFilePath = GetFolderName(a_strPathname);
|
|
|
+ if (strFilePath=="")
|
|
|
{
|
|
|
// file path string is an empty string
|
|
|
- logger.Info("Load: file path string is an empty string.");
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
// field file sub folder string
|
|
|
- CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
|
|
|
- string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
|
|
|
+ String strFieldFileSubFolder = strFilePath + "\\" + SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
|
|
|
+
|
|
|
// check if the field file sub folder exists
|
|
|
- COTSEDSBase cOTSFileSys = new COTSEDSBase();
|
|
|
- if (!cOTSFileSys.Exists(strFieldFileSubFolder))
|
|
|
+ if (!Exists(strFieldFileSubFolder))
|
|
|
{
|
|
|
// field files folder doesn't exist
|
|
|
- logger.Info("Load: field files folder doesn't exist (%s).");
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
SetWorkingFolderStr(strFieldFileSubFolder);
|
|
|
// create sample measure result file
|
|
|
CSmplMsrResultFile pSmplMsrResultFile = new CSmplMsrResultFile();
|
|
|
- XmlDocument xmlDoc = new XmlDocument();
|
|
|
- xmlDoc.LoadXml(a_strPathname);
|
|
|
- XmlNode root = xmlDoc.SelectSingleNode("XMLData");
|
|
|
- pSmplMsrResultFile.Serialize(false, xmlDoc, root);
|
|
|
|
|
|
// file version
|
|
|
- CSmplMsrResultFile cSmplMsrResult = new CSmplMsrResultFile();
|
|
|
- string strFileVersion = cSmplMsrResult.GetFileVersion();
|
|
|
- COTSHelper OTSHelper = new COTSHelper();
|
|
|
- System.UInt32 nFileVersion = OTSHelper.GetVersionFromString(strFileVersion);
|
|
|
- if (nFileVersion==0)
|
|
|
- {
|
|
|
- // invalid file
|
|
|
- logger.Info("Load: invalid sample measure result file %s");
|
|
|
+ String strFileVersion = pSmplMsrResultFile.GetFileVersion();
|
|
|
+ uint nFileVersion = GetVersionFromString(strFileVersion);
|
|
|
+ if (nFileVersion == 0)
|
|
|
+ {// invalid file
|
|
|
+
|
|
|
return false;
|
|
|
}
|
|
|
// sample measure result file
|
|
|
@@ -185,6 +421,228 @@ namespace OTSModelSharp
|
|
|
// ok, return TRUE
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ // Get file versio
|
|
|
+ // File Version should be format <Major version>.<Minor version>.<Build version>, like 1.2.3
|
|
|
+ public uint GetVersionFromString(string a_sVersion)
|
|
|
+ {
|
|
|
+ int nMajorVersion = 0;
|
|
|
+ int nMinorVersion = 0;
|
|
|
+ int nBuildVersion = 0;
|
|
|
+
|
|
|
+ uint nVersion = 0;
|
|
|
+ if (GetMajorVersionFromString(a_sVersion, nMajorVersion) &&
|
|
|
+ GetMinorVersionFromString(a_sVersion, nMinorVersion) &&
|
|
|
+ GetBuildVersionFromString(a_sVersion, nBuildVersion))
|
|
|
+ {
|
|
|
+ nVersion = (uint)nMajorVersion * 10000 + (uint)nMinorVersion * 100 + (uint)nBuildVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ return nVersion;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool GetMinorVersionFromString(string a_sVersion, int a_nVersion)
|
|
|
+ {
|
|
|
+ // version string
|
|
|
+ String strVersion=a_sVersion;
|
|
|
+
|
|
|
+ // get major file version string position first
|
|
|
+ int nPosFirst = strVersion.IndexOf('.');
|
|
|
+ if (nPosFirst < 0)
|
|
|
+ {
|
|
|
+ // failed to find major file version string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get minor file version string position
|
|
|
+ int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
|
|
|
+ int nStrLength = nPosSecond - nPosFirst - 1;
|
|
|
+ if (nStrLength <= 0)
|
|
|
+ {
|
|
|
+ // failed to find minor file version string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get minor file version string
|
|
|
+ String strMinorVersion = strVersion.Remove(nPosFirst + 1, nStrLength);
|
|
|
+
|
|
|
+
|
|
|
+ // the minor file version string can't be empty
|
|
|
+ strMinorVersion.Trim();
|
|
|
+ if (strMinorVersion=="")
|
|
|
+ {
|
|
|
+ // failed to find minor file version string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // convert the minor version string to minor version number
|
|
|
+ if (!StringToInt(strMinorVersion, a_nVersion))
|
|
|
+ {
|
|
|
+ // failed to convert the major file version string to number
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ok, return TRUE
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool GetMajorVersionFromString(string a_sVersion, int a_nVersion)
|
|
|
+ {
|
|
|
+ // version string
|
|
|
+ String strVersion=a_sVersion;
|
|
|
+
|
|
|
+ // get major file version string position
|
|
|
+ int nPosFirst = strVersion.IndexOf('.');
|
|
|
+ if (nPosFirst <= 0)
|
|
|
+ {
|
|
|
+ // failed to find major file version
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get major file version string
|
|
|
+ String strMajorVersion = strVersion.PadLeft(nPosFirst);
|
|
|
+
|
|
|
+ // the major file version string can't be empty
|
|
|
+ strMajorVersion.Trim();
|
|
|
+ if (strMajorVersion=="")
|
|
|
+ {
|
|
|
+ // failed to find major file version
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // convert the major version string to major version number
|
|
|
+ if (!StringToInt(strMajorVersion, a_nVersion))
|
|
|
+ {
|
|
|
+ // failed to convert the major file version string to number
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ok, return TRUE
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool GetBuildVersionFromString(string a_sVersion, int a_nBuild)
|
|
|
+ {
|
|
|
+ // version string
|
|
|
+ String strVersion=a_sVersion;
|
|
|
+
|
|
|
+ // get major file version string position first
|
|
|
+ int nPosFirst = strVersion.IndexOf('.');
|
|
|
+ if (nPosFirst < 0)
|
|
|
+ {
|
|
|
+ // failed to find major file version string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get minor file version string position
|
|
|
+ int nPosSecond = strVersion.IndexOf('.', nPosFirst + 1);
|
|
|
+
|
|
|
+ if (nPosSecond < 0)
|
|
|
+ {
|
|
|
+ // failed to find minor file version string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get build string position
|
|
|
+ int nStrLength = strVersion.Length - nPosSecond - 1;
|
|
|
+ if (nStrLength <= 0)
|
|
|
+ {
|
|
|
+ // failed to find build string
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // get build string
|
|
|
+ String strBuild = strVersion.PadRight(nStrLength);
|
|
|
+
|
|
|
+ // build string can't be empty
|
|
|
+ strBuild.Trim();
|
|
|
+ if (strBuild=="")
|
|
|
+ {
|
|
|
+ // failed to convert the build string to number
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // convert the build string to build number
|
|
|
+ if (!StringToInt(strBuild, a_nBuild))
|
|
|
+ {
|
|
|
+ // failed to convert the build string to number
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ok, return TRUE
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Strings to int.
|
|
|
+ public bool StringToInt(string a_sValue, int a_nValue)
|
|
|
+ {
|
|
|
+ if (!IsDigitString(a_sValue))
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ a_nValue = Convert.ToInt32(a_sValue);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Determines whether is digit string.
|
|
|
+ public bool IsDigitString(string a_sValue)
|
|
|
+ {
|
|
|
+ String strInt = a_sValue;
|
|
|
+ strInt.Trim();
|
|
|
+
|
|
|
+ if (strInt=="")
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ int nStart = 0;
|
|
|
+
|
|
|
+ if (strInt[nStart] == '-')
|
|
|
+ {
|
|
|
+ ++nStart;
|
|
|
+ }
|
|
|
+
|
|
|
+ // cycle through string and check each character if it is a digit
|
|
|
+ for (; nStart < strInt.Length; ++nStart)
|
|
|
+ {
|
|
|
+ if (strInt[nStart] !='-' )
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // gets the name of the folder
|
|
|
+ public String GetFolderName(String a_strPathName)
|
|
|
+ {
|
|
|
+ string str = "";
|
|
|
+ char[] sPath = new char[COTSModelConst.MAX_PATH];
|
|
|
+ str.CopyTo(0, sPath, 0, Convert.ToInt32(a_strPathName));
|
|
|
+
|
|
|
+ return sPath.ToString();
|
|
|
+ }
|
|
|
+
|
|
|
public bool LoadFieldDataFromDB(string a_strPathname)
|
|
|
{
|
|
|
// check the pathname string
|
|
|
@@ -202,8 +660,8 @@ namespace OTSModelSharp
|
|
|
a_strPathname = FileDialog.SelectedPath;
|
|
|
}
|
|
|
// get path of the pathname
|
|
|
- COTSHelper cOTSHelper = new COTSHelper();
|
|
|
- string strFilePath = cOTSHelper.GetFolderName(a_strPathname);
|
|
|
+ // COTSHelper cOTSHelper = new COTSHelper();
|
|
|
+ string strFilePath = GetFolderName(a_strPathname);
|
|
|
if (strFilePath==null)
|
|
|
{
|
|
|
// file path string is an empty string
|
|
|
@@ -214,8 +672,8 @@ namespace OTSModelSharp
|
|
|
CSmplMsrResultFile cSmplMsrResultFile = new CSmplMsrResultFile();
|
|
|
string strFieldFileSubFolder = strFilePath + "\\" + cSmplMsrResultFile.SMPL_MSR_RESULT_FIELDS_FILE_SUBFOLDER + "\\";
|
|
|
// check if the field file sub folder exists
|
|
|
- COTSEDSBase cOTSFileSys = new COTSEDSBase();
|
|
|
- if (!cOTSFileSys.Exists(strFieldFileSubFolder))
|
|
|
+ // COTSEDSBase cOTSFileSys = new COTSEDSBase();
|
|
|
+ if (!Exists(strFieldFileSubFolder))
|
|
|
{// field files folder doesn't exist
|
|
|
logger.Info("Load: field files folder doesn't exist (%s).");
|
|
|
return false;
|
|
|
@@ -243,8 +701,147 @@ namespace OTSModelSharp
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- // Save
|
|
|
- public bool Save(string a_strPathname )
|
|
|
+
|
|
|
+ public bool GetAllFieldsFromDB(List<COTSFieldData> allFlds, CMsrSampleStatus status, CMsrResults rst, double aFieldArea)
|
|
|
+ {
|
|
|
+ String sDatabaseName = GetPathName();
|
|
|
+
|
|
|
+ if (Exists(sDatabaseName))
|
|
|
+ {
|
|
|
+ if (!Open(m_strPathName,false))
|
|
|
+ {
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Point> completedfld = new List<Point>();
|
|
|
+ var IncADataDB = m_IncAFileMgr.GetIncADB();
|
|
|
+
|
|
|
+ m_IncADataDB.GetAllFieldsRecord(ref allFlds);
|
|
|
+ var SegmentDB = m_IncAFileMgr.GetSegmentDB();
|
|
|
+ double msrFldsArea = 0;
|
|
|
+
|
|
|
+ // std::map<int, COTSParticleList> mapTypeParticles;//record typeId relevants particlelist;
|
|
|
+ Dictionary<int, List<COTSParticle>> mapTypeParticles = new Dictionary<int, List<COTSParticle>>();
|
|
|
+ // std::map<std::vector<int>, COTSSegmentsList> AllSegments;
|
|
|
+ Dictionary<List<int>, List<COTSParticle>> AllSegments = new Dictionary<List<int>, List<COTSParticle>>();
|
|
|
+ if (SegmentDB.GetAllSegmentsRecord(AllSegments))
|
|
|
+ {
|
|
|
+ int nCol;
|
|
|
+ foreach(var fld in allFlds)
|
|
|
+
|
|
|
+ {
|
|
|
+ int fldId = fld.GetId();
|
|
|
+ List<COTSParticle> parts = fld.GetParticleList();
|
|
|
+ foreach(var part in parts)
|
|
|
+
|
|
|
+ {
|
|
|
+ List<int> fldvec = new List<int>();
|
|
|
+ fldvec.Add(fldId);
|
|
|
+ fldvec.Add(part.GetTagId());
|
|
|
+
|
|
|
+ var itr = AllSegments.Values;
|
|
|
+
|
|
|
+ if (itr != AllSegments.Last)
|
|
|
+ {
|
|
|
+ COTSFeature f = new COTSFeature();
|
|
|
+ f.SetSegmentsList(itr.second);
|
|
|
+ part.SetFeature(f);
|
|
|
+ }
|
|
|
+ mapTypeParticles[part.GetType()].Add(part);
|
|
|
+ }
|
|
|
+ completedfld.Add(fld.GetPosition());
|
|
|
+ msrFldsArea += aFieldArea;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // get MsrStatus info from DB.
|
|
|
+ var GenDB = GetGeneralInfoDB();
|
|
|
+ String strTimeStart = "";
|
|
|
+ String strTimeEnd = "";
|
|
|
+ String strRstStatus = "";
|
|
|
+ GenDB.GetStringValue(GetTableItemNameTimeStart(), strTimeStart);
|
|
|
+ GenDB.GetStringValue(GetTableItemNameTimeEnd(), strTimeEnd);
|
|
|
+ GenDB.GetStringValue(GetTableItemNameResultStatus(), strRstStatus);
|
|
|
+ status.SetCompletedFieldsCenter(completedfld);
|
|
|
+ status.SetCompletedFields(completedfld.Count);
|
|
|
+ DateTime timeStart, timeEnd;
|
|
|
+ TimeSpan timeSpan;
|
|
|
+ timeStart = GetDateTimeFromString(strTimeStart);
|
|
|
+ timeEnd = GetDateTimeFromString(strTimeEnd);
|
|
|
+ status.SetStartTime(timeStart);
|
|
|
+ status.SetEndTime(timeEnd);
|
|
|
+ status.SetUsedTime(timeEnd - timeStart);
|
|
|
+ status.SetStatus(m_nStatus);
|
|
|
+ //get MsrResults data from map.
|
|
|
+ List<CMsrResultItem> rstItms = new List<CMsrResultItem>();
|
|
|
+ double allPartArea = 0;
|
|
|
+ foreach (var typeParticles in mapTypeParticles)
|
|
|
+ {
|
|
|
+ CMsrResultItem rstItm = new CMsrResultItem();
|
|
|
+ int typeNum = 0;
|
|
|
+ double typeArea = 0;
|
|
|
+ foreach (var p in mapTypeParticles)
|
|
|
+ {
|
|
|
+ typeNum += 1;
|
|
|
+ typeArea += Convert.ToInt32(p);
|
|
|
+ }
|
|
|
+ rstItm.SetTypeId(Convert.ToInt32(typeParticles));
|
|
|
+ rstItm.SetNumber((uint)typeNum);
|
|
|
+ rstItm.SetArea((uint)typeArea);
|
|
|
+ rstItms.Add(rstItm);
|
|
|
+ allPartArea += typeArea;
|
|
|
+ }
|
|
|
+ rst.SetResultItems(rstItms);
|
|
|
+ rst.SetMeasuredArea((uint)msrFldsArea * 1000000);
|
|
|
+ rst.SetRadio(allPartArea / (msrFldsArea * 1000000));
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public String GetTableItemNameTimeStart()
|
|
|
+ {
|
|
|
+ return COTSModelConst.g_sTableItemNameTimeStart;
|
|
|
+ }
|
|
|
+ public String GetTableItemNameTimeEnd()
|
|
|
+ {
|
|
|
+ return COTSModelConst.g_sTableItemNameTimeEnd;
|
|
|
+ }
|
|
|
+ public String GetTableItemNameResultStatus()
|
|
|
+ {
|
|
|
+ return COTSModelConst.g_sTableItemNameResultStatus;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CSQLiteDB GetGeneralInfoDB()
|
|
|
+ {
|
|
|
+ if (m_generalInfoTable != null)
|
|
|
+ {
|
|
|
+ var datastorePtr = GetDatastore();
|
|
|
+
|
|
|
+ if (datastorePtr != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ m_generalInfoTable.GetDatastore();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return m_generalInfoTable;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public string GetDatastore()
|
|
|
+ {
|
|
|
+ return conStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ public DateTime GetDateTimeFromString( String a_DateTime)
|
|
|
+ {
|
|
|
+ DateTime ole_time = new DateTime();
|
|
|
+ DateTime.Now.ToString();
|
|
|
+ return ole_time;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Save
|
|
|
+ public bool Save(string a_strPathname )
|
|
|
{
|
|
|
// safety check
|
|
|
if (m_pSmplMsrResultFile==null)
|