using BBWY.Client.APIServices.QiKu;
using BBWY.Client.APIServices;
using BBWY.Client.Helpers;
using BBWY.Client.Models.APIModel.Response.PackTask;
using BBWY.Client.Models.PackTask;
using BBWY.Client.Models;
using BBWY.Client.Views.PackTask;
using GalaSoft.MvvmLight.Command;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing.Printing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using WebSocketSharp;
using System.IO;
using BBWY.Client.Models.APIModel;
using Org.BouncyCastle.Bcpg;
using System.Threading;
namespace BBWY.Client.ViewModels.PackTask
{
public class PackDetailViewModel : BaseVM
{
private PackProcessType packProcessType;
///
/// 推荐工序=0,自定义工序=1
///
public PackProcessType PackProcessType { get => packProcessType; set { Set(ref packProcessType, value); } }
private decimal allFees;
///
/// 任务总费用
///
public decimal AllFees { get => allFees; set { Set(ref allFees, value); } }
private decimal processPrice;
///
/// 工序单价
///
public decimal ProcessPrice { get => processPrice; set { Set(ref processPrice, value); } }
private decimal consumableFees;
///
/// 耗材费用
///
public decimal ConsumableFees { get => consumableFees; set { Set(ref consumableFees, value); } }
public ObservableCollection packUserModelList;
public ObservableCollection PackUserModelList { get => packUserModelList; set { Set(ref packUserModelList, value); } }
// private decimal? customProcessSinglePrice;
///
/// 定制工序单价
///
public decimal? CustomProcessSinglePrice
{
get; set;
}
private string directionalSingleFees;
public string DirectionalSingleFees
{
get => directionalSingleFees; set
{
Set(ref directionalSingleFees, value);
try
{
CustomProcessSinglePrice = decimal.Parse(DirectionalSingleFees);
}
catch
{
CustomProcessSinglePrice = null;
}
}
}
private decimal packFees;
///
/// 打包原价
///
public decimal PackFees { get => packFees; set { Set(ref packFees, value); } }
private decimal discountFactory;
///
/// 折扣系数
///
public decimal DiscountFactory { get => discountFactory; set { Set(ref discountFactory, value); } }
private decimal packDiscountFees;
///
/// 打包折后价价
///
public decimal PackDiscountFees { get => packDiscountFees; set { Set(ref packDiscountFees, value); } }
private int processTaskCount;
///
/// 工序任务量
///
public int ProcessTaskCount
{
get => processTaskCount; set
{
Set(ref processTaskCount, value);
if (PackProcessType == PackProcessType.推荐工序 && SelectProcessComboIdV2 > 0 && ProcessTaskCount > 0)
TotalPackFeesDetail(null, ProcessTaskCount, SelectProcessComboIdV2);
if (PackProcessType == PackProcessType.自定义工序 && !SelectProcessType.IsNullOrEmpty() && ProcessTaskCount > 0)
TotalPackFeesDetail(SelectProcessType, ProcessTaskCount, null);
}
}
//void OnProcessTaskCountChanged()
//{
// PackFees = decimal.Parse((ProcessTaskCount * ProcessPrice).ToString("0.00")); ;
// PackDiscountFees = decimal.Parse((PackFees * DiscountFactory).ToString("0.00"));
//}
private ObservableCollection processComboList;
///
/// 套餐类型列表
///
public ObservableCollection ProcessComboList { get => processComboList; set { Set(ref processComboList, value); } }
private ObservableCollection processComboListV2;
///
/// 套餐类型列表
///
public ObservableCollection ProcessComboListV2 { get => processComboListV2; set { Set(ref processComboListV2, value); } }
private long selectProcessComboId;
///
/// 选中套餐类型
///
public long SelectProcessComboId
{
get => selectProcessComboId; set
{
Set(ref selectProcessComboId, value);
OnProcessComboChanged(SelectProcessComboId);
}
}
private long selectProcessComboIdV2;
///
/// 选中套餐类型(推荐工序)
///
public long SelectProcessComboIdV2
{
get => selectProcessComboIdV2; set
{
Set(ref selectProcessComboIdV2, value);
OnProcessComboChanged(SelectProcessComboIdV2);
}
}
public bool isConsumableTypeListEnable;
public bool IsConsumableTypeListEnable { get => isConsumableTypeListEnable; set { Set(ref isConsumableTypeListEnable, value); } }
private void OnProcessComboChanged(long SelectProcessComboId, int type = 1)
{
if (SelectProcessComboId <= 0)
{
return;
}
if (PackProcessType == PackProcessType.推荐工序)
{
if (ProcessComboListV2 == null || ProcessComboListV2.Count <= 0)
{
return;
}
if (!DirectionalSingleFees.IsNullOrEmpty())
DirectionalSingleFees = string.Empty;//
var selectProcessComboData = ProcessComboListV2.
SingleOrDefault(p => p.ProcessComboId == SelectProcessComboId);
App.Current.Dispatcher.Invoke(new Action(() =>
{
ConsumableServiceList.Clear();
}));
IsConsumableTypeListEnable = false;
ProcessPrice = selectProcessComboData.ProcessComboNamePrice;
ConsumableFees = 0;
AllFees = ConsumableFees + PackDiscountFees;
if (selectProcessComboData != null && selectProcessComboData.ConsumableTypeList != null && selectProcessComboData.ConsumableTypeList.Count > 0)//自动添加列表
{
foreach (var item in selectProcessComboData.ConsumableTypeList)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
ConsumableServiceList.Add(new PackItemModel
{
ConsumableTypeList = new ObservableCollection { item.ConsumableTypeName },
ConsumableType = item.ConsumableTypeName,
ConsumableItemList = item.ConsumableList,
//ConsumableItem = item.ConsumableList.FirstOrDefault()?.ConsumableName,
//ConsumablePrice = item.ConsumableList.FirstOrDefault().ConsumablePrice,
TaskCount = ProcessTaskCount,
TotalConsumableFees = ToTalConsumableFees,
}); ;
}));
}
}
//关联工序类型名
var discountRes = processService.GetDiscountFactory(SelectProcessType, ProcessTaskCount, SelectProcessComboIdV2);
if (!discountRes.Success)
{
System.Windows.MessageBox.Show(discountRes.Msg);
return;
}
if (discountRes.Success && discountRes.Data != null)
{
DiscountFactory = discountRes.Data.DiscountFactory;
if (FeesMode == FeesMode.定向收费 && CustomProcessSinglePrice != null)
{
PackFees = decimal.Parse((ProcessTaskCount * CustomProcessSinglePrice.Value).ToString("0.00"));
}
else
{
FeesMode = discountRes.Data.FeesMode;
PackFees = decimal.Parse((ProcessTaskCount * ProcessPrice).ToString("0.00"));
}
PackDiscountFees = decimal.Parse((PackFees * DiscountFactory).ToString("0.00"));
AllFees = ConsumableFees + PackDiscountFees;
}
}
if (PackProcessType == PackProcessType.自定义工序)
{
var selectProcessComboData = ProcessComboList.
SingleOrDefault(p => p.ProcessComboId == SelectProcessComboId);
App.Current.Dispatcher.Invoke(new Action(() =>
{
ConsumableServiceList.Clear();
}));
IsConsumableTypeListEnable = false;
if (SelectProcessType == "定制")
{
IsConsumableTypeListEnable = true;
ConsumableServiceList = new ObservableCollection();
}
else
{
if (!DirectionalSingleFees.IsNullOrEmpty())
DirectionalSingleFees = string.Empty;
}
ConsumableFees = 0;
AllFees = ConsumableFees + PackDiscountFees;
if (selectProcessComboData != null && selectProcessComboData.ConsumableTypeList != null && selectProcessComboData.ConsumableTypeList.Count > 0)//自动添加列表
{
foreach (var item in selectProcessComboData.ConsumableTypeList)
{
App.Current.Dispatcher.Invoke(new Action(() =>
{
ConsumableServiceList.Add(new PackItemModel
{
ConsumableTypeList = new ObservableCollection { item.ConsumableTypeName },
ConsumableType = item.ConsumableTypeName,
ConsumableItemList = item.ConsumableList,
//ConsumableItem = item.ConsumableList.FirstOrDefault()?.ConsumableName,
//ConsumablePrice = item.ConsumableList.FirstOrDefault().ConsumablePrice,
TaskCount = ProcessTaskCount,
TotalConsumableFees = ToTalConsumableFees,
}); ;
}));
}
}
}
if (PackProcessType == PackProcessType.推荐工序 && SelectProcessComboIdV2 > 0 && ProcessTaskCount > 0)
TotalPackFeesDetail(null, ProcessTaskCount, SelectProcessComboIdV2);
if (PackProcessType == PackProcessType.自定义工序 && !SelectProcessType.IsNullOrEmpty() && ProcessTaskCount > 0)
TotalPackFeesDetail(SelectProcessType, ProcessTaskCount, null);
}
private void TotalPackFeesDetail(string processType, int taskCount, long? processComboId)
{
var discountRes = processService.GetDiscountFactory(processType, taskCount, processComboId);
if (!discountRes.Success)
{
System.Windows.MessageBox.Show(discountRes.Msg);
return;
}
if (discountRes.Success && discountRes.Data != null)
{
DiscountFactory = discountRes.Data.DiscountFactory;
if (FeesMode == FeesMode.定向收费 && CustomProcessSinglePrice != null)
{
PackFees = decimal.Parse((taskCount * CustomProcessSinglePrice.Value).ToString("0.00"));
}
else
{
FeesMode = discountRes.Data.FeesMode;
PackFees = decimal.Parse((taskCount * ProcessPrice).ToString("0.00"));
}
PackDiscountFees = decimal.Parse((PackFees * DiscountFactory).ToString("0.00"));
AllFees = ConsumableFees + PackDiscountFees;
}
//统计打包费用
}
private List processTypeList;
///
/// 工序类型列表
///
public List ProcessTypeList { get => processTypeList; set { Set(ref processTypeList, value); } }
private string selectProcessType;
///
/// 选中工序类型
///
public string SelectProcessType
{
get => selectProcessType; set
{
Set(ref selectProcessType, value);
OnProcessTypeChanged(SelectProcessType);
}
}
private void OnProcessTypeChanged(string SelectProcessType)
{
if (SelectProcessType.IsNullOrEmpty()) return;
var processTypeData = ProcessTypeList.SingleOrDefault(p => p.ProcessTypeName == SelectProcessType);
App.Current.Dispatcher.Invoke(new Action(() =>
{
ProcessPrice = processTypeData.ProcessTypePrice;
ProcessComboList = processTypeData.ProcessComboList;
}));
if (ProcessComboList != null || ProcessComboList.Count() > 0)
{
SelectProcessComboId = ProcessComboList.FirstOrDefault().ProcessComboId;
}
}
private string selectProductResistant;
///
/// 选中易碎等级
///
public string SelectProductResistant
{
get => selectProductResistant; set
{
Set(ref selectProductResistant, value);
OnProductResistantChanged(SelectProductResistant);
}
}
private void OnProductResistantChanged(string SelectProductResistant, int isTaskCount = 0)
{
if (SelectProductResistant.IsNullOrEmpty())
{
return;
}
if (isTaskCount == 0)//获取绑定的耗材列表
{
if (ProductResistantList == null || ProductResistantList.Count <= 0 || SelectProductResistant == null) return;
var processTypeData = ProductResistantList.SingleOrDefault(p => p.ProductResistantName == SelectProductResistant);
App.Current.Dispatcher.Invoke(new Action(() =>
{
//ProcessPrice = processTypeData.ProcessTypePrice;
ProcessComboListV2 = processTypeData.ProcessComboList;
}));
if (ProcessComboListV2 != null || ProcessComboListV2.Count() > 0)
{
SelectProcessComboIdV2 = ProcessComboListV2.FirstOrDefault().ProcessComboId;
}
}
}
private string suggestPackUserName;
///
/// 打包人
///
public string SuggestPackUserName { get => suggestPackUserName; set { Set(ref suggestPackUserName, value); } }
private int? floorDragNumber;
public int? FloorDragNumber { get => floorDragNumber; set { Set(ref floorDragNumber, value); } }
private string packUserName;
///
/// 打包人
///
public string PackUserName { get => packUserName; set { Set(ref packUserName, value); } }
private int incrementPartTaskCount;
///
/// 配件任务数量
///
public int IncrementPartTaskCount { get => incrementPartTaskCount; set { Set(ref incrementPartTaskCount, value); } }
private int incrementPartCount;
///
/// 配件数量
///
public int IncrementPartCount { get => incrementPartCount; set { Set(ref incrementPartCount, value); } }
private string directionalFees;
///
/// 定向费用
///
public string DirectionalFees { get => directionalFees; set { Set(ref directionalFees, value); } }
private BitmapImage barcodeImage;
///
/// 任务Id条形码
///
public BitmapImage BarcodeImage { get => barcodeImage; set { Set(ref barcodeImage, value); } }
private BitmapImage taskImage;
///
/// 任务Id条形码
///
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 printList;
///
/// 打印机列表
///
public ObservableCollection PrintList { get => printList; set { Set(ref printList, value); } }
private ObservableCollection packTaskList;
///
/// 动态数据表
///
public ObservableCollection PackTaskList { get => packTaskList; set { Set(ref packTaskList, value); } }
private PackTaskModel packTaskModel;
public PackTaskModel PackTaskModel { get => packTaskModel; set { Set(ref packTaskModel, value); } } //
///
/// 添加打包人
///
public ICommand AddPackUserCommand { get; set; }
public ICommand AddConsumableCommand { get; set; }
public ICommand UpLoadPackCommand { get; set; }
public ICommand SetAllCountCommand { get; set; }
public ICommand PrintCommand { get; set; }
public ICommand SetCustomProcessPriceCommand { get; set; }
readonly PackTaskService packTaskService;
readonly PackDetailService packDetailService;
readonly ProcessService processService;
private ObservableCollection increateList = new ObservableCollection();
public ObservableCollection IncreateList { get => increateList; set { Set(ref increateList, value); } } //
//private ObservableCollection
// packList = new ObservableCollection();
//public ObservableCollection PackList { get => packList; set { Set(ref packList, value); } } //
private ObservableCollection
consumableServiceList = new ObservableCollection();
public ObservableCollection ConsumableServiceList { get => consumableServiceList; set { Set(ref consumableServiceList, value); } } //
private ObservableCollection basicPackProcessList = new ObservableCollection();
private ObservableCollection incrementProcessList = new ObservableCollection();
///
///增量工序
///
public ObservableCollection IncrementProcessList { get => incrementProcessList; set { Set(ref incrementProcessList, value); } } //
///
/// 基础包装工序
///
public ObservableCollection BasicPackProcessList { get => basicPackProcessList; set { Set(ref basicPackProcessList, value); } }
private string discount = "1";
///
/// 折扣
///
public string Discount { get => discount; set { Set(ref discount, value); } }
public ObservableCollection MemberList { get; set; } = new ObservableCollection();
public ObservableCollection ConsumableList { get; set; } = new ObservableCollection();
///
/// 加载原数据
///
public List LoadList = new List();
public void InitPrintList()
{
TaskImage = MyPrintHelper.GetBarcodeImage(TaskId.ToString(), 300, 60);
BarcodeImage = MyPrintHelper.GetBarcodeImage(SkuId, 300, 60);
PrintList = new ObservableCollection();
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)
{
}
}
public PackDetailViewModel(PackTaskService packTaskService, PackDetailService packDetailService, ProcessService processService)//, long taskId
{
this.processService = processService;
this.packTaskService = packTaskService;
this.packDetailService = packDetailService;
PackUserModelList = new ObservableCollection();
AddConsumableCommand = new RelayCommand(AddConsumable);
UpLoadPackCommand = new RelayCommand