예제 #1
0
        /// <summary>
        /// 添加
        /// </summary>
        private static string Add(HttpContext context)
        {
            //if (!_isedit)
            //{
            //    return null;
            //}

            try
            {
                //var userid = websiteOwner; //Comm.DataLoadTool.GetCurrUserID();
                //if (string.IsNullOrEmpty(userid))
                //{
                //    return "请重新登录";
                //}
                var keyword   = context.Request["MsgKeyword"];
                var matchtype = context.Request["MatchType"];
                if (!bll.CheckUserKeyword(websiteOwner, keyword))
                {
                    return("关键字重复");
                }
                var model = new WeixinReplyRuleInfo();
                model.MsgKeyword  = keyword;
                model.MatchType   = matchtype;
                model.ReceiveType = "news";
                model.ReplyType   = "news";
                model.CreateDate  = DateTime.Now;
                model.RuleType    = 1;
                var sourceIds = context.Request["SourceIds"];
                model.UID    = bll.GetGUID(BLLJIMP.TransacType.WeixinReplyRuleAdd);
                model.UserID = websiteOwner;
                WeixinReplyRuleImgsInfo ruleImgsInfo;
                if (bll.Add(model))//规则表添加成功,往图文表插入
                {
                    if (!string.IsNullOrEmpty(sourceIds))
                    {
                        foreach (var item in sourceIds.Split(','))
                        {
                            var sourceinfo = bll.Get <WeixinMsgSourceInfo>(string.Format("SourceID='{0}'", item));
                            ruleImgsInfo             = new WeixinReplyRuleImgsInfo();
                            ruleImgsInfo.UID         = bll.GetGUID(BLLJIMP.TransacType.WeixinReplyRuleImgAdd);
                            ruleImgsInfo.RuleID      = model.UID;
                            ruleImgsInfo.Title       = sourceinfo.Title;
                            ruleImgsInfo.Description = sourceinfo.Description;
                            ruleImgsInfo.PicUrl      = sourceinfo.PicUrl;
                            ruleImgsInfo.Url         = sourceinfo.Url;
                            bll.Add(ruleImgsInfo);
                        }
                        return("true");
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("false");
        }
예제 #2
0
        private static string Edit(HttpContext context)
        {
            //if (!_isedit)
            //{
            //    return null;
            //}

            try
            {
                var uid = context.Request["UID"];
                //if (string.IsNullOrEmpty(userid))
                //{
                //    return "请重新登录";
                //}
                var keyword   = context.Request["MsgKeyword"];
                var matchType = context.Request["MatchType"];
                var oldInfo   = bll.Get <WeixinReplyRuleInfo>(string.Format("UID={0}", uid));
                if (oldInfo.MsgKeyword != keyword)//对比关键字已经改变
                {
                    //关键字改变,检查关键字是否重复
                    if (!bll.CheckUserKeyword(websiteOwner, keyword))
                    {
                        return("关键字重复");
                    }
                }
                var sourceType = context.Request["SourceType"];
                var sourceIds  = context.Request["SourceIds"];
                var model      = new WeixinReplyRuleInfo();
                model.UID         = uid;
                model.MsgKeyword  = keyword;
                model.MatchType   = matchType;
                model.ReceiveType = "news";
                model.ReplyType   = "news";
                model.RuleType    = 1;
                model.UID         = context.Request["UID"];
                model.UserID      = websiteOwner;
                WeixinReplyRuleImgsInfo ruleImgsInfo;
                if (bll.Update(model))//规则表更新成功,更新图文表信息
                {
                    if (!string.IsNullOrEmpty(sourceIds))
                    {
                        if (sourceType.Equals("imagelist"))//原有的图文表
                        {
                            //更新图文列表
                            bll.Delete(new WeixinReplyRuleImgsInfo(), string.Format("RuleID='{0}' And UID Not IN ({1})", uid, sourceIds));
                            return("true");
                        }
                        else if (sourceType.Equals("source"))//从素材表中选择
                        {
                            //删除旧图片
                            bll.Delete(new WeixinReplyRuleImgsInfo(), string.Format("RuleID='{0}'", uid));
                            //添加新图片
                            foreach (var item in sourceIds.Split(','))
                            {
                                var sourceInfo = bll.Get <WeixinMsgSourceInfo>(string.Format("SourceID='{0}'", item));
                                ruleImgsInfo             = new WeixinReplyRuleImgsInfo();
                                ruleImgsInfo.UID         = bll.GetGUID(BLLJIMP.TransacType.WeixinReplyRuleImgAdd);
                                ruleImgsInfo.RuleID      = model.UID;
                                ruleImgsInfo.Title       = sourceInfo.Title;
                                ruleImgsInfo.Description = sourceInfo.Description;
                                ruleImgsInfo.PicUrl      = sourceInfo.PicUrl;
                                ruleImgsInfo.Url         = sourceInfo.Url;
                                bll.Add(ruleImgsInfo);
                            }
                            return("true");
                        }
                    }
                    else
                    {
                        return("请选择素材");
                    }
                }
                else
                {
                    return("更新规则表失败");
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("false");
        }
예제 #3
0
        /// <summary>
        /// 保存规则
        /// </summary>
        private void SaveRule()
        {
            WeixinReplyRuleInfo model = new WeixinReplyRuleInfo();

            model.MsgKeyword = this.txtKeyWord.Text.Trim();

            if (CheckIsEmpty(model.MsgKeyword, "关键字不能为空!"))
            {
                this.txtKeyWord.Focus();
                return;
            }

            //判断关键字不能重复
            if (this.weixinBll.Exists(model, "MsgKeyword"))
            {
                this.ShowMessge("该关键字已经存在!");
                return;
            }

            switch (this.rdoListReplyType.SelectedItem.Text)
            {
            case "文本":
                model.ReplyContent = this.txtTextContent.Text.Trim();
                if (CheckIsEmpty(model.ReplyContent, "回复内容不能为空!"))
                {
                    this.txtTextContent.Focus();
                    return;
                }
                model.ReplyType = "text";
                model.UID       = this.weixinBll.GetGUID(TransacType.WeixinReplyRuleAdd);

                break;

            case "图文":
                model.ReplyType = "news";
                // 保存图文
                List <BLLJIMP.Model.Weixin.Article> imgList = this.GetVistateImgList();

                if (imgList.Count <= 0)
                {
                    this.ShowMessge("图文消息图片数量不能为 0 !");
                    return;
                }
                model.UID = this.weixinBll.GetGUID(TransacType.WeixinReplyRuleAdd);

                List <WeixinReplyRuleImgsInfo> imgModelList = new List <WeixinReplyRuleImgsInfo>();
                int tmpOrderIndex = 0;
                foreach (var item in imgList)
                {
                    WeixinReplyRuleImgsInfo imgModel = new WeixinReplyRuleImgsInfo();
                    imgModel.UID         = this.weixinBll.GetGUID(TransacType.WeixinReplyRuleImgAdd);
                    imgModel.RuleID      = model.UID;
                    imgModel.Description = item.Description;
                    imgModel.OrderIndex  = tmpOrderIndex;
                    imgModel.PicUrl      = item.PicUrl;
                    imgModel.Title       = item.Title;
                    imgModel.Url         = item.Url;
                    tmpOrderIndex++;
                    imgModelList.Add(imgModel);
                }

                if (!this.weixinBll.AddList <WeixinReplyRuleImgsInfo>(imgModelList))
                {
                    this.ShowMessge("保存图片失败!");
                    return;
                }

                break;

            default:
                break;
            }


            model.UserID      = this.userInfo.UserID;
            model.ReceiveType = "text";//目前默认只接收文本推送信息处理
            model.MatchType   = this.ddlMatchType.SelectedItem.Text;
            model.CreateDate  = DateTime.Now;

            if (this.weixinBll.Add(model))
            {
                //this.ShowMessge("添加成功!");

                this.ViewState["imgData"] = null;

                this.LoadData();

                this.ClearAddPanel();
                //this.HideAddPanel();
            }
            else
            {
                this.ShowMessge("添加失败!");
            }
        }