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

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

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

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<DailyFoundryproduction>().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 DailyFoundlyProduction_AddNew(DateTime Date,string DocNo,int Unitid,int MetalId,int Meltingoperatorone,int Meltingoperatortwo,int Dieoperatorone,int Dieoperatortwo,int Dieoperatorthree,string Opreading,string Clreading,string FcStarttime,string FcFinishtime,string PowerAverage,string DrossWeight,string InwardRiserWeight,string InwardTurningWeight,string InwardRejectionWeight, ref int FpId,string Dieoperatorfour,string Dieoperatorfive,string Dieoperatorsix, ref string errorDesc)
        {
            errorDesc = "";

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

         

            var paramDate = new SqlParameter("pDate", Date);
            var paramDocNo = new SqlParameter("pDocNo", DocNo);
            var paramUnitid = new SqlParameter("pUnitid", Unitid);
            var paramMetalId = new SqlParameter("pMetalId", MetalId);
            var paramMeltingoperatorone = new SqlParameter("pMeltingoperatorone", Meltingoperatorone);
            var paramMeltingoperatortwo = new SqlParameter("pMeltingoperatortwo", Meltingoperatortwo);
            var paramDieoperatorone = new SqlParameter("pDieoperatorone", Dieoperatorone);
            var paramDieoperatortwo = new SqlParameter("pDieoperatortwo", Dieoperatortwo);
           
            var paramDieoperatorthree = new SqlParameter("pDieoperatorthree", Dieoperatorthree);
            var paramOpreading = new SqlParameter("pOpreading", Opreading);
            var paramClreading = new SqlParameter("pClreading", Clreading);
            var paramFcStarttime = new SqlParameter("pFcStarttime", FcStarttime);
            
           var paramFcFinishtime = new SqlParameter("pFcFinishtime", FcFinishtime);
            var paramPowerAverage = new SqlParameter("pPowerAverage", PowerAverage);
            var paramDrossWeight = new SqlParameter("pDrossWeight", DrossWeight);
            var paramInwardRiserWeight = new SqlParameter("pInwardRiserWeight", InwardRiserWeight);
            var paramInwardTurningWeight = new SqlParameter("pInwardTurningWeight", InwardTurningWeight);
            var paramInwardRejectionWeight = new SqlParameter("pInwardRejectionWeight", InwardRejectionWeight);
            var paramFpId = new SqlParameter("pFpId", System.Data.SqlDbType.Int);
            paramFpId.Direction = System.Data.ParameterDirection.Output;

            var paramDieoperatorfour = new SqlParameter("pDieoperatorfour", Dieoperatorfour);
            var paramDieoperatorfive = new SqlParameter("pDieoperatorfive", Dieoperatorfive);
            var paramDieoperatorsix = new SqlParameter("pDieoperatorsix", Dieoperatorsix);
           
            

            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProduction_AddNew  @pDate,@pDocNo,@pUnitid,@pMetalId,@pMeltingoperatorone,@pMeltingoperatortwo,@pDieoperatorone,@pDieoperatortwo,@pDieoperatorthree,@pOpreading,@pClreading,@pFcStarttime,@pFcFinishtime,@pPowerAverage,@pDrossWeight,@pInwardRiserWeight,@pInwardTurningWeight,@pInwardRejectionWeight,@pFpId OUT,@pDieoperatorfour,@pDieoperatorfive,@pDieoperatorsix",
                                                ReturnValueParam, paramDate, paramDocNo, paramUnitid, paramMetalId, paramMeltingoperatorone, paramMeltingoperatortwo, paramDieoperatorone, paramDieoperatortwo, paramDieoperatorthree, paramOpreading, paramClreading, paramFcStarttime, paramFcFinishtime, paramPowerAverage, paramDrossWeight, paramInwardRiserWeight, paramInwardTurningWeight, paramInwardRejectionWeight, paramFpId, paramDieoperatorfour, paramDieoperatorfive, paramDieoperatorsix);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);


                    FpId = Convert.ToInt32(paramFpId.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 DailyFoundlyProduction_Edit(int FpId, DateTime Date, string DocNo, int Unitid, int MetalId, int Meltingoperatorone, int Meltingoperatortwo, int Dieoperatorone, int Dieoperatortwo, int Dieoperatorthree, string Opreading, string Clreading, string FcStarttime, string FcFinishtime, string PowerAverage, string DrossWeight, string InwardRiserWeight, string InwardTurningWeight, string InwardRejectionWeight, string Dieoperatorfour, string Dieoperatorfive, string Dieoperatorsix, ref string errorDesc)
        {
            errorDesc = "";

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


            var paramFpId = new SqlParameter("pFpId", FpId);
            var paramDate = new SqlParameter("pDate", Date);
            var paramDocNo = new SqlParameter("pDocNo", DocNo);
            var paramUnitid = new SqlParameter("pUnitid", Unitid);
            var paramMetalId = new SqlParameter("pMetalId", MetalId);
            var paramMeltingoperatorone = new SqlParameter("pMeltingoperatorone", Meltingoperatorone);
            var paramMeltingoperatortwo = new SqlParameter("pMeltingoperatortwo", Meltingoperatortwo);
            var paramDieoperatorone = new SqlParameter("pDieoperatorone", Dieoperatorone);
            var paramDieoperatortwo = new SqlParameter("pDieoperatortwo", Dieoperatortwo);

            var paramDieoperatorthree = new SqlParameter("pDieoperatorthree", Dieoperatorthree);
            var paramOpreading = new SqlParameter("pOpreading", Opreading);
            var paramClreading = new SqlParameter("pClreading", Clreading);
            var paramFcStarttime = new SqlParameter("pFcStarttime", FcStarttime);

            var paramFcFinishtime = new SqlParameter("pFcFinishtime", FcFinishtime);
            var paramPowerAverage = new SqlParameter("pPowerAverage", PowerAverage);
            var paramDrossWeight = new SqlParameter("pDrossWeight", DrossWeight);
            var paramInwardRiserWeight = new SqlParameter("pInwardRiserWeight", InwardRiserWeight);
            var paramInwardTurningWeight = new SqlParameter("pInwardTurningWeight", InwardTurningWeight);
            var paramInwardRejectionWeight = new SqlParameter("pInwardRejectionWeight", InwardRejectionWeight);
            var paramDieoperatorfour = new SqlParameter("pDieoperatorfour", Dieoperatorfour);
            var paramDieoperatorfive = new SqlParameter("pDieoperatorfive", Dieoperatorfive);
            var paramDieoperatorsix = new SqlParameter("pDieoperatorsix", Dieoperatorsix);
            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProduction_Edit  @pFpId,@pDate,@pDocNo,@pUnitid,@pMetalId,@pMeltingoperatorone,@pMeltingoperatortwo,@pDieoperatorone,@pDieoperatortwo,@pDieoperatorthree,@pOpreading,@pClreading,@pFcStarttime,@pFcFinishtime,@pPowerAverage,@pDrossWeight,@pInwardRiserWeight,@pInwardTurningWeight,@pInwardRejectionWeight,@pDieoperatorfour,@pDieoperatorfive,@pDieoperatorsix",
                                                ReturnValueParam, paramFpId, paramDate, paramDocNo, paramUnitid, paramMetalId, paramMeltingoperatorone, paramMeltingoperatortwo, paramDieoperatorone, paramDieoperatortwo, paramDieoperatorthree, paramOpreading, paramClreading, paramFcStarttime, paramFcFinishtime, paramPowerAverage, paramDrossWeight, paramInwardRiserWeight, paramInwardTurningWeight, paramInwardRejectionWeight, paramDieoperatorfour, paramDieoperatorfive, paramDieoperatorsix);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);


                    FpId = Convert.ToInt32(paramFpId.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 List<DailyFoundryproduction> DailyFoundryproduction_GetAll(int FpId)
        {
            var paramFpId = new SqlParameter("pFpId", FpId);
            

            return this.Database.SqlQuery<DailyFoundryproduction>(
                            "Sp_DailyFoundayProduction_Getall @pFpId",
                            paramFpId).ToList();
        }



        public virtual int DailyFoundlyProductionone_AddNew(int FpId,string HeatNo,string AlloyIngotWeight,string AlloyIngotPcs,string RejectionWeight,string ReasonForRejection,string RiserWeight,string TurningWeight,string PouringEndTime,string MetalTemp,string AtbrenorFive,string AsrtenNoofPc,string Magnesium,string N2DeGassingTime,string Gr530,string CoverAlFlux,string RejectionNo,int MetalgradId,string Atb,string Atbqty, ref string errorDesc)
        {
            errorDesc = "";

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

         

            var paramFpId = new SqlParameter("pFpId", FpId);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramAlloyIngotWeight = new SqlParameter("pAlloyIngotWeight", AlloyIngotWeight);
            var paramAlloyIngotPcs = new SqlParameter("pAlloyIngotPcs", AlloyIngotPcs);
            var paramRejectionWeight = new SqlParameter("pRejectionWeight", RejectionWeight);
            var paramReasonForRejection = new SqlParameter("pReasonForRejection", ReasonForRejection);
            var paramRiserWeight = new SqlParameter("pRiserWeight", RiserWeight);
            var paramTurningWeight = new SqlParameter("pTurningWeight", TurningWeight);
            var paramPouringEndTime = new SqlParameter("pPouringEndTime", PouringEndTime);
            var paramMetalTemp = new SqlParameter("pMetalTemp", MetalTemp);
            var paramAtbrenorFive = new SqlParameter("pAtbrenorFive", AtbrenorFive);
            var paramAsrtenNoofPc = new SqlParameter("pAsrtenNoofPc", AsrtenNoofPc);
            var paramMagnesium = new SqlParameter("pMagnesium", Magnesium);
            var paramN2DeGassingTime = new SqlParameter("pN2DeGassingTime", N2DeGassingTime);
            var paramGr530 = new SqlParameter("pGr530", Gr530);
            var paramCoverAlFlux = new SqlParameter("pCoverAlFlux", CoverAlFlux);
            var paramRejectionNo = new SqlParameter("pRejectionNo", RejectionNo);
            var paramMetalgradId = new SqlParameter("pMetalgradId", MetalgradId);
            var paramAtb = new SqlParameter("pAtb", Atb);
            var paramAtbqty = new SqlParameter("pAtbqty", Atbqty);

            
             var dbContext = this.Database;

            using (var dbContextTransaction = dbContext.BeginTransaction())
            {
                int errorNo = 0;
                
                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductionOne_AddNew   @pFpId,@pHeatNo,@pAlloyIngotWeight,@pAlloyIngotPcs,@pRejectionWeight,@pReasonForRejection,@pRiserWeight,@pTurningWeight,@pPouringEndTime,@pMetalTemp,@pAtbrenorFive,@pAsrtenNoofPc,@pMagnesium,@pN2DeGassingTime,@pGr530,@pCoverAlFlux,@pRejectionNo,@pMetalgradId,@pAtb,@pAtbqty",
                                                ReturnValueParam, paramFpId, paramHeatNo, paramAlloyIngotWeight, paramAlloyIngotPcs, paramRejectionWeight, paramReasonForRejection, paramRiserWeight, paramTurningWeight, paramPouringEndTime, paramMetalTemp, paramAtbrenorFive, paramAsrtenNoofPc, paramMagnesium, paramN2DeGassingTime, paramGr530, paramCoverAlFlux, paramRejectionNo, paramMetalgradId, paramAtb, paramAtbqty);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);


                    FpId = Convert.ToInt32(paramFpId.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 DailyFoundlyProductionone_Edit(int FqId1, string HeatNo, string AlloyIngotWeight, string AlloyIngotPcs, string RejectionWeight, string ReasonForRejection, string RiserWeight, string TurningWeight,string PouringEndTime, string MetalTemp, string AtbrenorFive, string AsrtenNoofPc, string Magnesium, string N2DeGassingTime, string Gr530, string CoverAlFlux,string RejectionNo,int MetalgradId, string Atb, string Atbqty, ref string errorDesc)
        {
            errorDesc = "";

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



            var paramFqId1 = new SqlParameter("pFqId1", FqId1);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramAlloyIngotWeight = new SqlParameter("pAlloyIngotWeight", AlloyIngotWeight);
            var paramAlloyIngotPcs = new SqlParameter("pAlloyIngotPcs", AlloyIngotPcs);
            var paramRejectionWeight = new SqlParameter("pRejectionWeight", RejectionWeight);
            var paramReasonForRejection = new SqlParameter("pReasonForRejection", ReasonForRejection);
            var paramRiserWeight = new SqlParameter("pRiserWeight", RiserWeight);
            var paramTurningWeight = new SqlParameter("pTurningWeight", TurningWeight);
            var paramPouringEndTime = new SqlParameter("pPouringEndTime", PouringEndTime);
            var paramMetalTemp = new SqlParameter("pMetalTemp", MetalTemp);
            var paramAtbrenorFive = new SqlParameter("pAtbrenorFive", AtbrenorFive);
            var paramAsrtenNoofPc = new SqlParameter("pAsrtenNoofPc", AsrtenNoofPc);
            var paramMagnesium = new SqlParameter("pMagnesium", Magnesium);
            var paramN2DeGassingTime = new SqlParameter("pN2DeGassingTime", N2DeGassingTime);
            var paramGr530 = new SqlParameter("pGr530", Gr530);
            var paramCoverAlFlux = new SqlParameter("pCoverAlFlux", CoverAlFlux);
            var paramRejectionNo = new SqlParameter("pRejectionNo", RejectionNo);
            var paramMetalgradId = new SqlParameter("pMetalgradId", MetalgradId);
            var paramAtb = new SqlParameter("pAtb", Atb);
            var paramAtbqty = new SqlParameter("pAtbqty", Atbqty);

            

            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductionone_Edit   @pFqId1,@pHeatNo,@pAlloyIngotWeight,@pAlloyIngotPcs,@pRejectionWeight,@pReasonForRejection,@pRiserWeight,@pTurningWeight,@pPouringEndTime,@pMetalTemp,@pAtbrenorFive,@pAsrtenNoofPc,@pMagnesium,@pN2DeGassingTime,@pGr530,@pCoverAlFlux,@pRejectionNo,@pMetalgradId,@pAtb,@pAtbqty",
                                                ReturnValueParam, paramFqId1, paramHeatNo, paramAlloyIngotWeight, paramAlloyIngotPcs, paramRejectionWeight, paramReasonForRejection, paramRiserWeight, paramTurningWeight,paramPouringEndTime, paramMetalTemp, paramAtbrenorFive, paramAsrtenNoofPc, paramMagnesium, paramN2DeGassingTime, paramGr530, paramCoverAlFlux, paramRejectionNo, paramMetalgradId, paramAtb, paramAtbqty);

                    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 List<DailyFoundryproductionone> DailyFoundryproductionone_GetAll(int FqId1,int FpId)
        {
            var paramFqId1 = new SqlParameter("pFqId1", FqId1);
            var paramFpId = new SqlParameter("pFpId", FpId);


            return this.Database.SqlQuery<DailyFoundryproductionone>(
                            "Sp_DailyFoundayProductionone_Getall @pFqId1,@pFpId",
                            paramFqId1, paramFpId).ToList();
        }



        public virtual int DailyFoundlyProductiontwo_AddNew(int FpId,string HeatNo,string InsertCorner,int ItemNo,string NoofPcs,string WeightInKg,string RejectionPcs,string No,string Reason, ref string errorDesc)
        {
            errorDesc = "";

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



            var paramFpId = new SqlParameter("pFpId", FpId);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramInsertCorner = new SqlParameter("pInsertCorner", InsertCorner);
            var paramItemNo = new SqlParameter("pItemNo", ItemNo);
            var paramNoofPcs = new SqlParameter("pNoofPcs", NoofPcs);
            var paramWeightInKg = new SqlParameter("pWeightInKg", WeightInKg);
            var paramRejectionPcs = new SqlParameter("pRejectionPcs", RejectionPcs);
            var paramNo = new SqlParameter("pNo", No);
            var paramReason = new SqlParameter("pReason", Reason);






            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductiontwo_AddNew   @pFpId,@pHeatNo,@pInsertCorner,@pItemNo,@pNoofPcs,@pWeightInKg,@pRejectionPcs,@pNo,@pReason",
                                                ReturnValueParam, paramFpId, paramHeatNo, paramInsertCorner, paramItemNo, paramNoofPcs,paramWeightInKg,paramRejectionPcs,paramNo,paramReason);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);


                    FpId = Convert.ToInt32(paramFpId.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 DailyFoundlyProductiontwo_Edit(int FqId2, string HeatNo, string InsertCorner, int ItemNo, string NoofPcs, string WeightInKg, string RejectionPcs, string No, string Reason, ref string errorDesc)
        {
            errorDesc = "";

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



            var paramFqId2 = new SqlParameter("pFqId2", FqId2);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramInsertCorner = new SqlParameter("pInsertCorner", InsertCorner);
            var paramItemNo = new SqlParameter("pItemNo", ItemNo);
            var paramNoofPcs = new SqlParameter("pNoofPcs", NoofPcs);
            var paramWeightInKg = new SqlParameter("pWeightInKg", WeightInKg);
            var paramRejectionPcs = new SqlParameter("pRejectionPcs", RejectionPcs);
            var paramNo = new SqlParameter("pNo", No);
            var paramReason = new SqlParameter("pReason", Reason);

            

            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductiontwo_Edit   @pFqId2,@pHeatNo,@pInsertCorner,@pItemNo,@pNoofPcs,@pWeightInKg,@pRejectionPcs,@pNo,@pReason",
                                                ReturnValueParam, paramFqId2, paramHeatNo, paramInsertCorner, paramItemNo, paramNoofPcs, paramWeightInKg, paramRejectionPcs, paramNo, paramReason);

                    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 List<DailyFoundryproductiontwo> DailyFoundryproductiontwo_GetAll(int FqId2, int FpId)
        {
            var paramFqId2 = new SqlParameter("pFqId2", FqId2);
            var paramFpId = new SqlParameter("pFpId", FpId);


            return this.Database.SqlQuery<DailyFoundryproductiontwo>(
                            "Sp_DailyFoundayProductiontwo_Getall @pFqId2,@pFpId",
                            paramFqId2, paramFpId).ToList();
        }

        

        public virtual int DailyFoundlyProductionthree_AddNew(int FpId, string HeatNo, string DgasStartTime, string DgasEndTime,ref string errorDesc)
        {
            errorDesc = "";

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



            var paramFpId = new SqlParameter("pFpId", FpId);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramDgasStartTime = new SqlParameter("pDgasStartTime", DgasStartTime);
            var paramDgasEndTime = new SqlParameter("pDgasEndTime", DgasEndTime);



            


            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductionthree_AddNew   @pFpId,@pHeatNo,@pDgasStartTime,@pDgasEndTime",
                                                ReturnValueParam, paramFpId, paramHeatNo, paramDgasStartTime, paramDgasEndTime);

                    errorNo = Convert.ToInt32(ReturnValueParam.Value);


                    FpId = Convert.ToInt32(paramFpId.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 DailyFoundlyProductionthree_Edit(int Id, string HeatNo, string DgasStartTime, string DgasEndTime, ref string errorDesc)
        {
            errorDesc = "";

            var ReturnValueParam = new SqlParameter("@ReturnValue", System.Data.SqlDbType.Int);
            ReturnValueParam.Direction = System.Data.ParameterDirection.Output;
            
            var paramId = new SqlParameter("pId", Id);
            var paramHeatNo = new SqlParameter("pHeatNo", HeatNo);
            var paramDgasStartTime = new SqlParameter("pDgasStartTime", DgasStartTime);
            var paramDgasEndTime = new SqlParameter("pDgasEndTime", DgasEndTime);
            
            var dbContext = this.Database;

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

                try
                {
                    dbContext.ExecuteSqlCommand("Exec @ReturnValue = Sp_DailyFoundayProductionthree_Edit   @pId,@pHeatNo,@pDgasStartTime,@pDgasEndTime",
                                                ReturnValueParam, paramId, paramHeatNo, paramDgasStartTime, paramDgasEndTime);

                    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 List<DailyFoundryproductionthree> DailyFoundryproductionthree_GetAll(int Id, int FpId)
        {
            var paramId = new SqlParameter("pId", Id);
            var paramFpId = new SqlParameter("pFpId", FpId);

            return this.Database.SqlQuery<DailyFoundryproductionthree>(
                            "Sp_DailyFoundayProductionthree_Getall @pId,@pFpId",
                            paramId, paramFpId).ToList();
        }





    }
}