Пример #1
0
    public static void lstDataOutputEmission(int nIDIndicator, int OperationType, int nFacility, string sYear, ResultData resultData)
    {
        PTTGC_EPIEntities db = new PTTGC_EPIEntities();

        CReturnData result = new CReturnData();

        result.objDataEmission = new ObjData();
        result.lstAddStack     = new List <TData_Emission>();
        result.objDataEmission.lstNonCombustion           = new List <TData_Emission>();
        result.objDataEmission.lstCEM                     = new List <TData_Emission>();
        result.objDataEmission.lstAdditional              = new List <TData_Emission>();
        result.objDataEmission.lstAdditionalNonCombustion = new List <TData_Emission>();
        result.objDataEmission.lstStack                   = new List <TData_Stack>();
        result.lstAddAdditional = new List <TData_Emission>();
        result.lstOtherPrd      = new List <TM_Emission_OtherProduct>();
        result.lstVOC           = new List <TData_Emission>();
        Func <string, string> GetValueNameMasterData = (sIDMaster) =>
        {
            string sMasterName     = "";
            int    nIDMaster       = int.Parse(sIDMaster);
            var    sDataMasterType = db.TData_Type.FirstOrDefault(w => w.cActive == "Y" && w.IndicatorID == nIDIndicator && w.nID == nIDMaster);
            if (sDataMasterType != null)
            {
                sMasterName = sDataMasterType.sName;
            }
            return(sMasterName);
        };
        Func <string, string> GetValueNameUnit = (sID) =>
        {
            string sUnitName = "";
            int    nID       = int.Parse(sID);
            var    sDataUnit = db.mTUnit.FirstOrDefault(w => w.cActive == "Y" && w.UnitID == nID);
            if (sDataUnit != null)
            {
                sUnitName = sDataUnit.UnitName;
            }
            return(sUnitName);
        };

        #region mTProductIndicator
        var lstTProduct   = db.mTProductIndicator.Where(w => w.IDIndicator == nIDIndicator).ToList();
        var lstUseProduct = db.TEmissionUseProduct.Where(w => w.OperationTypeID == OperationType).Select(s => new
        {
            ProductID = s.ProductID,
            nOrder    = s.nOrder,
            cSetCode  = s.cSetCode,
        }).ToList();
        //var lstmTProductIndicator = db.mTProductIndicator.Where(w => w.IDIndicator == nIndicator && lstUseProduct.Contains(w.ProductID)).ToList();
        var lstmTProductIndicator = (from p in lstTProduct
                                     from u in lstUseProduct.Where(w => w.ProductID == p.ProductID)
                                     select new
        {
            ProductID = p.ProductID,
            ProductName = p.ProductName,
            sType = p.sType,
            sUnit = p.sUnit,
            nGroupCalc = p.nGroupCalc,
            nOption = p.nOption,
            cTotal = p.cTotal,
            nOrder = u.nOrder,
            cSetCode = u.cSetCode,
        }).ToList();
        lstmTProductIndicator.Where(w => w.sType == "SUM" || w.sType == "SUM2").ToList().ForEach(f =>
        {
            if (f.sType == "SUM" || f.sType == "SUM2")
            {
                result.objDataEmission.lstNonCombustion.Add(new TData_Emission
                {
                    ProductID   = f.ProductID,
                    ProductName = f.ProductName,
                    UnitID      = f.sType == "SUM" ? (int?)2 : null,
                    sUnit       = f.sUnit,
                    sType       = f.sType,
                    cTotal      = f.cTotal,
                    cSetCode    = f.cSetCode,
                    nGroupCalc  = f.nGroupCalc,
                    M1          = "",
                    M2          = "",
                    M3          = "",
                    M4          = "",
                    M5          = "",
                    M6          = "",
                    M7          = "",
                    M8          = "",
                    M9          = "",
                    M10         = "",
                    M11         = "",
                    M12         = "",
                    Target      = "",
                    nTotal      = "",
                });
                result.objDataEmission.lstCEM.Add(new TData_Emission
                {
                    ProductID   = f.ProductID,
                    ProductName = f.ProductName,
                    UnitID      = f.sType == "SUM" ? (int?)2 : null,
                    sUnit       = f.sUnit,
                    sType       = f.sType,
                    cTotal      = f.cTotal,
                    cSetCode    = f.cSetCode,
                    nGroupCalc  = f.nGroupCalc,
                    M1          = "",
                    M2          = "",
                    M3          = "",
                    M4          = "",
                    M5          = "",
                    M6          = "",
                    M7          = "",
                    M8          = "",
                    M9          = "",
                    M10         = "",
                    M11         = "",
                    M12         = "",
                    Target      = "",
                    nTotal      = "",
                });
            }
        });
        lstmTProductIndicator.Where(w => w.sType == "2" || w.sType == "2H").OrderBy(o => o.nOrder).ThenBy(o2 => o2.nGroupCalc).ToList().ForEach(f =>
        {
            result.lstAddStack.Add(new TData_Emission
            {
                ProductID   = f.ProductID,
                ProductName = f.ProductName,
                sUnit       = f.sUnit,
                sType       = f.sType,
                nOption     = f.nOption ?? null,
                cTotal      = f.cTotal,
                nGroupCalc  = f.nGroupCalc,
                cSetCode    = f.cSetCode,
                M1          = "",
                M2          = "",
                M3          = "",
                M4          = "",
                M5          = "",
                M6          = "",
                M7          = "",
                M8          = "",
                M9          = "",
                M10         = "",
                M11         = "",
                M12         = "",
                Target      = "",
                nTotal      = "",
            });
        });
        db.mTProductIndicator.Where(w => w.IDIndicator == nIDIndicator && w.sType == "OTH").OrderBy(o => o.nOrder).ThenBy(o2 => o2.nGroupCalc).ToList().ForEach(f =>
        {
            result.lstAddAdditional.Add(new TData_Emission
            {
                ProductID   = f.ProductID,
                ProductName = f.ProductName,
                sUnit       = f.sUnit,
                sType       = f.sType,
                nOption     = f.nOption ?? null,
                cTotal      = f.cTotal,
                nGroupCalc  = f.nGroupCalc,
                M1          = "",
                M2          = "",
                M3          = "",
                M4          = "",
                M5          = "",
                M6          = "",
                M7          = "",
                M8          = "",
                M9          = "",
                M10         = "",
                M11         = "",
                M12         = "",
                Target      = "",
                nTotal      = "",
            });
        });
        lstmTProductIndicator.Where(w => w.sType == "VOC").OrderBy(o => o.nOrder).ToList().ForEach(f =>
        {
            result.lstVOC.Add(new TData_Emission
            {
                ProductID   = f.ProductID,
                ProductName = f.ProductName,
                sUnit       = f.sUnit,
                sType       = f.sType,
                nOption     = f.nOption ?? null,
                cTotal      = f.cTotal,
                nGroupCalc  = f.nGroupCalc,
                M1          = "",
                M2          = "",
                M3          = "",
                M4          = "",
                M5          = "",
                M6          = "",
                M7          = "",
                M8          = "",
                M9          = "",
                M10         = "",
                M11         = "",
                M12         = "",
                Target      = "",
                nTotal      = "",
            });
        });

        db.TM_Emission_OtherProduct.Where(w => w.cActive == "Y" && w.cDel == "N").ToList().ForEach(f =>
        {
            result.lstOtherPrd.Add(new TM_Emission_OtherProduct
            {
                nProductID = f.nProductID,
                sName      = f.sName
            });
        });
        #endregion

        #region EPI_FORM
        var itemEPI_FORM = db.TEPI_Forms.FirstOrDefault(w => w.sYear == sYear && w.IDIndicator == nIDIndicator && w.OperationTypeID == OperationType && w.FacilityID == nFacility);
        if (itemEPI_FORM != null)
        {
            #region Non-Combustion
            var dataNonCombustion = db.TEmission_Product_ByType.Where(w => w.sType == "NCS" && w.FormID == itemEPI_FORM.FormID).ToList();
            result.objDataEmission.lstNonCombustion.ForEach(f =>
            {
                var item = dataNonCombustion.FirstOrDefault(w => w.ProductID == f.ProductID);
                if (item != null)
                {
                    f.M1     = SystemFunction.ConvertFormatDecimal4(item.M1);
                    f.M2     = SystemFunction.ConvertFormatDecimal4(item.M2);
                    f.M3     = SystemFunction.ConvertFormatDecimal4(item.M3);
                    f.M4     = SystemFunction.ConvertFormatDecimal4(item.M4);
                    f.M5     = SystemFunction.ConvertFormatDecimal4(item.M5);
                    f.M6     = SystemFunction.ConvertFormatDecimal4(item.M6);
                    f.M7     = SystemFunction.ConvertFormatDecimal4(item.M7);
                    f.M8     = SystemFunction.ConvertFormatDecimal4(item.M8);
                    f.M9     = SystemFunction.ConvertFormatDecimal4(item.M9);
                    f.M10    = SystemFunction.ConvertFormatDecimal4(item.M10);
                    f.M11    = SystemFunction.ConvertFormatDecimal4(item.M11);
                    f.M12    = SystemFunction.ConvertFormatDecimal4(item.M12);
                    f.Target = SystemFunction.ConvertFormatDecimal4(item.Target);
                    f.nTotal = SystemFunction.ConvertFormatDecimal4(item.nTotal);
                }
            });
            #endregion

            #region CEM
            var dataCEM = db.TEmission_Product_ByType.Where(w => w.sType == "CEM" && w.FormID == itemEPI_FORM.FormID).ToList();
            result.objDataEmission.lstCEM.ForEach(f =>
            {
                var item = dataCEM.FirstOrDefault(w => w.ProductID == f.ProductID);
                if (item != null)
                {
                    f.M1     = SystemFunction.ConvertFormatDecimal4(item.M1);
                    f.M2     = SystemFunction.ConvertFormatDecimal4(item.M2);
                    f.M3     = SystemFunction.ConvertFormatDecimal4(item.M3);
                    f.M4     = SystemFunction.ConvertFormatDecimal4(item.M4);
                    f.M5     = SystemFunction.ConvertFormatDecimal4(item.M5);
                    f.M6     = SystemFunction.ConvertFormatDecimal4(item.M6);
                    f.M7     = SystemFunction.ConvertFormatDecimal4(item.M7);
                    f.M8     = SystemFunction.ConvertFormatDecimal4(item.M8);
                    f.M9     = SystemFunction.ConvertFormatDecimal4(item.M9);
                    f.M10    = SystemFunction.ConvertFormatDecimal4(item.M10);
                    f.M11    = SystemFunction.ConvertFormatDecimal4(item.M11);
                    f.M12    = SystemFunction.ConvertFormatDecimal4(item.M12);
                    f.Target = SystemFunction.ConvertFormatDecimal4(item.Target);
                    f.nTotal = SystemFunction.ConvertFormatDecimal4(item.nTotal);
                }
            });
            #endregion

            #region Additional Combustion
            var dataAdddtionalCombustion = db.TEmission_Product_ByType.Where(w => w.sType == "ACS" && w.FormID == itemEPI_FORM.FormID).ToList();
            foreach (var item in dataAdddtionalCombustion)
            {
                var dataName = result.lstOtherPrd.FirstOrDefault(f => f.nProductID == item.ProductID);
                result.objDataEmission.lstAdditional.Add(new TData_Emission
                {
                    ProductID       = item.ProductID,
                    ProductName     = dataName != null ? dataName.sName : "",
                    sUnit           = GetValueNameUnit(item.UnitID + ""),
                    nOtherProductID = item.ProductID,
                    UnitID          = item.UnitID,
                    M1     = SystemFunction.ConvertFormatDecimal4(item.M1),
                    M2     = SystemFunction.ConvertFormatDecimal4(item.M2),
                    M3     = SystemFunction.ConvertFormatDecimal4(item.M3),
                    M4     = SystemFunction.ConvertFormatDecimal4(item.M4),
                    M5     = SystemFunction.ConvertFormatDecimal4(item.M5),
                    M6     = SystemFunction.ConvertFormatDecimal4(item.M6),
                    M7     = SystemFunction.ConvertFormatDecimal4(item.M7),
                    M8     = SystemFunction.ConvertFormatDecimal4(item.M8),
                    M9     = SystemFunction.ConvertFormatDecimal4(item.M9),
                    M10    = SystemFunction.ConvertFormatDecimal4(item.M10),
                    M11    = SystemFunction.ConvertFormatDecimal4(item.M11),
                    M12    = SystemFunction.ConvertFormatDecimal4(item.M12),
                    Target = SystemFunction.ConvertFormatDecimal4(item.Target),
                    nTotal = SystemFunction.ConvertFormatDecimal4(item.nTotal),
                    sType  = "OTH"
                });
            }
            #endregion

            #region Additional Non-Combustion
            var dataAdddtionalNonCombustion = db.TEmission_Product_ByType.Where(w => w.sType == "ANC" && w.FormID == itemEPI_FORM.FormID).ToList();
            foreach (var item in dataAdddtionalNonCombustion)
            {
                var dataName = result.lstOtherPrd.FirstOrDefault(f => f.nProductID == item.ProductID);
                result.objDataEmission.lstAdditionalNonCombustion.Add(new TData_Emission
                {
                    ProductID       = item.ProductID,
                    ProductName     = dataName != null ? dataName.sName : "",
                    sUnit           = GetValueNameUnit(item.UnitID + ""),
                    nOtherProductID = item.ProductID,
                    UnitID          = item.UnitID,
                    M1     = SystemFunction.ConvertFormatDecimal4(item.M1),
                    M2     = SystemFunction.ConvertFormatDecimal4(item.M2),
                    M3     = SystemFunction.ConvertFormatDecimal4(item.M3),
                    M4     = SystemFunction.ConvertFormatDecimal4(item.M4),
                    M5     = SystemFunction.ConvertFormatDecimal4(item.M5),
                    M6     = SystemFunction.ConvertFormatDecimal4(item.M6),
                    M7     = SystemFunction.ConvertFormatDecimal4(item.M7),
                    M8     = SystemFunction.ConvertFormatDecimal4(item.M8),
                    M9     = SystemFunction.ConvertFormatDecimal4(item.M9),
                    M10    = SystemFunction.ConvertFormatDecimal4(item.M10),
                    M11    = SystemFunction.ConvertFormatDecimal4(item.M11),
                    M12    = SystemFunction.ConvertFormatDecimal4(item.M12),
                    Target = SystemFunction.ConvertFormatDecimal4(item.Target),
                    nTotal = SystemFunction.ConvertFormatDecimal4(item.nTotal),
                    sType  = "OTH",
                });
            }
            result.objDataEmission.lstAdditionalNonCombustion = result.objDataEmission.lstAdditionalNonCombustion.OrderBy(o => o.ProductName).ToList();
            #endregion

            #region VOC
            var dataVoc = db.TEmission_VOC.Where(w => w.FormID == itemEPI_FORM.FormID).ToList();
            result.lstVOC.ForEach(f =>
            {
                var item = dataVoc.FirstOrDefault(w => w.ProductID == f.ProductID);
                if (item != null)
                {
                    f.M1     = SystemFunction.ConvertFormatDecimal4(item.M1);
                    f.M2     = SystemFunction.ConvertFormatDecimal4(item.M2);
                    f.M3     = SystemFunction.ConvertFormatDecimal4(item.M3);
                    f.M4     = SystemFunction.ConvertFormatDecimal4(item.M4);
                    f.M5     = SystemFunction.ConvertFormatDecimal4(item.M5);
                    f.M6     = SystemFunction.ConvertFormatDecimal4(item.M6);
                    f.M7     = SystemFunction.ConvertFormatDecimal4(item.M7);
                    f.M8     = SystemFunction.ConvertFormatDecimal4(item.M8);
                    f.M9     = SystemFunction.ConvertFormatDecimal4(item.M9);
                    f.M10    = SystemFunction.ConvertFormatDecimal4(item.M10);
                    f.M11    = SystemFunction.ConvertFormatDecimal4(item.M11);
                    f.M12    = SystemFunction.ConvertFormatDecimal4(item.M12);
                    f.Target = SystemFunction.ConvertFormatDecimal4(item.Target);
                    f.nTotal = SystemFunction.ConvertFormatDecimal4(item.nTotal);
                }
            });
            #endregion
            #endregion
        }

        resultData.lstDataNonCombustion           = result.objDataEmission.lstNonCombustion;
        resultData.lstDataCEM                     = result.objDataEmission.lstCEM;
        resultData.lstDataAdditionalCombustion    = result.objDataEmission.lstAdditional;
        resultData.lstDataAdditionalNonCombustion = result.objDataEmission.lstAdditionalNonCombustion;
        resultData.lstDataVOC                     = result.lstVOC;
    }