Пример #1
0
        /// <summary>
        /// 增加一条记录,返回新的ID号。需要有一个单一主键,并且开启有标识符属性(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <int> InsertAsync(StatVisitEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into StatVisit (" +
                            "D1," +
                            "D2," +
                            "D3," +
                            "D4," +
                            "D5," +
                            "D6," +
                            "D7," +
                            "D8," +
                            "D9," +
                            "D10) " +
                            "values(" +
                            "@D1," +
                            "@D2," +
                            "@D3," +
                            "@D4," +
                            "@D5," +
                            "@D6," +
                            "@D7," +
                            "@D8," +
                            "@D9," +
                            "@D10)";

            return(await Task.Run(() => _DB.ReturnID(strSQL, dict)));
        }
Пример #2
0
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Add(StatVisitEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into StatVisit (" +
                            "D1," +
                            "D2," +
                            "D3," +
                            "D4," +
                            "D5," +
                            "D6," +
                            "D7," +
                            "D8," +
                            "D9," +
                            "D10) " +
                            "values(" +
                            "@D1," +
                            "@D2," +
                            "@D3," +
                            "@D4," +
                            "@D5," +
                            "@D6," +
                            "@D7," +
                            "@D8," +
                            "@D9," +
                            "@D10)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Пример #3
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(StatVisitEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("ID", entity.ID);
     dict.Add("D1", entity.D1);
     dict.Add("D2", entity.D2);
     dict.Add("D3", entity.D3);
     dict.Add("D4", entity.D4);
     dict.Add("D5", entity.D5);
     dict.Add("D6", entity.D6);
     dict.Add("D7", entity.D7);
     dict.Add("D8", entity.D8);
     dict.Add("D9", entity.D9);
     dict.Add("D10", entity.D10);
 }
Пример #4
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <StatVisitEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            StatVisitEntity obj    = null;
            string          strSQL = "select top 1 * from StatVisit where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Пример #5
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static StatVisitEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            StatVisitEntity info = new StatVisitEntity();

            info.ID  = rdr.GetInt32("ID");
            info.D1  = rdr.GetInt32("D1");
            info.D2  = rdr.GetInt32("D2");
            info.D3  = rdr.GetInt32("D3");
            info.D4  = rdr.GetInt32("D4");
            info.D5  = rdr.GetInt32("D5");
            info.D6  = rdr.GetInt32("D6");
            info.D7  = rdr.GetInt32("D7");
            info.D8  = rdr.GetInt32("D8");
            info.D9  = rdr.GetInt32("D9");
            info.D10 = rdr.GetInt32("D10");
            return(info);
        }
Пример #6
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(StatVisitEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update StatVisit SET " +
                            "D1 = @D1," +
                            "D2 = @D2," +
                            "D3 = @D3," +
                            "D4 = @D4," +
                            "D5 = @D5," +
                            "D6 = @D6," +
                            "D7 = @D7," +
                            "D8 = @D8," +
                            "D9 = @D9," +
                            "D10 = @D10" +
                            " WHERE " +

                            "ID = @ID";

            return(await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)));
        }
Пример #7
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(StatVisitEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Пример #8
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(StatVisitEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }