Exemple #1
0
        //同步
        protected void btnSyn_Click(object sender, EventArgs e)
        {
            string err = "";

            Model.wx_userweixin weixin = GetWeiXinCode();
            WeiXinCRMComm       wcr    = new WeiXinCRMComm();
            string accessToken         = wcr.getAccessToken(weixin.id, out err);

            if (err != "")
            {
                return;
            }
            GroupsJson gJson            = Groups.Get(accessToken);
            List <GroupsJson_Group> gjg = gJson.groups;

            #region   将数据插入到数据库里
            BLL.wx_crm_group   gBll  = new BLL.wx_crm_group();
            Model.wx_crm_group group = new Model.wx_crm_group();
            try
            {
                gBll.DeleteByWid(weixin.id);

                int ttCount     = gjg.Count;
                int insertCount = 0;
                for (int i = 0; i < gjg.Count; i++)
                {
                    group.id    = gjg[i].id;
                    group.name  = gjg[i].name;
                    group.count = gjg[i].count;
                    group.wid   = weixin.id;
                    bool succ = gBll.Add(group);
                    if (succ)
                    {
                        insertCount++;
                    }
                }
                if (ttCount == insertCount)
                {
                    //将此次同步的日期更新到设置表里
                    BLL.wx_crm_setting setBll = new BLL.wx_crm_setting();
                    setBll.UpdateGroupSysDate(weixin.id, ttCount, DateTime.Now);
                    JscriptMsg("分组同步成功!", "group_list.aspx", "Success");
                }
                else
                {
                    JscriptMsg("分组同步失败!", "", "Error");
                    return;
                }
            }
            catch (Exception ex)
            {
                JscriptMsg("分组同步失败!" + ex.Message, "", "Error");
                return;
            }
            #endregion
        }