1、營業查詢介紹
本模塊是最后一個模塊,該板塊需要的功能有:營業數據列表,查詢數據,導出數據,數據統計。
2、UI設計布局
TabControl 是 WPF 中用于創建多頁標簽式界面的控件,常用于組織多個子內容區域。每個子內容通過 TabItem 定義,用戶可以通過點擊標簽頭切換內容,通過修改樣式和模板,可以完全自定義 TabControl 的外觀。可以通過代碼動態管理 TabControl 中的 TabItem,TabControl 支持數據綁定,可以通過 ItemsSource 屬性綁定到一個集合,并使用 ItemTemplate 定義標簽頭的顯示方式,TabControl 提供了多個有用的事件,例如 SelectionChanged,可以在用戶切換標簽頁時執行自定義邏輯:通過設置 TabStripPlacement 屬性,可以改變標簽頭的位置,使其顯示在左側、右側或底部。
<UserControlx:Class="HQ.fResApp.UControls.BusinessInquiry"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:MetroChart="clr-namespace:De.TorstenMandelkow.MetroChart;assembly=De.TorstenMandelkow.MetroChart"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:pu="clr-namespace:Panuon.UI.Silver;assembly=Panuon.UI.Silver"xmlns:vm="clr-namespace:HQ.fResApp.ViewModel"d:DesignHeight="450"d:DesignWidth="1000"Background="#f6f9ff"mc:Ignorable="d"><UserControl.DataContext><vm:BusinessInquiryListVModel /></UserControl.DataContext><TabControlMargin="20"VerticalAlignment="Stretch"pu:TabControlHelper.HeaderPanelBackground="#fcfcfc"pu:TabControlHelper.ItemHeight="50"pu:TabControlHelper.ItemPadding="20,0"pu:TabControlHelper.ItemsAlignment="LeftOrTop"pu:TabControlHelper.SelectedBackground="#FF009BFF"pu:TabControlHelper.SelectedForeground="#ffffff"pu:TabControlHelper.TabControlStyle="Card"><TabItemBackground="BlanchedAlmond"BorderBrush="AliceBlue"BorderThickness="1"Cursor="Hand"FontFamily="雅黑"FontSize="20"Header="營業訂單數據"><Grid Margin="10"><Grid.ColumnDefinitions><ColumnDefinition Width="56*" /><ColumnDefinition Width="411*" /></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition /></Grid.RowDefinitions><Grid Grid.ColumnSpan="2"><Grid.RowDefinitions><RowDefinition Height="80" /><RowDefinition /><RowDefinition Height="60" /></Grid.RowDefinitions><Grid Background="#ffffff"><Grid.ColumnDefinitions><ColumnDefinition /></Grid.ColumnDefinitions><StackPanel Orientation="Horizontal"><TextBoxWidth="280"Height="40"Margin="0,0,20,0"pu:TextBoxHelper.Watermark="輸入訂單號搜索"FontSize="15"Foreground="#909399"Text="{Binding BillHistoryKey}" /><Buttonx:Name="btnSearch"Width="100"Height="40"Margin="0,0,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#009BFF"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/search.png"pu:IconHelper.Width="40"Background="#FF009BFF"BorderBrush="#FF009BFF"Command="{Binding FindCommand}"Content="查詢"Cursor="Hand"FontSize="16"Foreground="#ffffff"IsDefault="true" /><ButtonWidth="100"Height="40"Margin="0,0,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#009BFF"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/Refresh.png"pu:IconHelper.Width="40"Background="LightSlateGray"BorderBrush="#FF009BFF"Command="{Binding ResetCommand}"Content="重置"Cursor="Hand"FontSize="16"Foreground="#ffffff" /><ButtonWidth="140"Height="40"Margin="0,0,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#65d17f"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/openorder.png"pu:IconHelper.Width="35"Background="#ab4321"BorderBrush="#65d17f"Command="{Binding BackUpAllCommand}"Content="導出全部數據"Cursor="Hand"FontSize="16"Foreground="#ffffff" /><ButtonWidth="140"Height="40"Margin="0,0,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#65d17f"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/openorder.png"pu:IconHelper.Width="35"Background="#65d17f"BorderBrush="#65d17f"Command="{Binding BackUpPageCommand}"Content="導出本頁數據"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel></Grid><DataGridx:Name="tableList"Grid.Row="1"pu:DataGridHelper.ColumnHorizontalContentAlignment="Center"pu:DataGridHelper.HeaderBackground="#FF009BFF"pu:DataGridHelper.HeaderForeground="#ffffff"pu:DataGridHelper.HeaderMinHeight="50"pu:DataGridHelper.HoverBackground="#FF009BFF"pu:DataGridHelper.ResizeThumbThickness="0.5"pu:DataGridHelper.SelectedBackground="Transparent"pu:DataGridHelper.SelectedForeground="Red"AlternatingRowBackground="#f7faff"AutoGenerateColumns="False"CanUserAddRows="False"CanUserDeleteRows="False"CanUserReorderColumns="False"CanUserResizeRows="False"Cursor="Pen"FontSize="16"ItemsSource="{Binding BillHistoryDataList}"SelectionMode="Extended"SelectionUnit="FullRow"><DataGrid.RowStyle><Style TargetType="DataGridRow"><!-- Event綁定MouseLeftButtonUp表示鼠標點擊事件,Handler表示具體的事件處理程序 --><Setter Property="Height" Value="40" /><!-- 樣式觸發器,IsMouseOver表示鼠標滑過時事件 --><Style.Triggers><Trigger Property="IsMouseOver" Value="True"><Setter Property="Background"><Setter.Value><LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"><GradientStop Offset="0.98" Color="#FF73BCE8" /><GradientStop Offset="0" Color="White" /></LinearGradientBrush></Setter.Value></Setter></Trigger></Style.Triggers></Style></DataGrid.RowStyle><DataGrid.Columns><DataGridTextColumnWidth="2*"Binding="{Binding tName}"FontSize="18"Header="餐桌號"IsReadOnly="True" /><DataGridTextColumnWidth="3*"Binding="{Binding obId}"FontSize="18"Header="訂單號"IsReadOnly="True" /><DataGridTextColumnWidth="4*"Binding="{Binding obDate, StringFormat='{}{0:yyyy年MM月dd日 dddd HH時mm分}', ConverterCulture=zh-CN}"FontSize="18"Header="開單時間"IsReadOnly="True" /><DataGridTextColumnWidth="2*"Binding="{Binding obNumber}"FontSize="18"Header="消費人數"IsReadOnly="True" /><DataGridTextColumnWidth="2*"Binding="{Binding opConsumeMoney}"FontSize="18"Header="消費金額"IsReadOnly="True" /><DataGridTextColumnWidth="2*"Binding="{Binding opClientMoney}"FontSize="18"Header="支付金額"IsReadOnly="True" /><DataGridTextColumnWidth="4*"Binding="{Binding obDate, StringFormat='{}{0:yyyy年MM月dd日 dddd HH時mm分}', ConverterCulture=zh-CN}"FontSize="18"Header="創建時間"IsReadOnly="True" /><DataGridTextColumnWidth="3*"Binding="{Binding opRemark}"FontSize="18"Header="備注"IsReadOnly="True" /></DataGrid.Columns></DataGrid><Grid Grid.Row="2"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="250" /></Grid.ColumnDefinitions><pu:Paginationx:Name="tabPagination"Height="45"Margin="0,0,20,0"HorizontalAlignment="Left"Background="#963F3F3F"CurrentIndex="{Binding BillHistoryCurrentIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"CurrentIndexChanged="tabPageActiveChanged"Cursor="Hand"HoverBrush="#FF009BFF"Spacing="15"TotalIndex="{Binding BillHistoryTotalIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /><StackPanelGrid.Column="1"HorizontalAlignment="Right"Orientation="Horizontal"><ButtonWidth="20"Height="45"Padding="-35,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.HoverBrush="Transparent"pu:IconHelper.Width="35"Background="Transparent"BorderBrush="Transparent"Content="共"FontSize="17"FontWeight="ExtraBold"Foreground="#2F4056" /><Buttonx:Name="txtTotalNum"Height="45"Padding="-35,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.HoverBrush="Transparent"pu:IconHelper.Width="35"Background="Transparent"BorderBrush="Transparent"Content="{Binding BillHistoryTotalNum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"FontSize="17"FontWeight="ExtraBold"Foreground="#FF009BFF" /><ButtonWidth="100"Height="45"Padding="-35,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.HoverBrush="Transparent"pu:IconHelper.Width="35"Background="Transparent"BorderBrush="Transparent"Content="條數據/每頁"FontSize="17"FontWeight="ExtraBold"Foreground="#2F4056" /><TextBoxx:Name="txtPageSize"Grid.Row="2"Width="50"Height="30"HorizontalAlignment="Center"pu:TextBoxHelper.CornerRadius="0"Text="{Binding BillHistoryPageSize, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /><ButtonWidth="20"Height="45"Padding="-35,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.HoverBrush="Transparent"pu:IconHelper.Width="35"Background="Transparent"BorderBrush="Transparent"Content="條"FontSize="17"FontWeight="ExtraBold"Foreground="#2F4056" /></StackPanel></Grid></Grid></Grid></TabItem><TabItemBackground="BlanchedAlmond"BorderBrush="AliceBlue"BorderThickness="1"Cursor="Hand"FontFamily="雅黑"FontSize="20"FontWeight="Bold"Header="最近一周"><Grid><Grid.RowDefinitions><RowDefinition Height="1*" /><RowDefinition Height="9*" /></Grid.RowDefinitions><StackPanel HorizontalAlignment="Right" Orientation="Horizontal"><ButtonWidth="100"Height="40"Margin="0,-10,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#009BFF"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/Refresh.png"pu:IconHelper.Width="40"Background="#65d17f"BorderBrush="#65d17f"Content="刷新"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel><MetroChart:ClusteredColumnChartGrid.Row="1"Margin="0,-10,20,0"ChartLegendVisibility="Collapsed"ChartSubTitle="額度"ChartTitle="最近一周營業情況統計"ChartTitleVisibility="Visible"IsRowColumnSwitched="True"ToolTipFormat="{Binding Path=ToolTipFormat}"><MetroChart:ClusteredColumnChart.Series><MetroChart:ChartSeriesDisplayMember="Name"ItemsSource="{Binding Path=WeekDatas}"SeriesTitle="日期"ValueMember="Count" /></MetroChart:ClusteredColumnChart.Series></MetroChart:ClusteredColumnChart></Grid></TabItem><TabItemBackground="BlanchedAlmond"BorderBrush="AliceBlue"BorderThickness="1"Cursor="Hand"FontFamily="雅黑"FontSize="20"FontWeight="Bold"Header="最近一個月"><Grid><Grid.RowDefinitions><RowDefinition Height="1*" /><RowDefinition Height="9*" /></Grid.RowDefinitions><StackPanel HorizontalAlignment="Right" Orientation="Horizontal"><ButtonWidth="100"Height="40"Margin="0,-10,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#009BFF"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/Refresh.png"pu:IconHelper.Width="40"Background="#65d17f"BorderBrush="#65d17f"Content="刷新"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel><MetroChart:ClusteredColumnChartGrid.Row="1"Margin="0,-10,20,0"ChartLegendVisibility="Collapsed"ChartSubTitle="額度"ChartTitle="最近一個月營業情況統計"ChartTitleVisibility="Visible"IsRowColumnSwitched="True"ToolTipFormat="{Binding Path=ToolTipFormat}"><MetroChart:ClusteredColumnChart.Series><MetroChart:ChartSeriesDisplayMember="Name"ItemsSource="{Binding Path=MonthDatas}"SeriesTitle="日期"ValueMember="Count" /></MetroChart:ClusteredColumnChart.Series></MetroChart:ClusteredColumnChart></Grid></TabItem><TabItemBackground="BlanchedAlmond"BorderBrush="AliceBlue"BorderThickness="1"Cursor="Hand"FontFamily="雅黑"FontSize="20"FontWeight="Bold"Header="按年份統計"><Grid><Grid.RowDefinitions><RowDefinition Height="1*" /><RowDefinition Height="9*" /></Grid.RowDefinitions><StackPanel HorizontalAlignment="Right" Orientation="Horizontal"><ButtonWidth="100"Height="40"Margin="0,-10,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#009BFF"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/Refresh.png"pu:IconHelper.Width="40"Background="#65d17f"BorderBrush="#65d17f"Content="刷新"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel><MetroChart:ClusteredColumnChartGrid.Row="1"Margin="0,-10,20,0"ChartLegendVisibility="Collapsed"ChartSubTitle="額度"ChartTitle="各年份營業情況統計"ChartTitleVisibility="Visible"IsRowColumnSwitched="True"ToolTipFormat="{Binding Path=ToolTipFormat}"><MetroChart:ClusteredColumnChart.Series><MetroChart:ChartSeriesDisplayMember="Name"ItemsSource="{Binding Path=YearDatas}"SeriesTitle="年份"ValueMember="Count" /></MetroChart:ClusteredColumnChart.Series></MetroChart:ClusteredColumnChart></Grid></TabItem></TabControl>
</UserControl>
3、viewmodel模型
ViewModel 的主要職責是封裝業務邏輯和狀態,為視圖提供數據綁定和命令綁定的接口。通過數據綁定,ViewModel 能夠將數據從 Model 傳遞到 View,同時處理用戶輸入和界面邏輯,而無需直接操作 UI 元素,viewmodel就是一個類,這個類中包括了變量,屬性,命令,其中屬性和命令是最重要的,屬性是動態通知屬性,當屬性的值發生更改時,自動更新界面元素標簽,反過來也是這樣的,命令來說就是響應事件,如單擊,雙擊,右鍵等。
using HQ.BLL;
using HQ.COMM;
using HQ.COMM.DtoModel;
using HQ.fResApp.BaseModel;
using HQ.fResApp.Utils;
using HQ.fResApp.ViewModel.PageViewModel;
using HQ.MODEL.DBModel;
using Panuon.UI.Silver;
using Panuon.UI.Silver.Core;
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.Input;namespace HQ.fResApp.ViewModel
{/// <summary>/// 營業查詢視圖模型/// </summary>public class BusinessInquiryListVModel : ViewModelBase{#region 變量BillHistoryBLL billhistoryBLL = new BillHistoryBLL();public string ToolTipFormat{get { return "當前額度是:{1},在總額中占比為:{3:P2}"; }}#endregionpublic BusinessInquiryListVModel(){BillHistoryDataList = getBillHistoryList();InitUIData();}#region 屬性public ObservableCollection<Population> weekDatas = new ObservableCollection<Population>(); public ObservableCollection<Population> WeekDatas{get { return weekDatas; }set{weekDatas = value;OnPropertyChanged();}}public ObservableCollection<Population> monthDatas = new ObservableCollection<Population>();public ObservableCollection<Population> MonthDatas{get { return monthDatas; }set{monthDatas = value;OnPropertyChanged();}}public ObservableCollection<Population> yearhDatas = new ObservableCollection<Population>(); public ObservableCollection<Population> YearDatas{get { return yearhDatas; }set{yearhDatas = value;OnPropertyChanged();}}ObservableCollection<BillHistory> billHistoryDataList = new ObservableCollection<BillHistory>();/// <summary>///歷史訂單列表/// </summary>public ObservableCollection<BillHistory> BillHistoryDataList{get { return billHistoryDataList; }set{billHistoryDataList = value;OnPropertyChanged();}}private int billHistoryCurrentIndex = 1;/// <summary>/// 當前頁,默認第1頁/// </summary>public int BillHistoryCurrentIndex{get { return billHistoryCurrentIndex; }set{billHistoryCurrentIndex = value;OnPropertyChanged();}}private int billHistoryTotalIndex;/// <summary>/// 總頁數/// </summary>public int BillHistoryTotalIndex{get { return billHistoryTotalIndex; }set{billHistoryTotalIndex = value;OnPropertyChanged();}}private int billHistoryTotalNum;/// <summary>/// 總條數/// </summary>public int BillHistoryTotalNum{get { return billHistoryTotalNum; }set{billHistoryTotalNum = value;OnPropertyChanged();}}private int billHistoryPageSize = 15;/// <summary>/// 每頁條數,默認10條/// </summary>public int BillHistoryPageSize{get { return billHistoryPageSize; }set{billHistoryPageSize = value;OnPropertyChanged();//當改變每頁條數時,觸發以下事件BillHistoryDataList = getBillHistoryList(); //訂單歷史數據集合}}private string billHistoryKey = "";/// <summary>/// 搜索時的關鍵字,默認為空/// </summary>public string BillHistoryKey{get { return billHistoryKey; }set{billHistoryKey = value;OnPropertyChanged();}}#endregion#region 方法private void InitUIData(){//最近一周var _resweek = billhistoryBLL.CountBillHistoryData(new CountModelDto { _where = 7 }).Result;if (_resweek.statusCode == (int)ApiEnum.Status){foreach (var item in _resweek.data){weekDatas.Add(new Population() { Name = item.wDate, Count = item.countCost });}}//最近一月var _resmonth = billhistoryBLL.CountBillHistoryData(new CountModelDto { _where = 30 }).Result;if (_resmonth.statusCode == (int)ApiEnum.Status){foreach (var item in _resmonth.data){monthDatas.Add(new Population() { Name = item.wDate, Count = item.countCost });}}//按年份var _resyear = billhistoryBLL.CountBillHistoryData(new CountModelDto { _where = 365 }).Result;if (_resyear.statusCode == (int)ApiEnum.Status){foreach (var item in _resyear.data){yearhDatas.Add(new Population() { Name = item.wDate, Count = item.countCost });}}}/// <summary>/// 獲取訂單歷史數據/// </summary>/// <returns></returns>public ObservableCollection<BillHistory> getBillHistoryList(){ObservableCollection<BillHistory> TableDataList = new ObservableCollection<BillHistory>();var parms = new PageParm { page = BillHistoryCurrentIndex, limit = BillHistoryPageSize, key = BillHistoryKey.Trim() };var pageRes = billhistoryBLL.GetBillHistoryPages(parms).Result;//分頁查詢結果if (pageRes.statusCode == (int)ApiEnum.Status){var _pageResData = pageRes.data;var tabList = _pageResData.Items;//數據集需要重新處理,將每個數據項加上復選框,用于頁面數據展示if (tabList != null && tabList.Count != 0){foreach (var item in tabList){var curBill = new BillHistory{obGuid = item.obGuid,obId = item.obId,tName = item.tName,obDate = item.obDate,obNumber = item.obNumber,opConsumeMoney = item.opConsumeMoney,opClientMoney = item.opClientMoney,opRemark = item.opRemark,lastUpDate = item.lastUpDate };TableDataList.Add(curBill);}BillHistoryTotalNum = (int)_pageResData.TotalItems;BillHistoryCurrentIndex = (int)_pageResData.CurrentPage;BillHistoryTotalIndex = (int)_pageResData.TotalPages;}else{Notice.Show("沒有獲取到歷史列表數據!", "提示", 3, MessageBoxIcon.Info);Logger.Default.ProcessError((int)ApiEnum.Error, "沒有獲取到歷史列表數據");}}else{Notice.Show("沒有獲取到歷史列表數據!", "提示", 3, MessageBoxIcon.Info);Logger.Default.ProcessError(pageRes.statusCode, "獲取到歷史列表數據異常");}return TableDataList;}/// <summary>/// 導出數據/// </summary>/// <param name="array">列表對象</param>/// <param name="filename">文件名稱</param>/// <exception cref="NotImplementedException"></exception>private void Backup<T>(List<T> array, string name){var t = typeof(T);var properties = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);var contents = new StringBuilder();//標題foreach (var item in properties){//得到第一個自定義屬性的參數的值,即屬性描述var desc = item.CustomAttributes.ToList()[0].ConstructorArguments[0].Value.ToString();contents.Append(desc);contents.Append(",");}contents.Append("\r\n");//換行//內容foreach (var model in array){var row = new StringBuilder();foreach (var property in properties){var val = property.GetValue(model);row.Append(val);row.Append(",");}contents.Append(row.ToString());contents.Append("\r\n");}//finename -> 表格+日期var date = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);var filename = $"{name}{date}.csv";var rootImagPath = Directory.GetCurrentDirectory().Replace(@"\bin\Debug", "") + @"\Resources\proData\" + filename;//保存File.WriteAllText(rootImagPath, contents.ToString(), Encoding.UTF8);//以utf-8的格式保存成csv格式MessageBoxX.Show("數據導出成功!", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations(){MessageBoxIcon = MessageBoxIcon.Success,ButtonBrush = "#F1C825".ToColor().ToBrush(),});}#endregion/// <summary>/// 查詢命令/// </summary>public ICommand FindCommand{get{return new RelayCommand(o =>{BillHistoryDataList = getBillHistoryList();});}}/// <summary>/// 重置命令/// </summary>public ICommand ResetCommand{get{return new RelayCommand(o =>{BillHistoryCurrentIndex = 1;//當前頁為第1頁BillHistoryPageSize = 15;//每頁10條BillHistoryKey = "";//關鍵字清空 BillHistoryDataList = getBillHistoryList();//訂單數據集合 });}}/// <summary>/// 導出本頁/// </summary>public ICommand BackUpPageCommand{get{return new RelayCommand(o =>{Backup(BillHistoryDataList.ToList(), "billspage");});}}/// <summary>/// 導出全部/// </summary>public ICommand BackUpAllCommand{get{return new RelayCommand(o =>{ParmString ps = new ParmString();var objdata = billhistoryBLL.QueryBillHistoryList(ps).Result.data;Backup(objdata, "billslist");});}}}
}
using HQ.BLL;
using HQ.COMM.DtoModel;
using HQ.fResApp.BaseModel;
using HQ.fResApp.Utils;
using HQ.fResApp.ViewModel.PageViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace HQ.fResApp.ViewModel
{/// <summary>/// 營業查詢視圖模型/// </summary>public class MetroChartVModel : ViewModelBase{BillHistoryBLL openBillsService = new BillHistoryBLL();public string ToolTipFormat{get { return "當前額度是:{1},在總額中占比為:{3:P2}"; }}private readonly ObservableCollection<Population> _weekDatas = new ObservableCollection<Population>();private readonly ObservableCollection<Population> _monthDatas = new ObservableCollection<Population>();private readonly ObservableCollection<Population> _yearhDatas = new ObservableCollection<Population>();public ObservableCollection<Population> WeekDatas { get { return _weekDatas; } }public ObservableCollection<Population> MonthDatas { get { return _monthDatas; } }public ObservableCollection<Population> YearDatas { get { return _yearhDatas; } }public MetroChartVModel(){//最近一周var _resweek = openBillsService.CountBillHistoryData(new CountModelDto { _where = 7 }).Result;if (_resweek.statusCode == (int)ApiEnum.Status){foreach (var item in _resweek.data) { _weekDatas.Add(new Population(){ Name = item.wDate, Count = item.countCost }); }}//最近一月var _resmonth = openBillsService.CountBillHistoryData(new CountModelDto { _where = 30 }).Result;if (_resmonth.statusCode == (int)ApiEnum.Status){foreach (var item in _resmonth.data) { _monthDatas.Add(new Population() { Name = item.wDate, Count = item.countCost }); }}//按年份var _resyear = openBillsService.CountBillHistoryData(new CountModelDto { _where = 365 }).Result;if (_resyear.statusCode == (int)ApiEnum.Status){foreach (var item in _resyear.data) { _yearhDatas.Add(new Population() { Name = item.wDate, Count = item.countCost }); }}}}
}
4、運行測試
原創不易,打字截圖不易,走過路過,不要錯過,歡迎點贊,收藏,轉載,復制,抄襲,留言,灌水,噴火,吐槽,動動你的金手指,早日實現財務自由!