|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using BPASmartClient.Helper;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.MorkTM;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.Mvvm.Input;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.MilkWithTea.ViewModel
- {
- public class PatrameterSettiongViewModel: ObservableObject
- {
- /// <summary>
- /// 物料通道口列表
- /// </summary>
- public ObservableCollection<MaterialPosion> materialPosions { get; set; } = new ObservableCollection<MaterialPosion>();
- /// <summary>
- /// 转盘位置列表
- /// </summary>
- public ObservableCollection<OutMaterialPosion> TurntablePosion { get; set; } = new ObservableCollection<OutMaterialPosion>();
-
- /// <summary>
- /// 出料位置ID
- /// </summary>
- public int MaterialID { get { return _materialID; } set { _materialID = value; OnPropertyChanged(); } }
- private int _materialID = 0;
- /// <summary>
- /// 出料重量
- /// </summary>
- public float OutMaterailWeight { get { return _outMaterilWeight; } set { _outMaterilWeight = value; OnPropertyChanged(); } }
- private float _outMaterilWeight;
- /// <summary>
- /// 装盘ID
- /// </summary>
- public int TurntableID { get { return _turntableID; } set { _turntableID = value; OnPropertyChanged(); } }
- private int _turntableID = 0;
- /// <summary>
- /// 矫正的通道号
- /// </summary>
- public int CorrectPassway { get { return _CorrectPassway; } set { _CorrectPassway = value; OnPropertyChanged(); } }
- private int _CorrectPassway = 0;
- /// <summary>
- /// 通道是否开启
- /// </summary>
- public bool PasswayIsOpen { get { return _passwayIsOpen; } set { _passwayIsOpen = value; OnPropertyChanged(); } }
- private bool _passwayIsOpen ;
- /// <summary>
- /// 矫正重量
- /// </summary>
- public float CorrectMatetailWeight { get { return _CorrectMatetailWeight; } set { _CorrectMatetailWeight = value; OnPropertyChanged(); } }
- private float _CorrectMatetailWeight = 0;
- /// <summary>
- /// 矫正时间
- /// </summary>
- public int OutTime { get { return _0utTime; } set { _0utTime = value; OnPropertyChanged(); } }
- private int _0utTime = 0;
-
- public bool IsEnable { get { return !GLobal.makeEnable; } set { GLobal.makeEnable = !value; OnPropertyChanged(); } }
- /// <summary>
- /// 出料动作
- /// </summary>
- public RelayCommand OutMaterailCommad { get; set; }
- /// <summary>
- /// 转动转盘
- /// </summary>
- public RelayCommand TurntableCommad { get; set; }
- /// <summary>
- /// 开始矫正
- /// </summary>
- public RelayCommand CheckPasswayCommad { get; set; }
- /// <summary>
- /// 开启通道
- /// </summary>
- public RelayCommand OpenPasswayCommand { get; set; }
- /// <summary>
- /// 确认重量
- /// </summary>
- public RelayCommand CheckMaterailWeightCommand { get; set; }
-
- #region 设备配置
-
- /// <summary>
- /// 店铺名称
- /// </summary>
- public string ShopName { get { return _shopName; } set { _shopName = value; OnPropertyChanged(); } }
- private string _shopName;
- /// <summary>
- /// 店铺ID
- /// </summary>
- public string ShopID { get { return _shopID; } set { _shopID = value; OnPropertyChanged(); } }
- private string _shopID;
- /// <summary>
- /// 设备ID
- /// </summary>
- public string DeviceID { get { return _deviceID; } set { _deviceID = value; OnPropertyChanged(); } }
- private string _deviceID;
- /// <summary>
- /// PLC地址
- /// </summary>
- public string PLCAdress { get { return _pLCAdress; } set { _pLCAdress = value; OnPropertyChanged(); } }
- private string _pLCAdress;
-
- public RelayCommand SaveDevicesCommand { get; set; }
- #endregion
-
- public PatrameterSettiongViewModel()
- {
-
- OutMaterailCommad = new RelayCommand(new Action(() =>
- {
- ActionManage.GetInstance.Send("通道口出料", new object[] { MaterialID +1, OutMaterailWeight });
-
- }));
-
- TurntableCommad = new RelayCommand(new Action(() =>
- {
- ActionManage.GetInstance.Send("转盘转动", new object[] { TurntableID });
- }));
-
- OpenPasswayCommand = new RelayCommand(new Action(() =>
- {
- if(PasswayIsOpen) ActionManage.GetInstance.Send("开启通道", new object[] { CorrectPassway + 1 });
-
- }));
-
- CheckPasswayCommad = new RelayCommand(new Action(() =>
- {
- ActionManage.GetInstance.Send("开始矫正", new object[] { CorrectPassway + 1,OutTime });
- }));
-
- CheckMaterailWeightCommand = new RelayCommand(new Action(() =>
- {
- ActionManage.GetInstance.Send("矫正重量", new object[] { CorrectPassway + 1, CorrectMatetailWeight });
- }));
-
- SaveDevicesCommand = new RelayCommand(SaveDeviceMessage);
-
- init();
- }
- private void init()
- {
- foreach (MaterialPosion materialPosion in Enum.GetValues(typeof(MaterialPosion)))
- {
- materialPosions.Add(materialPosion);
- }
-
- foreach (OutMaterialPosion outMaterialPosion in Enum.GetValues(typeof(OutMaterialPosion)))
- {
- TurntablePosion.Add(outMaterialPosion);
- }
- ShopName = GLobal.deviceConfig.ElementAt(0).ShopName;
- ShopID = GLobal.deviceConfig.ElementAt(0).ShopId;
- DeviceID = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).DeviceId;
- PLCAdress = GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress;
- }
-
- private void SaveDeviceMessage()
- {
- if (GLobal.deviceConfig.Count > 0)
- {
- GLobal.deviceConfig.ElementAt(0).ShopName = ShopName;
- GLobal.deviceConfig.ElementAt(0).ShopId = ShopID;
- GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).DeviceId = DeviceID;
- GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).Id = Guid.NewGuid().ToString();
- GLobal.deviceConfig.ElementAt(0).deviceModels.ElementAt(0).communicationDevcies.ElementAt(0).communicationPar.IPAddress = PLCAdress;
- File.WriteAllText($"{LocaPath.GetInstance().GetDeviceConfigPath}奶茶味魔方.json", JsonConvert.SerializeObject(GLobal.deviceConfig));
- }
-
- }
- }
- }
|