|
|
|
@ -1,20 +1,90 @@
|
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using GalaSoft.MvvmLight.Command;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SlnMesnac.Model.domain;
|
|
|
|
|
using SlnMesnac.Repository.service;
|
|
|
|
|
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.Input;
|
|
|
|
|
|
|
|
|
|
namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
{
|
|
|
|
|
public class SetKindWindowViewModel : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private ILogoFormulaService? formulaService;
|
|
|
|
|
private ILogoConfigService? logoConfigService;
|
|
|
|
|
private string CachMaterialType;
|
|
|
|
|
// 缓存第一次查到的海康配方
|
|
|
|
|
public Dictionary<string, int> TypeCache = new Dictionary<string, int>();
|
|
|
|
|
public LogoConfig record = null;
|
|
|
|
|
|
|
|
|
|
public delegate void SetKindWindowDelegate();
|
|
|
|
|
|
|
|
|
|
public SetKindWindowViewModel(string materialType)
|
|
|
|
|
{
|
|
|
|
|
MaterialType = materialType;
|
|
|
|
|
formulaService = App.ServiceProvider.GetService<ILogoFormulaService>();
|
|
|
|
|
logoConfigService = App.ServiceProvider.GetService<ILogoConfigService>();
|
|
|
|
|
SaveCommand = new RelayCommand(Save);
|
|
|
|
|
// 初始加载内容
|
|
|
|
|
Init(materialType);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Init(string materialType)
|
|
|
|
|
{
|
|
|
|
|
record = logoConfigService.GetByMaterialType(materialType);
|
|
|
|
|
if (record == null) return;
|
|
|
|
|
MaterialType = record.MaterialName;
|
|
|
|
|
IsDetectionChecked = record.IsChecked == 0 ? false : true;
|
|
|
|
|
List<LogoFormula> list = formulaService.GetListAsync().Result;
|
|
|
|
|
if(list!=null && list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
MaterialTypes.Add(item.Value);
|
|
|
|
|
TypeCache.Add(item.Value, item.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Save()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(_selectedMaterialType) && IsDetectionChecked)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请选择型号");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_selectedMaterialType)){
|
|
|
|
|
//需要检测
|
|
|
|
|
string select = _selectedMaterialType;
|
|
|
|
|
TypeCache.TryGetValue(select, out int key);
|
|
|
|
|
record.CheckKind = key;
|
|
|
|
|
}
|
|
|
|
|
#region 修改配方
|
|
|
|
|
if (record != null)
|
|
|
|
|
{
|
|
|
|
|
record.IsChecked = IsDetectionChecked ? 1 : 0;
|
|
|
|
|
if(record.IsChecked == 0)
|
|
|
|
|
{
|
|
|
|
|
// 不检测,复位0
|
|
|
|
|
record.CheckKind = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
logoConfigService.updateByMaterialType(record);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
MessageBox.Show("修改完成");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 属性
|
|
|
|
|
/// <summary>
|
|
|
|
@ -37,7 +107,35 @@ namespace SlnMesnac.WPF.ViewModel
|
|
|
|
|
set { _IsDetectionChecked = value; RaisePropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _selectedMaterialType;
|
|
|
|
|
public string SelectedMaterialType
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedMaterialType; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_selectedMaterialType = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
// 可以在这里处理选中项变化后的逻辑
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下拉框集合
|
|
|
|
|
/// </summary>
|
|
|
|
|
private ObservableCollection<string> _materialTypes = new ObservableCollection<string>();
|
|
|
|
|
public ObservableCollection<string> MaterialTypes
|
|
|
|
|
{
|
|
|
|
|
get { return _materialTypes; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_materialTypes = value;
|
|
|
|
|
RaisePropertyChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public RelayCommand SaveCommand { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|