FilesManager.aspx.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:6k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections.Generic;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.IO;
  12. public partial class FileBooks_FilesManager : System.Web.UI.Page
  13. {
  14.     /// <summary>
  15.     /// 模板 
  16.     /// </summary>
  17.     Model.Files MR = new Model.Files();
  18.     /// <summary>
  19.     /// 业务
  20.     /// </summary>
  21.     BLL.Files BR = new BLL.Files();
  22.     /// <summary>
  23.     /// 查询条件
  24.     /// </summary>
  25.     public string TiaoJian
  26.     {
  27.         get
  28.         {
  29.             if (ViewState["FilesTiaoJian"] == null)
  30.             {
  31.                 return "";
  32.             }
  33.             else
  34.             {
  35.                 return ViewState["FilesTiaoJian"].ToString();
  36.             }
  37.         }
  38.         set { ViewState["FilesTiaoJian"] = value; }
  39.     }
  40.     protected void Page_Load(object sender, EventArgs e)
  41.     {
  42.         LoginLogic.MatchLoad("../", "FileBooks_FilesManager");
  43.         if (!IsPostBack)
  44.         {
  45.             TiaoJian = "";
  46.             if (Request.QueryString["TiaoJian"] != null)
  47.             {
  48.                 TiaoJian = Server.UrlDecode(Request.QueryString["TiaoJian"].ToString());
  49.             }
  50.             MyDataBind(1);
  51.         }
  52.     }
  53.     /// <summary>
  54.     /// 获取信息
  55.     /// </summary>
  56.     /// <param name="pidx">页号</param>
  57.     public void MyDataBind(int pidx)
  58.     {
  59.         AspNetPager1.RecordCount = BR.GetCount(TiaoJian);
  60.         List<Model.Files> LRData = BR.GetPageList(20, pidx, "ID", false, TiaoJian);
  61.         if (LRData.Count == 0)
  62.         {
  63.             Model.Files MR = new Model.Files();
  64.             LRData.Add(MR);
  65.         }
  66.         GridView1.DataSource = LRData;
  67.         GridView1.DataBind();
  68.     }
  69.     /// <summary>
  70.     /// 卷按案
  71.     /// </summary>
  72.     /// <returns></returns>
  73.     public string SuoShuJuanAn()
  74.     {
  75.         if (Eval("SSJA") != null)
  76.         {
  77.             int Id = int.Parse(Eval("SSJA").ToString());
  78.             return EnumGet.GetRollName(Id);
  79.         }
  80.         else
  81.         {
  82.             return "";
  83.         }
  84.     }
  85.     /// <summary>
  86.     /// 附件下载地址
  87.     /// </summary>
  88.     /// <returns></returns>
  89.     public string FuJian()
  90.     {
  91.         if (Eval("FJPath") != null)
  92.         {
  93.             string FJPath = Eval("FJPath").ToString();
  94.             return "<a href='UpLoadFiles/" + FJPath + "' target='_blank'>下载</a>";
  95.         }
  96.         else
  97.         {
  98.             return "-";
  99.         }
  100.     }
  101.     /// <summary>
  102.     /// 操作
  103.     /// </summary>
  104.     /// <returns></returns>
  105.     public string CaoZuo()
  106.     {
  107.         string Id = Eval("Id").ToString();
  108.         //编辑 清空密码 删除
  109.         string Rtstr = "<a href='UpFilesAdd.aspx'>添加文件</a>&nbsp;&nbsp;";
  110.         if (BR.GetCount(TiaoJian) > 0)
  111.         {
  112.             Rtstr += "<a href='UpFilesEdit.aspx?id=" + Id + "'>修改文件信息</a>&nbsp;&nbsp;";
  113.         }
  114.         return Rtstr;
  115.     }
  116.     protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
  117.     {
  118.         MyDataBind(e.NewPageIndex);
  119.     }
  120.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  121.     {
  122.         for (int i = 0; i < GridView1.Rows.Count; i++)
  123.         {
  124.             //首先判断是否是数据行
  125.             if (e.Row.RowType == DataControlRowType.DataRow)
  126.             {
  127.                 //当鼠标停留时更改背景色
  128.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F0F0F0'");
  129.                 //当鼠标移开时还原背景色
  130.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  131.             }
  132.         }
  133.     }
  134.     protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  135.     {
  136.         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  137.         {
  138.             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  139.             if (CheckBox1.Checked)
  140.             {
  141.                 cbox.Checked = true;
  142.             }
  143.             else
  144.             {
  145.                 cbox.Checked = false;
  146.             }
  147.         }
  148.     }
  149.     protected void DelButton1_Click(object sender, EventArgs e)
  150.     {
  151.         try
  152.         {
  153.             for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
  154.             {
  155.                 CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxItem");
  156.                 if (cbox.Checked)
  157.                 {
  158.                     // Response.Write(GridView1.Rows[i].Cells[1].Text.ToString() + ":True");
  159.                   
  160.                     int Id = int.Parse(GridView1.Rows[i].Cells[1].Text.ToString());
  161.                     if (Id == 0)
  162.                     {
  163.                         throw new Exception("该记录不能删除!");
  164.                     }
  165.                     DelFile(Id);
  166.                     BR.Delete(Id);
  167.                 }
  168.                 else
  169.                 {
  170.                     //Response.Write((GridView1.Rows[i].Cells[1]).Text.ToString() + ":False");
  171.                 }
  172.             }
  173.             MessageBox.Show("删除完成!");
  174.         }
  175.         catch (Exception exp)
  176.         { MessageBox.Show(exp.Message); }
  177.         MyDataBind(AspNetPager1.CurrentPageIndex);
  178.     }
  179.     /// <summary>
  180.     /// 删除文件
  181.     /// </summary>
  182.     /// <param name="GuidStr"></param>
  183.     public void DelFile(int ID)
  184.     {
  185.         try
  186.         {
  187.             Model.Files Mf = new BLL.Files().GetModel(ID);
  188.             string FileUpdatePathFull = AppDomain.CurrentDomain.BaseDirectory + "FileBooks\UpLoadFiles\" + Mf.FJPath;
  189.             File.Delete(FileUpdatePathFull);
  190.         }
  191.         catch { }
  192.     }
  193. }