/// <summary> /// 删除单条数据方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbtnDel_Click(object sender, CommandEventArgs e) { if (!string.IsNullOrEmpty(e.CommandName)) { var cmatt = cmattDAL.GetModel(Convert.ToInt32(e.CommandName), 1); if (cmatt != null) { string fileToBeDeleted = Server.MapPath(@"~/UploadFiles/" + cmatt.AttName); if (File.Exists(fileToBeDeleted)) { File.Delete(fileToBeDeleted); //此文件夹下的文件约100G } } List <SqlParameter> parameters = new List <SqlParameter>(); string SqlWhere = " AID in (select * from dbo.SplitToTable('" + e.CommandName + "',','))"; DataSet dtArea = cmAreaDAL.GetList(SqlWhere, parameters); if (dtArea != null) { if (dtArea.Tables[0].Rows.Count > 0) { cmAreaDAL.DeleteList(e.CommandName); } } ECommerce.CM.DAL.CMPro cmProDal = new ECommerce.CM.DAL.CMPro(); string strWhere = "AID in (select * from dbo.SplitToTable('" + e.CommandName + "',','))"; cmProDal.DeletePro(strWhere); cmAreaDAL.DeleteList(e.CommandName); var res = aDAL.DelArticleTran(Convert.ToInt32(e.CommandName)); if (res) { DataBingList(false); } else { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('删除失败!');</script>"); } } else { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('操作失败!');</script>"); } }
/// <summary> /// 批量删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btndelList_Click(object sender, EventArgs e) { try { bool res = false; #region 获取删除商品Id int i = 0; string delStr = ""; foreach (RepeaterItem item in rptArticle.Items) { CheckBox cb = (CheckBox)item.FindControl("cbSelect"); if (cb == null || !cb.Checked) continue; i++; var litId = cb.ToolTip; if (litId != null) { delStr += litId + ","; //将Id拼接在一起形成字符串 } } #endregion if (i == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择您要操作的数据!');</script>"); } if (delStr != "") { var delAid = delStr.Substring(0, delStr.Length - 1).Split(','); if (delAid.Length > 0) { for (int j = 0; j < delAid.Length; j++) { var cmatt = cmattDAL.GetModel(Convert.ToInt32(delAid[j]), 1); if (cmatt != null) { string fileToBeDeleted = Server.MapPath(@"~/UploadFiles/" + cmatt.AttName); if (File.Exists(fileToBeDeleted)) { File.Delete(fileToBeDeleted); //此文件夹下的文件约100G } } } } List<SqlParameter> parameters = new List<SqlParameter>(); string SqlWhere = " AID in (select * from dbo.SplitToTable('" + delStr.Substring(0, delStr.Length - 1) + "',','))"; DataSet dtArea = cmAreaDAL.GetList(SqlWhere, parameters); if (dtArea != null) { if (dtArea.Tables[0].Rows.Count > 0) { cmAreaDAL.DeleteList(delStr.Substring(0, delStr.Length - 1)); } } ECommerce.CM.DAL.CMPro cmProDal = new ECommerce.CM.DAL.CMPro(); string strWhere = "AID in (select * from dbo.SplitToTable('" + delStr.Substring(0, delStr.Length - 1) + "',','))"; cmProDal.DeletePro(strWhere); res = aDAL.DeleteArt(delStr.Substring(0, delStr.Length - 1)); //删除商品方法 } if (res) { //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');</script>"); DataBingList(false); //商品列表绑定方法参数商品名称 } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');</script>"); } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');</script>"); } }
/// <summary> /// 批量删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btndelList_Click(object sender, EventArgs e) { try { bool res = false; #region 获取删除商品Id int i = 0; string delStr = ""; foreach (RepeaterItem item in rptArticle.Items) { CheckBox cb = (CheckBox)item.FindControl("cbSelect"); if (cb == null || !cb.Checked) { continue; } i++; var litId = cb.ToolTip; if (litId != null) { delStr += litId + ","; //将Id拼接在一起形成字符串 } } #endregion if (i == 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择您要操作的数据!');</script>"); } if (delStr != "") { var delAid = delStr.Substring(0, delStr.Length - 1).Split(','); if (delAid.Length > 0) { for (int j = 0; j < delAid.Length; j++) { var cmatt = cmattDAL.GetModel(Convert.ToInt32(delAid[j]), 1); if (cmatt != null) { string fileToBeDeleted = Server.MapPath(@"~/UploadFiles/" + cmatt.AttName); if (File.Exists(fileToBeDeleted)) { File.Delete(fileToBeDeleted); //此文件夹下的文件约100G } } } } List <SqlParameter> parameters = new List <SqlParameter>(); string SqlWhere = " AID in (select * from dbo.SplitToTable('" + delStr.Substring(0, delStr.Length - 1) + "',','))"; DataSet dtArea = cmAreaDAL.GetList(SqlWhere, parameters); if (dtArea != null) { if (dtArea.Tables[0].Rows.Count > 0) { cmAreaDAL.DeleteList(delStr.Substring(0, delStr.Length - 1)); } } ECommerce.CM.DAL.CMPro cmProDal = new ECommerce.CM.DAL.CMPro(); string strWhere = "AID in (select * from dbo.SplitToTable('" + delStr.Substring(0, delStr.Length - 1) + "',','))"; cmProDal.DeletePro(strWhere); res = aDAL.DeleteArt(delStr.Substring(0, delStr.Length - 1)); //删除商品方法 } if (res) { //Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功!');</script>"); DataBingList(false); //商品列表绑定方法参数商品名称 } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');</script>"); } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败!');</script>"); } }
/// <summary> /// 删除单条数据方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbtnDel_Click(object sender, CommandEventArgs e) { if (!string.IsNullOrEmpty(e.CommandName)) { var cmatt = cmattDAL.GetModel(Convert.ToInt32(e.CommandName), 1); if (cmatt != null) { string fileToBeDeleted = Server.MapPath(@"~/UploadFiles/" + cmatt.AttName); if (File.Exists(fileToBeDeleted)) { File.Delete(fileToBeDeleted); //此文件夹下的文件约100G } } List<SqlParameter> parameters = new List<SqlParameter>(); string SqlWhere = " AID in (select * from dbo.SplitToTable('" + e.CommandName + "',','))"; DataSet dtArea = cmAreaDAL.GetList(SqlWhere, parameters); if (dtArea != null) { if (dtArea.Tables[0].Rows.Count > 0) { cmAreaDAL.DeleteList(e.CommandName); } } ECommerce.CM.DAL.CMPro cmProDal = new ECommerce.CM.DAL.CMPro(); string strWhere = "AID in (select * from dbo.SplitToTable('" + e.CommandName + "',','))"; cmProDal.DeletePro(strWhere); cmAreaDAL.DeleteList(e.CommandName); var res = aDAL.DelArticleTran(Convert.ToInt32(e.CommandName)); if (res) { DataBingList(false); } else { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('删除失败!');</script>"); } } else { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('操作失败!');</script>"); } }