using BPASmartClient.CustomResource.Pages.Model; using BPASmartClient.CustomResource.UserControls.MessageShow; using BPASmartClient.MorkCL.Model.DB; using BPASmartClient.MorkCL.Server; namespace BPASmartClient.MorkCL.ViewModel { public class AddRawMaterialViewModel : NotifyBase { private ObservableCollection accessories; private ObservableCollection ingredients; private ObservableCollection seasonings; public AddRawMaterialViewModel() { //InitialTestData(); RefreshData(); RemoveAccessoryCommand = new BPARelayCommand((Id) => { if (!MessageNotify.GetInstance.ShowDialog($"请确认 ,是否删除物料信息【{Id}】?")) { return; } var result = SqliteHelper.GetInstance.DelAccessories(Id); if (result) { RefreshData(); NoticeDemoViewModel.OpenMsg(CustomResource.UserControls.EnumPromptType.Success, Application.Current.MainWindow, "提示", "删除辅料信息成功!"); } }); RemoveIngreditentCommand = new BPARelayCommand((Id) => { if (!MessageNotify.GetInstance.ShowDialog($"请确认 ,是否删除物料信息【{Id}】?")) { return; } var result = SqliteHelper.GetInstance.DelIngredients(Id); if (result) { RefreshData(); NoticeDemoViewModel.OpenMsg(CustomResource.UserControls.EnumPromptType.Success, Application.Current.MainWindow, "提示", "删除主料信息成功!"); } }); RemoveSeasoningCommand = new BPARelayCommand((Id) => { if (!MessageNotify.GetInstance.ShowDialog($"请确认 ,是否删除物料信息【{Id}】?")) { return; } var result = SqliteHelper.GetInstance.DelSeasoning(Id); if (result) { RefreshData(); NoticeDemoViewModel.OpenMsg(CustomResource.UserControls.EnumPromptType.Success, Application.Current.MainWindow, "提示", "删除调料信息成功!"); } }); AddMaterialCommand = new BPARelayCommand((materialType) => { EditRawMaterialView editRawMaterialView = new EditRawMaterialView(); ActionManage.GetInstance.Send(new MaterialBase(), "OpenEditRawMaterialView"); ActionManage.GetInstance.Send(materialType, "ChangeMaterialType"); if (editRawMaterialView.ShowDialog() == true) { RefreshData(); } }); EditCommand = new BPARelayCommand((o) => { EditRawMaterialView editRawMaterialView = new EditRawMaterialView(); ActionManage.GetInstance.Send(o, "OpenEditRawMaterialView"); if (editRawMaterialView.ShowDialog() == true) { RefreshData(); } }); } private void InitialTestData() { Accessories = new ObservableCollection(); for (int i = 0; i < 8; i++) { Accessories.Add(new AccessoriesTB() { Id = i.ToString(), Name = $"第{i}样", Loc = i }); } Ingredients = new(); for (int i = 0; i < 12; i++) { Ingredients.Add(new IngredientsTB() { Id = i.ToString(), Name = $"第{i}样" }); } Seasonings = new(); for (int i = 0; i < 3; i++) { Seasonings.Add(new SeasoningTB() { Id = i.ToString(), Name = $"第{i}样", Loc = i }); } } private void RefreshData() { Ingredients = new ObservableCollection(SqliteHelper.GetInstance.GetIngredients()); Accessories = new ObservableCollection(SqliteHelper.GetInstance.GetAccessories().OrderBy(tb => tb.Loc)); Seasonings = new ObservableCollection(SqliteHelper.GetInstance.GetSeasoning().OrderBy(tb => tb.Loc)); } /// 辅料信息集合 public ObservableCollection Accessories { get => accessories; set { accessories = value; OnPropertyChanged(); } } /// 主料信息集合 public ObservableCollection Ingredients { get => ingredients; set { ingredients = value; OnPropertyChanged(); } } /// 调料信息集合 public ObservableCollection Seasonings { get => seasonings; set { seasonings = value; OnPropertyChanged(); } } /// 删除辅料信息 public BPARelayCommand RemoveAccessoryCommand { get; set; } /// 删除主料信息 public BPARelayCommand RemoveIngreditentCommand { get; set; } /// 删除调料信息 public BPARelayCommand RemoveSeasoningCommand { get; set; } /// 添加物料信息。 public BPARelayCommand AddMaterialCommand { get; set; } /// 编辑物料信息。 public BPARelayCommand EditCommand { get; set; } } }