コード例 #1
0
ファイル: ArticlePG.aspx.cs プロジェクト: sychenying/MX
        protected void btnsave_Click(object sender, EventArgs e)
        {
            if (Request["type"] == "Edit")
            {
                long Id   = Convert.ToInt64(Request["ID"]);
                var  item = db.Find(Id);
                if (item != null)
                {
                    item.Title    = txtbt.Text;
                    item.ImgStr   = hfimg.Value;
                    item.ShortTxt = txtbz.Text;
                    item.Content  = txtnr.Text;
                    item.CID      = Convert.ToInt64(ddllm.SelectedValue);
                    if (db.Edit(item))
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "e1", "edOK();", true);
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(GetType(), "e2", "layer.alert('修改失败');", true);
                    }
                }
                else
                {
                    //找不到数据就返回列表
                    Response.Redirect("LinksListPG.aspx");
                }
            }
            else
            {
                Models.Article item = new Models.Article();
                item.Title      = txtbt.Text;
                item.ImgStr     = hfimg.Value;
                item.ProductTxt = "";
                item.ShortTxt   = txtbz.Text;
                item.Content    = txtnr.Text;
                item.AddTime    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                item.Clicks     = 1;
                item.CID        = Convert.ToInt64(ddllm.SelectedValue);


                if (db.Add(item))
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "a1", "adOK()", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "a2", "layer.alert('添加失败');", true);
                }
            }
        }