Пример #1
0
        protected string LayDanhSachHinhAnh()
        {
            BUSAlbum busalbum = new BUSAlbum();

            List<ALBUM> dsAlBum = busalbum.SelectALBUMsAll();
            string str = "";

            if (dsAlBum.Count() == 0)
            {
                str = "Không có album";
                return str;
            }
            str += "<table><tr>";
            int count = 0;
            for (int i = 0; i < dsAlBum.Count; i++)
            {
                if (count == 1)
                {
                    str+="</tr><tr>";
                    count = 0;
                }
                str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href ='" + "Album.aspx?id=" + dsAlBum[i].MaAlbum + "'>" + dsAlBum[i].TenAlbum + "</a>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                count++;
            }
            str += "</tr></table>";
            return str;
        }
        protected void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                //lay thong tin tu textbox
                ALBUM lpDTO = new ALBUM();
                lpDTO.MaAlbum  = Convert.ToInt32(this.txtmaalbum.Text);
                lpDTO.TenAlbum  = this.txttenalbum.Text;

                //Goi ham cap nhat
                BUSAlbum BUSAlbum = new BUSAlbum();
                if (BUSAlbum.Them(lpDTO) == 0)
                {
                    //Thong bao
                    lbThongBao.Text = "Thêm Thành Công";
                    lbThongBao.Visible = true;
                    //Response.Redirect("LoaiMatHang.aspx");
                }
                else
                {
                    lbThongBao.Text = "Thêm Không Thành Công";
                    lbThongBao.Visible = true;
                }
            }

            catch
            {
                lbThongBao.Text = "Thêm Không Thành Công";
                lbThongBao.Visible = true;
            }
        }
        protected void btnXoa_Click(object sender, EventArgs e)
        {
            try
            {
                //lay thong tin tu textbox
                int mahoatdong = int.Parse(Request.QueryString["id"]);

                //xac nhan truoc khi xoa
                DialogResult rs = MessageBox.Show("Bạn có chắc là muốn xoá Hoạt Động <" + mahoatdong + "> không?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (rs == DialogResult.Yes)
                {
                    //Goi ham xoa
                    BUSAlbum BUSAlbum = new BUSAlbum();
                    if (BUSAlbum.Xoa(mahoatdong) == 0)
                    {
                        //Thong bao
                        lbThongBao.Text = "Xóa Thành Công";
                        lbThongBao.Visible = true;
                        Response.Redirect("HoatDong.aspx");
                    }
                    else
                    {
                        lbThongBao.Text = "Xóa Không Thành Công";
                        lbThongBao.Visible = true;
                    }
                }
                else
                {
                    Response.Redirect("HoatDong.aspx");
                }
            }

            catch
            {
                lbThongBao.Text = "Xoa Không Thành Công";
                lbThongBao.Visible = true;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Thong tin nguoi dung
            NGUOIDUNG a = new NGUOIDUNG();
            a.MaNguoiDung  = 1;
            Session["NGUOIDUNG"] = a;

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

                //lay thong tin va load len cac textbox
                BUSAlbum BUSAlbum = new BUSAlbum();
                ALBUM lpDTO = BUSAlbum.TimKiem(mahoatdong);
                this.txtmaalbum.Text = Convert.ToString(lpDTO.MaAlbum);
                this.txttenalbum.Text = lpDTO.TenAlbum ;
            }
        }