123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- using OTSDataType;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading.Tasks;
- using OTSModelSharp.DTLBase;
- using OTSModelSharp.ServiceInterface;
- using OTSCOMMONCLR;
- namespace OTSModelSharp
- {
- public class CPosXrayDBMgr
- {
- protected static NLog.Logger logger = null;
- bool m_bHasElement;
- List<CPosXrayClr> m_listPosXray;
- //database
- CXRayDataDB m_pXrayDataDB;
- CElementChemistryDB m_pElementChemistryDB;
- CPosXrayInfoDB m_pXrayInfoDB;
-
- const long GENERALXRAYCHANNELS = 2000;
-
- private CSQLiteDBStore m_dbStore;
-
- public CPosXrayDBMgr(CSQLiteDBStore a_dbStore)
- {
-
- m_dbStore = a_dbStore;
- m_listPosXray = new List<CPosXrayClr>();
- logger = NLog.LogManager.GetCurrentClassLogger();
- }
- public void InitDataTable()
- {
- m_pXrayDataDB = new CXRayDataDB(m_dbStore, new CXRayDataTable());
- m_pXrayDataDB.Init();
- m_pElementChemistryDB = new CElementChemistryDB(m_dbStore, new CElementChemistryTable());
- m_pElementChemistryDB.Init();
- m_pXrayInfoDB = new CPosXrayInfoDB(m_dbStore, new CPosXrayInfoTable());
- m_pXrayInfoDB.Init();
-
-
- }
- //// Load/Save
- //public bool Load(int fldId, bool a_bClear)
- //{
- // // clear all data if necessary
- // if (a_bClear)
- // {
- // m_listPosXray.Clear();
- // }
- // if (!GetXrayList(fldId))
- // {
- // return false;
- // }
- // // ok, return TRUE
- // return true;
- //}
- //x-ray
- public List<CPosXrayClr> GetPosXrayList() { return m_listPosXray; }
- public void SetHasElement(bool a_bHasElement) { m_bHasElement = a_bHasElement; }
- public CElementChemistryDB GetElementChemistryDB()
- {
- if (m_pElementChemistryDB == null)
- {
- m_pElementChemistryDB = new CElementChemistryDB(m_dbStore, new CElementChemistryTable());
- }
- return m_pElementChemistryDB;
- }
- //protected
- //protected bool GetXrayList(int fldId)
- //{
- // //get x-ray info list
- // List<CPosXrayClr> listInfo = new List<CPosXrayClr>();
- // //listInfo.Clear();
- // if (!GetXrayInfoList(ref listInfo, fldId))
- // {
- // logger.Error("GetXrayList: get x-ray info failed.");
- // return false;
- // }
- // if (listInfo == null)
- // {
- // return false;
- // }
- // foreach (CPosXrayClr pInfo in listInfo)
- // {
- // //get x-ray data
- // CPosXrayClr pXray = new CPosXrayClr();
- // pXray.SetIndex(Convert.ToInt32(pInfo.GetIndex()));
- // pXray.SetPartTagId(Convert.ToInt32(pInfo.GetPartTagId()));
- // pXray.SetPosition(pInfo.GetPosition());
- // pXray.SetScanFieldId(Convert.ToInt32(pInfo.GetScanFieldId()));
- // pXray.SetFeatureId(Convert.ToInt32(pInfo.GetFeatureId()));
- // long a_nXrayId = pInfo.GetIndex();
- // long a_nFieldId = pInfo.GetScanFieldId();
- // if (!GetXrayData(a_nXrayId, a_nFieldId, pXray))
- // {
- // logger.Error("GetXrayList: get x-ray data failed.");
-
- // return false;
- // }
- // //get element list
- // if (m_bHasElement)
- // {
- // long nElementSize = pInfo.GetElementNum();
- // if (nElementSize == 0)
- // {
- // m_listPosXray.Add(pXray);
- // continue;
- // }
- // List<CElementChemistryClr> listElementChemistry = new List<CElementChemistryClr>();
- // if (!GetElementChemistry(a_nXrayId, a_nFieldId, nElementSize, ref listElementChemistry))
- // {
- // logger.Error("GetXrayList: get x-ray data failed.");
-
- // return false;
- // }
- // pXray.SetElementQuantifyData(listElementChemistry);
- // }
- // m_listPosXray.Add(pXray);
- // }
- // return true;
- //}
- public bool SaveXray(List<CPosXrayClr> a_listPosXray,bool m_bHasElement)
- {
- if (a_listPosXray != null)
- {
-
- CElementChemistryDB XElementChemistryDB = GetElementChemistryDB();
- m_dbStore.CloseSynchronous();
- m_dbStore.BeginTransaction();
- m_listPosXray = a_listPosXray;
- //save info list
- SaveXrayInfoList();
- foreach (CPosXrayClr pPosXray in a_listPosXray)
- {
- if (!SavePosXrayPtr(pPosXray))
- {
- logger.Error("Failed to save x-ray data.");
-
- return false;
- }
- //save element
- if (m_bHasElement)
- {
- if (!XElementChemistryDB.SaveElementChemistriesList(pPosXray))
- {
- logger.Error("Failed to save element chemistry list data.");
- return false;
- }
- }
- }
-
- m_dbStore.CommitTransaction();
- }
- return true;
- }
- public bool SavePosXrayPtr(CPosXrayClr a_pXray)
- {
- var tableInfoPtr =m_pXrayDataDB. GetTableInfo();
- var datastorePtr = m_pXrayDataDB.GetDatastore();
- String sInsertFormat = tableInfoPtr.GetInsertCommandFormatString(true);
-
- UInt32[] xrayData = a_pXray.GetXrayData();
- String sSQLCommand = string.Format(sInsertFormat,
- a_pXray.GetIndex(),
- a_pXray.GetScanFieldId()
- );
- byte[] bytedata = new byte[GENERALXRAYCHANNELS * 4];
-
- for (int j = 0; j < GENERALXRAYCHANNELS; j++)
- {
- uint m = xrayData[j];
- byte[] dwordData = BitConverter.GetBytes(m);
- bytedata[j * 4] = dwordData[0];
- bytedata[j * 4 + 1] = dwordData[1];
- bytedata[j * 4 + 2] = dwordData[2];
- bytedata[j * 4 + 3] = dwordData[3];
-
- }
- if (!datastorePtr.InsertBlobData(sSQLCommand, bytedata, Convert.ToInt32(otsdataconst.GENERALXRAYCHANNELS) * 4))
- {
- string.Format(a_pXray.GetIndex().ToString(),
- a_pXray.GetScanFieldId(),
- 0,
- sSQLCommand);
- return false;
- }
- return true;
- }
-
-
- protected bool SaveXrayInfoList()
- {
- var XrayInfoDB = GetXrayInfoDB();
- //List<CPosXray> m_listPosXray;
- //m_listPosXray
- if (!XrayInfoDB.SaveXrayInfoList(m_listPosXray))
- {
- logger.Error("Failed to save xray info list.");
-
- return false;
- }
- return true;
- }
-
- protected bool GetXrayInfoList(ref List<CPosXrayClr> a_listXra, int fldId)
- {
- var XrayInfoDB = GetXrayInfoDB();
- if (XrayInfoDB==null)
- {
- logger.Error("Failed to open result setting table");
-
- return false;
- }
- a_listXra = XrayInfoDB.GetXrayInfoListByFieldId(fldId);
- return true;
- }
- //protected bool GetXrayData( long a_nXrayId, long a_nFieldId, CPosXrayClr a_pPosXray)
- //{
- // if (a_pPosXray==null)
- // {
- // logger.Error("Invalid x-ray point.");
- // return false;
- // }
- // CXRayDataDB XrayDataDB = GetXrayDataDB();
- // if (XrayDataDB==null)
- // {
- // logger.Error("Failed to open result setting table");
- // return false;
- // }
- // CPosXrayClr pPosXray = XrayDataDB.GetXRayDataById(a_nXrayId, a_nFieldId);
- // a_pPosXray.SetXrayData(pPosXray.GetXrayData());
- // return true;
- //}
- //protected bool GetElementChemistry( long a_nXrayId, long a_nFieldId, long a_nElementSize,ref List<CElementChemistryClr> a_listElementChemistry)
- //{
- // CElementChemistryDB XElementChemistryDB = GetElementChemistryDB();
- // if (XElementChemistryDB==null)
- // {
- // logger.Error("Failed to open result setting table");
- // return false;
- // }
- // a_listElementChemistry.Clear();
- // a_listElementChemistry = XElementChemistryDB.GetElementChemistryListById(a_nXrayId, a_nFieldId, a_nElementSize);
- // return true;
- //}
- //Get DB
- public CXRayDataDB GetXrayDataDB()
- {
- if (m_pXrayDataDB==null)
- {
-
- m_pXrayDataDB = new CXRayDataDB(m_dbStore, new CXRayDataTable());
-
- }
- return m_pXrayDataDB;
- }
- public CPosXrayInfoDB GetXrayInfoDB()
- {
- if (m_pXrayInfoDB==null)
- {
- m_pXrayInfoDB = new CPosXrayInfoDB(m_dbStore,new CPosXrayInfoTable());
- }
- return m_pXrayInfoDB;
- }
- // cleanup
- protected void Cleanup()
- {
- // need to do nothing at the moment
- m_listPosXray.Clear();
- }
-
- // duplication
- protected void Duplicate( CPosXrayDBMgr a_oSource)
- {
- // initialization
- m_listPosXray.Clear();
- // copy data over
- foreach(CPosXrayClr pPosXray in a_oSource.m_listPosXray)
- //for (auto pPosXray : a_oSource.m_listPosXray)
- {
- CPosXrayClr pPosXrayNew = new CPosXrayClr(pPosXray);
- m_listPosXray.Add(pPosXrayNew);
- }
- }
- }
-
- }
|