| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.AppSetting;
- using ivf_tl_Entity.Entity.Mark;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Manage.Converts;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- 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.Shapes;
- namespace ivf_tl_Manage.Win
- {
- /// <summary>
- /// UserEntityWindow.xaml 的交互逻辑
- /// </summary>
- public partial class UserEntityWindow : Window
- {
- private bool isAdd = true;
- private UserManageEntity UserManageEntity { get; set; } = null;
- public UserEntityWindow(ObservableCollection<RoleEntity> roleList)
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- this._role_ComBox.ItemsSource = roleList;
- this.Closed += (a, b) =>
- {
- AppData.Instance.MainWindow.Activate();
- };
- }
- public UserEntityWindow(UserManageEntity markKeyEntity, ObservableCollection<RoleEntity> roleList)
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- this._role_ComBox.ItemsSource = roleList;
- UserManageEntity = markKeyEntity;
- if(markKeyEntity.roles != null && markKeyEntity.roles.Any() && roleList.Any())
- {
- this._role_ComBox.SelectedItem = roleList.FirstOrDefault(x => x.id == markKeyEntity.roles.First().id);
- }
- isAdd = false;
- //this._title_TextBlock.Text = "编辑";
- this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
- this._name_TextBox.Text = UserManageEntity.username;
- this._account_TextBox.Text = UserManageEntity.account;
- this._password_TextBox.Text = "********";
- this._passSure_TextBox.Text = "********";
- this._account_TextBox.IsEnabled = false;
- this._password_TextBox.IsEnabled = false;
- this._passSure_TextBox.IsEnabled = false;
- this.Closed += (a, b) =>
- {
- AppData.Instance.MainWindow.Activate();
- };
- }
- private void MessageBoxShow(string mess)
- {
- this.message.Text = mess;
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogService.ExceptionLog(ex, $"UserEntityWindow.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- AppData.Instance.LogService.TLLog($"UserEntityWindow.{message}", logType);
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- return;
- }
- private void Ok_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- string nameString = this._name_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(nameString))
- {
- //MessageBoxShow($"用户名称不能为空");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0135"));
- return;
- }
- string accountString = this._account_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(accountString))
- {
- //MessageBoxShow($"登录账号不能为空");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0131"));
- return;
- }
- string wordString = this._password_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(wordString))
- {
- //MessageBoxShow($"登录密码不能为空");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0136"));
- return;
- }
- string wordSureString = this._passSure_TextBox.Text.Trim();
- if (string.IsNullOrEmpty(wordSureString))
- {
- //MessageBoxShow($"确认密码不能为空");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0137"));
- return;
- }
- if(wordString != wordSureString)
- {
- //MessageBoxShow($"两次密码不一致");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0285"));
- return;
- }
- if(!(this._role_ComBox.SelectedItem is RoleEntity currentRole))
- {
- //MessageBoxShow($"请选择角色");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0133"));
- return;
- }
- long roleId = currentRole.id;
- var pro = AppData.Instance.GetSettingProvider();
- string error = null;
- if (isAdd)
- {
- string body = JsonConvert.SerializeObject(new
- {
- account = accountString,
- password = wordString,
- username = nameString,
- verifyPassword = wordSureString,
- roleIds = new List<long> { roleId },
- });
- error = pro.AddUserApi(body);
- }
- else
- {
- string body = JsonConvert.SerializeObject(new
- {
- id = UserManageEntity.id,
- username= nameString,
- roleIds=new List<long> { roleId },
- });
- error = pro.EditUserApi(body);
- }
- if (!string.IsNullOrEmpty(error))
- {
- //MessageBoxShow($"操作失败,{error}");
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
- return;
- }
- if (!isAdd)
- {
- UserManageEntity.username = nameString;
- UserManageEntity.roles = new List<RoleEntity> { currentRole };
- }
- this.DialogResult = true;
- return;
- }
- catch (Exception ex)
- {
- ExLog(ex, "Ok_Click");
- //MessageBoxShow($"操作失败:{ex.Message}");
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")}:{ex.Message}");
- }
- }
- }
- }
|