コード例 #1
0
ファイル: AddNews.aspx.cs プロジェクト: liuyim93/yohome
 protected void btnSave_Click(object sender, EventArgs e)
 {
     Model.News news = new Model.News();
     if (txtTitle.Text == "")
     {
         MessageBox.Alert("标题不能为空!", Page);
         txtTitle.Focus();
     }
     else
     {
         if (dropType.SelectedItem.Text == "--请选择新闻类型--")
         {
             MessageBox.Alert("请选择新闻类型!", Page);
             dropType.Focus();
         }
         else
         {
             news.NewsTypeId = Convert.ToInt32(dropType.SelectedValue);
             if (txtTimer.Value == "")
             {
                 news.CreateTime = DateTime.Now.ToString("yyyy-MM-dd");
             }
             else
             {
                 news.CreateTime = txtTimer.Value;
             }
             if (hfImgUrl.Value == "")
             {
                 news.ImgUrl = txtImgUrl.Text.Trim();
             }
             else
             {
                 news.ImgUrl = hfImgUrl.Value;
             }
             news.Title     = txtTitle.Text;
             news.Intro     = fck_intro.Value;
             news.Details   = fck_detail.Value;
             news.IsShow    = Convert.ToInt32(chkShow.Checked);
             news.IsTop     = Convert.ToInt32(chkTop.Checked);
             news.IndexShow = Convert.ToInt32(chkIndex.Checked);
             if (hfId.Value == "" || hfId.Value == null)
             {
                 try
                 {
                     NewsBll.AddNews(news);
                     MessageBox.AlertAndRedirect("添加成功!", "News.aspx", Page);
                 }
                 catch (Exception)
                 {
                     MessageBox.Alert("添加失败!", Page);
                     /*throw;*/
                 }
             }
             else
             {
                 news.NewsId = Convert.ToInt32(hfId.Value);
                 try
                 {
                     NewsBll.UpdateNews(news);
                     MessageBox.AlertAndRedirect("修改成功!", "News.aspx", Page);
                 }
                 catch (Exception)
                 {
                     MessageBox.Alert("修改失败!", Page);
                     /*throw;*/
                 }
             }
         }
     }
 }