protected void btExport_Click(object sender, EventArgs e)
        {
            BUSHoatDong bushoatdong = new BUSHoatDong();
            HOATDONG hoatdong = bushoatdong.TimKiem(int.Parse(Request.QueryString["id"]));
            fileSave = "Chi_Tiet_Dang_Ky_Hoat_Dong_" + hoatdong.TenHoatDong + ".xls";

            ExportToExcel();

            Response.Redirect("~\\Download\\" + fileSave);
        }
        protected void ddlMaHoatDong_SelectedIndexChanged(object sender, EventArgs e)
        {
            BUSHoatDong bushoatdong = new BUSHoatDong();
            HOATDONG hoatdong = bushoatdong.TimKiem(int.Parse(ddlMaHoatDong.SelectedValue));
            txtTenHoatDong.Text = hoatdong.TenHoatDong;
            ddlLoaiHoatDong.Text = hoatdong.MaLoaiHoatDong.ToString();

            txtNgayDienRa.Text = hoatdong.NgayDienRa.Value.Day + "/" + hoatdong.NgayDienRa.Value.Month + "/" + hoatdong.NgayDienRa.Value.Year;
            txtThoiGianBatDauDK.Text = hoatdong.ThoiGianBatDauDangKy.Value.Day + "/" + hoatdong.ThoiGianBatDauDangKy.Value.Month + "/" + hoatdong.ThoiGianBatDauDangKy.Value.Year;
            txtThoiGianKetThucDK.Text = hoatdong.ThoiGianKetThucDangKy.Value.Day + "/" + hoatdong.ThoiGianKetThucDangKy.Value.Month + "/" + hoatdong.ThoiGianKetThucDangKy.Value.Year;
        }
 public void LoadImage()
 {
     BUSLoaiHoatDong busLoaiHD = new BUSLoaiHoatDong();
     LOAIHOATDONG aLoaiHD = busLoaiHD.TimKiem("Hoạt động nổi bật");
     if (aLoaiHD != null)
     {
         BUSHoatDong busHD = new BUSHoatDong();
         List<HOATDONG> dsHDNoiBat = busHD.LayHoatDongTheoLoai(aLoaiHD.MaLoaiHoatDong);
         if (dsHDNoiBat.Count > 0)
         {
             imgMain.ImageUrl = "~/Uploads/HinhAnhHoatDong/" + dsHDNoiBat[0].HinhAnh;
             imgMain.AlternateText = "Không tìm thấy hình ảnh";
             imgMain.PostBackUrl = "~/ChiTietHoatDong.aspx?id=" + dsHDNoiBat[0].MaHoatDong;
         }
     }
 }
        protected void btCapNhat_Click(object sender, EventArgs e)
        {
            if (KiemTra() == false)
            {
                txtThongTin.Text = "Thời gian không hợp lệ";
                return;
            }

            HOATDONG hoatdong = new HOATDONG();
            hoatdong.MaHoatDong = int.Parse(ddlMaHoatDong.SelectedValue);
            hoatdong.TenHoatDong = txtTenHoatDong.Text;
            hoatdong.MaLoaiHoatDong = int.Parse(ddlMaHoatDong.SelectedValue);

            hoatdong.NgayDienRa = new DateTime(int.Parse(txtNgayDienRa.Text.Substring(6, 4)), int.Parse(txtNgayDienRa.Text.Substring(3, 2)), int.Parse(txtNgayDienRa.Text.Substring(0, 2)));
            hoatdong.ThoiGianBatDauDangKy = new DateTime(int.Parse(txtThoiGianBatDauDK.Text.Substring(6, 4)), int.Parse(txtThoiGianBatDauDK.Text.Substring(3, 2)), int.Parse(txtThoiGianBatDauDK.Text.Substring(0, 2)));
            hoatdong.ThoiGianKetThucDangKy = new DateTime(int.Parse(txtThoiGianKetThucDK.Text.Substring(6, 4)), int.Parse(txtThoiGianKetThucDK.Text.Substring(3, 2)), int.Parse(txtThoiGianKetThucDK.Text.Substring(0, 2)));

            BUSHoatDong bushoatdong = new BUSHoatDong();
            bushoatdong.CapNhat(hoatdong);
        }
        //Load
        public int LoadHoatDong()
        {
            List<HOATDONG> lt = new List<HOATDONG>();

            BUSHoatDong BUSHoatDong = new BUSHoatDong();

            lt = BUSHoatDong.SelectHOATDONGsAll();
            if (lt.Count > 0)
            {
                this.GridViewHoatDong.DataSource = lt;
                GridViewHoatDong.DataBind();
                PanelDanhSach.Visible = true;
                PanelMessage.Visible = false;

                return lt.Count;
            }
            else
            {
                PanelDanhSach.Visible = false;
                PanelMessage.Visible = true;
                return 0;
            }
        }
 protected void ddlLoaiHoatDong_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddlLoaiHoatDong.SelectedIndex != -1)
     {
         int iMaLoai = int.Parse(ddlLoaiHoatDong.SelectedValue);
         BUSLoaiHoatDong busLoaiHD = new BUSLoaiHoatDong();
         LOAIHOATDONG LoaiTatCa = busLoaiHD.TimKiem("Tất Cả");
         if (LoaiTatCa != null && iMaLoai == LoaiTatCa.MaLoaiHoatDong)
         {
             int soDong = LoadHoatDong();
             FilterSTT(soDong, 0, int.Parse(DropDownListPaging.SelectedValue));
         }
         else
         {
             //Lấy hoạt động theo mã loại
             BUSHoatDong busHoatDong = new BUSHoatDong();
             List<HOATDONG> dsHoatDong = busHoatDong.LayHoatDongTheoLoai(iMaLoai);
             GridViewHoatDong.DataSource = dsHoatDong;
             GridViewHoatDong.AutoGenerateColumns = false;
             GridViewHoatDong.DataBind();
             this.FilterSTT(dsHoatDong.Count, GridViewHoatDong.PageIndex, int.Parse(DropDownListPaging.SelectedValue));
         }
     }
 }
        protected void WriteTitle(ExcelCOM.Worksheet worksheet)
        {
            BUSHoatDong bushoatdong = new BUSHoatDong();
            HOATDONG hoatdong = bushoatdong.TimKiem(int.Parse(Request.QueryString["id"]));

            ExcelCOM.Range sheetTitle = (ExcelCOM.Range)worksheet.get_Range("A1", "D1");
            sheetTitle.MergeCells = true;
            sheetTitle.Value2 = "Chi Tiết Đăng Ký Hoạt Động " + hoatdong.TenHoatDong;
            sheetTitle.Font.Bold = true;
            sheetTitle.Font.Size = 20;
            sheetTitle.HorizontalAlignment = ExcelCOM.XlHAlign.xlHAlignCenter;
            sheetTitle.Rows.AutoFit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(sheetTitle);

            for (int i = 0; i < GridViewDangKyHoatDong.Columns.Count; i++)
            {
                WriteIndexColumn(worksheet, 3, i + 1, GridViewDangKyHoatDong.Columns[i].ToString());
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Thong tin nguoi dung

            BUSHoatDong HoatDongBUS = new BUSHoatDong();
            List<HOATDONG> DSHoatDong = HoatDongBUS.SelectHOATDONGsAll();
            drlHoatDong.DataSource = DSHoatDong;
            drlHoatDong.DataTextField = "TenHoatDong";
            drlHoatDong.DataValueField = "MaHoatDong";
            drlHoatDong.DataBind();

            if (Request.QueryString["id"] != null)
            {
                //lay ma
                int mahoatdong = int.Parse(Request.QueryString["id"]);

                //lay thong tin va load len cac textbox
                BUSThongBao BUSThongBao = new BUSThongBao();
                THONGBAO lpDTO = BUSThongBao.TimKiem(mahoatdong);
                txttieude.Text = lpDTO.TieuDe ;
                txtnoidung.Content = lpDTO.NoiDung ;
                drlHoatDong.SelectedValue = mahoatdong.ToString();
            }
        }
        protected void XoaHoatDong(int id)
        {
            try
            {
                //xac nhan truoc khi xoa
                BUSHoatDong bus = new BUSHoatDong();
                if (bus.Xoa(id) == 0)
                {
                    //Thong bao
                    Response.Redirect("HoatDong.aspx");
                }

            }

            catch
            {
            }
        }
 protected void btXoa_Click(object sender, EventArgs e)
 {
     BUSHoatDong bushoatdong = new BUSHoatDong();
     bushoatdong.Xoa(int.Parse(ddlMaHoatDong.SelectedValue));
     Response.Redirect("QuanLyHoatDong.aspx");
 }
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (KiemTra() == false)
            {
                return;
            }

            try
            {
                //lay thong tin tu textbox
                HOATDONG lpDTO = new HOATDONG();
                lpDTO.MaHoatDong = int.Parse(Request.QueryString["id"]);
                lpDTO.TenHoatDong = txttenhoatdong.Text;
                lpDTO.MaLoaiHoatDong = int.Parse(ddlLoaiHoatDong.SelectedValue);
                //
                IFormatProvider culture = new CultureInfo("vi-VN", true);

                lpDTO.NgayDienRa = DateTime.Parse(txtngaydienra.Text, culture);
                lpDTO.ThoiGianBatDauDangKy = DateTime.Parse(txtthoigianbatdaudangky.Text, culture);
                lpDTO.ThoiGianKetThucDangKy = DateTime.Parse(txtthoigianketthucdangky.Text, culture);

                if (image.ImageUrl == link)
                {
                    lpDTO.HinhAnh = link.Substring(defaultLink.Length);
                }
                else
                {
                    if (image.ImageUrl != "")
                    {
                        lpDTO.HinhAnh = RenameHinhAnh(image.ImageUrl, lpDTO.TenHoatDong).Substring(defaultLink.Length);
                    }
                }

                //Goi ham cap nhat
                BUSHoatDong BUSHoatDong = new BUSHoatDong();
                if (BUSHoatDong.CapNhat(lpDTO) == 0)
                {
                    //Thong bao
                    lbThongBao.Text = "Cập Nhật Thành Công";
                    lbThongBao.Visible = true;
                    link = "";
                    linkTemp = "";
                    Response.Redirect("~/administration/HoatDong.aspx?id=" + Request.QueryString["id"]);
                }
                else
                {
                    lbThongBao.Text = "Cập Nhật Không Thành Công";
                    lbThongBao.Visible = true;
                }
            }

            catch
            {
                lbThongBao.Text = "Cập nhật Không Thành Công";
                lbThongBao.Visible = true;
            }

            DeleteHinhAnh(linkTemp);
            link = "";
            linkTemp = "";
        }
        protected void LoadHoatDong()
        {
            //lay ma
            int mahoatdong = int.Parse(Request.QueryString["id"]);

            //lay thong tin va load len cac textbox
            BUSHoatDong BUSHoatDong = new BUSHoatDong();
            HOATDONG lpDTO = BUSHoatDong.TimKiem(mahoatdong);
            txttenhoatdong.Text = lpDTO.TenHoatDong;
            ddlLoaiHoatDong.SelectedValue = lpDTO.MaLoaiHoatDong.ToString();
            txtngaydienra.Text = ((DateTime)lpDTO.NgayDienRa).ToString("dd/MM/yyyy");
            txtthoigianbatdaudangky.Text = ((DateTime)lpDTO.ThoiGianBatDauDangKy).ToString("dd/MM/yyyy");
            txtthoigianketthucdangky.Text = ((DateTime)lpDTO.ThoiGianKetThucDangKy).ToString("dd/MM/yyyy");

            if (lpDTO.HinhAnh == "")
            {
                link = "";
                image.Visible = false;
            }
            else
            {
                if (lpDTO.HinhAnh != "")
                {
                    link = defaultLink + lpDTO.HinhAnh;
                    image.ImageUrl = link;
                    image.Visible = true;
                }
            }
        }
        protected void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                //lay thong tin tu textbox
                int mahoatdong = int.Parse(Request.QueryString["id"]);

                BUSHoatDong BUSHoatDong = new BUSHoatDong();
                HOATDONG hoatdong = BUSHoatDong.TimKiem(mahoatdong);

                //xac nhan truoc khi xoa

                    //Goi ham xoa

                    BUSDangKyHoatDong BUSDangKyHoatDong = new BUSDangKyHoatDong();
                    BUSDangKyHoatDong.Xoa(mahoatdong);

                    if (BUSHoatDong.Xoa(mahoatdong) == 0)
                    {
                        //Thong bao
                        lbThongBao.Text = "Xóa Thành Công";
                        lbThongBao.Visible = true;
                        DeleteHinhAnh(link);
                        link = "";
                        Response.Redirect("~/administration/HoatDong.aspx");
                    }
                    else
                    {
                        lbThongBao.Text = "Xóa Không Thành Công";
                        lbThongBao.Visible = true;
                    }

            }

            catch
            {
                lbThongBao.Text = "Xóa Không Thành Công";
                lbThongBao.Visible = true;
            }
        }