Ejemplo n.º 1
0
        /// <summary>
        /// 通过数据读取器生成实体类
        /// </summary>
        /// <param name="rdr"></param>
        /// <returns></returns>
        private static PresentEntity GetEntityFromrdr(NullableDataReader rdr)
        {
            PresentEntity info = new PresentEntity();

            info.PresentID        = rdr.GetInt32("PresentID");
            info.PresentName      = rdr.GetString("PresentName");
            info.PresentPic       = rdr.GetString("PresentPic");
            info.Unit             = rdr.GetString("Unit");
            info.PresentNum       = rdr.GetString("PresentNum");
            info.ServiceTermUnit  = rdr.GetInt32("ServiceTermUnit");
            info.ServiceTerm      = rdr.GetInt32("ServiceTerm");
            info.Price            = rdr.GetDecimal("Price");
            info.Price_Market     = rdr.GetDecimal("Price_Market");
            info.Weight           = rdr.GetDouble("Weight");
            info.Stocks           = rdr.GetInt32("Stocks");
            info.StocksProject    = rdr.GetInt32("StocksProject");
            info.OrderNum         = rdr.GetInt32("OrderNum");
            info.AlarmNum         = rdr.GetInt32("AlarmNum");
            info.ProductCharacter = rdr.GetInt32("ProductCharacter");
            info.DownloadUrl      = rdr.GetString("DownloadUrl");
            info.Remark           = rdr.GetString("Remark");
            info.PresentThumb     = rdr.GetString("PresentThumb");
            info.PresentIntro     = rdr.GetString("PresentIntro");
            info.PresentExplain   = rdr.GetString("PresentExplain");
            return(info);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新一条记录(异步方式)
        /// </summary>
        /// <param name="entity">实体模型</param>
        /// <returns></returns>
        public virtual async Task <bool> UpdateAsync(PresentEntity entity)
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            GetParameters(entity, dict);
            string strSQL = "Update Present SET " +
                            "PresentName = @PresentName," +
                            "PresentPic = @PresentPic," +
                            "Unit = @Unit," +
                            "PresentNum = @PresentNum," +
                            "ServiceTermUnit = @ServiceTermUnit," +
                            "ServiceTerm = @ServiceTerm," +
                            "Price = @Price," +
                            "Price_Market = @Price_Market," +
                            "Weight = @Weight," +
                            "Stocks = @Stocks," +
                            "StocksProject = @StocksProject," +
                            "OrderNum = @OrderNum," +
                            "AlarmNum = @AlarmNum," +
                            "ProductCharacter = @ProductCharacter," +
                            "DownloadUrl = @DownloadUrl," +
                            "Remark = @Remark," +
                            "PresentThumb = @PresentThumb," +
                            "PresentIntro = @PresentIntro," +
                            "PresentExplain = @PresentExplain" +
                            " WHERE " +

                            "PresentID = @PresentID";

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

            GetParameters(entity, dict);

            string strSQL = "insert into Present (" +
                            "PresentID," +
                            "PresentName," +
                            "PresentPic," +
                            "Unit," +
                            "PresentNum," +
                            "ServiceTermUnit," +
                            "ServiceTerm," +
                            "Price," +
                            "Price_Market," +
                            "Weight," +
                            "Stocks," +
                            "StocksProject," +
                            "OrderNum," +
                            "AlarmNum," +
                            "ProductCharacter," +
                            "DownloadUrl," +
                            "Remark," +
                            "PresentThumb," +
                            "PresentIntro," +
                            "PresentExplain) " +
                            "values(" +
                            "@PresentID," +
                            "@PresentName," +
                            "@PresentPic," +
                            "@Unit," +
                            "@PresentNum," +
                            "@ServiceTermUnit," +
                            "@ServiceTerm," +
                            "@Price," +
                            "@Price_Market," +
                            "@Weight," +
                            "@Stocks," +
                            "@StocksProject," +
                            "@OrderNum," +
                            "@AlarmNum," +
                            "@ProductCharacter," +
                            "@DownloadUrl," +
                            "@Remark," +
                            "@PresentThumb," +
                            "@PresentIntro," +
                            "@PresentExplain)";

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

            GetParameters(entity, dict);

            string strSQL = "insert into Present (" +
                            "PresentID," +
                            "PresentName," +
                            "PresentPic," +
                            "Unit," +
                            "PresentNum," +
                            "ServiceTermUnit," +
                            "ServiceTerm," +
                            "Price," +
                            "Price_Market," +
                            "Weight," +
                            "Stocks," +
                            "StocksProject," +
                            "OrderNum," +
                            "AlarmNum," +
                            "ProductCharacter," +
                            "DownloadUrl," +
                            "Remark," +
                            "PresentThumb," +
                            "PresentIntro," +
                            "PresentExplain) " +
                            "values(" +
                            "@PresentID," +
                            "@PresentName," +
                            "@PresentPic," +
                            "@Unit," +
                            "@PresentNum," +
                            "@ServiceTermUnit," +
                            "@ServiceTerm," +
                            "@Price," +
                            "@Price_Market," +
                            "@Weight," +
                            "@Stocks," +
                            "@StocksProject," +
                            "@OrderNum," +
                            "@AlarmNum," +
                            "@ProductCharacter," +
                            "@DownloadUrl," +
                            "@Remark," +
                            "@PresentThumb," +
                            "@PresentIntro," +
                            "@PresentExplain)";

            return(_DB.ExeSQLResult(strSQL, dict));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取实体(异步方式)
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual async Task <PresentEntity> GetEntityAsync(string strWhere, Dictionary <string, object> dict = null)
        {
            PresentEntity obj    = null;
            string        strSQL = "select top 1 * from Present where 1=1 " + strWhere;

            using (NullableDataReader reader = await Task.Run(() => _DB.GetDataReader(strSQL, dict)))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="strWhere">参数化查询条件(例如: and Name = @Name )</param>
        /// <param name="dict">参数的名/值集合</param>
        /// <returns></returns>
        public virtual PresentEntity GetEntity(string strWhere, Dictionary <string, object> dict = null)
        {
            PresentEntity obj    = null;
            string        strSQL = "select top 1 * from Present where 1=1 " + strWhere;

            using (NullableDataReader reader = _DB.GetDataReader(strSQL, dict))
            {
                if (reader.Read())
                {
                    obj = GetEntityFromrdr(reader);
                }
            }
            return(obj);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 把实体类转换成键/值对集合
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="dict"></param>
 private static void GetParameters(PresentEntity entity, Dictionary <string, object> dict)
 {
     dict.Add("PresentID", entity.PresentID);
     dict.Add("PresentName", entity.PresentName);
     dict.Add("PresentPic", entity.PresentPic);
     dict.Add("Unit", entity.Unit);
     dict.Add("PresentNum", entity.PresentNum);
     dict.Add("ServiceTermUnit", entity.ServiceTermUnit);
     dict.Add("ServiceTerm", entity.ServiceTerm);
     dict.Add("Price", entity.Price);
     dict.Add("Price_Market", entity.Price_Market);
     dict.Add("Weight", entity.Weight);
     dict.Add("Stocks", entity.Stocks);
     dict.Add("StocksProject", entity.StocksProject);
     dict.Add("OrderNum", entity.OrderNum);
     dict.Add("AlarmNum", entity.AlarmNum);
     dict.Add("ProductCharacter", entity.ProductCharacter);
     dict.Add("DownloadUrl", entity.DownloadUrl);
     dict.Add("Remark", entity.Remark);
     dict.Add("PresentThumb", entity.PresentThumb);
     dict.Add("PresentIntro", entity.PresentIntro);
     dict.Add("PresentExplain", entity.PresentExplain);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 增加或更新一条记录(异步方式)
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual async Task <bool> AddOrUpdateAsync(PresentEntity entity, bool IsSave)
 {
     return(IsSave ? await AddAsync(entity) : await UpdateAsync(entity));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 增加或更新一条记录
 /// </summary>
 /// <param name="entity">实体模型</param>
 /// <param name="IsSave">是否增加</param>
 /// <returns></returns>
 public virtual bool AddOrUpdate(PresentEntity entity, bool IsSave)
 {
     return(IsSave ? Add(entity) : Update(entity));
 }