report_list_receive.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:9k
源码类别:
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_report_report_list_receive : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- if (Request.QueryString["r_id"] != null)
- {
- PnlReport.Visible = true;
- this.readReport(Request.QueryString["r_id"]);
- this.setReport(Request.QueryString["r_id"]);
- }
- }
- }
- protected void readReport(string id)
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- SqlCommand cmd = new SqlCommand("update OA_REPORT_RECEIVER set is_read=1, read_date='" +
- time + "' where id=" + id, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- ReportList.DataBind();
- }
- protected void setReport(string r_id)
- {
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- 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);
- SqlDataReader dr = cmd.ExecuteReader();
- string report_id = "0";
- if (dr.Read())
- {
- report_id = dr["report_id"].ToString();
- LblSign.Text = dr["sign"].ToString();
- LblSignDate.Text = dr["sign_date"].ToString();
- LblTitle.Text = dr["title"].ToString();
- LblContent.Text = dr["content"].ToString();
- LblProposal.Text = dr["proposal"].ToString();
- LblSummarize.Text = dr["summarize"].ToString();
- LblSendDate.Text = dr["send_date"].ToString();
- LblReceiver.Text = dr["emp_name"].ToString();
- }
- dr.Close();
- cmd = new SqlCommand("select name, content_length from OA_REPORT_ATTACHMENT where report_id=" + report_id, conn);
- dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- BtnAttachment.Text = dr["name"].ToString();
- ContentLength.Value = dr["content_length"].ToString();
- }
- else
- {
- //沒有附件
- BtnAttachment.Visible = false;
- LblNoAttachment.Visible = true;
- }
- dr.Close();
- conn.Close();
- if (LblSign.Text.Equals(""))
- {
- PnlSign.Visible = true;
- Panel1.Visible = false;
- }
- else
- {
- PnlSign.Visible = false;
- Panel1.Visible = true;
- }
- }
- catch (Exception ex)
- {
- Response.Write(ex.ToString());
- }
- }
- protected void Page_Init(object sender, EventArgs e)
- {
- if (Session["user"] != null)
- {
- int user_id = ((User)Session["user"]).Id;
- SqlDataSource1.SelectCommand = SqlDataSource1.SelectCommand + " and receiver=" + user_id;
- }
- }
- protected void ReportList_RowCommand(object sender, GridViewCommandEventArgs e)
- {
- if (e.CommandName.Equals("DeleteData"))
- {
- string id = e.CommandArgument.ToString();
- //點擊刪除按鈕
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("update OA_REPORT_RECEIVER set is_del=1 where id=" + id, conn);
- cmd.ExecuteNonQuery();
- ReportList.DataBind();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }
- protected void ReportList_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- LinkButton btnDelete = (LinkButton)e.Row.FindControl("BtnDelete");
- btnDelete.CommandArgument = ReportList.DataKeys[e.Row.RowIndex].Value.ToString();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand cmd = new SqlCommand("select is_read, sign from OA_REPORT_RECEIVER where id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
- int is_read = 0;
- string sign = "";
- SqlDataReader dr = cmd.ExecuteReader();
- if(dr.Read())
- {
- is_read = Convert.ToInt32(dr["is_read"].ToString());
- sign = dr["sign"].ToString();
- }
- dr.Close();
- Label label = (Label)e.Row.FindControl("LblState");
- if (is_read == 1)
- {
- label.Text = "已讀";
- label.ForeColor = System.Drawing.Color.Blue;
- }
- else
- {
- label.Text = "未讀";
- label.ForeColor = System.Drawing.Color.Red;
- }
- Label lblSign = (Label)e.Row.FindControl("LblSign");
- if (sign.Equals(""))
- {
- lblSign.Text = "未簽批";
- lblSign.ForeColor = System.Drawing.Color.Red;
- }
- else
- {
- lblSign.Text = "已簽批";
- lblSign.ForeColor = System.Drawing.Color.Blue;
- }
- conn.Close();
- }
- }
- protected void ReportList_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- //設置主鍵
- ReportList.DataKeyNames = new string[] { "id" };
- //行高亮
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor; this.style.backgroundColor='#c8dafa';this.style.cursor='pointer';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- e.Row.Attributes.Add("onclick", "location.href='report_list_receive.aspx?r_id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
- }
- }
- protected void BtnAttachment_Click(object sender, EventArgs e)
- {
- this.DownLoadFile(BtnAttachment.Text);
- }
- 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["REPORT_FOLDER"] != null)
- {
- folder = Application["REPORT_FOLDER"].ToString();
- }
- string directory = "d:\oa(new)\web\oa_upload\report\";
- try
- {
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name, 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);
- }
- }
- protected void BtnOk_Click(object sender, EventArgs e)
- {
- string id = "0";
- if (Request.QueryString["r_id"] != null)
- {
- id = Request.QueryString["r_id"];
- }
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DateMgr mgr = new DateMgr();
- string time = mgr.getDateTime();
- string sql = "update OA_REPORT_RECEIVER set sign='"+TxtSign.Text.Replace("n","<br>").
- Replace(" ", " ")+"', sign_date='"+time+"' where id="+id;
- SqlCommand cmd = new SqlCommand(sql, conn);
- int count = cmd.ExecuteNonQuery();
- conn.Close();
- ReportList.DataBind();
- PnlReport.Visible = false;
- PnlSign.Visible = false;
- }
- }