示例#1
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;
            }
        }