demo20230512/Models/ExtensionMethods/ProductLCAExtension.cs

182 lines
7.7 KiB
C#
Raw Permalink Normal View History

2023-05-12 10:20:28 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Reflection;
using Resources;
namespace Weee.Models.ExtensionMethods
{
public static class ProductLCAExtension
{
public static decimal GetScopeOnePrimaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.WorkHourSheet.GetTotalKgCO2e() +
productLca.VehicleSheet.Where(x => x.Type == Vehicle.VehicleType.owned).ToList().GetTotalKgCO2e() +
productLca.GasolineEquipmentSheet.GetTotalKgCO2e() +
productLca.KitchenSheet.Where(x => x.Type == Kitchen.KitchenType.owned).ToList().GetTotalKgCO2e() +
productLca.KitchenSheet.Where(x => x.Type == Kitchen.KitchenType.other).ToList().GetTotalKgCO2e() +
productLca.RefrigerantSheet.GetTotalKgCO2e() +
productLca.FireEquipmentSheet.GetTotalKgCO2e() +
productLca.OtherCompoundSheet.GetTotalKgCO2e();
}
public static decimal GetScopeTwoPrimaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.PowerUsageSheet.GetTotalKgCO2e() + productLca.SteamUsageSheet.GetTotalKgCO2e();
}
public static decimal GetScopeThreePrimaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.WaterUsageSheet.GetTotalKgCO2e() +
productLca.VehicleSheet.Where(x => x.Type == Vehicle.VehicleType.rental).ToList().GetTotalKgCO2e() +
productLca.KitchenSheet.Where(x => x.Type == Kitchen.KitchenType.outsourcing).ToList().GetTotalKgCO2e();
}
public static decimal GetPrimaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return (productLca.WorkHourSheet.GetTotalKgCO2e() +
productLca.VehicleSheet.GetTotalKgCO2e() +
productLca.GasolineEquipmentSheet.GetTotalKgCO2e() +
productLca.KitchenSheet.GetTotalKgCO2e() +
productLca.RefrigerantSheet.GetTotalKgCO2e() +
productLca.FireEquipmentSheet.GetTotalKgCO2e() +
productLca.OtherCompoundSheet.GetTotalKgCO2e() +
productLca.PowerUsageSheet.GetTotalKgCO2e() +
productLca.SteamUsageSheet.GetTotalKgCO2e() +
productLca.WaterUsageSheet.GetTotalKgCO2e());
}
public static decimal GetLcaResultKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.Materials.GetTotalKgCO2e() +
productLca.GetPrimaryFabKgCO2e();
}
public static decimal GetSecondaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.Materials.GetTotalKgCO2e() +
productLca.GetLcaResultKgCO2e() +
productLca.TransportSheet.GetTotalKgCO2e();
}
public static decimal GetPrimaryAndSecondaryFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return (productLca.GetPrimaryFabKgCO2e() + productLca.GetSecondaryFabKgCO2e());
}
public static decimal GetTotalFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca == null) return 0;
return productLca.GetPrimaryFabKgCO2e() +
productLca.WasteSheet.GetTotalKgCO2e() +
productLca.WasteTransportSheet.GetTotalKgCO2e();
}
public static decimal GetScopeOneDistributeByWeightFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeWeight() == 0) return 0;
return productLca.GetScopeOnePrimaryFabKgCO2e() / productLca.GetDistributeWeight();
}
public static decimal GetScopeOneDistributeByAreaFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeArea() == 0) return 0;
return productLca.GetScopeOnePrimaryFabKgCO2e() / productLca.GetDistributeArea();
}
public static decimal GetScopeOneDistributeByHourFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
return productLca.GetScopeOnePrimaryFabKgCO2e() * productLca.GetDistributeHour();
}
public static decimal GetScopeTwoDistributeByWeightFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeWeight() == 0) return 0;
return productLca.GetScopeTwoPrimaryFabKgCO2e() / productLca.GetDistributeWeight();
}
public static decimal GetScopeTwoDistributeByAreaFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeArea() == 0) return 0;
return productLca.GetScopeTwoPrimaryFabKgCO2e() / productLca.GetDistributeArea();
}
public static decimal GetScopeTwoDistributeByHourFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
return productLca.GetScopeTwoPrimaryFabKgCO2e() * productLca.GetDistributeHour();
}
public static decimal GetScopeThreeDistributeByWeightFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeWeight() == 0) return 0;
return productLca.GetScopeThreePrimaryFabKgCO2e() / productLca.GetDistributeWeight();
}
public static decimal GetScopeThreeDistributeByAreaFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
if (productLca.GetDistributeArea() == 0) return 0;
return productLca.GetScopeThreePrimaryFabKgCO2e() / productLca.GetDistributeArea();
}
public static decimal GetScopeThreeDistributeByHourFabKgCO2e<T>(this T productLca) where T : ProductLCA
{
return productLca.GetScopeThreePrimaryFabKgCO2e() * productLca.GetDistributeHour();
}
public static decimal GetDistributeWeight<T>(this T productLca) where T : ProductLCA
{
decimal distributeWeight = 0;
if (productLca.TargetProduct.Weight.HasValue &&
productLca.FabProductionWeight.HasValue) {
distributeWeight = productLca.TargetProduct.Weight.Value * productLca.FabProductionWeight.Value;
}
return distributeWeight;
}
public static decimal GetDistributeArea<T>(this T productLca) where T : ProductLCA
{
decimal distributeArea = 0;
if (productLca.TargetProduct.AreaSize.HasValue &&
productLca.FabProductionArea.HasValue) {
distributeArea = productLca.TargetProduct.AreaSize.Value * productLca.FabProductionArea.Value;
}
return distributeArea;
}
public static decimal GetDistributeHour<T>(this T productLca) where T : ProductLCA
{
decimal distributeHour = 0;
if (!productLca.FabProductionHour.HasValue ||
!productLca.ProductProductionPcs.HasValue)
{
return 0;
}
if (productLca.FabProductionHour.Value != 0 &&
productLca.ProductProductionPcs.Value != 0)
{
distributeHour = (productLca.ProductProductionHour.Value / productLca.FabProductionHour.Value) * (1 / productLca.ProductProductionPcs.Value);
}
return distributeHour;
}
}
}