| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- using OTSDataType;
- using OTSModelSharp.DTL;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace OTSModelSharp
- {
- public class CIncAFileMgr
- {
- // file pathname
- String m_strPathName;
- // particle list
- List<COTSParticle> m_listParticle = new List<COTSParticle>();
- // X-ray list
- List<CPosXray> m_listPosXray = new List<CPosXray>();
- //database
- CIncAFileMgr m_pIncADataDB;
- CSQLiteTable cSQLiteTable = new CSQLiteTable();
- CMergeParticleDB m_pMergePartDB = new CMergeParticleDB("", null);
- CSmallParticleInfoDB m_pSmallPartInfoDB;
- CSegmentDB m_pSegmentDB;
- IDBBase myDB;
- System.Drawing.Point m_FieldPos;
- CGenInfoDB m_generalInfoTable;
- CMsrSampleStatus msrStatus;
- CInformationDB mInformationDB;
- CIncADataDB m_IncADataDB;
- CSegmentDB m_SegmentDB;
-
- public CIncAFileMgr(String fileName)
- {
- // initialization
- m_strPathName = fileName;
- Init();
- var mergePartDB = this.GetMergedParticleDB();
- mergePartDB.Init();//judge if the table exist,if exist delete firstly,then creat,else creat.
- var smallPartDB = this.GetSmallParticleInfoDB();
- smallPartDB.Init();
- }
- // initialization
- public void Init()
- {
- // particle list
- m_listParticle.Clear();
- // X-ray list
- m_listPosXray.Clear();
- if (!CreateIncAFile())
- {
-
- }
- }
- public CSegmentDB GetSegmentDB()
- {
- if (m_pSegmentDB!=null)
- {
- var datastorePtr = GetDatastore();
- if (datastorePtr!=null)
- {
- m_pSegmentDB = datastorePtr;
- }
- }
- return m_pSegmentDB;
- }
- public CSegmentDB GetDatastore()
- {
- return m_pSegmentDB;
- }
- //Create
- public bool CreateIncAFile()
- {
- // check file name
- m_strPathName.Trim();
- if (m_strPathName=="")
- {
- // error, wrong file name
- return false;
- }
- // get database name
- String sDatabaseName = m_strPathName;
- if (Exists(sDatabaseName))
- {
- if (!Open(m_strPathName, false))
- {
- return false;
- }
- }
- else
- {
- if (!Create(m_strPathName,false))
- {
- return false;
- }
- }
- return true;
- }
- public bool Open(string a_sFileName, bool a_bForce /*= TRUE*/)
- {
- var datastorePtr = GetDatastore();
- return Open(a_sFileName, a_bForce);
- }
- // check if the file exists or not
- public bool Exists(string a_sPath)
- {
- return true;
- }
- public CSmallParticleInfoDB GetSmallParticleInfoDB()
- {
- if (m_pSmallPartInfoDB!=null)
- {
- var datastorePtr = GetDatastore();
-
- if (datastorePtr!=null)
- {
- m_pSmallPartInfoDB = new CSmallParticleInfoDB("", cSQLiteTable);
- }
- }
-
- return m_pSmallPartInfoDB;
- }
- //Get DB
- public CIncAFileMgr GetIncADB()
- {
- if (m_pIncADataDB!=null)
- {
- var datastorePtr = GetDatastore();
- if (datastorePtr!=null)
- {
- m_pIncADataDB = new CIncAFileMgr("");
- }
- }
-
- return m_pIncADataDB;
- }
- public CMergeParticleDB GetMergedParticleDB()
- {
- if (m_pMergePartDB!=null)
- {
- var datastorePtr = GetDatastore();
- if (datastorePtr!=null)
- {
- m_pMergePartDB = new CMergeParticleDB("", cSQLiteTable);
- }
- }
- return m_pMergePartDB;
- }
- public bool Create(string a_sFileName, bool a_bOverwrite /*= FALSE*/)
- {
- var datastorePtr = GetDatastore();
- if (Create(a_sFileName, a_bOverwrite))
- {
- return InitFile();
- }
- return false;
- }
- // particle list
- public List<COTSParticle> GetParticleList() { return m_listParticle; }
- public bool InitFile()
- {
- var generalInfoTable = GetGeneralInfoDB();
-
- if (generalInfoTable!=null)
- {
- return false;
- }
- // return generalInfoTable.Init();
- return false;
- }
- public CGenInfoDB GetGeneralInfoDB()
- {
- if (m_generalInfoTable!=null)
- {
- var datastorePtr = GetDatastore();
- if (datastorePtr!=null)
- {
- // m_generalInfoTable.reset(new CGenInfoDB("",datastorePtr));
- m_generalInfoTable.GetTableInfo();
- }
- }
- return m_generalInfoTable;
- }
- public void SetPosXrayList(List<CPosXray> a_listPosXray, bool a_bClear)
- {
- // clear holes list if necessary
- if (a_bClear)
- {
- m_listPosXray.Clear();
- }
- // copy the list
- foreach (var pPosXray in a_listPosXray)
- {
- m_listPosXray.Add(pPosXray);
- }
- }
- public void SetParticleList(List<COTSParticle> a_listParticle, bool a_bClear)
- {
- // clear holes list if necessary
- if (a_bClear)
- {
- m_listParticle.Clear();
- }
- // copy the list
- foreach (var pParticle in a_listParticle)
- {
- m_listParticle.Add(pParticle);
- }
- }
- public void SetFieldPos(System.Drawing.Point p) { m_FieldPos = p; }
- public void SetMsrStatus(CMsrSampleStatus s) { msrStatus = s; }
- public bool Save(String a_strPathName/* = _T("")*/)
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // check file pathname
- a_strPathName.Trim();
- if (a_strPathName == "")
- {
- // file open dialog
- OpenFileDialog openFileDialog = new OpenFileDialog();
- if (openFileDialog.ShowDialog() != DialogResult.OK)
- {
- return false;
- }
- // get file pathname
-
- a_strPathName = openFileDialog.FileName;
- }
- // file pathname
- m_strPathName = a_strPathName;
- /*if (!CreateIncAFile())
- {
- LogErrorTrace(__FILE__, __LINE__, _T("Create or open X-ray file failed."));
- return FALSE;
- }*/
- if (SaveIncAList())
- {
- return false;
- }
- // ok, return TRUE
- return true;
- }
- public bool SaveIncAList()
- {
- var IncADataDB = GetIncADB();
- SqlHelper cSQLiteStore = new SqlHelper(); //CSQLiteStore cSQLiteStore = new CSQLiteStore();
- cSQLiteStore.ExecuteNonQuery("PRAGMA synchronous = OFF; "); //cSQLiteStore.CloseSynchronous();
- cSQLiteStore.ExecuteNonQuery("begin transaction;"); //cSQLiteStore.BeginTransaction();
-
- m_generalInfoTable = GetGeneralInfoDB();
- mInformationDB.UpdateTimeStampRow(m_generalInfoTable.GetTableItemNameTimeEnd(), "");
-
- int sta = Convert.ToInt32(msrStatus);
- mInformationDB.UpdateIntegerRow(m_generalInfoTable.GetTableItemNameResultStatus(), sta,"");
- foreach (var pParticle in m_listParticle)
- {
- int nFieldId = pParticle.GetFieldId();
- int nXrayId = pParticle.GetAnalysisId();
- CPosXray pXrayPtr;
-
- bool IsChanged = false;
- for (int itr = 0; itr < m_listPosXray.Count; itr++)
- {
- if (m_listPosXray[itr].ToString() != "")
- {
- CPosXray PosXray = m_listPosXray[itr];
-
- m_listPosXray.RemoveAt(itr);
- IsChanged = true;
- }
- }
- if (!IsChanged)
- {
- return false;//m_listPosXray[itr];
- }
- else
- {
- pXrayPtr = new CPosXray();
- }
- //save x-ray data
-
- if (!m_IncADataDB.SaveAIncA(pParticle, pXrayPtr, m_FieldPos))
- {
- return false;
- }
- // save segment
- var SegmentDB = GetSegmentDB();
- if (!m_SegmentDB.SaveFeature(pParticle))
- {
- return false;
- }
- }
- IncADataDB.GetDatastore();
- return true;
- }
-
- }
- }
|