Browse Source

add page in EventViewModel

chenkui 2 days ago
parent
commit
1b5cec0bc0

+ 165 - 111
CyberX8_MainPages/ViewModels/EventViewModel.cs

@@ -1,19 +1,22 @@
 using Aitex.Core.RT.Event;
 using Aitex.Core.RT.Log;
 using Aitex.Core.WCF;
+using CyberX8_MainPages.Roles;
+using CyberX8_MainPages.Unity;
+using CyberX8_MainPages.Views;
 using MECF.Framework.Common.DataCenter;
+using OpenSEMI.ClientBase;
 using Prism.Commands;
 using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Imaging;
-using CyberX8_MainPages.Unity;
-using CyberX8_MainPages.Views;
 
 namespace CyberX8_MainPages.ViewModels
 {
@@ -21,6 +24,11 @@ namespace CyberX8_MainPages.ViewModels
     {
         #region 私有字段
         //private int MenuPermission;
+        private int m_Total;
+        private int m_PageCount;
+        private int m_CurrentPage = 1;
+
+        private int m_onePageCounts = 30;
         #endregion
 
         #region 属性
@@ -45,7 +53,7 @@ namespace CyberX8_MainPages.ViewModels
         public bool IsAuto
         {
             get { return m_IsAuto; }
-            set 
+            set
             {
                 if (value == true)
                 {
@@ -74,6 +82,31 @@ namespace CyberX8_MainPages.ViewModels
 
         public Func<string, List<EventItem>> QueryDBEventFunc { get; set; }
         public Func<List<string>> QueryEventList { get; set; }
+
+        public int Total
+        {
+            get { return m_Total; }
+            set
+            {
+                SetProperty(ref m_Total, value);
+            }
+        }
+        public int PageCount
+        {
+            get { return m_PageCount; }
+            set
+            {
+                SetProperty(ref m_PageCount, value);
+            }
+        }
+        public int CurrentPage
+        {
+            get { return m_CurrentPage; }
+            set
+            {
+                SetProperty(ref m_CurrentPage, value);
+            }
+        }
         #endregion
 
         #region 命令
@@ -130,6 +163,15 @@ namespace CyberX8_MainPages.ViewModels
 
 
         }
+        private void PopDialog(EventItem obj)
+        {
+            Application.Current.Dispatcher.Invoke(() =>
+            {
+                DialogBox.ShowInfo(obj.Explaination);
+
+            });
+            //MessageBox.Show(obj.Explaination,"Information",MessageBoxButton.OK,MessageBoxImage.Information);
+        }
         private void Instance_OnEvent(EventItem eventItem)
         {
             switch (eventItem.Type)
@@ -137,13 +179,13 @@ namespace CyberX8_MainPages.ViewModels
                 case EventType.EventUI_Notify:
                     Application.Current.Dispatcher.Invoke(delegate
                     {
-                        SearchedResult.Insert(0,new Aitex.Core.UI.View.Common.SystemLogItem() 
-                        { 
-                            ID=eventItem.Id.ToString(),
-                            LogType=eventItem.Level.ToString(),
-                            Time=eventItem.OccuringTime.ToString(),
-                            TargetChamber=eventItem.Source,
-                            Detail=eventItem.Description,
+                        SearchedResult.Insert(0, new Aitex.Core.UI.View.Common.SystemLogItem()
+                        {
+                            ID = eventItem.Id.ToString(),
+                            LogType = eventItem.Level.ToString(),
+                            Time = eventItem.OccuringTime.ToString(),
+                            TargetChamber = eventItem.Source,
+                            Detail = eventItem.Description,
                             Icon = new BitmapImage(new Uri(string.Format("pack://application:,,,/MECF.Framework.Common;component/Resources/SystemLog/{0}.png", eventItem.Level.ToString()), UriKind.Absolute))
 
                         }
@@ -151,7 +193,7 @@ namespace CyberX8_MainPages.ViewModels
                     });
                     break;
                 case EventType.Dialog_Nofity:
-                    //PopDialog(obj);
+                    //PopDialog(eventItem);
                     break;
                 case EventType.KickOut_Notify:
                     break;
@@ -172,8 +214,13 @@ namespace CyberX8_MainPages.ViewModels
             this.view = (EventView)eventView;
             this.view.wfTimeFrom.Value = this.SearchBeginTime;
             this.view.wfTimeTo.Value = this.SearchEndTime;
+            this.view.pageControl.CurrentPageChanged += PageControl_CurrentPageChanged;
             this.Preload();
         }
+        private void PageControl_CurrentPageChanged(int currentPage)
+        {
+            PageChanged(currentPage);
+        }
         /// <summary>
         /// 预先载入数据
         /// </summary>
@@ -198,7 +245,7 @@ namespace CyberX8_MainPages.ViewModels
 
             //第一次默认查询
             //if (SearchedResult == null)
-                //Search();
+            //Search();
         }
 
         /// <summary>
@@ -274,128 +321,135 @@ namespace CyberX8_MainPages.ViewModels
         {
             Task.Factory.StartNew(() =>
             {
-                try
+                this.view.Dispatcher.Invoke(() =>
                 {
-                    SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
-                    this.SearchBeginTime = this.view.wfTimeFrom.Value;
-                    this.SearchEndTime = this.view.wfTimeTo.Value;
+                    try
+                    {
+                        this.SearchBeginTime = this.view.wfTimeFrom.Value;
+                        this.SearchEndTime = this.view.wfTimeTo.Value;
 
-                    string sqlEvent = "";
-                    string sqlOperationLog = "";
-                    string sql = "";
+                        string test = $"SELECT COUNT(*) FROM \"event_data\" where \"occur_time\" >='{SearchBeginTime.ToString("yyyy/MM/dd HH:mm:ss")}' and \"occur_time\" <='{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"));
+                        test += SearchSqlString();
 
-                        sqlEvent += GetSourceWhere();
+                        Total = QueryDataClient.Instance.Service.GetDBEventAllCount(test);
 
-                        sqlEvent += " and (FALSE ";
-                        if (SearchAlarmEvent) sqlEvent += " OR \"level\"='Alarm' ";
-                        if (SearchWarningEvent) sqlEvent += " OR \"level\"='Warning' ";
-                        if (SearchInfoEvent) sqlEvent += " OR \"level\"='Information' ";
-                        sqlEvent += " ) ";
+                        PageCount = (Total / m_onePageCounts) + 1;
 
-                        if (!string.IsNullOrWhiteSpace(SelectedEvent) && SelectedEvent != "All") sqlEvent += string.Format(" and lower(\"event_enum\")='{0}' ", SelectedEvent.ToLower());
 
-                        //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());
+                        SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
+                        PageQuery(CurrentPage);
                     }
-
-                    if (SearchOpeLog)
+                    catch (Exception ex)
                     {
-                        //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());
+                        //LOG.Write(ex);
+                        LOG.WriteExeption(ex);
                     }
+                });
 
-                    sql = sqlEvent;
+            });
+        }
 
-                    if (!string.IsNullOrEmpty(sqlOperationLog))
-                    {
-                        if (string.IsNullOrEmpty(sql))
-                        {
-                            sql = sqlOperationLog;
-                        }
-                        else
-                        {
-                            sql += " UNION ALL " + sqlOperationLog;
-                        }
-                    }
+        private void PageQuery(int pageIndex)
+        {
+            SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
+            this.SearchBeginTime = this.view.wfTimeFrom.Value;
+            this.SearchEndTime = this.view.wfTimeTo.Value;
 
-                    
-                    if (!string.IsNullOrEmpty(sql) && QueryDBEventFunc != null)
-                    {
-                        sql += " order by \"occur_time\" DESC limit 2000;";
+            string sqlEvent = "";
+            string sql = "";
+            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("yyyy/MM/dd HH:mm:ss"), SearchEndTime.ToString("yyyy/MM/dd HH:mm:ss"));
+            sqlEvent += SearchSqlString();
 
-                        List<EventItem> lstEvent = QueryDBEventFunc(sql);
 
-                        if (lstEvent == null)
-                            return;
 
-                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
-                        {
-                            
-
-                            string logTypeStr;
-
-                            foreach (EventItem ev in lstEvent)
-                            {
-                                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))
-                                }); ;
-                            }
-                            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);
-                            }
-
-                        }));
-                    }
-                    else
+
+            sql = sqlEvent;
+            sql += $" order by \"occur_time\" ASC limit {m_onePageCounts} offset {(pageIndex - 1) * m_onePageCounts};";
+
+
+
+            if (!string.IsNullOrEmpty(sql) && QueryDBEventFunc != null)
+            {
+
+                List<EventItem> lstEvent = QueryDBEventFunc(sql);
+
+                if (lstEvent == null)
+                    return;
+                string logTypeStr;
+
+                foreach (EventItem ev in lstEvent)
+                {
+                    switch (ev.Level)
                     {
-                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
-                        {
-                            SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
-                            RaisePropertyChanged("SearchedResult");
-                        }));
+                        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))
+                    }); ;
                 }
-                catch (Exception ex)
+                RaisePropertyChanged("SearchedResult");
+            }
+            else
+            {
+                SearchedResult = new ObservableCollection<Aitex.Core.UI.View.Common.SystemLogItem>();
+                RaisePropertyChanged("SearchedResult");
+            }
+        }
+        public void PageChanged(int CurrentPage)
+        {
+            Task.Factory.StartNew(() =>
+            {
+                this.view.Dispatcher.Invoke(() =>
                 {
-                    //LOG.Write(ex);
-                    LOG.WriteExeption(ex);
-                }
+                    try
+                    {
+                        PageQuery(CurrentPage);
+                    }
+                    catch (Exception ex)
+                    {
+                        LOG.WriteExeption(ex);
+                    }
+                });
+
             });
+
         }
+        public string SearchSqlString()
+        {
+            this.SearchBeginTime = this.view.wfTimeFrom.Value;
+            this.SearchEndTime = this.view.wfTimeTo.Value;
 
+            string sqlEvent = "";
+
+            string sql = "";
+
+
+            //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 += " and (FALSE ";
+            if (SearchAlarmEvent) sqlEvent += " OR \"level\"='Alarm' ";
+            if (SearchWarningEvent) sqlEvent += " OR \"level\"='Warning' ";
+            if (SearchInfoEvent) sqlEvent += " OR \"level\"='Information' ";
+
+            sqlEvent += " ) ";
+            sql = sqlEvent;
+
+
+            return sql;
+
+        }
         private EventView view;
         #endregion
     }

+ 2 - 0
CyberX8_MainPages/Views/EventView.xaml

@@ -8,6 +8,7 @@
              xmlns:wf ="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
              xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
              xmlns:prism="http://prismlibrary.com/"
+             xmlns:customeControl="clr-namespace:CyberX8_Themes.CustomControls;assembly=CyberX8_Themes"
              xmlns:converters="clr-namespace:CyberX8_Themes.Converters;assembly=CyberX8_Themes"
              prism:ViewModelLocator.AutoWireViewModel="True"
              mc:Ignorable="d" 
@@ -123,6 +124,7 @@
                     <!--<Border BorderBrush="{DynamicResource Table_BD}" BorderThickness="0,1,1,1" Background="{DynamicResource Table_BG_Content}" Padding="5,1" Width="150" Height="24">
                         <TextBlock Text="" FlowDirection="LeftToRight" FontFamily="Arial" FontSize="14" Foreground="{DynamicResource FG_Black}" VerticalAlignment="Center"/>
                     </Border>-->
+                    <customeControl:Pagination PageCount="{Binding PageCount,UpdateSourceTrigger=PropertyChanged}"  Height="30" x:Name="pageControl"/>
                 </StackPanel>
 
                 <DataGrid Grid.Row="1" Margin="0,5,0,0"

+ 5 - 0
CyberX8_RT/Modules/RouteManager.cs

@@ -42,6 +42,7 @@ using MECF.Framework.Common.WaferHolder;
 using CyberX8_RT.Schedulers;
 using MECF.Framework.Common.ProcessCell;
 using System.Reflection;
+using Aitex.Core.Utilities;
 
 namespace CyberX8_RT.Modules
 {
@@ -689,6 +690,10 @@ namespace CyberX8_RT.Modules
             Transition(RtState.AutoIdle, MSG.ResetWafers, ResetWafers, RtState.AutoIdle);
             Transition(RtState.Idle, MSG.ResetWafers, ResetWafers, RtState.Idle);
             Transition(RtState.Init, MSG.ResetWafers, ResetWafers, RtState.Init);
+
+            EnumLoop<RtState>.ForEach((item) => { fsm.MapState((int)item, item.ToString()); });
+
+            EnumLoop<MSG>.ForEach((item) => { fsm.MapMessage((int)item, item.ToString()); });
         }
 
         private bool FsmMonitor(object[] objs)

+ 228 - 0
CyberX8_Themes/CustomControls/Pagination.cs

@@ -0,0 +1,228 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+
+
+namespace CyberX8_Themes.CustomControls
+{
+    public class Pagination : Control
+    {
+        private UserControls.PathButton _btnPrev = null;
+        private Button _btnOne = null;
+        private Button _btnDotPrev = null;
+        private Button _btnCenterOne = null;
+        private Button _btnCenterTwo = null;
+        private Button _btnCenterThree = null;
+        private Button _btnCenterFour = null;
+        private Button _btnCenterFive = null;
+        private Button _btnDotNext = null;
+        private Button _btnLast = null;
+        private UserControls.PathButton _btnNext = null;
+        public Action<int> CurrentPageChanged;
+        public int PageCount
+        {
+            get { return (int)GetValue(PageCountProperty); }
+            set
+            {
+                SetValue(PageCountProperty, value);
+            }
+        }
+        public static readonly DependencyProperty PageCountProperty =
+            DependencyProperty.Register("PageCount", typeof(int), typeof(Pagination), new PropertyMetadata(1, (d, e) =>
+            {
+                if (!(d is Pagination pagination)) return;
+                var page = (int)e.NewValue;
+                pagination.IsSimple = page < 6;
+
+                pagination.UpdateControl();
+
+
+            }));
+        public bool IsSimple
+        {
+            get { return (bool)GetValue(IsSimpleProperty); }
+            set { SetValue(IsSimpleProperty, value); }
+        }
+        public static readonly DependencyProperty IsSimpleProperty =
+            DependencyProperty.Register("IsSimple", typeof(bool), typeof(Pagination), new PropertyMetadata(false));
+
+
+        public int CurrentPage
+        {
+            get { return (int)GetValue(CurrentPageProperty); }
+            set
+            {
+                SetValue(CurrentPageProperty, value);
+                CurrentPageChanged(value);
+            }
+        }
+        public static readonly DependencyProperty CurrentPageProperty =
+            DependencyProperty.Register("CurrentPage", typeof(int), typeof(Pagination), new PropertyMetadata(1, (d, e) =>
+            {
+                if (!(d is Pagination pagination)) return;
+                if (pagination.PageCount > 5)
+                {
+                    pagination.UpdateControl();
+                }
+                else
+                {
+                    pagination.UpdateControlSimple();
+                }
+            }));
+        public override void OnApplyTemplate()
+        {
+            base.OnApplyTemplate();
+
+
+            if (PageCount > 5)
+            {
+                InitControls();
+            }
+            else
+            {
+                InitControlsSimple();
+            }
+        }
+        private List<Button> _simpleButtons = new List<Button>();
+        private void InitControlsSimple()
+        {
+            _btnPrev = GetTemplateChild("btnPrev") as UserControls.PathButton;
+            if (_btnPrev == null)
+            {
+                return;
+            }
+            _btnCenterOne = GetTemplateChild("btnCenterOne") as Button;
+            _btnCenterTwo = GetTemplateChild("btnCenterTwo") as Button;
+            _btnCenterThree = GetTemplateChild("btnCenterThree") as Button;
+            _btnCenterFour = GetTemplateChild("btnCenterFour") as Button;
+            _btnCenterFive = GetTemplateChild("btnCenterFive") as Button;
+            _btnNext = GetTemplateChild("btnNext") as UserControls.PathButton;
+            _simpleButtons.Clear();
+            _simpleButtons.Add(_btnCenterOne);
+            _simpleButtons.Add(_btnCenterTwo);
+            _simpleButtons.Add(_btnCenterThree);
+            _simpleButtons.Add(_btnCenterFour);
+            _simpleButtons.Add(_btnCenterFive);
+            BindClickSimple();
+            UpdateControlSimple();
+        }
+
+
+        private void UpdateControlSimple()
+        {
+            if (_btnCenterOne == null)
+            {
+                return;
+            }
+            _btnCenterOne.Visibility = PageCount >= 1 ? Visibility.Visible : Visibility.Collapsed;
+            _btnCenterTwo.Visibility = PageCount >= 2 ? Visibility.Visible : Visibility.Collapsed;
+            _btnCenterThree.Visibility = PageCount >= 3 ? Visibility.Visible : Visibility.Collapsed;
+            _btnCenterFour.Visibility = PageCount >= 4 ? Visibility.Visible : Visibility.Collapsed;
+            _btnCenterFive.Visibility = PageCount >= 5 ? Visibility.Visible : Visibility.Collapsed;
+            _btnPrev.IsEnabled = CurrentPage > 1;
+            _btnNext.IsEnabled = CurrentPage < PageCount;
+            _btnCenterOne.Background = _btnCenterTwo.Background = _btnCenterThree.Background = _btnCenterFour.Background = _btnCenterFive.Background = Brushes.LightBlue;
+            _simpleButtons[CurrentPage - 1].Background = Brushes.Green;
+        }
+
+
+        private void BindClickSimple()
+        {
+            _btnPrev.Click += (s, e) => CurrentPage -= 1;
+            _btnCenterOne.Click += (s, e) => CurrentPage = 1;
+            _btnCenterTwo.Click += (s, e) => CurrentPage = 2;
+            _btnCenterThree.Click += (s, e) => CurrentPage = 3;
+            _btnCenterFour.Click += (s, e) => CurrentPage = 4;
+            _btnCenterFive.Click += (s, e) => CurrentPage = 5;
+            _btnNext.Click += (s, e) => CurrentPage += 1;
+        }
+
+
+        private void InitControls()
+        {
+            _btnPrev = GetTemplateChild("btnPrev") as UserControls.PathButton;
+            _btnPrev.Cursor = Cursors.Hand;
+            _btnOne = GetTemplateChild("btnOne") as Button;
+            _btnDotPrev = GetTemplateChild("btnDotPrev") as Button;
+            _btnCenterOne = GetTemplateChild("btnCenterOne") as Button;
+            _btnCenterTwo = GetTemplateChild("btnCenterTwo") as Button;
+            _btnCenterThree = GetTemplateChild("btnCenterThree") as Button;
+            _btnCenterFour = GetTemplateChild("btnCenterFour") as Button;
+            _btnCenterFive = GetTemplateChild("btnCenterFive") as Button;
+            _btnDotNext = GetTemplateChild("btnDotNext") as Button;
+            _btnLast = GetTemplateChild("btnLast") as Button;
+            _btnNext = GetTemplateChild("btnNext") as UserControls.PathButton;
+            _btnNext.Cursor = Cursors.Hand;
+            BindClick();
+            UpdateControl();
+        }
+        private void BindClick()
+        {
+            if (_btnPrev == null)
+            {
+                return;
+            }
+            _btnPrev.Click += (s, e) => SetIndex(-1);
+            _btnOne.Click += (s, e) => SetIndex(1 - CurrentPage);
+            _btnDotPrev.Click += (s, e) => SetIndex(-3);
+            _btnCenterOne.Click += (s, e) => SetIndex(-2);
+            _btnCenterTwo.Click += (s, e) => SetIndex(-1);
+            _btnCenterFour.Click += (s, e) => SetIndex(1);
+            _btnCenterFive.Click += (s, e) => SetIndex(2);
+            _btnDotNext.Click += (s, e) => SetIndex(3);
+            _btnLast.Click += (s, e) => SetIndex(PageCount - CurrentPage);
+            _btnNext.Click += (s, e) => SetIndex(1);
+        }
+        public void SetIndex(int page)
+        {
+            if (page < 0)
+            {
+                if (CurrentPage + page > 0)
+                {
+                    CurrentPage += page;
+                }
+            }
+            else if (page > 0)
+            {
+                if (CurrentPage + page <= PageCount)
+                {
+                    CurrentPage += page;
+                }
+            }
+        }
+
+
+        private void UpdateControl()
+        {
+            if (_btnPrev == null)
+            {
+                return;
+            }
+            _btnPrev.IsEnabled = CurrentPage > 1;
+            _btnOne.Visibility = CurrentPage < 4 ? Visibility.Collapsed : Visibility.Visible;
+            _btnDotPrev.Visibility = CurrentPage < 4 ? Visibility.Collapsed : Visibility.Visible;
+            _btnCenterOne.Visibility = CurrentPage != 3 && CurrentPage != PageCount ? Visibility.Collapsed : Visibility.Visible;
+            _btnCenterTwo.Visibility = CurrentPage == 1 || (PageCount - CurrentPage) == 2 ? Visibility.Collapsed : Visibility.Visible;
+            _btnCenterFour.Visibility = CurrentPage == 3 || CurrentPage == PageCount ? Visibility.Collapsed : Visibility.Visible;
+            _btnCenterFive.Visibility = CurrentPage != 1 && (PageCount - CurrentPage) != 2 ? Visibility.Collapsed : Visibility.Visible;
+            _btnDotNext.Visibility = PageCount - CurrentPage < 3 ? Visibility.Collapsed : Visibility.Visible;
+            _btnLast.Visibility = PageCount - CurrentPage < 3 ? Visibility.Collapsed : Visibility.Visible;
+            _btnNext.IsEnabled = CurrentPage != PageCount;
+
+
+            _btnOne.Content = 1;
+            _btnCenterOne.Content = CurrentPage - 2;
+            _btnCenterTwo.Content = CurrentPage - 1;
+            _btnCenterThree.Content = CurrentPage;
+            _btnCenterFour.Content = CurrentPage + 1;
+            _btnCenterFive.Content = CurrentPage + 2;
+            _btnLast.Content = PageCount;
+        }
+    }
+}

+ 1 - 0
CyberX8_Themes/CyberX8_Themes.csproj

@@ -135,6 +135,7 @@
     <Compile Include="CustomControls\GuangChuanRobot.cs" />
     <Compile Include="CustomControls\CustomRobot.cs" />
     <Compile Include="CustomControls\MultiComboBox.cs" />
+    <Compile Include="CustomControls\Pagination.cs" />
     <Compile Include="CustomControls\PathButton.cs" />
     <Compile Include="CustomControls\SERobot.cs" />
     <Compile Include="CustomControls\SplitButton.cs" />

File diff suppressed because it is too large
+ 103 - 1
CyberX8_Themes/Themes/Generic.xaml


+ 7 - 0
Framework/Common/DBCore/DB.cs

@@ -61,5 +61,12 @@ namespace Aitex.Core.RT.DBCore
 
             return null;
         }
+        public static int GetAllCount(string cmdText, params object[] p)
+        {
+            if (Instance != null)
+                return Instance.GetAllCount(cmdText, p);
+
+            return 0;
+        }
     }
 }

+ 5 - 0
Framework/Common/DBCore/DatabaseManager.cs

@@ -203,5 +203,10 @@ namespace Aitex.Core.RT.DBCore
                 LOG.WriteExeption(ex);
             }
         }
+
+        public int GetAllCount(string cmdText, params object[] p)
+        {
+            return _db.GetAllCount(cmdText, p);
+        }
     }
 }

+ 2 - 0
Framework/Common/DBCore/ICommonDB.cs

@@ -23,5 +23,7 @@ namespace Aitex.Core.RT.DBCore
 
 
         DataSet ExecuteDataset(string cmdText, params object[] p);
+
+        int GetAllCount(string cmdText, params object[] p);
     }
 }

+ 23 - 0
Framework/Common/DBCore/PostgresqlDB.cs

@@ -345,5 +345,28 @@ namespace Aitex.Core.RT.DBCore
             }
 
         }
+
+        public int GetAllCount(string cmdText, params object[] p)
+        {
+            using (var connection = new NpgsqlConnection(_connectionString))
+            {
+                connection.Open();
+                connection.ChangeDatabase(_dbName);
+                using (NpgsqlCommand command = new NpgsqlCommand())
+                {
+                    try
+                    {
+                        PrepareCommand(command, connection, cmdText, p);
+
+                        return Convert.ToInt32(command.ExecuteScalar());
+                    }
+                    catch (Exception ex)
+                    {
+                        LOG.WriteExeption(cmdText, ex);
+                        return 0;
+                    }
+                }
+            }
+        }
     }
 }

+ 2 - 0
Framework/Common/DataCenter/IQueryDataService.cs

@@ -290,5 +290,7 @@ namespace MECF.Framework.Common.DataCenter
         [OperationContract]
         void EditUser(UserItem userName);
 
+        [OperationContract]
+        int GetDBEventAllCount(string sql);
     }
 }

+ 4 - 0
Framework/Common/DataCenter/QueryDataService.cs

@@ -206,6 +206,10 @@ namespace MECF.Framework.Common.DataCenter
         {
             return ProcessDataRecorder.GetHistoryStepList(begin,end);
         }
+        public int GetDBEventAllCount(string sql)
+        {
+            return EventDBWriter.QueryDBEventCount(sql);
+        }
         public List<OffsetItem> QueryOffsetDataByTime(string moduleName, DateTime from_time, DateTime to_time)
         {
             return OffsetDataRecorder.QueryOffsetDataByTime(moduleName, from_time, to_time);

+ 6 - 0
Framework/Common/DataCenter/QueryDataServiceClient.cs

@@ -283,5 +283,11 @@ namespace MECF.Framework.Common.DataCenter
             Invoke(svc => { svc.SetTypedConfigContent(type, contentPath, content); });
 
         }
+        public int GetDBEventAllCount(string sql)
+        {
+            int result = 0;
+            Invoke(svc => { result = svc.GetDBEventAllCount(sql); });
+            return result;
+        }
     }
 }

+ 5 - 0
Framework/Common/Event/EventDBWriter.cs

@@ -84,5 +84,10 @@ namespace Aitex.Core.RT.Event
 
             return result;
         }
+
+        public static int QueryDBEventCount(string sql)
+        {
+            return DB.GetAllCount(sql);
+        }
     }
 }