protected void dl_SuatChieuHienTai_PreRender(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            var dsdmsc = (from dmsc in dt.DanhMucSuatChieus
                          select dmsc).OrderBy(dmsc => dmsc.ThoiGianBatDau);

            dl_SuatChieuHienTai.DataSource = dsdmsc;
            dl_SuatChieuHienTai.DataBind();
            int _count = 0;
            foreach (DanhMucSuatChieu dmsc in dsdmsc)
            {
                Label lb = (Label)dl_SuatChieuHienTai.Items[_count].FindControl("lb_ThoiGianBatDau");
                lb.Text = dmsc.ThoiGianBatDau.ToShortTimeString();
                lb.ForeColor = dmsc.TinhTrang ? Color.LightGreen : Color.DarkGray;

                Label lbTT = (Label)dl_SuatChieuHienTai.Items[_count].FindControl("lb_TrangThai");
                lbTT.Text = dmsc.TinhTrang ? "Đang sử dụng" : "Chưa sử dụng";
                lbTT.ForeColor = dmsc.TinhTrang ? Color.Green : Color.Red;

                LinkButton btn = (LinkButton)dl_SuatChieuHienTai.Items[_count].FindControl("btn_ThayDoi");
                btn.Text = dmsc.TinhTrang ? "Ngưng sử dụng" : "Sử dụng";

                LinkButton btnCN = (LinkButton)dl_SuatChieuHienTai.Items[_count].FindControl("btn_CapNhatGia");
                btnCN.CommandName = _count.ToString();
                ++_count;
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     NguoiDung nd = (NguoiDung)Session["NguoiDung"];
     if (nd == null || nd.DanhMucNguoiDung.TenDanhMucNguoiDung != "Admin")
         Response.Redirect("/thanhvien/yeucauquyenadmin.aspx");
 }
 protected void UpdatePanel1_PreRender(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     PhongChieuPhim phong = (PhongChieuPhim)Session["Phong"];
     if (phong != null)
     {
         var query = from ghe in dt.Ghes
                     where ghe.MaPhongChieuPhim == phong.MaPhongChieuPhim
                     select ghe;
         dl_SoDoGhe.DataSource = query;
         dl_SoDoGhe.DataBind();
         dl_SoDoGhe.RepeatColumns = phong.SoGheTrenHang;
         int _count = 0;
         foreach (Ghe ghe in query)
         {
             ImageButton imgbtn = (ImageButton)dl_SoDoGhe.Items[_count].FindControl("btn_Chuyen");
             imgbtn.ToolTip = (char)(ghe.Hang + 65) + (ghe.SoThuTu + 1).ToString() + " - Ghế " + ghe.DanhMucGhe.TenDanhMucGhe;
             if (ghe.DanhMucGhe.TenDanhMucGhe.CompareTo("Thường") == 0)
                 imgbtn.ImageUrl = "/Img/ghethuong.jpg";
             else
                 imgbtn.ImageUrl = "/Img/ghevip.jpg";
             _count++;
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            KiemTraQuyenBinhLuan(dt);
            LoadThongTinPhim(dt, ((Phim)Session["CurrentPhim"]));
            if (!IsPostBack)
            {
                try
                {
                    //Th_HinhAnh.ImageUrl = ((Phim)Session["CurrentPhim"]).AnhPhim;
                    //KiemTraQuyenBinhLuan(dt);
                    //FormView_Phim.DataSource = from phim in dt.Phims
                    //                           where phim.MaPhim == currentPhim.MaPhim
                    //                           select phim;
                    //FormView_Phim.DataBind();

                }
                catch
                {
                    Response.Redirect("Default.aspx");
                }
            }
            else
            {

            }
        }
        public void MyDataBind()
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            List<SuatChieu> _dsSuatChieu = (from _sc in dt.SuatChieus
                                           where _sc.LichChieuPhim.NgayChieu.Date >= DateTime.Now.Date && _sc.TinhTrang == true
                                            orderby _sc.MaPhim ascending
                                           select _sc).ToList();
            if (_dsSuatChieu.Count == 0)
                return;

            List<SuatChieu> _dsSuatChieuTheoPhim = new List<SuatChieu>();
            int _currentPhim = -1;
            for (int i = 0; i < _dsSuatChieu.Count; i++)
            {
                if (_dsSuatChieu[i].MaPhim != _currentPhim)
                {
                    _dsSuatChieuTheoPhim.Add(_dsSuatChieu[i]);
                    _currentPhim = _dsSuatChieu[i].MaPhim;
                }
            }

            //DataList _temp = (DataList)Panel1.FindControl("dtl_DanhSachPhim");
            ((DataList)Panel1.FindControl("dtl_DanhSachPhim")).DataSource = _dsSuatChieuTheoPhim;
            ((DataList)Panel1.FindControl("dtl_DanhSachPhim")).DataBind();
            //dtl_DanhSachPhim.DataSource = _dsSuatChieuTheoPhim;
            //dtl_DanhSachPhim.DataBind();
        }
 protected void btn_ThayDoi_Click(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     var suatchieu = from _suatchieu in dt.SuatChieus
                     where _suatchieu.MaSuatChieu == int.Parse(((LinkButton)sender).CommandArgument)
                     select _suatchieu;
     dt.SuatChieus.DeleteAllOnSubmit(suatchieu);
     dt.SubmitChanges();
 }
        //protected void btn_Sua_Click(object sender, EventArgs e)
        //{
        //    Button btn = (Button)sender;
        //    //((TextBox)dl_SuatChieuHienTai.Items[int.Parse(btn.CommandName)].FindControl("tb_ThoiGian")).ReadOnly = false;
        //    CinemaLINQDataContext dt = new CinemaLINQDataContext();
        //    DateTime time = new DateTime();
        //    for (int i = 0; i < 96; ++i)
        //    {
        //        DanhMucSuatChieu dmsc = new DanhMucSuatChieu();
        //        dmsc.ThoiGianBatDau = time.AddMinutes(i * 15);
        //        dmsc.TinhTrang = false;
        //        dmsc.GiaDanhMuc = 90000;
        //        dt.DanhMucSuatChieus.InsertOnSubmit(dmsc);
        //    }
        //    dt.SubmitChanges();
        //}
        protected void btn_ThayDoi_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            var query = (from dmsc in dt.DanhMucSuatChieus
                        where dmsc.MaDanhMucSuatChieu == int.Parse(((LinkButton)sender).CommandArgument)
                        select dmsc).Single();
            query.TinhTrang = !query.TinhTrang;

            dt.SubmitChanges();
        }
 protected void btn_CapNhatGia_Click(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     var query = (from dmsc in dt.DanhMucSuatChieus
                  where dmsc.MaDanhMucSuatChieu == int.Parse(((LinkButton)sender).CommandArgument)
                  select dmsc).Single();
     var giaMoi = int.Parse(((TextBox)dl_SuatChieuHienTai.Items[int.Parse(((LinkButton)sender).CommandName)].FindControl("tb_GiaDanhMuc")).Text);
     query.GiaDanhMuc = giaMoi;
     dt.SubmitChanges();
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                CinemaLINQDataContext dt = new CinemaLINQDataContext();
                int maxMaPhim = -1;
                try
                {
                    maxMaPhim = (from film in dt.Phims select film.MaPhim).Max();
                }
                catch
                {
                    maxMaPhim = 1;
                }
                string posterFileName =  (maxMaPhim + 1).ToString() + Th_AnhPhim.FileName.Substring(Th_AnhPhim.FileName.Length - 4);
                string posterName = "/phim/poster/" + posterFileName;
                Th_AnhPhim.SaveAs(Server.MapPath("/phim/poster/") + posterFileName);
                string trailerFileName = (maxMaPhim + 1).ToString() + Th_Trailer.FileName.Substring(Th_Trailer.FileName.Length - 4);
                string trailerName = "/phim/trailer/" + trailerFileName;
                Th_Trailer.SaveAs(Server.MapPath("/phim/trailer/") + trailerFileName);

                Phim phim = new Phim();
                phim.TenPhim = Th_TenPhim.Text;
                phim.TheLoai = int.Parse(DropDownList1.SelectedItem.Value);
                phim.DaoDien = Th_DaoDien.Text;
                phim.DienVienThamGia = Th_DienVien.Text;
                phim.NoiDung = Th_NoiDung.Text;
                phim.NgonNgu = Th_NgonNgu.Text;
                phim.ThoiLuong = int.Parse(Th_ThoiLuong.Text);
                phim.DiemDanhGia = 0;
                phim.TinhTrang = true;
                phim.AnhPhim = posterName;
                phim.TrailerPhim = trailerName;
                phim.LoaiPhim = int.Parse(DropDownList2.SelectedItem.Value);

                dt.Phims.InsertOnSubmit(phim);

                dt.SubmitChanges();
                Session["SelectedFilmID"] = phim.MaPhim;
                Response.Redirect("ThemPhimThanhCong.aspx");
            }
            catch
            {

            }
        }
        protected void btn_PhatSinh_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            for (int i = 0; i < int.Parse(cbb_ChonNgay.SelectedItem.Value); ++i)
            {
                var query = from _lichchieu in dt.LichChieuPhims
                                where _lichchieu.NgayChieu.CompareTo(DateTime.Today.AddDays(i + 1)) == 0
                                select _lichchieu;
                LichChieuPhim lichchieu = null;
                if (query.Count<LichChieuPhim>() == 0)
                {
                    lichchieu = new LichChieuPhim();
                    lichchieu.NgayChieu = DateTime.Today.AddDays(i + 1);
                    lichchieu.TinhTrang = true;
                    dt.LichChieuPhims.InsertOnSubmit(lichchieu);
                    dt.SubmitChanges();
                }
                else
                {
                    lichchieu = query.Single();
                }

                var dmSuatChieu = from _dmsc in dt.DanhMucSuatChieus
                                  where _dmsc.TinhTrang == true
                                  select _dmsc;
                foreach (DanhMucSuatChieu dmsc in dmSuatChieu)
                {
                    var suatchieu = from _suatchieu in dt.SuatChieus
                                    where _suatchieu.MaLichChieu == lichchieu.MaLichChieuPhim && _suatchieu.MaPhim == int.Parse(cbb_ChonPhim.SelectedItem.Value) && _suatchieu.MaPhong == int.Parse(cbb_Phong.SelectedItem.Value) && _suatchieu.MaDanhMucSuatChieu == dmsc.MaDanhMucSuatChieu
                                    select _suatchieu;
                    if (suatchieu.Count<SuatChieu>() == 0)
                    {
                        SuatChieu sc = new SuatChieu();
                        sc.MaLichChieu = lichchieu.MaLichChieuPhim;
                        sc.MaPhim = int.Parse(cbb_ChonPhim.SelectedItem.Value);
                        sc.MaPhong = int.Parse(cbb_Phong.SelectedItem.Value);
                        sc.MaDanhMucSuatChieu = dmsc.MaDanhMucSuatChieu;
                        sc.TinhTrang = false;
                        dt.SuatChieus.InsertOnSubmit(sc);
                        dt.SubmitChanges();
                    }
                }
            }
        }
        protected void btn_Chuyen_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            if (Session["Phong"] == null)
                Response.Redirect("/admin/default.aspx");

            Ghe ghe = dt.Ghes.Where(_ghe => _ghe.MaGhe == int.Parse(((ImageButton)sender).CommandArgument)).Select(_ghe => _ghe).Single();

            if (ghe.MaDanhMucGhe == dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Thường") == 0).Select(dmg => dmg.MaDanhMucGhe).Single())
            {
                ghe.MaDanhMucGhe = dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Vip") == 0).Select(dmg => dmg.MaDanhMucGhe).Single();
            }
            else
            {
                ghe.MaDanhMucGhe = dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Thường") == 0).Select(dmg => dmg.MaDanhMucGhe).Single();
            }

            dt.SubmitChanges();
        }
        protected void btn_Chuyen_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            var phong = (from _phong in dt.PhongChieuPhims
                         where _phong.MaPhongChieuPhim == int.Parse(cbb_Phong.SelectedItem.Value)
                         select _phong).Single();

            Ghe ghe = dt.Ghes.Where(_ghe => _ghe.MaGhe == int.Parse(((ImageButton)sender).CommandArgument)).Select(_ghe => _ghe).Single();

            if (ghe.MaDanhMucGhe == dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Thường") == 0).Select(dmg => dmg.MaDanhMucGhe).Single())
            {
                ghe.MaDanhMucGhe = dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Vip") == 0).Select(dmg => dmg.MaDanhMucGhe).Single();
            }
            else
            {
                ghe.MaDanhMucGhe = dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Thường") == 0).Select(dmg => dmg.MaDanhMucGhe).Single();
            }

            dt.SubmitChanges();
        }
        protected void UpdatePanel1_PreRender(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            NguoiDung nguoiDung = ((NguoiDung)Session["NguoiDung"]);
            var query = from binhLuan in dt.BinhLuans
                        where binhLuan.MaPhim == ((Phim)Session["CurrentPhim"]).MaPhim && binhLuan.TinhTrang == dt.DanhMucTinhTrangBinhLuans.Where(ttbl => ttbl.TenTinhTrang.CompareTo("Bình thường")==0).Select(ttbl => ttbl.MaTinhTrang).Single()
                        select binhLuan;

            DataList1.DataSource = query;
            DataList1.DataBind();

            int _count = 0;
            foreach (BinhLuan _bl in query)
            {
                if (nguoiDung != null && (nguoiDung.MaDanhMucNguoiDung == dt.DanhMucNguoiDungs.Where(dmnd=> dmnd.TenDanhMucNguoiDung.CompareTo("Admin") == 0).Select(dmnd=>dmnd.MaDanhMucNguoiDung).Single() || nguoiDung.MaNguoiDung == _bl.MaNguoiDung))
                {
                    ((TextBox)DataList1.Items[_count].FindControl("Th_NoiDungBinhLuan")).ReadOnly = false;
                    DataList1.Items[_count].FindControl("Xl_Sua").Visible = true;
                    DataList1.Items[_count].FindControl("Xl_Xoa").Visible = true;
                }
                else
                {
                    ((TextBox)DataList1.Items[_count].FindControl("Th_NoiDungBinhLuan")).ReadOnly = true;
                    DataList1.Items[_count].FindControl("Xl_Sua").Visible = false;
                    DataList1.Items[_count].FindControl("Xl_Xoa").Visible = false;
                }
                Button temp = (Button)DataList1.Items[_count].FindControl("Xl_Sua");
                temp.CommandName = _count.ToString();
                _count++;
            }
            if (nguoiDung == null)
            {
                UpdatePanel1.FindControl("Xl_ThemBinhLuan").Visible = false;
                UpdatePanel1.FindControl("Th_BinhLuanMoi").Visible = false;
            }
            else
            {
                UpdatePanel1.FindControl("Xl_ThemBinhLuan").Visible = true;
                UpdatePanel1.FindControl("Th_BinhLuanMoi").Visible = true;
            }
        }
Exemple #14
0
        public void BindingData()
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            List<Phim> _dsPhim = (from _phim in dt.Phims
                                  where _phim.SuatChieus.Where(sc => sc.LichChieuPhim.NgayChieu.Date >= DateTime.Now.Date).Count() > 0
                                  orderby _phim.TenPhim ascending
                                  select _phim).ToList();

            if (_dsPhim.Count == 0)
            {
                return;
            }
            else
            {
                PagedDataSource pds = new PagedDataSource();
                pds.DataSource = _dsPhim;
                pds.AllowPaging = true;
                pds.PageSize = _pageSize;
                pds.CurrentPageIndex = CurrentIndex;

                Th_KetQuaTraCuu.DataSource = pds;
                Th_KetQuaTraCuu.DataBind();

                if (Session["NguoiDung"] == null || ((NguoiDung)Session["NguoiDung"]).MaDanhMucNguoiDung != 1)
                {
                    int _temp = _dsPhim.Count - (CurrentIndex * _pageSize);
                    int _itemCount = 0;
                    if (_temp >= _pageSize)
                        _itemCount = _pageSize;
                    else
                        _itemCount = _temp;

                    for (int i = 0; i < _itemCount; i++)
                    {
                        ((LinkButton)Th_KetQuaTraCuu.Items[i].FindControl("lbt_ChinhSuaPhim")).Visible = false;
                    }
                }

                Pagging_CountPage(_dsPhim.Count);
            }
        }
 protected void btn_XacNhan_Click(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     if (Session["DungDo"] != null && (bool)Session["DungDo"] == true)
         lb_ThongBao.Text = "Vẫn còn đụng độ trên lịch chiếu - Thêm mới thất bại";
     else
     {
         for (int i = 0; i < int.Parse(cbb_ChonNgay.SelectedItem.Value); ++i)
         {
             var query = from _lichchieu in dt.LichChieuPhims
                         where _lichchieu.NgayChieu.CompareTo(DateTime.Today.AddDays(i + 1)) == 0
                         select _lichchieu;
             LichChieuPhim lichchieu = null;
             if (query.Count<LichChieuPhim>() == 0)
             {
                 lichchieu = new LichChieuPhim();
                 lichchieu.NgayChieu = DateTime.Today.AddDays(i + 1);
                 lichchieu.TinhTrang = true;
                 dt.LichChieuPhims.InsertOnSubmit(lichchieu);
                 dt.SubmitChanges();
             }
             else
             {
                 lichchieu = query.Single();
             }
             var dsSuatChieu = from _suatchieu in dt.SuatChieus
                               where _suatchieu.MaLichChieu == lichchieu.MaLichChieuPhim && _suatchieu.MaPhim == int.Parse(cbb_ChonPhim.SelectedItem.Value) && _suatchieu.MaPhong == int.Parse(cbb_Phong.SelectedItem.Value) && _suatchieu.TinhTrang == false
                               select _suatchieu;
             foreach (SuatChieu _suatchieu in dsSuatChieu)
             {
                 _suatchieu.TinhTrang = true;
                 dt.SubmitChanges();
             }
             var dsSuatChieuTam = from _suatchieu in dt.SuatChieus
                                  where _suatchieu.TinhTrang == false
                                  select _suatchieu;
             dt.SuatChieus.DeleteAllOnSubmit(dsSuatChieuTam);
             dt.SubmitChanges();
         }
     }
 }
        protected void btn_ThemSuat_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            var query = from dmsc in dt.DanhMucSuatChieus
                        where dmsc.ThoiGianBatDau.Hour == int.Parse(tb_Gio.Text) && dmsc.ThoiGianBatDau.Minute == int.Parse(tb_Phut.Text)
                        select dmsc;

            if (query.Count<DanhMucSuatChieu>() == 0)
            {
                DanhMucSuatChieu dmsc = new DanhMucSuatChieu();
                DateTime time = new DateTime(1990, 1, 1);
                time = time.AddHours(int.Parse(tb_Gio.Text));
                time = time.AddMinutes(int.Parse(tb_Phut.Text));
                dmsc.ThoiGianBatDau = time;
                dmsc.TinhTrang = true;
                dmsc.GiaDanhMuc = int.Parse(tb_GiaDanhMucSuatMoi.Text);
                dt.DanhMucSuatChieus.InsertOnSubmit(dmsc);
                dt.SubmitChanges();
            }
        }
        protected void btn_ThemPhongMoi_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            PhongChieuPhim phong = (PhongChieuPhim)Session["Phong"];
            if (phong == null)
                Response.Redirect("/admin/default.aspx");
            var __phong = (from _phong in dt.PhongChieuPhims
                         where _phong.MaPhongChieuPhim == phong.MaPhongChieuPhim
                         select _phong).Single();

            __phong.TinhTrang = true;
            dt.SubmitChanges();

            var dsGhe = from _ghe in dt.Ghes
                        where _ghe.MaPhongChieuPhim == __phong.MaPhongChieuPhim
                        select _ghe;
            foreach (Ghe _ghe in dsGhe)
            {
                _ghe.TinhTrang = 1;
            }
            dt.SubmitChanges();

            var dsGheTam = from _ghe in dt.Ghes
                           where _ghe.TinhTrang == -1
                           select _ghe;

            dt.Ghes.DeleteAllOnSubmit(dsGheTam);
            dt.SubmitChanges();

            var dsPhongTam = from _phong in dt.PhongChieuPhims
                             where _phong.TinhTrang == false
                             select _phong;

            dt.PhongChieuPhims.DeleteAllOnSubmit(dsPhongTam);
            dt.SubmitChanges();

            Session["Phong"] = null;
            Response.Redirect("/admin/ThemPhongThanhCong.aspx");
        }
        protected void Xl_DangNhap_Click(object sender, EventArgs e)
        {
            try
            {
                CinemaLINQDataContext dt = new CinemaLINQDataContext();
                Session["PreviousUrl"] = Request.Url;
                string tenDangNhap = Th_TenDangNhap.Text;
                string matKhau = Th_MatKhau.Text;
                MD5 md5Hasher = MD5.Create();
                byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(matKhau));

                StringBuilder sBuilder = new StringBuilder();
                for (int i = 0; i < data.Length; i++)
                {
                    sBuilder.Append(data[i].ToString("x2"));
                }
                string strPassword = sBuilder.ToString();

                var query = (from nguoiDung in dt.NguoiDungs
                             where tenDangNhap.CompareTo(nguoiDung.TenNguoiDung) == 0 && strPassword.CompareTo(nguoiDung.MatKhau) == 0
                             select nguoiDung).Single();
                if (query.TinhTrang == dt.DanhMucTinhTrangNguoiDungs.Where(ttnd=> ttnd.TenDanhMucTinhTrangNguoiDung.CompareTo("Tạm khóa") == 0).Select(ttnd=> ttnd.MaDanhMucTinhTrangNguoiDung).Single())
                {
                    Label2.Text = "Tài khoản đã bị khóa, vui lòng kiểm tra lại";
                    Label2.Visible = true;
                }
                else
                {
                    Session["NguoiDung"] = query;
                    Response.Redirect("dangnhapthanhcong.aspx");
                }
            }
            catch
            {
                Label2.Text = "Sai tên đăng nhập hoặc mật khẩu";
                Label2.Visible = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Th_TenPhim.Text == null || Th_TenPhim.Text.Trim().Length == 0)
                {
                    CinemaLINQDataContext dt = new CinemaLINQDataContext();

                    Th_TenPhim.Text = ((Phim)Session["CurrentPhim"]).TenPhim;
                    Th_DaoDien.Text = ((Phim)Session["CurrentPhim"]).DaoDien;
                    Th_DienVien.Text = ((Phim)Session["CurrentPhim"]).DienVienThamGia;
                    Th_NgonNgu.Text = ((Phim)Session["CurrentPhim"]).NgonNgu;
                    Th_NoiDung.Text = ((Phim)Session["CurrentPhim"]).NoiDung;
                    Th_ThoiLuong.Text = ((Phim)Session["CurrentPhim"]).ThoiLuong.ToString();

                    Image1.ImageUrl = ((Phim)Session["CurrentPhim"]).AnhPhim;
                }
            }
            catch
            {
                Response.Redirect("Default.aspx");
            }
        }
        protected void Xl_CapNhatThayDoi_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            var query = (from phim in dt.Phims
                         where phim.MaPhim == ((Phim)Session["CurrentPhim"]).MaPhim
                         select phim).Single();

            query.TenPhim = Th_TenPhim.Text;
            query.NoiDung = Th_NoiDung.Text;
            query.TheLoai = int.Parse(DropDownList1.SelectedItem.Value);
            query.LoaiPhim = int.Parse(DropDownList2.SelectedItem.Value);
            query.ThoiLuong = int.Parse(Th_ThoiLuong.Text);
            query.DienVienThamGia = Th_DienVien.Text;
            query.DaoDien = Th_DaoDien.Text;
            query.NgonNgu = Th_NgonNgu.Text;
            if (Th_AnhPhim.FileName != null && Th_AnhPhim.FileName.Trim().Length != 0)
            {
                string posterFileName = query.MaPhim.ToString() + Th_AnhPhim.FileName.Substring(Th_AnhPhim.FileName.Length - 4);
                string posterName = "/phim/poster/" + posterFileName;
                Th_AnhPhim.SaveAs(Server.MapPath("/phim/poster/") + posterFileName);
                query.AnhPhim = posterName;
            }

            if (Th_Trailer.FileName != null && Th_Trailer.FileName.Trim().Length != 0)
            {
                string trailerFileName = query.MaPhim.ToString() + Th_Trailer.FileName.Substring(Th_Trailer.FileName.Length - 4);
                string trailerName = "/phim/trailer/" + trailerFileName;
                Th_Trailer.SaveAs(Server.MapPath("/phim/trailer/") + trailerFileName);
                query.TrailerPhim = trailerName;
            }

            dt.SubmitChanges();
            Session["CurrentPhim"] = query;
            Response.Redirect("default.aspx");
        }
 protected void Xl_Sua_Click(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     var query = (from binhLuan in dt.BinhLuans
                  where binhLuan.MaBinhLuan == int.Parse(((Button)sender).CommandArgument)
                  select binhLuan).Single();
     query.NoiDungBinhLuan = ((TextBox)DataList1.Items[int.Parse(((Button)sender).CommandName)].FindControl("Th_NoiDungBinhLuan")).Text;
     dt.SubmitChanges();
 }
 protected void Xl_Xoa_Click(object sender, EventArgs e)
 {
     CinemaLINQDataContext dt = new CinemaLINQDataContext();
     var query = (from binhLuan in dt.BinhLuans
                  where binhLuan.MaBinhLuan == int.Parse(((Button)sender).CommandArgument)
                  select binhLuan).Single();
     query.TinhTrang = dt.DanhMucTinhTrangBinhLuans.Where(ttbl => ttbl.TenTinhTrang.CompareTo("Đã xóa") == 0).Select(ttbl => ttbl.MaTinhTrang).Single(); ;
     dt.SubmitChanges();
 }
 private void KiemTraQuyenBinhLuan(CinemaLINQDataContext dt)
 {
     if ((NguoiDung)Session["NguoiDung"] != null)
     {
         var query = from cd_ in dt.ChamDiems
                     where cd_.MaNguoiDung == ((NguoiDung)Session["NguoiDung"]).MaNguoiDung && cd_.MaPhim == ((Phim)Session["CurrentPhim"]).MaPhim
                     select cd_;
         if (query.Count<ChamDiem>() == 0)
         {
             Th_DiemCuaBan.Visible = true;
             Xl_ChoDiem.Visible = true;
             Lb_DiemCuaBan.Visible = true;
             Lb_DaChoDiem.Visible = false;
         }
         else
         {
             Th_DiemCuaBan.Visible = false;
             Xl_ChoDiem.Visible = false;
             Lb_DiemCuaBan.Visible = false;
             Lb_DaChoDiem.Visible = true;
             Lb_DaChoDiem.Text = "Bạn đã chấm điểm cho phim này rồi";
         }
     }
     else
     {
         Th_DiemCuaBan.Visible = false;
         Xl_ChoDiem.Visible = false;
         Lb_DiemCuaBan.Visible = false;
         Lb_DaChoDiem.Visible = true;
         Lb_DaChoDiem.Text = "Bạn cần đăng nhập để chấm điểm cho phim";
     }
 }
        protected void Xl_XemSoDoGhe_Click(object sender, EventArgs e)
        {
            int soHang = int.Parse(tb_SoHangGhe.Text);
            int soGheTrenHang = int.Parse(tb_SoGheTrenHang.Text);
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            PhongChieuPhim phong = new PhongChieuPhim();
            phong.MaRapChieuPhim = int.Parse(cbb_RapPhim.SelectedItem.Value);
            phong.TenPhongChieuPhim = tb_TenPhong.Text;
            phong.TongSoLuongGhe = soGheTrenHang * soHang;
            phong.TinhTrang = false;
            phong.SoHang = soHang;
            phong.SoGheTrenHang = soGheTrenHang;
            dt.PhongChieuPhims.InsertOnSubmit(phong);

            dt.SubmitChanges();

            for (int i = 0; i < soHang; ++i)
            {
                for (int j = 0; j < soGheTrenHang; ++j)
                {
                    Ghe ghe = new Ghe();
                    ghe.MaPhongChieuPhim = phong.MaPhongChieuPhim;
                    ghe.TenGhe = "Ghe";
                    ghe.MaDanhMucGhe = dt.DanhMucGhes.Where(dmg => dmg.TenDanhMucGhe.CompareTo("Thường") == 0).Select(dmg => dmg.MaDanhMucGhe).Single();
                    ghe.Hang = i;
                    ghe.SoThuTu = j;
                    ghe.TinhTrang = -1;
                    dt.Ghes.InsertOnSubmit(ghe);
                    dt.SubmitChanges();
                }
            }

            Session["Phong"] = (PhongChieuPhim)phong;
        }
 private void LoadThongTinPhim(CinemaLINQDataContext dt, Phim currentPhim)
 {
     FormView_Phim.DataSource = from phim in dt.Phims
                                where phim.MaPhim == currentPhim.MaPhim
                                select phim;
     FormView_Phim.DataBind();
 }
        protected void Xl_ChoDiem_Click(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();

            ChamDiem cd = new ChamDiem();
            cd.MaPhim = ((Phim)Session["CurrentPhim"]).MaPhim;
            cd.SoDiem = int.Parse(Th_DiemCuaBan.SelectedItem.Value);
            cd.MaNguoiDung = ((NguoiDung)Session["NguoiDung"]).MaNguoiDung;

            dt.ChamDiems.InsertOnSubmit(cd);

            dt.SubmitChanges();

            var query = (from phim in dt.Phims
                         where phim.MaPhim == ((Phim)Session["CurrentPhim"]).MaPhim
                         select phim).Single();
            var query1 = from cd_ in dt.ChamDiems
                         where cd_.MaPhim == ((Phim)Session["CurrentPhim"]).MaPhim
                         select cd_.SoDiem;

            query.DiemDanhGia = (float)query1.Sum() / (float)query1.Count();

            dt.SubmitChanges();

            KiemTraQuyenBinhLuan(dt);
            LoadThongTinPhim(dt, ((Phim)Session["CurrentPhim"]));
        }
        protected void UpdatePanel1_PreRender(object sender, EventArgs e)
        {
            CinemaLINQDataContext dt = new CinemaLINQDataContext();
            if (cbb_ChonPhim.SelectedIndex == -1 || cbb_ChonNgay.SelectedIndex == -1 || cbb_Phong.SelectedIndex == -1)
                return;
            List<DateTime> dsNgayChieu = new List<DateTime>();
            for (int i = 0; i < int.Parse(cbb_ChonNgay.SelectedItem.Value); ++i)
                dsNgayChieu.Add(DateTime.Today.AddDays(i + 1));
            var dsLichChieu = from _lichChieu in dt.LichChieuPhims
                        where dsNgayChieu.Contains(_lichChieu.NgayChieu)
                        select _lichChieu;
            dl_DsLichChieu.DataSource = dsLichChieu;
            dl_DsLichChieu.DataBind();

            int count = 0;
            foreach (LichChieuPhim _lichchieu in dsLichChieu)
            {
                Label lb_NgayChieu = (Label)dl_DsLichChieu.Items[count].FindControl("lb_NgayChieu");
                lb_NgayChieu.Text = _lichchieu.NgayChieu.ToShortDateString();
                DataList dl_SuatChieu = (DataList)dl_DsLichChieu.Items[count].FindControl("dl_SuatChieu");
                var dsSuatChieu = (from _suatchieu in dt.SuatChieus
                                  where _suatchieu.MaLichChieu == _lichchieu.MaLichChieuPhim && _suatchieu.MaPhong == int.Parse(cbb_Phong.SelectedItem.Value) && _suatchieu.MaPhim == int.Parse(cbb_ChonPhim.SelectedItem.Value)
                                  select _suatchieu).OrderBy(_suatchieu => _suatchieu.DanhMucSuatChieu.ThoiGianBatDau);
                dsSuatChieu.OrderBy(_suatchieu => _suatchieu.DanhMucSuatChieu.ThoiGianBatDau);
                dl_SuatChieu.DataSource = dsSuatChieu;
                dl_SuatChieu.DataBind();

                int _count = 0;
                foreach (SuatChieu _suatchieu in dsSuatChieu)
                {
                    Label lb_ThoiGian = (Label)dl_SuatChieu.Items[_count].FindControl("lb_ThoiGian");
                    lb_ThoiGian.Text = _suatchieu.DanhMucSuatChieu.ThoiGianBatDau.ToShortTimeString();
                    Label lb_Phong = (Label)dl_SuatChieu.Items[_count].FindControl("lb_Phong");
                    lb_Phong.Text = _suatchieu.PhongChieuPhim.TenPhongChieuPhim;
                    Label lb_Phim = (Label)dl_SuatChieu.Items[_count].FindControl("lb_Phim");
                    lb_Phim.Text = _suatchieu.Phim.TenPhim;
                    Label lb_TinhTrang = (Label)dl_SuatChieu.Items[_count].FindControl("lb_TinhTrang");
                    var dsSuatChieuCungGio = from __suatchieu in dt.SuatChieus
                                             where __suatchieu.MaPhong == _suatchieu.MaPhong && __suatchieu.MaDanhMucSuatChieu == _suatchieu.MaDanhMucSuatChieu && __suatchieu.MaSuatChieu != _suatchieu.MaSuatChieu && __suatchieu.MaLichChieu == _suatchieu.MaLichChieu
                                             || (((__suatchieu.DanhMucSuatChieu.ThoiGianBatDau.CompareTo(_suatchieu.DanhMucSuatChieu.ThoiGianBatDau) > 0 && __suatchieu.DanhMucSuatChieu.ThoiGianBatDau.CompareTo(_suatchieu.DanhMucSuatChieu.ThoiGianBatDau.AddMinutes(_suatchieu.Phim.ThoiLuong)) <= 0)
                                             || (_suatchieu.DanhMucSuatChieu.ThoiGianBatDau.CompareTo(__suatchieu.DanhMucSuatChieu.ThoiGianBatDau) > 0 && _suatchieu.DanhMucSuatChieu.ThoiGianBatDau.CompareTo(__suatchieu.DanhMucSuatChieu.ThoiGianBatDau.AddMinutes(__suatchieu.Phim.ThoiLuong)) <= 0))
                                             && __suatchieu.DanhMucSuatChieu.SuatChieus.Count<SuatChieu>(___suatchieu => ___suatchieu.MaLichChieu == _suatchieu.MaLichChieu) != 0)
                                             select __suatchieu;

                    ((LinkButton)dl_SuatChieu.Items[_count].FindControl("btn_ThayDoi")).Text = "Xóa";
                    Session["DungDo"] = false;
                    if (dsSuatChieuCungGio.Count<SuatChieu>() != 0)
                    {
                        lb_TinhTrang.Text = "Đụng độ";
                        lb_TinhTrang.ForeColor = Color.Red;
                        Session["DungDo"] = true;
                    }
                    ++_count;
                }
                ++count;
            }
        }
        protected void Xl_ThemBinhLuan_Click(object sender, EventArgs e)
        {
            try
            {
                CinemaLINQDataContext dt = new CinemaLINQDataContext();

                BinhLuan bl = new BinhLuan();
                bl.MaPhim = ((Phim)Session["CurrentPhim"]).MaPhim;
                bl.NoiDungBinhLuan = Th_BinhLuanMoi.Text;
                bl.MaNguoiDung = ((NguoiDung)Session["NguoiDung"]).MaNguoiDung;
                bl.TinhTrang = dt.DanhMucTinhTrangBinhLuans.Where(ttbl => ttbl.TenTinhTrang.CompareTo("Bình thường")==0).Select(ttbl => ttbl.MaTinhTrang).Single();
                bl.ThoiGianBinhLuan = DateTime.Now;
                dt.BinhLuans.InsertOnSubmit(bl);

                dt.SubmitChanges();

                Th_BinhLuanMoi.Text = "";
                //Response.Redirect("/phim/chitietphim.aspx");
            }
            catch
            {
                //Response.Redirect("/phim/chitietphim.aspx");
            }
        }