using BPA.Models;
using BPA.Helper;
using BPASmartClient.Model;
using BPASmartClient.Model.小炒机;
using BPASmartClient.MorkF.Model;
using BPASmartClient.ViewModel;
using BPA.Helper;
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.Windows.Threading;
namespace BPASmartClient.MorkF.ViewModel
{
partial class LocalMenuViewModel:NotifyBase
{
///
/// 单个菜品流程
///
public ObservableCollection PotActionStep { get { return _PotActionStep; }
set { _PotActionStep = value; OnPropertyChanged(); } }
private ObservableCollection _PotActionStep = new ObservableCollection();
public string MaterialName { get; set; }
///
/// 选中的菜品
///
public string SelectMaterialName { get { return _selectMaterialName; } set { _selectMaterialName = value; OnPropertyChanged(); } }
private string _selectMaterialName;
///
/// 菜品combox集合
///
public ObservableCollection MaterialNames { get; set; } = new ObservableCollection();
///
/// 动作名称combox集合
///
public ObservableCollection strPotActions { get; set; } = new ObservableCollection();
///
/// 全部菜品流程集合
///
public MaterialAndFryingTime materialAndFryingTime { get; set; } = Json.Data;
public BPARelayCommand Delete { get; set; }
public BPARelayCommand AddFryTime { get; set; }
public BPARelayCommand NewStartLocalMaterial { get; set; }
public BPARelayCommand AddMaterial { get; set; }
public BPARelayCommand DeleteMaterial { get; set; }
public BPARelayCommand RenameMaterial { get; set; }
public BPARelayCommand Save { get; set; }
private void Deleted(object o)
{
if (o == null) return;
if(o is PotActions p)
{
PotActionStep.Remove(p);
}
for (int i = 0; i < PotActionStep.Count; i++)
{
PotActionStep[i].FryTime = i + 1;
}
}
public LocalMenuViewModel()
{
//if (Json.Data.LocalstirFryGoods.StirPotActions.Count > 0)
//{
// PotActionStep.Clear();
// PotActionStep = new ObservableCollection(Json.Data.LocalstirFryGoods.StirPotActions);
//}
Json.Read();
if (Json.Data.materials.Count > 0)
{
MaterialNames.Clear();
materialAndFryingTime.materials = Json.Data.materials;
foreach (var item in materialAndFryingTime.materials)
{
MaterialNames.Add(item.Key);
//if (MaterialNames.Count == 1)
//{
// MaterialName = item.Key;
// PotActionStep.Clear();
// foreach (var item2 in item.Value)
// {
// PotActionStep.Add(item2);
// }
//}
}
}
Delete = new BPARelayCommand(Deleted);
AddFryTime = new BPARelayCommand(() =>
{
List seasoningLists = new List();
seasoningLists.Add(new SeasoningList { Loc = 0, Qty = 0 });
PotActionStep.Add(new BPA.Models.PotActions
{
FryTime = PotActionStep.Count + 1,
During = 0,
SeasoningLists = seasoningLists,
});
});
NewStartLocalMaterial = new BPARelayCommand(() =>
{
ActionManage.GetInstance.Send("NewStartLocalOrder", SelectMaterialName);
});
AddMaterial = new BPARelayCommand(() =>
{
//尝试是否能找到
if(MaterialNames.FirstOrDefault(o=>o == MaterialName) == MaterialName)
{
MessageBox.Show("该菜品已经添加");
}
else
{
MaterialNames.Add(MaterialName);
SelectMaterialName = MaterialName;
}
});
DeleteMaterial = new BPARelayCommand(() =>
{
if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
{
materialAndFryingTime.materials.Remove(SelectMaterialName);
}
MaterialNames.Remove(SelectMaterialName);
PotActionStep.Clear();
});
//RenameMaterial = new BPARelayCommand(() =>
//{
// //尝试是否能找到
// if (MaterialNames.FirstOrDefault(o => o == SelectMaterialName) == SelectMaterialName)
// {
// MaterialNames.Remove(SelectMaterialName);
// MaterialNames.Add(MaterialName);
// if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
// {
// materialAndFryingTime.materials.Add(MaterialName, materialAndFryingTime.materials[SelectMaterialName]);
// materialAndFryingTime.materials.Remove(SelectMaterialName);
// }
// }
//});
Save = new BPARelayCommand(new Action(() =>
{
if(PotActionStep.Count > 0)
{
ObservableCollection newPotActionSteps = new ObservableCollection();
foreach (var step in PotActionStep)
{
newPotActionSteps.Add(step);
}
if (materialAndFryingTime.materials.ContainsKey(SelectMaterialName))
{
materialAndFryingTime.materials[SelectMaterialName] = newPotActionSteps;
}
else
{
materialAndFryingTime.materials.Add(SelectMaterialName, newPotActionSteps);
}
}
//Json.Data.LocalstirFryGoods.GoodsKey = 11;
//Json.Data.LocalstirFryGoods.StirPotActions = new List(PotActionStep);
//Json.Save();
//Json.Data.materials = materialAndFryingTime.materials;
Json.Save();
//ActionManage.GetInstance.Send("LocalMenuClose");
}));
foreach(var pot in Enum.GetNames(typeof(StirFryPotActionEnum)))
{
strPotActions.Add(pot);
}
ActionManage.GetInstance.Register(new Action(()=>
{
for (int i = 0; i < Json.Data.LocalstirFryGoods.StirPotActions.Count; i++)
{
Json.Data.LocalstirFryGoods.StirPotActions[i].FryTime = i + 1;
}
}), "SortFryTime");
ActionManage.GetInstance.Register(new Action((o) =>
{
if (o == null) return ;
if(o is int[] ints)
{
Json.Data.LocalstirFryGoods.StirPotActions[ints[0]].FryTime = ints[1]+1;
Json.Data.LocalstirFryGoods.StirPotActions[ints[1]].FryTime = ints[0]+1;
var res = Json.Data.LocalstirFryGoods.StirPotActions[ints[0]];
Json.Data.LocalstirFryGoods.StirPotActions.Remove(res);
Json.Data.LocalstirFryGoods.StirPotActions.Insert(ints[1],res);
}
}), "PotActionStep");
ActionManage.GetInstance.Register(new Action(o =>
{
if (o is string str)
{
SelectMaterialName = str;
PotActionStep.Clear();
if (materialAndFryingTime.materials.ContainsKey(str))
{
foreach (var item2 in materialAndFryingTime.materials[str])
{
PotActionStep.Add(item2);
}
}
}
}), "LoacMenuSelectMaterial",true);
}
}
}