using BBWY.Client.Models.APIModel.Response.PackTask;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace BBWY.Client.Views.PackTask
{
///
/// MinFeesExcelControl.xaml 的交互逻辑
///
public partial class MinFeesExcelControl : UserControl
{
public MinFeesExcelControl()
{
InitializeComponent();
}
///
/// 是否仓库端
///
public bool IsWareHouse
{
get { return (bool)GetValue(IsWareHouseProperty); }
set
{
SetValue(IsWareHouseProperty, value);
}
}
public static readonly DependencyProperty IsWareHouseProperty =
DependencyProperty.Register("IsWareHouse", typeof(bool), typeof(MinFeesExcelControl), new PropertyMetadata(true, ChangedProperty1));
///
/// 价格
///
//public decimal FeesPrice
//{
// get { return (decimal)GetValue(FeesPriceProperty); }
// set
// {
// SetValue(FeesPriceProperty, value);
// }
//}
//public static readonly DependencyProperty FeesPriceProperty =
// DependencyProperty.Register("FeesPrice", typeof(decimal), typeof(FeesExcelControl), new PropertyMetadata(ChangedProperty2));
public bool IsMin
{
get
{
return (bool)GetValue(IsMinProperty);
}
set
{
SetValue(IsMinProperty, value);
}
}
public static readonly DependencyProperty IsMinProperty =
DependencyProperty.Register("IsMin", typeof(bool), typeof(MinFeesExcelControl));
public FeesItemResponse FeesItem
{
get
{
return (FeesItemResponse)GetValue(FeesItemProperty);
}
set
{
SetValue(FeesItemProperty, value);
}
}
public static readonly DependencyProperty FeesItemProperty =
DependencyProperty.Register("FeesItem", typeof(FeesItemResponse), typeof(MinFeesExcelControl), new PropertyMetadata(ChangedProperty));
private static void ChangedProperty1(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as FeesExcelControl;
var newValue = e.NewValue as FeesItemResponse;
}
private static void ChangedProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as MinFeesExcelControl;
// control.Str
var newValue = e.NewValue as FeesItemResponse;
control.FeesItem = newValue;
if (control.IsWareHouse)
{
control.LoadData(false);
}
else
{
control.LoadData(true);
}
}
string xaml = @"
[:Columns:]
[:Header:]
[:ListData:]
";
///
/// index 从1开始 0+1 增值服务 和打包耗材
///
string columnData = @"
";
string incrementConsumableStr = @"
";
//string totalIncrementConsumableStr = @"
//
//
//
//
//
//
//
//";
string basicPackStr = @"
[:Columns:]
[:BasicProcessData:]
";
string basicProcessdata = @"
";
string increateProcessStr = @"
[:Columns:]
[:IncreateProcessDatas:]
";
string increateProcessData = @"
";
string increatePartData = @"
";
string FeesModeStr = @"
";
string discountFactorStr = @"
";
//string processFeesStr = @"
//
//
//
//
//
//
//
//
//";
string columnStr = "";
//string increateService = @"
// ";
string workProcess = "\r\n \r\n ";
string consumableService = "\r\n \r\n ";
private void LoadData(bool isPrice)
{
isPrice = false;
if (FeesItem == null || FeesItem.ServiceList.Count <= 0)
{
return;
}
try
{
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Clear();
});
int packserviceCount = 0;
bool isExitIncrementPart = false;
if (FeesItem.IncrementPartTaskCount != null && FeesItem.IncrementPartTaskCount > 0 && FeesItem.IncrementPartCount > 1)
{
isExitIncrementPart = true;
packserviceCount++;
}
var basicProcessList = FeesItem.PackItemList.Where(f => f.ProcessType == Models.ProcessType.基础包装工序).ToList();
if (basicProcessList.Count > 0) packserviceCount++;
var increateProcessList = FeesItem.PackItemList.Where(f => f.ProcessType == Models.ProcessType.增值服务工序).ToList();
if (increateProcessList.Count > 0) packserviceCount++;
var processList = FeesItem.PackItemList;
var consumableList = FeesItem.ConsumableList;
if (packserviceCount > 0) packserviceCount += 2;
var processCount = packserviceCount;
var consumableCount = consumableList.Count();
var columnCount = consumableCount + processCount + 1;
StringBuilder columns = new StringBuilder();
for (int i = 0; i < columnCount; i++)
{
columns.AppendLine(columnStr);
}
StringBuilder serviceData = new StringBuilder();
int allCount = consumableCount + processCount ;
int rowIndex = 0;
if (basicProcessList.Count > 0)//打包服务
{
StringBuilder basicSB = new StringBuilder();
StringBuilder basiccolumns = new StringBuilder();
for (int i = 0; i < basicProcessList.Count; i++)
{
basicSB.AppendLine(basicProcessdata.Replace("[:index:]", $"{i}")
.Replace("[:ServiceName:]", $" {basicProcessList[i].ItemName} ")
.Replace("[:ServiceCount:]", $"{basicProcessList[i].ItemPrice}*{basicProcessList[i].ItemCount}"));
basiccolumns.AppendLine(columnStr);
}
serviceData.AppendLine(basicPackStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:Columns:]", $"{basiccolumns}")
.Replace("[:ServiceCount:]", $"{FeesItem.BasicProcessPrice}*{FeesItem.BasicProcessCount}")
.Replace("[:BasicProcessData:]", basicSB.ToString()));
}
if (increateProcessList.Count > 0)
{
rowIndex++;
StringBuilder increateProcessSB = new StringBuilder();
StringBuilder increateProcesscolumns = new StringBuilder();
for (int i = 0; i < increateProcessList.Count(); i++)
{
increateProcessSB.AppendLine(increateProcessData.Replace("[:index:]", $"{i}")
.Replace("[:ServiceName:]", $" {increateProcessList[i].ItemName} ")
.Replace("[:ServiceCount:]", $"{increateProcessList[i].ItemPrice}*{increateProcessList[i].ItemCount}"));
increateProcesscolumns.AppendLine(columnStr);
}
//[:IncreateProcessCount:]
serviceData.AppendLine(increateProcessStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:IncreateProcessCount:]", $"{increateProcessList.Count()}")
.Replace("[:Columns:]", $"{increateProcesscolumns}")
.Replace("[:IncreateProcessDatas:]", $"{increateProcessSB.ToString()}")
.Replace("[:ServiceCount:]", $"{FeesItem.BasicProcessPrice}*{FeesItem.BasicProcessCount}"));
}
if (isExitIncrementPart)
{
rowIndex++;
serviceData.AppendLine(increatePartData.Replace("[:index:]", $"{rowIndex}")
.Replace("[:PartCount:]", $"{FeesItem.IncrementPartCount}")
.Replace("[:ServiceCount:]", $"{FeesItem.IncrementPartPrice}*{FeesItem.IncrementPartTaskCount}"));
}
if (processCount > 0)
{
rowIndex++;
serviceData.AppendLine(FeesModeStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:FeesMode:]", $"{FeesItem.FeesMode}"));
rowIndex++;
serviceData.AppendLine(discountFactorStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:DiscountFactor:]", $"{FeesItem.DiscountFoctor}")
);
}
if (consumableList.Count > 0)
{
foreach (var item in consumableList)
{
rowIndex++;
serviceData.AppendLine(incrementConsumableStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:ServiceName:]", $" {item.ItemName} ")
.Replace("[:ServiceCount:]", $""));
}
}
StringBuilder header = new StringBuilder();
if (processCount > 0)
{
header.AppendLine(workProcess);
}
if (consumableCount > 0)
{
header.AppendLine(consumableService);
}
decimal allFees = 0;
decimal discount = 0;
decimal discountFees = 0;
discount = FeesItem.disCount;
allFees = FeesItem.AllFees;
discountFees = allFees * discount;
string discountStr = "原价";
if (discount > 1)
discountStr = $"{discount.ToString("0.0")}倍";
if (discount < 1)
discountStr = $"{(discount * 10).ToString("0.0")}折";
var newGrid = xaml.Replace("[:Header:]", header.ToString())
.Replace("[:Columns:]", columns.ToString())
.Replace("[:ColumnCount:]", $"{columnCount}")
.Replace("[:ColumnCount-2:]", $"{columnCount - 1}")
.Replace("[:1+IncreateCount:]", $"{0}")
.Replace("[:1+IncreateCount+ProcessCount:]", $"{ processCount}")
.Replace("[:1+IncreateCount+ProcessCount:+ConsumableCount]", $"{ processCount + consumableCount}")
.Replace("[:2+IncreateCount+ProcessCount:+ConsumableCount]", $"{1 + processCount + consumableCount}")
.Replace("[:3+IncreateCount+ProcessCount:+ConsumableCount]", $"{2 + processCount + consumableCount}")
.Replace("[:IncreateCount:]", $"{0}")
.Replace("[:ProcessCount:]", $"{processCount}")
.Replace("[:ConsumableCount:]", $"{consumableCount}")
.Replace("[:TaskId:]", $"{FeesItem.TaskId}")
.Replace("[:ListData:]", serviceData.ToString())
.Replace("[:AllFees:]", $"{FeesItem.PackFees}");
if (IsMin)
{
newGrid = newGrid.Replace(@"MinWidth=""84""", "").Replace(@"[:Visity:]", "Width=\"0\"");
}
else
{
//
newGrid = newGrid.Replace(@"[:Visity:]", "");
}
var grid = XamlReader.Parse(newGrid) as Grid;
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Add(grid);
});
}
catch
{
}
}
}
}