|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- 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 EditRawMaterialViewModel : NotifyBase
- {
- public EditRawMaterialViewModel()
- {
- ActionManage.GetInstance.Register((object o) =>
- {
- //为Null代表是新增。
- if (o != null && o is MaterialBase material)
- {
- if (String.IsNullOrEmpty(material.Id) || material.Id.Length <= 0)
- {
- IsNewAdd = true;
- }
- else
- {
- IsNewAdd = false;
- if (material is AccessoriesTB)
- {
- CurrentMaterialType = "辅料";
- }
- else if (material is IngredientsTB)
- {
- CurrentMaterialType = "主料";
- }
- else if (material is SeasoningTB)
- {
- CurrentMaterialType = "调料";
- }
- else
- {
- throw new Exception($"参数不是物料数据类型");
- }
- MaterialName = material.Name;
- MaterialLoc = material.Loc;
- _materialID = material.Id;
- MaterialDescription = material.Description;
- }
- }
- }, "OpenEditRawMaterialView", true);
- ActionManage.GetInstance.Register((object o) =>
- {
- string materialType = o is String ? (String)o : null;
- CurrentMaterialType = materialType!;
- }, "ChangeMaterialType", true);
-
- SaveParamCommand = new BPARelayCommand(() =>
- {
- #region 数据验证
-
- if (!MessageNotify.GetInstance.ShowDialog("请确认,是否保存该物料信息?"))
- {
- return;
- }
-
- if (string.IsNullOrEmpty(MaterialName) || MaterialName.Length <= 0)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,物料名称不正确!");
- return;
- }
- if (MaterialLoc <= 0 && CurrentMaterialType != "主料")
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,物料位置应为正整数!");
- return;
- }
- if (CurrentMaterialType == "调料" && (MaterialLoc <= 0 || MaterialLoc > 3))
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,调料位置应大于0 且小于等于 3 !");
- return;
- }
- if (CurrentMaterialType == "辅料" && (MaterialLoc <= 0 || MaterialLoc > 8))
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"失败,调料位置应大于0 且小于等于 8 !");
- return;
- }
- #endregion 数据验证
-
- //新增
- if (IsNewAdd)
- {
- try
- {
- switch (CurrentMaterialType)
- {
- case "主料":
- //if (SqliteHelper.GetInstance.GetIngredientsInfoByLoc(MaterialLoc))
- //{
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
- // return;
- //}
- IngredientsTB ingredients = new IngredientsTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.AddIngredients(ingredients);
- ActionManage.GetInstance.Send("RefreshIngredients");
- break;
-
- case "辅料":
- if (SqliteHelper.GetInstance.GetAccessoriesInfoByLoc(MaterialLoc))
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
- return;
- }
- AccessoriesTB accessories = new AccessoriesTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.AddAccessories(accessories);
- break;
-
- case "调料":
- if (SqliteHelper.GetInstance.GetSeasoningInfoByLoc(MaterialLoc))
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"添加失败,该位置已有物料!");
- return;
- }
- SeasoningTB seasoning = new SeasoningTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.AddSeasoning(seasoning);
- break;
- }
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"新增物料:{MaterialName} 成功!");
- }
- catch (Exception ex)
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"新增一条物料:{MaterialName} 失败!");
- }
- }
- else
- {
- try
- {
- switch (CurrentMaterialType)
- {
- case "主料":
- //if (SqliteHelper.GetInstance.GetIngredientsInfoByLoc(MaterialLoc))
- //{
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
- // return;
- //}
- IngredientsTB ingredients = new IngredientsTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.EditIngredients(ingredients);
- break;
-
- case "辅料":
- //if (SqliteHelper.GetInstance.GetAccessoriesInfoByLoc(MaterialLoc))
- //{
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
- // return;
- //}
- AccessoriesTB accessories = new AccessoriesTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.EditAccessories(accessories);
- break;
-
- case "调料":
- //if (SqliteHelper.GetInstance.GetSeasoningInfoByLoc(MaterialLoc))
- //{
- // NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改失败,该位置已有物料!");
- // return;
- //}
- SeasoningTB seasoning = new SeasoningTB() { Name = MaterialName, Loc = MaterialLoc, Id = _materialID, Description = MaterialDescription };
- SqliteHelper.GetInstance.EditSeasoning(seasoning);
- break;
- }
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Success, Application.Current.MainWindow, "提示", $"修改物料:{MaterialName} 成功!");
- }
- catch
- {
- NoticeDemoViewModel.OpenMsg(EnumPromptType.Error, Application.Current.MainWindow, "提示", $"修改物料:{MaterialName} 失败!");
- }
- }
- //保存处理。
- ActionManage.GetInstance.Send(true, "CloseEditRawMaterialView");
- });
-
- CancelCommand = new BPARelayCommand(() =>
- {
- ActionManage.GetInstance.Send(false, "CloseEditRawMaterialView");
- });
- }
-
- public BPARelayCommand SaveParamCommand { get; set; }
- public BPARelayCommand CancelCommand { get; set; }
-
- private string _materialID;
-
- public ObservableCollection<string> MaterialType { get; set; } = new ObservableCollection<string>() { "主料", "辅料", "调料" };
-
- private bool _IsNewAdd;
-
- public bool IsNewAdd
- {
- get { return _IsNewAdd; }
- set
- {
- _IsNewAdd = value;
- if (value == true)
- {
- MaterialTypeVis = Visibility.Visible;
- }
- else
- MaterialTypeVis = Visibility.Hidden;
- OnPropertyChanged();
- }
- }
-
- private string _CurrentMaterialType;
-
- /// <summary>物料类型</summary>
- public string CurrentMaterialType
- {
- get { return _CurrentMaterialType; }
- set
- {
- _CurrentMaterialType = value;
- if (value == "主料")
- {
- LocationVis = Visibility.Hidden;
- }
- else
- LocationVis = Visibility.Visible;
- OnPropertyChanged();
- }
- }
-
- private string _MaterialName;
-
- /// <summary>物料名称</summary>
- public string MaterialName
- {
- get { return _MaterialName; }
- set { _MaterialName = value; OnPropertyChanged(); }
- }
-
- private int _MaterialLoc;
-
- /// <summary>物料位置</summary>
- public int MaterialLoc
- {
- get { return _MaterialLoc; }
- set { _MaterialLoc = value; OnPropertyChanged(); }
- }
-
- private string _MaterialDescription;
-
- public string MaterialDescription
- {
- get { return _MaterialDescription; }
- set { _MaterialDescription = value; }
- }
-
- private Visibility _MaterialTypeVis;
-
- /// <summary>是否新增,如果是新增,则显示主料类型框。反之,则不显示。</summary>
- public Visibility MaterialTypeVis
- {
- get { return _MaterialTypeVis; }
- set { _MaterialTypeVis = value; OnPropertyChanged(); }
- }
-
- private Visibility _LocationVis;
-
- /// <summary>是否显示位置框,如果为主料,则不显示。反之,则显示。</summary>
- public Visibility LocationVis
- {
- get { return _LocationVis; }
- set { _LocationVis = value; OnPropertyChanged(); }
- }
- }
- }
|