using HxModel; using HxUserManagement.HxBLL; using HxUserManagement.HxDAL; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; 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 XHandler.Class; using XImagingXhandler.XDAL; using DataEntity.User; using XHandler.View.MethodProperty; using DriverLib.Engine; using DataEntity.Share; namespace XHandler.View.User { /// /// UserCenter.xaml 的交互逻辑 /// public partial class UserCenter : UserControl { #region CustomEvent public static readonly RoutedEvent editRoutedEvent = EventManager.RegisterRoutedEvent("editEvent", RoutingStrategy.Bubble, typeof(Class.CustomEvent.CustomRoutedEventHandler), typeof(UserCenter)); [Description("editEvent")] public event Class.CustomEvent.CustomRoutedEventHandler editEvent { add { this.AddHandler(editRoutedEvent, value); } remove { this.RemoveHandler(editRoutedEvent, value); } } private void RaiseEditEvent(string l) { Class.CustomRoutedEventArgs arg = new Class.CustomRoutedEventArgs(editRoutedEvent, l); this.RaiseEvent(arg); } public static readonly RoutedEvent resetPswdRoutedEvent = EventManager.RegisterRoutedEvent("resetPswdEvent", RoutingStrategy.Bubble, typeof(Class.CustomEvent.CustomRoutedEventHandler), typeof(UserCenter)); [Description("resetPswdEvent")] public event Class.CustomEvent.CustomRoutedEventHandler resetPswdEvent { add { this.AddHandler(resetPswdRoutedEvent, value); } remove { this.RemoveHandler(resetPswdRoutedEvent, value); } } private void RaiseResetPswdEvent(string l) { Class.CustomRoutedEventArgs arg = new Class.CustomRoutedEventArgs(resetPswdRoutedEvent, l); this.RaiseEvent(arg); } #endregion public List userInfoList; public List roleList; public List statusList; public UserCenter() { InitializeComponent(); Task.Factory.StartNew(() => { userInfoList = UserDB.GetAllUserInfo();//userInfoBLL.GetAllUserInfo(); OnFinished(); }); roleList = UserDB.GetRoles();//DataModel.GetRoles(); RoleTab role = new RoleTab(); role.name = Properties.Resources.strPleaseSelect; roleList.Insert(0, role); comboxRole.ItemsSource = roleList; comboxRole.SelectedIndex = 0; statusList = GetStatusList();//DataModel.GetStatusList(); statusList.Insert(0, Properties.Resources.strPleaseSelect); comboxAccountStatus.ItemsSource = statusList; comboxAccountStatus.SelectedIndex = 0; } public List GetStatusList() { List list = new List(); string disable = XImagingXhandler.XDAL.UserStatusEnum.DisablEnum.GetDescription(); list.Add(disable); string enable = XImagingXhandler.XDAL.UserStatusEnum.EnableEnum.GetDescription(); list.Add(enable); return list; } private void OnFinished() { Dispatcher.BeginInvoke(new Action(() => { datagrid.ItemsSource = userInfoList; })); } private void textboxUserName_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Refresh(); } } private void textboxPhone_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { Refresh(); } } private void comboxRole_SelectionChanged(object sender, SelectionChangedEventArgs e) { Refresh(); } private void comboxAccountStatus_SelectionChanged(object sender, SelectionChangedEventArgs e) { Refresh(); } private void datagrid_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex() + 1; } private void btnEdit_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; Button btn = (Button)sender; if (btn != null) { string id = (string)btn.Tag; RaiseEditEvent(id); } } private void btnDelete_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; Button btn = (Button)sender; if (btn != null) { string id = (string)btn.Tag; UserInfo user = datagrid.SelectedItem as UserInfo; string msg = string.Format(Properties.UserResource.strDeleteUserConfirm, user.username); //MessageBoxResult ret = MessageBox.Show(msg, "Tips", MessageBoxButton.YesNo); PlsToolTipWin plsToolTipWin; plsToolTipWin = new PlsToolTipWin(msg); plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; plsToolTipWin.Height = 1080; plsToolTipWin.Width = 1920; plsToolTipWin.btnClearData.Visibility = Visibility.Hidden; SolidColorBrush mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(70, 0, 0, 0)); plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush; MethodAction.Instance.StatusLamp(6); plsToolTipWin.ShowDialog(); if ((bool)plsToolTipWin.DialogResult==true)//ret == MessageBoxResult.Yes) { bool result = UserDB.DelUserById(id);//userInfoBLL.DelById(id); if (result) { plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strDeleteSuccess); plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; plsToolTipWin.Height = 450; plsToolTipWin.Width = 600; plsToolTipWin.btnCancel.Visibility = Visibility.Hidden; mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)); plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush; plsToolTipWin.ShowDialog(); } else { plsToolTipWin = new PlsToolTipWin(Properties.UserResource.strDeleteFailed); plsToolTipWin.WindowStartupLocation = WindowStartupLocation.CenterScreen; plsToolTipWin.Height = 450; plsToolTipWin.Width = 600; plsToolTipWin.btnCancel.Visibility = Visibility.Hidden; mybtn1_Brush = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0, 0, 0, 0)); plsToolTipWin.Background = (System.Windows.Media.Brush)mybtn1_Brush; plsToolTipWin.ShowDialog(); } Refresh(); } } } private void btnPswdReset_Click(object sender, RoutedEventArgs e) { if (EventResponseController.Instance.CanExecute() == false) return; Button btn = (Button)sender; if (btn != null) { string id = (string)btn.Tag; RaiseResetPswdEvent(id); } } private void ResetPassword_closeEvent(object sender, EventArgs e) { throw new NotImplementedException(); } public void Refresh() { string name = textboxUserName.Text; string phone = textboxPhone.Text; string state = ""; if (comboxAccountStatus.SelectedIndex > 0) state = comboxAccountStatus.SelectedIndex == 1 ? "0" : "1"; string authority = ""; if (comboxRole.SelectedIndex > 0) { RoleTab role = comboxRole.SelectedItem as RoleTab; authority = role.role_id; } userInfoList = Search(name, phone, state, authority); datagrid.ItemsSource = userInfoList; } private List Search(string name, string phone, string state, string authority) { return UserDB.Search(name, phone, state, authority); } } }