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.
47 lines
2.2 KiB
47 lines
2.2 KiB
using Audit.View;
|
|
using Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
|
|
/// <summary>
|
|
/// 统计成本变换器
|
|
/// 输入:原料代码、原料价格、时间区间
|
|
/// 输出:总成本
|
|
/// </summary>
|
|
namespace Audit.ConvertMoels
|
|
{
|
|
internal class GramsSumConvert : IMultiValueConverter
|
|
{
|
|
private DyelotsBulkedRecipe dyelotsBulkedRecipe = new DyelotsBulkedRecipe();
|
|
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
string productcode = System.Convert.ToString(values[0]);//转换数组1的信息原料代码
|
|
float price = System.Convert.ToSingle(values[1]);//转换数组2的信息单价
|
|
if (string.IsNullOrWhiteSpace(StatisticsView.query_start)) StatisticsView.query_start = DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd");//默认开始时间当前日期前30天
|
|
if (string.IsNullOrWhiteSpace(StatisticsView.query_end)) StatisticsView.query_end = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd");//默认结束时间当前日期后一天
|
|
dyelotsBulkedRecipe.ProductCode = System.Convert.ToString(productcode);//传递原料代码
|
|
dyelotsBulkedRecipe.DispenseStartTime = System.Convert.ToDateTime(StatisticsView.query_start);//传递开始时间
|
|
dyelotsBulkedRecipe.DispenseEndTime = System.Convert.ToDateTime(StatisticsView.query_end);//传递结束时间
|
|
float sum_grams = (float)new DyelotsBulkedRecipeProvider().SelectCode(dyelotsBulkedRecipe).Sum(x => x.DispenseGrams);//查询并返回统计结果
|
|
if (sum_grams > 0 && price > 0)
|
|
{
|
|
float sum = (sum_grams * price) / 1000;//计算
|
|
return sum.ToString("#0.00");//返回总成本两位小数(元)
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public object[] ConvertBack(object value, Type[] targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|
|
|