protected void btnCreate_Click(object sender, EventArgs e) { mtvTheLoai.ActiveViewIndex = 1; clsTheLoai tl = new clsTheLoai(); tl.TenTheLoai = txtName.Text; tl.MoTa = txtMota.Text; tl.Hot = ckbHot.Checked; tl.Stt = Convert.ToInt32(txtViTri.Text); tl.Images = DateTime.Now.Second + fileUp.FileName; clsBSTheLoai bsTL = new clsBSTheLoai(); //if (fileUp.HasFile) //{ if (bsTL.InsertTL(tl)) { lblMes.Text = "<script>alert('Danh mục phụ đã được tạo');</script>"; mtvTheLoai.ActiveViewIndex = 0; grvTheLoai.DataBind(); //fileUp.SaveAs(Server.MapPath("~/Images/HinhAnh/") + DateTime.Now.Second + fileUp.FileName); } else { lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>"; } // } //else { // lblMes.Text = "<script>alert('Bạn chưa chọn hình ảnh !');</script>"; // } }
protected void btnEdit_Click(object sender, EventArgs e) { clsTheLoai tl = new clsTheLoai(); tl.TenTheLoai = txtNameEdit.Text; tl.MoTa = txtMotaEdit.Text; tl.Hot = ckbHotEdit.Checked; tl.Stt = Convert.ToInt32(txtViTriEdit.Text); tl.Id = Convert.ToInt32(hfID.Value); tl.Images = DateTime.Now.Second + fileEdit.FileName; clsBSTheLoai bsTL = new clsBSTheLoai(); int type = 2; //if (CheckBox1.Checked) //{ // type = 1; //} //else { // type = 2; //} if (bsTL.EditTL(tl,2)) { if (type==1) { //if (fileEdit.HasFile) //{ // //fileEdit.SaveAs(Server.MapPath("~/Images/HinhAnh/") + DateTime.Now.Second + fileUp.FileName); //} //else { // lblMes.Text = "<script>alert('Bạn chưa chọn file');</script>"; //} } lblMes.Text = "<script>alert('Danh mục phụ đã được sửa');</script>"; mtvTheLoai.ActiveViewIndex = 0; grvTheLoai.DataBind(); } else { lblMes.Text = "<script>alert('Lỗi, vui lòng kiểm tra dữ liệu !');</script>"; } }
protected void btnXoa_Click(object sender, EventArgs e) { LinkButton lbt = (LinkButton)sender; HiddenField h = (HiddenField)lbt.FindControl("hfID"); clsTheLoai tl = new clsTheLoai(); tl.Id = Convert.ToInt32(h.Value); clsBSTheLoai t = new clsBSTheLoai(); if (t.DelTL(tl)) { lblMes.Text = "<script>alert('Danh mục phụ đã được xóa');</script>"; mtvTheLoai.ActiveViewIndex = 0; grvTheLoai.DataBind(); } else { lblMes.Text = "<script>alert('Lỗi, không thể xóa !');</script>"; } }