步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.0 KiB

2 years ago
using BBWY.Client.APIServices;
using BBWY.Client.Models.APIModel.Request;
using BBWY.Client.ViewModels;
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.Resources;
using System.Text;
using System.Windows.Input;
using System.Windows.Media.TextFormatting;
namespace BBWY.Client.Models.PackTask
{
public class ConsumableModel : BaseVM, IDenpendency
{
public ConsumableService consumableService;
public ICommand EditConsumableCommand { get; set; }
public ICommand DeletedConsumableCommand { get; set; }
public ICommand SaveConsumableCommand { get; set; }
public Action ReflashDatas { get; set; }
public ConsumableModel(ConsumableService consumableService)
{
this.consumableService = consumableService;
EditConsumableCommand = new RelayCommand(EditConsumable);
DeletedConsumableCommand = new RelayCommand<ObservableCollection<ConsumableModel>>(DeletedConsumable);
SaveConsumableCommand = new RelayCommand<object>(SaveConsumable);
}
public void SaveConsumable(object obj)
{
if (string.IsNullOrEmpty(Name))
{
new TipsWindow("耗材品名不能为空!").Show();
return;
}
if (this.Price == null)
{
new TipsWindow("价格不能为空!").Show();
return;
}
ApiResponse<object> 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
});
}
else
{
res = consumableService.Add(new ConsuableRequest
{
Heigth = Heigth,
Length = Length,
Name = Name,
Price = Price.Value,
Remark = Remark,
Weigth = Weigth,
Width = Width
});
}
if (res != null && res.Success)
{
var win = obj as System.Windows.Window;
if (ReflashDatas != null) ReflashDatas();
win.Close();
}
else
{
new TipsWindow(res.Msg).Show();
}
}
public void DeletedConsumable(ObservableCollection<ConsumableModel> list)
{
var res = consumableService.Deleted(Id);
if (res.Success)
{
list.Remove(this);
}
}
public void EditConsumable()
{
EditConsumable add = new EditConsumable(this);
add.Show();
}
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); } }
}
}