Пример #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         BindType();
         txtTimer.Value = DateTime.Now.ToString("yyyy-MM-dd");
         if (Request.QueryString["typeId"] != null && Request.QueryString["typeId"] != "")
         {
             int             typeId = Convert.ToInt32(Request.QueryString["typeId"]);
             List <NewsType> list   = NewsTypeBll.GetNewsTypebyId(typeId);
             if (list.Count > 0)
             {
                 dropType.SelectedValue = Request.QueryString["typeId"];
             }
         }
         else
         {
             if (Request.QueryString["id"] != "" && Request.QueryString["id"] != null)
             {
                 int id = Convert.ToInt32(Request.QueryString["id"]);
                 List <Model.News> list = NewsBll.GetNewsbyId(id);
                 if (list.Count > 0)
                 {
                     txtTitle.Text          = list[0].Title;
                     txtTimer.Value         = list[0].CreateTime;
                     txtImgUrl.Text         = list[0].ImgUrl;
                     dropType.SelectedValue = list[0].NewsTypeId.ToString();
                     fck_intro.Value        = list[0].Intro;
                     fck_detail.Value       = list[0].Details;
                     chkShow.Checked        = Convert.ToBoolean(list[0].IsShow);
                     chkTop.Checked         = Convert.ToBoolean(list[0].IsTop);
                     chkIndex.Checked       = Convert.ToBoolean(list[0].IndexShow);
                     hfId.Value             = id.ToString();
                 }
             }
         }
     }
 }
Пример #2
0
        protected void dgNews_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            switch (e.CommandName.ToLower())
            {
            case "status":
                int newsId             = Convert.ToInt32(e.CommandArgument);
                List <Model.News> list = NewsBll.GetNewsbyId(newsId);
                if (list.Count > 0)
                {
                    if (list[0].IsShow == 0)
                    {
                        try
                        {
                            NewsBll.UpdateStatus(newsId, 1);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                    else
                    {
                        try
                        {
                            NewsBll.UpdateStatus(newsId, 0);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                }
                break;

            case "top":
                int newsId1             = Convert.ToInt32(e.CommandArgument);
                List <Model.News> list1 = NewsBll.GetNewsbyId(newsId1);
                if (list1.Count > 0)
                {
                    if (list1[0].IsTop == 0)
                    {
                        try
                        {
                            NewsBll.UpdateTop(newsId1, 1);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                    else
                    {
                        try
                        {
                            NewsBll.UpdateTop(newsId1, 0);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                }
                break;

            case "index":
                int newsId2             = Convert.ToInt32(e.CommandArgument);
                List <Model.News> list2 = NewsBll.GetNewsbyId(newsId2);
                if (list2.Count > 0)
                {
                    if (list2[0].IndexShow == 0)
                    {
                        try
                        {
                            NewsBll.UpdateIndex(newsId2, 1);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                    else
                    {
                        try
                        {
                            NewsBll.UpdateIndex(newsId2, 0);
                            BindData();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Alert("未知错误:" + ex, Page);
                            /*throw;*/
                        }
                    }
                }
                break;

            case "del":
                int id = Convert.ToInt32(e.CommandArgument);
                try
                {
                    NewsBll.DeleteNews(id);
                    MessageBox.Alert("删除成功!", Page);
                    BindData();
                }
                catch (Exception)
                {
                    MessageBox.Alert("删除失败!", Page);
                    /*throw;*/
                }
                break;

            default:
                break;
            }
        }