report_list_send.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:13k
源码类别:
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_send : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- if (Request.QueryString["s_id"] != null)
- {
- PnlReport.Visible = true;
- this.setReport(Request.QueryString["s_id"]);
- }
- }
- }
- protected void setReport(string s_id)
- {
- ArrayList emp_names = new ArrayList();
- ArrayList department_id = new ArrayList();
- ArrayList read_date = new ArrayList();
- try
- {
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- 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);
- SqlDataReader dr = cmd.ExecuteReader();
- string report_id = "0";
- if (dr.Read())
- {
- report_id = dr["report_id"].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();
- }
- 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;
- LblNoAttachment.Text = "無";
- }
- dr.Close();
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id, conn);
- int count = Convert.ToInt32(cmd.ExecuteScalar());
- LblStatistics.Text = "收件人共" + count + "人;";
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
- " and is_read=1", conn);
- LblStatistics.Text = LblStatistics.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人已讀;";
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
- " and is_read=0", conn);
- LblStatistics.Text = LblStatistics.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人未讀";
- //創建已讀人員信息列表
- cmd = new SqlCommand("select r.id, e.emp_name, e.department_id, r.read_date from " +
- "OA_REPORT_RECEIVER r inner join OA_EMPLOYEE e on r.receiver=e.id where is_read=1 and report_id=" + report_id, conn);
- dr = cmd.ExecuteReader();
- emp_names.Clear();
- department_id.Clear();
- read_date.Clear();
- while (dr.Read())
- {
- emp_names.Add(dr["emp_name"].ToString());
- department_id.Add(dr["department_id"].ToString());
- read_date.Add(dr["read_date"].ToString());
- }
- dr.Close();
- if (emp_names.Count > 0)
- {
- //添加表頭
- TableRow tr = new TableRow();
- TableCell cell1 = new TableCell();
- cell1.Text = "員工姓名";
- TableCell cell2 = new TableCell();
- cell2.Text = "所屬部門";
- TableCell cell3 = new TableCell();
- cell3.Text = "最後閱讀時間";
- tr.Cells.Add(cell1);
- tr.Cells.Add(cell2);
- tr.Cells.Add(cell3);
- TblRead.Rows.Add(tr);
- }
- for (int i = 0; i < department_id.Count; i++)
- {
- cmd = new SqlCommand("select name from OA_DEPARTMENT where id=" + department_id[i], conn);
- string department = cmd.ExecuteScalar().ToString();
- TableRow tr = new TableRow();
- TableCell cell1 = new TableCell();
- cell1.Text = emp_names[i].ToString();
- TableCell cell2 = new TableCell();
- cell2.Text = department;
- TableCell cell3 = new TableCell();
- cell3.Text = read_date[i].ToString();
- tr.Cells.Add(cell1);
- tr.Cells.Add(cell2);
- tr.Cells.Add(cell3);
- TblRead.Rows.Add(tr);
- }
- //創建未讀人員信息列表
- cmd = new SqlCommand("select r.id, e.emp_name, e.department_id from OA_REPORT_RECEIVER r " +
- "inner join OA_EMPLOYEE e on r.receiver=e.id where is_read=0 and report_id=" + report_id, conn);
- dr = cmd.ExecuteReader();
- emp_names.Clear();
- department_id.Clear();
- while (dr.Read())
- {
- emp_names.Add(dr["emp_name"].ToString());
- department_id.Add(dr["department_id"].ToString());
- }
- dr.Close();
- if (emp_names.Count > 0)
- {
- //添加表頭
- TableRow tr = new TableRow();
- TableCell cell1 = new TableCell();
- cell1.Text = "員工姓名";
- TableCell cell2 = new TableCell();
- cell2.Text = "所屬部門";
- tr.Cells.Add(cell1);
- tr.Cells.Add(cell2);
- TblUnRead.Rows.Add(tr);
- }
- for (int i = 0; i < department_id.Count; i++)
- {
- DepartmentDAO departmentDAO = new DepartmentDAO();
- string department = (departmentDAO.queryById(Convert.ToInt32(department_id[i]))).Full_name;
- TableRow tr = new TableRow();
- TableCell cell1 = new TableCell();
- cell1.Text = emp_names[i].ToString();
- TableCell cell2 = new TableCell();
- cell2.Text = department;
- tr.Cells.Add(cell1);
- tr.Cells.Add(cell2);
- TblUnRead.Rows.Add(tr);
- }
- dr.Close();
- //簽批
- cmd = new SqlCommand("select e.emp_name, r.sign_date, r.sign from OA_REPORT_RECEIVER r inner " +
- "join OA_EMPLOYEE e on r.receiver=e.id where report_id="+report_id+"and sign<>''", conn);
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- TableRow tr1 = new TableRow();
- TableCell td1 = new TableCell();
- td1.Text = "簽批人";
- td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
- TableCell td2 = new TableCell();
- td2.Text = dr["emp_name"].ToString();
- td2.HorizontalAlign = HorizontalAlign.Left;
- tr1.Cells.Add(td1);
- tr1.Cells.Add(td2);
- TblSign.Rows.Add(tr1);
- TableRow tr2 = new TableRow();
- td1 = new TableCell();
- td1.Text = "簽批時間";
- td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
- td2 = new TableCell();
- td2.Text = dr["sign_date"].ToString();
- td2.HorizontalAlign = HorizontalAlign.Left;
- tr2.Cells.Add(td1);
- tr2.Cells.Add(td2);
- TblSign.Rows.Add(tr2);
- TableRow tr3 = new TableRow();
- td1 = new TableCell();
- td1.Text = "簽批內容";
- td1.Width = System.Web.UI.WebControls.Unit.Pixel(151);
- td2 = new TableCell();
- td2.Text = dr["sign"].ToString();
- td2.HorizontalAlign = HorizontalAlign.Left;
- tr3.Cells.Add(td1);
- tr3.Cells.Add(td2);
- TblSign.Rows.Add(tr3);
- TblSign.Rows.Add(new TableRow());
- }
- dr.Close();
- conn.Close();
- }
- catch (Exception ex)
- {
- Response.Write(ex.ToString());
- }
- }
- 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 Page_Init(object sender, EventArgs e)
- {
- if (Session["user"] != null)
- {
- int user_id = ((User)Session["user"]).Id;
- SqlDataSource1.SelectCommand = SqlDataSource1.SelectCommand + " and sender="+user_id;
- }
- }
- 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_send.aspx?s_id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString() + "'");
- }
- }
- 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();
- Label label = (Label)e.Row.FindControl("LblStatistics");
- string report_id = "0";
- SqlCommand cmd = new SqlCommand("SELECT report_id FROM dbo.OA_REPORT_SENDER where id=" + ReportList.DataKeys[e.Row.RowIndex].Value.ToString(), conn);
- SqlDataReader dr = cmd.ExecuteReader();
- if (dr.Read())
- {
- report_id = dr["report_id"].ToString();
- }
- dr.Close();
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
- " and is_read=1", conn);
- label.Text = Convert.ToInt32(cmd.ExecuteScalar()) + "人已讀;";
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
- " and is_read=0", conn);
- label.Text = label.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人未讀;";
- cmd = new SqlCommand("select count(id) from OA_REPORT_RECEIVER where report_id=" + report_id +
- " and sign<>''", conn);
- label.Text = label.Text + Convert.ToInt32(cmd.ExecuteScalar()) + "人已簽批";
- conn.Close();
- }
- }
- 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_SENDER set is_del=1 where id=" + id, conn);
- cmd.ExecuteNonQuery();
- conn.Close();
- ReportList.DataBind();
- PnlReport.Visible = false;
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- }
- protected void BtnAttachment_Click(object sender, EventArgs e)
- {
- this.DownLoadFile(BtnAttachment.Text);
- }
- }