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.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 { /// /// MarkLevelWindow.xaml 的交互逻辑 /// public partial class MarkLevelWindow : Window { private bool isAdd = true; private MarkLevelEntity markLevel = null; public MarkLevelWindow(MarkLevelEntity markLevelEntity) { try { InitializeComponent(); this.Owner = AppData.Instance.MainWindow; markLevel = markLevelEntity; this.Closed += (a, b) => AppData.Instance.MainWindow.Activate(); } catch (Exception ex) { ExLog(ex, "MarkLevelWindow"); } } public MarkLevelWindow(MarkLevelEntity markLevelEntity, bool b) { try { InitializeComponent(); this.Owner = AppData.Instance.MainWindow; isAdd = false; markLevel = markLevelEntity; //this._title_TextBlock.Text = "编辑"; this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083"); this._name_TextBox.Text = markLevel.name; this._min_TextBox.Text = markLevel.min.ToString(); this._max_TextBox.Text = markLevel.max.ToString(); this.Closed += (a, b) => AppData.Instance.MainWindow.Activate(); } catch (Exception ex) { ExLog(ex, "MarkLevelWindow"); } } 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("0229")); return; } if(nameString.Length > 10) { //MessageBoxShow("级别名称长度为1-10"); MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0229")); return; } if(int.TryParse(this._min_TextBox.Text.Trim(), out int newMinTime) && newMinTime > 0) { } else { //MessageBoxShow("最小范围只能输入大于0的数字"); MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0294")); return; } if (int.TryParse(this._max_TextBox.Text.Trim(), out int newMaxTime) && newMaxTime > 0) { } else { //MessageBoxShow("最大范围只能输入大于0的数字"); MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0295")); return; } if (newMaxTime < newMinTime) { //MessageBoxShow("最大范围不能小于最小范围"); MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0296")); return; } string remakr = this._remake_TextBox.Text.Trim(); MarkLevelEntity newLevel = new MarkLevelEntity(); newLevel.name = nameString; newLevel.min = newMinTime; newLevel.max = newMaxTime; newLevel.id = markLevel.id; newLevel.info = remakr; var pro = AppData.Instance.GetMarkSettingProvider(); string error = null; if (isAdd) error = pro.AddMarkLevelApi(newLevel); else error = pro.UpdateMarkLevelApi(JsonConvert.SerializeObject(newLevel)); if (!string.IsNullOrEmpty(error)) { //MessageBoxShow($"操作失败,{error}"); MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}"); return; } markLevel.id = newLevel.id; markLevel.name = nameString; markLevel.min = newMinTime; markLevel.max = newMaxTime; markLevel.info= remakr; this.DialogResult = true; return; } catch (Exception ex) { ExLog(ex, "Ok_Click"); MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}"); } } private void MessageBoxShow(string mess) { this.message.Text = mess; } private void ExLog(Exception ex, string name) { AppData.Instance.LogService.ExceptionLog(ex, $"MarkUseView.{name}", LogEnum.RunException); } private void ErrorLog(string message, LogEnum logType) { AppData.Instance.LogService.TLLog($"MarkUseView.{message}", logType); } private void Cancel_MouseUp(object sender, MouseButtonEventArgs e) { this.DialogResult = false; return; } } }