Bläddra i källkod

颗粒列表优化改进2.1版--重构获取数据库结构,一次性调用所有颗粒数据库信息以减少数据库耗时的影响,加快分页速度

CXS 3 år sedan
förälder
incheckning
e7a0d33c33

+ 26 - 38
OTSIncAReportApp/Control_Grids/ParticlesGridDevidePage.cs

@@ -78,8 +78,8 @@ namespace OTSIncAReportGrids
 
 
         FieldData fieldData;
-
-        private string m_filename = "";
+        DataTable particlesAll;
+        ParticleData Particledata;
 
         #region 分页器相关
 
@@ -183,42 +183,26 @@ namespace OTSIncAReportGrids
             table = lan.GetNameTable(this.Name);
 
             fieldData = new FieldData(result.FilePath);
+            Particledata = new ParticleData(result.FilePath);
         }
 
         private void ParticlesGridDevidePage_Load(object sender, EventArgs e)
         {
             //初始化底层操作类
             m_OTSIncAReportGridsFun = new OTSIncAReportGridsFun(m_ReportApp, this);
-
-            if (Language.ReadDefaultLanguage() == "EN")
-            {
-                cbB_order.Items.Add("Default");
-                cbB_order.Items.Add("ParticlesName");
-                cbB_order.Items.Add("Dmax Ascend");
-                cbB_order.Items.Add("Dmax Descend");
-                cbB_order.Items.Add("Area Ascend");
-                cbB_order.Items.Add("Area Descend");
-            }
-            else
-            {
-                cbB_order.Items.Add("默认");
-                cbB_order.Items.Add("颗粒名称");
-                cbB_order.Items.Add("最大直径 升序");
-                cbB_order.Items.Add("最大直径 降序");
-                cbB_order.Items.Add("面积 升序");
-                cbB_order.Items.Add("面积 降序");
-            }
-            cbB_order.SelectedIndex = 0;
-
+            //多次测试发现 读取数据库时间耗时长,但读取条数目对读取数据库时长影响不大,故此处直接读取所有数据库信息,以取代多次连接数据库方式,优化分页速度
+            particlesAll = new DataTable();
+            particlesAll = Particledata.GetInfoForPartucleDevidePage2(condition);
+            
             cbB_PageSize.Items.Add("20");
             cbB_PageSize.Items.Add("100");
             cbB_PageSize.Items.Add("500");
             cbB_PageSize.Items.Add("1000");
             cbB_PageSize.Items.Add("5000");
             cbB_PageSize.Items.Add("All");
-            cbB_PageSize.SelectedIndexChanged -= new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
+            //cbB_PageSize.SelectedIndexChanged -= new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
             cbB_PageSize.SelectedIndex = 0;
-            cbB_PageSize.SelectedIndexChanged += new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
+            //cbB_PageSize.SelectedIndexChanged += new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
 
         }
 
@@ -514,19 +498,25 @@ namespace OTSIncAReportGrids
 
                 }
             }
-
-            ParticleData fielddata = new ParticleData(result.FilePath);
-            DataTable particles = fielddata.GetInfoForPartucleDevidePage(PageIndex, pageSize, OrderFunction, condition);
             if(PageSize==-1)
             {
-                PageSize = particles.Rows.Count;
+                PageSize = particlesAll.Rows.Count;
             }
 
-            if (particles == null)
+            if (particlesAll == null)
             {
                 return;
             }
-
+            RecordCount = particlesAll.Rows.Count;
+            DataTable particles = particlesAll.Clone();
+            for (int fi = (PageIndex - 1) * pageSize; fi < PageIndex * pageSize; fi++)
+            {
+                if (fi > RecordCount - 1)
+                {
+                    break;
+                }
+                particles.ImportRow(particlesAll.Rows[fi]);
+            }
             string particleM = "";
             //获取需要显示的元素名
             List<string> ElementTypeSort = new List<string>(str_ElementsColName.Split(',').ToList());//去重
@@ -538,9 +528,6 @@ namespace OTSIncAReportGrids
 
             string filePath = result.FilePath + "\\FIELD_FILES\\";
             KeyValuePair<string, Bitmap> FieldImage = new KeyValuePair<string, Bitmap>();
-
-            RecordCount = fielddata.GetCountOfParticles(condition) + fielddata.GetCountOfMergedParticles(condition); //此值= 合成拼接颗粒的所有子颗粒数目-拼接颗粒数目 , 颗粒总数 = 所有子颗粒数目 - 合成拼接颗粒的所有子颗粒数目 + 拼接颗粒数目;
-
             for (int i = 0; i < particles.Rows.Count; i++)
             {
                 //更新进度,每100条记录加载完,更新一次进度
@@ -570,12 +557,12 @@ namespace OTSIncAReportGrids
                                 string filePatht = result.FilePath + "\\FIELD_FILES\\";
                                 string imagePatht = filePatht + "Field" + subt.Split(',')[0].Split(':')[0].ToString() + ".bmp";
                                 //然后将取出的数据,转换成Bitmap对象
-                                Bitmap tempbit = fielddata.ReadImageFile(imagePatht);
+                                Bitmap tempbit = Particledata.ReadImageFile(imagePatht);
                                 int pixw = tempbit.Width;
                                 double xs = pixw / ScanFieldSize;
 
                                 particleM = particleM + "," + subt;
-                                Bitmap bmap = fielddata.GetBitmapForBig(subt, xs, result.FilePath);
+                                Bitmap bmap = Particledata.GetBitmapForBig(subt, xs, result.FilePath);
                                 if (bmap != null)
                                 {
                                     string[] str = subt.Split(',');
@@ -597,11 +584,11 @@ namespace OTSIncAReportGrids
                                 if (FieldImage.Key != particles.Rows[i]["fieldid"].ToString() || FieldImage.Value == null)
                                 {
                                     string imagePath = filePath + "Field" + particles.Rows[i]["fieldid"].ToString() + ".bmp";
-                                    FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), fielddata.ReadImageFile(imagePath));
+                                    FieldImage = new KeyValuePair<string, Bitmap>(particles.Rows[i]["fieldid"].ToString(), Particledata.ReadImageFile(imagePath));
                                 }
 
                                 Rectangle rectangle = new Rectangle() { X = Convert.ToInt32(particles.Rows[i]["RectLeft"]), Y = Convert.ToInt32(particles.Rows[i]["RectTop"]), Width = Convert.ToInt32(particles.Rows[i]["RectWidth"]), Height = Convert.ToInt32(particles.Rows[i]["RectHeight"]) };
-                                Bitmap bmap = fielddata.GetBitmapByParticle(FieldImage.Value, rectangle);
+                                Bitmap bmap = Particledata.GetBitmapByParticle(FieldImage.Value, rectangle);
                                 bmap.Tag = new List<string>() { particles.Rows[i]["FieldId"].ToString(), particles.Rows[i]["ParticleId"].ToString(), particles.Rows[i]["TypeId"].ToString() };
                                 dgV_ParticlesDevidePage.Rows[add_rowindex].Cells[k].Value = bmap;
                                 dgV_ParticlesDevidePage.Rows[add_rowindex].Height = bmap.Height + 20;
@@ -1382,6 +1369,7 @@ namespace OTSIncAReportGrids
                 pageSize = int.Parse(cbB_PageSize.SelectedItem.ToString());
             }
             lnkFirst_Click(null, null);
+            SetDataGridViewStyle();
         }
 
         /// <summary>

+ 8 - 16
OTSIncAReportApp/DataOperation/DataAccess/ParticleData.cs

@@ -421,23 +421,15 @@ namespace OTSIncAReportApp.DataOperation.DataAccess
             string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,ElementNum,SegmentNum,FieldPosX as 'SEMPosX',FieldPosY as 'SEMPosY',ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles, (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,ElementNum,SegmentNum,FieldPosX,FieldPosY,ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,(select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = INcAData.XRayId and fieldid = INcAData.fieldid  ) as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " + condition + " order by " + OrderFunction + " limit " + pagesize.ToString() + " offset " + p.ToString();
             //SQLiteTransaction tr = dbHelper.BeginTranscation();
             DataTable DT=new DataTable();
-            DT = dbHelper.ExecuteQuery2(sqliteString);
-            //try
-            //{
-            //    DT = dbHelper.ExecuteQuery(sqliteString);
-            //    dbHelper.TranscationCommit(tr);
-            //}
-            //catch (Exception ee)
-            //{
-            //    //回滚
-            //    dbHelper.TranscationRollback(tr);
-            //}
-            //finally
-            //{
-
-            //    dbHelper.CloseConnection();
-            //}
+            DT = dbHelper.ExecuteQuery(sqliteString);
+            return DT;
+        }
 
+        public DataTable GetInfoForPartucleDevidePage2(string condition)
+        {
+            string sqliteString = "select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,ElementNum,SegmentNum,FieldPosX as 'SEMPosX',FieldPosY as 'SEMPosY',ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,SubParticles, (select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = MergedParticleInfo.XRayId and fieldid = MergedParticleInfo.fieldid) as Element from MergedParticleInfo where 1=1 " + condition + " union select fieldid,particleid,AveGray,RectLeft,RectTop,RectWidth,RectHeight,Area,PosX,PosY,TypeId,ElementNum,SegmentNum,FieldPosX,FieldPosY,ParticleId,DMAX,DMIN,DPERP,PERIMETER,ORIENTATION,DINSCR,DMEAN,DELONG,DFERET,TypeName,TypeColor,'' as SubParticles,(select group_concat(name || '-' || Percentage, ';') from ElementChemistry where XRayId = INcAData.XRayId and fieldid = INcAData.fieldid  ) as Element from INcAData where xrayid > -1 and instr(','||(select ifnull(group_concat(SubParticles, ','),'') from MergedParticleInfo)|| ',',',' || fieldid || ':' || particleid || ',')= 0 " + condition;
+            DataTable DT = new DataTable();
+            DT = dbHelper.ExecuteQuery(sqliteString);
             return DT;
         }