<#if table??>
================================= List Page Begin ====================================
${table.entityName}ListPage.xaml
--------------------------------------------------------------------------------------
<Page x:Class="app.view.${table.entityName}ListPage"
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:app="clr-namespace:app.component"
Title="${table.entityName}ListPage" Loaded="Page_Loaded">
<Page.Resources>
<Style TargetType="Label">
<Setter Property="Width" Value="75" />
<Setter Property="HorizontalContentAlignment" Value="Right" />
<Setter Property="Padding" Value="10 5" />
</Style>
<Style TargetType="WrapPanel" x:Key="fieldWPStyle">
<Setter Property="Margin" Value="0 0 0 5" />
<Setter Property="Height" Value="25" />
</Style>
</Page.Resources>
<Border BorderThickness="1" BorderBrush="Silver">
<DockPanel>
<DockPanel DockPanel.Dock="Top">
<StackPanel Orientation="Vertical">
<WrapPanel Margin="0 5 0 0">
<#list table.columns as column>
<#if column.columName != "id">
<WrapPanel Name="search_${column.attributeName}Wp" Style="{StaticResource fieldWPStyle}" Visibility="Collapsed">
<Label Name="search_${column.attributeName}Lb" Content="${column.columComment}"/>
<TextBox Height="23" Name="search_${column.attributeName}Tb" Width="120" />
</WrapPanel>
</#if>
</#list>
<WrapPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="查询" Height="23" Width="50" Margin="15 0 10 0" Click="SearchBtn_Click"/>
<Button Content="清空" Height="23" Width="50" Click="Search_CleanUpBtn_Click" />
</WrapPanel>
</WrapPanel>
<Separator/>
</StackPanel>
</DockPanel>
<DockPanel DockPanel.Dock="Bottom">
<app:Pager x:Name="pager" PageSize="5" GetDataDelegateHandler="LoadData" />
</DockPanel>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="35" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ToolBar Grid.Row="0" ToolBarTray.IsLocked="True" Loaded="ToolBar_Loaded">
<Button Content="新增" Click="Button_Click_AddNew"></Button>
<Button Content="修改" Click="Button_Click_Modify"></Button>
<Button Content="详情" Click="Button_Click_Info"></Button>
<Button Content="删除" Click="Button_Click_Del"></Button>
</ToolBar>
<DataGrid x:Name="dataGrid" Grid.Row="1" ItemsSource="{Binding}" IsReadOnly="True" Style="{StaticResource recordListDGStyle}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SelectionMode="Single">
<DataGrid.Columns>
<#list table.columns as column>
<DataGridTextColumn x:Name="${column.attributeName}DGTC" Header="${column.columComment}" Width="100" Binding="{Binding ${column.attributeNameFLU}}"/>
</#list>
</DataGrid.Columns>
</DataGrid>
</Grid>
</DockPanel>
</Border>
</Page>
======================================================================================
${table.entityName}ListPage.xaml.cs
--------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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;
using app.util;
using net.yeetop.csutils;
using net.yeetop.csutils.attribute;
using app.service;
using net.yeetop.csbase.entity;
using app.entity;
using System.Collections.ObjectModel;
using app.context;
using System.Globalization;
namespace app.view {
/// <summary>
/// ${table.entityName}ListPage.xaml 的交互逻辑
/// </summary>
public partial class ${table.entityName}ListPage : Page {
[Resource(Name = "${table.entityNameFLL}Service")]
private I${table.entityName}Service ${table.entityNameFLL}Service;
private bool hasInited = false;
public ${table.entityName}ListPage() {
InitializeComponent();
SimpleAnnotation.DependencyInject(this);
// 表格自动生成行号
ViewUtils4WPF.ShowDataGridLineNumberDefault(this.dataGrid);
this.dataGrid.MouseDoubleClick += new MouseButtonEventHandler((sender, args) => {
ShowDetailPage(IConstant.DetailWinMode.INFO, (sender as DataGrid).SelectedItem as ${table.entityName});
});
}
/// <summary>
/// 分页控件回调函数,返回总记录数
/// </summary>
/// <param name="pageNo">页码,由分页控件传入</param>
/// <param name="pageSize">页面记录大小,由分页控件传入</param>
/// <returns></returns>
private int LoadData(int pageNo, int pageSize) {
try {
${table.entityName} filter = new ${table.entityName}();
<#list table.columns as column>
<#if column.columName != "id">
<#if column.columType?lower_case == "int">
filter.${column.attributeNameFLU} = Convert.ToInt32(this.search_${column.attributeName}Tb.Text);
<#elseif column.columType?lower_case == "bigint">
filter.${column.attributeNameFLU} = Convert.ToInt64(this.search_${column.attributeName}Tb.Text);
<#elseif column.columType?lower_case == "decimal">
filter.${column.attributeNameFLU} = Convert.ToDecimal(this.search_${column.attributeName}Tb.Text);
<#else>
filter.${column.attributeNameFLU} = this.search_${column.attributeName}Tb.Text;
</#if>
</#if>
</#list>
Page<${table.entityName}> page = this.${table.entityNameFLL}Service.Get${table.entityName}List(pageNo, pageSize, "asc", "id", filter);
ObservableCollection<${table.entityName}> items = new ObservableCollection<${table.entityName}>();
foreach (${table.entityName} item in page.ResultList) {
if (item != null) {
items.Add(item);
} else {
items.Add(new ${table.entityName}() {
Id = -1
});
}
}
this.dataGrid.DataContext = items;
return page.Total;
} catch (Exception e) {
MessageBox.Show("系统出错[${table.entityName}ListPage#LoadData, " + e.Message + "],请联系管理员!", "出错!", MessageBoxButton.OK, MessageBoxImage.Error);
return 0;
}
}
/// <summary>
/// 刷新DataGrid并跳转到PageNoFlag标识的页
/// </summary>
/// <param name="pageNoFlag"></param>
private void RefreshDataGrid(IConstant.PageNoFlag pageNoFlag) {
switch (pageNoFlag) {
case IConstant.PageNoFlag.CURRENT:
this.pager.Refresh();
break;
case IConstant.PageNoFlag.FIRST:
this.pager.GotoFirstPage();
break;
case IConstant.PageNoFlag.LAST:
this.pager.GotoLastPage();
if (this.dataGrid.Items.Count == this.pager.PageSize) {
this.pager.GotoLastPage(); // 确保跳转到最后一页
}
break;
default:
break;
}
}
private void Page_Loaded(object sender, RoutedEventArgs e) {
if (!hasInited) {
hasInited = true;
}
}
private void ToolBar_Loaded(object sender, RoutedEventArgs e) {
// 去除工具条右侧扩展下拉三角按钮
ToolBar toolBar = sender as ToolBar;
ViewUtils4WPF.DelToolBarRightExtendButton(toolBar);
}
// 按键事件
private void Button_Click_AddNew(object sender, RoutedEventArgs e) {
try {
ShowDetailPage(IConstant.DetailWinMode.ADD_NEW, null);
} catch (Exception ex) {
MessageBox.Show("打开添加窗口按钮事件出错,请联系技术人员![${table.entityName}ListPage, " + ex.Message + "]", "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void Button_Click_Modify(object sender, RoutedEventArgs e) {
try {
${table.entityName} ${table.entityNameFLL} = ViewUtils4WPF.GetDataGridSel