123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- 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 OTSCLRINTERFACE;
- using System.Data.SQLite;
- 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();
-
-
- }
-
- 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
-
- public bool SaveXray(List<CPosXrayClr> a_listPosXray,bool m_bHasElement)
- {
- if (a_listPosXray != null)
- {
-
- CElementChemistryDB XElementChemistryDB = GetElementChemistryDB();
- var XrayInfoDB = GetXrayInfoDB();
- var cmds = XrayInfoDB.GetSavingXrayInfoCmds(a_listPosXray);
-
- foreach (CPosXrayClr pPosXray in a_listPosXray)
- {
-
- var cmd = GetSavingPosXrayDataCmds(pPosXray);
- cmds.Add(cmd);
- //save element
- if (m_bHasElement)
- {
-
- var cmds1 = XElementChemistryDB.GetSavingElementChemistriesCmds(pPosXray);
- cmds.AddRange(cmds1);
- }
- }
- m_dbStore.ExecuteNonQueryBatch(ref cmds);
-
- }
- return true;
- }
- public List<KeyValuePair<string, SQLiteParameter[]>> GetSavingXrayCmds(List<CPosXrayClr> a_listPosXray, bool m_bHasElement)
- {
- List<KeyValuePair<string, SQLiteParameter[]>> cmds = new List<KeyValuePair<string, SQLiteParameter[]>>();
- if (a_listPosXray != null)
- {
- CElementChemistryDB XElementChemistryDB = GetElementChemistryDB();
- var xrayInfoDB = GetXrayInfoDB();
- var xrayinfocmds =xrayInfoDB.GetSavingXrayInfoCmds (a_listPosXray);
-
- cmds.AddRange(xrayinfocmds);
- foreach (CPosXrayClr pPosXray in a_listPosXray)
- {
-
- var cmd= GetSavingPosXrayDataCmds(pPosXray);
- cmds.Add(cmd);
-
- if (m_bHasElement)
- {
-
- var cmdlist = XElementChemistryDB.GetSavingElementChemistriesCmds(pPosXray);
-
- cmds.AddRange(cmdlist);
- }
- }
-
- }
- return cmds;
- }
-
- 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))
- {
-
- return false;
- }
- return true;
- }
- private KeyValuePair<string,SQLiteParameter[]> GetSavingPosXrayDataCmds(CPosXrayClr a_pXray)
- {
- KeyValuePair<string, SQLiteParameter[]> cmd;
- List<SQLiteParameter> ps = new List<SQLiteParameter>();
- var tableInfoPtr = m_pXrayDataDB.GetTableInfo();
- var datastorePtr = m_pXrayDataDB.GetDatastore();
- var sInsertFormat = tableInfoPtr.GetInsertCommand(true);
- var parasTem = sInsertFormat.Value;
- var paras = new SQLiteParameter[3];
- for (int j = 0; j < 3; j++)
- {
- paras[j] = new SQLiteParameter(parasTem[j].ParameterName);
- }
- UInt32[] xrayData = a_pXray.GetXrayData();
- paras[0].Value = a_pXray.GetIndex();
- paras[1].Value = 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];
- }
- paras[2].Value = bytedata;
-
-
- cmd = new KeyValuePair<string, SQLiteParameter[]>(sInsertFormat.Key,paras);
-
- return cmd;
- }
- //protected bool SaveXrayInfoList(List<CPosXrayClr> a_listPosXray)
- //{
- // var XrayInfoDB = GetXrayInfoDB();
-
- // var cmds = XrayInfoDB.GetSavingXrayInfoCmds(a_listPosXray);
- // m_dbStore.ExecuteNonQueryBatch(ref cmds);
- // 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;
- }
-
- //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);
- //}
- }
- }
-
- }
|