C#WPF实战出真汁06--【系统设置】--餐桌类型设置

1、系统设置的基本概念

系统设置是用于配置和管理餐桌类型和菜品类型,是维护整个系统的基础数据。通过系统设置,用户可以调整餐桌类型的添加,删除,编辑,分页,查询,重置,列表,选择等。

2、布局设计 

餐桌类型设置及菜品类型设置是通过TabControl控件实现的。不过要注意的是,左侧每个菜单点击时,右侧呈现出来的是用户控件,是用户控件,而不是窗体。

1、控件介绍

TabControl 是一种功能强大且灵活的控件,适用于需要分页显示内容的场景。通过合理使用其属性和事件,可以创建出满足各种需求的用户界面。TabControl 是一种常见的用户界面控件,用于在多个选项卡之间切换内容。它通常由一组标签页(TabPage)组成,每个标签页包含不同的内容,用户可以通过点击标签页头来切换显示的内容。在 WPF 中,TabControl 的使用方式更加灵活,通常与数据绑定结合使用。以下是 XAML 示例:

<TabControl><TabItem Header="选项卡1"><Label Content="这是第一个选项卡的内容"/></TabItem><TabItem Header="选项卡2"><Label Content="这是第二个选项卡的内容"/></TabItem>
</TabControl>

 TabControl 的事件,TabControl 提供了多个事件用于响应用户操作,以下是常见事件:

SelectedIndexChanged:当选中标签页发生变化时触发。该事件本项目中必须用到
Selecting:在选中标签页之前触发,可以取消选中操作。
Selected:在选中标签页之后触发。

2、布局应用

完整代码如下:

<UserControl x:Class="HQ.fResApp.UControls.XiTongSheZhi"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:HQ.fResApp.UControls"mc:Ignorable="d" xmlns:vm="clr-namespace:HQ.fResApp.ViewModel"  xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"xmlns:pu="clr-namespace:Panuon.UI.Silver;assembly=Panuon.UI.Silver"Padding="20"d:DesignHeight="450"d:DesignWidth="1000"Background="#f6f9ff"><UserControl.DataContext><vm:DiningDishTypeVModel/></UserControl.DataContext><TabControlMargin="10"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"><TabItem  Cursor="Hand" Header="餐桌类型设置" Background="Aquamarine" BorderThickness="1" FontSize="20"  BorderBrush="AliceBlue" FontFamily="黑体" FontStyle="Normal"   ><Grid Margin="10"><Grid.RowDefinitions><RowDefinition Height="55" /><RowDefinition Height="15" /><RowDefinition /><RowDefinition Height="73" /></Grid.RowDefinitions><Grid Background="#ffffff"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="460" /></Grid.ColumnDefinitions><StackPanel Orientation="Horizontal" Grid.ColumnSpan="2" Margin="0,0,410,0"><TextBoxx:Name="keyWhereTab"Width="200"Height="40"Margin="0,15,20,0"pu:TextBoxHelper.Watermark="输入餐桌关键字"FontSize="15"Foreground="#909399"Text="{Binding DiningTypeKey,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /><Button Width="130"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/search.png"pu:IconHelper.Width="40"Background="#FF009BFF"BorderBrush="#FF009BFF" Content="查询"Cursor="Hand"FontSize="16"Foreground="#ffffff"Command="{Binding FindCommand}"  CommandParameter="dining"IsDefault="true" /><Button Width="130"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="LightSlateGray"BorderBrush="#FF009BFF" Content="重置"Cursor="Hand"FontSize="16"Foreground="#ffffff"Command="{Binding ResetCommand}"  CommandParameter="dining"   /></StackPanel><StackPanelGrid.Column="1"HorizontalAlignment="Right"Orientation="Horizontal"><Buttonx:Name="btnAddTab"Width="130"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="#65d17f"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/add.png"pu:IconHelper.Width="35"Background="#65d17f"BorderBrush="#65d17f" Content="新增"Cursor="Hand"FontSize="16"Foreground="#ffffff" /><Buttonx:Name="btnDelTab"Width="130"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="#FF5722"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/remove1.png"pu:IconHelper.Width="35"Background="#FF5722"BorderBrush="#FF5722" Content="删除"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel></Grid><Border Grid.Row="1" /><DataGridx:Name="dataListTab"Grid.Row="2"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"AlternatingRowBackground="#f7faff"AutoGenerateColumns="False"CanUserAddRows="False"CanUserDeleteRows="False"CanUserReorderColumns="False"CanUserResizeRows="False"FontSize="16"ItemsSource="{Binding DiningTypeList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"SelectionMode="Extended"SelectionUnit="FullRow"><DataGrid.RowStyle><Style TargetType="{x:Type DataGridRow}"><EventSetter Event="UIElement.GotFocus" Handler="TabItem_GotFocus" /><Setter Property="Height" Value="40" /></Style></DataGrid.RowStyle><DataGrid.Columns><DataGridCheckBoxColumn x:Name="chkrtIdTab" CanUserSort="False"><DataGridCheckBoxColumn.HeaderTemplate><DataTemplate><CheckBoxx:Name="ckbSelectedAll"pu:CheckBoxHelper.CheckBoxStyle="Switch"Checked="ckbSelectedAllTab_Checked"Content="全选"Foreground="#ffffff"IsChecked="False"Unchecked="ckbSelectedAllTab_Unchecked" /></DataTemplate></DataGridCheckBoxColumn.HeaderTemplate></DataGridCheckBoxColumn><DataGridTextColumnWidth="2*"Binding="{Binding rtName}"Header="餐桌类型名称"IsReadOnly="True" /><DataGridTextColumnWidth="2*"Binding="{Binding rtLeastCost}"Header="最低消费"IsReadOnly="True" /><DataGridTextColumnWidth="1*"Binding="{Binding rtMostNumber}"Header="容纳人数"IsReadOnly="True" /><DataGridTextColumnWidth="1*"Binding="{Binding rtAmount}"Header="房间个数"IsReadOnly="True" /><DataGridTextColumnWidth="3*"Binding="{Binding createDate, ConverterCulture=zh-CN, StringFormat=\{0:yyyy年MM月dd日 dddd HH时mm分\}}"Header="创建日期"IsReadOnly="True" /></DataGrid.Columns></DataGrid><Grid Grid.Row="3"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="250" /></Grid.ColumnDefinitions><!--餐桌类型分页控件--><pu:Paginationx:Name="tabPaginationTab"Height="45"Margin="0,0,20,0"HorizontalAlignment="Left"Background="#963F3F3F"CurrentIndexChanged="tabPaginationTab_CurrentIndexChanged"Cursor="Hand"HoverBrush="#FF009BFF"Spacing="15"  CurrentIndex="{Binding DiningCurrentIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TotalIndex="{Binding DiningTotalIndex,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="txtTotalNumTab"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 DiningTotalNum,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="txtPageSizeTab"Grid.Row="2"Width="30"Height="30"HorizontalAlignment="Center"pu:TextBoxHelper.CornerRadius="0"Text="{Binding DiningPageSize,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></TabItem><TabItem  Cursor="Hand" Header="菜品类型设置"    Background="Aquamarine" BorderThickness="1" FontSize="20"  BorderBrush="AliceBlue" FontFamily="黑体" FontStyle="Normal"  ><Grid Margin="10"><Grid.ColumnDefinitions><ColumnDefinition Width="27*"/><ColumnDefinition Width="443*"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="55" /><RowDefinition Height="15" /><RowDefinition /><RowDefinition Height="73" /></Grid.RowDefinitions><Grid Background="#ffffff" Grid.ColumnSpan="2"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="460" /></Grid.ColumnDefinitions><StackPanel Orientation="Horizontal" Grid.ColumnSpan="2" Margin="0,0,385,0"><TextBoxx:Name="keyPWhere"Width="200"Height="40"Margin="20,15,20,0"pu:TextBoxHelper.Watermark="输入菜品关键字"FontSize="15"Foreground="#909399"Text="{Binding DishTypeKey,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" /> <Buttonx:Name="btnPSearch"Width="130"Height="40"Margin="0,15,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" Content="查询"Cursor="Hand"FontSize="16"Foreground="#ffffff"Command="{Binding FindCommand}"  CommandParameter="dish"IsDefault="true" /><Button Width="130"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="LightSlateGray"BorderBrush="#FF009BFF" Content="重置"Cursor="Hand"FontSize="16"Foreground="#ffffff"Command="{Binding ResetCommand}"  CommandParameter="dish"   /></StackPanel><StackPanelGrid.Column="1"HorizontalAlignment="Right"Orientation="Horizontal"><Buttonx:Name="btnPAdd"Width="130"Height="40"Margin="0,15,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/add.png"pu:IconHelper.Width="35"Background="#65d17f"BorderBrush="#65d17f" Content="新增"Cursor="Hand"FontSize="16"Foreground="#ffffff" /><Buttonx:Name="btnPDel"Width="130"Height="40"Margin="0,15,20,0"Padding="-10,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.ClickStyle="Sink"pu:ButtonHelper.CornerRadius="20"pu:ButtonHelper.HoverBrush="#FF5722"pu:ButtonHelper.Icon="/HQ.fResApp;component/Resources/icon/remove1.png" pu:IconHelper.Width="35"Background="#FF5722"BorderBrush="#FF5722" Content="删除"Cursor="Hand"FontSize="16"Foreground="#ffffff" /></StackPanel></Grid><Border Grid.Row="1" Grid.ColumnSpan="2" /><DataGridx:Name="dataPList"Grid.Row="2"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"AlternatingRowBackground="#f7faff"AutoGenerateColumns="False"CanUserAddRows="False"CanUserDeleteRows="False"CanUserReorderColumns="False"CanUserResizeRows="False"FontSize="16"ItemsSource="{Binding DishTypeList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"SelectionMode="Extended"SelectionUnit="FullRow" Grid.ColumnSpan="2"><DataGrid.RowStyle><Style TargetType="{x:Type DataGridRow}"><EventSetter Event="UIElement.GotFocus" Handler="ProItem_GotFocus" /><Setter Property="Height" Value="40" /></Style></DataGrid.RowStyle><DataGrid.Columns><DataGridCheckBoxColumn x:Name="chkrtPId" CanUserSort="False"><DataGridCheckBoxColumn.HeaderTemplate><DataTemplate><CheckBoxx:Name="ckbSelectedAll"pu:CheckBoxHelper.CheckBoxStyle="Switch"Checked="ckbSelectedAllPro_Checked"Content="全选"Foreground="#ffffff"IsChecked="False"Unchecked="ckbSelectedAllPro_Unchecked" /></DataTemplate></DataGridCheckBoxColumn.HeaderTemplate></DataGridCheckBoxColumn><DataGridTextColumnWidth="3*"Binding="{Binding mtName}"Header="菜品类型名称"IsReadOnly="True" /><DataGridTextColumnWidth="3*"Binding="{Binding createDate, ConverterCulture=zh-CN, StringFormat=\{0:yyyy年MM月dd日 dddd HH时mm分\}}"Header="创建日期"IsReadOnly="True" /></DataGrid.Columns></DataGrid><Grid Grid.Row="3" Grid.ColumnSpan="2"><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition Width="250" /></Grid.ColumnDefinitions><pu:Paginationx:Name="tabPPagination"Height="45"Margin="0,0,20,0"HorizontalAlignment="Left"Background="#963F3F3F"CurrentIndexChanged="ProPagination_CurrentIndexChanged"Cursor="Hand"HoverBrush="#FF009BFF"Spacing="15"CurrentIndex="{Binding DishCurrentIndex,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TotalIndex="{Binding DishTotalIndex,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="txtPTotalNum"Content="{Binding DishTotalNum,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"Height="45"Padding="-35,0,0,0"pu:ButtonHelper.ButtonStyle="Standard"pu:ButtonHelper.HoverBrush="Transparent"pu:IconHelper.Width="35"Background="Transparent"BorderBrush="Transparent" 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="txtPPageSize"Grid.Row="2"Width="25"Height="30"HorizontalAlignment="Center"pu:TextBoxHelper.CornerRadius="0"Text="{Binding DishPageSize,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></TabItem> </TabControl>
</UserControl>

Panuon.UI.Silver控件库中带有分页控件Pagination,这个分页控件蛮好用,灵活方便好使,支持随时修改每页条数,自动更新分页导航。

3、视图模型

在WPF中,ViewModel是MVVM(Model-View-ViewModel)架构模式的核心组件,负责连接View(界面)和Model(数据/业务逻辑)。

ViewModel的核心作用
数据绑定桥梁:通过属性暴露数据,供View双向绑定,实现数据自动同步。
命令处理:封装UI操作逻辑,通过ICommand接口实现事件响应(如按钮点击)。
状态管理:维护View的视觉状态(如加载中、错误提示等)。

1、查询命令

2、重置命令

完整代码如下:

using HQ.BLL;
using HQ.COMM;
using HQ.fResApp.BaseModel;
using HQ.fResApp.Utils;
using HQ.MODEL.DBModel;
using HQ.MODEL.UIModel;
using Panuon.UI.Silver;
using Panuon.UI.Silver.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Controls;
using System.Windows.Input;namespace HQ.fResApp.ViewModel
{/// <summary>/// 餐桌类型和菜品类型viewmodel/// </summary>public class DiningDishTypeVModel : ViewModelBase{DiningTypeBLL diningTypebll = new DiningTypeBLL();DishTypeBLL dishTypebll = new DishTypeBLL();#region 餐桌类型页面属性private ObservableCollection<DiningType> diningTypeList;/// <summary>/// 餐桌类型列表,页面绑定的数据源/// </summary>public ObservableCollection<DiningType> DiningTypeList{get { return diningTypeList; }set{diningTypeList = value;OnPropertyChanged();}}private string diningTypeKey="";/// <summary>/// 餐桌关键字/// </summary>public string DiningTypeKey{get { return diningTypeKey; }set{diningTypeKey = value;OnPropertyChanged();}} private int diningCurrentIndex=1;/// <summary>/// 餐桌类型当前页/// </summary>public int DiningCurrentIndex{get { return diningCurrentIndex; }set{diningCurrentIndex = value;OnPropertyChanged();}}private int diningTotalIndex;/// <summary>/// 餐桌类型总页数/// </summary>public int DiningTotalIndex{get { return diningTotalIndex; }set{diningTotalIndex = value;OnPropertyChanged();}} private int diningTotalNum;/// <summary>///  餐桌类型总条数/// </summary>public int DiningTotalNum{get { return diningTotalNum; }set{diningTotalNum = value;OnPropertyChanged();}}private int diningPageSize=10;/// <summary>///  餐桌类型每页条数/// </summary>public int DiningPageSize{get { return diningPageSize; }set{diningPageSize = value;OnPropertyChanged();DiningTypeList = GetDingTypeTable();}}#endregionpublic DiningDishTypeVModel(){DiningTypeList = GetDingTypeTable(); }/// <summary>/// 获取餐桌类型列表/// </summary>/// <returns></returns>public ObservableCollection<DiningType> GetDingTypeTable(){ObservableCollection<DiningType> tableDataList = new ObservableCollection<DiningType>(); var _parms = new PageParm { page = DiningCurrentIndex, limit = DiningPageSize, key = DiningTypeKey.Trim() }; var _pageRes = diningTypebll.GetPagesAsync(_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 _curTab = new DiningType{rtGuid = item.rtGuid,rtName = item.rtName,createDate = item.createDate};tableDataList.Add(_curTab);} DiningTotalNum = (int)_pageResData.TotalItems;DiningCurrentIndex  = (int)_pageResData.CurrentPage;DiningTotalIndex = (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>public ICommand FindCommand{get{return new RelayCommand(o =>{string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":DiningTypeList = GetDingTypeTable();break;}});}}/// <summary>/// 重置按钮的命令处理/// </summary>public ICommand ResetCommand{get{return new RelayCommand(o =>{string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":DiningCurrentIndex = 1;DiningPageSize = 10;DiningTypeKey = "";DiningTypeList = GetDingTypeTable();break;}});}}}
}

3、新增命令

4、编辑命令

5、完整代码 

using HQ.BLL;
using HQ.Comm;
using HQ.COMM;
using HQ.fResApp.BaseModel;
using HQ.fResApp.Utils;
using HQ.fResApp.ViewModel.PageViewModel;
using HQ.fResApp.XWindows;
using HQ.MODEL.DBModel;
using HQ.MODEL.UIModel;
using Panuon.UI.Silver;
using Panuon.UI.Silver.Core;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Xml.Linq;namespace HQ.fResApp.ViewModel
{/// <summary>/// 餐桌类型和菜品类型viewmodel/// </summary>public class DiningDishTypeListVModel : ViewModelBase{DiningTypeBLL diningTypebll = new DiningTypeBLL();DishTypeBLL dishTypebll = new DishTypeBLL();#region 餐桌类型页面属性private ObservableCollection<DiningTypeCheckInfo> diningTypeList;/// <summary>/// 餐桌类型列表,页面绑定的数据源/// </summary>public ObservableCollection<DiningTypeCheckInfo> DiningTypeList{get { return diningTypeList; }set{diningTypeList = value;OnPropertyChanged();}}private string diningTypeKey="";/// <summary>/// 餐桌关键字/// </summary>public string DiningTypeKey{get { return diningTypeKey; }set{diningTypeKey = value;OnPropertyChanged();}} private int diningCurrentIndex=1;/// <summary>/// 餐桌类型当前页/// </summary>public int DiningCurrentIndex{get { return diningCurrentIndex; }set{diningCurrentIndex = value;OnPropertyChanged();}}private int diningTotalIndex;/// <summary>/// 餐桌类型总页数/// </summary>public int DiningTotalIndex{get { return diningTotalIndex; }set{diningTotalIndex = value;OnPropertyChanged();}} private int diningTotalNum;/// <summary>///  餐桌类型总条数/// </summary>public int DiningTotalNum{get { return diningTotalNum; }set{diningTotalNum = value;OnPropertyChanged();}}private int diningPageSize=10;/// <summary>///  餐桌类型每页条数/// </summary>public int DiningPageSize{get { return diningPageSize; }set{diningPageSize = value;OnPropertyChanged();DiningTypeList = GetDingTypeTable();}}private bool isCheckAllDining = false;/// <summary>/// 餐桌全选状态/// </summary>public bool IsCheckAllDining{get { return isCheckAllDining; }set{isCheckAllDining = value;OnPropertyChanged();}}#endregion#region 菜品类型页面属性private ObservableCollection<DishTypeCheckInfo> dishTypeList;/// <summary>/// 菜品类型列表,页面绑定的数据源/// </summary>public ObservableCollection<DishTypeCheckInfo> DishTypeList{get { return dishTypeList; }set{dishTypeList = value;OnPropertyChanged();}}private string dishTypeKey="";/// <summary>/// 菜品关键字/// </summary>public string DishTypeKey{get { return dishTypeKey; }set{dishTypeKey = value;OnPropertyChanged();}}private int dishCurrentIndex = 1;/// <summary>/// 菜品类型当前页/// </summary>public int DishCurrentIndex{get { return dishCurrentIndex; }set{dishCurrentIndex = value;OnPropertyChanged();}}private int dishTotalIndex;/// <summary>/// 菜品类型总页数/// </summary>public int DishTotalIndex{get { return dishTotalIndex; }set{dishTotalIndex = value;OnPropertyChanged();}}private int dishTotalNum;/// <summary>/// 菜品类型总条数/// </summary>public int DishTotalNum{get { return dishTotalNum; }set{dishTotalNum = value;OnPropertyChanged();}}private int dishPageSize =10;/// <summary>///  菜品类型每页条数/// </summary>public int DishPageSize{get { return dishPageSize; }set{dishPageSize = value;OnPropertyChanged();DishTypeList = GetDishTypeTable();}}private bool isCheckAllDish = false;/// <summary>/// 餐桌全选状态/// </summary>public bool IsCheckAllDish{get { return isCheckAllDish; }set{isCheckAllDish = value;OnPropertyChanged();}}#endregionpublic DiningDishTypeListVModel(){DiningTypeList = GetDingTypeTable();DishTypeList = GetDishTypeTable();}/// <summary>/// 获取菜品类型列表/// </summary>/// <returns></returns>public ObservableCollection<DishTypeCheckInfo> GetDishTypeTable(){ObservableCollection<DishTypeCheckInfo> tableDataList = new ObservableCollection<DishTypeCheckInfo>(); var _parms = new PageParm { page = DishCurrentIndex, limit = DishPageSize, key = DishTypeKey.Trim() };var _pageRes = dishTypebll.GetPagesAsync(_parms).Result;//分页查询if (_pageRes.statusCode == (int)ApiEnum.Status){var _pageResData = _pageRes.data;var _tabList = _pageResData.Items;if (_tabList != null && _tabList.Count != 0){ObservableCollection<DishTypeCheckInfo> proDataList = new ObservableCollection<DishTypeCheckInfo>();foreach (var item in _tabList){ var _curTab = new DishTypeCheckInfo();_curTab.DishTypeInfo.mtGuid = item.mtGuid;_curTab.DishTypeInfo.mtName = item.mtName;_curTab.DishTypeInfo.createDate = item.createDate;tableDataList.Add(_curTab);} DishTotalNum = (int)_pageResData.TotalItems ;DishCurrentIndex = (int)_pageResData.CurrentPage;DishTotalIndex = (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>/// <returns></returns>public ObservableCollection<DiningTypeCheckInfo> GetDingTypeTable(){ObservableCollection<DiningTypeCheckInfo> tableDataList = new ObservableCollection<DiningTypeCheckInfo>(); var _parms = new PageParm { page = DiningCurrentIndex, limit = DiningPageSize, key = DiningTypeKey.Trim() }; var _pageRes = diningTypebll.GetPagesAsync(_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 _curTab = new DiningTypeCheckInfo();_curTab.DiningTypeInfo.rtGuid = item.rtGuid;_curTab.DiningTypeInfo.rtName = item.rtName;_curTab.DiningTypeInfo.rtLeastCost = item.rtLeastCost;_curTab.DiningTypeInfo.rtMostNumber = item.rtMostNumber;_curTab.DiningTypeInfo.rtAmount = item.rtAmount;_curTab.DiningTypeInfo.createDate = item.createDate;_curTab.IsCheck = false;tableDataList.Add(_curTab);} DiningTotalNum = (int)_pageResData.TotalItems;DiningCurrentIndex  = (int)_pageResData.CurrentPage;DiningTotalIndex = (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>public ICommand DiningCheckAllCmd{get{return new RelayCommand(o =>{//将业主列表每条记录的isCheck设为与标题状态一致foreach (var record in this.DiningTypeList){record.IsCheck = this.IsCheckAllDining;}});}}/// <summary>/// 菜品类型全选命令/// </summary>public ICommand DishCheckAllCmd{get{return new RelayCommand(o =>{//将业主列表每条记录的isCheck设为与标题状态一致foreach (var record in this.DishTypeList){record.IsCheck = this.IsCheckAllDish;}});}}/// <summary>/// 选择一条餐桌类型数据/// </summary>public ICommand CheckDiningType{get{return new RelayCommand(o =>{if (o != null){var item = o as DiningTypeCheckInfo;item.IsCheck =!item.IsCheck;}});}}/// <summary>/// 选择一条菜品类型数据/// </summary>public ICommand CheckDishType{get{return new RelayCommand(o =>{if (o != null){var item = o as DishTypeCheckInfo;item.IsCheck = !item.IsCheck;}});}}/// <summary>/// 查询按钮的命令处理/// </summary>public ICommand FindCommand{get{return new RelayCommand(o =>{ string typeobj=o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":DiningTypeList = GetDingTypeTable();break;case "dish":DishTypeList = GetDishTypeTable();break;} });}}/// <summary>/// 重置按钮的命令处理/// </summary>public ICommand ResetCommand{get{return new RelayCommand(o =>{string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":DiningCurrentIndex = 1;DiningPageSize = 10;DiningTypeKey = "";DiningTypeList = GetDingTypeTable();break;case "dish":DishCurrentIndex = 1;DishPageSize = 10;DishTypeKey = "";DishTypeList = GetDishTypeTable();break;}});}}/// <summary>/// 新增按钮的命令处理/// </summary>public ICommand AddCommand{get{return new RelayCommand(o =>{string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":WindowX AddWin = new DiningTypeInfo();if (AddWin != null){ AddWin.Closed += new EventHandler(RefreshDiningType);//注册关闭事件AddWin.ShowDialog(); }break;case "dish":DishCurrentIndex = 1;DishPageSize = 10;DishTypeKey = "";DishTypeList = GetDishTypeTable();break;}});}}/// <summary>/// 修改按钮的命令处理/// </summary>public ICommand EditCommand{get{return new RelayCommand(o =>{string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":List<string> delIds = new List<string>();delIds = this.DiningTypeList.Where(r => r.IsCheck == true).Select(r => r.DiningTypeInfo.rtGuid).ToList();if (delIds.Count == 0){MessageBoxX.Show("请选择要编辑的数据.", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations(){MessageBoxIcon = MessageBoxIcon.Warning,ButtonBrush = "#F1C825".ToColor().ToBrush(),});return;}if (delIds.Count >= 2){var _msgRes = MessageBoxX.Show("对不起,一次只能编辑一条数据", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations(){MessageBoxIcon = MessageBoxIcon.Info,ButtonBrush = "#F1C825".ToColor().ToBrush(),});}else{ string selectid = delIds.First();//获取记录idWindowX EditWin = new DiningTypeInfo(selectid); if (EditWin != null){ DiningDishTypeInfoVModel objvmodel = new DiningDishTypeInfoVModel(); DiningType result = diningTypebll.GetModelById(x=>x.rtGuid == selectid).Result.data;objvmodel.DiningTypeItem = result;EditWin.DataContext = objvmodel;EditWin.Closed += new EventHandler(RefreshDiningType);//注册关闭事件EditWin.ShowDialog();} RefreshDiningType(null, null);}  break;case "dish":DishTypeList = GetDishTypeTable();break;}});}}/// <summary>/// 删除按钮的命令处理/// </summary>public ICommand DeleteCommand{get{return new RelayCommand(o =>{ string typeobj = o.ToString();//获取命令传递过来的参数,即控件的 CommandParameter参数//处理点击动作(餐桌还是菜品执行不同的处理)switch (typeobj){case "dining":List<string> delIds = new List<string>();delIds = this.DiningTypeList.Where(r => r.IsCheck == true).Select(r => r.DiningTypeInfo.rtGuid).ToList();if (delIds.Count == 0){MessageBoxX.Show("请选择要删除的数据.", "提示", Application.Current.MainWindow, MessageBoxButton.OK, new MessageBoxXConfigurations(){MessageBoxIcon = MessageBoxIcon.Warning,ButtonBrush = "#F1C825".ToColor().ToBrush(),});return;}if (delIds.Count > 0){var _msgRes = MessageBoxX.Show("确定要删除吗?", "提示", Application.Current.MainWindow, MessageBoxButton.YesNo, new MessageBoxXConfigurations(){MessageBoxIcon = MessageBoxIcon.Warning,ButtonBrush = "#F1C825".ToColor().ToBrush(),});if (_msgRes == MessageBoxResult.No){return;}var res = new ApiResult<string>() { statusCode = (int)ApiEnum.Error };foreach (string id in delIds){res = diningTypebll.DeleteById(id).Result;} if (res.statusCode == (int)ApiEnum.Status){Notice.Show("成功删除【"+delIds.Count+"】条数据", "提示", 3, MessageBoxIcon.Success);}else{Notice.Show("删除失败!", "提示", 3, MessageBoxIcon.Error);Logger.Default.ProcessError(res.statusCode, "删除餐桌类型失败");}RefreshDiningType(null, null);}break;case "dish":DishTypeList = GetDishTypeTable();break;}});}}/// <summary>/// 刷新餐桌数据/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void RefreshDiningType(object sender, EventArgs e){DiningCurrentIndex = 1;DiningPageSize = 10;DiningTypeKey = "";DiningTypeList = GetDingTypeTable();}}
}

4、运行效果

由每页10条改为每页3条

在wpf中,按钮事件,比如单击事件的响应不是通过onclick这样的方式来实现的,而是通过bind mycommand绑定命令来实现的。

原创不易,打字截图不易,走过路过,不要错过,欢迎点赞,收藏,转载,复制,抄袭,留言,动动你的金手指,早日实现财务自由!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/news/919307.shtml
繁体地址,请注明出处:http://hk.pswp.cn/news/919307.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

旋钮键盘项目---foc讲解(闭环位置控制)

hello&#xff0c;周六休息了一天&#xff0c;出去打本了。趁着夜色&#xff0c;花费了几个小时&#xff0c;也是将闭环代码写完&#xff0c;参考了灯哥的思路。接下来介绍一下我的整个流程&#xff1a; 一、闭环位置控制思路&#xff1a; 其实懂得了开环&#xff0c;那么闭环…

为什么有些相机“即插即用”,而有些则需要采集卡?

在工业生产中&#xff0c;工业相机是“眼睛”&#xff0c;它帮助我们看到世界&#xff0c;但你知道吗&#xff1f;不同的工业相机接口就像不同的“通道”&#xff0c;有些“通道”直接就能与计算机连接&#xff0c;而有些则需要一个额外的小配件——图像采集卡。那么&#xff0…

【计算机网络 | 第7篇】物理层基本概念

文章目录物理层基本概念及数据通信系统解析一、物理层的核心定位&#x1f95d;二、物理层的功能&#x1f9fe;三、数据通信系统的模型&#x1f426;‍&#x1f525;&#xff08;一&#xff09;源系统&#xff08;二&#xff09;传输系统&#xff08;三&#xff09;目的系统四、…

一般情况下,python函数都会返回对象,但有时只调用一个函数,这是在修改这个信息

class Model:def __init__(self):self.training Truedef eval(self):self.training Falsereturn Nonem Model() print(m.training) # True m.eval() # 返回 None print(m.training) # False&#xff0c;模型内部状态已改变m.eval&#xff08;&#xff09;是在修改m的…

2025-08-17 李沐深度学习17——语义分割

文章目录1 语义分割1.1 介绍1.2 语义分割应用1.3 实例分割2 转置卷积2.1 工作原理2.2 为什么叫“转置”卷积2.3 转置卷积也是一种卷积3 FCN3.1 核心思想3.2 网络架构4 样式迁移4.1 基于 CNN 的样式迁移4.2 工作流程1 语义分割 1.1 介绍 语义分割&#xff08;Semantic Segment…

《若依》权限控制

若依内置了强大的权限控制系统&#xff0c;为企业级项目提供了通用的解决方案 以CRM系统为例&#xff0c;演示权限功能&#xff08;URL&#xff1a;https://huike-crm.itheima.net) demo账号&#xff08;超级管理员&#xff09;查看所有功能菜单 zhangsan账号&#xff08;市…

云原生俱乐部-RH134知识点总结(3)

这个系列的第二篇写了将近5000字&#xff0c;而且还是删节内容后的&#xff0c;如RAID就没写&#xff0c;因为头已经很大了。第二篇从早上写到下午&#xff0c;因为偷懒了&#xff0c;写着写着就停笔了。不过好在总算磨完了&#xff0c;现在开始写RH134系列的最后一篇内容。我这…

股票常见K线

1.底部反弹摸线特点长下影线之后必须有实体阴线踩实之后才考虑。macd绿缓慢收窄过程中的不买&#xff0c;刚转红也不买。macd转红之后等股价跌回之前macd绿首次收窄的最低点附近&#xff0c;而且跌破了所有均线&#xff0c;可以买入此股票。之后股票一波突破之前平台震荡平台&a…

计算机网络 THU 考研专栏简介

本专栏专为清华大学计算机网络考研复习设计&#xff0c;内容系统全面&#xff0c;涵盖从基础概念到重点考点的完整知识体系。具体包括&#xff1a;基础理论&#xff1a;计算机网络概念、分类、性能指标及网络分层模型&#xff08;OSI 七层、TCP/IP 四层&#xff09;。协议与技术…

VSCode打开新的文件夹之后当前打开的文件夹被覆盖

文件--首选项--设置&#xff1a;搜索showtabs设置为如下&#xff1a;

mac 电脑安装类似 nvm 的工具,node 版本管理工具

前言 苹果电脑开发时&#xff0c;有时候需要切换node 版本&#xff0c;window版有nvm可以管理node 版本&#xff0c;mac版本可以用另外一种 //全局安装n 模块 sudo npm install n -g//输入后回车&#xff0c;提示输入电脑密码&#xff0c;输入完密码回车等待下载完成即可//安装…

spdlog框架的安装与使用

spdlog框架的安装与使用spdlog的安装spdlog的使用spdlog二次封装总结&#xff1a;spdlog的安装 sudo apt-get install libspdlog-devspdlog的使用 同步日志器sync.cc (输出到显示器/输出到指定文件) #include<spdlog/spdlog.h> #include<spdlog/sinks/stdout_color…

使用websockets中的一些问题和解决方法

&#xff08;1&#xff09;TypeError: echo() missing 1 required positional argument: path报错自己写的代码如下&#xff1a;async def echo(websocket, path):...async def main():server await websockets.serve(echo, "0.0.0.0", 666)await server.wait_close…

机器人相关基础知识

机器人简介下面给出一份机器人方向“从入门到进阶”的极简知识地图&#xff0c;按「数学 → 硬件 → 软件 → 算法 → 应用」五层展开&#xff0c;配合常用开源资源。你可以把它当作“字典”随时查阅。&#x1f539; 1. 数学层&#xff08;所有算法的地基&#xff09;概念一句话…

Windows Server 打开vGPU RDP HEVC编码

查看已安装的驱动[rootlocalhost:~] esxcli software vib list Name Version Vendor Acceptance Level Install Date Platforms ----------------------------- ------------------------------------ ------ -…

OpenAL技术详解:跨平台3D音频API的设计与实践

引言&#xff1a;OpenAL的定位与价值 OpenAL&#xff08;Open Audio Library&#xff09; 是一套跨平台的3D音频应用程序接口&#xff08;API&#xff09;&#xff0c;专为高效渲染多通道三维定位音频而设计。其API风格与编程范式刻意模仿OpenGL&#xff0c;旨在为游戏开发、虚…

重温 K8s 基础概念知识系列五(存储、配置、安全和策略)

文章目录一、存储&#xff08;Storage&#xff09;1.1、Volume1.2、PersistentVolume (PV)1.3、PersistentVolumeClaim (PVC)1.4、StorageClass1.5、PVC 和 PV 的绑定过程&#xff1f;二、配置管理&#xff08;Configuration&#xff09;2.1、ConfigMap2.2、Secret2.3、存活、就…

通过PhotoShop将多张图片整合为gif动画

一、准备图片集合二、导入PS导入PS后点击确定&#xff1a;导入成功&#xff1a;三、添加时间轴勾选创建帧动画&#xff1a;此时时间轴进化为帧动画轴&#xff1a;四、图片集部署在帧动画轴点击帧动画轴右上角的三道横杠&#xff0c;从图层建立帧&#xff1a;此时图片集已经部署…

Easy Rules 规则引擎详解

Easy Rules 规则引擎详解 Easy Rules 是一个轻量级的 Java 规则引擎&#xff0c;它提供了一种简单而强大的方式来定义和执行业务规则。以下是 Easy Rules 的详细介绍&#xff1a; 1. 核心概念 1.1 规则 (Rule) 条件 (Condition): 当条件为 true 时执行动作动作 (Action): 条件满…

优雅设计:打造AI时代的高效后端API接口——领码课堂深度解析

&#x1f4cc; 摘要 后端API接口已经成为软件架构的神经系统。微服务演化、AI渗透、自动化治理……这些趋势迫使我们重新定义接口设计的标准。本文从统一规范、参数校验、异常处理、性能优化四大维度出发&#xff0c;结合领码Spark的接口治理平台与AI赋能实践&#xff0c;构建一…