Ejemplo n.º 1
0
        public Model.CMColumn GetModel(string strWhere, List <SqlParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from CMColumn ");
            Database db = DatabaseFactory.CreateDatabase();

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            if (parameters.Count > 0)
            {
                foreach (SqlParameter sqlParameter in parameters)
                {
                    dbCommand.Parameters.Add(sqlParameter);
                }
            }
            Model.CMColumn model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand)) {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.CMColumn model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CMColumn(");
            strSql.Append("ColName,ParentId,Level,Status,AddTime,SeoKey,SeoDes,ClickRate)");

            strSql.Append(" values (");
            strSql.Append("@ColName,@ParentId,@Level,@Status,@AddTime,@SeoKey,@SeoDes,@ClickRate)");
            strSql.Append(";select @@IDENTITY");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "ColName", DbType.String, model.ColName);
            db.AddInParameter(dbCommand, "ParentId", DbType.Int32, model.ParentId);
            db.AddInParameter(dbCommand, "Level", DbType.Int32, model.Level);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "SeoKey", DbType.String, model.SeoKey);
            db.AddInParameter(dbCommand, "SeoDes", DbType.String, model.SeoDes);
            db.AddInParameter(dbCommand, "ClickRate", DbType.Int32, model.ClickRate);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.CMColumn DataRowToModel(DataRow row)
 {
     Model.CMColumn model = new Model.CMColumn();
     if (row != null)
     {
         if (row["ColId"] != null && row["ColId"].ToString() != "")
         {
             model.ColId = Convert.ToInt32(row["ColId"].ToString());
         }
         if (row["ColName"] != null)
         {
             model.ColName = row["ColName"].ToString();
         }
         if (row["ParentId"] != null && row["ParentId"].ToString() != "")
         {
             model.ParentId = Convert.ToInt32(row["ParentId"].ToString());
         }
         if (row["Level"] != null && row["Level"].ToString() != "")
         {
             model.Level = Convert.ToInt32(row["Level"].ToString());
         }
         if (row["Status"] != null && row["Status"].ToString() != "")
         {
             model.Status = Convert.ToInt32(row["Status"].ToString());
         }
         if (row["AddTime"] != null && row["AddTime"].ToString() != "")
         {
             model.AddTime = Convert.ToDateTime(row["AddTime"].ToString());
         }
         if (row["SeoKey"] != null)
         {
             model.SeoKey = row["SeoKey"].ToString();
         }
         if (row["SeoDes"] != null)
         {
             model.SeoDes = row["SeoDes"].ToString();
         }
         if (row["ClickRate"] != null && row["ClickRate"].ToString() != "")
         {
             model.ClickRate = Convert.ToInt32(row["ClickRate"].ToString());
         }
     }
     return(model);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.CMColumn GetModel(int ColId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ColId,ColName,ParentId,Level,Status,AddTime,SeoKey,SeoDes,ClickRate from CMColumn ");
            strSql.Append(" where ColId=@ColId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "ColId", DbType.Int32, ColId);
            Model.CMColumn model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.CMColumn ReaderBind(IDataReader dataReader)
        {
            Model.CMColumn model = new Model.CMColumn();
            object         ojb;

            ojb = dataReader["ColId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ColId = Convert.ToInt32(ojb);
            }
            model.ColName = dataReader["ColName"].ToString();
            ojb           = dataReader["ParentId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ParentId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["Level"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Level = Convert.ToInt32(ojb);
            }
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = Convert.ToInt32(ojb);
            }
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = Convert.ToDateTime(ojb);
            }
            model.SeoKey = dataReader["SeoKey"].ToString();
            model.SeoDes = dataReader["SeoDes"].ToString();
            ojb          = dataReader["ClickRate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ClickRate = Convert.ToInt32(ojb);
            }
            return(model);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.CMColumn model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update CMColumn set ");
            strSql.Append("ColName=@ColName,");
            strSql.Append("ParentId=@ParentId,");
            strSql.Append("Level=@Level,");
            strSql.Append("Status=@Status,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("SeoKey=@SeoKey,");
            strSql.Append("SeoDes=@SeoDes,");
            strSql.Append("ClickRate=@ClickRate");
            strSql.Append(" where ColId=@ColId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "ColId", DbType.Int32, model.ColId);
            db.AddInParameter(dbCommand, "ColName", DbType.String, model.ColName);
            db.AddInParameter(dbCommand, "ParentId", DbType.Int32, model.ParentId);
            db.AddInParameter(dbCommand, "Level", DbType.Int32, model.Level);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "SeoKey", DbType.String, model.SeoKey);
            db.AddInParameter(dbCommand, "SeoDes", DbType.String, model.SeoDes);
            db.AddInParameter(dbCommand, "ClickRate", DbType.Int32, model.ClickRate);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }