using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using RNGClassLibrary;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;

namespace RNGWcfService1.ContextClass
{
    public class FuranceLogSheetDbContext : DbContext
    {
        public FuranceLogSheetDbContext() : base()
        {
            Database.SetInitializer<FuranceLogSheetDbContext>(null);
            base.Database.Connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["RNGConnectionStrings"].ConnectionString;
        }

        public System.Data.Entity.DbSet<FuranceLogSheet> User { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<FuranceLogSheet>().MapToStoredProcedures();
        }

        public void GetErrorDescription(int ErrorNo, ref string ErrorDesc)
        {
            var pErrCodeParam = new SqlParameter("pErrorNo", ErrorNo);

            var pErrDescParam = new SqlParameter("pErrorDesc", System.Data.SqlDbType.VarChar, 200);
            pErrDescParam.Direction = System.Data.ParameterDirection.Output;
            pErrDescParam.Value = "";

            this.Database.ExecuteSqlCommand("spErrors_GetErrorDesc @pErrorNo, @pErrorDesc out", pErrCodeParam, pErrDescParam);

            ErrorDesc = Convert.ToString(pErrDescParam.Value);
        }

        public virtual int FuranceLogSheet_AddNew(string UnitName, DateTime Date, string DayShiftOperator, string Shift, string StartMeterReading, string StopMeterReading, string TotalUnits, string TotalMelting, string UnitPerKg, string IsActive, string UserID, string FinalYear, string Status,
            ref int FuranceId, string NetProduction, string FloorMetal, string Rejection, string Riserweight, string SlagWeight, List<FuranceLogSheetIRN1> ListSalesFuranceLogSheetIRN1, List<FuranceLogSheetIRN2> ListSalesFuranceLogSheetIRN2, List<IRN2> ListIRN2, int ShiftMasterid,decimal BunchWeight, ref string errorDesc)
        {
            errorDesc = "";

            var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
            ReturnValueParam.Direction = System.Data.ParameterDirection.Output;

            var paramUnitName = new SqlParameter("pUnitName", UnitName);
            var paramDate = new SqlParameter("pDate", Date);
            var paramDayShiftOperator = new SqlParameter("pDayShiftOperator", DayShiftOperator);
            var paramShift = new SqlParameter("pShift", Shift);
            var paramStartMeterReading = new SqlParameter("pStartMeterReading", StartMeterReading);
            var paramStopMeterReading = new SqlParameter("pStopMeterReading", StopMeterReading);
            var paramTotalUnits = new SqlParameter("pTotalUnits", TotalUnits);
            var paramTotalMelting = new SqlParameter("pTotalMelting", TotalMelting);
            var paramUnitPerKg = new SqlParameter("pUnitPerKg", UnitPerKg);
            var paramIsActive = new SqlParameter("pIsActive", IsActive);
            var paramUserID = new SqlParameter("pUserID", UserID);
            var paramFinalYear = new SqlParameter("pFinalYear", FinalYear);
            var paramStatus = new SqlParameter("pStatus", Status);
            var paramFuranceId = new SqlParameter("pFuranceId", System.Data.SqlDbType.Int);
            paramFuranceId.Direction = System.Data.ParameterDirection.Output;
            var paramNetProduction = new SqlParameter("pNetProduction", NetProduction);
            var paramFloorMetal1 = new SqlParameter("pFloorMetal", FloorMetal);
            var paramRejection = new SqlParameter("pRejection", Rejection);
            var paramRiserweight = new SqlParameter("pRiserweight", Riserweight);
            var paramSlagWeight = new SqlParameter("pSlagWeight", SlagWeight);
            var paramShiftMasterid = new SqlParameter("pShiftMasterid", ShiftMasterid);
            var paramsBunchWeight = new SqlParameter("pBunchWeight", BunchWeight);

            var dbContext = this.Database;

            using (var dbContextTransaction = dbContext.BeginTransaction())
            {
                int errorNo = 0;

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheet_AddNew @pUnitName, @pDate, @pDayShiftOperator,@pShift,@pStartMeterReading,@pStopMeterReading,@pTotalUnits, @pTotalMelting,@pUnitPerKg,@pIsActive,@pUserID,@pFinalYear,@pStatus,@pFuranceId OUT,@pNetProduction,@pFloorMetal,@pRejection,@pRiserweight,@pSlagWeight,@pShiftMasterid,@pBunchWeight",
                                                ReturnValueParam, paramUnitName, paramDate, paramDayShiftOperator, paramShift, paramStartMeterReading, paramStopMeterReading, paramTotalUnits, paramTotalMelting, paramUnitPerKg, paramIsActive, paramUserID, paramFinalYear, paramStatus, paramFuranceId, paramNetProduction, paramFloorMetal1, paramRejection, paramRiserweight, paramSlagWeight, paramShiftMasterid, paramsBunchWeight);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);

                    if (errorNo >= 0) //**** Success
                    {


                        FuranceId = Convert.ToInt32(paramFuranceId.Value);
                        if (FuranceId > 0 && ListSalesFuranceLogSheetIRN1 != null)
                        {
                            if (ListSalesFuranceLogSheetIRN1.Count > 0)
                            {
                                foreach (FuranceLogSheetIRN1 objProd in ListSalesFuranceLogSheetIRN1)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCuNo = new SqlParameter("pCuNo", objProd.CuNo);
                                    var paramMetalGrade = new SqlParameter("pMetalGrade", objProd.MetalGrade);
                                    var paramLiningHtNo = new SqlParameter("pLiningHtNo", objProd.LiningHtNo);
                                    var paramStartNo = new SqlParameter("pStartNo", objProd.StartNo);
                                    var paramStopTime = new SqlParameter("pStopTime", objProd.StopTime);
                                    var paramVoltageInPanel = new SqlParameter("pVoltageInPanel", objProd.VoltageInPanel);
                                    var paramKWInPanel = new SqlParameter("pKWInPanel", objProd.KWInPanel);
                                    var paramCE = new SqlParameter("pCE", objProd.CE);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);
                                    var paramSilicon = new SqlParameter("pSilicon", objProd.Silicon);
                                    var paramAddedSilicon = new SqlParameter("pAddedSilicon", objProd.AddedSilicon);
                                    var paramPouredBoxNo = new SqlParameter("pPouredBoxNo", objProd.PouredBoxNo);
                                    var paramDrgNo = new SqlParameter("pDrgNo", objProd.DrgNo);
                                    var paramTappingTemp = new SqlParameter("pTappingTemp", objProd.TappingTemp);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);

                                    var paramstartdate = new SqlParameter("pstartdate", objProd.startdate);
                                    var paramenddate = new SqlParameter("penddate", objProd.enddate);
                                    var paramtotaltime = new SqlParameter("ptotaltime", objProd.totaltime);
                                    var paramtotalminit = new SqlParameter("ptotalminit", objProd.totalminit);

                                    var paramAddedCarbon = new SqlParameter("pAddedCarbon", objProd.AddedCarbon);
                                    var paramAddedFerroSilicon = new SqlParameter("pAddedFerroSilicon", objProd.AddedFerroSilicon);
                                    var paramBunchWeight = new SqlParameter("pBunchWeight", objProd.BunchWeight);
                                    var paramAddedCrcScrap = new SqlParameter("pAddedCrcScrap", objProd.AddedCrcScrap);



                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheetIRN1_AddNew @pFuranceId,@pHeatNo,@pCuNo, @pMetalGrade,@pLiningHtNo, @pStartNo,@pStopTime,@pVoltageInPanel,@pKWInPanel,@pCE,@pCarbon,@pSilicon,@pAddedSilicon,@pPouredBoxNo,@pDrgNo,@pTappingTemp,@pOther1,@pOther2,@pOther3,@pOther4,@pstartdate,@penddate,@ptotaltime,@ptotalminit,@pAddedCarbon,@pAddedFerroSilicon,@pBunchWeight,@pAddedCrcScrap",
                                                ReturnValueParam1, paramID, ParamHeatNo, paramCuNo, paramMetalGrade, paramLiningHtNo, paramStartNo, paramStopTime, paramVoltageInPanel, paramKWInPanel, paramCE, paramCarbon, paramSilicon, paramAddedSilicon, paramPouredBoxNo, paramDrgNo, paramTappingTemp, paramOther1, paramOther2, paramOther3, paramOther4, paramstartdate, paramenddate, paramtotaltime, paramtotalminit, paramAddedCarbon, paramAddedFerroSilicon, paramBunchWeight, paramAddedCrcScrap);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (FuranceId > 0 && ListSalesFuranceLogSheetIRN2 != null)
                        {
                            if (ListSalesFuranceLogSheetIRN2.Count > 0)
                            {
                                foreach (FuranceLogSheetIRN2 objProd in ListSalesFuranceLogSheetIRN2)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCuNo = new SqlParameter("pCuNo", objProd.CuNo);
                                    var paramCRCScarp = new SqlParameter("pCRCScarp", objProd.CRCScarp);
                                    var paramRiser = new SqlParameter("pRiser", objProd.Riser);
                                    var paramFloorMetal = new SqlParameter("pFloorMetal", objProd.FloorMetal);
                                    var paramTurning = new SqlParameter("pTurning", objProd.Turning);
                                    var paramRejectionScarp = new SqlParameter("pRejectionScarp", objProd.RejectionScarp);
                                    var paramCarburiser = new SqlParameter("pCarburiser", objProd.Carburiser);
                                    var paramFesilicon = new SqlParameter("pFesilicon", objProd.Fesilicon);
                                    var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", objProd.FeSiMagnesium);
                                    var paramInnoculant = new SqlParameter("pInnoculant", objProd.Innoculant);
                                    var paramMsScrap = new SqlParameter("pMsScrap", objProd.MsScrap);
                                    var paramCooper = new SqlParameter("pCooper", objProd.Cooper);
                                    var paramFeManganase = new SqlParameter("pFeManganase", objProd.FeManganase);
                                    var paramOtherMetal = new SqlParameter("pOtherMetal", objProd.OtherMetal);
                                    var paramChargeInKG = new SqlParameter("pChargeInKG", objProd.ChargeInKG);

                                    var paramNikal = new SqlParameter("pNikal", objProd.Nikal);
                                    var paramBoron = new SqlParameter("pBoron", objProd.Boron);
                                    var paramBismuthMetal = new SqlParameter("pBismuthMetal", objProd.BismuthMetal);
                                    var paramSorelMetal = new SqlParameter("pSorelMetal", objProd.SorelMetal);

                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheetIRN2_AddNew @pFuranceId,@pHeatNo,@pCuNo, @pCRCScarp,@pRiser, @pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFesilicon,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                                ReturnValueParam1, paramID, ParamHeatNo, paramCuNo, ParamHeatNo, paramCuNo, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFesilicon, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (FuranceId > 0 && ListIRN2 != null)
                        {
                            if (ListIRN2.Count > 0)
                            {
                                foreach (IRN2 objProd in ListIRN2)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamItemId = new SqlParameter("pItemId", objProd.ItemId);
                                    var paramItemValue = new SqlParameter("pItemValue", objProd.ItemValue);
                                    var paramHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCUNo = new SqlParameter("pCUNo", objProd.CUNo);
                                    var paramRemarks = new SqlParameter("pRemarks", objProd.Remarks);
                                    var paramCRCScarp = new SqlParameter("pCRCScarp", objProd.CRCScarp);
                                    var paramRiser = new SqlParameter("pRiser", objProd.Riser);
                                    var paramFloorMetal = new SqlParameter("pFloorMetal", objProd.FloorMetal);
                                    var paramTurning = new SqlParameter("pTurning", objProd.Turning);
                                    var paramRejectionScarp = new SqlParameter("pRejectionScarp", objProd.RejectionScarp);
                                    var paramCarburiser = new SqlParameter("pCarburiser", objProd.Carburiser);
                                    var paramFERROSILICON = new SqlParameter("pFERROSILICON", objProd.FERROSILICON);
                                    var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", objProd.FeSiMagnesium);
                                    var paramInnoculant = new SqlParameter("pInnoculant", objProd.Innoculant);
                                    var paramMsScrap = new SqlParameter("pMsScrap", objProd.MsScrap);
                                    var paramCooper = new SqlParameter("pCooper", objProd.Cooper);
                                    var paramFeManganase = new SqlParameter("pFeManganase", objProd.FeManganase);
                                    var paramOtherMetal = new SqlParameter("pOtherMetal", objProd.OtherMetal);
                                    var paramChargeInKG = new SqlParameter("pChargeInKG", objProd.ChargeInKG);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);
                                    var paramBunchweight = new SqlParameter("pBunchweight", objProd.Bunchweight);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);

                                    var paramNikal = new SqlParameter("pNikal", objProd.Nikal);
                                    var paramBoron = new SqlParameter("pBoron", objProd.Boron);
                                    var paramBismuthMetal = new SqlParameter("pBismuthMetal", objProd.BismuthMetal);
                                    var paramSorelMetal = new SqlParameter("pSorelMetal", objProd.SorelMetal);

                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_ItemIRN2_AddNew @pFuranceId,@pItemId,@pItemValue, @pHeatNo,@pCUNo,@pRemarks,@pCRCScarp,@pRiser,@pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFERROSILICON,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pOther1,@pOther2,@pOther3,@pOther4,@pBunchweight,@pCarbon,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                                ReturnValueParam1, paramID, ParamItemId, paramItemValue, paramHeatNo, paramCUNo, paramRemarks, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFERROSILICON, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramOther1, paramOther2, paramOther3, paramOther4, paramBunchweight, paramCarbon, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }


                        dbContextTransaction.Commit();
                        this.SaveChanges();
                    }

                    else //**** Error ****
                    {
                        dbContextTransaction.Rollback();
                        GetErrorDescription(errorNo, ref errorDesc);
                    }
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();

                    errorNo = -1;
                    errorDesc = Convert.ToString(ex.Message);
                }
                return errorNo;
            }
        }


        public virtual int furchaselogsheeteditListIRN2_AddNew(int FuranceId, List<IRN2> ListIRN2, ref string errorDesc)
        {

            {
                errorDesc = "";

                var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                ReturnValueParam.Direction = System.Data.ParameterDirection.Output;




                var dbContext = this.Database;

                using (var dbContextTransaction = dbContext.BeginTransaction())
                {
                    int errorNo = 0;

                    try
                    {





                        if (FuranceId > 0 && ListIRN2 != null)
                        {
                            if (ListIRN2.Count > 0)
                            {
                                foreach (IRN2 objProd in ListIRN2)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamItemId = new SqlParameter("pItemId", objProd.ItemId);
                                    var paramItemValue = new SqlParameter("pItemValue", objProd.ItemValue);
                                    var paramHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCUNo = new SqlParameter("pCUNo", objProd.CUNo);
                                    var paramRemarks = new SqlParameter("pRemarks", objProd.Remarks);
                                    var paramCRCScarp = new SqlParameter("pCRCScarp", objProd.CRCScarp);
                                    var paramRiser = new SqlParameter("pRiser", objProd.Riser);
                                    var paramFloorMetal = new SqlParameter("pFloorMetal", objProd.FloorMetal);
                                    var paramTurning = new SqlParameter("pTurning", objProd.Turning);
                                    var paramRejectionScarp = new SqlParameter("pRejectionScarp", objProd.RejectionScarp);
                                    var paramCarburiser = new SqlParameter("pCarburiser", objProd.Carburiser);
                                    var paramFERROSILICON = new SqlParameter("pFERROSILICON", objProd.FERROSILICON);
                                    var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", objProd.FeSiMagnesium);
                                    var paramInnoculant = new SqlParameter("pInnoculant", objProd.Innoculant);
                                    var paramMsScrap = new SqlParameter("pMsScrap", objProd.MsScrap);
                                    var paramCooper = new SqlParameter("pCooper", objProd.Cooper);
                                    var paramFeManganase = new SqlParameter("pFeManganase", objProd.FeManganase);
                                    var paramOtherMetal = new SqlParameter("pOtherMetal", objProd.OtherMetal);
                                    var paramChargeInKG = new SqlParameter("pChargeInKG", objProd.ChargeInKG);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);
                                    var paramBunchweight = new SqlParameter("pBunchweight", objProd.Bunchweight);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);

                                    var paramNikal = new SqlParameter("pNikal", objProd.Nikal);
                                    var paramBoron = new SqlParameter("pBoron", objProd.Boron);
                                    var paramBismuthMetal = new SqlParameter("pBismuthMetal", objProd.BismuthMetal);
                                    var paramSorelMetal = new SqlParameter("pSorelMetal", objProd.SorelMetal);

                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_ItemIRN2_AddNew @pFuranceId,@pItemId,@pItemValue, @pHeatNo,@pCUNo,@pRemarks,@pCRCScarp,@pRiser,@pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFERROSILICON,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pOther1,@pOther2,@pOther3,@pOther4,@pBunchweight,@pCarbon,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                                    ReturnValueParam1, paramID, ParamItemId, paramItemValue, paramHeatNo, paramCUNo, paramRemarks, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFERROSILICON, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramOther1, paramOther2, paramOther3, paramOther4, paramBunchweight, paramCarbon, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }

                        if (errorNo >= 0) //**** Success
                        {
                            dbContextTransaction.Commit();
                            this.SaveChanges();
                        }

                        else //**** Error ****
                        {
                            dbContextTransaction.Rollback();
                            GetErrorDescription(errorNo, ref errorDesc);
                        }
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();

                        errorNo = -1;
                        errorDesc = Convert.ToString(ex.Message);
                    }
                    return errorNo;
                }
            }
        }








        public virtual int furchaselogsheeteditListIRN1_AddNew(int FuranceId, List<FuranceLogSheetIRN1> ListSalesFuranceLogSheetIRN1, ref string errorDesc)
        {
            {
                errorDesc = "";

                var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                ReturnValueParam.Direction = System.Data.ParameterDirection.Output;




                var dbContext = this.Database;

                using (var dbContextTransaction = dbContext.BeginTransaction())
                {
                    int errorNo = 0;

                    try
                    {

                        if (FuranceId > 0 && ListSalesFuranceLogSheetIRN1 != null)
                        {
                            if (ListSalesFuranceLogSheetIRN1.Count > 0)
                            {


                                foreach (FuranceLogSheetIRN1 objProd in ListSalesFuranceLogSheetIRN1)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCuNo = new SqlParameter("pCuNo", objProd.CuNo);
                                    var paramMetalGrade = new SqlParameter("pMetalGrade", objProd.MetalGrade);
                                    var paramLiningHtNo = new SqlParameter("pLiningHtNo", objProd.LiningHtNo);
                                    var paramStartNo = new SqlParameter("pStartNo", objProd.StartNo);
                                    var paramStopTime = new SqlParameter("pStopTime", objProd.StopTime);
                                    var paramVoltageInPanel = new SqlParameter("pVoltageInPanel", objProd.VoltageInPanel);
                                    var paramKWInPanel = new SqlParameter("pKWInPanel", objProd.KWInPanel);
                                    var paramCE = new SqlParameter("pCE", objProd.CE);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);
                                    var paramSilicon = new SqlParameter("pSilicon", objProd.Silicon);
                                    var paramAddedSilicon = new SqlParameter("pAddedSilicon", objProd.AddedSilicon);
                                    var paramPouredBoxNo = new SqlParameter("pPouredBoxNo", objProd.PouredBoxNo);
                                    var paramDrgNo = new SqlParameter("pDrgNo", objProd.DrgNo);
                                    var paramTappingTemp = new SqlParameter("pTappingTemp", objProd.TappingTemp);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);
                                    var paramstartdate = new SqlParameter("pstartdate", objProd.startdate);
                                    var paramenddate = new SqlParameter("penddate", objProd.enddate);
                                    var paramtotaltime = new SqlParameter("ptotaltime", objProd.totaltime);
                                    var paramtotalminit = new SqlParameter("ptotalminit", objProd.totalminit);
                                    var paramAddedCarbon = new SqlParameter("pAddedCarbon", objProd.AddedCarbon);
                                    var paramAddedFerroSilicon = new SqlParameter("pAddedFerroSilicon", objProd.AddedFerroSilicon);
                                    var paramBunchWeight = new SqlParameter("pBunchWeight", objProd.BunchWeight);
                                    var paramAddedCrcScrap = new SqlParameter("pAddedCrcScrap", objProd.AddedCrcScrap);


                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheetIRN1_AddNew @pFuranceId,@pHeatNo,@pCuNo, @pMetalGrade,@pLiningHtNo, @pStartNo,@pStopTime,@pVoltageInPanel,@pKWInPanel,@pCE,@pCarbon,@pSilicon,@pAddedSilicon,@pPouredBoxNo,@pDrgNo,@pTappingTemp,@pOther1,@pOther2,@pOther3,@pOther4,@pstartdate,@penddate,@ptotaltime,@ptotalminit,@pAddedCarbon,@pAddedFerroSilicon,@pBunchWeight,@pAddedCrcScrap",
                                                ReturnValueParam1, paramID, ParamHeatNo, paramCuNo, paramMetalGrade, paramLiningHtNo, paramStartNo, paramStopTime, paramVoltageInPanel, paramKWInPanel, paramCE, paramCarbon, paramSilicon, paramAddedSilicon, paramPouredBoxNo, paramDrgNo, paramTappingTemp, paramOther1, paramOther2, paramOther3, paramOther4, paramstartdate, paramenddate, paramtotaltime, paramtotalminit, paramAddedCarbon, paramAddedFerroSilicon, paramBunchWeight, paramAddedCrcScrap);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }

                        if (errorNo >= 0) //**** Success
                        {
                            dbContextTransaction.Commit();
                            this.SaveChanges();
                        }

                        else //**** Error ****
                        {
                            dbContextTransaction.Rollback();
                            GetErrorDescription(errorNo, ref errorDesc);
                        }
                    }
                    catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();

                        errorNo = -1;
                        errorDesc = Convert.ToString(ex.Message);
                    }
                    return errorNo;
                }

            }
        }








        public virtual int Irnone_Edit(int IRN1ID, string HeatNo, string CuNo, string MetalGrade, string LiningHtNo, string StartNo, string StopTime, string VoltageInPanel, string KWInPanel, string CE, string Carbon, string Silicon, string AddedSilicon, string PouredBoxNo, string DrgNo, string TappingTemp, string Other1, string Other2, string Other3, string Other4, string startdate, string enddate, string totaltime, string totalminit, decimal AddedCarbon, decimal AddedFerroSilicon, decimal BunchWeight, decimal AddedCrcScrap, ref string errorDesc)
        {


            errorDesc = "";

            var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
            ReturnValueParam.Direction = System.Data.ParameterDirection.Output;

            var paramIRN1ID = new SqlParameter("pIRN1ID", IRN1ID);
            var ParamHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramCuNo = new SqlParameter("pCuNo", CuNo);
            var paramMetalGrade = new SqlParameter("pMetalGrade", MetalGrade);
            var paramLiningHtNo = new SqlParameter("pLiningHtNo", LiningHtNo);
            var paramStartNo = new SqlParameter("pStartNo", StartNo);
            var paramStopTime = new SqlParameter("pStopTime", StopTime);
            var paramVoltageInPanel = new SqlParameter("pVoltageInPanel", VoltageInPanel);
            var paramKWInPanel = new SqlParameter("pKWInPanel", KWInPanel);
            var paramCE = new SqlParameter("pCE", CE);
            var paramCarbon = new SqlParameter("pCarbon", Carbon);
            var paramSilicon = new SqlParameter("pSilicon", Silicon);
            var paramAddedSilicon = new SqlParameter("pAddedSilicon", AddedSilicon);
            var paramPouredBoxNo = new SqlParameter("pPouredBoxNo", PouredBoxNo);
            var paramDrgNo = new SqlParameter("pDrgNo", DrgNo);
            var paramTappingTemp = new SqlParameter("pTappingTemp", TappingTemp);
            var paramOther1 = new SqlParameter("pOther1", Other1);
            var paramOther2 = new SqlParameter("pOther2", Other2);
            var paramOther3 = new SqlParameter("pOther3", Other3);
            var paramOther4 = new SqlParameter("pOther4", Other4);
            var paramstartdate = new SqlParameter("pstartdate", startdate);
            var paramenddate = new SqlParameter("penddate", enddate);
            var paramtotaltime = new SqlParameter("ptotaltime", totaltime);
            var paramtotalminit = new SqlParameter("ptotalminit", totalminit);
            var paramAddedCarbon = new SqlParameter("pAddedCarbon", AddedCarbon);
            var paramAddedFerroSilicon = new SqlParameter("pAddedFerroSilicon", AddedFerroSilicon);
            var paramBunchWeight = new SqlParameter("pBunchWeight", BunchWeight);
            var paramAddedCrcScrap = new SqlParameter("pAddedCrcScrap", AddedCrcScrap);


            var dbContext = this.Database;

            using (var dbContextTransaction = dbContext.BeginTransaction())
            {
                int errorNo = 0;

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_Irnone_Edit @pIRN1ID,@pHeatNo,@pCuNo, @pMetalGrade,@pLiningHtNo, @pStartNo,@pStopTime,@pVoltageInPanel,@pKWInPanel,@pCE,@pCarbon,@pSilicon,@pAddedSilicon,@pPouredBoxNo,@pDrgNo,@pTappingTemp,@pOther1,@pOther2,@pOther3,@pOther4,@pstartdate,@penddate,@ptotaltime,@ptotalminit,@pAddedCarbon,@pAddedFerroSilicon,@pBunchWeight,@pAddedCrcScrap",
                                            ReturnValueParam, paramIRN1ID, ParamHeatNo, paramCuNo, paramMetalGrade, paramLiningHtNo, paramStartNo, paramStopTime, paramVoltageInPanel, paramKWInPanel, paramCE, paramCarbon, paramSilicon, paramAddedSilicon, paramPouredBoxNo, paramDrgNo, paramTappingTemp, paramOther1, paramOther2, paramOther3, paramOther4, paramstartdate, paramenddate, paramtotaltime, paramtotalminit, paramAddedCarbon, paramAddedFerroSilicon, paramBunchWeight, paramAddedCrcScrap);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);

                    if (errorNo >= 0) //**** Success
                    {
                        dbContextTransaction.Commit();
                        this.SaveChanges();
                    }
                    else //**** Error ****
                    {
                        dbContextTransaction.Rollback();
                        GetErrorDescription(errorNo, ref errorDesc);
                    }
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();

                    errorNo = -1;
                    errorDesc = Convert.ToString(ex.Message);
                }
                return errorNo;
            }
        }







        public virtual int Irntwo_Edit(int ItemIRN2_ID, int ItemId, string ItemValue, string HeatNo, string CUNo, string Remarks, string CRCScarp, string Riser, string FloorMetal, string Turning, string RejectionScarp, string Carburiser, string FERROSILICON, string FeSiMagnesium, string Innoculant, string MsScrap, string Cooper, string FeManganase, string OtherMetal, string ChargeInKG, string Other1, string Other2, string Other3, string Other4, int Bunchweight, string Carbon,string Nikal,string Boron,string BismuthMetal,string SorelMetal, ref string errorDesc)
        {


            errorDesc = "";

            var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
            ReturnValueParam.Direction = System.Data.ParameterDirection.Output;

            var paramItemIRN2_ID = new SqlParameter("pItemIRN2_ID", ItemIRN2_ID);
            var ParamItemId = new SqlParameter("pItemId", ItemId);
            var paramItemValue = new SqlParameter("pItemValue", ItemValue);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramCUNo = new SqlParameter("pCUNo", CUNo);
            var paramRemarks = new SqlParameter("pRemarks", Remarks);
            var paramCRCScarp = new SqlParameter("pCRCScarp", CRCScarp);
            var paramRiser = new SqlParameter("pRiser", Riser);
            var paramFloorMetal = new SqlParameter("pFloorMetal", FloorMetal);
            var paramTurning = new SqlParameter("pTurning", Turning);
            var paramRejectionScarp = new SqlParameter("pRejectionScarp", RejectionScarp);
            var paramCarburiser = new SqlParameter("pCarburiser", Carburiser);
            var paramFERROSILICON = new SqlParameter("pFERROSILICON", FERROSILICON);
            var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", FeSiMagnesium);
            var paramInnoculant = new SqlParameter("pInnoculant", Innoculant);
            var paramMsScrap = new SqlParameter("pMsScrap", MsScrap);
            var paramCooper = new SqlParameter("pCooper", Cooper);
            var paramFeManganase = new SqlParameter("pFeManganase", FeManganase);
            var paramOtherMetal = new SqlParameter("pOtherMetal", OtherMetal);
            var paramChargeInKG = new SqlParameter("pChargeInKG", ChargeInKG);
            var paramOther1 = new SqlParameter("pOther1", Other1);
            var paramOther2 = new SqlParameter("pOther2", Other2);
            var paramOther3 = new SqlParameter("pOther3", Other3);
            var paramOther4 = new SqlParameter("pOther4", Other4);
            var paramBunchweight = new SqlParameter("pBunchweight", Bunchweight);
            var paramCarbon = new SqlParameter("pCarbon", Carbon);
            var paramNikal = new SqlParameter("pNikal", Nikal);
            var paramBoron = new SqlParameter("pBoron", Boron);
            var paramBismuthMetal = new SqlParameter("pBismuthMetal", BismuthMetal);
            var paramSorelMetal = new SqlParameter("pSorelMetal", SorelMetal);



            var dbContext = this.Database;

            using (var dbContextTransaction = dbContext.BeginTransaction())
            {
                int errorNo = 0;

                try
                {

                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_ItemIRN2_Edit @pItemIRN2_ID,@pItemId,@pItemValue,@pHeatNo,@pCUNo,@pRemarks,@pCRCScarp,@pRiser,@pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFERROSILICON,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pOther1,@pOther2,@pOther3,@pOther4,@pBunchweight,@pCarbon,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                            ReturnValueParam, paramItemIRN2_ID, ParamItemId, paramItemValue, paramHeatNo, paramCUNo, paramRemarks, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFERROSILICON, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramOther1, paramOther2, paramOther3, paramOther4, paramBunchweight, paramCarbon, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);

                    if (errorNo >= 0) //**** Success
                    {
                        dbContextTransaction.Commit();
                        this.SaveChanges();
                    }
                    else //**** Error ****
                    {
                        dbContextTransaction.Rollback();
                        GetErrorDescription(errorNo, ref errorDesc);
                    }
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();

                    errorNo = -1;
                    errorDesc = Convert.ToString(ex.Message);
                }
                return errorNo;
            }
        }




        public virtual int FuranceLogSheet_Edit(int FuranceId, string UnitName, DateTime Date, string DayShiftOperator, string Shift, string StartMeterReading, string StopMeterReading, string TotalUnits, string TotalMelting, string UnitPerKg, string IsActive, string UserID, string FinalYear, string Status, string NetProduction, string FloorMetal, string Rejection, string Riserweight, string SlagWeight,
       List<FuranceLogSheetIRN1> ListSalesFuranceLogSheetIRN1, List<FuranceLogSheetIRN2> ListSalesFuranceLogSheetIRN2, List<IRN2> ListIRN2, int ShiftMasterid,decimal BunchWeight, ref string errorDesc)
        {
            errorDesc = "";

            var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
            ReturnValueParam.Direction = System.Data.ParameterDirection.Output;

            var paramFuranceId = new SqlParameter("pFuranceId", FuranceId);
            var paramUnitName = new SqlParameter("pUnitName", UnitName);
            var paramDate = new SqlParameter("pDate", Date);
            var paramDayShiftOperator = new SqlParameter("pDayShiftOperator", DayShiftOperator);
            var paramShift = new SqlParameter("pShift", Shift);
            var paramStartMeterReading = new SqlParameter("pStartMeterReading", StartMeterReading);
            var paramStopMeterReading = new SqlParameter("pStopMeterReading", StopMeterReading);
            var paramTotalUnits = new SqlParameter("pTotalUnits", TotalUnits);
            var paramTotalMelting = new SqlParameter("pTotalMelting", TotalMelting);
            var paramUnitPerKg = new SqlParameter("pUnitPerKg", UnitPerKg);
            var paramIsActive = new SqlParameter("pIsActive", IsActive);
            var paramUserID = new SqlParameter("pUserID", UserID);
            var paramFinalYear = new SqlParameter("pFinalYear", FinalYear);
            var paramStatus = new SqlParameter("pStatus", Status);
            var paramNetProduction = new SqlParameter("pNetProduction", NetProduction);
            var paramFloorMetal1 = new SqlParameter("pFloorMetal", FloorMetal);
            var paramRejection = new SqlParameter("pRejection", Rejection);
            var paramRiserweight = new SqlParameter("pRiserweight", Riserweight);
            var paramSlagWeight = new SqlParameter("pSlagWeight", SlagWeight);
            var paramShiftMasterid = new SqlParameter("pShiftMasterid", ShiftMasterid);
            var paramsBunchWeight = new SqlParameter("pBunchWeight", BunchWeight);


            var dbContext = this.Database;

            using (var dbContextTransaction = dbContext.BeginTransaction())
            {
                int errorNo = 0;

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheet_Edit @pFuranceId,@pUnitName, @pDate, @pDayShiftOperator,@pShift,@pStartMeterReading,@pStopMeterReading,@pTotalUnits, @pTotalMelting,@pUnitPerKg,@pIsActive,@pUserID,@pFinalYear,@pStatus,@pNetProduction,@pFloorMetal,@pRejection,@pRiserweight,@pSlagWeight,@pShiftMasterid,@pBunchWeight",
                                                ReturnValueParam, paramFuranceId, paramUnitName, paramDate, paramDayShiftOperator, paramShift, paramStartMeterReading, paramStopMeterReading, paramTotalUnits, paramTotalMelting, paramUnitPerKg, paramIsActive, paramUserID, paramFinalYear, paramStatus, paramNetProduction, paramFloorMetal1, paramRejection, paramRiserweight, paramSlagWeight, paramShiftMasterid, paramsBunchWeight);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);

                    if (errorNo >= 0) //**** Success
                    {


                        FuranceId = Convert.ToInt32(paramFuranceId.Value);
                        if (FuranceId > 0 && ListSalesFuranceLogSheetIRN1 != null)
                        {
                            if (ListSalesFuranceLogSheetIRN1.Count > 0)
                            {
                                foreach (FuranceLogSheetIRN1 objProd in ListSalesFuranceLogSheetIRN1)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCuNo = new SqlParameter("pCuNo", objProd.CuNo);
                                    var paramMetalGrade = new SqlParameter("pMetalGrade", objProd.MetalGrade);
                                    var paramLiningHtNo = new SqlParameter("pLiningHtNo", objProd.LiningHtNo);
                                    var paramStartNo = new SqlParameter("pStartNo", objProd.StartNo);
                                    var paramStopTime = new SqlParameter("pStopTime", objProd.StopTime);
                                    var paramVoltageInPanel = new SqlParameter("pVoltageInPanel", objProd.VoltageInPanel);
                                    var paramKWInPanel = new SqlParameter("pKWInPanel", objProd.KWInPanel);
                                    var paramCE = new SqlParameter("pCE", objProd.CE);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);
                                    var paramSilicon = new SqlParameter("pSilicon", objProd.Silicon);
                                    var paramAddedSilicon = new SqlParameter("pAddedSilicon", objProd.AddedSilicon);
                                    var paramPouredBoxNo = new SqlParameter("pPouredBoxNo", objProd.PouredBoxNo);
                                    var paramDrgNo = new SqlParameter("pDrgNo", objProd.DrgNo);
                                    var paramTappingTemp = new SqlParameter("pTappingTemp", objProd.TappingTemp);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);


                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_FuranceLogSheetIRN1_AddNew @pFuranceId,@pHeatNo,@pCuNo, @pMetalGrade,@pLiningHtNo, @pStartNo,@pStopTime,@pVoltageInPanel,@pKWInPanel,@pCE,@pCarbon,@pSilicon,@pAddedSilicon,@pPouredBoxNo,@pDrgNo,@pTappingTemp,@pOther1,@pOther2,@pOther3,@pOther4",
                                                ReturnValueParam1, paramID, ParamHeatNo, paramCuNo, paramMetalGrade, paramLiningHtNo, paramStartNo, paramStopTime, paramVoltageInPanel, paramKWInPanel, paramCE, paramCarbon, paramSilicon, paramAddedSilicon, paramPouredBoxNo, paramDrgNo, paramTappingTemp, paramOther1, paramOther2, paramOther3, paramOther4);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (FuranceId > 0 && ListSalesFuranceLogSheetIRN2 != null)
                        {
                            if (ListSalesFuranceLogSheetIRN2.Count > 0)
                            {
                                foreach (FuranceLogSheetIRN2 objProd in ListSalesFuranceLogSheetIRN2)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;

                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCuNo = new SqlParameter("pCuNo", objProd.CuNo);
                                    var paramCRCScarp = new SqlParameter("pCRCScarp", objProd.CRCScarp);
                                    var paramRiser = new SqlParameter("pRiser", objProd.Riser);
                                    var paramFloorMetal = new SqlParameter("pFloorMetal", objProd.FloorMetal);
                                    var paramTurning = new SqlParameter("pTurning", objProd.Turning);
                                    var paramRejectionScarp = new SqlParameter("pRejectionScarp", objProd.RejectionScarp);
                                    var paramCarburiser = new SqlParameter("pCarburiser", objProd.Carburiser);
                                    var paramFesilicon = new SqlParameter("pFesilicon", objProd.Fesilicon);
                                    var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", objProd.FeSiMagnesium);
                                    var paramInnoculant = new SqlParameter("pInnoculant", objProd.Innoculant);
                                    var paramMsScrap = new SqlParameter("pMsScrap", objProd.MsScrap);
                                    var paramCooper = new SqlParameter("pCooper", objProd.Cooper);
                                    var paramFeManganase = new SqlParameter("pFeManganase", objProd.FeManganase);
                                    var paramOtherMetal = new SqlParameter("pOtherMetal", objProd.OtherMetal);
                                    var paramChargeInKG = new SqlParameter("pChargeInKG", objProd.ChargeInKG);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);
                                    var paramBunchweight = new SqlParameter("pBunchweight", objProd.Bunchweight);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);

                                    var paramNikal = new SqlParameter("pNikal", objProd.Nikal);
                                    var paramBoron = new SqlParameter("pBoron", objProd.Boron);
                                    var paramBismuthMetal = new SqlParameter("pBismuthMetal", objProd.BismuthMetal);
                                    var paramSorelMetal = new SqlParameter("pSorelMetal", objProd.SorelMetal);


                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_ItemIRN2_Edit @pFuranceId,@pHeatNo,@pCuNo, @pCRCScarp,@pRiser, @pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFesilicon,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pOther1,@pOther2,@pOther3,@pOther4,@pBunchweight,@pCarbon,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                                ReturnValueParam1, paramID, ParamHeatNo, paramCuNo, ParamHeatNo, paramCuNo, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFesilicon, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramOther1, paramOther2, paramOther3, paramOther4, paramBunchweight, paramCarbon, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }
                        if (FuranceId > 0 && ListIRN2 != null)
                        {
                            if (ListIRN2.Count > 0)
                            {
                                foreach (IRN2 objProd in ListIRN2)
                                {
                                    var ReturnValueParam1 = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
                                    ReturnValueParam1.Direction = System.Data.ParameterDirection.Output;
                                    var paramItemIRN2_ID = new SqlParameter("pItemIRN2_ID", objProd.ItemIRN2_ID);
                                    var paramID = new SqlParameter("pFuranceId", FuranceId);
                                    var ParamItemId = new SqlParameter("pItemId", objProd.ItemId);
                                    var paramItemValue = new SqlParameter("pItemValue", objProd.ItemValue);
                                    var paramHeatNo = new SqlParameter("pHeatNo", objProd.HeatNo);
                                    var paramCUNo = new SqlParameter("pCUNo", objProd.CUNo);
                                    var paramRemarks = new SqlParameter("pRemarks", objProd.Remarks);
                                    var paramCRCScarp = new SqlParameter("pCRCScarp", objProd.CRCScarp);
                                    var paramRiser = new SqlParameter("pRiser", objProd.Riser);
                                    var paramFloorMetal = new SqlParameter("pFloorMetal", objProd.FloorMetal);
                                    var paramTurning = new SqlParameter("pTurning", objProd.Turning);
                                    var paramRejectionScarp = new SqlParameter("pRejectionScarp", objProd.RejectionScarp);
                                    var paramCarburiser = new SqlParameter("pCarburiser", objProd.Carburiser);
                                    var paramFERROSILICON = new SqlParameter("pFERROSILICON", objProd.FERROSILICON);
                                    var paramFeSiMagnesium = new SqlParameter("pFeSiMagnesium", objProd.FeSiMagnesium);
                                    var paramInnoculant = new SqlParameter("pInnoculant", objProd.Innoculant);
                                    var paramMsScrap = new SqlParameter("pMsScrap", objProd.MsScrap);
                                    var paramCooper = new SqlParameter("pCooper", objProd.Cooper);
                                    var paramFeManganase = new SqlParameter("pFeManganase", objProd.FeManganase);
                                    var paramOtherMetal = new SqlParameter("pOtherMetal", objProd.OtherMetal);
                                    var paramChargeInKG = new SqlParameter("pChargeInKG", objProd.ChargeInKG);
                                    var paramOther1 = new SqlParameter("pOther1", objProd.Other1);
                                    var paramOther2 = new SqlParameter("pOther2", objProd.Other2);
                                    var paramOther3 = new SqlParameter("pOther3", objProd.Other3);
                                    var paramOther4 = new SqlParameter("pOther4", objProd.Other4);
                                    var paramCarbon = new SqlParameter("pCarbon", objProd.Carbon);
                                    var paramNikal = new SqlParameter("pNikal", objProd.Nikal);
                                    var paramBoron = new SqlParameter("pBoron", objProd.Boron);
                                    var paramBismuthMetal = new SqlParameter("pBismuthMetal", objProd.BismuthMetal);
                                    var paramSorelMetal = new SqlParameter("pSorelMetal", objProd.SorelMetal);

                                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_ItemIRN2_Edit @pItemIRN2_ID,@pFuranceId,@pItemId,@pItemValue, @pHeatNo,@pCUNo,@pRemarks,@pCRCScarp,@pRiser,@pFloorMetal,@pTurning,@pRejectionScarp,@pCarburiser,@pFERROSILICON,@pFeSiMagnesium,@pInnoculant,@pMsScrap,@pCooper,@pFeManganase,@pOtherMetal,@pChargeInKG,@pOther1,@pOther2,@pOther3,@pOther4,@pCarbon,@pNikal,@pBoron,@pBismuthMetal,@pSorelMetal",
                                                ReturnValueParam1, paramItemIRN2_ID, paramID, ParamItemId, paramItemValue, paramHeatNo, paramCUNo, paramRemarks, paramCRCScarp, paramRiser, paramFloorMetal, paramTurning, paramRejectionScarp, paramCarburiser, paramFERROSILICON, paramFeSiMagnesium, paramInnoculant, paramMsScrap, paramCooper, paramFeManganase, paramOtherMetal, paramChargeInKG, paramOther1, paramOther2, paramOther3, paramOther4, paramCarbon, paramNikal, paramBoron, paramBismuthMetal, paramSorelMetal);

                                    errorNo = Convert.ToInt32(ReturnValueParam1.Value);


                                    if (errorNo < 0)
                                    {
                                        dbContextTransaction.Rollback();
                                        GetErrorDescription(errorNo, ref errorDesc);
                                        break;
                                    }
                                }
                            }
                        }


                        dbContextTransaction.Commit();
                        this.SaveChanges();
                    }

                    else //**** Error ****
                    {
                        dbContextTransaction.Rollback();
                        GetErrorDescription(errorNo, ref errorDesc);
                    }
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();

                    errorNo = -1;
                    errorDesc = Convert.ToString(ex.Message);
                }
                return errorNo;
            }
        }



        public virtual List<FuranceLogSheet> FuranceLogSheet_GetAll(int FuranceId)
        {
            var paramIRN1ID = new SqlParameter("pFuranceId", FuranceId);



            return this.Database.SqlQuery<FuranceLogSheet>(
                            "Sp_FuranceLogSheet_GetAll @pFuranceId",
                            paramIRN1ID).ToList();
        }

        public virtual List<IRN2> ItemIRN2_GetAll(int ItemIRN2_ID, int FuranceId)
        {
            var paramItemIRN2_ID = new SqlParameter("pItemIRN2_ID", ItemIRN2_ID);
            var paramFuranceId = new SqlParameter("pFuranceId", FuranceId);


            return this.Database.SqlQuery<IRN2>(
                            "Sp_ItemIRN2_GetAll @pItemIRN2_ID,@pFuranceId",
                            paramItemIRN2_ID, paramFuranceId).ToList();
        }


        public virtual List<IRN2> ItemIRN2_GetAllS(int ItemIRN2_ID, int FuranceId)
        {
            var paramItemIRN2_ID = new SqlParameter("pItemIRN2_ID", ItemIRN2_ID);
            var paramFuranceId = new SqlParameter("pFuranceId", FuranceId);


            return this.Database.SqlQuery<IRN2>(
                            "Sp_ItemIRN2_GetAll @pItemIRN2_ID,@pFuranceId",
                            paramItemIRN2_ID, paramFuranceId).ToList();
        }


        public virtual List<FuranceLogSheetIRN1> FuranceLogSheetIRN1_GetAll(int IRN1ID, int FuranceId)
        {
            var paramIRN1ID = new SqlParameter("pIRN1ID", IRN1ID);
            var paramFuranceId = new SqlParameter("pFuranceId", FuranceId);

            try
            {
                return this.Database.SqlQuery<FuranceLogSheetIRN1>(
                                "Sp_FuranceLogSheetIRN1_GetAll @pIRN1ID,@pFuranceId",
                                paramIRN1ID, paramFuranceId).ToList();
            }
            catch (Exception ex)
            {
                var sa = ex.Message;
            }
            return this.Database.SqlQuery<FuranceLogSheetIRN1>(
                               "Sp_FuranceLogSheetIRN1_GetAll @pIRN1ID,@pFuranceId",
                               paramIRN1ID, paramFuranceId).ToList();
        }
    }
}