示例#1
0
        /// <summary>增加一条数据
        ///
        /// </summary>
        public int Add(Nikita.Base.CacheStore.Model.CacheTables model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CacheTables(");
            strSql.Append("TableName, Remark, Status  )");
            strSql.Append(" values (");
            strSql.Append("@TableName, @Remark, @Status  )");
            strSql.Append(";select @@IDENTITY");
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            h.CreateCommand(strSql.ToString());
            if (model.TableName == null)
            {
                h.AddParameter("@TableName", DBNull.Value);
            }
            else
            {
                h.AddParameter("@TableName", model.TableName);
            }
            if (model.Remark == null)
            {
                h.AddParameter("@Remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Remark", model.Remark);
            }
            if (model.Status == null)
            {
                h.AddParameter("@Status", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Status", model.Status);
            }

            int    intResult;
            string obj = h.ExecuteScalar();

            if (!int.TryParse(obj, out intResult))
            {
                return(0);
            }
            return(intResult);
        }
示例#2
0
        /// <summary>更新一条数据
        ///
        /// </summary>
        public bool Update(Nikita.Base.CacheStore.Model.CacheTables model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update CacheTables set ");
            strSql.Append("TableName=@TableName, Remark=@Remark, Status=@Status  ");
            strSql.Append(" where Id=@Id ");
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            h.CreateCommand(strSql.ToString());
            if (model.Id == null)
            {
                h.AddParameter("@Id", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Id", model.Id);
            }
            if (model.TableName == null)
            {
                h.AddParameter("@TableName", DBNull.Value);
            }
            else
            {
                h.AddParameter("@TableName", model.TableName);
            }
            if (model.Remark == null)
            {
                h.AddParameter("@Remark", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Remark", model.Remark);
            }
            if (model.Status == null)
            {
                h.AddParameter("@Status", DBNull.Value);
            }
            else
            {
                h.AddParameter("@Status", model.Status);
            }

            return(h.ExecuteNonQuery());
        }
示例#3
0
        /// <summary>对象实体绑定数据
        ///
        /// </summary>
        public Nikita.Base.CacheStore.Model.CacheTables ReaderBind(IDataReader dataReader)
        {
            Nikita.Base.CacheStore.Model.CacheTables model = new Nikita.Base.CacheStore.Model.CacheTables();
            object ojb;

            ojb = dataReader["Id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Id = int.Parse(ojb.ToString());
            }
            model.TableName = dataReader["TableName"].ToString();
            model.Remark    = dataReader["Remark"].ToString();
            ojb             = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = int.Parse(ojb.ToString());
            }

            return(model);
        }
示例#4
0
        /// <summary>得到一个对象实体
        ///
        /// </summary>
        public Nikita.Base.CacheStore.Model.CacheTables GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from CacheTables ");
            strSql.Append(" where Id=@Id ");
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            h.CreateCommand(strSql.ToString());
            h.AddParameter("@Id", Id);
            Nikita.Base.CacheStore.Model.CacheTables model = null;
            using (IDataReader dataReader = h.ExecuteReader())
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                h.CloseConn();
            }
            return(model);
        }
示例#5
0
        /// <summary>根据条件得到一个对象实体
        ///
        /// </summary>
        public Nikita.Base.CacheStore.Model.CacheTables GetModelByCond(string strCond)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 * from CacheTables ");
            if (!string.IsNullOrEmpty(strCond))
            {
                strSql.Append(" where " + strCond);
            }
            IDbHelper h = GlobalHelp.GetDataAccessHelper();

            h.CreateCommand(strSql.ToString());
            Nikita.Base.CacheStore.Model.CacheTables model = null;
            using (IDataReader dataReader = h.ExecuteReader())
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                h.CloseConn();
            }
            return(model);
        }