| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- using ivf_tl_Entity.Entity;
- using ivf_tl_Entity.Entity.Mark;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Entity.Response;
- 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>
- /// MarkModelWindow.xaml 的交互逻辑
- /// </summary>
- public partial class MarkModelWindow : Window
- {
- private bool isAdd = true;
- private MarkEntity markEntity = null;
- public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection<MarkKeyEntity> keySource)
- {
- try
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- markEntity = p;
- MarkTypeSource = new ObservableCollection<MarkModelTypeEntity> { markModelTypeEntity };
- this._markType_ComBox.SelectedIndex = 0;
- MarkKeySource = keySource;
- this._parent_ComBox.ItemsSource = new List<MarkEntity> { p.ParentMark };
- this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
- }
- catch (Exception ex)
- {
- ExLog(ex, "MarkModelWindow");
- }
- }
- public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection<MarkKeyEntity> keySource, bool b)
- {
- try
- {
- InitializeComponent();
- this.Owner = AppData.Instance.MainWindow;
- this._parent_ComBox.ItemsSource = new List<MarkEntity> { p.ParentMark };
- isAdd = false;
- markEntity = p;
- MarkTypeSource = new ObservableCollection<MarkModelTypeEntity> { markModelTypeEntity };
- this._markType_ComBox.SelectedIndex = 0;
- MarkKeySource = keySource;
- //this._title_TextBlock.Text = "编辑";
- this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
- this._orderNum_TextBox.Text = markEntity.orderNum.ToString();
- this._markKey_ComBox.SelectedItem = MarkKeySource.FirstOrDefault(x => x.markKey == markEntity.markKey);
- this._weight_TextBox.Text = markEntity.weight.ToString("F2");
- //关键值计算
- if (UnitSource.ContainsKey(markEntity.unit))
- {
- this._unit_ComBox.SelectedItem = UnitSource.FirstOrDefault(x => x.Key == markEntity.unit);
- }
- if (markEntity.child == 0) this._noChildren_RadioButton.IsChecked = true;
- if (markEntity.defaultValue == 1) this._defeat_RadioButton.IsChecked = true;
- if (markEntity.keyNode == 1) this._scores_CheckBox.IsChecked = true;
- this._markKey_ComBox.IsEnabled = false;
- this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
- }
- catch (Exception ex)
- {
- ExLog(ex, "MarkModelWindow");
- }
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- return;
- }
- private void Ok_Click(object sender, RoutedEventArgs e)
- {
- try
- {
- if (int.TryParse(this._orderNum_TextBox.Text.Trim(), out int newNum) && newNum >= 0)
- {
- }
- else
- {
- //MessageBoxShow("显示序号只能输入大于0的数字");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0284"));
- return;
- }
- if (decimal.TryParse(this._weight_TextBox.Text.Trim(), out decimal newWeight) && newWeight >= 0)
- {
- }
- else
- {
- //MessageBoxShow("权重值只能输入0-100的数字");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0288"));
- return;
- }
- int newChild = 1;
- if (this._noChildren_RadioButton.IsChecked == true) newChild = 0;
- int newDef = 0;
- if (this._defeat_RadioButton.IsChecked == true) newDef = 1;
- var cKey = (MarkKeyEntity)this._markKey_ComBox.SelectedItem;
- if (cKey == null)
- {
- //MessageBoxShow("请选择阶段名称");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0116"));
- return;
- }
- var cUnit = (KeyValuePair<int, string>)this._unit_ComBox.SelectedItem;
- if (cUnit.Key == 0)
- {
- //MessageBoxShow("请选择权重值单位");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0226"));
- return;
- }
- if (newChild == 0 && cUnit.Value == "%")
- {
- //MessageBoxShow("不存在下级节点时,单位只能是分");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0297"));
- return;
- }
- if (newChild == 1 && cUnit.Value == "分")
- {
- //MessageBoxShow("存在下级节点时,单位只能是%");
- MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0298"));
- return;
- }
- int newKeyNode = 0;
- if (this._scores_CheckBox.IsChecked == true) newKeyNode = 1;
- MarkModelResponse newEntity = new MarkModelResponse();
- newEntity.id = markEntity.id;
- newEntity.child = newChild;
- //newEntity.defaultValue = newDef;
- newEntity.keyId = cKey.id;
- newEntity.markKey = cKey.markKey;
- newEntity.name = cKey.name;
- newEntity.keyNode = newKeyNode;
- newEntity.orderNum = newNum;
- newEntity.weight = newWeight;
- newEntity.unit = cUnit.Key;
- newEntity.state = markEntity.state;
- newEntity.parentId = markEntity.parentId;
- newEntity.model = markEntity.model;
- newEntity.level = markEntity.level;
- var pro = AppData.Instance.GetMarkSettingProvider();
- string error = null;
- if (isAdd) error = pro.AddMarkEntityApi(newEntity);
- else error = pro.UpdateMarkEntityApi(JsonConvert.SerializeObject(newEntity));
- if (!string.IsNullOrEmpty(error))
- {
- //MessageBoxShow($"操作失败,{error}");
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
- return;
- }
- markEntity.keyNode = newEntity.keyNode;
- markEntity.id = newEntity.id;
- markEntity.child = newEntity.child;
- //markEntity.defaultValue = newEntity.defaultValue;
- markEntity.markKey = newEntity.markKey;
- markEntity.model = newEntity.model;
- markEntity.name = newEntity.name;
- markEntity.orderNum = newEntity.orderNum;
- markEntity.parentId = newEntity.parentId;
- markEntity.state = newEntity.state;
- markEntity.unit = newEntity.unit;
- markEntity.weight = newEntity.weight;
- markEntity.level = newEntity.level;
- this.DialogResult = true;
- return;
- }
- catch (Exception ex)
- {
- ExLog(ex, "Ok_Click");
- MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}");
- }
- }
- public ObservableCollection<MarkModelTypeEntity> MarkTypeSource
- {
- get { return (ObservableCollection<MarkModelTypeEntity>)GetValue(MarkTypeSourceProperty); }
- set { SetValue(MarkTypeSourceProperty, value); }
- }
- // Using a DependencyProperty as the backing store for MarkTypeSource. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MarkTypeSourceProperty =
- DependencyProperty.Register("MarkTypeSource", typeof(ObservableCollection<MarkModelTypeEntity>), typeof(MarkModelWindow), new PropertyMetadata(null));
- public ObservableCollection<MarkKeyEntity> MarkKeySource
- {
- get { return (ObservableCollection<MarkKeyEntity>)GetValue(MarkKeySourceProperty); }
- set { SetValue(MarkKeySourceProperty, value); }
- }
- // Using a DependencyProperty as the backing store for MarkKeySource. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MarkKeySourceProperty =
- DependencyProperty.Register("MarkKeySource", typeof(ObservableCollection<MarkKeyEntity>), typeof(MarkModelWindow), new PropertyMetadata(null));
- public Dictionary<int, string> UnitSource
- {
- get { return (Dictionary<int, string>)GetValue(UnitSourceProperty); }
- set { SetValue(UnitSourceProperty, value); }
- }
- // Using a DependencyProperty as the backing store for UnitSource. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty UnitSourceProperty =
- DependencyProperty.Register("UnitSource", typeof(Dictionary<int, string>), typeof(MarkModelWindow), new PropertyMetadata(new Dictionary<int, string> { { 2, "%" }, { 1, "分" } }));
- private void MessageBoxShow(string mess)
- {
- this.message.Text = mess;
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogService.ExceptionLog(ex, $"MarkQucikWindow.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- AppData.Instance.LogService.TLLog($"MarkQucikWindow.{message}", logType);
- }
- }
- }
|