Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Request["id"] == null ? 0 : int.Parse(Request["id"]);

            BLL.ArticleManagement article = new BLL.ArticleManagement();


            Model.ArticleManagement model = new Model.ArticleManagement();
            model = article.GetModel(id);

            title    = model.Title;
            keyword  = model.Keyword;
            contents = model.Content;
            image    = model.Image;
            time     = Convert.ToDateTime(model.Uploadtime).ToString("yyyy-mm-dd");
        }
Beispiel #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int id = HttpContext.Current.Request["id"] == null?0: int.Parse(HttpContext.Current.Request["id"]);

            if (id > 0)  //当它大于0的时候说明文本框有数据,则是修改操作
            {
                ArticleManagement article = new ArticleManagement();

                //实例化一个相同Id的model用于修改数据
                Model.ArticleManagement model = new Model.ArticleManagement();
                model.Id         = id;
                model.Title      = txtTitle.Text;
                model.Keyword    = txtKeyword.Text;
                model.Content    = txtEditorContents.Text;
                model.Image      = hidImagePath.Value;
                model.Uploadtime = Convert.ToDateTime(test1.Value);
                //执行修改
                bool a = article.Update(model);
                if (a == true)
                {
                    Response.Write("<script>alert('修改成功!');window.location.href='Article.aspx'</script>");
                }
            }
            else
            {
                ArticleManagement article = new ArticleManagement();

                //实例化一个对象用来新增操作
                Model.ArticleManagement NewModel = new Model.ArticleManagement();
                //Id是自增长不需要添加
                NewModel.Title      = txtTitle.Text;
                NewModel.Keyword    = txtKeyword.Text;
                NewModel.Content    = txtEditorContents.Text;
                NewModel.Image      = Request["hidImagePath"];
                NewModel.Uploadtime = Convert.ToDateTime(test1.Value);

                int a = article.Add(NewModel);
                if (a > 0)
                {
                    Response.Write("<script>alert('添加成功!');window.location.href='Article.aspx'</script>");
                }
            }
        }