|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using BPASmart.Model;
- using BPASmartClient.Helper;
- 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;
-
- namespace BPASmart.RecipeManagement.ViewModel
- {
- public class TechnologyProcessViewModel : ObservableObject
- {
- public static int currentItemId;
-
- public int Id { get { return _id; } set { _id = value; OnPropertyChanged(); } }
- private int _id = 0;
-
- public ObservableCollection<TechnologyProcessModel> technologyProcessModels { get; set; } = new ObservableCollection<TechnologyProcessModel>();
-
- public string currentRecipeName { get { return _currentRecipeName; } set { _currentRecipeName = value; OnPropertyChanged(); } }
- private string _currentRecipeName = string.Empty;
-
-
- public RelayCommand CloseWindowCommand { get; set; }
-
- public ObservableCollection<string> meterailItems { 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 TechnologyProcessViewModel()
- {
- foreach (var item in Globle.GlobleData.recipeTechnologyProcess.recipeMaterials)
- {
- meterailItems.Add(item.Name);
- }
-
- ActionManage.GetInstance.Register(new Action<object>((obj) =>
- {
- if (obj != null)
- try
- {
- currentItemId = Convert.ToInt32(obj);
- }
- catch (Exception)
- {
-
- }
- }), "CurrentItemId");
- technologyProcessModels = Globle.GlobleData.recipeTechnologyProcess.TechnologyProcessModels;
-
-
- CloseWindowCommand = new RelayCommand(() =>
- {
- ActionManage.GetInstance.Send("CloseTechnologyProcessView");
- });
- ConfirmCommand = new RelayCommand(() =>
- {
- var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == Globle.GlobleData.recipeTechnologyProcess.ID);
- if (res != null)
- {
-
- res.TechnologyProcessModels = technologyProcessModels;
- }
- Json<LocalRecipes>.Save();
-
- ;
- ActionManage.GetInstance.Send("CloseTechnologyProcessView");
- });
-
- AddFrontFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (currentItemId == 0)
- {
- technologyProcessModels.Insert(0, new TechnologyProcessModel());
- }
- else
- {
- technologyProcessModels.Insert(currentItemId, new TechnologyProcessModel());
- currentItemId = currentItemId + 1;
- }
- }
- catch (Exception)
- {
-
- //throw;
- }
-
- });
- AddLastFlowItemCommand = new RelayCommand(() =>
- {
- try
- {
- if (technologyProcessModels.Count <= 0)
- {
- technologyProcessModels.Insert(0, new TechnologyProcessModel());
-
- }
- else if (currentItemId != 0)
- {
- technologyProcessModels.Insert(currentItemId + 1, new TechnologyProcessModel());
- }
- else
- {
- technologyProcessModels.Add(new TechnologyProcessModel());
- }
- }
- catch (Exception)
- {
-
- // throw;
- }
- });
- DeleteFlowItemCommand = new RelayCommand(() =>
- {
- if (technologyProcessModels.Count > 0)
- technologyProcessModels.RemoveAt(currentItemId);
- currentItemId = 0;
- });
- }
- }
- }
|