Exemple #1
0
        /// <summary>
        /// 判断当前节点是否已存在相同的
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int  ExistNum(ProductBaoPinEntity entity)
        {
            ///id=0,判断总数,ID>0判断除自己之外的总数
            string sql = @"Select count(1) from dbo.[ProductBaoPin] WITH(NOLOCK) ";

            string where = "where ";
            if (entity.Id == 0)
            {
                where = where + "  (Name=@Name) ";
            }
            else
            {
                where = where + " id<>@Id and  (Name=@Name) ";
            }
            sql = sql + where;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            if (entity.Id > 0)
            {
                db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            }

            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Exemple #2
0
        /// <summary>
        /// 根据主键值读取记录。如果数据库不存在这条数据将返回null
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public ProductBaoPinEntity GetProductBaoPin(int id)
        {
            string    sql = @"SELECT  [Id],[ProductDetailId],[Name],[BeginTime],[EndTime],[IsActive],[CreateTime]
							FROM
							dbo.[ProductBaoPin] WITH(NOLOCK)	
							WHERE [Id]=@id"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, id);
            ProductBaoPinEntity entity = new ProductBaoPinEntity();

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id = StringUtils.GetDbInt(reader["Id"]);
                    entity.ProductDetailId = StringUtils.GetDbInt(reader["ProductDetailId"]);
                    entity.Name            = StringUtils.GetDbString(reader["Name"]);
                    entity.BeginTime       = StringUtils.GetDbDateTime(reader["BeginTime"]);
                    entity.EndTime         = StringUtils.GetDbDateTime(reader["EndTime"]);
                    entity.IsActive        = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.CreateTime      = StringUtils.GetDbDateTime(reader["CreateTime"]);
                }
            }
            return(entity);
        }
Exemple #3
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="productBaoPin">待更新的实体对象</param>
        public int UpdateProductBaoPin(ProductBaoPinEntity entity)
        {
            string    sql = @" UPDATE dbo.[ProductBaoPin] SET
                       [ProductDetailId]=@ProductDetailId,[Name]=@Name,[BeginTime]=@BeginTime,[EndTime]=@EndTime,[IsActive]=@IsActive,[CreateTime]=@CreateTime
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@ProductDetailId", DbType.Int32, entity.ProductDetailId);
            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            db.AddInParameter(cmd, "@BeginTime", DbType.DateTime, entity.BeginTime);
            db.AddInParameter(cmd, "@EndTime", DbType.DateTime, entity.EndTime);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            return(db.ExecuteNonQuery(cmd));
        }
Exemple #4
0
        /// <summary>
        /// 插入一条记录到表ProductBaoPin,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="productBaoPin">要添加的ProductBaoPin数据实体对象</param>
        public int AddProductBaoPin(ProductBaoPinEntity productBaoPin)
        {
            if (productBaoPin.Id > 0)
            {
                return(UpdateProductBaoPin(productBaoPin));
            }
            else if (string.IsNullOrEmpty(productBaoPin.Name))
            {
                return((int)CommonStatus.ADD_Fail_Empty);
            }

            else if (ProductBaoPinBLL.Instance.IsExist(productBaoPin))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(ProductBaoPinDA.Instance.AddProductBaoPin(productBaoPin));
            }
        }
Exemple #5
0
        /// <summary>
        /// 插入一条记录到表ProductBaoPin,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="productBaoPin">待插入的实体对象</param>
        public int AddProductBaoPin(ProductBaoPinEntity entity)
        {
            string    sql = @"insert into ProductBaoPin( [ProductDetailId],[Name],[BeginTime],[EndTime],[IsActive],[CreateTime])VALUES
			            ( @ProductDetailId,@Name,@BeginTime,@EndTime,@IsActive,@CreateTime);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@ProductDetailId", DbType.Int32, entity.ProductDetailId);
            db.AddInParameter(cmd, "@Name", DbType.String, entity.Name);
            db.AddInParameter(cmd, "@BeginTime", DbType.DateTime, entity.BeginTime);
            db.AddInParameter(cmd, "@EndTime", DbType.DateTime, entity.EndTime);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, entity.CreateTime);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Exemple #6
0
 /// <summary>
 /// 更新一条ProductBaoPin记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="productBaoPin">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdateProductBaoPin(ProductBaoPinEntity productBaoPin)
 {
     return(ProductBaoPinDA.Instance.UpdateProductBaoPin(productBaoPin));
 }
Exemple #7
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(ProductBaoPinEntity productBaoPin)
 {
     return(ProductBaoPinDA.Instance.ExistNum(productBaoPin) > 0);
 }