Exemple #1
0
        /// <summary>
        ///Save,保存方法,先删除,再增加
        /// </summary>
        public void Save(t_wx_user model, SqlTransaction tran = null, params string[] str)
        {
            string        tran_flag = "1";
            SqlConnection conn      = new SqlConnection(Dal.DataHelper.constr);

            conn.Open();
            if (tran == null)
            {
                tran_flag = "0";
                tran      = conn.BeginTransaction();
            }
            try
            {
                Delete(model, tran, str);
                Add(model, tran);

                //如果传入事物,提交否则外层提交
                if (tran_flag == "0")
                {
                    tran.Commit();
                    conn.Close();
                }
            }
            catch (Exception e)
            {
                if (tran_flag == "0")
                {
                    tran.Rollback();
                    conn.Close();
                }
                throw e;
            }
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public override void Add(dynamic obj, SqlTransaction tran = null)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_wx_user(");
            strSql.Append("groupid,ts,cdefine1,cdefine2,cdefine3,cdefine4,cdefine5,wxgzh,openid,nickname,sex,city,country,province,remark");
            strSql.Append(") values (");
            strSql.Append("@groupid,@ts,@cdefine1,@cdefine2,@cdefine3,@cdefine4,@cdefine5,@wxgzh,@openid,@nickname,@sex,@city,@country,@province,@remark");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@groupid",  SqlDbType.VarChar, 100),
                new SqlParameter("@ts",       SqlDbType.VarChar,  30),
                new SqlParameter("@cdefine1", SqlDbType.VarChar, 100),
                new SqlParameter("@cdefine2", SqlDbType.VarChar, 100),
                new SqlParameter("@cdefine3", SqlDbType.VarChar, 100),
                new SqlParameter("@cdefine4", SqlDbType.VarChar, 100),
                new SqlParameter("@cdefine5", SqlDbType.VarChar, 100),
                new SqlParameter("@wxgzh",    SqlDbType.VarChar, 100),
                new SqlParameter("@openid",   SqlDbType.VarChar, 100),
                new SqlParameter("@nickname", SqlDbType.VarChar, 100),
                new SqlParameter("@sex",      SqlDbType.VarChar, 100),
                new SqlParameter("@city",     SqlDbType.VarChar, 100),
                new SqlParameter("@country",  SqlDbType.VarChar, 100),
                new SqlParameter("@province", SqlDbType.VarChar, 100),
                new SqlParameter("@remark",   SqlDbType.VarChar, 100)
            };
            t_wx_user model = (t_wx_user)obj;

            parameters[0].Value  = SqlNull(model.groupid);
            parameters[1].Value  = SqlNull(model.ts);
            parameters[2].Value  = SqlNull(model.cdefine1);
            parameters[3].Value  = SqlNull(model.cdefine2);
            parameters[4].Value  = SqlNull(model.cdefine3);
            parameters[5].Value  = SqlNull(model.cdefine4);
            parameters[6].Value  = SqlNull(model.cdefine5);
            parameters[7].Value  = SqlNull(model.wxgzh);
            parameters[8].Value  = SqlNull(model.openid);
            parameters[9].Value  = SqlNull(model.nickname);
            parameters[10].Value = SqlNull(model.sex);
            parameters[11].Value = SqlNull(model.city);
            parameters[12].Value = SqlNull(model.country);
            parameters[13].Value = SqlNull(model.province);
            parameters[14].Value = SqlNull(model.remark);
            if (tran == null)
            {
                DataHelper.ExcuteNonQuery(strSql.ToString(), parameters, false);
            }
            else
            {
                DataHelper.ExcuteNonQuery(strSql.ToString(), tran, parameters, false);
            }
        }
Exemple #3
0
        public string getWXUser()
        {
            //获取微信关注列表
            wx_user list2 = new Bll.wx.wx().GetWXUser_list();

            if (string.IsNullOrEmpty(list2.count))
            {
                list2.count = "0";
            }
            if (int.Parse(list2.count) < 1)
            {
                return("获取列表失败,或者没有关注者");
            }

            List <t_wx_user> list = new List <t_wx_user>();

            //获取用户详情
            foreach (var i in list2.data.openid)
            {
                wx_user_detail wxuser = new Bll.wx.wx().GetWXUser_detail(i);

                t_wx_user model = new t_wx_user();
                model.wxgzh    = "xxkj";
                model.openid   = wxuser.openid;
                model.nickname = wxuser.nickname;
                model.sex      = wxuser.sex;
                model.city     = wxuser.city;
                model.country  = wxuser.country;
                model.province = wxuser.province;
                model.remark   = wxuser.remark;
                model.groupid  = wxuser.groupid;
                model.ts       = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                list.Add(model);
            }

            SqlConnection conn = new SqlConnection(Dal.DataHelper.constr);

            conn.Open();
            SqlTransaction tran = conn.BeginTransaction();

            try
            {
                //删除之前记录
                DataHelper.ExcuteNonQuery("delete from t_wx_user", tran, null, false);
                foreach (var i in list)
                {
                    new Dal.Basedata.t_wx_userDal().Add(i, tran);
                }

                tran.Commit();
                conn.Close();
                return("成功");
            }
            catch (Exception ex)
            {
                tran.Rollback();
                conn.Close();
                return(ex.Message);
            }
        }