using CommunityToolkit.Mvvm.ComponentModel; using ivf_tl_Entity.Entity; using ivf_tl_Entity.Entity.Mark; using ivf_tl_Entity.Enums; using ivf_tl_Manage.Converts; using ivf_tl_Manage.Win; using ivf_tl_Service.HttpProvider; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox; namespace ivf_tl_Manage.ViewModels { public partial class MarkSettingViewModel : BaseViewModel { [ObservableProperty] private string currentSelectTitle; [ObservableProperty] private ObservableCollection markModelTypeList = new ObservableCollection(); [ObservableProperty] private ObservableCollection currentMarkModelTypeList = new ObservableCollection(); [ObservableProperty] private MarkModelTypeEntity currentMarkModelType = null; [ObservableProperty] private ObservableCollection markKeyList = new ObservableCollection(); [ObservableProperty] private ObservableCollection currentMarkKeyList = new ObservableCollection(); [ObservableProperty] private ObservableCollection quickButtonList = new ObservableCollection(); [ObservableProperty] private ObservableCollection currentQuickButtonList = new ObservableCollection(); [ObservableProperty] private ObservableCollection markLevelList = new ObservableCollection(); [ObservableProperty] private ObservableCollection currentMarkLevelList = new ObservableCollection(); [ObservableProperty] private ObservableCollection markEntityList = new ObservableCollection(); [ObservableProperty] private ObservableCollection markWeightList = new ObservableCollection(); [ObservableProperty] private int dataPageCount = -1; [ObservableProperty] private bool isVisPage = false; private int currentPage = 0; public int DataPageSize { get; set; } = 10; public string DataType { get; set; } = "1"; private MarkSettingProvider markSettingProvider = null; public MarkSettingViewModel() { base.ViewModelName = nameof(MarkSettingViewModel); try { int k = 1; //CurrentSelectTitle = "KEY值维护"; CurrentSelectTitle = KeyToStringConvert.GetLanguageStringByKey("0236"); markSettingProvider = AppData.Instance.GetMarkSettingProvider(); MarkKeyList.Clear(); var newList = markSettingProvider.GetAllMarkKeyApi().OrderBy(x => x.orderNum).ToList(); foreach (var item in newList) { item.num = k++; MarkKeyList.Add(item); } newList.Clear(); MarkModelTypeList = new ObservableCollection(markSettingProvider.GetAllMarkModelTypeApi()); if (MarkModelTypeList.Any()) { if (MarkModelTypeList.Count >= 2) { //MarkModelTypeList.Insert(0, new MarkModelTypeEntity { name = "全部", id = 0 }); MarkModelTypeList.Insert(0, new MarkModelTypeEntity { name = KeyToStringConvert.GetLanguageStringByKey("0027"), id = 0 }); } CurrentMarkModelType = MarkModelTypeList[0]; } k = 1; MarkLevelList = new ObservableCollection(markSettingProvider.GetAllMarkLevelApi()); foreach (var item in MarkLevelList) { item.num = k++; } k = 1; QuickButtonList.Clear(); var quickNewList = markSettingProvider.GetAllQuickButtonsApi().OrderBy(x => x.orderNum).ToList(); foreach (var item in quickNewList) { item.num = k++; QuickButtonList.Add(item); } quickNewList.Clear(); MarkWeightList = new ObservableCollection(markSettingProvider.GetMarkWeightList()); CurrentMarkKeyList = new ObservableCollection(MarkKeyList.Take(DataPageSize)); DataPageCount = MarkKeyList.Count; //CurrentSelectTitle = "模型设置"; //CurrentMarkModelTypeList = new ObservableCollection(MarkModelTypeList.Take(DataPageSize)); //DataPageCount = MarkModelTypeList.Count; } catch (Exception ex) { ExLog(ex, "MarkSettingViewModel"); } } partial void OnCurrentMarkModelTypeChanged(MarkModelTypeEntity value) { if (value == null) { MarkEntityList.Clear(); return; } MarkEntityList = new ObservableCollection(markSettingProvider.GetAllMarkEntityApi(CurrentMarkModelType.id)); } /// /// 刷新页面数据 /// /// public void DataChange(string newCurrentSelectTitle, string dataType) { try { CurrentSelectTitle = newCurrentSelectTitle; int newCount = -1; DataType = dataType; IsVisPage = false; switch (DataType) { case "1": newCount = MarkKeyList.Count; break; case "2": newCount = MarkModelTypeList.Count; break; case "3": newCount = MarkLevelList.Count; break; case "4": newCount = QuickButtonList.Count; break; case "5": IsVisPage = true; break; case "6": IsVisPage = true; break; } //switch (CurrentSelectTitle) //{ // case "KEY值维护": // newCount = MarkKeyList.Count; // break; // case "模型设置": // newCount = MarkModelTypeList.Count; // break; // case "级别设置": // newCount = MarkLevelList.Count; // break; // case "快捷定位设置": // newCount = QuickButtonList.Count; // break; // case "模型配置": // break; //} DataPageCount = -1; DataPageCount = newCount; } catch (Exception ex) { ExLog(ex, "DataChange"); } } public void DataLoad(int obj) { try { currentPage = obj; switch (DataType) { case "1": ModelKeyData(obj); break; case "2": ModelTypeData(obj); break; case "3": MarkLevelData(obj); break; case "4": QuickButtonData(obj); break; case "5": break; } //switch (CurrentSelectTitle) //{ // case "KEY值维护": // ModelKeyData(obj); // break; // case "模型设置": // ModelTypeData(obj); // break; // case "级别设置": // MarkLevelData(obj); // break; // case "快捷定位设置": // QuickButtonData(obj); // break; // case "模型配置": // break; //} } catch (Exception ex) { ExLog(ex, "DataLoad"); } } private void ModelKeyData(int obj) { CurrentMarkKeyList.Clear(); var list = MarkKeyList.Skip(DataPageSize * (obj - 1)).Take(DataPageSize); foreach (var item in list) { CurrentMarkKeyList.Add(item); } } private void ModelTypeData(int obj) { CurrentMarkModelTypeList.Clear(); var list = MarkModelTypeList.Skip(DataPageSize * (obj - 1)).Take(DataPageSize); foreach (var item in list) { CurrentMarkModelTypeList.Add(item); } } private void MarkLevelData(int obj) { CurrentMarkLevelList.Clear(); var list = MarkLevelList.Skip(DataPageSize * (obj - 1)).Take(DataPageSize); foreach (var item in list) { CurrentMarkLevelList.Add(item); } } private void QuickButtonData(int obj) { CurrentQuickButtonList.Clear(); var list = QuickButtonList.Skip(DataPageSize * (obj - 1)).Take(DataPageSize); foreach (var item in list) { CurrentQuickButtonList.Add(item); } } /// /// 添加操作 /// public void AddEntity() { try { switch (DataType) { case "1": AddMarkKey(); break; case "2": AddMarkType(); break; case "3": AddMarkLevel(); break; case "4": AddMarkQuick(); break; case "5": AddMarkModel(); break; case "6": AddMarkWeight(null); break; } } catch (Exception ex) { ExLog(ex, "AddEntity"); } } private void AddMarkKey() { try { int newOrderNum = 1; int newNum = 1; if (MarkKeyList.Any()) { newOrderNum = MarkKeyList.Last().orderNum + 1; newNum = MarkKeyList.Last().num + 1; } MarkKeyEntity markKeyEntity = new MarkKeyEntity() { orderNum = newOrderNum, num = newNum }; AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkKeyWindow(markKeyEntity).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; MarkKeyList.Add(markKeyEntity); if (CurrentMarkKeyList.Count < 10) { CurrentMarkKeyList.Add(markKeyEntity); } //if (CurrentMarkKeyList.Any()) //{ // var num = CurrentMarkKeyList.Count; // if (num < 10) // { // CurrentMarkKeyList.Add(markKeyEntity); // } //} //else //{ // markKeyEntity.num = 1; // CurrentMarkKeyList.Add(markKeyEntity); //} } catch (Exception ex) { ExLog(ex, "AddMarkKey"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void AddMarkType() { try { MarkModelTypeEntity markModelTypeEntity = new MarkModelTypeEntity(); AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkTypeWindow(markModelTypeEntity).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; MarkModelTypeList.Add(markModelTypeEntity); if (CurrentMarkModelTypeList.Count < 10) { CurrentMarkModelTypeList.Add(markModelTypeEntity); } } catch (Exception ex) { ExLog(ex, "AddMarkType"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void AddMarkLevel() { try { int newNum = 1; if (MarkLevelList.Any()) { newNum = MarkLevelList.Last().num + 1; } MarkLevelEntity markLevel = new MarkLevelEntity() { num = newNum }; AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkLevelWindow(markLevel).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; MarkLevelList.Add(markLevel); if (CurrentMarkLevelList.Count < 10) { CurrentMarkLevelList.Add(markLevel); } //if (CurrentMarkLevelList.Any()) //{ // var num = CurrentMarkLevelList.Last().num; // if (num < 10) // { // markLevel.num = num + 1; // CurrentMarkLevelList.Add(markLevel); // } //} //else //{ // markLevel.num = 1; // CurrentMarkLevelList.Add(markLevel); //} } catch (Exception ex) { ExLog(ex, "AddMarkLevel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void AddMarkQuick() { try { int newOrderNum = 1; int newNum = 1; if (QuickButtonList.Any()) { newOrderNum = QuickButtonList.Last().orderNum + 1; newNum = QuickButtonList.Last().num + 1; } ButtonEntity buttonEntity = new ButtonEntity() { type = "QUICK_BUTTON", num = newNum, orderNum = newOrderNum }; AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkQucikWindow(buttonEntity).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; QuickButtonList.Add(buttonEntity); var newList = QuickButtonList.OrderBy(x => x.orderNum).ToList(); QuickButtonList.Clear(); int k = 1; foreach (var item in newList) { item.num = k++; QuickButtonList.Add(item); } newList.Clear(); QuickButtonData(currentPage); } catch (Exception ex) { ExLog(ex, "AddMarkQuick"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void AddMarkModel() { try { MarkEntity newEntity = new MarkEntity() { level = 1, parentId = -1, state = 1 }; AppData.Instance.MainWindowViewModel.MaskVisibility = true; List listType = new List(); if (CurrentMarkModelType.id == 0) { listType = MarkModelTypeList.Where(x => x.id != 0).ToList(); } else { listType.Add(CurrentMarkModelType); } if (new MarkModelOneWindow(newEntity, listType, MarkKeyList).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; int k = 0; for (int i = 0; i < MarkEntityList.Count; i++) { var item = MarkEntityList[i]; if (item.orderNum > newEntity.orderNum) { k = i; break; } k = i + 1; } if (k < 0) k = 0; MarkEntityList.Insert(k, newEntity); } catch (Exception ex) { ExLog(ex, "AddMarkModel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } /// /// 编辑操作 /// /// public void EditEntity(object tag) { try { switch (DataType) { case "1": EditMarkKey((MarkKeyEntity)tag); break; case "2": EditMarkType((MarkModelTypeEntity)tag); break; case "3": EditMarkLevel((MarkLevelEntity)tag); break; case "4": EditMarkQuick((ButtonEntity)tag); break; case "5": break; } //switch (CurrentSelectTitle) //{ // case "KEY值维护": // EditMarkKey((MarkKeyEntity)tag); // break; // case "模型设置": // EditMarkType((MarkModelTypeEntity)tag); // break; // case "级别设置": // EditMarkLevel((MarkLevelEntity)tag); // break; // case "快捷定位设置": // EditMarkQuick((ButtonEntity)tag); // break; // case "模型配置": // break; //} } catch (Exception ex) { ExLog(ex, "EditEntity"); } } private void EditMarkKey(MarkKeyEntity markKeyEntity) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; new MarkKeyWindow(markKeyEntity, false).ShowDialog(); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } catch (Exception ex) { ExLog(ex, "EditMarkKey"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void EditMarkType(MarkModelTypeEntity markModelTypeEntity) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; new MarkTypeWindow(markModelTypeEntity, false).ShowDialog(); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } catch (Exception ex) { ExLog(ex, "EditMarkType"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void EditMarkLevel(MarkLevelEntity markLevel) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; new MarkLevelWindow(markLevel, false).ShowDialog(); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } catch (Exception ex) { ExLog(ex, "EditMarkLevel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void EditMarkQuick(ButtonEntity buttonEntity) { try { var oldNum = buttonEntity.orderNum; AppData.Instance.MainWindowViewModel.MaskVisibility = true; var a = new MarkQucikWindow(buttonEntity, false).ShowDialog(); AppData.Instance.MainWindowViewModel.MaskVisibility = false; if (a != true) return; if (oldNum == buttonEntity.orderNum) return; var newList = QuickButtonList.OrderBy(x => x.orderNum).ToList(); QuickButtonList.Clear(); int k = 1; foreach (var item in newList) { item.num = k++; QuickButtonList.Add(item); } newList.Clear(); QuickButtonData(currentPage); } catch (Exception ex) { ExLog(ex, "EditMarkQuick"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } /// /// 删除操作 /// /// public void DeleteEntity(object tag) { try { //switch (CurrentSelectTitle) //{ // case "KEY值维护": // DeleteMarkKey((MarkKeyEntity)tag); // break; // case "模型设置": // DeleteMarkType((MarkModelTypeEntity)tag); // break; // case "级别设置": // DeleteMarkLevel((MarkLevelEntity)tag); // break; // case "快捷定位设置": // DeleteMarkQuick((ButtonEntity)tag); // break; // case "模型配置": // break; //} switch (DataType) { case "1": DeleteMarkKey((MarkKeyEntity)tag); break; case "2": DeleteMarkType((MarkModelTypeEntity)tag); break; case "3": DeleteMarkLevel((MarkLevelEntity)tag); break; case "4": DeleteMarkQuick((ButtonEntity)tag); break; case "5": break; } //DataChange(CurrentSelectTitle); } catch (Exception ex) { ExLog(ex, "DeleteEntity"); } } private void DeleteMarkKey(MarkKeyEntity pro) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.name}的KEY值信息吗?", AppData.Instance.MainWindow).ShowDialog() != true if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteMarkKeyApi(pro.id); if (!string.IsNullOrEmpty(error)) { //ToastMessageShow($"删除失败:{error}"); ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return; } MarkKeyList.Remove(pro); CurrentMarkKeyList.Remove(pro); } catch (Exception ex) { ExLog(ex, "DeleteMarkKey"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void DeleteMarkType(MarkModelTypeEntity pro) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.name}的模型设置吗?", AppData.Instance.MainWindow).ShowDialog() != true if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteMarkModelAndTypeApi(pro.id); if (!string.IsNullOrEmpty(error)) { //ToastMessageShow($"删除失败:{error}"); ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return; } MarkModelTypeList.Remove(pro); CurrentMarkModelTypeList.Remove(pro); } catch (Exception ex) { ExLog(ex, "DeleteMarkType"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void DeleteMarkLevel(MarkLevelEntity pro) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.name}的级别设置吗?", AppData.Instance.MainWindow).ShowDialog() != true if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteMarkLevelApi(pro.id); if (!string.IsNullOrEmpty(error)) { //ToastMessageShow($"删除失败:{error}"); ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return; } MarkLevelList.Remove(pro); CurrentMarkLevelList.Remove(pro); } catch (Exception ex) { ExLog(ex, "DeleteMarkLevel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } private void DeleteMarkQuick(ButtonEntity pro) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.buttonName}的快捷定位设置吗?", AppData.Instance.MainWindow).ShowDialog() != true if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteButtonApi(pro.id); if (!string.IsNullOrEmpty(error)) { //ToastMessageShow($"删除失败:{error}"); ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return; } QuickButtonList.Remove(pro); CurrentQuickButtonList.Remove(pro); } catch (Exception ex) { ExLog(ex, "DeleteMarkQuick"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; } } /// /// 评分配置操作 /// /// /// public bool MarkOper(MarkEntity arg1, string arg2) { try { switch (arg2) { case "add": return AddMarkModel(arg1); case "edit": return EditMarkModel(arg1); case "del": return DelereMarkModel(arg1); } return false; } catch (Exception ex) { ExLog(ex, "MarkOper"); return false; } } private bool AddMarkModel(MarkEntity parent) { try { MarkEntity newEntity = new MarkEntity() { level = (parent.level + 1), parentId = parent.id, state = 1, model = parent.model, ParentMark = parent, }; AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkModelWindow(newEntity, MarkModelTypeList.FirstOrDefault(x => x.id == parent.model), MarkKeyList).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; if (parent.children == null || !parent.children.Any()) { parent.children = new ObservableCollection() { newEntity }; } else { parent.children.Add(newEntity); var list1 = parent.children.OrderBy(x => x.orderNum).ToList(); parent.children.Clear(); foreach (var item in list1) { parent.children.Add(item); } list1.Clear(); } return true; } catch (Exception ex) { ExLog(ex, "AddMarkModel"); return false; } } private bool EditMarkModel(MarkEntity pro) { try { if (pro.level == 1) { AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkModelOneWindow(pro, MarkModelTypeList.FirstOrDefault(x => x.id == pro.model), MarkKeyList, true).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; var list = MarkEntityList.OrderBy(x => x.orderNum).ToList(); MarkEntityList.Clear(); foreach (var item in list) { MarkEntityList.Add(item); } list.Clear(); return true; } AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (new MarkModelWindow(pro, MarkModelTypeList.FirstOrDefault(x => x.id == pro.model), MarkKeyList, false).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; var list1 = pro.ParentMark.children.OrderBy(x => x.orderNum).ToList(); pro.ParentMark.children.Clear(); foreach (var item in list1) { pro.ParentMark.children.Add(item); } list1.Clear(); return true; } catch (Exception ex) { ExLog(ex, "EditMarkModel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } public bool DelereMarkModel(MarkEntity pro) { try { if (pro.children != null && pro.children.Any()) { //ToastMessageShow($"当前节点存在子节点,请先删除子节点再进行尝试"); ToastMessageShow(KeyToStringConvert.GetLanguageStringByKey("0338")); return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.name}的模型配置吗?", AppData.Instance.MainWindow).ShowDialog() != true if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteMarkModelAndTypeApi(pro.id); if (!string.IsNullOrEmpty(error)) { //ToastMessageShow($"删除失败:{error}"); ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return false; } if (pro.ParentMark != null && pro.ParentMark.children != null) { pro.ParentMark.children.Remove(pro); if (!pro.ParentMark.children.Any()) { pro.ParentMark.children = new ObservableCollection(); } return true; } if (pro.level == 1 && MarkEntityList.Contains(pro)) { MarkEntityList.Remove(pro); return true; } return true; } catch (Exception ex) { ExLog(ex, "DelereMarkModel"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } public string SetMarkModelTypeEntityState(long id, int state) { try { return markSettingProvider.UpdateMarkModelTypeStateApi(id, state); } catch (Exception ex) { ExLog(ex, "SetMarkModelTypeEntityState"); return ex.Message; } } public string SetButtonState(long id, int state) { try { return markSettingProvider.UpdateButtonStateApi(id, state); } catch (Exception ex) { ExLog(ex, "SetButtonState"); return ex.Message; } } public bool MarkWeightOper(MarkWeight arg1, OperEnum arg2) { try { switch (arg2) { case OperEnum.Add: return AddMarkWeight(arg1); case OperEnum.Edit: return EditMarkWeight(arg1); case OperEnum.Delete: return DeleteMarkWeight(arg1); } return false; } catch (Exception ex) { ExLog(ex, "MarkOper"); return false; } } public bool AddMarkWeight(MarkWeight parent) { try { MarkWeight newEntity = new MarkWeight() { ParentMarkWeight = parent, }; if (parent != null) { newEntity.parentId = parent.id; } AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (parent == null) { if (new MarkWeightOneWindow(newEntity).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } else { if (new MarkWeightWindow(newEntity, MarkEntityList).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } AppData.Instance.MainWindowViewModel.MaskVisibility = false; if (parent == null) { MarkWeightList.Add(newEntity); return true; } if (parent.children == null || !parent.children.Any()) { parent.children = new ObservableCollection() { newEntity }; //parent.children.Add(newEntity); } else { parent.children.Add(newEntity); } return true; } catch (Exception ex) { ExLog(ex, "AddMarkWeight"); return false; } } public bool EditMarkWeight(MarkWeight current) { try { AppData.Instance.MainWindowViewModel.MaskVisibility = true; if (current.parentId == -1) { if (new MarkWeightOneWindow(current, true).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } else { if (new MarkWeightWindow(current, MarkEntityList, true).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } AppData.Instance.MainWindowViewModel.MaskVisibility = false; return true; } catch (Exception ex) { ExLog(ex, "EditMarkWeight"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } public bool DeleteMarkWeight(MarkWeight pro) { try { if (pro.children != null && pro.children.Any()) { //ToastMessageShow($"当前节点存在子节点,请先删除子节点再进行尝试"); ToastMessageShow(KeyToStringConvert.GetLanguageStringByKey("0338")); return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = true; //new MessageBoxWindow("删除", $"确定删除此条名为{pro.name}的权重配置吗?", AppData.Instance.MainWindow).ShowDialog() if (new MessageBoxWindow(KeyToStringConvert.GetLanguageStringByKey("0043"), KeyToStringConvert.GetLanguageStringByKey("0537"), AppData.Instance.MainWindow).ShowDialog() != true) { AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } AppData.Instance.MainWindowViewModel.MaskVisibility = false; string error = markSettingProvider.DeleteMarkWeightApi(pro.id); if (!string.IsNullOrEmpty(error)) { ToastMessageShow($"{KeyToStringConvert.GetLanguageStringByKey("0337")}:{error}"); return false; } if (pro.ParentMarkWeight != null && pro.ParentMarkWeight.children != null) { pro.ParentMarkWeight.children.Remove(pro); if (!pro.ParentMarkWeight.children.Any()) { pro.ParentMarkWeight.children = new ObservableCollection(); } return true; } if (MarkWeightList.Contains(pro)) { MarkWeightList.Remove(pro); return true; } return false; } catch (Exception ex) { ExLog(ex, "DeleteMarkWeight"); AppData.Instance.MainWindowViewModel.MaskVisibility = false; return false; } } } }