| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using System;
- using Prism.Mvvm;
- using System.Linq;
- using Prism.Commands;
- using SHJX.Service.Model.Control;
- using System.Windows.Controls;
- using SHJX.Service.CustomControl;
- using System.Collections.Generic;
- using SHJX.Service.Common.Extend;
- using SHJX.Service.Common.ReadXML;
- using System.Collections.ObjectModel;
- using SHJX.Service.Common.UserDelegate;
- using SHJX.Service.Common.ExtendElement;
- using SHJX.Service.Control.ServiceController;
- namespace SHJX.Service.ModelView
- {
- public class TemplateWindowViewModel : BindableBase
- {
- #region Field
- private string _searchStr = string.Empty;
- private readonly TemplateController _control;
- #endregion
- #region Property
- public List<SampleDetail> DetailSourceInfos { get; set; }
- public ObservableCollection<SampleDetail> DetailInfos { get; set; }
- private object _selectedEmployee;
- public object SelectedEmployee
- {
- get => _selectedEmployee;
- set => SetProperty(ref _selectedEmployee, value);
- }
- #endregion
- public TemplateWindowViewModel(ReadConfigUtil config)
- {
- _control = new TemplateController(config);
- DetailSourceInfos = new List<SampleDetail>();
- DetailInfos = new ObservableCollection<SampleDetail>();
- ImportTemlateFromLocaltion();
- }
- #region Command
- private DelegateCommand _interfaceDisplayCommand;
- public DelegateCommand InterfaceDisplayCommand => _interfaceDisplayCommand ?? new DelegateCommand(ExecuteInterfaceDisplayCommand);
- private DelegateCommand<object> _templateSearchChangedCommand;
- public DelegateCommand<object> TemplateSearchChangedCommand => _templateSearchChangedCommand ?? new DelegateCommand<object>(ExecuteTemplateSearchChangedCommand);
- private DelegateCommand _savaTemplateCommand;
- public DelegateCommand SavaTemplateCommand => _savaTemplateCommand ?? new DelegateCommand(ExecuteSavaTemplateCommand);
- private DelegateCommand _importTemplateToInterfaceCommand;
- public DelegateCommand ImportTemplateToInterfaceCommand => _importTemplateToInterfaceCommand ?? new DelegateCommand(ExecuteImportTemplateToInterfaceCommand);
- private DelegateCommand _importTemplateCommand;
- public DelegateCommand ImportTemplateCommand => _importTemplateCommand ?? new DelegateCommand(ExecuteImportTemplateCommand);
- private DelegateCommand _insertOneDataCommand;
- public DelegateCommand InsertOneDataCommand => _insertOneDataCommand ?? new DelegateCommand(ExecuteInsertOneDataCommand);
- private DelegateCommand _deleteOneDataCommand;
- public DelegateCommand DeleteOneDataCommand => _deleteOneDataCommand ?? new DelegateCommand(ExecuteDeleteOneDataCommand);
- private DelegateCommand _updateOneDataCommand;
- public DelegateCommand UpdateOneDataCommand => _updateOneDataCommand ?? new DelegateCommand(ExecuteUpdateOneDataCommand);
- #endregion
- #region Execute
- private void ExecuteUpdateOneDataCommand()
- {
- if (SelectedEmployee is not SampleDetail detail)
- {
- UMessageBox.Error("未选中对象,无法进行修改操作!");
- return;
- }
- InputDialog inputDialog = new(false, detail);
- if (inputDialog.ShowDialog().Equals(true))
- {
- var infos = DetailSourceInfos.Clone();
- infos.Where(item => item.NodeName.Equals(detail.NodeName)).ToArray()[0].SampleType = inputDialog.TextType;
- infos.Where(item => item.NodeName.Equals(detail.NodeName)).ToArray()[0].Concentration = inputDialog.TextConcentration.Substring(0, 1);
- SettingTemplateDataGrid(infos);
- };
- }
- /// <summary>
- /// 模板导入
- /// </summary>
- private void ExecuteImportTemplateCommand()
- {
- ImportTemlateFromLocaltion();
- }
- /// <summary>
- /// 删除一条数据
- /// </summary>
- /// <param name="obj"></param>
- private void ExecuteDeleteOneDataCommand()
- {
- if (SelectedEmployee is not SampleDetail detail)
- {
- UMessageBox.Error("未选中对象,无法进行删除操作!");
- return;
- }
- var infos = DetailSourceInfos.Clone();
- infos.Remove(infos.FirstOrDefault(item => item.NodeName.Equals(detail.NodeName)));
- SettingTemplateDataGrid(infos);
- }
- /// <summary>
- /// 插入新数据
- /// </summary>
- private void ExecuteInsertOneDataCommand()
- {
- InputDialog inputDialog = new();
- if (inputDialog.ShowDialog().Equals(false)) return;
- string pointName = inputDialog.TextPoint;
- string sampleType = inputDialog.TextType;
- string sampleConcentration = inputDialog.TextConcentration.Substring(0, 1);
- var infos = DetailSourceInfos.Clone();
- if (infos.Where(it => it.NodeName.Trim().Equals(pointName.Trim())).Any())
- {
- UMessageBox.SingleBtnInfo("已有节点数据,请勿重复添加!");
- return;
- }
- SampleDetail detail = new();
- detail.NodeName = pointName;
- detail.SampleType = sampleType;
- detail.Concentration = sampleConcentration;
- if (sampleType.In("空白", "标定"))
- {
- detail.Detail = sampleType;
- }
- infos.Add(detail);
- SettingTemplateDataGrid(infos);
- }
- /// <summary>
- /// 导入模板到界面
- /// </summary>
- private void ExecuteImportTemplateToInterfaceCommand()
- {
- Messager.Send("ReceiveTemplateData", DetailInfos.ToList());
- }
- /// <summary>
- /// 界面选中数据展示
- /// </summary>
- private void ExecuteInterfaceDisplayCommand()
- {
- Action<List<SampleDetail>> action = (details) => SettingTemplateDataGrid(details);
- Messager.Send("ReceiveTemplateDataFromMain", action);
- }
- private void SettingTemplateDataGrid(List<SampleDetail> templates)
- {
- if (DetailSourceInfos.Count > 0)
- {
- DetailSourceInfos.Clear();
- }
- if (DetailInfos.Count > 0)
- {
- DetailInfos.Clear();
- }
- List<SampleDetail> templates2 = new List<SampleDetail>(); ;
- foreach (var item in templates)
- {
- if (item.Concentration != "")
- { templates2.Add(item); }
- }
- DetailSourceInfos = templates2.OrderBy(item => Convert.ToInt32(item?.NodeName.Substring(1))).ToList();
- DetailInfos.AddRange(DetailSourceInfos);
- SearchSampleDetails();
- }
- /// <summary>
- /// 模板保存
- /// </summary>
- private void ExecuteSavaTemplateCommand()
- {
- _control.SaveTemplate(DetailInfos.ToList());
- }
- /// <summary>
- /// 搜索
- /// </summary>
- /// <param name="parameter"></param>
- private void ExecuteTemplateSearchChangedCommand(object parameter)
- {
- _searchStr = Convert.ToString(((TextBox)parameter)?.Text);
- SearchSampleDetails();
- }
- private void SearchSampleDetails()
- {
- if (string.IsNullOrWhiteSpace(_searchStr))
- {
- DetailInfos.Clear();
- DetailInfos.AddRange(DetailSourceInfos);
- return;
- }
- var findList = DetailSourceInfos.Where(item => item.NodeName.ToLower().Trim().Contains(_searchStr.ToLower().Trim())).ToList();
- DetailInfos.Clear();
- DetailInfos.AddRange(findList);
- }
- /// <summary>
- /// 从本地导入模板
- /// </summary>
- private void ImportTemlateFromLocaltion()
- {
- var templates = _control.GetSampleDetailsByTemplate();
- if (templates is null)
- {
- return;
- }
- SettingTemplateDataGrid(templates);
- }
- #endregion
- }
- }
|