protected void btnCapnhatSanpham_Click(object sender, EventArgs e) { long sanphamID = Convert.ToInt64(Request.QueryString[m_QUERYSUA]); try { lblRgexSanpham.Text = string.Empty; lblRegexUploadImage.Text = string.Empty; string tenSP = txtTensanpham.Text; string mota = txtMota.Text; if (string.IsNullOrEmpty(mota)) { mota = string.Empty; } string xuatxu = txtXuatxu.Text; string hinhanh = "hinhanhtest"; int loaispID = Convert.ToInt32(ddlLoaiSanpham.SelectedValue); SanphamController brlSanpham = new SanphamController(); brlSanpham.ValidateSanpham(sanphamID, tenSP, mota, xuatxu, hinhanh, loaispID); try { hinhanh = Luuhinhanh(hdImageUpload); } catch (Exception) { lblRegexUploadImage.Text = "Vui lòng chọn tệp hành ảnh với phần mở rộng là png,jpg,jpeg."; return; } if (string.IsNullOrEmpty(hinhanh)) { hinhanh = "hinhanhtest"; } brlSanpham.SuaSanpham(sanphamID, tenSP, mota, xuatxu, hinhanh, loaispID, cbIsNgungcungcap.Checked); hienthiDulieuKhiSuaSanpham(); Response.Write(@"<script language='javascript'>alert('Cập nhật thành công.');</script>"); } catch (ApplicationException ex) { lblRgexSanpham.Text = ex.Message; } }
protected void btnThemSanpham_Click(object sender, EventArgs e) { try { lblRgexSanpham.Text = string.Empty; lblRegexUploadImage.Text = string.Empty; string tenSP = txtTensanpham.Text; string mota = txtMota.Text; if (string.IsNullOrEmpty(mota)) { mota = string.Empty; } string xuatxu = txtXuatxu.Text; string hinhanh = string.IsNullOrEmpty(hdImageUpload.Value) ? string.Empty : "hinhanhtest"; int loaispID = Convert.ToInt32(ddlLoaiSanpham.SelectedValue); SanphamController brlSanpham = new SanphamController(); brlSanpham.ValidateSanpham(0, tenSP, mota, xuatxu, hinhanh, loaispID); try { hinhanh = Luuhinhanh(hdImageUpload); } catch (Exception) { lblRegexUploadImage.Text = "Vui lòng chọn tệp hành ảnh với phần mở rộng là png,jpg,jpeg."; return; } if (string.IsNullOrEmpty(hinhanh)) { lblRegexUploadImage.Text = "Vui lòng chọn tệp hành ảnh với phần mở rộng là png,jpg,jpeg."; return; } brlSanpham.ThemSanpham(tenSP, mota, xuatxu, hinhanh, loaispID); Response.Write(@"<script language='javascript'>alert('Thêm sản phẩm thành công.');</script>"); } catch (ApplicationException ex) { lblRgexSanpham.Text = ex.Message; } }