You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

327 lines
10 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using GummingCommon;
using GummingEntity;
using GummingSupport;
using GummingControl;
using System.Text;
using GummingBusiness;
using Newtonsoft.Json;
using GummingLine;
namespace Gumming
{
public class SysUserViewModule : ViewModelBase
{
#region base parameters
private int rows = 20;
private int pagenumber = 1;
public SysUserView View { get; set; }
private bool IsConfirm;
private bool isLoading;
private AppEnum.PathType _CurrentPathType;
public AppEnum.PathType CurrentPathType
{
get
{
return _CurrentPathType;
}
set
{
_CurrentPathType = value;
OnPropertyChanged("CurrentPathType");
}
}
#endregion
#region constructor
public SysUserViewModule()
{
View = new SysUserView();
View.DataContext = this;
InitializeCommands();
InitializeParameters();
}
private void InitializeCommands()
{
NewCommand = new DelegateCommand(OnNewCommand);
ModifyCommand = new DelegateCommand(OnModifyCommand);
ModifyPasswordCommand = new DelegateCommand(OnModifyPasswordCommand);
DeleteCommand = new DelegateCommand(OnDeleteCommand);
}
public override void InitializeParameters(object content = null)
{
IsConfirm = false;
WindowTitle = "";
PagerControlViewer = new PagerControlViewModule();
PagerControlViewer.OnPager += new PagerControlViewModule.PagerHandler(PagerControlView_OnPager);
StartLoadTestItem();
}
~SysUserViewModule()
{
}
#endregion
#region Binding Properties
public string WindowTitle { get; private set; }
private string _TotalRecords;
public string TotalRecords
{
get
{
return _TotalRecords;
}
set
{
_TotalRecords = value;
OnPropertyChanged("TotalRecords");
}
}
private ObservableCollection<SysUserEntity> _SysUsers;
public ObservableCollection<SysUserEntity> SysUsers
{
get
{
return _SysUsers;
}
set
{
_SysUsers = value;
OnPropertyChanged("SysUsers");
}
}
private SysUserEntity _SelectedUser;
public SysUserEntity SelectedUser
{
get
{
return _SelectedUser;
}
set
{
_SelectedUser = value;
OnPropertyChanged("SelectedUser");
}
}
private PagerControlViewModule _PagerControlViewer;
public PagerControlViewModule PagerControlViewer
{
get { return _PagerControlViewer; }
set
{
_PagerControlViewer = value;
OnPropertyChanged("PagerControlViewer");
}
}
#endregion
#region Binding Commands
private ICommand _NewCommand;
public ICommand NewCommand
{
get
{
return _NewCommand;
}
set
{
_NewCommand = value;
OnPropertyChanged("NewCommand");
}
}
private ICommand _ModifyCommand;
public ICommand ModifyCommand
{
get
{
return _ModifyCommand;
}
set
{
_ModifyCommand = value;
OnPropertyChanged("ModifyCommand");
}
}
private ICommand _ModifyPasswordCommand;
public ICommand ModifyPasswordCommand
{
get
{
return _ModifyPasswordCommand;
}
set
{
_ModifyPasswordCommand = value;
OnPropertyChanged("ModifyPasswordCommand");
}
}
private ICommand _DeleteCommand;
public ICommand DeleteCommand
{
get
{
return _DeleteCommand;
}
set
{
_DeleteCommand = value;
OnPropertyChanged("DeleteCommand");
}
}
#endregion
#region Private Methods
private void PagerControlView_OnPager(int currentpagenumber, int currentrows)
{
pagenumber = currentpagenumber;
rows = currentrows;
if (!isLoading)
{
Thread t = new Thread(StartLoadTestItem);
t.IsBackground = true;
t.Start();
}
}
private void StartLoadTestItem()
{
try
{
isLoading = true;
SysUsers = new ObservableCollection<SysUserEntity>();
var record = SysUserDA.Load(new PagerEntity() { PageIndex = pagenumber, Rows = rows, Conditions = " and 1=1 " });
List<SysUserEntity> users = (List<SysUserEntity>)record.rows;
View.Dispatcher.Invoke((Action)(() =>
{
foreach (var s in users)
{
var role = Global.SysRoles.FirstOrDefault(q => q.RoleCode == s.RoleId);
if (role != null)
{
s.RoleName = role.RoleName;
s.RoleDesc = role.RoleDesc;
}
SysUsers.Add(s);
}
OnPropertyChanged("HartSysUser");
TotalRecords = string.Format("<22><><EFBFBD>ü<EFBFBD>¼<EFBFBD><C2BC>: {0}", record.records);//.ToString("D5"));
PagerControlViewer.SetPager(rows, record.page, record.total, record.Count, record.records);
isLoading = false;
}));
}
catch (Exception ex)
{
LogService.WriteErrorLog(ex);
ShowErrorBox("Error:" + ex.Message);
return;
}
finally
{
CloseProgressView();
}
}
private void OnNewCommand(Object sender)
{
SysUserEditViewModule userEditor = new SysUserEditViewModule();
userEditor.ShowDialog();
if (userEditor.IsConfirm)
{
StartLoadTestItem();
}
}
private void OnModifyCommand(Object sender)
{
if (SelectedUser == null)
{
ShowErrorBox("<22><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ģ<DEB8>");
return;
}
if (SelectedUser.UserType == 1)
{
ShowErrorBox("<22><><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD>û<EFBFBD><C3BB><EFBFBD>");
return;
}
SysUserEditViewModule userEditor = new SysUserEditViewModule();
userEditor.UserId = SelectedUser.RecId;
userEditor.UserName = SelectedUser.UserName;
userEditor.PasswordText = Encryption.Decrypt(SelectedUser.Password);
userEditor.PasswordText2 = userEditor.PasswordText;
userEditor.SelectedUserRole = userEditor.UserRoles.FirstOrDefault(q=>q.RoleCode == SelectedUser.RoleId);
userEditor.ShowDialog();
if (userEditor.IsConfirm)
{
SelectedUser.UserName = userEditor.UserName;
SelectedUser.Password = Encryption.Encrypt(userEditor.PasswordText);
SelectedUser.RoleId = userEditor.SelectedUserRole.RoleCode;
}
}
private void OnModifyPasswordCommand(Object sender)
{
if (SelectedUser == null)
{
ShowErrorBox("<22><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ģ<DEB8>");
return;
}
PasswordEditViewModule userEditor = new PasswordEditViewModule();
userEditor.UserId = SelectedUser.RecId;
userEditor.RoleId = SelectedUser.RoleId;
userEditor.UserName = SelectedUser.UserName;
userEditor.PasswordText = Encryption.Decrypt(SelectedUser.Password);
userEditor.PasswordText2 = userEditor.PasswordText;
userEditor.ShowDialog();
if (userEditor.IsConfirm)
{
SelectedUser.UserName = userEditor.UserName;
SelectedUser.Password = Encryption.Encrypt(userEditor.PasswordText);
SelectedUser.RoleId = userEditor.RoleId;
}
}
private void OnDeleteCommand(Object sender)
{
if (!SysUsers.Any(q=>q.IsChecked))
{
ShowErrorBox("<22><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>");
return;
}
string deleteItems = string.Empty;
var checkedItems = SysUsers.Where(q => q.IsChecked).ToList();
for (int i = 0; i < checkedItems.Count; i++)
{
deleteItems = deleteItems + checkedItems[i].UserName + ",";
}
deleteItems = deleteItems.TrimEnd(',');
IMessageBoxService confirm = new MessageBoxServiceViewModule();
confirm.ShowOkCancel(string.Format(<><C8B7>Ҫɾ<D2AA><C9BE> {0} <20><>Щ<EFBFBD>û<EFBFBD><C3BB><EFBFBD> ?", deleteItems), CustomDialogIcons.OK);
if (confirm.DialogState == DialogState.Ok)
{
for (int i = 0; i < checkedItems.Count; i++)
{
if (checkedItems[i].UserType != 1)
{
SysUserDA.Delete(checkedItems[i].RecId);
}
}
StartLoadTestItem();
}
}
#endregion
}
}