report_list_send.aspx.cs
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:13k
源码类别:

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  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.Data.SqlClient;
  12. public partial class web_report_report_list_send : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             if (Request.QueryString["s_id"] != null)
  19.             {
  20.                 PnlReport.Visible = true;
  21.                 this.setReport(Request.QueryString["s_id"]);
  22.             }
  23.         }
  24.     }
  25.     protected void setReport(string s_id)
  26.     {
  27.         ArrayList emp_names = new ArrayList();
  28.         ArrayList department_id = new ArrayList();
  29.         ArrayList read_date = new ArrayList();
  30.         try
  31.         {
  32.             SqlConnection conn = dbConnection.getConnection();
  33.             conn.Open();
  34.             SqlCommand cmd = new SqlCommand("SELECT s.report_id, r.title, r.content, r.proposal, r.summarize, s.send_date FROM dbo.OA_REPORT_SENDER AS s INNER JOIN dbo.OA_REPORT_CONTENT AS r ON s.report_id = r.id WHERE s.id=" + s_id, conn);
  35.             SqlDataReader dr = cmd.ExecuteReader();
  36.             string report_id = "0";
  37.             if (dr.Read())
  38.             {
  39.                 report_id = dr["report_id"].ToString();
  40.                 LblTitle.Text = dr["title"].ToString();
  41.                 LblContent.Text = dr["content"].ToString();
  42.                 LblProposal.Text = dr["proposal"].ToString();
  43.                 LblSummarize.Text = dr["summarize"].ToString();
  44.                 LblSendDate.Text = dr["send_date"].ToString();
  45.             }
  46.             dr.Close();
  47.             cmd = new SqlCommand("select name, content_length from OA_REPORT_ATTACHMENT where report_id=" + report_id, conn);
  48.             dr = cmd.ExecuteReader();
  49.             if (dr.Read())
  50.             {
  51.                 BtnAttachment.Text = dr["name"].ToString();
  52.                 ContentLength.Value = dr["content_length"].ToString();
  53.             }
  54.             else
  55.             {
  56.                 //沒有附件
  57.                 BtnAttachment.Visible = false;
  58.                 LblNoAttachment.Visible = true;
  59.                 LblNoAttachment.Text = "無";
  60.             }
  61.             dr.Close();
  62.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id, conn);
  63.             int count = Convert.ToInt32(cmd.ExecuteScalar());
  64.             LblStatistics.Text = "收件人共" + count + "人;";
  65.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
  66.                 " and is_read=1", conn);
  67.             LblStatistics.Text = LblStatistics.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人已讀;";
  68.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
  69.                 " and is_read=0", conn);
  70.             LblStatistics.Text = LblStatistics.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人未讀";
  71.             //創建已讀人員信息列表
  72.             cmd = new SqlCommand("select r.id, e.emp_name, e.department_id, r.read_date from " +
  73.                 "OA_REPORT_RECEIVER r inner join OA_EMPLOYEE e on r.receiver=e.id where is_read=1 and report_id=" + report_id, conn);
  74.             dr = cmd.ExecuteReader();
  75.             emp_names.Clear();
  76.             department_id.Clear();
  77.             read_date.Clear();
  78.             while (dr.Read())
  79.             {
  80.                 emp_names.Add(dr["emp_name"].ToString());
  81.                 department_id.Add(dr["department_id"].ToString());
  82.                 read_date.Add(dr["read_date"].ToString());
  83.             }
  84.             dr.Close();
  85.             if (emp_names.Count > 0)
  86.             {
  87.                 //添加表頭
  88.                 TableRow tr = new TableRow();
  89.                 TableCell cell1 = new TableCell();
  90.                 cell1.Text = "員工姓名";
  91.                 TableCell cell2 = new TableCell();
  92.                 cell2.Text = "所屬部門";
  93.                 TableCell cell3 = new TableCell();
  94.                 cell3.Text = "最後閱讀時間";
  95.                 tr.Cells.Add(cell1);
  96.                 tr.Cells.Add(cell2);
  97.                 tr.Cells.Add(cell3);
  98.                 TblRead.Rows.Add(tr);
  99.             }
  100.             for (int i = 0; i < department_id.Count; i++)
  101.             {
  102.                 cmd = new SqlCommand("select name from OA_DEPARTMENT where id=" + department_id[i], conn);
  103.                 string department = cmd.ExecuteScalar().ToString();
  104.                 TableRow tr = new TableRow();
  105.                 TableCell cell1 = new TableCell();
  106.                 cell1.Text = emp_names[i].ToString();
  107.                 TableCell cell2 = new TableCell();
  108.                 cell2.Text = department;
  109.                 TableCell cell3 = new TableCell();
  110.                 cell3.Text = read_date[i].ToString();
  111.                 tr.Cells.Add(cell1);
  112.                 tr.Cells.Add(cell2);
  113.                 tr.Cells.Add(cell3);
  114.                 TblRead.Rows.Add(tr);
  115.             }
  116.             //創建未讀人員信息列表
  117.             cmd = new SqlCommand("select r.id, e.emp_name, e.department_id from OA_REPORT_RECEIVER r " +
  118.                 "inner join OA_EMPLOYEE e on r.receiver=e.id where is_read=0 and report_id=" + report_id, conn);
  119.             dr = cmd.ExecuteReader();
  120.             emp_names.Clear();
  121.             department_id.Clear();
  122.             while (dr.Read())
  123.             {
  124.                 emp_names.Add(dr["emp_name"].ToString());
  125.                 department_id.Add(dr["department_id"].ToString());
  126.             }
  127.             dr.Close();
  128.             if (emp_names.Count > 0)
  129.             {
  130.                 //添加表頭
  131.                 TableRow tr = new TableRow();
  132.                 TableCell cell1 = new TableCell();
  133.                 cell1.Text = "員工姓名";
  134.                 TableCell cell2 = new TableCell();
  135.                 cell2.Text = "所屬部門";
  136.                 tr.Cells.Add(cell1);
  137.                 tr.Cells.Add(cell2);
  138.                 TblUnRead.Rows.Add(tr);
  139.             }
  140.             for (int i = 0; i < department_id.Count; i++)
  141.             {
  142.                 DepartmentDAO departmentDAO = new DepartmentDAO();
  143.                 string department = (departmentDAO.queryById(Convert.ToInt32(department_id[i]))).Full_name;
  144.                 TableRow tr = new TableRow();
  145.                 TableCell cell1 = new TableCell();
  146.                 cell1.Text = emp_names[i].ToString();
  147.                 TableCell cell2 = new TableCell();
  148.                 cell2.Text = department;
  149.                 tr.Cells.Add(cell1);
  150.                 tr.Cells.Add(cell2);
  151.                 TblUnRead.Rows.Add(tr);
  152.             }
  153.             dr.Close();
  154.             //簽批
  155.             cmd = new SqlCommand("select e.emp_name, r.sign_date, r.sign from OA_REPORT_RECEIVER r inner " +
  156.                 "join OA_EMPLOYEE e on r.receiver=e.id where report_id="+report_id+"and sign<>''", conn);
  157.             dr = cmd.ExecuteReader();
  158.             while (dr.Read())
  159.             {
  160.                 TableRow tr1 = new TableRow();
  161.                 TableCell td1 = new TableCell();
  162.                 td1.Text = "簽批人";
  163.                 td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
  164.                 TableCell td2 = new TableCell();
  165.                 td2.Text = dr["emp_name"].ToString();
  166.                 td2.HorizontalAlign = HorizontalAlign.Left;
  167.                 tr1.Cells.Add(td1);
  168.                 tr1.Cells.Add(td2);
  169.                 TblSign.Rows.Add(tr1);
  170.                 TableRow tr2 = new TableRow();
  171.                 td1 = new TableCell();
  172.                 td1.Text = "簽批時間";
  173.                 td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
  174.                 td2 = new TableCell();
  175.                 td2.Text = dr["sign_date"].ToString();
  176.                 td2.HorizontalAlign = HorizontalAlign.Left;
  177.                 tr2.Cells.Add(td1);
  178.                 tr2.Cells.Add(td2);
  179.                 TblSign.Rows.Add(tr2);
  180.                 TableRow tr3 = new TableRow();
  181.                 td1 = new TableCell();
  182.                 td1.Text = "簽批內容";
  183.                 td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
  184.                 td2 = new TableCell();
  185.                 td2.Text = dr["sign"].ToString();
  186.                 td2.HorizontalAlign = HorizontalAlign.Left;
  187.                 tr3.Cells.Add(td1);
  188.                 tr3.Cells.Add(td2);
  189.                 TblSign.Rows.Add(tr3);
  190.                 TblSign.Rows.Add(new TableRow());
  191.             }
  192.             dr.Close();
  193.             conn.Close();
  194.         }
  195.         catch (Exception ex)
  196.         {
  197.             Response.Write(ex.ToString());
  198.         }
  199.     }
  200.     protected void DownLoadFile(string name)
  201.     {
  202.         string server_ip = "";
  203.         string root = "";
  204.         string folder = "";
  205.         if (Application["FILE_SERVER_IP"] != null)
  206.         {
  207.             server_ip = Application["FILE_SERVER_IP"].ToString();
  208.         }
  209.         if (Application["FILE_SERVER_ROOT"] != null)
  210.         {
  211.             root = Application["FILE_SERVER_ROOT"].ToString();
  212.         }
  213.         if (Application["REPORT_FOLDER"] != null)
  214.         {
  215.             folder = Application["REPORT_FOLDER"].ToString();
  216.         }
  217.         string directory = "d:\oa(new)\web\oa_upload\report\";
  218.         try
  219.         {
  220.             Response.Clear();
  221.             Response.ClearHeaders();
  222.             Response.Buffer = false;
  223.             Response.ContentType = "application/octet-stream";
  224.             Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8));
  225.             Response.AppendHeader("Content-Length", ContentLength.Value);
  226.             Response.WriteFile(directory + name);
  227.             Response.Flush();
  228.             Response.End();
  229.         }
  230.         catch (Exception ex)
  231.         {
  232.             Response.Write(ex.Message);
  233.         }
  234.     }
  235.     protected void Page_Init(object sender, EventArgs e)
  236.     { 
  237.         if (Session["user"] != null)
  238.         {
  239.             int user_id = ((User)Session["user"]).Id;
  240.             SqlDataSource1.SelectCommand = SqlDataSource1.SelectCommand + " and sender="+user_id;
  241.         }
  242.     }
  243.     protected void ReportList_RowDataBound(object sender, GridViewRowEventArgs e)
  244.     {
  245.         //設置主鍵
  246.         ReportList.DataKeyNames = new string[] { "id" };
  247.         //行高亮
  248.         if (e.Row.RowType == DataControlRowType.DataRow)
  249.         {
  250.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';this.style.cursor='pointer';");
  251.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  252.             e.Row.Attributes.Add("onclick", "location.href='report_list_send.aspx?s_id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  253.         }
  254.     }
  255.     protected void ReportList_RowCreated(object sender, GridViewRowEventArgs e)
  256.     {
  257.         if (e.Row.RowType == DataControlRowType.DataRow)
  258.         {
  259.             LinkButton btnDelete = (LinkButton)e.Row.FindControl("btnDelete");
  260.             btnDelete.CommandArgument = ReportList.DataKeys[e.Row.RowIndex].Value.ToString();
  261.             SqlConnection conn = dbConnection.getConnection();
  262.             conn.Open();
  263.             Label label = (Label)e.Row.FindControl("LblStatistics");
  264.             string report_id = "0";
  265.             SqlCommand cmd = new SqlCommand("SELECT report_id FROM dbo.OA_REPORT_SENDER where id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  266.             SqlDataReader dr = cmd.ExecuteReader();
  267.             if (dr.Read())
  268.             {
  269.                 report_id = dr["report_id"].ToString();
  270.             }
  271.             dr.Close();
  272.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
  273.                 " and is_read=1", conn);
  274.             label.Text = Convert.ToInt32(cmd.ExecuteScalar()) + "人已讀;";
  275.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
  276.                 " and is_read=0", conn);
  277.             label.Text = label.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人未讀;";
  278.             cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
  279.                 " and sign<>''", conn);
  280.             label.Text = label.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人已簽批";
  281.             conn.Close();
  282.         }
  283.     }
  284.     protected void ReportList_RowCommand(object sender, GridViewCommandEventArgs e)
  285.     {
  286.         if (e.CommandName.Equals("DeleteData"))
  287.         {
  288.             string id = e.CommandArgument.ToString();
  289.             //點擊刪除按鈕
  290.             try
  291.             {
  292.                 SqlConnection conn = dbConnection.getConnection();
  293.                 conn.Open();
  294.                 SqlCommand cmd = new SqlCommand("update OA_REPORT_SENDER set is_del=1 where id=" + id, conn);
  295.                 cmd.ExecuteNonQuery();
  296.                 conn.Close();
  297.                 ReportList.DataBind();
  298.                 PnlReport.Visible = false;
  299.             }
  300.             catch (Exception ex)
  301.             {
  302.                 Response.Write(ex.Message);
  303.             }
  304.         }
  305.     }
  306.     protected void BtnAttachment_Click(object sender, EventArgs e)
  307.     {
  308.         this.DownLoadFile(BtnAttachment.Text);
  309.     }
  310. }