Beispiel #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.Model.ArticleManagement model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ArticleManagement(");
            strSql.Append("Title,Keyword,Content,Image,Uploadtime)");
            strSql.Append(" values (");
            strSql.Append("@Title,@Keyword,@Content,@Image,@Uploadtime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",      SqlDbType.NVarChar,  20),
                new SqlParameter("@Keyword",    SqlDbType.NVarChar,  50),
                new SqlParameter("@Content",    SqlDbType.Text),
                new SqlParameter("@Image",      SqlDbType.NVarChar, 200),
                new SqlParameter("@Uploadtime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.Title;
            parameters[1].Value = model.Keyword;
            parameters[2].Value = model.Content;
            parameters[3].Value = model.Image;
            parameters[4].Value = model.Uploadtime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.ArticleManagement DataRowToModel(DataRow row)
 {
     Maticsoft.Model.ArticleManagement model = new Maticsoft.Model.ArticleManagement();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["Keyword"] != null)
         {
             model.Keyword = row["Keyword"].ToString();
         }
         if (row["Content"] != null)
         {
             model.Content = row["Content"].ToString();
         }
         if (row["Image"] != null)
         {
             model.Image = row["Image"].ToString();
         }
         if (row["Uploadtime"] != null && row["Uploadtime"].ToString() != "")
         {
             model.Uploadtime = DateTime.Parse(row["Uploadtime"].ToString());
         }
     }
     return(model);
 }
Beispiel #3
0
 private void ShowInfo(int Id)
 {
     Maticsoft.BLL.ArticleManagement   bll   = new Maticsoft.BLL.ArticleManagement();
     Maticsoft.Model.ArticleManagement model = bll.GetModel(Id);
     this.lblId.Text         = model.Id.ToString();
     this.lblTitle.Text      = model.Title;
     this.lblKeyword.Text    = model.Keyword;
     this.lblContent.Text    = model.Content;
     this.lblImage.Text      = model.Image;
     this.lblUploadtime.Text = model.Uploadtime.ToString();
 }
Beispiel #4
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtTitle.Text.Trim().Length == 0)
            {
                strErr += "Title不能为空!\\n";
            }
            if (this.txtKeyword.Text.Trim().Length == 0)
            {
                strErr += "Keyword不能为空!\\n";
            }
            if (this.txtContent.Text.Trim().Length == 0)
            {
                strErr += "Content不能为空!\\n";
            }
            if (this.txtImage.Text.Trim().Length == 0)
            {
                strErr += "Image不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtUploadtime.Text))
            {
                strErr += "Uploadtime格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      Id         = int.Parse(this.lblId.Text);
            string   Title      = this.txtTitle.Text;
            string   Keyword    = this.txtKeyword.Text;
            string   Content    = this.txtContent.Text;
            string   Image      = this.txtImage.Text;
            DateTime Uploadtime = DateTime.Parse(this.txtUploadtime.Text);


            Maticsoft.Model.ArticleManagement model = new Maticsoft.Model.ArticleManagement();
            model.Id         = Id;
            model.Title      = Title;
            model.Keyword    = Keyword;
            model.Content    = Content;
            model.Image      = Image;
            model.Uploadtime = Uploadtime;

            Maticsoft.BLL.ArticleManagement bll = new Maticsoft.BLL.ArticleManagement();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Beispiel #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.Model.ArticleManagement model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ArticleManagement set ");
            strSql.Append("Title=@Title,");
            strSql.Append("Keyword=@Keyword,");
            strSql.Append("Content=@Content,");
            strSql.Append("Image=@Image,");
            strSql.Append("Uploadtime=@Uploadtime");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",      SqlDbType.NVarChar,   20),
                new SqlParameter("@Keyword",    SqlDbType.NVarChar,   50),
                new SqlParameter("@Content",    SqlDbType.Text),
                new SqlParameter("@Image",      SqlDbType.NVarChar,  200),
                new SqlParameter("@Uploadtime", SqlDbType.DateTime),
                new SqlParameter("@Id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Title;
            parameters[1].Value = model.Keyword;
            parameters[2].Value = model.Content;
            parameters[3].Value = model.Image;
            parameters[4].Value = model.Uploadtime;
            parameters[5].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.ArticleManagement GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Title,Keyword,Content,Image,Uploadtime from ArticleManagement ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            Maticsoft.Model.ArticleManagement model = new Maticsoft.Model.ArticleManagement();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }