Browse Source

分页功能bug修复

lixiang 1 year ago
parent
commit
022b366a65

+ 116 - 100
Venus/Venus_MainPages/ViewModels/EventViewModel.cs

@@ -28,6 +28,8 @@ namespace Venus_MainPages.ViewModels
         private int m_CurrentPage=1;
 
         private int m_onePageCounts = 30;
+
+        private bool m_FirstFlag = true;
         #endregion
 
         #region 属性
@@ -199,12 +201,16 @@ namespace Venus_MainPages.ViewModels
 
         private void OnLoad(Object eventView)
         {
-            this.view = (EventView)eventView;
-            this.view.wfTimeFrom.Value = this.SearchBeginTime;
-            this.view.wfTimeTo.Value = this.SearchEndTime;
-            this.Preload();
-
-            this.view.pageControl.CurrentPageChanged += PageControl_CurrentPageChanged;
+            if (m_FirstFlag)
+            {
+                m_FirstFlag = false;
+                this.view = (EventView)eventView;
+                this.view.wfTimeFrom.Value = this.SearchBeginTime;
+                this.view.wfTimeTo.Value = this.SearchEndTime;
+                this.Preload();
+
+                this.view.pageControl.CurrentPageChanged += PageControl_CurrentPageChanged;
+            }        
         }
 
         private void PageControl_CurrentPageChanged(int currentPage)
@@ -311,133 +317,143 @@ namespace Venus_MainPages.ViewModels
         /// </summary>
         public void Search()
         {
+
             Task.Factory.StartNew(() =>
             {
-                try
+
+                this.view.Dispatcher.Invoke(() =>
                 {
-                    string test = $"SELECT COUNT(*) FROM \"event_data\" where \"occur_time\" >='{SearchBeginTime.ToString("yyyy/MM/dd HH:mm:ss")}' and \"occur_time\" <='{SearchEndTime.ToString("yyyyMMdd HHmmss")}';";
-                    Total = QueryDataClient.Instance.Service.GetDBEventAllCount(test);
+                    try
+                    {
 
-                    PageCount = (Total / m_onePageCounts) +1;
-                    
+                        this.SearchBeginTime = this.view.wfTimeFrom.Value;
+                        this.SearchEndTime = this.view.wfTimeTo.Value;
 
-                    SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
-                    this.SearchBeginTime = this.view.wfTimeFrom.Value;
-                    this.SearchEndTime = this.view.wfTimeTo.Value;
+                        string test = $"SELECT COUNT(*) FROM \"event_data\" where \"occur_time\" >='{SearchBeginTime.ToString("yyyy/MM/dd HH:mm:ss")}' and \"occur_time\" <='{SearchEndTime.ToString("yyyyMMdd HHmmss")}';";
+                        Total = QueryDataClient.Instance.Service.GetDBEventAllCount(test);
 
-                    string sqlEvent = "";
-                    string sqlOperationLog = "";
-                    string sql = "";
+                        PageCount = (Total / m_onePageCounts) + 1;
 
-                    if (SearchAlarmEvent || SearchWarningEvent || SearchInfoEvent)
-                    {
-                        sqlEvent = string.Format("SELECT \"event_id\", \"event_enum\", \"type\", \"occur_time\", \"level\",\"source\" , \"description\" FROM \"event_data\" where \"occur_time\" >='{0}' and \"occur_time\" <='{1}' ", SearchBeginTime.ToString("yyyyMMdd HHmmss"), SearchEndTime.ToString("yyyyMMdd HHmmss"));
-
-                        sqlEvent += GetSourceWhere();
 
-                        sqlEvent += " and (FALSE ";
-                        if (SearchAlarmEvent) sqlEvent += " OR \"level\"='Alarm' ";
-                        if (SearchWarningEvent) sqlEvent += " OR \"level\"='Warning' ";
-                        if (SearchInfoEvent) sqlEvent += " OR \"level\"='Information' ";
-                        sqlEvent += " ) ";
+                        SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
 
-                        if (!string.IsNullOrWhiteSpace(SelectedEvent) && SelectedEvent != "All") sqlEvent += string.Format(" and lower(\"event_enum\")='{0}' ", SelectedEvent.ToLower());
+                        this.view.pageControl.OnApplyTemplate();
 
-                        //if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlEvent += string.Format(" and lower(\"description\") like '%{0}%' ", SearchKeyWords.ToLower());
-                        if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlEvent += string.Format(" and lower(\"description\") like '%{0}%' or lower(\"type\") like '%{1}%'", SearchKeyWords.ToLower(), SearchKeyWords.ToLower());
-                    }
+                        string sqlEvent = "";
+                        string sqlOperationLog = "";
+                        string sql = "";
 
-                    if (SearchOpeLog)
-                    {
-                        //sqlOperationLog = string.Format(" SELECT \"UserName\" as \"Initiator\", 'UserOperation' as \"LogType\", \"Time\", \"ChamberId\" as \"TargetChamber\", \"Content\" as \"Description\" FROM \"OperationLog\" where \"Time\" >='{0}' and \"Time\" <='{1}' ", SearchBeginTime.ToString("yyyy/MM/dd HH:mm:ss"), SearchEndTime.ToString("yyyy/MM/dd HH:mm:ss"));
+                        if (SearchAlarmEvent || SearchWarningEvent || SearchInfoEvent)
+                        {
+                            sqlEvent = string.Format("SELECT \"event_id\", \"event_enum\", \"type\", \"occur_time\", \"level\",\"source\" , \"description\" FROM \"event_data\" where \"occur_time\" >='{0}' and \"occur_time\" <='{1}' ", SearchBeginTime.ToString("yyyyMMdd HHmmss"), SearchEndTime.ToString("yyyyMMdd HHmmss"));
 
-                        //if (!SearchPMA) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorA);
-                        //if (!SearchPMB) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorB);
-                        //if (!SearchPMC) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorC);
-                        //if (!SearchPMD) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorD);
-                        //if (!SearchSystem) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.System);                      
-                        //if (!SearchLL) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.Loadlock);
-                        //if (!SearchTM) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' and \"ChamberId\"<>'{1}' and \"ChamberId\"<>'{2}' ",
-                        //    ChamberSet.Loadlock, ChamberSet.Buffer1, ChamberSet.Cooldown);
-                        //if (!string.IsNullOrWhiteSpace(SelectedUser) && SelectedUser != "不限") sqlOperationLog += string.Format(" and lower(\"UserName\")='{0}' ", SelectedUser.ToLower());
+                            sqlEvent += GetSourceWhere();
 
-                        //if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlOperationLog += string.Format(" and lower(\"Content\") like '%{0}%' ", SearchKeyWords.ToLower());
-                    }
+                            sqlEvent += " and (FALSE ";
+                            if (SearchAlarmEvent) sqlEvent += " OR \"level\"='Alarm' ";
+                            if (SearchWarningEvent) sqlEvent += " OR \"level\"='Warning' ";
+                            if (SearchInfoEvent) sqlEvent += " OR \"level\"='Information' ";
+                            sqlEvent += " ) ";
 
-                    sql = sqlEvent;
+                            if (!string.IsNullOrWhiteSpace(SelectedEvent) && SelectedEvent != "All") sqlEvent += string.Format(" and lower(\"event_enum\")='{0}' ", SelectedEvent.ToLower());
 
-                    if (!string.IsNullOrEmpty(sqlOperationLog))
-                    {
-                        if (string.IsNullOrEmpty(sql))
-                        {
-                            sql = sqlOperationLog;
+                            //if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlEvent += string.Format(" and lower(\"description\") like '%{0}%' ", SearchKeyWords.ToLower());
+                            if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlEvent += string.Format(" and lower(\"description\") like '%{0}%' or lower(\"type\") like '%{1}%'", SearchKeyWords.ToLower(), SearchKeyWords.ToLower());
                         }
-                        else
+
+                        if (SearchOpeLog)
                         {
-                            sql += " UNION ALL " + sqlOperationLog;
+                            //sqlOperationLog = string.Format(" SELECT \"UserName\" as \"Initiator\", 'UserOperation' as \"LogType\", \"Time\", \"ChamberId\" as \"TargetChamber\", \"Content\" as \"Description\" FROM \"OperationLog\" where \"Time\" >='{0}' and \"Time\" <='{1}' ", SearchBeginTime.ToString("yyyy/MM/dd HH:mm:ss"), SearchEndTime.ToString("yyyy/MM/dd HH:mm:ss"));
+
+                            //if (!SearchPMA) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorA);
+                            //if (!SearchPMB) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorB);
+                            //if (!SearchPMC) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorC);
+                            //if (!SearchPMD) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.ReactorD);
+                            //if (!SearchSystem) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.System);                      
+                            //if (!SearchLL) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' ", ChamberSet.Loadlock);
+                            //if (!SearchTM) sqlOperationLog += string.Format(" and \"ChamberId\"<>'{0}' and \"ChamberId\"<>'{1}' and \"ChamberId\"<>'{2}' ",
+                            //    ChamberSet.Loadlock, ChamberSet.Buffer1, ChamberSet.Cooldown);
+                            //if (!string.IsNullOrWhiteSpace(SelectedUser) && SelectedUser != "不限") sqlOperationLog += string.Format(" and lower(\"UserName\")='{0}' ", SelectedUser.ToLower());
+
+                            //if (!string.IsNullOrWhiteSpace(SearchKeyWords)) sqlOperationLog += string.Format(" and lower(\"Content\") like '%{0}%' ", SearchKeyWords.ToLower());
                         }
-                    }
 
-                    
-                    if (!string.IsNullOrEmpty(sql) && QueryDBEventFunc != null)
-                    {
-                        sql += $" order by \"occur_time\" DESC limit {m_onePageCounts};";
+                        sql = sqlEvent;
 
-                        List<EventItem> lstEvent = QueryDBEventFunc(sql);
+                        if (!string.IsNullOrEmpty(sqlOperationLog))
+                        {
+                            if (string.IsNullOrEmpty(sql))
+                            {
+                                sql = sqlOperationLog;
+                            }
+                            else
+                            {
+                                sql += " UNION ALL " + sqlOperationLog;
+                            }
+                        }
 
-                        if (lstEvent == null)
-                            return;
 
-                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
+                        if (!string.IsNullOrEmpty(sql) && QueryDBEventFunc != null)
                         {
-                            
+                            sql += $" order by \"occur_time\" DESC limit {m_onePageCounts};";
 
-                            string logTypeStr;
+                            List<EventItem> lstEvent = QueryDBEventFunc(sql);
 
-                            foreach (EventItem ev in lstEvent)
+                            if (lstEvent == null)
+                                return;
+
+                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                             {
-                                switch (ev.Level)
+
+
+                                string logTypeStr;
+
+                                foreach (EventItem ev in lstEvent)
                                 {
-                                    case EventLevel.Information: logTypeStr = "Info"; break;
-                                    case EventLevel.Warning: logTypeStr = "Warning"; break;
-                                    case EventLevel.Alarm: logTypeStr = "Alarm"; break;
-                                    default: logTypeStr = "Undefine"; break;
+                                    switch (ev.Level)
+                                    {
+                                        case EventLevel.Information: logTypeStr = "Info"; break;
+                                        case EventLevel.Warning: logTypeStr = "Warning"; break;
+                                        case EventLevel.Alarm: logTypeStr = "Alarm"; break;
+                                        default: logTypeStr = "Undefine"; break;
+                                    }
+
+                                    SearchedResult.Add(new Aitex.Core.UI.View.Common.SystemLogItem()
+                                    {
+                                        ID = ev.Id.ToString(),
+                                        Time = ((DateTime)ev.OccuringTime).ToString("yyyy/MM/dd HH:mm:ss.fff"),
+                                        LogType = logTypeStr,
+                                        Detail = ev.Description,
+                                        TargetChamber = ev.Source,
+                                        Initiator = "",
+                                        Icon = new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/SystemLog/{0}.png", ev.Level.ToString()), UriKind.Absolute))
+                                    }); ;
                                 }
-                               
-                                SearchedResult.Add(new Aitex.Core.UI.View.Common.SystemLogItem()
-                                {                
-                                    ID = ev.Id.ToString() ,
-                                    Time = ((DateTime)ev.OccuringTime).ToString("yyyy/MM/dd HH:mm:ss.fff"),
-                                    LogType = logTypeStr,
-                                    Detail = ev.Description,
-                                    TargetChamber = ev.Source,
-                                    Initiator = "",
-                                    Icon = new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/SystemLog/{0}.png", ev.Level.ToString()), UriKind.Absolute))
-                                }); ;
-                            }
-                            RaisePropertyChanged("SearchedResult");
+                                RaisePropertyChanged("SearchedResult");
 
-                            if (SearchedResult.Count >= 2000)
-                            {
-                                //MessageBox.Show("Only display max 2000 items,reset the query condition", "query too many result", MessageBoxButton.OK, MessageBoxImage.Warning);
-                            }
+                                if (SearchedResult.Count >= 2000)
+                                {
+                                    //MessageBox.Show("Only display max 2000 items,reset the query condition", "query too many result", MessageBoxButton.OK, MessageBoxImage.Warning);
+                                }
 
-                        }));
+                            }));
+                        }
+                        else
+                        {
+                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
+                            {
+                                SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
+                                RaisePropertyChanged("SearchedResult");
+                            }));
+                        }
                     }
-                    else
+                    catch (Exception ex)
                     {
-                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
-                        {
-                            SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
-                            RaisePropertyChanged("SearchedResult");
-                        }));
+                        //LOG.Write(ex);
+                        LOG.WriteExeption(ex);
                     }
-                }
-                catch (Exception ex)
-                {
-                    //LOG.Write(ex);
-                    LOG.WriteExeption(ex);
-                }
+                });
+               
             });
         }
 

+ 4 - 4
Venus/Venus_MainPages/Views/EventView.xaml

@@ -87,22 +87,22 @@
             </Border>
 
             <StackPanel Grid.Row="7" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,20">
-                <Button Width="100" Height="30" FontFamily="Arial" Content="Query" Command="{Binding SearchCommand}" IsEnabled="{Binding IsAuto,Converter={StaticResource BoolToBool}}">
+                <customeControl:PathButton Width="110" Height="33" FontFamily="Arial" Content="Query" Command="{Binding SearchCommand}" IsEnabled="{Binding IsAuto,Converter={StaticResource BoolToBool}}">
                     <!--<i:Interaction.Triggers>
                         <i:EventTrigger EventName="Click">
                             <cal:ActionMessage MethodName="Search">
                             </cal:ActionMessage>
                         </i:EventTrigger>
                     </i:Interaction.Triggers>-->
-                </Button>
-                <Button Width="100" Height="30" Margin="0,5,0,0" FontFamily="Arial" Content="Export" Command="{Binding ExportCommand}" IsEnabled="{Binding IsAuto,Converter={StaticResource BoolToBool}}">
+                </customeControl:PathButton>
+                <customeControl:PathButton Width="110" Height="33" Margin="0,5,0,0" FontFamily="Arial" Content="Export" Command="{Binding ExportCommand}" IsEnabled="{Binding IsAuto,Converter={StaticResource BoolToBool}}">
                     <!--<i:Interaction.Triggers>
                         <i:EventTrigger EventName="Click">
                             <cal:ActionMessage MethodName="Export">
                             </cal:ActionMessage>
                         </i:EventTrigger>
                     </i:Interaction.Triggers>-->
-                </Button>
+                </customeControl:PathButton>
             </StackPanel>
         </Grid>
         <Grid Grid.Column="1" Margin="10,0,0,0">