Ejemplo n.º 1
0
 public bool Insert(LichChieu item)
 {
     try
     {
         db.LichChieux.Add(item);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
 public bool Edit(LichChieu item)
 {
     try
     {
         var dbEntry = db.LichChieux.SingleOrDefault(x => x.ID == item.ID);
         dbEntry.PhongChieuID    = item.PhongChieuID;
         dbEntry.ThoiGianBatDau  = item.ThoiGianBatDau;
         dbEntry.ThoiGianKetThuc = item.ThoiGianKetThuc;
         dbEntry.GiaVe           = item.GiaVe;
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
        public async Task <object> TaoLichChieu(LichChieuInsertVM lichChieuInsert)
        {
            var connection = new SqlConnection(connectionString);

            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
            Phim phim = connection.QuerySingleOrDefault <Phim>("SELECT * FROM [dbo].[PHIM] WHERE MaPhim = " + lichChieuInsert.MaPhim, commandType: CommandType.Text);

            if (phim == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã phim không hợp lệ!"));
            }

            LichChieu lichModel = new LichChieu();

            //DateTime temp;
            //try
            //{
            //    if (DateTime.TryParse(lichChieuInsert.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lichChieuInsert.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !");
            //}
            lichModel.NgayChieuGioChieu = lichChieuInsert.NgayChieuGioChieu;

            Rap kiemTraRap = connection.QuerySingleOrDefault <Rap>("SELECT * FROM [dbo].[RAP] WHERE MaRap = " + lichChieuInsert.MaRap, commandType: CommandType.Text);

            if (kiemTraRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !"));
            }

            CumRap kiemTraCumRap = connection.QuerySingleOrDefault <CumRap>("SELECT * FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + kiemTraRap.MaCumRap + "'", commandType: CommandType.Text);

            if (kiemTraCumRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã cụm rạp không tồn tại !"));
            }

            HeThongRap kiemTraHeThongRap = connection.QuerySingleOrDefault <HeThongRap>("SELECT * FROM [dbo].[HETHONGRAP] WHERE MaHeThongRap = '" + kiemTraCumRap.MaHeThongRap + "'", commandType: CommandType.Text);

            if (kiemTraHeThongRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã hệ thống rạp không tồn tại !"));
            }

            var listLichChieu    = connection.Query <LichChieu>("SELECT * FROM [dbo].[View_LICH_CHIEU_COMMON]", commandType: CommandType.Text);
            var kiemTraLichChieu = listLichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == phim.MaPhim && n.MaCumRap == kiemTraCumRap.MaCumRap && n.MaHeThongRap == kiemTraHeThongRap.MaHeThongRap && n.MaRap == lichChieuInsert.MaRap);
            //Trường hợp thời gian bắt đầu + thời lượng phim

            int      count      = 0;
            DateTime tgBDInsert = lichChieuInsert.NgayChieuGioChieu;
            DateTime tgKTInsert = lichChieuInsert.NgayChieuGioChieu.AddMinutes(phim.ThoiLuong);

            foreach (LichChieu lc in listLichChieu)
            {
                DateTime thoiGianBatDau  = lc.NgayChieuGioChieu;
                DateTime thoiGianKetThuc = lc.NgayChieuGioChieu.AddMinutes(phim.ThoiLuong);
                if (lichChieuInsert.MaRap == lc.MaRap)
                {
                    if ((tgBDInsert == thoiGianBatDau && tgKTInsert == thoiGianKetThuc) || (tgBDInsert > thoiGianBatDau && tgBDInsert < thoiGianKetThuc) || (tgKTInsert > thoiGianBatDau && tgKTInsert < thoiGianKetThuc) || tgBDInsert == thoiGianKetThuc || tgKTInsert == thoiGianBatDau)
                    {
                        count = count + 1;
                    }
                }
            }

            if (count > 0)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng !"));
            }

            //if (lichChieuInsert.GiaVe > 200000 || lichChieuInsert.GiaVe <= 45000)
            //{
            //    return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Giá từ 45.000 - 200.000");
            //}
            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            var param = new DynamicParameters();

            param.Add("@MARAP", lichChieuInsert.MaRap);
            param.Add("@MAPHIM", lichChieuInsert.MaPhim);
            param.Add("@NGAYCHIEUGIOCHIEU", lichModel.NgayChieuGioChieu);
            param.Add("@GIAVE", lichChieuInsert.GiaVe);
            param.Add("@GIAMGIA", lichChieuInsert.GiamGia);

            await connection.QueryAsync("LICH_CHIEU_INSERT", param, commandType : CommandType.StoredProcedure);

            return("Thêm lịch chiếu thành công !");
            //return tgKTInsert;
        }
Ejemplo n.º 4
0
        //Lấy danh sách phòng vé
        public async Task <object> LayDanhSachPhongVe(int maLichChieu)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                if (connection.State == ConnectionState.Closed)
                {
                    connection.Open();
                }
                if (maLichChieu == 0)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã lịch chiếu không hợp lệ!"));
                }
                LichChieu lichChieu = connection.QuerySingleOrDefault <LichChieu>("SELECT * FROM [dbo].[View_LICH_CHIEU_COMMON] " +
                                                                                  "WHERE MaLichChieu = " + maLichChieu, commandType: CommandType.Text);
                if (lichChieu == null)
                {
                    return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã lịch chiếu không tồn tại!"));
                }
                decimal giaVe = lichChieu.GiaVe;

                var listDanhSachGheDuocDat = connection.Query <Ve>("SELECT * FROM [dbo].[VE] " +
                                                                   "WHERE MaLichChieu = " + maLichChieu, commandType: CommandType.Text);

                bool flag = false;

                LichChieuTheoRapViewModel rap     = new LichChieuTheoRapViewModel();
                List <GheTheoHangVM>      listGhe = new List <GheTheoHangVM>();
                int?MaRap = lichChieu.MaRap;

                IEnumerable <Ghe>       listGheTheoRap = connection.Query <Ghe>("SELECT * FROM [dbo].[GHE] WHERE MaRap = " + lichChieu.MaRap, commandType: CommandType.Text);
                IEnumerable <LoaiGhe>   listLoaiGhe    = connection.Query <LoaiGhe>("SELECT * FROM dbo.LOAIGHE", commandType: CommandType.Text);
                IEnumerable <ThanhVien> listThanhVien  = connection.Query <ThanhVien>("SELECT * FROM dbo.THANHVIEN", commandType: CommandType.Text);
                IEnumerable <ThanhToan> listThanhToan  = connection.Query <ThanhToan>("SELECT * FROM dbo.PHIEUTHANHTOAN", commandType: CommandType.Text);

                foreach (var phongRap in listGheTheoRap.GroupBy(n => new { n.TenHang })) //Lấy ra rạp đang chiếu
                {
                    GheTheoHangVM gheTheoHang = new GheTheoHangVM();
                    gheTheoHang.TenHang = phongRap.Key.TenHang;
                    foreach (var pr in phongRap)
                    {
                        flag = false;
                        GheViewModel ghe     = new GheViewModel();
                        LoaiGhe      loaiGhe = new LoaiGhe();
                        loaiGhe   = listLoaiGhe.Single(n => n.MaLoaiGhe == pr.MaLoaiGhe);
                        ghe.MaRap = pr.MaRap;
                        // (phongRap.MaLoaiGheNavigation.ChietKhau * giaVe) / 100 +
                        int phuThu = loaiGhe.PhuThu;
                        ghe.GiaVe   = (phuThu * giaVe) / 100 + giaVe;
                        ghe.LoaiGhe = loaiGhe.TenLoaiGhe;
                        ghe.MaGhe   = pr.MaGhe;
                        ghe.TenGhe  = pr.TenGhe;
                        ghe.STT     = pr.SoThuTu;
                        ghe.PhuThu  = phuThu;
                        foreach (var rapDatVe in listDanhSachGheDuocDat) //Lấy ra danh sách ghế được đặt
                        {
                            //ghe.TaiKhoanNguoiDat= connection.QuerySingleOrDefault<string>("SELECT TaiKhoan FROM [dbo].[THANHVIEN] WHERE TaiKhoan = '" + rapDatVe.TaiKhoan + "'", commandType: CommandType.Text);

                            if (pr.MaGhe == rapDatVe.MaGhe && !rapDatVe.TrangThaiHuy)
                            {
                                ThanhToan thanhToan = listThanhToan.Single(n => n.MaThanhToan == rapDatVe.MaThanhToan);
                                ThanhVien tv        = listThanhVien.Single(n => n.MaThanhVien == thanhToan.MaThanhVien);
                                ghe.TaiKhoanNguoiDat = tv.TaiKhoan;
                                flag = true;
                            }
                        }
                        if (flag == true)
                        {
                            ghe.DaDat = true;
                        }
                        gheTheoHang.DanhSachGheTheoHang.Add(ghe);
                    }
                    listGhe.Add(gheTheoHang);
                }

                rap.DanhSachGhe            = listGhe;
                rap.ThongTinPhim.NgayChieu = lichChieu.NgayChieuGioChieu.ToString("dd/MM/yyyy");
                rap.ThongTinPhim.GioChieu  = lichChieu.NgayChieuGioChieu.ToString("HH:mm");
                //rap.ThongTinPhim.hinhAnh = DomainImage + LichChieu.MaPhimNavigation.HinhAnh;
                rap.ThongTinPhim.MaLichChieu = maLichChieu;
                rap.ThongTinPhim.TenRap      = connection.QuerySingleOrDefault <string>("SELECT TenRap FROM [dbo].[RAP] WHERE MaRap = '" + lichChieu.MaRap + "'", commandType: CommandType.Text);
                rap.ThongTinPhim.TenCumRap   = connection.QuerySingleOrDefault <string>("SELECT TenCumRap FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + lichChieu.MaCumRap + "'", commandType: CommandType.Text);
                rap.ThongTinPhim.DiaChi      = connection.QuerySingleOrDefault <string>("SELECT ThongTin FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + lichChieu.MaCumRap + "'", commandType: CommandType.Text);
                var phim = connection.QuerySingleOrDefault <Phim>("SELECT * FROM [dbo].[PHIM] WHERE MaPhim = '" + lichChieu.MaPhim + "'", commandType: CommandType.Text);
                rap.ThongTinPhim.TenPhim = phim.TenPhim;
                rap.ThongTinPhim.DoTuoi  = phim.DoTuoi;
                return(rap);
            }
        }
        public async Task <object> LayThongTinTaiKhoan(string taiKhoan)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                ThanhVien thanhVien = connection.QuerySingleOrDefault <ThanhVien>("SELECT * FROM dbo.ThanhVien WHERE TaiKhoan = '" + taiKhoan + "'", commandType: CommandType.Text);
                if (thanhVien == null)
                {
                    // I wish to return an error response how can i do that?
                    var response = await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi400, "Tài khoản không hợp lệ!");

                    return(response);
                }

                IEnumerable <Ve>     listDatVe         = connection.Query <Ve>("SELECT * FROM dbo.VE WHERE MaThanhVien = ' " + thanhVien.MaThanhVien + "'", commandType: CommandType.Text);
                List <ThongTinDatVe> listThongTinDatVe = new List <ThongTinDatVe>();

                if (listDatVe.Count() != 0)
                {
                    Ghe ghe = new Ghe();
                    foreach (var item in listDatVe.GroupBy(n => new { n.MaThanhToan }))
                    {
                        //, MaGhe = item.MaGhe, TenGhe = ghe.TenGhe, MaRap = ghe.MaRap, TenRap = rap.TenRap,MaHeThongRap = cumRap.MaHeThongRap,TenHeThongRap = connection.QuerySingleOrDefault("SELECT TenHeThongRap FROM dbo.HETHONGRAP WHERE MaHeThongRap = " + cumRap.MaHeThongRap, commandType: CommandType.Text)
                        ThongTinDatVe thongTinDatVe = new ThongTinDatVe();
                        Rap           rap           = new Rap();
                        CumRap        cumRap        = new CumRap();
                        LichChieu     lichChieu     = new LichChieu();

                        thongTinDatVe.MaThanhToan  = item.Key.MaThanhToan;
                        thongTinDatVe.TrangThaiHuy = connection.QuerySingleOrDefault <bool>("SELECT TrangThaiHuy FROM dbo.THANHTOAN WHERE MaThanhToan = " + item.Key.MaThanhToan, commandType: CommandType.Text);

                        foreach (var CTVe in item)
                        {
                            ThongTinGhe thongTinGhe = new ThongTinGhe();
                            lichChieu = connection.QuerySingleOrDefault <LichChieu>("SELECT * FROM dbo.LICHCHIEU WHERE MaLichChieu = " + CTVe.MaLichChieu, commandType: CommandType.Text);
                            //rap = connection.QuerySingleOrDefault<Rap>("SELECT * FROM dbo.RAP WHERE MaRap = " + lichChieu.MaRap, commandType: CommandType.Text);
                            //cumRap = connection.QuerySingleOrDefault<CumRap>("SELECT * FROM dbo.CUMRAP WHERE MaCumRap = '" + rap.MaCumRap + "'", commandType: CommandType.Text);
                            ghe = await connection.QuerySingleOrDefaultAsync <Ghe>("SELECT * FROM dbo.GHE WHERE MaGhe = " + CTVe.MaGhe, commandType : CommandType.Text);

                            thongTinDatVe.MaLichChieu = CTVe.MaLichChieu;
                            thongTinGhe.MaGhe         = ghe.MaGhe;
                            thongTinGhe.TenGhe        = ghe.TenGhe;
                            thongTinGhe.MaVe          = CTVe.MaVe;
                            thongTinGhe.NgayDat       = CTVe.NgayDat.Value;

                            thongTinDatVe.TenPhim           = connection.QuerySingleOrDefault <string>("SELECT TenPhim FROM dbo.Phim WHERE MaPhim = " + lichChieu.MaPhim, commandType: CommandType.Text);
                            thongTinDatVe.GiaVe             = CTVe.GiaVe.Value;
                            thongTinDatVe.NgayChieuGioChieu = lichChieu.NgayChieuGioChieu;
                            thongTinDatVe.MaRap             = lichChieu.MaRap;
                            thongTinDatVe.TenRap            = connection.QuerySingleOrDefault <string>("SELECT TenRap FROM dbo.Rap WHERE MaRap = " + lichChieu.MaRap, commandType: CommandType.Text);
                            thongTinDatVe.MaHeThongRap      = lichChieu.MaHeThongRap;
                            thongTinDatVe.MaCumRap          = lichChieu.MaCumRap;
                            thongTinDatVe.TenCumRap         = connection.QuerySingleOrDefault <string>("SELECT TenCumRap FROM dbo.CumRap WHERE MaCumRap = '" + lichChieu.MaCumRap + "'", commandType: CommandType.Text);
                            thongTinDatVe.DanhSachGhe.Add(thongTinGhe);
                        }
                        listThongTinDatVe.Add(thongTinDatVe);
                        //thongTinDatVe.ThoiLuongPhim = item.MaLichChieuNavigation.ThoiLuong.Value;
                    }
                }


                //ThongTinTaiKhoanVM ttTK = Mapper.Map<NguoiDung, ThongTinTaiKhoanVM>(tt);
                ThongTinTaiKhoanVM thongTinTaiKhoan = new ThongTinTaiKhoanVM();
                thongTinTaiKhoan.MaThanhVien   = thanhVien.MaThanhVien;
                thongTinTaiKhoan.LoaiNguoiDung = await connection.QuerySingleOrDefaultAsync <string>("SELECT TenLoai FROM dbo.LOAITHANHVIEN WHERE MaLoaiThanhVien = " + thanhVien.MaLoaiThanhVien, commandType : CommandType.Text);

                thongTinTaiKhoan.TaiKhoan       = thanhVien.TaiKhoan;
                thongTinTaiKhoan.MatKhau        = thanhVien.MatKhau;
                thongTinTaiKhoan.HoTen          = thanhVien.HoTen;
                thongTinTaiKhoan.Email          = thanhVien.Email;
                thongTinTaiKhoan.SoDT           = thanhVien.SoDienThoai;
                thongTinTaiKhoan.SoLuongVeDaMua = thanhVien.SoLuongVeMua;
                thongTinTaiKhoan.ThongTinDatVe  = listThongTinDatVe;
                return(thongTinTaiKhoan);
            }
        }
        public async Task <ActionResult> LayDanhSachPhongVe(LichChieuInsert lich)
        {
            Phim p = db.Phim.SingleOrDefault(n => n.MaPhim == lich.MaPhim);

            if (p == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "MaPhim không hợp lệ"));
            }

            LichChieu lichModel = new LichChieu();

            try
            {
                lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            }
            catch (Exception ex)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !"));
            }
            //DateTime temp;
            //try
            //{

            //    if (DateTime.TryParse(lich.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss!");
            //}

            var ckRap = db.Rap.SingleOrDefault(n => n.MaRap == lich.MaRap);

            if (ckRap == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !"));
            }

            var ckCum = db.CumRap.SingleOrDefault(n => n.MaCumRap == ckRap.MaCumRap);

            if (ckCum == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai cụm rạp!"));
            }
            var ckHeThongRap = db.HeThongRap.SingleOrDefault(n => n.MaHeThongRap == ckCum.MaHeThongRap);

            if (ckHeThongRap == null)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai hệ thống rạp!"));
            }
            var lichChieu = db.LichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == p.MaPhim && n.MaCumRap == ckCum.MaCumRap && n.MaHeThongRap == ckHeThongRap.MaHeThongRap && n.MaRap == lich.MaRap);

            if (lichChieu.Count() > 0)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng"));
            }

            if (lich.GiaVe > 200000 || lich.GiaVe < 75000)
            {
                return(await tbl.TBLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000"));
            }



            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            lichModel.MaRap        = lich.MaRap;
            lichModel.MaPhim       = lich.MaPhim;
            lichModel.ThoiLuong    = 120;
            lichModel.MaNhom       = p.MaNhom;
            lichModel.MaHeThongRap = ckHeThongRap.MaHeThongRap;
            lichModel.MaCumRap     = ckCum.MaCumRap;
            lichModel.GiaVe        = lich.GiaVe;
            db.LichChieu.Add(lichModel);
            db.SaveChanges();
            return(Ok("Thêm lịch chiếu thành công!"));
        }
        public async Task <object> TaoLichChieu(LichChieuInsertVM lichChieuInsert)
        {
            var connection = new SqlConnection(connectionString);

            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
            Phim phim = connection.QuerySingleOrDefault <Phim>("SELECT * FROM [dbo].[PHIM] WHERE MaPhim = " + lichChieuInsert.MaPhim, commandType: CommandType.Text);

            if (phim == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã phim không hợp lệ!"));
            }

            LichChieu lichModel = new LichChieu();

            //DateTime temp;
            //try
            //{
            //    if (DateTime.TryParse(lichChieuInsert.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lichChieuInsert.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ (có định dạng dd/MM/yyyy hh:mm:ss) !");
            //}
            lichModel.NgayChieuGioChieu = lichChieuInsert.NgayChieuGioChieu;

            Rap kiemTraRap = connection.QuerySingleOrDefault <Rap>("SELECT * FROM [dbo].[RAP] WHERE MaRap = " + lichChieuInsert.MaRap, commandType: CommandType.Text);

            if (kiemTraRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !"));
            }

            CumRap kiemTraCumRap = connection.QuerySingleOrDefault <CumRap>("SELECT * FROM [dbo].[CUMRAP] WHERE MaCumRap = '" + kiemTraRap.MaCumRap + "'", commandType: CommandType.Text);

            if (kiemTraCumRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã cụm rạp không tồn tại !"));
            }

            HeThongRap kiemTraHeThongRap = connection.QuerySingleOrDefault <HeThongRap>("SELECT * FROM [dbo].[HETHONGRAP] WHERE MaHeThongRap = '" + kiemTraCumRap.MaHeThongRap + "'", commandType: CommandType.Text);

            if (kiemTraHeThongRap == null)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Mã hệ thống rạp không tồn tại !"));
            }

            var listLichChieu    = connection.Query <LichChieu>("SELECT * FROM [dbo].[LICHCHIEU]", commandType: CommandType.Text);
            var kiemTraLichChieu = listLichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == phim.MaPhim && n.MaCumRap == kiemTraCumRap.MaCumRap && n.MaHeThongRap == kiemTraHeThongRap.MaHeThongRap && n.MaRap == lichChieuInsert.MaRap);

            if (kiemTraLichChieu.Count() > 0)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng !"));
            }

            if (lichChieuInsert.GiaVe > 200000 || lichChieuInsert.GiaVe < 75000)
            {
                return(await thongBaoLoi.thongBaoLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000"));
            }
            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            var param = new DynamicParameters();

            param.Add("@MARAP", lichChieuInsert.MaRap);
            param.Add("@MAPHIM", lichChieuInsert.MaPhim);
            param.Add("@NGAYCHIEUGIOCHIEU", lichModel.NgayChieuGioChieu);
            param.Add("@GIAVE", lichChieuInsert.GiaVe);
            param.Add("@MAHETHONGRAP", kiemTraHeThongRap.MaHeThongRap);
            param.Add("@MACUMRAP", kiemTraCumRap.MaCumRap);

            await connection.QueryAsync("LICH_CHIEU_INSERT", param, commandType : CommandType.StoredProcedure);

            return("Thêm lịch chiếu thành công !");
            //return lichModel.NgayChieuGioChieu.Date;
        }
        public async Task <ResponseEntity> TaoLichChieu(LichChieuInsert lich)
        {
            Phim p = db.Phim.SingleOrDefault(n => n.MaPhim == lich.MaPhim);

            if (p == null)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "MaPhim không hợp lệ", MessageConstant.ERROR));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "MaPhim không hợp lệ");
            }

            LichChieu lichModel = new LichChieu();

            try
            {
                lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            }
            catch (Exception ex)
            {
                return(new ResponseEntity(StatusCodeConstants.ERROR_SERVER, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !", MessageConstant.ERROR));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy !");
            }
            //DateTime temp;
            //try
            //{

            //    if (DateTime.TryParse(lich.NgayChieuGioChieu, out temp))
            //    {
            //        lichModel.NgayChieuGioChieu = DateTimes.ConvertDateHour(lich.NgayChieuGioChieu);
            //    }
            //    else
            //    {
            //        return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss !");
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return await tbl.TBLoi(ThongBaoLoi.Loi500, "Ngày chiếu giờ chiếu  không hợp lệ, Ngày chiếu phải có định dạng dd/MM/yyyy hh:mm:ss!");
            //}

            var ckRap = db.Rap.SingleOrDefault(n => n.MaRap == lich.MaRap);

            if (ckRap == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Mã rạp không tồn tại !", MessageConstant.MESSAGE_ERROR_404));
                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Mã rạp không tồn tại !");
            }

            var ckCum = db.CumRap.SingleOrDefault(n => n.MaCumRap == ckRap.MaCumRap);

            if (ckCum == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Chọn sai cụm rạp!", MessageConstant.MESSAGE_ERROR_404));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai cụm rạp!");
            }
            var ckHeThongRap = db.HeThongRap.SingleOrDefault(n => n.MaHeThongRap == ckCum.MaHeThongRap);

            if (ckHeThongRap == null)
            {
                return(new ResponseEntity(StatusCodeConstants.NOT_FOUND, "Chọn sai hệ thống rạp!", MessageConstant.MESSAGE_ERROR_404));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Chọn sai hệ thống rạp!");
            }
            var lichChieu = db.LichChieu.Where(n => n.NgayChieuGioChieu.Date == lichModel.NgayChieuGioChieu.Date && n.MaPhim == p.MaPhim && n.MaCumRap == ckCum.MaCumRap && n.MaHeThongRap == ckHeThongRap.MaHeThongRap && n.MaRap == lich.MaRap);

            if (lichChieu.Count() > 0)
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Lịch chiếu đã bị trùng", MessageConstant.BAD_REQUEST));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Lịch chiếu đã bị trùng");
            }

            if (lich.GiaVe > 200000 || lich.GiaVe < 75000)
            {
                return(new ResponseEntity(StatusCodeConstants.BAD_REQUEST, "Giá từ 75.000 - 200.000", MessageConstant.BAD_REQUEST));

                //return await tbl.TBLoi(ThongBaoLoi.Loi500, "Giá từ 75.000 - 200.000");
            }



            //Lấy mã rạp ngẫu nhiên không có trong lst đó

            lichModel.MaRap        = lich.MaRap;
            lichModel.MaPhim       = lich.MaPhim;
            lichModel.ThoiLuong    = 120;
            lichModel.MaNhom       = p.MaNhom;
            lichModel.MaHeThongRap = ckHeThongRap.MaHeThongRap;
            lichModel.MaCumRap     = ckCum.MaCumRap;
            lichModel.GiaVe        = lich.GiaVe;
            db.LichChieu.Add(lichModel);
            db.SaveChanges();
            return(new ResponseEntity(StatusCodeConstants.OK, "Thêm lịch chiếu thành công!", MessageConstant.MESSAGE_SUCCESS_200));

            //return Ok("Thêm lịch chiếu thành công!");
        }
Ejemplo n.º 9
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (btnThem.Text == "Thêm")
     {
         ClearText();
         btnThem.Text     = "Lưu";
         btnXoa.Text      = "Hủy";
         btnSua.Enabled   = false;
         btnThoat.Enabled = false;
         LockControl(false);
     }
     else
     {
         LichChieu item = new LichChieu();
         try
         {
             item.GiaVe = Convert.ToDecimal(txbGiaVe.Text);
         }
         catch
         {
             MessageBox.Show("Nhập sai giá vé !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         try
         {
             item.ThoiGianBatDau = TimeSpan.Parse(txbTgBatDau.Text);
         }
         catch
         {
             MessageBox.Show("Nhập sai thời gian bắt đầu!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         try
         {
             item.ThoiGianKetThuc = TimeSpan.Parse(txbTgKetThuc.Text);
         }
         catch
         {
             MessageBox.Show("Nhập sai thời gian kết thúc!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         item.NgayChieu    = dtpNgayChieu.Value.Date;
         item.PhimID       = Convert.ToInt32(cboPhim.SelectedValue);
         item.PhongChieuID = Convert.ToInt32(cboPhongChieu.SelectedValue);
         bool res = new LichChieuDAO().Insert(item);
         if (!res)
         {
             MessageBox.Show("Có lỗi xảy ra !", " Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         else
         {
             MessageBox.Show("Thêm thành công!", "Thành công", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadData(dtpNgayChieu.Value.Date);
             btnThem.Text     = "Thêm";
             btnXoa.Text      = "Xóa";
             btnSua.Enabled   = true;
             btnThoat.Enabled = true;
             LockControl(true);
         }
     }
 }