mail_list_delete.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:7k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.SqlClient;
- public partial class web_mail_mail_list_delete : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- LoginDAO.CheckLogin(Session, Response, "../", 2);
- if (!IsPostBack)
- {
- //設置主鍵
- MailList.DataKeyNames = new string[] { "id" };
- if (Request.QueryString["r_id"] != null)
- {
- PnlMail.Visible = true;
- this.readMail(Request.QueryString["r_id"]);
- this.setMail(Request.QueryString["r_id"]);
- }
- }
- }
- protected void readMail(string id)
- {
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("update OA_MAIL_RECEIVER set is_read=1, read_date='" +
- time + "' where id=" + id, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- MailList.DataBind();
- }
- protected void setMail(string r_id)
- {
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("SELECT r.mail_id, m.title, m.content, s.send_date, " +
- "e.id, e.emp_no, e.emp_name, p.name position FROM dbo.OA_MAIL_RECEIVER AS r INNER JOIN " +
- "dbo.OA_MAIL_SENDER AS s ON r.mail_id = s.mail_id INNER JOIN dbo.OA_EMPLOYEE AS e " +
- "ON s.sender = e.id INNER JOIN dbo.OA_MAIL_CONTENT AS m ON r.mail_id = m.id inner " +
- "join OA_EMPLOYEE_POSITION p on e.position=p.id WHERE r.id=" + r_id, conn);
- SqlDataReader dr = cmd.ExecuteReader();
- string mail_id = "0";
- if (dr.Read())
- {
- mail_id = dr["mail_id"].ToString();
- LblTitle.Text = dr["title"].ToString();
- TxtContent.Text = dr["content"].ToString().Replace("<br>", "n").Replace(" ", " ");
- LblSendDate.Text = dr["send_date"].ToString();
- SenderId.Value = dr["id"].ToString();
- LblSender.Text = dr["emp_no"].ToString() + " " + dr["emp_name"].ToString() + dr["position"].ToString();
- }
- dr.Close();
- cmd = new SqlCommand("select e.id, e.emp_no, e.emp_name, p.name from OA_MAIL_RECEIVER r inner join " +
- "OA_EMPLOYEE e on r.receiver=e.id inner join OA_EMPLOYEE_POSITION p on e.position=p.id " +
- "where mail_id=" + mail_id, conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- ReceiverIds.Value = ReceiverIds.Value + dr["id"].ToString() + ";";
- LblReceivers.Text = LblReceivers.Text + dr["emp_no"].ToString() + " " +
- dr["emp_name"].ToString() + dr["name"].ToString() + "; ";
- }
- dr.Close();
- if (!LblReceivers.Text.Equals(""))
- {
- LblReceivers.Text = LblReceivers.Text.Substring(0, LblReceivers.Text.Length - 2);
- }
- cmd = new SqlCommand("select cn_name, en_name, content_length from OA_MAIL_ATTACHMENT where mail_id=" + mail_id, conn);
- dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- BtnAttachment.Text = dr["cn_name"].ToString();
- AttachmentEnName.Value = dr["en_name"].ToString();
- ContentLength.Value = dr["content_length"].ToString();
- }
- else
- {
- //沒有附件
- LblNoAttachment.Visible = true;
- BtnAttachment.Visible = false;
- }
- dr.Close();
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.ToString());
- }
- }
- protected void MailList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("Restore"))
- {
- string id = e.CommandArgument.ToString();
- //點擊刪除按鈕
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("update OA_MAIL_RECEIVER set is_del=0 where id=" + id, conn);
- cmd.ExecuteNonQuery();
- MailList.DataBind();
- PnlMail.Visible = false;
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }
- protected void MailList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- LinkButton btnRestore = (LinkButton)e.Row.FindControl("BtnRestore");
- btnRestore.CommandArgument = MailList.DataKeys[e.Row.RowIndex].Value.ToString();
- }
- }
- protected void MailList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //行高亮
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "this.style.cursor='pointer';");
- e.Row.Attributes.Add("onclick", "location.href='mail_list_delete.aspx?r_id=" + MailList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
- }
- }
- protected void BtnAttachment_Click(object sender, EventArgs e)
- {
- this.DownLoadFile(AttachmentEnName.Value);
- }
- protected void DownLoadFile(string name)
- {
- string server_ip = "";
- string root = "";
- string folder = "";
- if (Application["FILE_SERVER_IP"] != null)
- {
- server_ip = Application["FILE_SERVER_IP"].ToString();
- }
- if (Application["FILE_SERVER_ROOT"] != null)
- {
- root = Application["FILE_SERVER_ROOT"].ToString();
- }
- if (Application["MAIL_FOLDER"] != null)
- {
- folder = Application["MAIL_FOLDER"].ToString();
- }
- //string directory = "\\" + server_ip + "\" + root + "\" + folder + "\";
- string directory = "\web\oa_upload\mail\";
- try
- {
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(BtnAttachment.Text, System.Text.Encoding.UTF8));
- Response.AppendHeader("Content-Length", ContentLength.Value);
- Response.WriteFile(directory + name);
- Response.Flush();
- Response.End();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }