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

308 lines
14 KiB

2 years ago
using BBWY.Client.APIServices;
using BBWY.Client.Models.APIModel.Response.PackTask;
using NPOI.POIFS.Crypt.Dsig;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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
{
/// <summary>
/// FeesExcelControl.xaml 的交互逻辑
/// </summary>
public partial class FeesExcelControl : UserControl
{
/// <summary>
/// 是否仓库端
/// </summary>
public bool IsWareHouse
{
get { return (bool)GetValue(IsWareHouseProperty); }
set
{
SetValue(IsWareHouseProperty, value);
}
}
public static readonly DependencyProperty IsWareHouseProperty =
DependencyProperty.Register("IsWareHouse", typeof(bool), typeof(FeesExcelControl), new PropertyMetadata(true, ChangedProperty1));
/// <summary>
/// 价格
/// </summary>
//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 FeesItemResponse FeesItem
{
get
{
return (FeesItemResponse)GetValue(FeesItemProperty);
}
set
{
SetValue(FeesItemProperty, value);
}
}
public static readonly DependencyProperty FeesItemProperty =
DependencyProperty.Register("FeesItem", typeof(FeesItemResponse), typeof(FeesExcelControl), 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 FeesExcelControl;
// control.Str
var newValue = e.NewValue as FeesItemResponse;
control.FeesItem = newValue;
if (control.IsWareHouse)
{
control.LoadData(false);
}
else
{
control.LoadData(true);
}
}
string xaml = @" <Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<Grid.ColumnDefinitions >
[:Columns:]
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=""30"" />
<RowDefinition Height=""30"" />
<RowDefinition Height=""30"" />
</Grid.RowDefinitions>
<Border Background=""#F2F2F2"" Grid.RowSpan=""2"" Grid.ColumnSpan=""[:ColumnCount:]""/>
<Border Width=""1"" HorizontalAlignment=""Left"" BorderBrush=""#D7D7D7"" Grid.Column=""0"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""1,0,0,0""/>
<Border Width=""1"" HorizontalAlignment=""Left"" BorderBrush=""#D7D7D7"" Grid.Column=""1"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""1,0,0,0""/>
<Border Width=""1"" HorizontalAlignment=""Right"" BorderBrush=""#D7D7D7"" Grid.Column=""[:1+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""0,0,1,0""/>
2 years ago
<Border Width=""1"" HorizontalAlignment=""Right"" BorderBrush=""#D7D7D7"" Grid.Column=""[:2+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""0,0,1,0""/>
<Border Width=""1"" HorizontalAlignment=""Right"" BorderBrush=""#D7D7D7"" Grid.Column=""[:3+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""0,0,1,0""/>
2 years ago
2 years ago
<Border Height=""1"" VerticalAlignment=""Top"" BorderBrush=""#D7D7D7"" Grid.Column=""0"" Grid.Row=""0"" Grid.ColumnSpan=""[:ColumnCount:]"" BorderThickness=""0,1,0,0""/>
2 years ago
<Border Height=""1"" VerticalAlignment=""Top"" BorderBrush=""#D7D7D7"" Grid.Column=""1"" Grid.Row=""1"" Grid.ColumnSpan=""[:ColumnCount-2:]"" BorderThickness=""0,1,0,0""/>
<Border Height=""1"" VerticalAlignment=""Bottom"" BorderBrush=""#D7D7D7"" Grid.Column=""0"" Grid.Row=""1"" Grid.ColumnSpan=""[:ColumnCount:]"" BorderThickness=""0,1,0,0""/>
<Border Height=""1"" VerticalAlignment=""Bottom"" BorderBrush=""#D7D7D7"" Grid.Column=""0"" Grid.Row=""2"" Grid.ColumnSpan=""[:ColumnCount:]"" BorderThickness=""0,1,0,0""/>
<TextBlock MinWidth=""84"" Text=""ID"" TextAlignment=""Center"" Grid.Column=""0"" Grid.RowSpan=""2"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
[:Header:]
2 years ago
<TextBlock MinWidth=""101"" TextAlignment=""Center"" Text="""" Grid.Column=""[:1+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.RowSpan=""2"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<TextBlock MinWidth=""101"" TextAlignment=""Center"" Text="""" Grid.Column=""[:2+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.RowSpan=""2"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<TextBlock MinWidth=""101"" TextAlignment=""Center"" Text="""" Grid.Column=""[:3+IncreateCount+ProcessCount:+ConsumableCount]"" Grid.RowSpan=""2"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
2 years ago
<TextBlock Text=""[:TaskId:]"" Grid.Row=""2"" Grid.Column=""0"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<TextBlock Text=""[:AllFees:]"" Grid.Row=""2"" Grid.Column=""[:1+IncreateCount+ProcessCount:+ConsumableCount]"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
2 years ago
<TextBlock Text=""[:Discount:]"" Grid.Row=""2"" Grid.Column=""[:2+IncreateCount+ProcessCount:+ConsumableCount]"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<TextBlock Text=""[:DiscountFees:]"" Grid.Row=""2"" Grid.Column=""[:3+IncreateCount+ProcessCount:+ConsumableCount]"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
2 years ago
[:ListData:]
</Grid>";
/// <summary>
/// index 从1开始 0+1
/// </summary>
string columnData = @"
<Grid Grid.Column=""[:index:]"" MinWidth=""84"" Grid.Row=""1"" Grid.RowSpan=""2"" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Width=""1"" HorizontalAlignment=""Left"" BorderBrush=""#D7D7D7"" Grid.RowSpan=""2"" BorderThickness=""0,0,1,0""/>
<TextBlock Text=""[:ServiceName:]"" Grid.Row=""0"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<TextBlock Text=""[:ServiceCount:]"" Grid.Row=""1"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
</Grid>";
string columnStr = "<ColumnDefinition />";
string increateService = @"<TextBlock Text=""增值服务"" Grid.Column=""1"" Grid.ColumnSpan=""[:IncreateCount:]"" VerticalAlignment=""Center"" HorizontalAlignment=""Center""/>
<Border Width=""1"" HorizontalAlignment=""Left"" BorderBrush=""#D7D7D7"" Grid.Column=""[:1+IncreateCount:]"" Grid.Row=""0"" Grid.RowSpan=""3"" BorderThickness=""1,0,0,0""/>";
string workProcess = "<TextBlock Text=\"打包服务\" Grid.Column=\"[:1+IncreateCount:]\" Grid.ColumnSpan=\"[:ProcessCount:]\" VerticalAlignment=\"Center\" HorizontalAlignment=\"Center\"/>\r\n <Border Width=\"1\" HorizontalAlignment=\"Left\" BorderBrush=\"#D7D7D7\" Grid.Column=\"[:1+IncreateCount+ProcessCount:]\" Grid.Row=\"0\" Grid.RowSpan=\"3\" BorderThickness=\"1,0,0,0\"/>\r\n ";
string consumableService = "<TextBlock Text=\"打包耗材\" Grid.Column=\"[:1+IncreateCount+ProcessCount:]\" Grid.ColumnSpan=\"[:ConsumableCount:]\" VerticalAlignment=\"Center\" HorizontalAlignment=\"Center\"/>\r\n <Border Width=\"1\" HorizontalAlignment=\"Left\" BorderBrush=\"#D7D7D7\" Grid.Column=\"[:1+IncreateCount+ProcessCount:+ConsumableCount]\" Grid.Row=\"0\" Grid.RowSpan=\"3\" BorderThickness=\"1,0,0,0\"/>\r\n ";
public FeesExcelControl()
{
InitializeComponent();
}
private void LoadData(bool isPrice)
{
2 years ago
isPrice = false;
2 years ago
if (FeesItem == null || FeesItem.ServiceList.Count <= 0)
{
return;
}
try
{
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Clear();
});
var increateList = FeesItem.ServiceList.Where(s => s.ServiceType == ServiceType.).ToList();
var processList = FeesItem.ServiceList.Where(s => s.ServiceType == ServiceType.).ToList();
var consumableList = FeesItem.ServiceList.Where(s => s.ServiceType == ServiceType.).ToList();
var increateCount = increateList.Count();
var processCount = processList.Count();
var consumableCount = consumableList.Count();
List<ServiceItemResponse> all = new List<ServiceItemResponse>();
all.AddRange(increateList);
all.AddRange(processList);
all.AddRange(consumableList);
2 years ago
var columnCount = 2 + all.Count + 2;
2 years ago
StringBuilder columns = new StringBuilder();
for (int i = 0; i < columnCount; i++)
{
columns.AppendLine(columnStr);
}
StringBuilder serviceData = new StringBuilder();
if (isPrice)
{
for (int i = 0; i < all.Count; i++)
{
serviceData.AppendLine(columnData.Replace("[:index:]", $"{i + 1}")
.Replace("[:ServiceName:]", $"{all[i].ItemName}")
.Replace("[:ServiceCount:]", $"{all[i].ItemPrice}"));
}
}
else
{
for (int i = 0; i < all.Count; i++)
{
serviceData.AppendLine(columnData.Replace("[:index:]", $"{i + 1}")
.Replace("[:ServiceName:]", $"{all[i].ItemName}")
.Replace("[:ServiceCount:]", $"{all[i].ItemPrice}*{all[i].ItemCount}"));
2 years ago
}
}
StringBuilder header = new StringBuilder();
if (increateCount > 0)
{
header.AppendLine(increateService);
}
if (processCount > 0)
{
header.AppendLine(workProcess);
}
if (consumableCount > 0)
{
header.AppendLine(consumableService);
}
2 years ago
decimal allFees = 0;
decimal discount = 0;
decimal discountFees = 0;
discount = FeesItem.disCount;
if (isPrice)
{
allFees = FeesItem.SingleFees;
}
else
{
allFees = FeesItem.AllFees;
}
discountFees = allFees * discount;
string discountStr = "原价";
2 years ago
2 years ago
if (discount > 1)
discountStr = $"{discount.ToString("0.0")}倍";
if (discount < 1)
discountStr = $"{(discount * 10).ToString("0.0")}折";
2 years ago
var newGrid = xaml.Replace("[:Header:]", header.ToString())
.Replace("[:Columns:]", columns.ToString())
.Replace("[:ColumnCount:]", $"{columnCount}")
2 years ago
.Replace("[:ColumnCount-2:]", $"{columnCount - 4}")
2 years ago
.Replace("[:1+IncreateCount:]", $"{increateCount + 1}")
.Replace("[:1+IncreateCount+ProcessCount:]", $"{1 + increateCount + processCount}")
.Replace("[:1+IncreateCount+ProcessCount:+ConsumableCount]", $"{1 + increateCount + processCount + consumableCount}")
2 years ago
.Replace("[:2+IncreateCount+ProcessCount:+ConsumableCount]", $"{2 + increateCount + processCount + consumableCount}")
.Replace("[:3+IncreateCount+ProcessCount:+ConsumableCount]", $"{3 + increateCount + processCount + consumableCount}")
2 years ago
.Replace("[:IncreateCount:]", $"{increateCount}")
.Replace("[:ProcessCount:]", $"{processCount}")
.Replace("[:ConsumableCount:]", $"{consumableCount}")
.Replace("[:TaskId:]", $"{FeesItem.TaskId}")
.Replace("[:ListData:]", serviceData.ToString())
2 years ago
.Replace("[:AllFees:]", $"{allFees}")
.Replace("[:Discount:]", discountStr)
.Replace("[:DiscountFees:]", $"{discountFees.ToString(" 0.00")}");
2 years ago
var grid = XamlReader.Parse(newGrid) as Grid;
App.Current.Dispatcher.Invoke(() =>
{
gd.Children.Add(grid);
});
}
catch
{
}
}
}
}