protected void btnSetNoImg_Click(object sender, EventArgs e)
 {
     if (Request["NewsID"] + "" == "")
     {
         Response.Redirect("RightsWarn.aspx");
     }
     else
     {
         try
         {
             WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
             WebProject.Model.BaseData.ZT_COM_News model_News = bll_News.GetModel(Int32.Parse(Request["NewsID"].ToString()));
             if (model_News.ImgUrl.ToString() != "onlinenone.jpg")
             {
                 System.IO.File.Delete(Server.MapPath("IMG/" + model_News.ImgUrl.ToString()));
                 model_News.ImgUrl = "onlinenone.jpg";
                 model_News.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo;
                 model_News.LastUpdateDate = DateTime.Now;
                 bll_News.Update(model_News);
             }
             LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "删除图片", "成功", "新闻标题:" + model_News.Title + ", 修改人:" + SessionUtil.GetAdminSession().AdminNo);
             MessageBox.Show(this, "删除原图片成功!");
         }
         catch
         {
             Response.Redirect("RightsWarn.aspx");
         }
     }
 }
 public void ShowData(string NewsTypeNo)
 {
     WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
     DataSet ds = null;
     if (NewsTypeNo == "ALL")
     {
         ds = bll_News.GetList(" 1=1 ");
     }
     else
     {
         ds = bll_News.GetList("NewsTypeNo='" + NewsTypeNo + "'");
     }
     if (ds.Tables[0].Rows.Count > 0)
     {
         this.lblMessage.Visible = false;
         this.btnDeleteSelect.Visible = true;
         this.GridView1.Visible = true;
         this.GridView1.DataSource = ds;
         this.GridView1.DataBind();
     }
     else
     {
         this.lblMessage.Visible = true;
         this.btnDeleteSelect.Visible = false;
         this.GridView1.Visible = false;
     }
 }
Beispiel #3
0
    public void ShowNewsInfo()
    {
        int currentPage = Convert.ToInt32(this.dang.Text);  //当前页
        WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
        DataSet ds = bll_News.GetList(" 1=1 ");
        this.count.Text = ds.Tables[0].Rows.Count.ToString();
        if (ds.Tables[0].Rows.Count != 0)
        {
            System.Web.UI.WebControls.PagedDataSource pds = new PagedDataSource();
            pds.DataSource = ds.Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 18; //设置页面显示的数目
            pds.CurrentPageIndex = currentPage - 1; //当前页面索引,索引号从0开始
            this.countpage.Text = pds.PageCount.ToString();//总页数

            if (currentPage == 1)
            {
                this.shou.Enabled = false;
                this.shang.Enabled = false;

            }
            else
            {
                this.shou.Enabled = true;
                this.shang.Enabled = true;
            }

            if (currentPage == pds.PageCount)
            {
                this.xia.Enabled = false;
                this.last.Enabled = false;
            }
            else
            {
                this.xia.Enabled = true;
                this.last.Enabled = true;
            }

            this.Repeater1.DataSource = pds;
            this.Repeater1.DataBind();
        }
        else
        {
            this.lblMessage.Visible = true;
            this.countpage.Text = this.dang.Text;
            this.shou.Enabled = false;
            this.shang.Enabled = false;
            this.xia.Enabled = false;
            this.last.Enabled = false;
        }
    }
 public void ShowNewsInfo()
 {
     if (Request["NewsID"] + "" == "")
     {
         Response.Redirect("ErrorPage.aspx");
     }
     else
     {
         try
         {
             int NewsID = Convert.ToInt32(Request.QueryString["NewsID"].ToString());
             WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
             WebProject.Model.BaseData.ZT_COM_News model_News = bll_News.GetModel(NewsID);
             this.lblTitle.Text = model_News.Title.ToString();
             this.lblBody.Text = model_News.Body.ToString();
         }
         catch
         {
             Response.Redirect("ErrorPage.aspx");
         }
     }
 }
 public void ShowData()
 {
     if (Request["NewsID"] + "" == "")
     {
         Response.Redirect("RightsWarn.aspx");
     }
     else
     {
         try
         {
             WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
             WebProject.Model.BaseData.ZT_COM_News model_News = bll_News.GetModel(Int32.Parse(Request["NewsID"].ToString()));
             this.txtBody.Text = model_News.Body.ToString();
             this.txtNewsOrder.Text = model_News.NewsOrder.ToString();
             this.txtNewsType.SelectedValue = model_News.NewsTypeNo.ToString();
             this.txtTitle.Text = model_News.Title.ToString();
         }
         catch
         {
             Response.Redirect("RightsWarn.aspx");
         }
     }
 }
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     if (this.txtTitle.Text.Trim() == "")
     {
         MessageBox.Show(this, "请输入新闻标题!");
         return;
     }
     int NewsOrder;
     if (this.txtNewsOrder.Text.Trim() == "")
     {
         NewsOrder = 1000;
     }
     else
     {
         double u;
         if (!double.TryParse(this.txtNewsOrder.Text.Trim(), out u))
         {
             MessageBox.Show(this, "排序必须为数字!");
             return;
         }
         else
         {
             NewsOrder = Convert.ToInt32(this.txtNewsOrder.Text.Trim());
         }
     }
     if (this.txtBody.Text.Trim() == "")
     {
         MessageBox.Show(this, "请输入新闻内容!");
         return;
     }
     if (Request["NewsID"] + "" == "")
     {
         Response.Redirect("RightsWarn.aspx");
     }
     else
     {
         Boolean fileTypeOK = false;
         String path = Server.MapPath("~/SysManage/IMG/");
         if (txtImgUrl.HasFile == false)
         {
             try
             {
                 WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
                 WebProject.Model.BaseData.ZT_COM_News model_News = bll_News.GetModel(Int32.Parse(Request["NewsID"].ToString()));
                 model_News.Body = this.txtBody.Text.Trim();
                 model_News.NewsTypeName = this.txtNewsType.Items[this.txtNewsType.SelectedIndex].Text.ToString();
                 model_News.NewsTypeNo = this.txtNewsType.SelectedValue.ToString();
                 model_News.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo;
                 model_News.LastUpdateDate = DateTime.Now;
                 model_News.NewsOrder = Int32.Parse(this.txtNewsOrder.Text.Trim());
                 model_News.Title = this.txtTitle.Text.Trim();
                 bll_News.Update(model_News);
                 LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "修改新闻", "成功", "新闻标题:" + model_News.Title + ", 修改人:" + SessionUtil.GetAdminSession().AdminNo);
                 MessageBox.ShowAndRedirect(this, "修改信息成功!", "NewsList.aspx");
             }
             catch
             {
                 Response.Redirect("RightsWarn.aspx");
             }
         }
         if (txtImgUrl.HasFile == true)
         {
             String fileExtension = System.IO.Path.GetExtension(txtImgUrl.FileName).ToLower();
             String[] allowedExtensions = { ".bmp", ".jpg", ".jpeg", ".png", ".gif" };
             for (int i = 0; i < allowedExtensions.Length; i++)
             {
                 if (fileExtension == allowedExtensions[i])
                 {
                     fileTypeOK = true;
                     break;
                 }
             }
             if (fileTypeOK == false)
             {
                 MessageBox.Show(this, "你要上传的文件类型不符合要求!");
                 return;
             }
             if (fileTypeOK == true)
             {
                 if (txtImgUrl.PostedFile.ContentLength > 10240000)
                 {
                     MessageBox.Show(this, "你选择上传的文件不能大于10M,请重新选择!");
                     return;
                 }
                 if (txtImgUrl.PostedFile.ContentLength <= 10240000)
                 {
                     try
                     {
                         string SaveFileName = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + fileExtension;
                         txtImgUrl.PostedFile.SaveAs(path + SaveFileName);
                         WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
                         WebProject.Model.BaseData.ZT_COM_News model_News = bll_News.GetModel(Int32.Parse(Request["NewsID"].ToString()));
                         model_News.Body = this.txtBody.Text.Trim();
                         model_News.NewsTypeName = this.txtNewsType.Items[this.txtNewsType.SelectedIndex].Text.ToString();
                         model_News.NewsTypeNo = this.txtNewsType.SelectedValue.ToString();
                         model_News.LastUpdateBy = SessionUtil.GetAdminSession().AdminNo;
                         model_News.LastUpdateDate = DateTime.Now;
                         model_News.ImgUrl = SaveFileName;
                         model_News.NewsOrder = Int32.Parse(this.txtNewsOrder.Text.Trim());
                         model_News.Title = this.txtTitle.Text.Trim();
                         bll_News.Update(model_News);
                         LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "修改新闻", "成功", "新闻标题:" + model_News.Title + ", 修改人:" + SessionUtil.GetAdminSession().AdminNo);
                         MessageBox.ShowAndRedirect(this, "修改信息成功!", "NewsList.aspx");
                     }
                     catch (Exception)
                     {
                         MessageBox.Show(this, "文件上传失败!");
                         return;
                     }
                 }
             }
         }
     }
 }
    protected void btnDeleteSelect_Click(object sender, EventArgs e)
    {
        if (Session["ZT_ADMIN"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            if (!Communal.CheckQx("NewsDelete.aspx"))
            {
                Response.Redirect("RightsWarn.aspx");
            }
            else
            {
                string DeleteTitle = "";
                foreach (GridViewRow gr in this.GridView1.Rows)
                {
                    CheckBox cb = (CheckBox)gr.Cells[1].FindControl("Select");
                    if (cb.Checked)
                    {
                        //删除数据库信息
                        Label ll = (Label)gr.Cells[1].FindControl("lblNewsID");
                        int NewsID = Convert.ToInt32(ll.Text);
                        WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
                        DeleteTitle += bll_News.GetModel(NewsID).Title + ",";
                        bll_News.Delete(NewsID);

                        //删除文件夹的图片
                        Label l2 = (Label)gr.Cells[0].FindControl("lblImgUrl");

                        if (l2.Text != "onlinenone.jpg")
                        {
                            System.IO.File.Delete(Server.MapPath("IMG/" + l2.Text));
                        }
                    }
                }
                LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "删除新闻", "成功", "新闻标题:" + DeleteTitle.TrimEnd(',') + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo);
                ShowData(txtNewsType.SelectedValue.ToString());
            }
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (Session["ZT_ADMIN"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            if (!Communal.CheckQx("NewsDelete.aspx"))
            {
                Response.Redirect("RightsWarn.aspx");
            }
            else
            {
                //删除数据库的信息
                Label ll = (Label)this.GridView1.Rows[e.RowIndex].Cells[1].FindControl("lblNewsID");
                int NewsID = Convert.ToInt32(ll.Text);
                WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
                LogManage.WriteLog(Request.UserHostAddress, "新闻管理", "删除新闻", "成功", "新闻标题:" + bll_News.GetModel(NewsID).Title + ", 操作人:" + SessionUtil.GetAdminSession().AdminNo);

                bll_News.Delete(NewsID);
                //删除文件夹的图片
                Label l2 = (Label)this.GridView1.Rows[e.RowIndex].Cells[0].FindControl("lblImgUrl");
                if (l2.Text != "onlinenone.jpg")
                {
                    System.IO.File.Delete(Server.MapPath("IMG/" + l2.Text));
                }
                //重新加载信息
                ShowData(txtNewsType.SelectedValue.ToString());
            }
        }
    }
 protected void btnSearch_Click(object sender, EventArgs e)
 {
     if (this.txtTitle.Text.Trim() != "")
     {
         WebProject.BLL.BaseData.ZT_COM_News bll_News = new WebProject.BLL.BaseData.ZT_COM_News();
         DataSet ds = bll_News.GetList("Title like '%" + this.txtTitle.Text.Trim() + "%'");
         if (ds.Tables[0].Rows.Count > 0)
         {
             this.lblMessage.Visible = false;
             this.btnDeleteSelect.Visible = true;
             this.GridView1.Visible = true;
             this.GridView1.DataSource = ds;
             this.GridView1.DataBind();
         }
         else
         {
             this.lblMessage.Visible = true;
             this.btnDeleteSelect.Visible = false;
             this.GridView1.Visible = false;
         }
     }
     else
     {
         this.txtTitle.Text = "请在此输入你要新闻标题";
     }
 }