Esempio n. 1
0
 public bool ThemGhe(GheDTO ghe)
 {
     try
     {
         using (var context = new QLRPContext())
         {
             foreach (var g in context.Ghes.Select(p => p).ToList())
             {
                 if (g.MaPhong == ghe.MaPhong && g.TenGhe == ghe.TenGhe)
                 {
                     throw new Exception($"Ghế {ghe.TenGhe} đã tồn tại trong phòng {ghe.TenPhong} rồi.");
                 }
             }
             context.Ghes.Add(new Ghe
             {
                 TenGhe   = ghe.TenGhe,
                 NgayTao  = DateTime.Now,
                 NguoiTao = CurrentUser.Username,
                 NgaySua  = DateTime.Now,
                 NguoiSua = CurrentUser.Username,
                 MaPhong  = ghe.MaPhong
             });
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 2
0
        public List <GheDTO> LoadGhe()
        {
            SqlConnection conn       = DataProvider.TaoKetNoi();
            string        strTruyVan = "Select * From Ghe where TrangThai=1";
            SqlDataReader sdr        = DataProvider.TruyVanDuLieu(strTruyVan, conn);
            List <GheDTO> ls         = new List <GheDTO>();

            while (sdr.Read())
            {
                GheDTO ketqua = new GheDTO();
                ketqua.MaGhe     = sdr["MaGhe"].ToString();
                ketqua.MaPhong   = int.Parse(sdr["MaPhong"].ToString());
                ketqua.TrangThai = int.Parse(sdr["TrangThai"].ToString());
                ls.Add(ketqua);
            }
            sdr.Close();
            conn.Close();
            return(ls);
        }
Esempio n. 3
0
 public bool UpdateGhe(GheDTO ghe)
 {
     try
     {
         using (var context = new QLRPContext())
         {
             var ghe_update = context.Ghes.SingleOrDefault(p => p.MaGhe == ghe.MaGhe);
             if (ghe_update != null)
             {
                 if (Utils.ValidateRowversion(ghe_update.RowVersion, ghe.RowVersion))
                 {
                     foreach (var g in context.Ghes.Select(p => p).ToList())
                     {
                         if (g.MaPhong == ghe.MaPhong && g.TenGhe == ghe.TenGhe)
                         {
                             throw new Exception($"Ghế {ghe.TenGhe} đã tồn tại trong phòng {ghe.TenPhong} rồi.");
                         }
                     }
                     ghe_update.TenGhe   = ghe.TenGhe;
                     ghe_update.MaPhong  = ghe.MaPhong;
                     ghe_update.NguoiSua = CurrentUser.Username;
                     ghe_update.NgaySua  = DateTime.Now;
                     context.SaveChanges();
                     return(true);
                 }
                 throw new Exception("Có ai đó đã update đối tượng này trước đó. Danh sách sẽ được load lại.");
             }
             throw new Exception("Không tìm thấy ghế!");
         }
     }
     catch (DbUpdateConcurrencyException)
     {
         throw new Exception("Hiện tại, có ai đó cũng đang update đối tượng này. Danh sách sẽ được load lại.");
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 4
0
        public List <GheDTO> LoadGhe(int MaPhong)
        {
            SqlConnection conn       = DataProvider.TaoKetNoi();
            string        strTruyVan = "Select * From Ghe where TrangThai=1 AND MaPhong = @MaPhong ORDER BY len(MaGhe), MaGhe";

            SqlParameter[] par = new SqlParameter[1];
            par[0] = new SqlParameter("@MaPhong", MaPhong);
            SqlDataReader sdr = DataProvider.TruyVanDuLieu(strTruyVan, par, conn);
            List <GheDTO> ls  = new List <GheDTO>();

            while (sdr.Read())
            {
                GheDTO ketqua = new GheDTO();
                ketqua.MaGhe     = sdr["MaGhe"].ToString();
                ketqua.MaPhong   = int.Parse(sdr["MaPhong"].ToString());
                ketqua.TrangThai = int.Parse(sdr["TrangThai"].ToString());
                ls.Add(ketqua);
            }
            sdr.Close();
            conn.Close();
            return(ls);
        }
Esempio n. 5
0
        public List <GheDTO> getGheStatusByTripID(string tripID)
        {
            List <GheDTO> gheDTOs = new List <GheDTO>();

            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@machuyenxe", tripID)
            };
            DataTable dt = new DataTable();

            dt = DataProvider.Instance.GetData("sp_getStatusSeatByTripId", parameters);
            foreach (DataRow dr in dt.Rows)
            {
                GheDTO gheDTO = new GheDTO();
                gheDTO.maghe  = dr["maghe"].ToString();
                gheDTO.status = int.Parse(dr["trangthai"].ToString());
                gheDTO.vitriX = int.Parse(dr["vitriX"].ToString());
                gheDTO.vitriY = int.Parse(dr["vitriY"].ToString());
                gheDTO.tang   = int.Parse(dr["tang"].ToString());
                gheDTO.status = int.Parse(dr["trangthai"].ToString());
                gheDTOs.Add(gheDTO);
            }
            return(gheDTOs);
        }
Esempio n. 6
0
        public XeDTO getSchemaCar1(string carID, string tripID)
        {
            XeDTO xeDTO = new XeDTO();

            xeDTO.floor1 = new List <GheDTO>();
            xeDTO.floor2 = new List <GheDTO>();
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@maxe", carID)
            };
            DataTable dt = new DataTable();

            dt = DataProvider.Instance.GetData("sp_getSechemaCar", parameters);

            //init defalut value
            int sohang = 7;
            int soghe  = 35;
            int socot  = 5;

            foreach (DataRow dr in dt.Rows)
            {
                GheDTO gheDTO = new GheDTO();
                gheDTO.maghe    = dr["maghe"].ToString();
                gheDTO.vitriX   = int.Parse(dr["vitriX"].ToString());
                gheDTO.vitriY   = int.Parse(dr["vitriY"].ToString());
                gheDTO.tang     = int.Parse(dr["tang"].ToString());
                gheDTO.isActive = bool.Parse(dr["active"].ToString());
                gheDTO.tenghe   = dr["tenghe"].ToString();
                gheDTO.status   = 0;
                ////////////////
                ///

                int.TryParse(dr["sohang"].ToString(), out sohang);

                int.TryParse(dr["socot"].ToString(), out socot);
                xeDTO.socot  = socot;
                xeDTO.sohang = sohang;
                xeDTO.maxe   = carID;

                int.TryParse(dr["soghe"].ToString(), out soghe);
                xeDTO.soghe = soghe;
                if (gheDTO.tang == 1)
                {
                    xeDTO.floor1.Add(gheDTO);
                }
                else if (gheDTO.tang == 2)
                {
                    xeDTO.floor2.Add(gheDTO);
                }
            }
            List <GheDTO> listTrangThaiGhe = getGheStatusByTripID(tripID);

            foreach (GheDTO ghe in listTrangThaiGhe)
            {
                if (ghe.status == 1)
                {
                    GheDTO ghe1 = xeDTO.floor1.SingleOrDefault(p => p.maghe == ghe.maghe);
                    GheDTO ghe2 = xeDTO.floor2.SingleOrDefault(p => p.maghe == ghe.maghe);
                    if (ghe1 != null)
                    {
                        xeDTO.floor1.Single(p => p.maghe == ghe.maghe).status = 1;
                    }
                    else if (ghe2 != null)
                    {
                        xeDTO.floor2.Single(p => p.maghe == ghe.maghe).status = 1;
                    }
                }
            }
            return(xeDTO);
        }