Forráskód Böngészése

元素 批量存储数据

cxs 1 éve
szülő
commit
2f3e9d4e7b

+ 30 - 35
OTSIncAMeasureApp/1-OTSMeasure/Measure/DBDataTransition/ElementChemistryDB.cs

@@ -76,49 +76,46 @@ namespace OTSModelSharp.DTLBase
             return true;
         }
 
-
-        public bool SaveElementChemistriesList(List<CPosXrayClr> a_xrayPointList)
+        public bool SaveElementChemistriesList_Batch(List<CPosXrayClr> a_xrayPointList)
         {
-
-            var tableInfoPtr = GetTableInfo();
-
-            var datastorePtr = GetDatastore();
-
-            String sInsertFormat = tableInfoPtr.GetInsertCommandFormatString();
-            String sSQLCommand = "";
-
+            List<KeyValuePair<string, SQLiteParameter[]>> list = new List<KeyValuePair<string, SQLiteParameter[]>>();
             foreach (var xrayPointInfo in a_xrayPointList)
             {
                 List<CElementChemistryClr> listElemnentChemistries = xrayPointInfo.GetElementQuantifyData();
-
                 int nSize = (int)listElemnentChemistries.Count;
                 int nElementIndex = 0;
                 foreach (var pElementChemistry in listElemnentChemistries)
                 {
-                    sSQLCommand = String.Format(sInsertFormat,
-                    xrayPointInfo.GetIndex(),
-                    xrayPointInfo.GetScanFieldId(),
-                    nElementIndex,
-                    nSize,
-                    pElementChemistry.GetName(),
-                    pElementChemistry.GetPercentage());
-                    //var helper = new SQLiteHelper(datastorePtr);         
-                    if (datastorePtr.RunCommand(sSQLCommand) != true)
-                    {
-
-
-
-                        return false;
-                    }
-
-                    nElementIndex++;
+                    //INSERT INTO ElementChemistry(XRayId, FieldId, ElementId, ElementNum, Name, Percentage) VALUES({ 0:G},{ 1:G},{ 2:G},{ 3:G},"{4:G}",{ 5:G})
+                    string sSQLCommand = "INSERT INTO ElementChemistry(XRayId, FieldId, ElementId, ElementNum, Name, Percentage) VALUES(@XRayId,@FieldId,@ElementId,@ElementNum,@Name,@Percentage)";
+                    var paras = new SQLiteParameter[6];
+                    paras[0] = new SQLiteParameter("XRayId");
+                    paras[0].Value = xrayPointInfo.GetIndex();
+                    paras[1] = new SQLiteParameter("FieldId");
+                    paras[1].Value = xrayPointInfo.GetScanFieldId();
+                    paras[2] = new SQLiteParameter("ElementId");
+                    paras[2].Value = nElementIndex;
+                    paras[3] = new SQLiteParameter("ElementNum");
+                    paras[3].Value = nSize;
+                    paras[4] = new SQLiteParameter("Name");
+                    paras[4].Value = pElementChemistry.GetName();
+                    paras[5] = new SQLiteParameter("Percentage");
+                    paras[5].Value = pElementChemistry.GetPercentage();
+                    list.Add(new KeyValuePair<string, SQLiteParameter[]>(sSQLCommand, paras));
                 }
-
             }
-
-            return true;
+            var datastorePtr = GetDatastore();
+            try
+            {
+                datastorePtr.ExecuteNonQueryBatch(ref list);
+                return true;
+            }
+            catch (Exception e)
+            {
+                NLog.LogManager.GetCurrentClassLogger().Error(e.Message);
+                return false;
+            }
         }
-
         public bool SaveElementChemistriesList(CPosXrayClr a_pxrayPoint)
         {
 
@@ -184,12 +181,10 @@ namespace OTSModelSharp.DTLBase
                 paras[4].Value = pElementChemistry.GetName();
                 paras[5].Value = pElementChemistry.GetPercentage();
 
-
-
                 nElementIndex++;
                 cmds.Add(new KeyValuePair<string, SQLiteParameter[]>(sInsertFormat.Key, paras));
             }
-
+            
             return cmds;
         }
 

+ 2 - 4
OTSIncAReportApp/1-UI/frmMeasureRstMgr.cs

@@ -685,7 +685,7 @@ namespace OTSIncAReportApp
             {
                 ches.Add(part.GetXray());
             }
-            xraydb.SaveElementChemistriesList(ches);
+            xraydb.SaveElementChemistriesList_Batch(ches);
             return true;
         }
 
@@ -758,11 +758,9 @@ namespace OTSIncAReportApp
 
         List<COTSParticleClr> ZeroElementProcess(OTSCLRINTERFACE.COTSClassifyEngineClr ClassifyEngineClr, List<COTSParticleClr> allParticles)
         {
-            //List<COTSParticleClr> ParticleClrs = new List<COTSParticleClr>();
             foreach (COTSParticleClr particleClr in allParticles)
             {
                 ClassifyEngineClr.ZeroElementProcess(particleClr);
-                //ParticleClrs.Add(particleClr);
             }
             return allParticles;
         }
@@ -814,7 +812,7 @@ namespace OTSIncAReportApp
             xraydb.RemoveAllRows();
             try
             {
-                xraydb.SaveElementChemistriesList(ches);
+                xraydb.SaveElementChemistriesList_Batch(ches);
             }
             catch(Exception ex)
             {