private void DelRec_Click(object sender, EventArgs e) { #region 除过滤词 if (this.CheckCookie()) { if (DNTRequest.GetString("id") != "") { BanWords.DeleteBanWords(DNTRequest.GetString("id")); Response.Redirect("global_wordgrid.aspx"); } else { base.RegisterStartupScript("", "<script>alert('您未选中任何选项');window.location.href='global_wordgrid.aspx';</script>"); } } #endregion }
private void addbadwords_Click(object sender, EventArgs e) { if (this.badwords.Text == "") { BindData(); return; } String[] badwords = getwords(); String[] filterwords; #region 根据radiobuttonlist选择条件 if (radfilter.SelectedValue == "0") { //清空当前词语表,再插入 string find = ""; string replacement = ""; string banWordsIdList = ""; foreach (DataRow dr in BanWords.GetBanWordList().Rows) { banWordsIdList += dr["id"].ToString() + ","; } if (banWordsIdList != "") { BanWords.DeleteBanWords(banWordsIdList.TrimEnd(',')); } for (int i = 0; i < badwords.Length; i++) { filterwords = badwords[i].Split('='); find = filterwords[0].ToString().Replace("\r", "").Trim(); if (!GetReplacement(badwords, filterwords, ref find, ref replacement)) { continue; } BanWords.CreateBanWord(username, find, replacement); } } if (radfilter.SelectedValue == "1") { //使用新的设置覆盖已经存在的词语 string find = ""; string replacement = ""; for (int i = 0; i < badwords.Length; i++) { filterwords = badwords[i].Split('='); find = filterwords[0].ToString().Replace("\r", "").Trim(); if (!GetReplacement(badwords, filterwords, ref find, ref replacement)) { continue; } BanWords.UpdateBadWords(find, replacement); } } if (radfilter.SelectedValue == "2") { //不导入已经存在的词语 string find = ""; string replacement = ""; DataTable dt = BanWords.GetBanWordList(); for (int i = 0; i < badwords.Length; i++) { #region //filterwords = badwords[i].Split('='); //find = filterwords[0].ToString().Replace("\r", "").Trim(); //#region //if (find == "") //{ // continue; //} //if (filterwords.Length == 2 && filterwords[1].ToString() != "") //{ // replacement = filterwords[1].ToString(); //} //else if (filterwords.Length < 2) //{ // replacement = "**"; //} //else//filterwords.Length > 2 的情况 //{ // replacement = filterwords[filterwords.Length - 1]; // filterwords.SetValue("", filterwords.Length - 1); // find = string.Join("=", filterwords); // find = find.Remove(find.Length - 2); //} //#endregion #endregion filterwords = badwords[i].Split('='); find = filterwords[0].ToString().Replace("\r", "").Trim(); if (!GetReplacement(badwords, filterwords, ref find, ref replacement)) { continue; } DataRow[] arrRow = dt.Select("find='" + find + "'"); if (arrRow.Length == 0) { BanWords.CreateBanWord(username, find, replacement); } } } #endregion BindData(); this.badwords.Text = ""; }