WinUser.xaml.cs
4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using HHECS.Bll;
using HHECS.Controls;
using HHECS.Model;
using HHECS.Model.BllModel;
using HHECS.Model.Entities;
using HHECS.View.Win;
using HHECS.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace HHECS.View.UserOperation
{
/// <summary>
/// User.xaml 的交互逻辑
/// </summary>
public partial class WinUser : MyWindow
{
public PageInfoVM PageInfo { get; set; } = new PageInfoVM();
public WinUser()
{
InitializeComponent();
AppSession.Bll.CheckPermission(AppSession.MenuOperations, SPBtns.Children);
this.page.DataContext = PageInfo;
}
private void BtnQuery_Click(object sender, RoutedEventArgs e)
{
Query();
}
private void Query()
{
string sql = "where 1=1 ";
if (!String.IsNullOrWhiteSpace(TxtUserCode.Text))
{
sql += $" and userCode like '{TxtUserCode.Text}%'";
}
if (!String.IsNullOrWhiteSpace(TxtUserName.Text))
{
sql += $" and userName like '{TxtUserName.Text}%'";
}
BllResult<int> result = AppSession.Bll.GetCommonModelCount<User>(sql);
if (result.Success)
{
PageInfo.TotalCount = result.Data;
var a = AppSession.Bll.GetCommonModeByPageCondition<User>(PageInfo.PageIndex, PageInfo.PageSize, sql, "");
if (a.Success)
{
DatagridMain.ItemsSource = a.Data;
}
else
{
MessageBox.Show($"查询出错:{a.Msg}");
}
}
else
{
MessageBox.Show($"查询失败:{result.Msg}");
}
}
private void BtnNew_Click(object sender, RoutedEventArgs e)
{
WinUserAddOrEdit user = new WinUserAddOrEdit(null);
user.ShowDialog();
}
private void BtnEdit_Click(object sender, RoutedEventArgs e)
{
if (DatagridMain.SelectedItem == null)
{
MessageBox.Show("请先选中一条数据");
}
else
{
User user = (User)DatagridMain.SelectedItem;
WinUserAddOrEdit userAddOrEdit = new WinUserAddOrEdit(user.Id);
userAddOrEdit.ShowDialog();
}
}
private void BtnDisable_Click(object sender, RoutedEventArgs e)
{
if (DatagridMain.SelectedItems.Count == 0)
{
MessageBox.Show("请先选中数据");
}
else
{
var temp = new List<User>();
foreach (var item in DatagridMain.SelectedItems)
{
temp.Add((User)item);
}
BllResult result = AppSession.Bll.SetUserDisable(temp.Select(t => t.Id).ToList(),1);
if (result.Success)
{
MessageBox.Show("禁用成功");
}
else
{
MessageBox.Show("禁用失败");
}
}
Query();
}
private void BtnEnable_Click(object sender, RoutedEventArgs e)
{
if (DatagridMain.SelectedItems.Count == 0)
{
MessageBox.Show("请先选中数据");
}
else
{
var temp = new List<User>();
foreach (var item in DatagridMain.SelectedItems)
{
temp.Add((User)item);
}
BllResult result = AppSession.Bll.SetUserDisable(temp.Select(t => t.Id).ToList(),0);
if (result.Success)
{
MessageBox.Show("启用成功");
}
else
{
MessageBox.Show("启用失败");
}
}
Query();
}
private void page_PageChanged(object sender, PageChangedEventArgs e)
{
PageInfo.PageIndex = e.CurrentPageIndex;
Query();
}
}
}