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
{
///
/// FeesExcelV2Control.xaml 的交互逻辑
///
public partial class FeesExcelV2Control : UserControl
{
public FeesExcelV2Control()
{
InitializeComponent();
}
public bool IsShopTotal
{
get
{
return (bool)GetValue(IsShopTotalProperty);
}
set
{
SetValue(IsShopTotalProperty, value);
}
}
public static readonly DependencyProperty IsShopTotalProperty =
DependencyProperty.Register("IsShopTotal", typeof(bool), typeof(FeesExcelV2Control),new PropertyMetadata(false));
//["IsShopTotal"]
public FeesItemResponse FeesItem
{
get
{
return (FeesItemResponse)GetValue(FeesItemProperty);
}
set
{
SetValue(FeesItemProperty, value);
}
}
public static readonly DependencyProperty FeesItemProperty =
DependencyProperty.Register("FeesItem", typeof(FeesItemResponse), typeof(FeesExcelV2Control), new PropertyMetadata(ChangedProperty));
private static void ChangedProperty(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var control = d as FeesExcelV2Control;
var newValue = e.NewValue as FeesItemResponse;
control.FeesItem = newValue;
control.LoadData();
}
string xaml = @"
[:Columns:]
[:Header:]
[:ListData:]
";
string processComboStr = @"
";
string discountFactorStr = @"
";
string processFeesStr = @"
";
//赔付金额
string compensationFeesStr = @"
";
//实际收益
string actualIncomeStr = @"
";
string columnStr = "";
string workProcess = "\r\n \r\n ";
string consumableService = "\r\n \r\n ";
string incrementConsumableStr = @"
";
string totalIncrementConsumableStr = @"
";
private void LoadData()
{
if (FeesItem == null )
{
return;
}
try
{
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Clear();
});
var consumableList = FeesItem.ConsumableList;
var processCount = 6;
var consumableCount = consumableList.Count();
if (consumableCount > 0)
{
consumableCount++;
}
columnStr = columnStr.Replace("[:Width:]", "*");
var columnCount = consumableCount + 2;
StringBuilder columns = new StringBuilder();
for (int i = 1; i < columnCount; i++)
{
columns.AppendLine(columnStr);
}
columnCount += processCount;
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")));
//赔付金额
serviceData.AppendLine(compensationFeesStr.Replace("[:CompensationFees:]", FeesItem.CompensateFees?.ToString("0.00")));
//实际收益
serviceData.AppendLine(actualIncomeStr.Replace("[:ActualIncome:]", FeesItem.ActualPackFees?.ToString("0.00")));
int rowIndex = 6;
if (consumableList.Count > 0)
{
foreach (var item in consumableList)
{
rowIndex++;
serviceData.AppendLine(incrementConsumableStr.Replace("[:index:]", $"{rowIndex}")
.Replace("[:ServiceName:]", $"{item.ItemName}")
.Replace("[:ServiceCount:]", $"{item.ItemPrice}*{item.ItemCount}"));
}
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:]", $"{FeesItem.TaskId}")
.Replace("[:ListData:]", serviceData.ToString())
.Replace("[:AllFees:]", $"{FeesItem.AllFees.ToString("0.00")}");
//.Replace("[:Discount:]", $"{FeesItem.DiscountFoctor}")
//.Replace("[:DiscountFees:]", $"{discountFees.ToString(" 0.00")}");
newGrid = newGrid.Replace(@"[:Visity:]", "");
if (IsShopTotal)//[:IsShopTotal:]
{
newGrid = newGrid.Replace(@"[:IsShopTotal:]", @"Width=""0""");
}
else
{
newGrid = newGrid.Replace(@"[:IsShopTotal:]", "");
}
var grid = XamlReader.Parse(newGrid) as Grid;
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Add(grid);
});
}
catch
{
}
}
}
}