private void Populate(Int32 slipidno)
        {
            LorryHireDAL     obj1 = new LorryHireDAL();
            tblLorryHireSlip obj  = obj1.SelectById(slipidno);


            if (obj != null)
            {
                hidlorryhireidno.Value     = Convert.ToString(obj.LryHire_Idno);
                ddlDateRange.SelectedValue = Convert.ToString(obj.Year_Idno);
                ddlDateRange_SelectedIndexChanged(null, null);
                ddlDateRange.Enabled      = false;
                txtslipdate.Text          = Convert.ToDateTime(obj.Lry_Date).ToString("dd-MM-yyyy");
                txtslipno.Text            = Convert.ToString(obj.Lry_SlipNo);
                ddlFromCity.SelectedValue = Convert.ToString(obj.Loc_Idno);
                ddllorryno.SelectedValue  = Convert.ToString(obj.Lry_Idno);

                ddllorryno_SelectedIndexChanged(null, null);
                txtsupliedby.Text        = Convert.ToString(obj.SupliedTo);
                txtfreight.Text          = Convert.ToDouble(obj.TotalFrghtAmnt).ToString("N2");
                txtadvance.Text          = Convert.ToDouble(obj.AdvanceAmnt).ToString("N2");
                txtnetamnt.Text          = Convert.ToDouble(obj.Net_amnt).ToString("N2");
                txtremark.Text           = Convert.ToString(obj.Remark);
                txtothercharges.Text     = Convert.ToDouble(obj.OtherCharges).ToString("N2");
                txtUnloading.Text        = Convert.ToDouble(obj.Unloading).ToString("N2");
                txtDetectionCharges.Text = Convert.ToDouble(obj.DetectionCharges).ToString("N2");
                txtDiesel.Text           = Convert.ToDouble(obj.Diesel).ToString("N2");
                txtTds.Text = Convert.ToDouble(obj.TDS).ToString("N2");
            }
            DtTemp          = obj1.selectDetl(ApplicationFunction.ConnectionString(), Convert.ToInt32(ddlDateRange.SelectedValue), slipidno);
            obj1            = null;
            ViewState["dt"] = DtTemp;
            this.BindGrid();
        }
        //Insert
        public Int64 Insert(Int64 Slipno, DateTime?Lorry_Date, Int64 Loc_Idno, Int64 Truck_Idno, string strsupllyby, Int64 Year_Idno, Double totlfrghtamnt, Double advanceamnt, Double netamnt, DateTime?Date_Added, string strremarks, Double othercharg, Double unloading, Double detentioncharg, Double diesel, Double TDS, DataTable Dttemp)
        {
            Int64 LorryHire_Idno = 0;

            using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
            {
                try
                {
                    tblLorryHireSlip objlorry = db.tblLorryHireSlips.Where(slipno => (slipno.Lry_Idno == Truck_Idno) && (slipno.Year_Idno == Year_Idno) && (slipno.Loc_Idno == Loc_Idno)).FirstOrDefault();
                    if (objlorry == null)
                    {
                        objlorry                  = new tblLorryHireSlip();
                        objlorry.Lry_SlipNo       = Slipno;
                        objlorry.Lry_Date         = Lorry_Date;
                        objlorry.Loc_Idno         = Loc_Idno;
                        objlorry.Lry_Idno         = Truck_Idno;
                        objlorry.SupliedTo        = strsupllyby;
                        objlorry.Year_Idno        = Year_Idno;
                        objlorry.Date_Added       = Date_Added;
                        objlorry.TotalFrghtAmnt   = totlfrghtamnt;
                        objlorry.AdvanceAmnt      = advanceamnt;
                        objlorry.Net_amnt         = netamnt;
                        objlorry.Remark           = strremarks;
                        objlorry.OtherCharges     = othercharg;
                        objlorry.Unloading        = unloading;
                        objlorry.DetectionCharges = detentioncharg;
                        objlorry.Diesel           = diesel;
                        objlorry.TDS              = TDS;
                        db.tblLorryHireSlips.AddObject(objlorry);
                        db.SaveChanges();
                        LorryHire_Idno = objlorry.LryHire_Idno;
                        if (Dttemp.Rows.Count > 0)
                        {
                            foreach (DataRow Dr in Dttemp.Rows)
                            {
                                tblLorryHireSlipGRDetl objHireSlipDetl = new tblLorryHireSlipGRDetl();
                                objHireSlipDetl.LryHire_Idno = LorryHire_Idno;
                                objHireSlipDetl.GR_Idno      = Convert.ToInt32(Dr["Gr_Idno"]);
                                db.tblLorryHireSlipGRDetls.AddObject(objHireSlipDetl);
                                db.SaveChanges();
                            }
                        }
                    }
                    else
                    {
                        return(LorryHire_Idno);
                    }
                }
                catch (Exception ex)
                {
                    return(-1);
                }
                return(LorryHire_Idno);
            }
        }
        //
        /// <summary>
        /// Delete record from ItemMast
        /// </summary>
        /// <param name="intItemIdno"></param>
        /// <returns></returns>
        public int Delete(int intSlipIdno)
        {
            int intValue = 0;

            try
            {
                using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
                {
                    tblLorryHireSlip objLrySlip = (from mast in db.tblLorryHireSlips
                                                   where mast.LryHire_Idno == intSlipIdno
                                                   select mast).FirstOrDefault();
                    if (objLrySlip != null)
                    {
                        db.tblLorryHireSlips.DeleteObject(objLrySlip);
                        db.SaveChanges();
                        intValue = 1;
                    }
                    tblLorryHireSlipGRDetl objLrydetl = (from mast in db.tblLorryHireSlipGRDetls
                                                         where mast.LryHire_Idno == intSlipIdno
                                                         select mast).FirstOrDefault();
                    if (objLrydetl != null)
                    {
                        db.tblLorryHireSlipGRDetls.DeleteObject(objLrydetl);
                        db.SaveChanges();
                        intValue = 1;
                    }
                }
            }
            catch (Exception Ex)
            {
                if (Convert.ToBoolean(Ex.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) == true)
                {
                    intValue = -1;
                }
            }
            return(intValue);
        }
        //Update
        public Int64 Update(Int64 lorryhireIdno, Int64 Slipno, DateTime?Lorry_Date, Int64 Loc_Idno, Int64 Truck_Idno, string strsupllyby, Int64 Year_Idno, Double totlfrghtamnt, Double advanceamnt, Double netamnt, DateTime?Date_Modified, string strremarks, Double othercharg, Double unloading, Double detentioncharg, Double diesel, Double TDS, DataTable Dttemp)
        {
            Int64 LorryHire_Idno = 0;

            using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
            {
                try
                {
                    tblLorryHireSlip objlorryupdate = db.tblLorryHireSlips.Where(rh => rh.LryHire_Idno == lorryhireIdno).FirstOrDefault();
                    if (objlorryupdate != null)
                    {
                        objlorryupdate.Lry_SlipNo       = Slipno;
                        objlorryupdate.Lry_Date         = Lorry_Date;
                        objlorryupdate.Loc_Idno         = Loc_Idno;
                        objlorryupdate.Lry_Idno         = Truck_Idno;
                        objlorryupdate.SupliedTo        = strsupllyby;
                        objlorryupdate.Year_Idno        = Year_Idno;
                        objlorryupdate.Date_Modified    = Date_Modified;
                        objlorryupdate.TotalFrghtAmnt   = totlfrghtamnt;
                        objlorryupdate.AdvanceAmnt      = advanceamnt;
                        objlorryupdate.Remark           = strremarks;
                        objlorryupdate.Net_amnt         = netamnt;
                        objlorryupdate.OtherCharges     = othercharg;
                        objlorryupdate.Unloading        = unloading;
                        objlorryupdate.DetectionCharges = detentioncharg;
                        objlorryupdate.Diesel           = diesel;
                        objlorryupdate.TDS = TDS;
                        db.SaveChanges();
                        LorryHire_Idno = objlorryupdate.LryHire_Idno;

                        List <tblLorryHireSlipGRDetl> HireLorryDetl = db.tblLorryHireSlipGRDetls.Where(rd => rd.LryHire_Idno == LorryHire_Idno).ToList();
                        foreach (tblLorryHireSlipGRDetl rgd in HireLorryDetl)
                        {
                            db.tblLorryHireSlipGRDetls.DeleteObject(rgd);
                            db.SaveChanges();
                        }
                        if (Dttemp.Rows.Count > 0)
                        {
                            foreach (DataRow Dr in Dttemp.Rows)
                            {
                                tblLorryHireSlipGRDetl objHireSlipDetl = new tblLorryHireSlipGRDetl();
                                objHireSlipDetl.LryHire_Idno = LorryHire_Idno;
                                objHireSlipDetl.GR_Idno      = Convert.ToInt32(Dr["Gr_Idno"]);
                                db.tblLorryHireSlipGRDetls.AddObject(objHireSlipDetl);
                                db.SaveChanges();
                            }
                            //  dbTran.Commit();
                        }
                    }

                    else
                    {
                        LorryHire_Idno = -1;
                    }
                }
                catch (Exception ex)
                {
                    LorryHire_Idno = 0;
                }
                return(LorryHire_Idno);
            }
        }