You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AUCMA_SCADA/Aucma.Core.Palletiz/ViewModels/SetRangeWindowViewModel.cs

186 lines
5.3 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<JumpRange> jumpRanges = new List<JumpRange>();
public SetRangeWindowViewModel()
{
InitDataGrid();
DeleteCommand = new RelayCommand<object>(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();
}
}
/// <summary>
/// 初始化配置文件的角度列表
/// </summary>
public void InitDataGrid()
{
int id = 1;
ListItems.Clear();
List<JumpRange> list = config.GetJumpRanges();
if (list == null || list.Count == 0) return;
foreach(JumpRange jumpRange in list)
{
ListItems.Add(jumpRange);
}
}
#region 参数定义
/// <summary>
/// 删除
/// </summary>
public RelayCommand<object> DeleteCommand { get; set; }
private ObservableCollection<JumpRange> listItems = new ObservableCollection<JumpRange>() { };
public ObservableCollection<JumpRange> 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);
}
/// <summary>
/// 奇数货道旋转角
/// </summary>
private int _selectedOddNumber;
public int SelectedOddNumber
{
get { return _selectedOddNumber; }
set
{
_selectedOddNumber = value;
OnPropertyChanged(nameof(SelectedOddNumber));
}
}
/// <summary>
/// 偶数货道旋转角
/// </summary>
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();
}
}
/// <summary>
/// 根据货物容积确定旋转规则 转180度发1不转发3
/// </summary>
/// <param name="prodWeight"></param>
/// <returns></returns>
public int JudgeRotation(int spaceCode, int prodWeight)
{
try
{
List<JumpRange> 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
}
}