Example #1
0
        public Model.CMArticle GetModel(string strWhere, List <SqlParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from CMArticle ");
            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.CMArticle model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand)) {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Example #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.CMArticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CMArticle(");
            strSql.Append("ColId,ATId,Title,Description,Author,Source,Content,Hits,Status,IsTop,IsSplendid,PEmplId,CEmplId,AddTime,CheckTime,SeoTitle,SeoKeyword,SeoDes,AttType,OrgId,DisplayTime)");

            strSql.Append(" values (");
            strSql.Append("@ColId,@ATId,@Title,@Description,@Author,@Source,@Content,@Hits,@Status,@IsTop,@IsSplendid,@PEmplId,@CEmplId,@AddTime,@CheckTime,@SeoTitle,@SeoKeyword,@SeoDes,@AttType,@OrgId,@DisplayTime)");
            strSql.Append(";select @@IDENTITY");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "ColId", DbType.Int32, model.ColId);
            db.AddInParameter(dbCommand, "ATId", DbType.Int32, model.ATId);
            db.AddInParameter(dbCommand, "Title", DbType.String, model.Title);
            db.AddInParameter(dbCommand, "Description", DbType.String, model.Description);
            db.AddInParameter(dbCommand, "Author", DbType.String, model.Author);
            db.AddInParameter(dbCommand, "Source", DbType.String, model.Source);
            db.AddInParameter(dbCommand, "Content", DbType.String, model.Content);
            db.AddInParameter(dbCommand, "Hits", DbType.Int32, model.Hits);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "IsTop", DbType.Byte, model.IsTop);
            db.AddInParameter(dbCommand, "IsSplendid", DbType.Byte, model.IsSplendid);
            db.AddInParameter(dbCommand, "PEmplId", DbType.Int32, model.PEmplId);
            db.AddInParameter(dbCommand, "CEmplId", DbType.Int32, model.CEmplId);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "CheckTime", DbType.DateTime, model.CheckTime);
            db.AddInParameter(dbCommand, "SeoTitle", DbType.String, model.SeoTitle);
            db.AddInParameter(dbCommand, "SeoKeyword", DbType.String, model.SeoKeyword);
            db.AddInParameter(dbCommand, "SeoDes", DbType.String, model.SeoDes);
            db.AddInParameter(dbCommand, "AttType", DbType.Byte, model.AttType);
            db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId);
            db.AddInParameter(dbCommand, "DisplayTime", DbType.Int32, model.DisplayTime);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
Example #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.CMArticle GetModel(int AId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select AId,ColId,ATId,Title,Description,Author,Source,Content,Hits,Status,IsTop,IsSplendid,PEmplId,CEmplId,AddTime,CheckTime,SeoTitle,SeoKeyword,SeoDes,AttType,OrgId,DisplayTime from CMArticle ");
            strSql.Append(" where AId=@AId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "AId", DbType.Int32, AId);
            Model.CMArticle model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Example #4
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.CMArticle ReaderBind(IDataReader dataReader)
        {
            Model.CMArticle model = new Model.CMArticle();
            object          ojb;

            ojb = dataReader["AId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["ColId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ColId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["ATId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ATId = Convert.ToInt32(ojb);
            }
            model.Title       = dataReader["Title"].ToString();
            model.Description = dataReader["Description"].ToString();
            model.Author      = dataReader["Author"].ToString();
            model.Source      = dataReader["Source"].ToString();
            model.Content     = dataReader["Content"].ToString();
            ojb = dataReader["Hits"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Hits = Convert.ToInt32(ojb);
            }
            ojb = dataReader["Status"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Status = Convert.ToInt32(ojb);
            }
            ojb = dataReader["IsTop"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsTop = Convert.ToInt32(ojb);
            }
            ojb = dataReader["IsSplendid"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IsSplendid = Convert.ToInt32(ojb);
            }
            ojb = dataReader["PEmplId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PEmplId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["CEmplId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CEmplId = Convert.ToInt32(ojb);
            }
            ojb = dataReader["AddTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AddTime = Convert.ToDateTime(ojb);
            }
            ojb = dataReader["CheckTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CheckTime = Convert.ToDateTime(ojb);
            }
            model.SeoTitle   = dataReader["SeoTitle"].ToString();
            model.SeoKeyword = dataReader["SeoKeyword"].ToString();
            model.SeoDes     = dataReader["SeoDes"].ToString();
            ojb = dataReader["AttType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AttType = Convert.ToInt32(ojb);
            }
            ojb = dataReader["OrgId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrgId = Convert.ToInt64(ojb);
            }
            ojb = dataReader["DisplayTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DisplayTime = Convert.ToInt32(ojb);
            }
            return(model);
        }
Example #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.CMArticle DataRowToModel(DataRow row)
 {
     Model.CMArticle model = new Model.CMArticle();
     if (row != null)
     {
         if (row["AId"] != null && row["AId"].ToString() != "")
         {
             model.AId = Convert.ToInt32(row["AId"].ToString());
         }
         if (row["ColId"] != null && row["ColId"].ToString() != "")
         {
             model.ColId = Convert.ToInt32(row["ColId"].ToString());
         }
         if (row["ATId"] != null && row["ATId"].ToString() != "")
         {
             model.ATId = Convert.ToInt32(row["ATId"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["Description"] != null)
         {
             model.Description = row["Description"].ToString();
         }
         if (row["Author"] != null)
         {
             model.Author = row["Author"].ToString();
         }
         if (row["Source"] != null)
         {
             model.Source = row["Source"].ToString();
         }
         if (row["Content"] != null)
         {
             model.Content = row["Content"].ToString();
         }
         if (row["Hits"] != null && row["Hits"].ToString() != "")
         {
             model.Hits = Convert.ToInt32(row["Hits"].ToString());
         }
         if (row["Status"] != null && row["Status"].ToString() != "")
         {
             model.Status = Convert.ToInt32(row["Status"].ToString());
         }
         if (row["IsTop"] != null && row["IsTop"].ToString() != "")
         {
             model.IsTop = Convert.ToInt32(row["IsTop"].ToString());
         }
         if (row["IsSplendid"] != null && row["IsSplendid"].ToString() != "")
         {
             model.IsSplendid = Convert.ToInt32(row["IsSplendid"].ToString());
         }
         if (row["PEmplId"] != null && row["PEmplId"].ToString() != "")
         {
             model.PEmplId = Convert.ToInt32(row["PEmplId"].ToString());
         }
         if (row["CEmplId"] != null && row["CEmplId"].ToString() != "")
         {
             model.CEmplId = Convert.ToInt32(row["CEmplId"].ToString());
         }
         if (row["AddTime"] != null && row["AddTime"].ToString() != "")
         {
             model.AddTime = Convert.ToDateTime(row["AddTime"].ToString());
         }
         if (row["CheckTime"] != null && row["CheckTime"].ToString() != "")
         {
             model.CheckTime = Convert.ToDateTime(row["CheckTime"].ToString());
         }
         if (row["SeoTitle"] != null)
         {
             model.SeoTitle = row["SeoTitle"].ToString();
         }
         if (row["SeoKeyword"] != null)
         {
             model.SeoKeyword = row["SeoKeyword"].ToString();
         }
         if (row["SeoDes"] != null)
         {
             model.SeoDes = row["SeoDes"].ToString();
         }
         if (row["AttType"] != null && row["AttType"].ToString() != "")
         {
             model.AttType = Convert.ToInt32(row["AttType"].ToString());
         }
         if (row["OrgId"] != null && row["OrgId"].ToString() != "")
         {
             model.OrgId = Convert.ToInt64(row["OrgId"].ToString());
         }
         if (row["DisplayTime"] != null && row["DisplayTime"].ToString() != "")
         {
             model.DisplayTime = Convert.ToInt32(row["DisplayTime"].ToString());
         }
     }
     return(model);
 }
Example #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.CMArticle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update CMArticle set ");
            strSql.Append("ColId=@ColId,");
            strSql.Append("ATId=@ATId,");
            strSql.Append("Title=@Title,");
            strSql.Append("Description=@Description,");
            strSql.Append("Author=@Author,");
            strSql.Append("Source=@Source,");
            strSql.Append("Content=@Content,");
            strSql.Append("Hits=@Hits,");
            strSql.Append("Status=@Status,");
            strSql.Append("IsTop=@IsTop,");
            strSql.Append("IsSplendid=@IsSplendid,");
            strSql.Append("PEmplId=@PEmplId,");
            strSql.Append("CEmplId=@CEmplId,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("CheckTime=@CheckTime,");
            strSql.Append("SeoTitle=@SeoTitle,");
            strSql.Append("SeoKeyword=@SeoKeyword,");
            strSql.Append("SeoDes=@SeoDes,");
            strSql.Append("AttType=@AttType,");
            strSql.Append("OrgId=@OrgId,");
            strSql.Append("DisplayTime=@DisplayTime");
            strSql.Append(" where AId=@AId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "AId", DbType.Int32, model.AId);
            db.AddInParameter(dbCommand, "ColId", DbType.Int32, model.ColId);
            db.AddInParameter(dbCommand, "ATId", DbType.Int32, model.ATId);
            db.AddInParameter(dbCommand, "Title", DbType.String, model.Title);
            db.AddInParameter(dbCommand, "Description", DbType.String, model.Description);
            db.AddInParameter(dbCommand, "Author", DbType.String, model.Author);
            db.AddInParameter(dbCommand, "Source", DbType.String, model.Source);
            db.AddInParameter(dbCommand, "Content", DbType.String, model.Content);
            db.AddInParameter(dbCommand, "Hits", DbType.Int32, model.Hits);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "IsTop", DbType.Byte, model.IsTop);
            db.AddInParameter(dbCommand, "IsSplendid", DbType.Byte, model.IsSplendid);
            db.AddInParameter(dbCommand, "PEmplId", DbType.Int32, model.PEmplId);
            db.AddInParameter(dbCommand, "CEmplId", DbType.Int32, model.CEmplId);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "CheckTime", DbType.DateTime, model.CheckTime);
            db.AddInParameter(dbCommand, "SeoTitle", DbType.String, model.SeoTitle);
            db.AddInParameter(dbCommand, "SeoKeyword", DbType.String, model.SeoKeyword);
            db.AddInParameter(dbCommand, "SeoDes", DbType.String, model.SeoDes);
            db.AddInParameter(dbCommand, "AttType", DbType.Byte, model.AttType);
            db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId);
            db.AddInParameter(dbCommand, "DisplayTime", DbType.Int32, model.DisplayTime);
            int rows = db.ExecuteNonQuery(dbCommand);

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