Esempio n. 1
0
        /// <summary>
        /// 转换SqlDataReader类型数据记录为实体
        /// </summary>
        private static Entity.ExchangeCodeEntity ConvertToEntityFromDataReader(SqlDataReader reader)
        {
            Entity.ExchangeCodeEntity entity = new Entity.ExchangeCodeEntity();
            entity.Id           = Convert.ToInt32(reader["Id"]);
            entity.ShopId       = Convert.ToInt32(reader["ShopId"]);
            entity.ExchangeCode = reader["ExchangeCode"].ToString();

            return(entity);
        }
Esempio n. 2
0
        /// <summary>
        /// 转换DataRow类型数据记录为实体
        /// </summary>
        private static Entity.ExchangeCodeEntity ConvertToEntityFromDataRow(DataRow row)
        {
            Entity.ExchangeCodeEntity entity = new Entity.ExchangeCodeEntity();
            entity.Id           = Convert.ToInt32(row["Id"]);
            entity.ShopId       = Convert.ToInt32(row["ShopId"]);
            entity.ExchangeCode = row["ExchangeCode"].ToString();

            return(entity);
        }
Esempio n. 3
0
        /// <summary>
        /// 更新数据库中一条记录(根据主键条件)
        /// </summary>
        /// <param name="entity">Entity.ExchangeCodeEntity实体类</param>
        public static void Update(Entity.ExchangeCodeEntity entity)
        {
            List <SqlParameter> commandParms = new List <SqlParameter>();

            commandParms.Add(SqlHelper.CreateParam("@Id", SqlDbType.Int, 0, ParameterDirection.Input, entity.Id));
            commandParms.Add(SqlHelper.CreateParam("@ShopId", SqlDbType.Int, 0, ParameterDirection.Input, entity.ShopId));
            commandParms.Add(SqlHelper.CreateParam("@ExchangeCode", SqlDbType.VarChar, 50, ParameterDirection.Input, entity.ExchangeCode));

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, C_SP_EXCHANGECODE_UPDATE, commandParms);
        }
Esempio n. 4
0
        /// <summary>
        /// 向数据表中插入一条新记录
        /// </summary>
        /// <param name="entity">Entity.ExchangeCodeEntity实体类</param>
        /// <remarks>如果表存在自增长字段,插入记录成功后自增长字段值会更新至实体</remarks>
        public static void Insert(Entity.ExchangeCodeEntity entity)
        {
            List <SqlParameter> commandParms = new List <SqlParameter>();
            SqlParameter        id_Id        = SqlHelper.CreateParam("@Id", SqlDbType.Int, 0, ParameterDirection.Output, null);

            commandParms.Add(id_Id);
            commandParms.Add(SqlHelper.CreateParam("@ShopId", SqlDbType.Int, 0, ParameterDirection.Input, entity.ShopId));
            commandParms.Add(SqlHelper.CreateParam("@ExchangeCode", SqlDbType.VarChar, 50, ParameterDirection.Input, entity.ExchangeCode));

            SqlHelper.ExecuteNonQuery(ConnectionString, CommandType.Text, C_SP_EXCHANGECODE_INSERT, commandParms);
            entity.Id = Convert.ToInt32(id_Id.Value);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取数据库一条记录实体(根据主键条件)
        /// </summary>
        /// <param name="id">主键字段id</param>
        /// <returns>Entity.ExchangeCodeEntity实体类</returns>
        public static Entity.ExchangeCodeEntity GetById(int id)
        {
            Entity.ExchangeCodeEntity entity       = null;
            List <SqlParameter>       commandParms = new List <SqlParameter>();

            commandParms.Add(SqlHelper.CreateParam("@Id", SqlDbType.Int, 0, ParameterDirection.Input, id));

            using (SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, CommandType.Text, C_SP_EXCHANGECODE_GET, commandParms))
            {
                if (reader.Read())
                {
                    entity = ConvertToEntityFromDataReader(reader);
                }
            }

            return(entity);
        }