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

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_mail_mail_list_delete : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         LoginDAO.CheckLogin(Session, Response, "../", 2);
  17.         if (!IsPostBack)
  18.         {
  19.             //設置主鍵
  20.             MailList.DataKeyNames = new string[] { "id" };
  21.             if (Request.QueryString["r_id"] != null)
  22.             {
  23.                 PnlMail.Visible = true;
  24.                 this.readMail(Request.QueryString["r_id"]);
  25.                 this.setMail(Request.QueryString["r_id"]);
  26.             }
  27.         }
  28.     }
  29.     protected void readMail(string id)
  30.     {
  31.         DateMgr mgr = new DateMgr();
  32.         string time = mgr.getDateTime();
  33.         SqlConnection conn = dbConnection.getConnection();
  34.         conn.Open();
  35.         SqlCommand cmd = new SqlCommand("update OA_MAIL_RECEIVER set is_read=1, read_date='" +
  36.             time + "' where id=" + id, conn);
  37.         cmd.ExecuteNonQuery();
  38.         conn.Close();
  39.         MailList.DataBind();
  40.     }
  41.     protected void setMail(string r_id)
  42.     {
  43.         try
  44.         {
  45.             SqlConnection conn = dbConnection.getConnection();
  46.             conn.Open();
  47.             SqlCommand cmd = new SqlCommand("SELECT r.mail_id, m.title, m.content, s.send_date, " +
  48.                 "e.id, e.emp_no, e.emp_name, p.name position FROM dbo.OA_MAIL_RECEIVER AS r INNER JOIN " +
  49.                 "dbo.OA_MAIL_SENDER AS s ON r.mail_id = s.mail_id INNER JOIN dbo.OA_EMPLOYEE AS e " +
  50.                 "ON s.sender = e.id INNER JOIN dbo.OA_MAIL_CONTENT AS m ON r.mail_id = m.id inner " +
  51.                 "join OA_EMPLOYEE_POSITION p on e.position=p.id WHERE r.id=" + r_id, conn);
  52.             SqlDataReader dr = cmd.ExecuteReader();
  53.             string mail_id = "0";
  54.             if (dr.Read())
  55.             {
  56.                 mail_id = dr["mail_id"].ToString();
  57.                 LblTitle.Text = dr["title"].ToString();
  58.                 TxtContent.Text = dr["content"].ToString().Replace("<br>", "n").Replace("&nbsp;", " ");
  59.                 LblSendDate.Text = dr["send_date"].ToString();
  60.                 SenderId.Value = dr["id"].ToString();
  61.                 LblSender.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + dr["position"].ToString();
  62.             }
  63.             dr.Close();
  64.             cmd = new SqlCommand("select e.id, e.emp_no, e.emp_name, p.name from OA_MAIL_RECEIVER r inner join " +
  65.                 "OA_EMPLOYEE e on r.receiver=e.id inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
  66.                 "where mail_id=" + mail_id, conn);
  67.             dr = cmd.ExecuteReader();
  68.             while (dr.Read())
  69.             {
  70.                 ReceiverIds.Value = ReceiverIds.Value + dr["id"].ToString() + ";";
  71.                 LblReceivers.Text = LblReceivers.Text + dr["emp_no"].ToString() + " " +
  72.                     dr["emp_name"].ToString() + dr["name"].ToString() + "; ";
  73.             }
  74.             dr.Close();
  75.             if (!LblReceivers.Text.Equals(""))
  76.             {
  77.                 LblReceivers.Text = LblReceivers.Text.Substring(0, LblReceivers.Text.Length - 2);
  78.             }
  79.             cmd = new SqlCommand("select cn_name, en_name, content_length from OA_MAIL_ATTACHMENT where mail_id=" + mail_id, conn);
  80.             dr = cmd.ExecuteReader();
  81.             if (dr.Read())
  82.             {
  83.                 BtnAttachment.Text = dr["cn_name"].ToString();
  84.                 AttachmentEnName.Value = dr["en_name"].ToString();
  85.                 ContentLength.Value = dr["content_length"].ToString();
  86.             }
  87.             else
  88.             {
  89.                 //沒有附件
  90.                 LblNoAttachment.Visible = true;
  91.                 BtnAttachment.Visible = false;
  92.             }
  93.             dr.Close();
  94.             conn.Close();
  95.         }
  96.         catch (Exception ex)
  97.         {
  98.             Response.Write(ex.ToString());
  99.         }
  100.     }
  101.     protected void MailList_RowCommand(object sender, GridViewCommandEventArgs e)
  102.     {
  103.         if (e.CommandName.Equals("Restore"))
  104.         {
  105.             string id = e.CommandArgument.ToString();
  106.             //點擊刪除按鈕
  107.             try
  108.             {
  109.                 SqlConnection conn = dbConnection.getConnection();
  110.                 conn.Open();
  111.                 SqlCommand cmd = new SqlCommand("update OA_MAIL_RECEIVER set is_del=0 where id=" + id, conn);
  112.                 cmd.ExecuteNonQuery();
  113.                 MailList.DataBind();
  114.                 PnlMail.Visible = false;
  115.             }
  116.             catch (Exception ex)
  117.             {
  118.                 Response.Write(ex.Message);
  119.             }
  120.         }
  121.     }
  122.     protected void MailList_RowCreated(object sender, GridViewRowEventArgs e)
  123.     {
  124.         if (e.Row.RowType == DataControlRowType.DataRow)
  125.         {
  126.             LinkButton btnRestore = (LinkButton)e.Row.FindControl("BtnRestore");
  127.             btnRestore.CommandArgument = MailList.DataKeys[e.Row.RowIndex].Value.ToString();
  128.         }
  129.     }
  130.     protected void MailList_RowDataBound(object sender, GridViewRowEventArgs e)
  131.     {
  132.         //行高亮
  133.         if (e.Row.RowType == DataControlRowType.DataRow)
  134.         {
  135.             e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
  136.             e.Row.Attributes.Add("onclick", "location.href='mail_list_delete.aspx?r_id=" + MailList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
  137.         }
  138.     }
  139.     protected void BtnAttachment_Click(object sender, EventArgs e)
  140.     {
  141.         this.DownLoadFile(AttachmentEnName.Value);
  142.     }
  143.     protected void DownLoadFile(string name)
  144.     {
  145.         string server_ip = "";
  146.         string root = "";
  147.         string folder = "";
  148.         if (Application["FILE_SERVER_IP"] != null)
  149.         {
  150.             server_ip = Application["FILE_SERVER_IP"].ToString();
  151.         }
  152.         if (Application["FILE_SERVER_ROOT"] != null)
  153.         {
  154.             root = Application["FILE_SERVER_ROOT"].ToString();
  155.         }
  156.         if (Application["MAIL_FOLDER"] != null)
  157.         {
  158.             folder = Application["MAIL_FOLDER"].ToString();
  159.         }
  160.         //string directory = "\\" + server_ip + "\" + root + "\" + folder + "\";
  161.         string directory = "\web\oa_upload\mail\";
  162.         try
  163.         {
  164.             Response.Clear();
  165.             Response.ClearHeaders();
  166.             Response.Buffer = false;
  167.             Response.ContentType = "application/octet-stream";
  168.             Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(BtnAttachment.Text, System.Text.Encoding.UTF8));
  169.             Response.AppendHeader("Content-Length", ContentLength.Value);
  170.             Response.WriteFile(directory + name);
  171.             Response.Flush();
  172.             Response.End();
  173.         }
  174.         catch (Exception ex)
  175.         {
  176.             Response.Write(ex.Message);
  177.         }
  178.     }
  179. }