Exemplo n.º 1
0
        /// <summary>
        /// 增加一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> AddAsync(U_UserTextEntity entity)
        {
            if (entity.ID <= 0)
            {
                entity.ID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into U_UserText (" +
                            "ID," +
                            "Nominate," +
                            "RegIP," +
                            "QQOpenID," +
                            "QQWeiboOpenID," +
                            "RenrenOpenID," +
                            "SinaOpenID," +
                            "SharingRatio," +
                            "WxOpenID) " +
                            "values(" +
                            "@ID," +
                            "@Nominate," +
                            "@RegIP," +
                            "@QQOpenID," +
                            "@QQWeiboOpenID," +
                            "@RenrenOpenID," +
                            "@SinaOpenID," +
                            "@SharingRatio," +
                            "@WxOpenID)";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemplo n.º 2
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(U_UserTextEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("ID", entity.ID);
     dict.Add("Nominate", entity.Nominate);
     dict.Add("RegIP", entity.RegIP);
     dict.Add("QQOpenID", entity.QQOpenID);
     dict.Add("QQWeiboOpenID", entity.QQWeiboOpenID);
     dict.Add("RenrenOpenID", entity.RenrenOpenID);
     dict.Add("SinaOpenID", entity.SinaOpenID);
     dict.Add("SharingRatio", entity.SharingRatio);
     dict.Add("WxOpenID", entity.WxOpenID);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <U_UserTextEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            U_UserTextEntity obj    = null;
            string           strSQL = "select top 1 * from U_UserText where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static U_UserTextEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            U_UserTextEntity info = new U_UserTextEntity();

            info.ID            = rdr.GetInt32("ID");
            info.Nominate      = rdr.GetString("Nominate");
            info.RegIP         = rdr.GetString("RegIP");
            info.QQOpenID      = rdr.GetString("QQOpenID");
            info.QQWeiboOpenID = rdr.GetString("QQWeiboOpenID");
            info.RenrenOpenID  = rdr.GetString("RenrenOpenID");
            info.SinaOpenID    = rdr.GetString("SinaOpenID");
            info.SharingRatio  = rdr.GetDouble("SharingRatio");
            info.WxOpenID      = rdr.GetString("WxOpenID");
            return(info);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(U_UserTextEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update U_UserText SET " +
                            "Nominate = @Nominate," +
                            "RegIP = @RegIP," +
                            "QQOpenID = @QQOpenID," +
                            "QQWeiboOpenID = @QQWeiboOpenID," +
                            "RenrenOpenID = @RenrenOpenID," +
                            "SinaOpenID = @SinaOpenID," +
                            "SharingRatio = @SharingRatio," +
                            "WxOpenID = @WxOpenID" +
                            " WHERE " +

                            "ID = @ID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual int Insert(U_UserTextEntity entity)
        {
            if (entity.ID <= 0)
            {
                entity.ID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into U_UserText (" +
                            "ID," +
                            "Nominate," +
                            "RegIP," +
                            "QQOpenID," +
                            "QQWeiboOpenID," +
                            "RenrenOpenID," +
                            "SinaOpenID," +
                            "SharingRatio," +
                            "WxOpenID) " +
                            "values(" +
                            "@ID," +
                            "@Nominate," +
                            "@RegIP," +
                            "@QQOpenID," +
                            "@QQWeiboOpenID," +
                            "@RenrenOpenID," +
                            "@SinaOpenID," +
                            "@SharingRatio," +
                            "@WxOpenID)";

            if (_DB.ExeSQLResult(strSQL, dict))
            {
                return(DataConverter.CLng(entity.ID));
            }
            return(-1);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(U_UserTextEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Exemplo n.º 8
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(U_UserTextEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }