diff --git a/BBWY.Client/APIServices/QiKu/ConsumableService.cs b/BBWY.Client/APIServices/QiKu/ConsumableService.cs index eb10a179..fe32e568 100644 --- a/BBWY.Client/APIServices/QiKu/ConsumableService.cs +++ b/BBWY.Client/APIServices/QiKu/ConsumableService.cs @@ -51,7 +51,7 @@ namespace BBWY.Client.APIServices public ApiResponse Search(ConsumableSearchRequest consumable) { - return SendRequest(globalContext.QKApiHost, "api/Consumable/Search", + return SendRequest(globalContext.QKApiHost, "api/Consumable/SearchConsumableList", consumable , null, HttpMethod.Post); } diff --git a/BBWY.Client/Models/APIModel/Request/ConsumableRequest.cs b/BBWY.Client/Models/APIModel/Request/ConsumableRequest.cs index 67307e0c..718a3ade 100644 --- a/BBWY.Client/Models/APIModel/Request/ConsumableRequest.cs +++ b/BBWY.Client/Models/APIModel/Request/ConsumableRequest.cs @@ -9,8 +9,8 @@ namespace BBWY.Client.Models.APIModel.Request public class ConsumableResponse { - public int OrderCount { get; set; } - public ConsumableModel[] Consumables { get; set; } + public int TotalCount { get; set; } + public ConsumableModel[] SearchConsumableList { get; set; } } public class ConsumableSearchRequest @@ -67,6 +67,6 @@ namespace BBWY.Client.Models.APIModel.Request /// /// 耗材归属 /// - public long ConsumableTypeId { get; set; } + public long? ConsumableTypeId { get; set; } } } diff --git a/BBWY.Client/Models/APIModel/Response/PackTask/GetConsumableTypeResponse.cs b/BBWY.Client/Models/APIModel/Response/PackTask/GetConsumableTypeResponse.cs index fb8a75ba..edadae7b 100644 --- a/BBWY.Client/Models/APIModel/Response/PackTask/GetConsumableTypeResponse.cs +++ b/BBWY.Client/Models/APIModel/Response/PackTask/GetConsumableTypeResponse.cs @@ -6,8 +6,14 @@ namespace BBWY.Client.Models.APIModel.Response.PackTask { public class GetConsumableTypeResponse:NotifyObject { - public string ConsumableTypeName { get; set; } - public long ConsumableTypeId { get; set; } + private string consumableTypeName; + + public string ConsumableTypeName { get => consumableTypeName; set { Set(ref consumableTypeName, value); } } + + + private long consumableTypeId; + + public long ConsumableTypeId { get => consumableTypeId; set { Set(ref consumableTypeId, value); } } } } diff --git a/BBWY.Client/Models/PackTask/ConsumableModel.cs b/BBWY.Client/Models/PackTask/ConsumableModel.cs index 576cf638..db3d9f9e 100644 --- a/BBWY.Client/Models/PackTask/ConsumableModel.cs +++ b/BBWY.Client/Models/PackTask/ConsumableModel.cs @@ -27,9 +27,14 @@ namespace BBWY.Client.Models.PackTask }; public ObservableCollection ConsumableTypeList { get => consumableTypeList; set { Set(ref consumableTypeList, value); } } - private ConsumableType? consumableType; - public ConsumableType? ConsumableType - { get => consumableType; set { Set(ref consumableType, value); } } + private string consumableTypeName; + public string ConsumableTypeName + { get => consumableTypeName; set { Set(ref consumableTypeName, value); } } + + + private string addConsumableTypeName; + public string AddConsumableTypeName + { get => addConsumableTypeName; set { Set(ref addConsumableTypeName, value); } } @@ -37,6 +42,7 @@ namespace BBWY.Client.Models.PackTask public ICommand EditConsumableCommand { get; set; } public ICommand DeletedConsumableCommand { get; set; } public ICommand SaveConsumableCommand { get; set; } + public ICommand AddConsumableTypeCommand { get; set; } public Action ReflashDatas { get; set; } public ConsumableModel(ConsumableService consumableService) @@ -50,8 +56,17 @@ namespace BBWY.Client.Models.PackTask { GetConsumableTypeList(); } + AddConsumableTypeCommand= new RelayCommand(AddConsumableType); } + private void AddConsumableType() + { + var res = consumableService.AddConsumableType(AddConsumableTypeName); + if (res.Success) + { + GetConsumableTypeList(); + } + } private long consumableTypeId; public long ConsumableTypeId @@ -85,6 +100,7 @@ namespace BBWY.Client.Models.PackTask Weigth = Weigth, Width = Width, ConsumableTypeId = ConsumableTypeId, + }); } @@ -154,7 +170,7 @@ namespace BBWY.Client.Models.PackTask public void EditConsumable() { - GetConsumableTypeList(); + //GetConsumableTypeList(); EditConsumable add = new EditConsumable(new ConsumableModel(consumableService) { Heigth = this.Heigth, @@ -165,8 +181,9 @@ namespace BBWY.Client.Models.PackTask Remark = this.Remark, Width = this.Width, Price = this.Price, - ConsumableType = this.ConsumableType, - ConsumableTypeList = this.ConsumableTypeList + ConsumableTypeList = this.ConsumableTypeList, + ConsumableTypeName=this.ConsumableTypeName, + ConsumableTypeId = this.ConsumableTypeId, }); diff --git a/BBWY.Client/ViewModels/PackTask/ConsumableViewModel.cs b/BBWY.Client/ViewModels/PackTask/ConsumableViewModel.cs index 50ab6337..7f54e59f 100644 --- a/BBWY.Client/ViewModels/PackTask/ConsumableViewModel.cs +++ b/BBWY.Client/ViewModels/PackTask/ConsumableViewModel.cs @@ -52,6 +52,7 @@ namespace BBWY.Client.ViewModels.PackTask public ICommand TaskPageIndexChangedCommand { get; set; } public ICommand AddConsumableCommand { get; set; } public ICommand SearchConsumableCommand { get; set; } + private readonly ConsumableService consumableService; public ConsumableViewModel(ConsumableService consumableService) @@ -68,7 +69,11 @@ namespace BBWY.Client.ViewModels.PackTask LoadIndex(p.PageIndex); }); SearchConsumable(); + } + + + private void LoadIndex(int pageIndex) { PageIndex = pageIndex;// @@ -90,10 +95,10 @@ namespace BBWY.Client.ViewModels.PackTask if (res.Success) { ConsumableList = new ObservableCollection(); - if (res.Data != null && res.Data.Consumables != null && res.Data.Consumables.Count() > 0) + if (res.Data != null && res.Data.SearchConsumableList != null && res.Data.SearchConsumableList.Count() > 0) { - OrderCount = res.Data.OrderCount; - foreach (var item in res.Data.Consumables) + OrderCount = res.Data.TotalCount; + foreach (var item in res.Data.SearchConsumableList) { App.Current.Dispatcher.Invoke(() => { @@ -107,8 +112,8 @@ namespace BBWY.Client.ViewModels.PackTask Remark = item.Remark, Weigth = item.Weigth, Width = item.Width, - ConsumableType = item.ConsumableType, - + ConsumableTypeName =item.ConsumableTypeName, + ConsumableTypeId = item.ConsumableTypeId, }); }); } diff --git a/BBWY.Client/ViewModels/PackTask/EditConsumableViewModel.cs b/BBWY.Client/ViewModels/PackTask/EditConsumableViewModel.cs index be3db589..f6a3f4ac 100644 --- a/BBWY.Client/ViewModels/PackTask/EditConsumableViewModel.cs +++ b/BBWY.Client/ViewModels/PackTask/EditConsumableViewModel.cs @@ -1,11 +1,207 @@ -using BBWY.Common.Models; +using BBWY.Client.APIServices; +using BBWY.Client.Models.APIModel.Request; +using BBWY.Client.Models; +using BBWY.Client.Models.PackTask; +using BBWY.Client.Views.PackTask; +using BBWY.Common.Models; +using GalaSoft.MvvmLight.Command; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Text; +using System.Windows; +using System.Windows.Input; +using BBWY.Client.Models.APIModel.Response.PackTask; namespace BBWY.Client.ViewModels.PackTask { public class EditConsumableViewModel:BaseVM,IDenpendency { + public ObservableCollection consumableTypeList = new ObservableCollection() + { + + }; + public ObservableCollection ConsumableTypeList { get => consumableTypeList; set { Set(ref consumableTypeList, value); } } + + private string consumableTypeName; + public string ConsumableTypeName + { get => consumableTypeName; set { Set(ref consumableTypeName, value); } } + + + private string addConsumableTypeName; + public string AddConsumableTypeName + { get => addConsumableTypeName; set { Set(ref addConsumableTypeName, value); } } + + + + public ConsumableService consumableService; + public ICommand EditConsumableCommand { get; set; } + public ICommand DeletedConsumableCommand { get; set; } + public ICommand SaveConsumableCommand { get; set; } + public ICommand AddConsumableTypeCommand { get; set; } + public Action ReflashDatas { get; set; } + + public EditConsumableViewModel(ConsumableService consumableService) + { + this.consumableService = consumableService; + EditConsumableCommand = new RelayCommand(EditConsumable); + + DeletedConsumableCommand = new RelayCommand>(DeletedConsumable); + SaveConsumableCommand = new RelayCommand(SaveConsumable); + if (consumableService != null) + { + GetConsumableTypeList(); + } + AddConsumableTypeCommand = new RelayCommand(AddConsumableType); + } + + private void AddConsumableType() + { + var res = consumableService.AddConsumableType(AddConsumableTypeName); + if (res.Success) + { + GetConsumableTypeList(); + } + } + + private long consumableTypeId; + public long ConsumableTypeId + { get => consumableTypeId; set { Set(ref consumableTypeId, value); } } + + + public void SaveConsumable(object obj) + { + if (string.IsNullOrEmpty(Name)) + { + new TipsWindow("耗材品名不能为空!").Show(); + return; + } + + if (this.Price == null) + { + new TipsWindow("价格不能为空!").Show(); + return; + } + ApiResponse res = null; + if (Id > 0)//修改 + { + res = consumableService.Edit(new ConsuableRequest + { + Id = Id, + Heigth = Heigth, + Length = Length, + Name = Name, + Price = Price.Value, + Remark = Remark, + Weigth = Weigth, + Width = Width, + ConsumableTypeId = ConsumableTypeId, + }); + + } + else + { + res = consumableService.Add(new ConsuableRequest + { + + Heigth = Heigth, + Length = Length, + Name = Name, + Price = Price.Value, + Remark = Remark, + Weigth = Weigth, + Width = Width, + ConsumableTypeId = ConsumableTypeId, + }); + + } + + if (res != null && res.Success) + { + var win = obj as System.Windows.Window; + + ViewModelLocator viewModel = new ViewModelLocator(); + var con = viewModel.Consumable; + con.SearchConsumable(); + //if (ReflashDatas != null) ReflashDatas(); + win.Close(); + } + else + { + if (res != null) + new TipsWindow(res.Msg).Show(); + } + } + public ConsumableModel model; + + public void DeletedConsumable(ObservableCollection list) + { + MessageBoxResult result = System.Windows.MessageBox.Show("是否删除?", "提示", + MessageBoxButton.YesNo, + MessageBoxImage.Warning); + if (result != MessageBoxResult.Yes) return; + + var res = consumableService.Deleted(Id); + if (res.Success) + { + ViewModelLocator viewModel = new ViewModelLocator(); + var con = viewModel.Consumable; + con.SearchConsumable(); + list.Remove(model); + } + } + + + + void GetConsumableTypeList() + { + var res = consumableService.GetConsumableTypeList(); + if (res.Success && res.Data != null) + { + ConsumableTypeList = res.Data; + + } + } + + + public void EditConsumable() + { + GetConsumableTypeList(); + EditConsumable add = new EditConsumable(new ConsumableModel(consumableService) + { + Heigth = this.Heigth, + Length = this.Length, + Id = this.Id, + Name = this.Name, + Weigth = this.Weigth, + Remark = this.Remark, + Width = this.Width, + Price = this.Price, + ConsumableTypeId = this.ConsumableTypeId, + ConsumableTypeList = this.ConsumableTypeList, + ConsumableTypeName = this.ConsumableTypeName, + + }); + + add.ShowDialog(); + + } + + private long id; + public long Id { get => id; set { Set(ref id, value); } } + private string name; + public string Name { get => name; set { Set(ref name, value); } } + private decimal? price; + public decimal? Price { get => price; set { Set(ref price, value); } } + private double? weigth; + public double? Weigth { get => weigth; set { Set(ref weigth, value); } } + private double? length; + public double? Length { get => length; set { Set(ref length, value); } } + private double? width; + public double? Width { get => width; set { Set(ref width, value); } } + private double? heigth; + public double? Heigth { get => heigth; set { Set(ref heigth, value); } } + private string remark; + public string Remark { get => remark; set { Set(ref remark, value); } } } } diff --git a/BBWY.Client/Views/PackTask/Consumable.xaml b/BBWY.Client/Views/PackTask/Consumable.xaml index 5c8ddb4d..53197c21 100644 --- a/BBWY.Client/Views/PackTask/Consumable.xaml +++ b/BBWY.Client/Views/PackTask/Consumable.xaml @@ -50,6 +50,9 @@ Background="{StaticResource Button.Selected.Background}" BorderThickness="0" Foreground="White"> + +