protected void btnok_Click(object sender, EventArgs e) { Maticsoft.BLL.NewsInfo newbll = new Maticsoft.BLL.NewsInfo(); Maticsoft.Model.NewsInfo newmodel = new Maticsoft.Model.NewsInfo(); if (txtNewsTitle.Text.Trim() == "") { lblNewsTitle.Text = "请填写新闻标题"; return; } newmodel.NewsTitle = txtNewsTitle.Text.Trim(); lblNewsTitle.Text = ""; if (txtKeyword.Text.Trim() == "") { lblkeyword.Text = "请填写新闻关键字"; return; } newmodel.NewsKey = txtKeyword.Text.Trim(); lblkeyword.Text = ""; newmodel.NewsTypeID = int.Parse(drpNewsType.SelectedValue); if (txtwrite.Text.Trim() == "") { lblwrite.Text = "请填写新闻发布人"; return; } newmodel.Write = txtwrite.Text.Trim(); lblwrite.Text = ""; newmodel.Fatime = Convert.ToDateTime(txtfatime.Text.Trim()); newmodel.ImageURL = Image1.ImageUrl; newmodel.NewsContent = txtNewContent.Text.Trim(); newbll.Add(newmodel); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('信息添加成功!')</script>"); txtNewsTitle.Text = ""; txtKeyword.Text = ""; txtwrite.Text = ""; txtfatime.Text = ""; txtNewContent.Text = ""; }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtNewsTitle.Text.Trim().Length == 0) { strErr += "NewsTitle不能为空!\\n"; } if (this.txtNewsKey.Text.Trim().Length == 0) { strErr += "NewsKey不能为空!\\n"; } if (this.txtWrite.Text.Trim().Length == 0) { strErr += "Write不能为空!\\n"; } if (!PageValidate.IsNumber(txtNewsTypeID.Text)) { strErr += "NewsTypeID格式错误!\\n"; } if (!PageValidate.IsDateTime(txtFatime.Text)) { strErr += "Fatime格式错误!\\n"; } if (this.txtImageURL.Text.Trim().Length == 0) { strErr += "ImageURL不能为空!\\n"; } if (!PageValidate.IsNumber(txtHitNum.Text)) { strErr += "HitNum格式错误!\\n"; } if (this.txtNewsContent.Text.Trim().Length == 0) { strErr += "NewsContent不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string NewsTitle = this.txtNewsTitle.Text; string NewsKey = this.txtNewsKey.Text; string Write = this.txtWrite.Text; int NewsTypeID = int.Parse(this.txtNewsTypeID.Text); DateTime Fatime = DateTime.Parse(this.txtFatime.Text); string ImageURL = this.txtImageURL.Text; int HitNum = int.Parse(this.txtHitNum.Text); string NewsContent = this.txtNewsContent.Text; Maticsoft.Model.NewsInfo model = new Maticsoft.Model.NewsInfo(); model.NewsTitle = NewsTitle; model.NewsKey = NewsKey; model.Write = Write; model.NewsTypeID = NewsTypeID; model.Fatime = Fatime; model.ImageURL = ImageURL; model.HitNum = HitNum; model.NewsContent = NewsContent; Maticsoft.BLL.NewsInfo bll = new Maticsoft.BLL.NewsInfo(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }