浏览代码

颗粒列表优化改进2.2版--重构获取数据库结构,一次性调用所有颗粒数据库信息以减少数据库耗时的影响,进度条及其它一些尝试

CXS 3 年之前
父节点
当前提交
3be225b8fe
共有 1 个文件被更改,包括 50 次插入31 次删除
  1. 50 31
      OTSIncAReportApp/Control_Grids/ParticlesGridDevidePage.cs

+ 50 - 31
OTSIncAReportApp/Control_Grids/ParticlesGridDevidePage.cs

@@ -163,7 +163,7 @@ namespace OTSIncAReportGrids
             m_ReportApp = ReportApp;
             result = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult];
 
-            //设置窗体的双缓冲
+            //设置窗体的双缓冲,以保证大数据时拖动不卡
             this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
             this.UpdateStyles();
 
@@ -171,17 +171,15 @@ namespace OTSIncAReportGrids
 
             //利用反射设置DataGridView的双缓冲
             Type dgvType = this.dgV_ParticlesDevidePage.GetType();
-            PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",BindingFlags.Instance | BindingFlags.NonPublic);
+            PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
             pi.SetValue(this.dgV_ParticlesDevidePage, true, null);
 
-            m_frm_userprogress = new Frm_UserProgress();
-
-            m_mythread_state = false;
-            m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
-
             lan = new Language(this);
             table = lan.GetNameTable(this.Name);
 
+            m_mythread_state = false;
+            m_mythread = new Thread(new ParameterizedThreadStart(Thread_GO));
+            //m_frm_userprogress = new Frm_UserProgress();
             fieldData = new FieldData(result.FilePath);
             Particledata = new ParticleData(result.FilePath);
         }
@@ -190,19 +188,20 @@ namespace OTSIncAReportGrids
         {
             //初始化底层操作类
             m_OTSIncAReportGridsFun = new OTSIncAReportGridsFun(m_ReportApp, this);
+
+            ProgressStart();
+
             //多次测试发现 读取数据库时间耗时长,但读取条数目对读取数据库时长影响不大,故此处直接读取所有数据库信息,以取代多次连接数据库方式,优化分页速度
             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.SelectedIndex = 0;
-            //cbB_PageSize.SelectedIndexChanged += new System.EventHandler(this.cbB_PageSize_SelectedIndexChanged);
 
         }
 
@@ -363,25 +362,10 @@ namespace OTSIncAReportGrids
         {
             dgV_ParticlesDevidePage.Visible = false;
 
-            #region 加载显示进度条部份
-            this.Cursor = Cursors.WaitCursor;
-            m_frm_userprogress = new Frm_UserProgress();
-
-            //显示进度条,计算进度条应该显示的位置和宽度
-            Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
-            if (ls_main_form == null)
+            if (m_frm_userprogress.IsDisposed)
             {
-                m_frm_userprogress.Visible = false;
+                ProgressStart();
             }
-            else
-            {
-                string str7 = table["str7"].ToString();
-                m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
-                m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 80, ls_main_form.Location.Y + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
-                m_frm_userprogress.Show();
-                m_frm_userprogress.SetProgressValueAndText(0, str7);
-            }
-            #endregion
 
             dgV_ParticlesDevidePage.Rows.Clear();
             dgV_ParticlesDevidePage.Columns.Clear();
@@ -532,7 +516,6 @@ namespace OTSIncAReportGrids
             {
                 //更新进度,每100条记录加载完,更新一次进度
                 if (i % 10 == 0)
-                    
                     m_frm_userprogress.SetProgressValueAndText((int)(jd * i), "loading..");
 
                 Dictionary<string, string>.Enumerator enl = keyValues.GetEnumerator();
@@ -649,6 +632,16 @@ namespace OTSIncAReportGrids
                 }
             }
             
+            //for(int i=0;i< dgV_ParticlesDevidePage.Rows.Count;i++)
+            //{
+            //    for(int j= strs.Count()+5;j< dgV_ParticlesDevidePage.Columns.Count;j++)
+            //    {
+            //        if(dgV_ParticlesDevidePage.Rows[i].Cells[j].Value == null)
+            //        {
+            //            dgV_ParticlesDevidePage.Rows[i].Cells[j].Value = 0;
+            //        }
+            //    }
+            //}
 
             #region 加载进度条进度部份结束
             //加载完成设置鼠标为默认
@@ -675,9 +668,6 @@ namespace OTSIncAReportGrids
             //用户不能调整 行高
             dgV_ParticlesDevidePage.AllowUserToResizeRows = false;
 
-            //改变行的高度;
-            //Gview_gz.RowTemplate.Height = 20;
-
             //点击选择整行
             dgV_ParticlesDevidePage.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
 
@@ -1225,10 +1215,39 @@ namespace OTSIncAReportGrids
                 condition += " and TypeName Like \"%" + tbx_Type.Text + "%\" ";
             }
 
+            if (m_frm_userprogress.IsDisposed)
+            {
+                ProgressStart();
+            }
+            particlesAll = new DataTable();
+            particlesAll = Particledata.GetInfoForPartucleDevidePage2(condition);
+
             lnkFirst_Click(null, null);
             SetDataGridViewStyle();
         }
 
+        void ProgressStart()
+        {
+            #region 加载显示进度条部份
+            this.Cursor = Cursors.WaitCursor;
+            m_frm_userprogress = new Frm_UserProgress();
+
+            //显示进度条,计算进度条应该显示的位置和宽度
+            Form ls_main_form = this.ParentForm.ParentForm;//取出父窗体
+            if (ls_main_form == null)
+            {
+                m_frm_userprogress.Visible = false;
+            }
+            else
+            {
+                m_frm_userprogress.Width = (int)(MyPrimaryScreen.DESKTOP.Width / MyPrimaryScreen.ScaleX * 0.9);
+                m_frm_userprogress.Location = new Point(ls_main_form.Location.X + 200, ls_main_form.Location.Y + 200 + (int)(MyPrimaryScreen.DESKTOP.Height / MyPrimaryScreen.ScaleX) / 2);
+                m_frm_userprogress.Show();
+                m_frm_userprogress.SetProgressValueAndText(0, "Loading data of particles...");
+            }
+            #endregion
+        }
+
         private void cbB_order_SelectedIndexChanged(object sender, EventArgs e)
         {
             int ordernum = cbB_order.SelectedIndex;