|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.CustomResource.UserControls;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.Helper;
- using FryPot_DosingSystem.Model;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
- using Microsoft.Toolkit.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;
-
- namespace FryPot_DosingSystem.ViewModel
- {
- internal class FlowProcessSetViewModel:ObservableObject
- {
-
- public int Id { get; set; } = 0;
- public static int materialNum { get; set; }
- public ObservableCollection<FlowProcessModel> flowProcessModels { get; set; } = new ObservableCollection<FlowProcessModel>();
- /// <summary>
- /// 目标重量偏差
- /// </summary>
- public string targetWeightOffset { get { return _targetWeightOffset; } set { _targetWeightOffset = value;OnPropertyChanged(); } }
- private string _targetWeightOffset="0";
-
- private string _stirTime="0";
- /// <summary>
- /// 秘制配方搅拌时间
- /// </summary>
- public string StirTime
- {
- get { return _stirTime; }
- set { _stirTime = value; OnPropertyChanged(); }
- }
-
-
- public string currentRecipeName { get; set; }
- public static int currentItemId { get; set; }
- public RelayCommand CloseWindowCommand { get; set; }
-
- public ObservableCollection<string> FlowItems { get; set; } = new ObservableCollection<string>();
- public RelayCommand ConfirmCommand { get; set; }
- public RelayCommand AddLastFlowItemCommand { get; set; }
- public RelayCommand AddFrontFlowItemCommand { get; set; }
- public RelayCommand DeleteFlowItemCommand { get; set; }
-
-
- public FlowProcessSetViewModel()
- {
- Json<FlowProcessNames>.Read();
- // FlowProcessNames.GetInstance.Names = Json<FlowProcessNames>.Data.Names;
- // FlowItems = Json<FlowProcessNames>.Data.NameId;
- foreach (KeyValuePair<string, int> item in Json<FlowProcessNames>.Data.NameId)
- {
- FlowItems.Add(item.Key);
- }
- ActionManage.GetInstance.Register(new Action<object>((obj) =>
- {
- if (obj != null)
- try
- {
- currentItemId = Convert.ToInt32(obj);
- }
- catch (Exception)
- {
-
- }
- }), "CurrentItemId");
- //ActionManage.GetInstance.Register(new Action<object>(obj =>
- //{
- // if (obj != null)
- // materialNum = Convert.ToInt32(obj);
- //}), "MaterialNum");
- ActionManage.GetInstance.Register(new Action<object>(recipeName =>
- {
- if (recipeName != null)
- {
- currentRecipeName = recipeName.ToString();
- var res = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.FlowProcess?.RecipeName == recipeName?.ToString());
- if (res != null && res is NewRecipeModel recipe) //编辑已有工艺
- {
- targetWeightOffset = recipe.FlowProcess.targetWeightOffset.ToString();
- StirTime=recipe.FlowProcess.StirTime.ToString();
- foreach (var item in recipe.materialCollection)
- {
- if (!FlowItems.Contains(item.MaterialLoc.ToString()))
- FlowItems.Add(item.MaterialLoc.ToString());//下拉框
- }
- foreach (var item in recipe.FlowProcess.fpModels)
- {
- flowProcessModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight, TargeWeight=item.TargeWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
- }
- // ActionManage.GetInstance.Send("MaterialNum", recipe.materialCollection.Count);
- }
- else//创建新工艺
- {
- var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == recipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = recipeName.ToString();
-
- foreach (var item in name.materialCollection)
- {
-
- if (!FlowItems.Contains(item.MaterialLoc.ToString()))
- FlowItems.Add(item.MaterialLoc.ToString());//下拉框
- }
- ActionManage.GetInstance.Send("MaterialNum", name.materialCollection.Count);
- //name.FlowProcess.fpModels = flowProcessModels;
- }
-
- }
- }
-
-
- }), "EditFlowProcess");
- CloseWindowCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("CloseFlowProcessView");
- });
- ConfirmCommand = new RelayCommand(() =>
- {
- var name = Json<RecipeManage>.Data.Recipes.FirstOrDefault(p => p.RecipeName == currentRecipeName.ToString());
- if (name != null)
- {
- name.FlowProcess.RecipeName = currentRecipeName.ToString();
-
- if (float.TryParse(targetWeightOffset.Trim(), out float offset))
- {
- name.FlowProcess.targetWeightOffset = offset;//目标重量偏差
- }
- else
- {
- MessageBox.Show("非法目标重量偏差设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
- name.FlowProcess.targetWeightOffset = 0.0F;
- return;
- }
- if (ushort.TryParse(StirTime.Trim(), out ushort time))
- {
- name.FlowProcess.StirTime = time;//秘制配方搅拌时间
- }
- else
- {
- MessageBox.Show("非法秘制配方搅拌时间设置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
- name.FlowProcess.StirTime = 0;
- return;
- }
- //工艺桶号重复性检测
- foreach (var item in name.materialCollection)
- {
- var res = flowProcessModels.Where(p => p.FryMaterialNum == item.MaterialLoc.ToString());
- if (res.Count() > 1)
- {
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, App.MainWindow, "提示", $"保存失败,桶号重复!");
- MessageNotify.GetInstance.ShowUserLog("保存失败,桶号重复");
- MessageBox.Show("保存失败,桶号重复", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- }
- //工艺步骤中清洗工艺重复性检测
- if (flowProcessModels.FirstOrDefault(p=>p.FryMaterialNum=="清洗")!=null)
- {
- if (flowProcessModels.Where(p => p.FryMaterialNum == "清洗").Count() > 1||flowProcessModels.IndexOf(flowProcessModels.FirstOrDefault(p => p.FryMaterialNum == "清洗"))<flowProcessModels.Count-1)
- {
- MessageNotify.GetInstance.ShowUserLog("保存失败,清洗工艺重复或非法配置");
- MessageBox.Show("保存失败,清洗工艺重复或非法配置", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
- return;
- }
- }
- // name.FlowProcess.fpModels = flowProcessModels;
- name.FlowProcess.fpModels.Clear();
- foreach (var item in flowProcessModels)
- {
- name.FlowProcess.fpModels.Add(new FlowProcessModel { FryMaterialNum = item.FryMaterialNum, FrySpeed = item.FrySpeed, FryWeight = item.FryWeight,TargeWeight=item.TargeWeight, FryTemperature = item.FryTemperature, FryPeriodTime = item.FryPeriodTime, SmallFirePercent = item.SmallFirePercent, MidFirePercent = item.MidFirePercent, BigFirePercent = item.BigFirePercent, StrongFirePercent = item.StrongFirePercent });
- }
-
- //foreach (var item in name.materialCollection)
- //{
- // string s= Json<FlowProcessNames>.Data.Names.FirstOrDefault(p=>p == item.MaterialLoc.ToString());
- // Json<FlowProcessNames>.Data.Names.Remove(s);
- //}
- }
- Json<RecipeManage>.Save();
- Json<FlowProcessNames>.Save();
- ActionManage.GetInstance.Send("CloseFlowProcessView");
- });
-
- AddFrontFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (currentItemId == 0)
- {
- flowProcessModels.Insert(0, new FlowProcessModel());
- }
- else
- {
- flowProcessModels.Insert(currentItemId, new FlowProcessModel());
- currentItemId = currentItemId + 1;
- }
- }
- catch (Exception)
- {
-
- //throw;
- }
-
- });
- AddLastFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (flowProcessModels.Count <= 0)
- {
- flowProcessModels.Insert(0, new FlowProcessModel());
-
- }
- else if (currentItemId != 0)
- {
- flowProcessModels.Insert(currentItemId + 1, new FlowProcessModel());
- }
- else
- {
- flowProcessModels.Add(new FlowProcessModel());
- }
- }
- catch (Exception)
- {
-
- // throw;
- }
- });
- DeleteFlowItemCommand = new RelayCommand(() =>
- {
- if (flowProcessModels.Count > 0)
- flowProcessModels.RemoveAt(currentItemId);
- currentItemId = 0;
- });
-
-
-
- }
- }
- }
|