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.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace NEIntelligentControl2.Views.Basic
{
///
/// 状态栏
///
public partial class InfoBar : UserControl
{
public static readonly DependencyProperty IsPaginationProperty = DependencyProperty.Register("IsPagination", typeof(bool), typeof(InfoBar));
public static readonly DependencyProperty PageCountProperty = DependencyProperty.Register("PageCount", typeof(int), typeof(InfoBar));
public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register("PageIndex", typeof(int), typeof(InfoBar));
public static readonly DependencyProperty EachPageCountProperty = DependencyProperty.Register("EachPageCount", typeof(int), typeof(InfoBar));
///
/// 是否分页
///
public bool IsPagination { get => (bool)GetValue(IsPaginationProperty); set => SetValue(IsPaginationProperty, value); }
///
/// 总页数
///
public int PageCount { get=>(int)GetValue(PageCountProperty); set => SetValue(PageCountProperty, value); }
///
/// 当前页码
///
public int PageIndex { get => (int)GetValue(PageIndexProperty); set => SetValue(PageIndexProperty, value); }
///
/// 每页条数
///
public int EachPageCount { get => (int)GetValue(EachPageCountProperty); set => SetValue(EachPageCountProperty, value); }
///
/// 分页动作 每页数据,第几页
///
public Action OnPagination { get; set; }
public InfoBar()
{
InitializeComponent();
IsPagination = true;
PageCount = 1;
PageIndex = 1;
EachPageCount = 100;
}
internal void Inof(string v)
{
// FFCA5100 FF006CBE
Dispatcher.Invoke(() =>
{
this.Visibility = Visibility.Visible;
_SBMain.Background = new SolidColorBrush(Color.FromRgb(0x00, 0x6C, 0xBE));
_TBStatus.Text = v;
_tbEachCountTitle.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
});
}
internal void Warning(string v)
{
Dispatcher.Invoke(() =>
{
this.Visibility = Visibility.Visible;
_SBMain.Background = new SolidColorBrush(Color.FromRgb(0xCA, 0x51, 0x00));
_TBStatus.Text = v;
_tbEachCountTitle.Foreground = new SolidColorBrush(Colors.WhiteSmoke);
});
}
internal void Success()
{
Dispatcher.Invoke(() =>
{
this._TBStatus.Text = "就绪";
_SBMain.Background = new SolidColorBrush(Colors.WhiteSmoke);
_tbEachCountTitle.Foreground = new SolidColorBrush(Colors.Black);
if (!IsPagination)
{
this.Visibility = Visibility.Collapsed;
}
});
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var tag = ((Control)sender).Tag as string;
if (tag == null) return;
switch (tag)
{
case "first":// 第一页
PageIndex = 1;
break;
case "previous":// 上一页
if (PageIndex <= 1) return;
--PageIndex;
break;
case "last":// 下一页
if (PageIndex >= PageCount) return;
++PageIndex;
break;
case "latest":// 最后一页
PageIndex = PageCount;
break;
default:return;
}
this.OnPagination?.Invoke(EachPageCount, PageIndex);
}
}
}