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
{
///
/// MarkModelWindow.xaml 的交互逻辑
///
public partial class MarkModelWindow : Window
{
private bool isAdd = true;
private MarkEntity markEntity = null;
public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection keySource)
{
try
{
InitializeComponent();
this.Owner = AppData.Instance.MainWindow;
markEntity = p;
MarkTypeSource = new ObservableCollection { markModelTypeEntity };
this._markType_ComBox.SelectedIndex = 0;
MarkKeySource = keySource;
this._parent_ComBox.ItemsSource = new List { p.ParentMark };
this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
}
catch (Exception ex)
{
ExLog(ex, "MarkModelWindow");
}
}
public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection keySource, bool b)
{
try
{
InitializeComponent();
this.Owner = AppData.Instance.MainWindow;
this._parent_ComBox.ItemsSource = new List { p.ParentMark };
isAdd = false;
markEntity = p;
MarkTypeSource = new ObservableCollection { 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)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 MarkTypeSource
{
get { return (ObservableCollection)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), typeof(MarkModelWindow), new PropertyMetadata(null));
public ObservableCollection MarkKeySource
{
get { return (ObservableCollection)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), typeof(MarkModelWindow), new PropertyMetadata(null));
public Dictionary UnitSource
{
get { return (Dictionary)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), typeof(MarkModelWindow), new PropertyMetadata(new Dictionary { { 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);
}
}
}