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

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_receive : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (!IsPostBack)
  17.         {
  18.             if (Request.QueryString["r_id"] != null)
  19.             {
  20.                 PnlReport.Visible = true;
  21.                 this.readReport(Request.QueryString["r_id"]);
  22.                 this.setReport(Request.QueryString["r_id"]);
  23.             }
  24.         }
  25.     }
  26.     protected void readReport(string id)
  27.     {
  28.         SqlConnection conn = dbConnection.getConnection();
  29.         conn.Open();
  30.         DateMgr mgr = new DateMgr();
  31.         string time = mgr.getDateTime();
  32.         SqlCommand cmd = new SqlCommand("update OA_REPORT_RECEIVER set is_read=1, read_date='" +
  33.             time + "' where id=" + id, conn);
  34.         cmd.ExecuteNonQuery();
  35.         conn.Close();
  36.         ReportList.DataBind();
  37.     }
  38.     protected void setReport(string r_id)
  39.     {
  40.         try
  41.         {
  42.             SqlConnection conn = dbConnection.getConnection();
  43.             conn.Open();
  44.             SqlCommand cmd = new SqlCommand("SELECT r.report_id, r.sign, r.sign_date, m.title, m.content, m.proposal, m.summarize, s.send_date, e.emp_name FROM dbo.OA_REPORT_RECEIVER AS r INNER JOIN dbo.OA_REPORT_SENDER AS s ON r.report_id = s.report_id INNER JOIN dbo.OA_EMPLOYEE AS e ON s.sender = e.id INNER JOIN dbo.OA_REPORT_CONTENT AS m ON r.report_id = m.id WHERE r.id=" + r_id, conn);
  45.             SqlDataReader dr = cmd.ExecuteReader();
  46.             string report_id = "0";
  47.             if (dr.Read())
  48.             {
  49.                 report_id = dr["report_id"].ToString();
  50.                 LblSign.Text = dr["sign"].ToString();
  51.                 LblSignDate.Text = dr["sign_date"].ToString();
  52.                 LblTitle.Text = dr["title"].ToString();
  53.                 LblContent.Text = dr["content"].ToString();
  54.                 LblProposal.Text = dr["proposal"].ToString();
  55.                 LblSummarize.Text = dr["summarize"].ToString();
  56.                 LblSendDate.Text = dr["send_date"].ToString();
  57.                 LblReceiver.Text = dr["emp_name"].ToString();
  58.             }
  59.             dr.Close();
  60.             cmd = new SqlCommand("select name, content_length from OA_REPORT_ATTACHMENT where report_id=" + report_id, conn);
  61.             dr = cmd.ExecuteReader();
  62.             if (dr.Read())
  63.             {
  64.                 BtnAttachment.Text = dr["name"].ToString();
  65.                 ContentLength.Value = dr["content_length"].ToString();
  66.             }
  67.             else
  68.             {
  69.                 //沒有附件
  70.                 BtnAttachment.Visible = false;
  71.                 LblNoAttachment.Visible = true;
  72.             }
  73.             dr.Close();
  74.             conn.Close();
  75.             if (LblSign.Text.Equals(""))
  76.             {
  77.                 PnlSign.Visible = true;
  78.                 Panel1.Visible = false;
  79.             }
  80.             else
  81.             {
  82.                 PnlSign.Visible = false;
  83.                 Panel1.Visible = true;
  84.             }
  85.         }
  86.         catch (Exception ex)
  87.         {
  88.             Response.Write(ex.ToString());
  89.         }
  90.     }
  91.     protected void Page_Init(object sender, EventArgs e)
  92.     {
  93.         if (Session["user"] != null)
  94.         {
  95.             int user_id = ((User)Session["user"]).Id;
  96.             SqlDataSource1.SelectCommand = SqlDataSource1.SelectCommand + " and receiver=" + user_id;
  97.         }
  98.     }
  99.     protected void ReportList_RowCommand(object sender, GridViewCommandEventArgs e)
  100.     {
  101.         if (e.CommandName.Equals("DeleteData"))
  102.         {
  103.             string id = e.CommandArgument.ToString();
  104.             //點擊刪除按鈕
  105.             try
  106.             {
  107.                 SqlConnection conn = dbConnection.getConnection();
  108.                 conn.Open();
  109.                 SqlCommand cmd = new SqlCommand("update OA_REPORT_RECEIVER set is_del=1 where id=" + id, conn);
  110.                 cmd.ExecuteNonQuery();
  111.                 ReportList.DataBind();
  112.             }
  113.             catch (Exception ex)
  114.             {
  115.                 Response.Write(ex.Message);
  116.             }
  117.         }
  118.     }
  119.     protected void ReportList_RowCreated(object sender, GridViewRowEventArgs e)
  120.     {
  121.         if (e.Row.RowType == DataControlRowType.DataRow)
  122.         {
  123.             LinkButton btnDelete = (LinkButton)e.Row.FindControl("BtnDelete");
  124.             btnDelete.CommandArgument = ReportList.DataKeys[e.Row.RowIndex].Value.ToString();
  125.             SqlConnection conn = dbConnection.getConnection();
  126.             conn.Open();
  127.             SqlCommand cmd = new SqlCommand("select is_read, sign from OA_REPORT_RECEIVER where id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
  128.             int is_read = 0;
  129.             string sign = "";
  130.             SqlDataReader dr = cmd.ExecuteReader();
  131.             if(dr.Read())
  132.             {
  133.                 is_read = Convert.ToInt32(dr["is_read"].ToString());
  134.                 sign = dr["sign"].ToString();
  135.             }
  136.             dr.Close();
  137.             Label label = (Label)e.Row.FindControl("LblState");
  138.             if (is_read == 1)
  139.             {
  140.                 label.Text = "已讀";
  141.                 label.ForeColor = System.Drawing.Color.Blue;
  142.             }
  143.             else
  144.             {
  145.                 label.Text = "未讀";
  146.                 label.ForeColor = System.Drawing.Color.Red;
  147.             }
  148.             Label lblSign = (Label)e.Row.FindControl("LblSign");
  149.             if (sign.Equals(""))
  150.             {
  151.                 lblSign.Text = "未簽批";
  152.                 lblSign.ForeColor = System.Drawing.Color.Red;
  153.             }
  154.             else
  155.             {
  156.                 lblSign.Text = "已簽批";
  157.                 lblSign.ForeColor = System.Drawing.Color.Blue;
  158.             }
  159.             conn.Close();
  160.         }
  161.     }
  162.     protected void ReportList_RowDataBound(object sender, GridViewRowEventArgs e)
  163.     {        
  164.         //設置主鍵
  165.         ReportList.DataKeyNames = new string[] { "id" };
  166.         //行高亮
  167.         if (e.Row.RowType == DataControlRowType.DataRow)
  168.         {
  169.             e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';this.style.cursor='pointer';");
  170.             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
  171.             e.Row.Attributes.Add("onclick", "location.href='report_list_receive.aspx?r_id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  172.         }
  173.     }
  174.     protected void BtnAttachment_Click(object sender, EventArgs e)
  175.     {
  176.         this.DownLoadFile(BtnAttachment.Text);
  177.     }
  178.     protected void DownLoadFile(string name)
  179.     {
  180.         string server_ip = "";
  181.         string root = "";
  182.         string folder = "";
  183.         if (Application["FILE_SERVER_IP"] != null)
  184.         {
  185.             server_ip = Application["FILE_SERVER_IP"].ToString();
  186.         }
  187.         if (Application["FILE_SERVER_ROOT"] != null)
  188.         {
  189.             root = Application["FILE_SERVER_ROOT"].ToString();
  190.         }
  191.         if (Application["REPORT_FOLDER"] != null)
  192.         {
  193.             folder = Application["REPORT_FOLDER"].ToString();
  194.         }
  195.         string directory = "d:\oa(new)\web\oa_upload\report\";
  196.         try
  197.         {
  198.             Response.Clear();
  199.             Response.ClearHeaders();
  200.             Response.Buffer = false;
  201.             Response.ContentType = "application/octet-stream";
  202.             Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8));
  203.             Response.AppendHeader("Content-Length", ContentLength.Value);
  204.             Response.WriteFile(directory + name);
  205.             Response.Flush();
  206.             Response.End();
  207.         }
  208.         catch (Exception ex)
  209.         {
  210.             Response.Write(ex.Message);
  211.         }
  212.     }
  213.     protected void BtnOk_Click(object sender, EventArgs e)
  214.     {
  215.         string id = "0";
  216.         if (Request.QueryString["r_id"] != null)
  217.         {
  218.             id = Request.QueryString["r_id"];
  219.         }
  220.         SqlConnection conn = dbConnection.getConnection();
  221.         conn.Open();
  222.         
  223.         DateMgr mgr = new DateMgr();
  224.         string time = mgr.getDateTime();
  225.         string sql = "update OA_REPORT_RECEIVER set sign='"+TxtSign.Text.Replace("n","<br>").
  226.             Replace(" ", "&nbsp;")+"', sign_date='"+time+"' where id="+id;
  227.         SqlCommand cmd = new SqlCommand(sql, conn);
  228.         int count = cmd.ExecuteNonQuery();
  229.         conn.Close();
  230.         ReportList.DataBind();
  231.         PnlReport.Visible = false;
  232.         PnlSign.Visible = false;
  233.     }
  234. }