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
{
///
/// MinFeesExcelV2Control.xaml 的交互逻辑
///
public partial class MinFeesExcelV2Control : UserControl
{
public MinFeesExcelV2Control()
{
InitializeComponent();
}
public FeesItemResponse FeesItem
{
get
{
return (FeesItemResponse)GetValue(FeesItemProperty);
}
set
{
SetValue(FeesItemProperty, value);
}
}
public static readonly DependencyProperty FeesItemProperty =
DependencyProperty.Register("FeesItem", typeof(FeesItemResponse), typeof(MinFeesExcelV2Control), new PropertyMetadata(ChangedProperty));
private static void ChangedProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as MinFeesExcelV2Control;
var newValue = e.NewValue as FeesItemResponse;
control.FeesItem = newValue;
control.LoadData();
}
string xaml = @"
[:Columns:]
[:Header:]
[:ListData:]
";
string processComboStr1 = @"
";
string processComboStr = @"
";
string discountFactorStr = @"
";
string processFeesStr = @"
";
string columnStr = "";
string workProcess = "\r\n \r\n ";
string consumableService = "\r\n \r\n ";
string incrementConsumableStr = @"
";
string totalIncrementConsumableStr = @"
";
private void LoadData()
{
if (FeesItem == null || FeesItem.ProcessComboTaskCount <= 0)
{
return;
}
try
{
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Clear();
});
var consumableList = FeesItem.ConsumableList;
var processCount = 3;
var consumableCount = consumableList.Count();
columnStr = columnStr.Replace("[:Width:]", "auto");
var columnCount = consumableCount + processCount + 2;
StringBuilder columns = new StringBuilder();
for (int i = 1; i < columnCount; i++)
{
columns.AppendLine(columnStr);
}
StringBuilder serviceData = new StringBuilder();
int allCount = consumableCount + processCount;
serviceData.AppendLine(processComboStr.Replace("[:ProcessTypeName:]", $" {FeesItem.ProcessTypeName} ")
.Replace("[:ProcessComboName:]", $" {FeesItem.ProcessComboName} ")
.Replace("[:ProcessComboPrice:]", $"{FeesItem.ProcessComboPrice}*{FeesItem.ProcessComboTaskCount}")
);
serviceData.AppendLine(discountFactorStr.Replace("[:DiscountFactor:]", FeesItem.DiscountFoctor?.ToString()));
//serviceData.AppendLine(processFeesStr.Replace("[:PackFees:]", FeesItem.PackFees.ToString("0.00")));
int rowIndex = 3;
if (consumableList.Count > 0)
{
foreach (var item in consumableList)
{
rowIndex++;
serviceData.AppendLine(incrementConsumableStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:ServiceName:]", $"{item.ItemName}")
).Replace("[:ServiceCount:]", $"");//
}
rowIndex++;
//serviceData.AppendLine(totalIncrementConsumableStr.Replace("[:index:]", $"{rowIndex}")
// .Replace("[:Price:]", $"{FeesItem.ConsumableFees}")
// );
}
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 - 2}")
.Replace("[:1+ProcessCount:]", $"{1 + processCount}")
.Replace("[:1+ProcessCount:+ConsumableCount]", $"{1 + processCount + consumableCount}")
.Replace("[:2+ProcessCount:+ConsumableCount]", $"{2 + processCount + consumableCount}")
.Replace("[:3+ProcessCount:+ConsumableCount]", $"{3 + processCount + consumableCount}")
.Replace("[:ProcessCount:]", $"{processCount}")
.Replace("[:ConsumableCount:]", $"{consumableCount}")
.Replace("[:TaskId:]", $"")
.Replace("[:ListData:]", serviceData.ToString())
.Replace("[:AllFees:]", $"{FeesItem.PackFees.ToString("0.00")}");//打包费用
newGrid = newGrid.Replace(@"[:Visity:]", "");
var grid = XamlReader.Parse(newGrid) as Grid;
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Add(grid);
});
}
catch
{
}
}
}
}