using Admin.Core.Model; using Aucma.Core.Palletiz.config; using Aucma.Core.Palletiz.Models; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; 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.Speech.Synthesis; namespace Aucma.Core.Palletiz.ViewModels { public partial class SetRangeWindowViewModel : ObservableObject { private static AppConfig config = new AppConfig(); public List jumpRanges = new List(); public SetRangeWindowViewModel() { InitDataGrid(); DeleteCommand = new RelayCommand(obj => Delete(obj)); } public void Delete(object obj) { MessageBoxResult result = MessageBox.Show("确认删除吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { string objId = obj.ToString(); Console.WriteLine(objId); JumpRange delete = config.GetJumpRanges().FirstOrDefault(x => x.ObjId == int.Parse(objId)); string deleteStr = $"[{delete.MinModel}-{delete.MaxModel}-{delete.OddSpaceRange}-{delete.EvenSpaceRange}]"; // 配置文件减去该字符串 // string temp = config.RangeConfig; // string result1 = temp.Replace(deleteStr, ""); config.RangeConfig = config.RangeConfig.Replace(deleteStr, ""); MessageBox.Show("删除成功"); InitDataGrid(); } } /// /// 初始化配置文件的角度列表 /// public void InitDataGrid() { int id = 1; ListItems.Clear(); List list = config.GetJumpRanges(); if (list == null || list.Count == 0) return; foreach(JumpRange jumpRange in list) { ListItems.Add(jumpRange); } } #region 参数定义 /// /// 删除 /// public RelayCommand DeleteCommand { get; set; } private ObservableCollection listItems = new ObservableCollection() { }; public ObservableCollection ListItems { get { return listItems; } set { listItems = value; OnPropertyChanged();//属性通知 } } private string minModel; public string MinModel { get => minModel; set => SetProperty(ref minModel, value); } private string maxModel; public string MaxModel { get => maxModel; set => SetProperty(ref maxModel, value); } /// /// 奇数货道旋转角 /// private int _selectedOddNumber; public int SelectedOddNumber { get { return _selectedOddNumber; } set { _selectedOddNumber = value; OnPropertyChanged(nameof(SelectedOddNumber)); } } /// /// 偶数货道旋转角 /// private int _selectedEvenNumber; public int SelectedEvenNumber { get { return _selectedEvenNumber; } set { _selectedEvenNumber = value; OnPropertyChanged(nameof(SelectedEvenNumber)); } } #endregion #region [RelayCommand] private async Task Save(string obj) { MessageBoxResult result = MessageBox.Show("确认保存吗?", "确认", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { config.RangeConfig = config.RangeConfig + $"[{MinModel}-{MaxModel}-{SelectedOddNumber}-{SelectedEvenNumber}]"; MessageBox.Show("保存成功"); InitDataGrid(); } } /// /// 根据货物容积确定旋转规则 转180度发1,不转发3 /// /// /// public int JudgeRotation(int spaceCode, int prodWeight) { try { List list = config.GetJumpRanges(); foreach (JumpRange range in list) { if (range.MinModel <= prodWeight && range.MaxModel > prodWeight) // 找到该型号规则 { if (spaceCode % 2 == 0) // 偶数货道 { return range.EvenSpaceRange == 0 ? 3 : 1; } else { return range.OddSpaceRange == 0 ? 3 : 1; } } } } catch (Exception ex) { Console.WriteLine("JudgeRotation" + ex.Message); } return -1; } #endregion } }