using PdmSwPlugin.Common.Constants;
|
using PdmSwPlugin.PriceCheck.Model;
|
using PdmSwPlugin.PriceCheck.Param;
|
using System;
|
using System.Collections.ObjectModel;
|
using System.Linq;
|
using System.Windows.Controls;
|
|
namespace PdmSwPlugin.PriceCheck
|
{
|
/// <summary>
|
/// TaibanControl.xaml 的交互逻辑
|
/// </summary>
|
public partial class TaibanControl : UserControl, PriceCounter
|
{
|
public TaibanModel Model;
|
|
public ModelProperty ModelProperty
|
{
|
get => Model.ModelProperty;
|
set => Model.ModelProperty = value;
|
}
|
|
// 缓存服务器返回的工艺数据
|
private Technology tech { get; set; }
|
|
public TaibanControl(ModelProperty modelProperty)
|
{
|
Model = new TaibanModel(modelProperty);
|
DataContext = Model;
|
InitializeComponent();
|
}
|
|
public double GetPrice(out string message)
|
{
|
return Model.CountTotal(out message);
|
}
|
|
public double DoCount(Technology tech, out string message)
|
{
|
message = null;
|
// 傻逼WPF瞎几把触发事件,真尼玛弱智,垃圾,垃圾垃圾,傻逼
|
if (tech == null)
|
{
|
return 0;
|
}
|
this.tech = tech;
|
|
TechProp densityProp = tech.props.FirstOrDefault(e => e.name == PriceCheckName.DENSITY);
|
TechProp unitPriceProp = tech.props.FirstOrDefault(e => e.name == PriceCheckName.UNIT_PRICE);
|
TechCraft surfaceCraft = tech.surfaceProcesses.FirstOrDefault(e => e.parameter == PriceCheckName.SURFACE_UP_W);
|
TechCraft heatCraft = tech.heatProcesses.FirstOrDefault(e => e.parameter == PriceCheckName.UNIT_PRICE_CN);
|
|
ModelProperty.density = densityProp == null ? 0 : double.Parse(densityProp.value);
|
// 计算体积 立方毫米
|
ModelProperty.currentVolume = (ModelProperty.length + 10) * (ModelProperty.width + 10) * (ModelProperty.height + 5);
|
// 计算重量 g
|
ModelProperty.weight = ModelProperty.currentVolume / 1000000 * ModelProperty.density;
|
|
// 保存材料单价
|
ModelProperty.stuffUnitPrice = unitPriceProp == null ? 0 : double.Parse(unitPriceProp.value);
|
ModelProperty.stuffPrice = ModelProperty.stuffUnitPrice * ModelProperty.weight;
|
Model.stuffFee = ModelProperty.stuffPrice.ToString();
|
// 保存表处理单价
|
ModelProperty.surfaceUnitPrice = surfaceCraft == null ? 0 : double.Parse(surfaceCraft.value);
|
|
ModelProperty.surfacePrice = (ModelProperty.length + ModelProperty.height) * (ModelProperty.width + ModelProperty.height) * 2 * ModelProperty.surfaceUnitPrice / 10000;
|
//ModelProperty.surfaceUnitPrice * ModelProperty.weight;
|
Model.surfaceFee = ModelProperty.surfacePrice.ToString();
|
|
Model.ProcessGrid = new ObservableCollection<TechProcess>(tech.techProcesses);
|
if (Model.ProcessGrid.Count > 0)
|
{
|
Model.workFee = Model.ProcessGrid.Select(e => e.price).Aggregate((i, j) => i + j).ToString();
|
}
|
else
|
{
|
Model.workFee = "0";
|
}
|
|
double totalPrice = Model.CountTotal(out message);
|
if (message != null)
|
{
|
Model.price = null;
|
return 0;
|
}
|
Model.price = totalPrice.ToString();
|
return totalPrice;
|
}
|
|
private void workFeeTable_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
|
{
|
Model.workFee = Model.ProcessGrid.Select(data => data.price).Aggregate((i, j) => i + j).ToString();
|
double totalPrice = Model.CountTotal(out string message);
|
if (message != null)
|
{
|
Model.price = null;
|
}
|
else
|
{
|
Model.price = totalPrice.ToString();
|
}
|
}
|
}
|
}
|