report_approvel.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:28k
源码类别:
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;
- using Microsoft.Office.Interop.Excel;
- using Microsoft.Office.Interop;
- using System.Reflection;
- using System.IO;
- using System.Runtime.InteropServices;
- using ExcelApplication = Microsoft.Office.Interop.Excel.Application;
- using Label = System.Web.UI.WebControls.Label;
- public partial class web_123_report_approvel : System.Web.UI.Page
- {
- ArrayList array_1 = new ArrayList();
- ArrayList array_2 = new ArrayList();
- //string str_path = "..\..\oa_upload\temp\";
- string str_path = "~/upload/";
- string str_name = "hello.xls";
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- LoginDAO.CheckLogin(Session, Response, "../../", 2);
- if (Table1.Visible = false)
- {
- Button2.Enabled = false;
- }
- else if(Table1.Visible=true)
- {
- Button2.Enabled = true;
- }
- }
- }
- public void getnum()
- {
- if (!TxtBeginTime.Text.ToString().Equals("") && !TxtEndTime.Text.ToString().Equals(""))
- {
- array_1 = new ArrayList();
- SqlConnection con = dbConnection.getConnection();
- con.Open();
- SqlCommand cmd = new SqlCommand();
- if (DropDf_type.SelectedValue.ToString().Equals("1"))
- {
- if (DrpDownType.SelectedValue.ToString().Equals("1"))
- {
- cmd.CommandText = "select f.id as f_id,f.form_id ,e.emp_name,d.name,f.vacation_begin,f.vacation_end,f.days,f.off_type from oa_tw_approvel_form" +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id " +
- " where vacation_begin>='" + TxtBeginTime.Text + "' and vacation_begin<='" + TxtEndTime.Text + "' and off_type<>1 and total_result='同意' order by name,emp_name";
- cmd.Connection = con;
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["form_id"].ToString();
- array_2.Add("'"+Convert.ToString(dr["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["name"].ToString();
- array_2.Add(Convert.ToString(dr["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["vacation_begin"].ToString();
- array_2.Add("'"+Convert.ToString(dr["vacation_begin"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["vacation_end"].ToString();
- array_2.Add("'"+Convert.ToString(dr["vacation_end"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/tw/my_list.aspx?a_id=" + dr["f_id"].ToString()+"&k=1";
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- }
- dr.Close();
- }
- else if (DrpDownType.SelectedValue.ToString().Equals("4"))
- {
- array_1 = new ArrayList();
- cmd.CommandText = "select f.id,f.form_id,e.emp_name,d.name,f.business_begin,f.business_end,f.days,f.off_type from oa_tw_approvel_form" +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id where" +
- " vacation_begin>='" + TxtBeginTime.Text + "' and vacation_begin<='" + TxtEndTime.Text + "' and off_type=1 and total_result='同意' order by name,emp_name";
- cmd.Connection = con;
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["form_id"].ToString();
- array_2.Add("'"+Convert.ToString(dr["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["name"].ToString();
- array_2.Add(Convert.ToString(dr["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["'" + "business_begin"].ToString();
- array_2.Add(Convert.ToString(dr["business_begin"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["'" + "business_end"].ToString();
- array_2.Add(Convert.ToString(dr["business_end"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/tw/my_list.aspx?a_id=" + dr["f_id"].ToString()+"&k=1";
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- }
- dr.Close();
- }
- else
- {
- array_1 = new ArrayList();
- if (DrpDownType.SelectedValue.ToString().Equals("2"))
- {
- cmd.CommandText = "select f.id,f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.days from oa_ch_business_form " +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id where" +
- " begin_time>='" + TxtBeginTime.Text + "' and begin_time<='" + TxtEndTime.Text + "' and total_result='同意' order by name,emp_name";
- }
- else if (DrpDownType.SelectedValue.ToString().Equals("3"))
- {
- cmd.CommandText = "select f.id,f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.hours from oa_ch_off_form " +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id where" +
- " begin_time>='" + TxtBeginTime.Text + "' and begin_time<='" + TxtEndTime.Text + "' and total_result='同意' order by name,emp_name";
- }
- cmd.Connection = con;
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["form_id"].ToString();
- array_2.Add("'" + Convert.ToString(dr["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["name"].ToString();
- array_2.Add(Convert.ToString(dr["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["begin_time"].ToString();
- array_2.Add("'" + Convert.ToString(dr["begin_time"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["end_time"].ToString();
- array_2.Add("'" + Convert.ToString(dr["end_time"]));
- tr.Cells.Add(td);
- if (DrpDownType.SelectedValue.ToString().Equals("2"))
- {
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- }
- else if (DrpDownType.SelectedValue.ToString().Equals("3"))
- {
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["hours"].ToString() + "小時";
- array_2.Add(Convert.ToString(td.Text));
- }
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/ch/my_list_d.aspx?a_id=" + dr["id"].ToString();
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- }
- dr.Close();
- }
- con.Close();
- }
- else
- {
- int flag = 0;
- cmd.CommandText = "select f.id as f_id,f.form_id ,e.emp_name,d.name,f.vacation_begin,f.vacation_end,f.days,f.off_type from oa_tw_approvel_form" +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id " +
- " where vacation_begin>='" + TxtBeginTime.Text + "' and vacation_begin<='" + TxtEndTime.Text + "' and off_type<>1 and emp_no='"+TxtEmp_no.Text+
- "' and total_result='同意' order by name,emp_name";
- cmd.Connection = con;
- SqlDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["form_id"].ToString();
- array_2.Add("'" + Convert.ToString(dr["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["name"].ToString();
- array_2.Add(Convert.ToString(dr["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["vacation_begin"].ToString();
- array_2.Add("'" + Convert.ToString(dr["vacation_begin"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["vacation_end"].ToString();
- array_2.Add("'" + Convert.ToString(dr["vacation_end"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/tw/my_list.aspx?a_id=" + dr["f_id"].ToString()+"&k=1";
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- flag = 1;
- }
- dr.Close();
- if (flag == 0)
- {
- array_1 = new ArrayList();
- cmd.CommandText = "select f.id,f.form_id,e.emp_name,d.name,f.business_begin,f.business_end,f.days,f.off_type from oa_tw_approvel_form" +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id where" +
- " vacation_begin>='" + TxtBeginTime.Text + "' and vacation_begin<='" + TxtEndTime.Text + "' and off_type=1 and total_result='同意'and emp_no='"+TxtEmp_no.Text+
- "' order by name,emp_name";
- cmd.Connection = con;
- SqlDataReader dr1 = cmd.ExecuteReader();
- while (dr1.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr1["form_id"].ToString();
- array_2.Add("'" + Convert.ToString(dr1["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr1["name"].ToString();
- array_2.Add(Convert.ToString(dr1["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr1["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr1["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr1["business_begin"].ToString();
- array_2.Add("'" + Convert.ToString(dr1["business_begin"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr1["business_end"].ToString();
- array_2.Add("'" + Convert.ToString(dr1["business_end"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/tw/my_list.aspx?a_id=" + dr1["f_id"].ToString()+"&k=1";
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- }
- dr1.Close();
- cmd.CommandText = "select f.id,f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.days from oa_ch_business_form " +
- " as f inner join oa_employee as e on f.emp_id=e.id inner join oa_department as d on e.department_id=d.id where" +
- " begin_time>='" + TxtBeginTime.Text + "' and begin_time<='" + TxtEndTime.Text + "'and emp_no='" + TxtEmp_no.Text + "'and total_result='同意' order by name,emp_name";
- cmd.Connection = con;
- SqlDataReader dr2 = cmd.ExecuteReader();
- while (dr2.Read())
- {
- array_2 = new ArrayList();
- Table1.Visible = true;
- TableRow tr = new TableRow();
- TableCell td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["form_id"].ToString();
- array_2.Add("'" + Convert.ToString(dr2["form_id"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["name"].ToString();
- array_2.Add(Convert.ToString(dr2["name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["emp_name"].ToString();
- array_2.Add(Convert.ToString(dr2["emp_name"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["begin_time"].ToString();
- array_2.Add("'" + Convert.ToString(dr2["begin_time"]));
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["end_time"].ToString();
- array_2.Add("'" + Convert.ToString(dr2["end_time"]));
- tr.Cells.Add(td);
- if (DrpDownType.SelectedValue.ToString().Equals("2"))
- {
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["days"].ToString() + "天";
- array_2.Add(Convert.ToString(td.Text));
- }
- else if (DrpDownType.SelectedValue.ToString().Equals("3"))
- {
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- td.Text = dr2["hours"].ToString() + "小時";
- array_2.Add(Convert.ToString(td.Text));
- }
- tr.Cells.Add(td);
- td = new TableCell();
- td.BorderWidth = Unit.Pixel(1);
- HyperLink hl = new HyperLink();
- hl.Text = "查看";
- hl.Target = "blank";
- hl.NavigateUrl = "../../approvel/ch/my_list_d.aspx?a_id=" + dr2["id"].ToString()+"&k=1";
- td.Controls.Add(hl);
- tr.Cells.Add(td);
- Table1.Rows.Add(tr);
- array_1.Add(array_2);
- } dr2.Close();
- }
- }
- con.Close();
- }
- else
- {
- Response.Write("<script>alert('日期不能為空!')</script>");
- }
- }
- public void getexcel()
- {
- ExcelApplication exc = new ExcelApplication();
- exc.Visible = false;
- exc.UserControl = false;
- Workbooks workbooks = exc.Workbooks;
- _Workbook workbook = workbooks.Add(true);
- Sheets shs = workbook.Sheets;
- _Worksheet sh = (_Worksheet)shs.get_Item(1);
- Range rang = sh.get_Range(sh.Cells[1, 1], sh.Cells[1, 6]);
- rang.Merge(true);
- rang.Value2 = "差假統計表";
- sh.Cells[2, 1] = "單號";
- sh.Cells[2, 2] = "部門";
- sh.Cells[2, 3] = "姓名";
- sh.Cells[2, 4] = "日期起";
- sh.Cells[2, 5] = "日期迄";
- sh.Cells[2, 6] = "總計";
- rang.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- int n=3;
- int m=1;
- foreach(ArrayList i in array_1)
- {
- m = 1;
- foreach (string j in i)
- {
- Range rang1 = sh.get_Range(sh.Cells[n,m],sh.Cells[n,m]);
- // rang1.Merge(true);
- rang1.Value2 = j;
- m++;
- }
- n++;
- }
- exc.Visible = true;
- exc.UserControl = true;
- exc.Columns.AutoFit();
- exc.Columns.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- string strFilePhysicalPath = Server.MapPath(str_path) + str_name;
- if (File.Exists(strFilePhysicalPath))
- {
- File.Delete(strFilePhysicalPath);
- }
- sh.Name = "hello";
- exc.DisplayAlerts = false;
- exc.AlertBeforeOverwriting = false;
- //exc.Save(strFilePhysicalPath);
- sh.SaveAs(strFilePhysicalPath, Type.Missing, Type.Missing, Type.Missing,
- Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
- workbook.Save();
- ReleaseCom(sh);
- ReleaseCom(shs);
- ReleaseCom(workbook);
- ReleaseCom(workbooks);
- exc.Quit();
- ReleaseCom(exc);
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- getnum();
- }
- private void ReleaseCom(object pComObj)
- {
- try
- {
- if (pComObj != null)
- {
- System.Runtime.InteropServices.Marshal.ReleaseComObject(pComObj);
- }
- }
- catch
- {
- }
- finally
- {
- pComObj = null;
- }
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- int flag = 0;
- getnum();
- getexcel();
- flag = download(str_name ,str_path);
- }
- protected void DropDf_type_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (DropDf_type.SelectedValue.ToString().Equals("1"))
- {
- Label6.Enabled = false;
- TxtEmp_no.Enabled = false;
- DrpDownType.Enabled = true;
- Label2.Enabled = true;
- }
- else
- {
- Label6.Enabled = true;
- TxtEmp_no.Enabled = true;
- DrpDownType.Enabled = false;
- Label2.Enabled = false;
- }
- }
- public int download(string str_name,string str_path)
- {
- try
- {
- string FullFileName = Server.MapPath(str_path) + str_name;
- FileInfo DownloadFile = new FileInfo(FullFileName);
- Response.Clear();
- Response.ClearHeaders();
- Response.Buffer = false;
- Response.ContentType = "application/octet-stream";
- Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
- Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
- Response.WriteFile(DownloadFile.FullName);
- Response.Flush();
- Response.End();
- return 1;
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- return 0;
- }
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar1.Visible == true)
- {
- Calendar1.Visible = false;
- }
- else
- {
- Calendar1.Visible = true;
- }
- }
- protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar2.Visible == true)
- {
- Calendar2.Visible = false;
- }
- else
- {
- Calendar2.Visible = true;
- }
- }
- protected void Calendar1_SelectionChanged(object sender, EventArgs e)
- {
- string year = Calendar1.SelectedDate.Year.ToString();
- string month = Calendar1.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = Calendar1.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- TxtBeginTime.Text = year + "-" + month + "-" + day;
- Calendar1.Visible = false;
- }
- protected void Calendar2_SelectionChanged(object sender, EventArgs e)
- {
- string year = Calendar2.SelectedDate.Year.ToString();
- string month = Calendar2.SelectedDate.Month.ToString();
- if (month.Length == 1)
- {
- month = "0" + month;
- }
- string day = Calendar2.SelectedDate.Day.ToString();
- if (day.Length == 1)
- {
- day = "0" + day;
- }
- TxtEndTime.Text = year + "-" + month + "-" + day;
- Calendar2.Visible = false;
- }
- public void is_ok()
- {
- if (Table1.Visible = false)
- {
- Button2.Enabled = false;
- }
- else { Button2.Enabled = true; }
- }
- }