using BPA.Helper; using BPASmartClient.Model; using BPASmartClient.MorkS.Model; using BPASmartClient.MorkS.View; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; namespace BPASmartClient.MorkS.ViewModel { internal class GoodsMakeViewModel : NotifyBase { public ObservableCollection GoodsModels { get; set; } = new ObservableCollection(); public BPARelayCommand SendOrderCommand { get; set; } public BPARelayCommand DeleteOrderCommand { get; set; } public BPARelayCommand EditCommand { get; set; } public GoodsMakeViewModel() { Json.Read(); GoodsModels = Json.Data.GoodsModels; ActionManage.GetInstance.Register(new Action((res) => { if (res != null && res is GoodsModel goods) { var result = GoodsModels.FirstOrDefault(p => p.OrderNum == goods.OrderNum); if (result == null) { GoodsModels.Add(goods); Json.Save(); } else { MessageBox.Show("新增订单失败!","提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } }), "orderEdit"); SendOrderCommand = new BPARelayCommand((s) => { var res = GoodsModels.FirstOrDefault(p => p.OrderNum.Equals(s)); if (res != null) { new MorksSimorderModel() { Bowloc = res.BowlLoc, NoodleLoc = res.NoodlesLoc }.Publish(); } }); EditCommand = new BPARelayCommand(() => { GoodsEditView goodsEditView = new GoodsEditView(); goodsEditView.ShowDialog(); }); DeleteOrderCommand = new BPARelayCommand((res) => { if (!string.IsNullOrEmpty(res)) { var re = GoodsModels.FirstOrDefault(p=>p.OrderNum.Equals(res)); if (re != null) { GoodsModels.Remove(re); Json.Save(); } else { MessageBox.Show("未查找到当前订单,删除失败!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning); } } }); } } }