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

            GetParameters(entity, dict);

            string strSQL = "insert into IncludeFile (" +
                            "ID," +
                            "Name," +
                            "Description," +
                            "IncludeType," +
                            "AssociateType," +
                            "FileName," +
                            "Template) " +
                            "values(" +
                            "@ID," +
                            "@Name," +
                            "@Description," +
                            "@IncludeType," +
                            "@AssociateType," +
                            "@FileName," +
                            "@Template)";

            if (await Task.Run(() => _DB.ExeSQLResult(strSQL, dict)))
            {
                return(DataConverter.CLng(entity.ID));
            }
            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// 增加一条记录
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual bool Add(IncludeFileEntity entity)
        {
            if (entity.ID <= 0)
            {
                entity.ID = GetNewID();
            }
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);

            string strSQL = "insert into IncludeFile (" +
                            "ID," +
                            "Name," +
                            "Description," +
                            "IncludeType," +
                            "AssociateType," +
                            "FileName," +
                            "Template) " +
                            "values(" +
                            "@ID," +
                            "@Name," +
                            "@Description," +
                            "@IncludeType," +
                            "@AssociateType," +
                            "@FileName," +
                            "@Template)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Esempio n. 3
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(IncludeFileEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("ID", entity.ID);
     dict.Add("Name", entity.Name);
     dict.Add("Description", entity.Description);
     dict.Add("IncludeType", entity.IncludeType);
     dict.Add("AssociateType", entity.AssociateType);
     dict.Add("FileName", entity.FileName);
     dict.Add("Template", entity.Template);
 }
Esempio n. 4
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static IncludeFileEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            IncludeFileEntity info = new IncludeFileEntity();

            info.ID            = rdr.GetInt32("ID");
            info.Name          = rdr.GetString("Name");
            info.Description   = rdr.GetString("Description");
            info.IncludeType   = rdr.GetInt32("IncludeType");
            info.AssociateType = rdr.GetInt32("AssociateType");
            info.FileName      = rdr.GetString("FileName");
            info.Template      = rdr.GetString("Template");
            return(info);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <IncludeFileEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            IncludeFileEntity obj    = null;
            string            strSQL = "select top 1 * from IncludeFile where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Esempio n. 6
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(IncludeFileEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update IncludeFile SET " +
                            "Name = @Name," +
                            "Description = @Description," +
                            "IncludeType = @IncludeType," +
                            "AssociateType = @AssociateType," +
                            "FileName = @FileName," +
                            "Template = @Template" +
                            " WHERE " +

                            "ID = @ID";

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