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

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

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

            db.AddInParameter(cmd, "@ProductName", DbType.String, entity.ProductName);

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

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <PartsProductFoundEntity> GetPartsProductFoundAll()
        {
            string sql = @"SELECT    [Id],[ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort] from dbo.[PartsProductFound] WITH(NOLOCK)	";
            IList <PartsProductFoundEntity> entityList = new List <PartsProductFoundEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PartsProductFoundEntity entity = new PartsProductFoundEntity();
                    entity.Id              = StringUtils.GetDbInt(reader["Id"]);
                    entity.ProductName     = StringUtils.GetDbString(reader["ProductName"]);
                    entity.ProductFullName = StringUtils.GetDbString(reader["ProductFullName"]);
                    entity.ClassFoundId    = StringUtils.GetDbInt(reader["ClassFoundId"]);
                    entity.ProductFoundId  = StringUtils.GetDbInt(reader["ProductFoundId"]);
                    entity.PYFirst         = StringUtils.GetDbString(reader["PYFirst"]);
                    entity.PingYingFull    = StringUtils.GetDbString(reader["PingYingFull"]);
                    entity.IsActive        = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.IsHot           = StringUtils.GetDbInt(reader["IsHot"]);
                    entity.Sort            = StringUtils.GetDbInt(reader["Sort"]);
                    entityList.Add(entity);
                }
            }
            return(entityList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据主键值读取记录。如果数据库不存在这条数据将返回null
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public PartsProductFoundEntity GetPartsProductFound(int id)
        {
            string    sql = @"SELECT  [Id],[ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort]
							FROM
							dbo.[PartsProductFound] WITH(NOLOCK)	
							WHERE [Id]=@id"                            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

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

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    entity.Id              = StringUtils.GetDbInt(reader["Id"]);
                    entity.ProductName     = StringUtils.GetDbString(reader["ProductName"]);
                    entity.ProductFullName = StringUtils.GetDbString(reader["ProductFullName"]);
                    entity.ClassFoundId    = StringUtils.GetDbInt(reader["ClassFoundId"]);
                    entity.ProductFoundId  = StringUtils.GetDbInt(reader["ProductFoundId"]);
                    entity.PYFirst         = StringUtils.GetDbString(reader["PYFirst"]);
                    entity.PingYingFull    = StringUtils.GetDbString(reader["PingYingFull"]);
                    entity.IsActive        = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.IsHot           = StringUtils.GetDbInt(reader["IsHot"]);
                    entity.Sort            = StringUtils.GetDbInt(reader["Sort"]);
                }
            }
            return(entity);
        }
Ejemplo n.º 4
0
        public IList <PartsProductFoundEntity> GetPartsProductFoundShow(string py, int scopetype, int scopeid, SearchMethod searchmethod)
        {
            string where = " where 1=1 ";
            if (!string.IsNullOrEmpty(py) && searchmethod == SearchMethod.PY)
            {
                where += " and PYFirst like @Key ";
            }
            if (!string.IsNullOrEmpty(py) && searchmethod == SearchMethod.PingYing)
            {
                where += " and PingYingFull like @Key ";
            }
            if (!string.IsNullOrEmpty(py) && searchmethod == SearchMethod.Name)
            {
                where += " and ProductName like @Key ";
            }
            if (scopetype == (int)ScopeTypeEnum.Normal)
            {
                where += " AND ScopeType=@ScopeType  and  scopeid = @ScopeId ";
            }

            string sql = @"SELECT Top 50
						 [Id],[ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort],ProductUnitName,ScopeId,ScopeType from dbo.[PartsProductFound] WITH(NOLOCK)	
						"                         + where + "Order By Sort desc,ProductName asc";


            IList <PartsProductFoundEntity> entityList = new List <PartsProductFoundEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Key", DbType.String, py + "%");
            if (scopetype == (int)ScopeTypeEnum.Normal)
            {
                db.AddInParameter(cmd, "@ScopeType", DbType.Int16, scopetype);
                db.AddInParameter(cmd, "@ScopeId", DbType.Int32, scopeid);
            }
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PartsProductFoundEntity entity = new PartsProductFoundEntity();
                    entity.Id              = StringUtils.GetDbInt(reader["Id"]);
                    entity.ProductName     = StringUtils.GetDbString(reader["ProductName"]);
                    entity.ProductFullName = StringUtils.GetDbString(reader["ProductFullName"]);
                    entity.ClassFoundId    = StringUtils.GetDbInt(reader["ClassFoundId"]);
                    entity.ProductFoundId  = StringUtils.GetDbInt(reader["ProductFoundId"]);
                    entity.PYFirst         = StringUtils.GetDbString(reader["PYFirst"]);
                    entity.PingYingFull    = StringUtils.GetDbString(reader["PingYingFull"]);
                    entity.IsActive        = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.IsHot           = StringUtils.GetDbInt(reader["IsHot"]);
                    entity.Sort            = StringUtils.GetDbInt(reader["Sort"]);
                    entity.ScopeId         = StringUtils.GetDbInt(reader["ScopeId"]);
                    entity.ScopeType       = StringUtils.GetDbInt(reader["ScopeType"]);
                    entity.ProductUnitName = StringUtils.GetDbString(reader["ProductUnitName"]);
                    entityList.Add(entity);
                }
            }

            return(entityList);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public IList <PartsProductFoundEntity> GetPartsProductFoundList(int pagesize, int pageindex, ref int recordCount)
        {
            string sql = @"SELECT   [Id],[ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort]
						FROM
						(SELECT ROW_NUMBER() OVER (ORDER BY Id desc) AS ROWNUMBER,
						 [Id],[ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort] from dbo.[PartsProductFound] WITH(NOLOCK)	
						WHERE  1=1 ) as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize"                        ;

            string sql2 = @"Select count(1) from dbo.[PartsProductFound] with (nolock) ";
            IList <PartsProductFoundEntity> entityList = new List <PartsProductFoundEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
            db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize);

            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    PartsProductFoundEntity entity = new PartsProductFoundEntity();
                    entity.Id              = StringUtils.GetDbInt(reader["Id"]);
                    entity.ProductName     = StringUtils.GetDbString(reader["ProductName"]);
                    entity.ProductFullName = StringUtils.GetDbString(reader["ProductFullName"]);
                    entity.ClassFoundId    = StringUtils.GetDbInt(reader["ClassFoundId"]);
                    entity.ProductFoundId  = StringUtils.GetDbInt(reader["ProductFoundId"]);
                    entity.PYFirst         = StringUtils.GetDbString(reader["PYFirst"]);
                    entity.PingYingFull    = StringUtils.GetDbString(reader["PingYingFull"]);
                    entity.IsActive        = StringUtils.GetDbInt(reader["IsActive"]);
                    entity.IsHot           = StringUtils.GetDbInt(reader["IsHot"]);
                    entity.Sort            = StringUtils.GetDbInt(reader["Sort"]);
                    entityList.Add(entity);
                }
            }
            cmd = db.GetSqlStringCommand(sql2);
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return(entityList);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 根据主键值更新记录的全部字段(注意:该方法不会对自增字段、timestamp类型字段以及主键字段更新!如果要更新主键字段,请使用Update方法)。
        /// 如果数据库有数据被更新了则返回True,否则返回False
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="partsProductFound">待更新的实体对象</param>
        public int UpdatePartsProductFound(PartsProductFoundEntity entity)
        {
            string    sql = @" UPDATE dbo.[PartsProductFound] SET
                       [ProductName]=@ProductName,[ProductFullName]=@ProductFullName,[ClassFoundId]=@ClassFoundId,[ProductFoundId]=@ProductFoundId,[PYFirst]=@PYFirst,[PingYingFull]=@PingYingFull,[IsActive]=@IsActive,[IsHot]=@IsHot,[Sort]=@Sort
                       WHERE [Id]=@id";
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@Id", DbType.Int32, entity.Id);
            db.AddInParameter(cmd, "@ProductName", DbType.String, entity.ProductName);
            db.AddInParameter(cmd, "@ProductFullName", DbType.String, entity.ProductFullName);
            db.AddInParameter(cmd, "@ClassFoundId", DbType.Int32, entity.ClassFoundId);
            db.AddInParameter(cmd, "@ProductFoundId", DbType.Int32, entity.ProductFoundId);
            db.AddInParameter(cmd, "@PYFirst", DbType.String, entity.PYFirst);
            db.AddInParameter(cmd, "@PingYingFull", DbType.String, entity.PingYingFull);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@IsHot", DbType.Int32, entity.IsHot);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            return(db.ExecuteNonQuery(cmd));
        }
        /// <summary>
        /// 插入一条记录到表PartsProductFound,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0。
        /// 该方法提供给界面等UI层调用
        /// </summary>
        /// <param name="partsProductFound">要添加的PartsProductFound数据实体对象</param>
        public int AddPartsProductFound(PartsProductFoundEntity partsProductFound)
        {
            if (partsProductFound.Id > 0)
            {
                return(UpdatePartsProductFound(partsProductFound));
            }
            else if (string.IsNullOrEmpty(partsProductFound.ProductName))
            {
                return((int)CommonStatus.ADD_Fail_Empty);
            }
            else if (string.IsNullOrEmpty(partsProductFound.ProductFullName))
            {
                return((int)CommonStatus.ADD_Fail_Empty);
            }

            else if (PartsProductFoundBLL.Instance.IsExist(partsProductFound))
            {
                return((int)CommonStatus.ADD_Fail_Exist);
            }
            else
            {
                return(PartsProductFoundDA.Instance.AddPartsProductFound(partsProductFound));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 插入一条记录到表PartsProductFound,如果表中存在自增字段,则返回值为新记录的自增字段值,否则返回0
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="partsProductFound">待插入的实体对象</param>
        public int AddPartsProductFound(PartsProductFoundEntity entity)
        {
            string    sql = @"insert into PartsProductFound( [ProductName],[ProductFullName],[ClassFoundId],[ProductFoundId],[PYFirst],[PingYingFull],[IsActive],[IsHot],[Sort])VALUES
			            ( @ProductName,@ProductFullName,@ClassFoundId,@ProductFoundId,@PYFirst,@PingYingFull,@IsActive,@IsHot,@Sort);
			SELECT SCOPE_IDENTITY();"            ;
            DbCommand cmd = db.GetSqlStringCommand(sql);

            db.AddInParameter(cmd, "@ProductName", DbType.String, entity.ProductName);
            db.AddInParameter(cmd, "@ProductFullName", DbType.String, entity.ProductFullName);
            db.AddInParameter(cmd, "@ClassFoundId", DbType.Int32, entity.ClassFoundId);
            db.AddInParameter(cmd, "@ProductFoundId", DbType.Int32, entity.ProductFoundId);
            db.AddInParameter(cmd, "@PYFirst", DbType.String, entity.PYFirst);
            db.AddInParameter(cmd, "@PingYingFull", DbType.String, entity.PingYingFull);
            db.AddInParameter(cmd, "@IsActive", DbType.Int32, entity.IsActive);
            db.AddInParameter(cmd, "@IsHot", DbType.Int32, entity.IsHot);
            db.AddInParameter(cmd, "@Sort", DbType.Int32, entity.Sort);
            object identity = db.ExecuteScalar(cmd);

            if (identity == null || identity == DBNull.Value)
            {
                return(0);
            }
            return(Convert.ToInt32(identity));
        }
 /// <summary>
 /// 更新一条PartsProductFound记录。
 /// 该方法提供给界面等UI层调用
 /// </summary>
 /// <param name="partsProductFound">待更新的实体对象</param>
 /// <param name="columns">要更新的列名,不提供任何列名时默认将更新主键之外的所有列</param>
 public int UpdatePartsProductFound(PartsProductFoundEntity partsProductFound)
 {
     return(PartsProductFoundDA.Instance.UpdatePartsProductFound(partsProductFound));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 判断对象是否存在
 /// </summary>
 /// <param name="dicEnum"></param>
 /// <returns></returns>
 public bool IsExist(PartsProductFoundEntity partsProductFound)
 {
     return(PartsProductFoundDA.Instance.ExistNum(partsProductFound) > 0);
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取显示的部分要选择的产品列表
        /// </summary>
        /// <param name="py"></param>
        /// <returns></returns>
        public IList <PartsProductFoundEntity> GetPartsProductFoundShow(string key, int scopetype, int scopeid, bool cache)
        {
            IList <PartsProductFoundEntity> list = new List <PartsProductFoundEntity>();
            string _cachekey = "GetPartsProductFoundShow_" + key + "_" + scopetype + "_" + scopeid;// SysCacheKey.PartsProductFoundListKey;

            if (cache)
            {
                object obj = MemCache.GetCache(_cachekey);
                if (obj != null)
                {
                    list = (IList <PartsProductFoundEntity>)obj;
                }
            }
            if (list == null || list.Count == 0)
            {
                list = PartsProductFoundDA.Instance.GetPartsProductFoundShow(key, scopetype, scopeid, SearchMethod.PY);
                if ((list == null || list.Count < 50) && !string.IsNullOrEmpty(key))
                {
                    IList <PartsProductFoundEntity> list2 = PartsProductFoundDA.Instance.GetPartsProductFoundShow(key, scopetype, scopeid, SearchMethod.PingYing);
                    if (list2 != null && list2.Count > 0)
                    {
                        if (list == null)
                        {
                            list = list2;
                        }
                        else
                        {
                            for (int i = 0; i < 50 - list.Count && i < list2.Count - 1; i++)
                            {
                                PartsProductFoundEntity entity = list2[i];
                                list.Add(entity);
                            }
                        }
                    }
                }
                if ((list == null || list.Count == 0) && !string.IsNullOrEmpty(key))
                {
                    IList <PartsProductFoundEntity> list3 = PartsProductFoundDA.Instance.GetPartsProductFoundShow(key, scopetype, scopeid, SearchMethod.Name);
                    if (list3 != null && list3.Count > 0)
                    {
                        if (list == null)
                        {
                            list = list3;
                        }
                        else
                        {
                            for (int i = 0; i < 50 - list.Count && i < list3.Count - 1; i++)
                            {
                                PartsProductFoundEntity entity = list3[i];
                                list.Add(entity);
                            }
                        }
                    }
                }
                if (cache)
                {
                    MemCache.AddCache(_cachekey, list);
                }
            }
            return(list);
        }