| | |
| | | using System; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | using HMI.Base; |
| | | using HMI.Core.Api; |
| | | using HMI.Base; |
| | | using HMI.Core.Util; |
| | | using HMI.MenuManage.Entity; |
| | | using HMI.MenuManage.Model; |
| | | using HMI.UI.Util; |
| | | using log4net; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Windows; |
| | | using System.Windows.Controls; |
| | | |
| | | namespace HMI.MenuManage |
| | | { |
| | |
| | | public partial class UserManage : PluginControl |
| | | { |
| | | UserManageModel Model; |
| | | private ILog log; |
| | | |
| | | public UserManage() |
| | | { |
| | | Model = new UserManageModel(); |
| | |
| | | Button btn = (Button)sender; |
| | | if (btn.Name == "addBtn") |
| | | { |
| | | UserModal userModal = new UserModal |
| | | try |
| | | { |
| | | Title = "新增用户", |
| | | Owner = Window.GetWindow(this), |
| | | sqliteHelper = Model.sqliteHelper |
| | | }; |
| | | if (userModal.Open(new UserData()) == true) |
| | | UserModal userModal = new UserModal |
| | | { |
| | | Title = LangUtil.Get("HMI.User.Add"), |
| | | Owner = Window.GetWindow(this), |
| | | sqliteHelper = Model.sqliteHelper |
| | | }; |
| | | if (userModal.Open(new UserData()) == true) |
| | | { |
| | | Model.LoadData(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Model.LoadData(); |
| | | log.Error("Add User Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.AddFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "refreshBtn") |
| | | { |
| | | Model.LoadData(); |
| | | } |
| | | else if (btn.Name == "editBtn") |
| | | { |
| | | UserModal userModal = new UserModal |
| | | { |
| | | Title = "编辑用户", |
| | | Owner = Window.GetWindow(this), |
| | | sqliteHelper = Model.sqliteHelper |
| | | }; |
| | | if (userModal.Open((UserData)btn.DataContext) == true) |
| | | try |
| | | { |
| | | Model.LoadData(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Refresh User Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.RefreshFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "delBtn") { } |
| | | else if (btn.Name == "editBtn") |
| | | { |
| | | try |
| | | { |
| | | UserModal userModal = new UserModal |
| | | { |
| | | Title = LangUtil.Get("HMI.User.Edit"), |
| | | Owner = Window.GetWindow(this), |
| | | sqliteHelper = Model.sqliteHelper |
| | | }; |
| | | if (userModal.Open((UserData)btn.DataContext) == true) |
| | | { |
| | | Model.LoadData(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Edit User Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.EditFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "deleteBatchBtn") |
| | | { |
| | | try |
| | | { |
| | | List<string> usernames = Model.DataSource.Where(x => x.Selected).Select(x => x.Username).ToList(); |
| | | if (usernames == null || usernames.Count <= 0) |
| | | { |
| | | ToastHelper.Warning(Window.GetWindow(this), LangUtil.Get("HMI.NoDeleteData")); |
| | | return; |
| | | } |
| | | |
| | | var res = MsgBoxHelper.WarnMessage(Window.GetWindow(this), |
| | | string.Format(LangUtil.Get("HMI.MakeSureDeletes"), usernames.Count)); |
| | | if (res == MessageBoxResult.OK) |
| | | { |
| | | Model.DeleteUserByUsernames(usernames); |
| | | Model.LoadData(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Delete User Batch Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.DeleteFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "delBtn") |
| | | { |
| | | try |
| | | { |
| | | var data = (UserData)((Button)sender).DataContext; |
| | | var res = MsgBoxHelper.WarnMessage(Window.GetWindow(this), |
| | | string.Format(LangUtil.Get("HMI.MakeSureDeleteSingle"), data.Name)); |
| | | if (res == MessageBoxResult.OK) |
| | | { |
| | | Model.DeleteUserByUsername(data.Username); |
| | | Model.LoadData(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Delete User Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.DeleteFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | else if (btn.Name == "saveRoleBtn") |
| | | { |
| | | try |
| | | { |
| | | Model.SaveUserRole(); |
| | | Model.LoadUserRole(); |
| | | ToastHelper.Success(Window.GetWindow(this), "保存成功"); |
| | | ToastHelper.Success(Window.GetWindow(this), LangUtil.Get("App.SaveSuccess")); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | log.Error("Update User-Role Rel Failed.", ex); |
| | | ToastHelper.Error(Window.GetWindow(this), $"{LangUtil.Get("App.SaveFailed")}: {ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void SetLogger(ILog logger) |
| | | { |
| | | log = logger; |
| | | } |
| | | |
| | | public void SetBaseFolder(string folder) |
| | | { |
| | | throw new NotImplementedException(); |
| | | } |
| | | } |
| | | } |