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.1 KiB
47 lines
2.1 KiB
|
4 years ago
|
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>
|
||
|
|
/// 统计消耗量变换器
|
||
|
|
/// 输入:原料代码、时间区间
|
||
|
|
/// 输出:消耗总量(KG)
|
||
|
|
/// </summary>
|
||
|
|
namespace Audit.ConvertMoels
|
||
|
|
{
|
||
|
|
internal class ConsumptionConvert : IValueConverter
|
||
|
|
{
|
||
|
|
private DyelotsBulkedRecipe dyelotsBulkedRecipe = new DyelotsBulkedRecipe();
|
||
|
|
// public static string Code = null;
|
||
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||
|
|
{
|
||
|
|
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(value);//传递原料代码
|
||
|
|
dyelotsBulkedRecipe.DispenseStartTime = System.Convert.ToDateTime(StatisticsView.query_start + " " + StatisticsView.date_start_time);//传递开始时间
|
||
|
|
dyelotsBulkedRecipe.DispenseEndTime = System.Convert.ToDateTime(StatisticsView.query_end + " " + StatisticsView.date_end_time);//传递结束时间
|
||
|
|
float sum_grams = (float)new DyelotsBulkedRecipeProvider().SelectCode(dyelotsBulkedRecipe).Sum(x => x.DispenseGrams);//查询并返回统计结果
|
||
|
|
if (sum_grams == 0)//统计结果为0返回空非0返回实际值
|
||
|
|
{
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
float sum = sum_grams / 1000;//计算
|
||
|
|
return sum.ToString("#0.00");//返回总消耗两位
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||
|
|
{
|
||
|
|
throw new NotImplementedException();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|