示例#1
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        string Title   = TextBox1.Text;
        string Body    = TextBox3.Text;
        string Author  = name;
        string Date    = DateTime.Now.ToString("yyyy-MM-dd");
        string ifadmin = (Int32.Parse(usertype) - 1).ToString();
        string ifpass  = (Int32.Parse(usertype) - 1).ToString();

        if (TextBox1.Text != "" && TextBox3.Text != "")
        {
            if (!NewsID.Equals(""))
            {
                DataSet ds = nd.GetNewsById(NewsID);
                TitlePic = ds.Tables[0].Rows[0]["TitlePic"].ToString();

                if (FileUpload1.HasFile && !TitlePic.Equals(FileUpload1.FileName))
                {
                    TitlePic = UPimage(570, 385);
                }
                nd.updateNews(NewsID, Title, Body, TitlePic);
                nd.DeleteNewsTagByNewsID(NewsID);
                getcheck(CheckBoxList1, NewsID);
                if (diytag.Value != "")
                {
                    nd.insertTags(diytag.Value);
                    DataSet sd = nd.GetLastTags();
                    nd.insertNewsTag(NewsID, sd.Tables[0].Rows[0]["TagID"].ToString());
                }
                Response.Write(Util.ShowMessage("你的文章已经修改,请耐心等待管理员审核!"));
            }
            else
            {
                if (FileUpload1.HasFile)
                {
                    TitlePic = UPimage(570, 385);
                }
                else
                {
                    TitlePic = "default.jpg";  // 默认图片
                }
                nd.insertNews(Title, Body, Author, Date, TutorID, TitlePic, ifadmin, ifpass);
                DataSet ds = nd.GetLastNews();
                NewsID = ds.Tables[0].Rows[0]["NewsID"].ToString();
                getcheck(CheckBoxList1, NewsID);
                if (diytag.Value != "")
                {
                    nd.insertTags(diytag.Value);
                    DataSet sd = nd.GetLastTags();
                    nd.insertNewsTag(NewsID, sd.Tables[0].Rows[0]["TagID"].ToString());
                }
                TextBox1.Text   = "";
                TextBox3.Text   = "";
                Image1.ImageUrl = "../images/" + TitlePic;
                Response.Write(Util.ShowMessage("你的文章已经提交,请耐心等待管理员审核!"));
            }
        }
        else
        {
            Response.Write("<script language=\"JavaScript\">alert(\"信息不完全!\")</script>");
        }
    }