Ejemplo n.º 1
0
        public Int64 Insert(tblChlnBookHead obj, DataTable Dttemp, string GrHeadsIdno)
        {
            Int64 chlnBookId = 0;

            using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
            {
                tblChlnBookHead CHead = new tblChlnBookHead();

                tblChlnBookHead RH = db.tblChlnBookHeads.Where(rh => (rh.Chln_No == obj.Chln_No) && (rh.Year_Idno == obj.Year_Idno) && (rh.BaseCity_Idno == obj.BaseCity_Idno) && rh.Chln_type == 2).FirstOrDefault();
                if (RH != null)
                {
                    chlnBookId = -1;
                }
                else
                {
                    db.tblChlnBookHeads.AddObject(obj);
                    db.SaveChanges();
                    chlnBookId = obj.Chln_Idno;
                    string[] GrIdnos = GrHeadsIdno.Split(new string[] { "," }, StringSplitOptions.None);
                    if (Dttemp.Rows.Count > 0)
                    {
                        for (int i = 0; i < Dttemp.Rows.Count; i++)
                        {
                            tblChlnBookDetl objtblChlnBookDetl = new tblChlnBookDetl();
                            objtblChlnBookDetl.GR_Idno           = Convert.ToInt32(GrIdnos[i + 1]);
                            objtblChlnBookDetl.DelvryPlce_Idno   = Convert.ToInt32(Dttemp.Rows[i]["ToCityIdno"]);
                            objtblChlnBookDetl.ChlnBookHead_Idno = chlnBookId;
                            db.tblChlnBookDetls.AddObject(objtblChlnBookDetl);
                            db.SaveChanges();
                        }
                    }
                    if (Dttemp.Rows.Count > 0)
                    {
                        for (int i = 0; i < Dttemp.Rows.Count; i++)
                        {
                            Int32 GrIdno = 0;
                            GrIdno = Convert.ToInt32(GrIdnos[i + 1]);
                            TblGrHead objTblGrHead = (from obj1 in db.TblGrHeads where obj1.GR_Idno == GrIdno select obj1).FirstOrDefault();
                            objTblGrHead.Chln_Idno = chlnBookId;
                            db.SaveChanges();
                        }
                    }
                }
            }
            return(chlnBookId);
        }
        public Int64 Update(DataTable ChallanBookDetl, Int32 Chlnidno)
        {
            Int64 ChallanBookHeadId = 0;

            using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
            {
                db.Connection.Open();
                using (DbTransaction dbTran = db.Connection.BeginTransaction())
                {
                    try
                    {
                        List <tblChlnBookDetl> rcptdetl = db.tblChlnBookDetls.Where(rd => rd.ChlnBookHead_Idno == Chlnidno).ToList();
                        //foreach (tblChlnBookDetl rgd in rcptdetl)
                        //{
                        //    db.tblChlnBookDetls.DeleteObject(rgd);
                        //    db.SaveChanges();
                        //}
                        tblChlnBookDetl obj = new tblChlnBookDetl();
                        foreach (DataRow rgd in ChallanBookDetl.Rows)
                        {
                            if (Convert.ToBoolean(rgd["Delivered"]) == true)
                            {
                                obj.Delivered   = Convert.ToBoolean(rgd["Delivered"]);
                                obj.Delvry_Date = Convert.ToDateTime((rgd["Delvry_Date"]));
                                obj.Shrtg       = Convert.ToBoolean(rgd["Shrtg"]);
                                obj.remark      = Convert.ToString(rgd["remark"]);
                                db.SaveChanges();
                            }
                        }
                        dbTran.Commit();
                    }

                    catch
                    {
                        dbTran.Rollback();
                    }
                }

                return(ChallanBookHeadId);
            }
        }
Ejemplo n.º 3
0
        public Int64 Update(tblChlnBookHead obj, Int32 ChlnIdno, DataTable Dttemp, string GrHeadsIdno)
        {
            Int64 chlnBoookId = 0;

            using (TransportMandiEntities db = new TransportMandiEntities(MultipleDBDAL.strDynamicConString()))
            {
                db.Connection.Open();
                using (DbTransaction dbTran = db.Connection.BeginTransaction())
                {
                    try
                    {
                        tblChlnBookHead CH = db.tblChlnBookHeads.Where(rh => rh.Chln_No == obj.Chln_No && (rh.Chln_Idno != ChlnIdno) && (rh.Year_Idno == obj.Year_Idno) && (rh.BaseCity_Idno == obj.BaseCity_Idno) && (rh.Chln_type == 2)).FirstOrDefault();
                        if (CH != null)
                        {
                            chlnBoookId = -1;
                        }
                        else
                        {
                            tblChlnBookHead TBH = db.tblChlnBookHeads.Where(rh => rh.Chln_Idno == ChlnIdno).FirstOrDefault();
                            if (TBH != null)
                            {
                                TBH.Chln_No        = obj.Chln_No;
                                TBH.Chln_Date      = obj.Chln_Date;
                                TBH.BaseCity_Idno  = obj.BaseCity_Idno;
                                TBH.DelvryPlc_Idno = obj.DelvryPlc_Idno;
                                TBH.Truck_Idno     = obj.Truck_Idno;
                                TBH.Year_Idno      = obj.Year_Idno;
                                TBH.Chln_type      = obj.Chln_type;
                                TBH.Driver_Idno    = obj.Driver_Idno;
                                TBH.Delvry_Instrc  = obj.Delvry_Instrc;
                                TBH.Inv_Idno       = obj.Inv_Idno;
                                TBH.Gross_Amnt     = obj.Gross_Amnt;
                                TBH.Commsn_Amnt    = obj.Commsn_Amnt;
                                TBH.Other_Amnt     = obj.Other_Amnt;
                                TBH.Net_Amnt       = obj.Net_Amnt;
                                TBH.Work_type      = obj.Work_type;
                                TBH.Adv_Amnt       = obj.Adv_Amnt;
                                TBH.RcptType_Idno  = obj.RcptType_Idno;
                                TBH.Inst_No        = obj.Inst_No;
                                TBH.Inst_Dt        = obj.Inst_Dt;
                                TBH.Bank_Idno      = obj.Bank_Idno;
                                db.SaveChanges();
                                chlnBoookId = TBH.Chln_Idno;
                                List <tblChlnBookDetl> ChlnDetl = db.tblChlnBookDetls.Where(rd => rd.ChlnBookHead_Idno == ChlnIdno).ToList();
                                foreach (tblChlnBookDetl rgd in ChlnDetl)
                                {
                                    db.tblChlnBookDetls.DeleteObject(rgd);
                                    db.SaveChanges();
                                }
                                //foreach (tblChlnBookDetl rgd in ChlnDetl)
                                //{
                                //    rgd.ChlnBookHead_Idno = chlnBoookId;
                                //    db.tblChlnBookDetls.AddObject(rgd);
                                //    db.SaveChanges();
                                //}

                                string[] GrIdnos = GrHeadsIdno.Split(new string[] { "," }, StringSplitOptions.None);
                                if (Dttemp.Rows.Count > 0)
                                {
                                    for (int i = 0; i < Dttemp.Rows.Count; i++)
                                    {
                                        tblChlnBookDetl objtblChlnBookDetl = new tblChlnBookDetl();
                                        objtblChlnBookDetl.GR_Idno           = Convert.ToInt32(GrIdnos[i + 1]);
                                        objtblChlnBookDetl.DelvryPlce_Idno   = Convert.ToInt32(Dttemp.Rows[i]["ToCityIdno"]);
                                        objtblChlnBookDetl.ChlnBookHead_Idno = ChlnIdno;
                                        db.tblChlnBookDetls.AddObject(objtblChlnBookDetl);
                                        db.SaveChanges();
                                    }
                                }
                                if (Dttemp.Rows.Count > 0)
                                {
                                    for (int i = 0; i < Dttemp.Rows.Count; i++)
                                    {
                                        Int32 GrIdno = 0;
                                        GrIdno = Convert.ToInt32(GrIdnos[i + 1]);
                                        TblGrHead objTblGrHead = (from obj1 in db.TblGrHeads where obj1.GR_Idno == GrIdno select obj1).FirstOrDefault();
                                        objTblGrHead.Chln_Idno = ChlnIdno;
                                        db.SaveChanges();
                                    }
                                }
                                dbTran.Commit();
                            }
                        }
                    }
                    catch
                    {
                        dbTran.Rollback();
                    }
                }
            }
            return(chlnBoookId);
        }