protected void btnDelete_Click(object sender, EventArgs e) { ArrayList ar = new ArrayList(); foreach (DataGridItem m_Item in dgrListAppro.Items) { CheckBox chk_Select = (CheckBox)m_Item.FindControl("optSelect"); if (chk_Select != null && chk_Select.Checked) { ar.Add(double.Parse(dgrListAppro.DataKeys[int.Parse(m_Item.ItemIndex.ToString())].ToString())); } } if (ar.Count > 0) { for (int i = 0; i < ar.Count; i++) { int _ID = int.Parse(ar[i].ToString()); AnhDAL _DAL = new AnhDAL(); _DAL.DeleteFromT_Anh(_ID); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "alert('Chưa chọn ảnh muốn xóa.!!')", true); return; } LoadDataApprovied(); }
protected void btnXoaAnh_Click(object sender, EventArgs e) { AnhDAL _dalanh = new AnhDAL(); string SqlUpdate = string.Empty; foreach (DataListItem m_Item in dgrListImages.Items) { int _ID = int.Parse(this.dgrListImages.DataKeys[m_Item.ItemIndex].ToString()); CheckBox chk_Select = (CheckBox)m_Item.FindControl("optSelect"); Label lbFileAttach = m_Item.FindControl("lbFileAttach") as Label; if (chk_Select != null && chk_Select.Checked) { _dalanh.DeleteFromT_Anh(_ID); string path = HttpContext.Current.Server.MapPath("/" + System.Configuration.ConfigurationManager.AppSettings["viewimg"].ToString() + lbFileAttach.Text); System.IO.FileInfo fi = new System.IO.FileInfo(path); try { if (File.Exists(path)) { fi.Delete(); } } catch (Exception ex) { throw ex; } } } LoadDataImage(); }
public void dgrListAppro_EditCommand(object source, DataGridCommandEventArgs e) { if (e.CommandArgument.ToString().ToLower() == "edit") { dgrListAppro.EditItemIndex = e.Item.ItemIndex; LoadDataApprovied(); } if (e.CommandArgument.ToString().ToLower() == "delete") { AnhDAL _DAL = new AnhDAL(); int _ID = Convert.ToInt32(dgrListAppro.DataKeys[e.Item.ItemIndex].ToString()); _DAL.DeleteFromT_Anh(_ID); LoadDataApprovied(); } }
public void dgrListImages_EditCommand(object source, DataListCommandEventArgs e) { ImageButton btnAdd = e.Item.FindControl("btnAdd") as ImageButton; ImageButton btnUpdate = e.Item.FindControl("btnUpdate") as ImageButton; ImageButton btnCancel = e.Item.FindControl("btnCancel") as ImageButton; ImageButton btndelete = e.Item.FindControl("Imagebuttondelete") as ImageButton; TextBox txtTacgia = e.Item.FindControl("txtTacgia") as TextBox; TextBox hdnValueTacGiaAnh = e.Item.FindControl("hdnValueTacGiaAnh") as TextBox; TextBox txtChuthich = e.Item.FindControl("txtChuthich") as TextBox; Label lbdesc = e.Item.FindControl("lbdesc") as Label; Label lbtacgia = e.Item.FindControl("lbtacgia") as Label; int _ID = Convert.ToInt32(dgrListImages.DataKeys[e.Item.ItemIndex].ToString()); _objimg = _dalanh.GetOneFromT_AnhByID(_ID); if (e.CommandArgument.ToString().ToLower() == "delete") { Label lbFileAttach = e.Item.FindControl("lbFileAttach") as Label; string path = HttpContext.Current.Server.MapPath("/" + System.Configuration.ConfigurationManager.AppSettings["viewimg"].ToString() + lbFileAttach.Text); System.IO.FileInfo fi = new System.IO.FileInfo(path); try { if (File.Exists(path)) { fi.Delete(); } } catch (Exception ex) { throw ex; } _dalanh.DeleteFromT_Anh(_ID); string thaotac = "Thao tác xóa ảnh đính kèm: " + _objimg.Duongdan_Anh + " tại " + Request["MaDoiTuong"].ToString() + " thuộc tin bài: " + Txt_tieude.Text.Trim(); UltilFunc.Log_Action(_user.UserID, _user.UserName, DateTime.Now, int.Parse(Request["Menu_ID"].ToString()), thaotac); LoadDataImage(); } if (e.CommandArgument.ToString().ToLower() == "editinfo") { btndelete.Visible = false; btnAdd.Visible = false; btnUpdate.Visible = true; btnCancel.Visible = true; lbdesc.Visible = false; lbtacgia.Visible = false; txtTacgia.Visible = true; txtChuthich.Visible = true; if (_objimg != null && _objimg.Ma_Nguoichup != 0) { hdnValueTacGiaAnh.Text = _objimg.Ma_Nguoichup.ToString(); } else { hdnValueTacGiaAnh.Text = ""; } if (_objimg.NguoiChup != "") { txtTacgia.Text = _objimg.NguoiChup; } else { txtTacgia.Text = ""; } if (_objimg.Chuthich.Length > 0) { txtChuthich.Text = _objimg.Chuthich; } else { txtChuthich.Text = ""; } } if (e.CommandArgument.ToString().ToLower() == "update") { string _chuthich = ""; string _tacgia = ""; int _tacgiaID = 0; if (txtChuthich.Text != "") { _chuthich = UltilFunc.RemoveEnterCode(txtChuthich.Text.Trim().Replace("'", "''")); } if (_objimg != null && _objimg.Ma_Nguoichup != 0) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = _objimg.Ma_Nguoichup; } if (!String.IsNullOrEmpty(hdnValueTacGiaAnh.Text)) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = int.Parse(hdnValueTacGiaAnh.Text.ToString()); } string SqlUpdate = ""; SqlUpdate = "update T_Anh set Chuthich=N'" + _chuthich + "',NguoiChup=N'" + _tacgia + "',Ma_Nguoichup=" + _tacgiaID + " where Ma_Anh=" + _ID; Ulti.ExecSql(SqlUpdate); LoadDataImage(); lbdesc.Text = txtChuthich.Text; lbtacgia.Text = txtTacgia.Text; btnAdd.Visible = true; btnUpdate.Visible = false; btnCancel.Visible = false; lbdesc.Visible = true; lbtacgia.Visible = true; txtChuthich.Visible = false; txtTacgia.Visible = false; } if (e.CommandArgument.ToString().ToLower() == "cancel") { btndelete.Visible = true; btnAdd.Visible = true; btnUpdate.Visible = false; btnCancel.Visible = false; lbdesc.Visible = true; lbtacgia.Visible = true; txtTacgia.Visible = false; txtChuthich.Visible = false; } }