Exemple #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            //依据词组
            if (dd_groups.SelectedIndex == 0)
            {
                Message.Alert(this, "请选择一个词组", "null");
                return;
            }
            List <SMSModel.Keywords> list = new List <SMSModel.Keywords>();
            string keywords = txt_keywords.Text.Trim();

            foreach (string s in keywords.Split(','))
            {
                SMSModel.Keywords keyword = new SMSModel.Keywords();
                keyword.Enable          = rb_status.SelectedValue == "1" ? true : false;
                keyword.KeyGroup        = dd_groups.SelectedValue;
                keyword.KeywordsType    = rb_types.SelectedValue == "-1" ? "" : rb_types.SelectedValue;
                keyword.ReplaceKeywords = txt_other.Text.Trim();
                keyword.Words           = s;
                if (!string.IsNullOrEmpty(keyword.Words))
                {
                    list.Add(keyword);
                }
            }
            if (list.Count == 0)
            {
                Message.Alert(this, "请添加敏感词", "null");
                return;
            }
            SMSModel.RPCResult r = ZHSMSProxy.GetZHSMSPlatService().AddKeywords(dd_groups.SelectedValue, list);
            if (r.Success)
            {
                load();
                Message.Success(this, "添加成功", "null");
            }
            else
            {
                Message.Alert(this, r.Message, "null");
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (dd_groups.SelectedIndex == 0)
                {
                    Message.Alert(this, "请选择一个敏感词组", "null");
                    return;
                }
                string path = this.FileUpload1.PostedFile.FileName;
                if (path == "" || path == null)
                {
                    Message.Alert(this, "请选择一个文件,文件格式为txt", "null");
                    return;
                }
                if (System.IO.Path.GetExtension(FileUpload1.FileName).ToLower() != ".txt")
                {
                    Message.Alert(this, "文件格式为txt", "null");
                    return;
                }
                path = Server.MapPath("~/Temp/") + FileUpload1.FileName;
                FileUpload1.PostedFile.SaveAs(path);
                DataTable dt = CreateTable();
                using (StreamReader sr = new StreamReader(path))
                {
                    string str;
                    while ((str = sr.ReadLine()) != null)
                    {
                        if (str != "")
                        {
                            DataRow  dr  = dt.NewRow();
                            string[] arr = str.Split(',');
                            if (arr.Length >= 2)
                            {
                                if (arr[0] != "")
                                {
                                    dr["keyword"] = arr[0];
                                    dr["other"]   = arr[1];
                                    dt.Rows.Add(dr);
                                }
                            }
                            else if (arr.Length == 1)
                            {
                                if (arr[0] != "")
                                {
                                    dr["keyword"] = arr[0];
                                    dr["other"]   = "";
                                    dt.Rows.Add(dr);
                                }
                            }
                        }
                    }
                }
                File.Delete(path);
                if (dt.Rows.Count == 0)
                {
                    Message.Alert(this, "文件是空的", "null");
                    return;
                }

                List <SMSModel.Keywords> list = new List <SMSModel.Keywords>();
                foreach (DataRow row in dt.Rows)
                {
                    SMSModel.Keywords keyword = new SMSModel.Keywords();
                    keyword.Enable          = rb_status.SelectedValue == "1" ? true : false;
                    keyword.KeyGroup        = dd_groups.SelectedValue;
                    keyword.KeywordsType    = rb_types.SelectedValue == "-1" ? "" : rb_types.SelectedValue;
                    keyword.ReplaceKeywords = row["other"].ToString();
                    keyword.Words           = row["keyword"].ToString();
                    if (!string.IsNullOrEmpty(keyword.Words))
                    {
                        list.Add(keyword);
                    }
                }
                if (list.Count == 0)
                {
                    Message.Alert(this, "请添加敏感词", "null");
                    return;
                }
                SMSModel.RPCResult r = ZHSMSProxy.GetZHSMSPlatService().AddKeywords(dd_groups.SelectedValue, list);
                if (r.Success)
                {
                    load();
                    Message.Success(this, "添加成功", "null");
                }
                else
                {
                    Message.Alert(this, r.Message, "null");
                }
            }
            catch
            {
                Message.Alert(this, "操作失败", "null");
            }
        }