步步为盈
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.

684 lines
25 KiB

2 years ago
using AutoMapper;
using AutoMapper.Internal;
using BBWY.Client.APIServices;
2 years ago
using BBWY.Client.Helpers;
2 years ago
using BBWY.Client.Models;
using BBWY.Client.Models.APIModel.Request;
using BBWY.Client.Models.APIModel.Response.PackTask;
using BBWY.Client.Models.PackTask;
using BBWY.Client.Views.PackTask;
using BBWY.Common.Models;
using GalaSoft.MvvmLight.Command;
2 years ago
using HandyControl.Controls;
2 years ago
using Microsoft.Extensions.Logging;
2 years ago
using NPOI.Util;
2 years ago
using Org.BouncyCastle.Asn1.Crmf;
2 years ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
2 years ago
using System.Diagnostics;
2 years ago
using System.Drawing.Printing;
using System.IO;
2 years ago
using System.Linq;
2 years ago
using System.Reflection;
2 years ago
using System.Reflection.Metadata.Ecma335;
2 years ago
using System.Runtime.CompilerServices;
2 years ago
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
2 years ago
using System.Windows.Media.Imaging;
2 years ago
namespace BBWY.Client.ViewModels.PackTask
{
public class PackServiceViewModel : BaseVM, IDenpendency
{
private int? floorDragNumber;
public int? FloorDragNumber { get => floorDragNumber; set { Set(ref floorDragNumber, value); } }
2 years ago
private string packUserName;
/// <summary>
/// 打包人
/// </summary>
public string PackUserName { get => packUserName; set { Set(ref packUserName, value); } }
private int incrementPartTaskCount;
/// <summary>
/// 配件任务数量
/// </summary>
public int IncrementPartTaskCount { get => incrementPartTaskCount; set { Set(ref incrementPartTaskCount, value); } }
2 years ago
2 years ago
//public ObservableCollection<string> incrementPartCountList = new ObservableCollection<string>() {
//"0","1","2","3","4件以上"
//};
//public ObservableCollection<string> IncrementPartCountList { get => incrementPartCountList; set { Set(ref incrementPartCountList, value); } }
private int incrementPartCount;
/// <summary>
/// 配件数量
/// </summary>
public int IncrementPartCount { get => incrementPartCount; set { Set(ref incrementPartCount, value); } }
private string directionalFees;
2 years ago
/// <summary>
/// 定向费用
/// </summary>
2 years ago
public string DirectionalFees { get => directionalFees; set { Set(ref directionalFees, value); } }
2 years ago
2 years ago
private BitmapImage barcodeImage;
/// <summary>
/// 任务Id条形码
/// </summary>
public BitmapImage BarcodeImage { get => barcodeImage; set { Set(ref barcodeImage, value); } }
private BitmapImage taskImage;
/// <summary>
/// 任务Id条形码
/// </summary>
public BitmapImage TaskImage { get => taskImage; set { Set(ref taskImage, value); } }
private string printName;
public string PrintName { get => printName; set { Set(ref printName, value); } }
private ObservableCollection<string> printList;
/// <summary>
/// 打印机列表
/// </summary>
public ObservableCollection<string> PrintList { get => printList; set { Set(ref printList, value); } }
2 years ago
private ObservableCollection<PackTaskModel> packTaskList;
/// <summary>
/// 动态数据表
/// </summary>
public ObservableCollection<PackTaskModel> PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }
private PackTaskModel packTaskModel;
public PackTaskModel PackTaskModel { get => packTaskModel; set { Set(ref packTaskModel, value); } } //
2 years ago
public ICommand AddPackServiceCommand { get; set; }
2 years ago
public ICommand AddBasicPackServiceCommand { get; set; }
2 years ago
public ICommand AddIncreateServiceCommand { get; set; }
public ICommand AddConsumableCommand { get; set; }
public ICommand UpLoadPackCommand { get; set; }
public ICommand SetAllCountCommand { get; set; }
2 years ago
public ICommand PrintCommand { get; set; }
2 years ago
readonly PackTaskService packTaskService;
readonly ConsumableService consumableService;
2 years ago
readonly PackDetailService packDetailService;
2 years ago
readonly BatchPurchaseService batchPurchaseService;
2 years ago
private ObservableCollection<PackItemModel> increateList = new ObservableCollection<PackItemModel>();
public ObservableCollection<PackItemModel> IncreateList { get => increateList; set { Set(ref increateList, value); } } //
2 years ago
2 years ago
//private ObservableCollection<PackItemModel>
// packList = new ObservableCollection<PackItemModel>();
//public ObservableCollection<PackItemModel> PackList { get => packList; set { Set(ref packList, value); } } //
2 years ago
2 years ago
private ObservableCollection<PackItemModel>
consumableServiceList = new ObservableCollection<PackItemModel>();
public ObservableCollection<PackItemModel> ConsumableServiceList { get => consumableServiceList; set { Set(ref consumableServiceList, value); } } //
2 years ago
2 years ago
private ObservableCollection<PackItemModel> basicPackProcessList = new ObservableCollection<PackItemModel>();
private ObservableCollection<PackItemModel> incrementProcessList = new ObservableCollection<PackItemModel>();
/// <summary>
///增量工序
/// </summary>
public ObservableCollection<PackItemModel> IncrementProcessList { get => incrementProcessList; set { Set(ref incrementProcessList, value); } } //
/// <summary>
/// 基础包装工序
/// </summary>
public ObservableCollection<PackItemModel> BasicPackProcessList { get => basicPackProcessList; set { Set(ref basicPackProcessList, value); } }
2 years ago
private string discount = "1";
/// <summary>
/// 折扣
/// </summary>
public string Discount { get => discount; set { Set(ref discount, value); } } //
2 years ago
2 years ago
2 years ago
public ObservableCollection<PackServiceDTO> IncreateServiceList { get; set; } = new ObservableCollection<PackServiceDTO>();
2 years ago
public ObservableCollection<PackUser> MemberList { get; set; } = new ObservableCollection<PackUser>();
public ObservableCollection<ConsumableModel> ConsumableList { get; set; } = new ObservableCollection<ConsumableModel>();
2 years ago
public ObservableCollection<PackServiceDTO> PackServiceList { get; set; } = new ObservableCollection<PackServiceDTO>();
2 years ago
/// <summary>
/// 基础包装服务项目列表
/// </summary>
public ObservableCollection<PackServiceDTO> BasicPackServiceList { get; set; } = new ObservableCollection<PackServiceDTO>();
2 years ago
private readonly PackServiceService packServiceService;
2 years ago
2 years ago
/// <summary>
/// 加载原数据
/// </summary>
public List<PackItemModel> LoadList = new List<PackItemModel>();
2 years ago
2 years ago
public void InitPrintList()
{
2 years ago
TaskImage = MyPrintHelper.GetBarcodeImage(TaskId.ToString(), 300, 60);
2 years ago
BarcodeImage = MyPrintHelper.GetBarcodeImage(SkuId, 300, 60);
PrintList = new ObservableCollection<string>();
var printingNames = PrinterSettings.InstalledPrinters;//获取本机的打印机数据
int index = -1;
int selectIndex = 0;
foreach (string name in printingNames)
{
if (name == "Microsoft XPS Document Writer" || name == "Microsoft Print to PDF" || name == "Fax")
{
continue;
}
index++;
if (name.Contains("Deli"))
{
selectIndex = index;
}
PrintList.Add(name);
}
try
{
var applicationPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string printNames = Path.Combine(applicationPath, "printName.init");
if (File.Exists(printNames))
{
PrintName = File.ReadAllText(printNames);
}
else
{
if (PrintList.Count > 0)
{
PrintName = PrintList[0].ToString();
}
}
}
catch (Exception)
{
}
}
2 years ago
public PackServiceViewModel(PackTaskService packTaskService, ConsumableService consumableService, PackServiceService packServiceService, PackDetailService packDetailService, BatchPurchaseService batchPurchaseService)//, long taskId
2 years ago
{
2 years ago
//TaskId = taskId;
2 years ago
this.consumableService = consumableService;
this.packTaskService = packTaskService;
2 years ago
this.packServiceService = packServiceService;
this.packDetailService = packDetailService;
2 years ago
this.batchPurchaseService = batchPurchaseService;
2 years ago
AddIncreateServiceCommand = new RelayCommand(AddIncreateService);
AddPackServiceCommand = new RelayCommand(AddPackService);
2 years ago
AddBasicPackServiceCommand = new RelayCommand(AddBasicPackService);
2 years ago
AddConsumableCommand = new RelayCommand(AddConsumable);
UpLoadPackCommand = new RelayCommand<object>(UpLoadPack);
SetAllCountCommand = new RelayCommand<object>(SetAllCount);
2 years ago
2 years ago
//加载数据
2 years ago
//LoadPackDatas();
2 years ago
}
2 years ago
2 years ago
/// <summary>
/// 加载任务数据
/// </summary>
2 years ago
public void LoadPackDatas()
2 years ago
{
2 years ago
IncrementPartTaskCount = TaskCount;
2 years ago
try
{
InitPrintList();
}
catch (Exception)
{
}
2 years ago
LoadList = new List<PackItemModel>();
2 years ago
Task task = Task.Factory.StartNew(() =>
2 years ago
{
2 years ago
var resMember = this.packTaskService.GetPackMembers();//成员表
if (resMember.Success)
{
MemberList = new ObservableCollection<PackUser>();
foreach (var item in resMember.Data)
{
App.Current.Dispatcher.Invoke(() =>
{
MemberList.Add(item);
});
}
}
var res = this.packDetailService.GetPackTaskDetail(TaskId);
2 years ago
2 years ago
if (res.Success)
{
2 years ago
IncrementPartCount = res.Data.IncrementPartCount == null ? 0 : res.Data.IncrementPartCount.Value;
2 years ago
if (res.Data != null && res.Data.IncrementItemList.Count() > 0)
{
IncreateServiceList = new ObservableCollection<PackServiceDTO>();
foreach (var packService in res.Data.IncrementItemList)
{
if (packService.ServiceType == ServiceType.)
App.Current.Dispatcher.Invoke(() =>
{
IncreateServiceList.Add(packService);//加载增值服务列表
});
}
}
if (res.Data != null && res.Data.ProcessItemList.Count() > 0)
{
PackServiceList = new ObservableCollection<PackServiceDTO>();
BasicPackServiceList = new ObservableCollection<PackServiceDTO>();
foreach (var packService in res.Data.ProcessItemList)
{
if (packService.ServiceType == ServiceType.)
2 years ago
2 years ago
App.Current.Dispatcher.Invoke(() =>
{
BasicPackServiceList.Add(packService);
2 years ago
if (packService.Name != "贴条码")
PackServiceList.Add(packService);//加载工序服务列表
2 years ago
});
}
}
if (res.Data != null && res.Data.ConsumableItemList.Count() > 0)
{
ConsumableList = new ObservableCollection<ConsumableModel>();
foreach (var item in res.Data.ConsumableItemList)
{
App.Current.Dispatcher.Invoke(() =>
{
ConsumableList.Add(new ConsumableModel(consumableService)
{
Width = item.Width,
Weigth = item.Weigth,
Remark = item.Remark,
Price = item.Price,
Name = item.Name,
Length = item.Length,
Heigth = item.Heigth,
Id = item.Id
});
});
}
}
2 years ago
if (res.Data.IncreateList != null)
{
2 years ago
IncreateList = new ObservableCollection<PackItemModel>();
2 years ago
2 years ago
foreach (var item in res.Data.IncreateList)
{
App.Current.Dispatcher.Invoke(() =>
{
2 years ago
IncreateList.Add(new PackItemModel()
2 years ago
{
2 years ago
MemberList = MemberList,
IncreateServiceList = IncreateServiceList,
2 years ago
ItemCount = item.ItemCount,
ItemName = item.ItemName,
SelectId = item.SelectId,
SelectUserId = item.SelectUserId,
MemberName = item.MemberName
});
});
}
2 years ago
2 years ago
}
2 years ago
if (res.Data.ConsumableList != null)
2 years ago
{
2 years ago
ConsumableServiceList = new ObservableCollection<PackItemModel>();
foreach (var item in res.Data.ConsumableList)
2 years ago
{
App.Current.Dispatcher.Invoke(() =>
{
2 years ago
ConsumableServiceList.Add(new PackItemModel()
2 years ago
{
2 years ago
MemberList = MemberList,
2 years ago
ConsumableList = ConsumableList,
ItemCount = item.ItemCount,
ItemName = item.ItemName,
SelectId = item.SelectId,
});
});
}
}
if (res.Data.IncrementProcessList != null)
{
IncrementProcessList = new ObservableCollection<PackItemModel>();
foreach (var item in res.Data.IncrementProcessList)
{
App.Current.Dispatcher.Invoke(() =>
{
IncrementProcessList.Add(new PackItemModel()
{
MemberList = MemberList,
PackServiceList = PackServiceList.Copy(),
2 years ago
ItemCount = item.ItemCount,
ItemName = item.ItemName,
SelectId = item.SelectId,
SelectUserId = item.SelectUserId,
MemberName = item.MemberName
});
});
}
}
2 years ago
if (res.Data.BasicPackProcessList != null)
2 years ago
{
2 years ago
BasicPackProcessList = new ObservableCollection<PackItemModel>();
foreach (var item in res.Data.BasicPackProcessList)
2 years ago
{
App.Current.Dispatcher.Invoke(() =>
{
2 years ago
BasicPackProcessList.Add(new PackItemModel()
2 years ago
{
2 years ago
MemberList = MemberList,
2 years ago
PackServiceList = BasicPackServiceList.Copy(),
2 years ago
ItemCount = item.ItemCount,
ItemName = item.ItemName,
SelectId = item.SelectId,
2 years ago
SelectUserId = item.SelectUserId,
MemberName = item.MemberName
2 years ago
});
});
}
}
2 years ago
2 years ago
LoadList.AddRange(IncreateList);
2 years ago
LoadList.AddRange(IncrementProcessList);
DirectionalFees = res.Data.DirectionalFees?.ToString();
2 years ago
}
});
}
2 years ago
2 years ago
/// <summary>
2 years ago
/// 批量设置耗材数量
2 years ago
/// </summary>
/// <param name="obj"></param>
private void SetAllCount(object obj)
{
SetCountWindow set = new SetCountWindow();
set.SetCount = new Action<int>((s) =>
{
var lbox = obj as ListBox;
var serviceList = lbox.ItemsSource as ObservableCollection<PackItemModel>;
foreach (var item in serviceList)
{
if (item.ItemName == null)
{
item.ItemName = ConsumableList.SingleOrDefault(c => c.Id == item.SelectId).Name;
}
item.ItemCount = s;
}
lbox.ItemsSource = serviceList;
});
set.Show();
}
private long taskId;
public long TaskId { get => taskId; set { Set(ref taskId, value); } } //
private int taskCount;
public int TaskCount { get => taskCount; set { Set(ref taskCount, value); } } //
2 years ago
public string OrderId { get; set; }
public string SkuId { get; set; }
2 years ago
2 years ago
2 years ago
private List<PackItemModel> IsOverCount(ObservableCollection<PackItemModel> packItemModels, bool needUserId = true)
{
2 years ago
2 years ago
2 years ago
List<PackItemModel> disItems = new List<PackItemModel>();
2 years ago
2 years ago
foreach (var packItem in packItemModels)//增值服务上传
2 years ago
{
2 years ago
var item = new PackItemModel
2 years ago
{
2 years ago
ItemCount = packItem.ItemCount,
SelectId = packItem.SelectId,
SelectUserId = packItem.SelectUserId,
ItemName = packItem.ItemName,
MemberName = packItem.MemberName
};
if (needUserId)
if (item.SelectId <= 0 || string.IsNullOrEmpty(item.SelectUserId) || item.ItemCount <= 0)
{
System.Windows.MessageBox.Show($"数据输入有误");
return null;
}
else
if (item.SelectId <= 0 || item.ItemCount <= 0)
{
System.Windows.MessageBox.Show($"数据输入有误");
return null;
}
2 years ago
if (item.ItemCount > TaskCount)
{
2 years ago
System.Windows.MessageBox.Show($"{item.ItemName}:{item.ItemCount}超出任务量{TaskCount}");
return null;
2 years ago
}
2 years ago
if (disItems.Select(a => a.SelectId).Contains(item.SelectId))//相同服务 存在累加
2 years ago
{
2 years ago
var data = disItems.SingleOrDefault(a => a.SelectId == item.SelectId);
2 years ago
2 years ago
if (data != null) data.ItemCount += item.ItemCount;
2 years ago
2 years ago
if (data.ItemCount > TaskCount)//累积超出任务量
2 years ago
{
2 years ago
System.Windows.MessageBox.Show($"{item.ItemName}:{data.ItemCount}超出任务量{TaskCount}");
return null;
2 years ago
}
continue;
}
2 years ago
disItems.Add(item);
}
2 years ago
2 years ago
return disItems;
}
2 years ago
2 years ago
2 years ago
/// <summary>
/// 上传数据 (判断是否超量) 统一上传
/// </summary>
private void UpLoadPack(object obj)
{
decimal? directFees = null;
if (!string.IsNullOrEmpty(DirectionalFees))
2 years ago
{
2 years ago
try
2 years ago
{
2 years ago
directFees = decimal.Parse(DirectionalFees);
2 years ago
}
2 years ago
catch (Exception)
2 years ago
{
2 years ago
directFees = null;
2 years ago
}
2 years ago
2 years ago
}
2 years ago
2 years ago
PackTaskDetailRequest packTaskDetail = new PackTaskDetailRequest();
packTaskDetail.DirectionalFees = directFees;
packTaskDetail.IncrementPartCount = IncrementPartCount;
packTaskDetail.IncrementPartTaskCount = IncrementPartTaskCount;
packTaskDetail.TaskId = TaskId;
2 years ago
2 years ago
decimal IncreateFees = 0, PackFees = 0, ConsumableFees = 0, DiscountPrice = 0;
2 years ago
2 years ago
var disIncreateList = IsOverCount(IncreateList);
if (disIncreateList == null) return;
2 years ago
2 years ago
var disBasicPackProcessList = IsOverCount(BasicPackProcessList);
if (disBasicPackProcessList == null) return;
2 years ago
2 years ago
if (disBasicPackProcessList.Select(d => d.SelectId).Distinct().Count() > 2)
2 years ago
{
2 years ago
System.Windows.MessageBox.Show("基础包装工序不能超过两道");
return;
2 years ago
}
2 years ago
2 years ago
var disIncrementProcessList = IsOverCount(IncrementProcessList);
if (disIncrementProcessList == null) return;
2 years ago
2 years ago
if (disBasicPackProcessList.Select(d=>d.ItemName).Distinct().Count()==1&& disBasicPackProcessList.Select(d => d.ItemName).Contains("贴条码")
&& disIncrementProcessList.Count>0)
{
System.Windows.MessageBox.Show("只有一道贴码工序,无法添加增值包装工序");
return;
}
2 years ago
var disConsumableServiceList = IsOverCount(ConsumableServiceList, false);
if (disConsumableServiceList == null) return;
2 years ago
2 years ago
packTaskDetail.IncreateList = IncreateList.ToList();
packTaskDetail.BasicPackProcessList = BasicPackProcessList.ToList();
packTaskDetail.IncrementProcessList = IncrementProcessList.ToList();
packTaskDetail.ConsumableList = disConsumableServiceList;
2 years ago
2 years ago
var res = packDetailService.SetPackTaskDetail(packTaskDetail);
2 years ago
if (res != null && res.Success)
{
2 years ago
// new TipsWindow("上传成功!").Show();
2 years ago
var win = obj as System.Windows.Window;
2 years ago
if (SetAllFees != null)
2 years ago
SetAllFees();
2 years ago
win.Close();
}
}
/// <summary>
/// 更新 打包员 和费用数据
/// </summary>
2 years ago
public Action SetAllFees { get; set; }
2 years ago
private void AddPackService()
{
2 years ago
App.Current.Dispatcher.Invoke(new Action(() =>
2 years ago
{
2 years ago
IncrementProcessList.Add(new PackItemModel()
{
ItemCount = TaskCount,
MemberList = MemberList,
PackServiceList = PackServiceList,
});
}));
}
private void AddBasicPackService()
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
BasicPackProcessList.Add(new PackItemModel()
{
ItemCount = TaskCount,
MemberList = MemberList,
2 years ago
PackServiceList = BasicPackServiceList,
2 years ago
});
}));
2 years ago
}
2 years ago
2 years ago
private void AddIncreateService()
{
2 years ago
App.Current.Dispatcher.Invoke(new Action(() =>
2 years ago
{
2 years ago
IncreateList.Add(new PackItemModel()
{
ItemCount = TaskCount,
IncreateServiceList = IncreateServiceList,
MemberList = MemberList,
});
}));
2 years ago
}
private void AddConsumable()
{
2 years ago
App.Current.Dispatcher.Invoke(new Action(() =>
2 years ago
{
2 years ago
ConsumableServiceList.Add(new PackItemModel()
{
ItemCount = TaskCount,
ConsumableList = ConsumableList
});
}));
2 years ago
}
}
}