254 lines
6.1 KiB
C#
254 lines
6.1 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Models.Models;
|
|
using SamplePre.Models;
|
|
using SamplePre.Models.Models;
|
|
using SamplePre.ProcessBll.BLL;
|
|
using SamplePreSystem.UI.ConfigManager.chirld;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace SamplePreSystem.UI.ViewModel.ConfigManager
|
|
{
|
|
public partial class SysConfigMangerViewModel : ObservableObject
|
|
{
|
|
|
|
|
|
SystemBll systemBll = new SystemBll();
|
|
|
|
public SysConfigMangerViewModel()
|
|
{
|
|
GetDictClassData();
|
|
}
|
|
|
|
|
|
private List<TreeItemModel> _dictClassList = new List<TreeItemModel>();
|
|
|
|
public List<TreeItemModel> DictClassList
|
|
{
|
|
get { return _dictClassList; }
|
|
set {
|
|
|
|
SetProperty(ref _dictClassList, value);
|
|
|
|
}
|
|
}
|
|
|
|
private sys_dict_class _dictClass = new sys_dict_class();
|
|
|
|
public sys_dict_class DictClass
|
|
{
|
|
get { return _dictClass; }
|
|
set {
|
|
|
|
SetProperty(ref _dictClass, value);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取字典分类数据
|
|
/// </summary>
|
|
public void GetDictClassData()
|
|
{
|
|
List<TreeItemModel> list = new List<TreeItemModel>();
|
|
//获取样本
|
|
var dictClassTemp = systemBll.QueryDictClassData();
|
|
|
|
var root1 = new TreeItemModel() { Id = 0, Name = "系统配置", IconKind = PackIconKind.DnsOutline };
|
|
foreach (var item in dictClassTemp)
|
|
{
|
|
root1.Children.Add(new TreeItemModel() { Id = item.id, Name = item.dict_type,Parent = root1 , IconKind = PackIconKind.FileDocumentOutline });
|
|
}
|
|
list.Add(root1);
|
|
|
|
DictClassList = list;
|
|
}
|
|
|
|
|
|
private List<sys_dict> _sysdicts = new List<sys_dict>();
|
|
|
|
public List<sys_dict> SysDicts
|
|
{
|
|
get { return _sysdicts; }
|
|
set {
|
|
|
|
SetProperty(ref _sysdicts, value);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private sys_dict _sysDict = new sys_dict();
|
|
|
|
public sys_dict SysDict
|
|
{
|
|
get { return _sysDict; }
|
|
set {
|
|
|
|
SetProperty(ref _sysDict, value);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 查询字典明细
|
|
/// </summary>
|
|
/// <param name="standID"></param>
|
|
public void GetDictData(int classid)
|
|
{
|
|
//查询
|
|
SysDicts = systemBll.QueryDictByClassId(classid);
|
|
|
|
}
|
|
|
|
|
|
public bool NewAddDict()
|
|
{
|
|
if (string.IsNullOrEmpty(this.DictClass.dict_type))
|
|
{
|
|
MessageBox.Show("内容不能为空");
|
|
return false;
|
|
}
|
|
|
|
|
|
systemBll.SaveSysDictClass(DictClass);
|
|
|
|
//获取数据
|
|
GetDictClassData();
|
|
|
|
return true;
|
|
}
|
|
|
|
public void DeleteDict()
|
|
{
|
|
|
|
if (MessageBox.Show($"确定移除:{DictClass.dict_type}", "提示",MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
|
{
|
|
//判断是否有子配置项
|
|
if (this.systemBll.QueryDictByClassId(DictClass.id).Count > 0)
|
|
{
|
|
MessageBox.Show("存在配置子项目,不能删除!");
|
|
return;
|
|
}
|
|
if (this.systemBll.DelDictClassById(DictClass.id) <= 0)
|
|
{
|
|
MessageBox.Show("删除失败!");
|
|
return;
|
|
}
|
|
|
|
//获取数据
|
|
GetDictClassData();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool NewAddDictDetail()
|
|
{
|
|
if (SysDict == null || string.IsNullOrEmpty(this.SysDict.data_type) || string.IsNullOrEmpty(this.SysDict.data_value))
|
|
{
|
|
MessageBox.Show("内容不能为空");
|
|
return false;
|
|
}
|
|
|
|
SysDict.class_id = DictClass.id;
|
|
SysDict.id = Guid.NewGuid().ToString();
|
|
|
|
|
|
this.systemBll.SaveSysDict(SysDict);
|
|
|
|
//刷新
|
|
GetDictData(DictClass.id);
|
|
|
|
return true;
|
|
}
|
|
|
|
public void DeleteDictDetail()
|
|
{
|
|
|
|
if (MessageBox.Show($"确定移除:{SysDict.data_type}", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
|
{
|
|
//移除
|
|
this.systemBll.DelSysDictByid(SysDict);
|
|
|
|
//刷新
|
|
GetDictData(DictClass.id);
|
|
}
|
|
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddClassClick()
|
|
{
|
|
//var vm = this.DataContext as SysConfigMangerViewModel;
|
|
|
|
//清空对象内容
|
|
DictClass = new SamplePre.Models.Models.sys_dict_class();
|
|
|
|
NewDictClassWindow frm = new NewDictClassWindow(this);
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void DelClassClick()
|
|
{
|
|
DeleteDict();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void TvDataSelectedItemChanged(RoutedPropertyChangedEventArgs<object> e)
|
|
{
|
|
//var vm = this.DataContext as SysConfigMangerViewModel;
|
|
|
|
var node = e.NewValue as TreeItemModel;
|
|
|
|
DictClass.dict_type = node.Name;
|
|
DictClass.id = node.Id;
|
|
|
|
GetDictData(node.Id);
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void AddItemClick()
|
|
{
|
|
SysDict = new Models.Models.sys_dict();
|
|
if (DictClass.id == null || DictClass.id == 0)
|
|
{
|
|
MessageBox.Show("请先选择分类");
|
|
|
|
return;
|
|
}
|
|
|
|
NewDictDetailWindow frm = new NewDictDetailWindow(this);
|
|
frm.ShowDialog();
|
|
}
|
|
|
|
[RelayCommand]
|
|
public void DelItemClick()
|
|
{
|
|
DeleteDictDetail();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|