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

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. using Microsoft.Office.Interop.Excel;
  13. using Microsoft.Office.Interop;
  14. using System.Reflection;
  15. using System.Runtime.InteropServices;
  16. using ExcelApplication = Microsoft.Office.Interop.Excel.Application;
  17. using Label = System.Web.UI.WebControls.Label;
  18. public partial class web_123_report_approvel : System.Web.UI.Page
  19. {
  20.     ArrayList array_1 = new ArrayList();
  21.     ArrayList array_2 = new ArrayList();
  22.     protected void Page_Load(object sender, EventArgs e)
  23.     {
  24.     }
  25.     public void getnum()
  26.     {
  27.         if (!TxtBeginTime.Text.ToString().Equals("") && !TxtEndTime.Text.ToString().Equals(""))
  28.         {
  29.             array_1 = new ArrayList();
  30.             SqlConnection con = dbConnection.getConnection();
  31.             con.Open();
  32.             SqlCommand cmd = new SqlCommand();
  33.             if (DrpDownType.SelectedValue.ToString().Equals("1"))
  34.             {
  35.                 cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.vacation_begin,f.vacation_end,f.days,f.off_type from oa_tw_approvel_form" +
  36.                     " 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" +
  37.                     " vacation_begin>='" + TxtBeginTime.Text + "' and  vacation_begin<='" + TxtEndTime.Text + "' and off_type<>1 order by name,emp_name";
  38.                 cmd.Connection = con;
  39.                 SqlDataReader dr = cmd.ExecuteReader();
  40.                 while (dr.Read())
  41.                 {
  42.                     array_2 = new ArrayList();
  43.                     Table1.Visible = true;
  44.                     TableRow tr = new TableRow();
  45.                     TableCell td = new TableCell();
  46.                     td.BorderWidth = Unit.Pixel(1);
  47.                     td.Text = dr["form_id"].ToString();
  48.                     array_2.Add(Convert.ToString(dr["form_id"]));
  49.                     tr.Cells.Add(td);
  50.                     td = new TableCell();
  51.                     td.BorderWidth = Unit.Pixel(1);
  52.                     td.Text = dr["name"].ToString();
  53.                     array_2.Add(Convert.ToString(dr["name"]));
  54.                     tr.Cells.Add(td);
  55.                     td = new TableCell();
  56.                     td.BorderWidth = Unit.Pixel(1);
  57.                     td.Text = dr["emp_name"].ToString();
  58.                     array_2.Add(Convert.ToString(dr["emp_name"]));
  59.                     tr.Cells.Add(td);
  60.                     td = new TableCell();
  61.                     td.BorderWidth = Unit.Pixel(1);
  62.                     td.Text = dr["vacation_begin"].ToString();
  63.                     array_2.Add(Convert.ToString(dr["vacation_begin"]));
  64.                     tr.Cells.Add(td);
  65.                     td = new TableCell();
  66.                     td.BorderWidth = Unit.Pixel(1);
  67.                     td.Text = dr["vacation_end"].ToString();
  68.                     array_2.Add(Convert.ToString(dr["vacation_end"]));
  69.                     tr.Cells.Add(td);
  70.                     td = new TableCell();
  71.                     td.BorderWidth = Unit.Pixel(1);
  72.                     td.Text = dr["days"].ToString() + "天";
  73.                     array_2.Add(Convert.ToString(td.Text));
  74.                     tr.Cells.Add(td);
  75.                     Table1.Rows.Add(tr);
  76.                     array_1.Add(array_2);
  77.                 }
  78.                 dr.Close();
  79.             }
  80.             else if (DrpDownType.SelectedValue.ToString().Equals("4"))
  81.             {
  82.                 array_1 = new ArrayList();
  83.                 cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.business_begin,f.business_end,f.days,f.off_type from oa_tw_approvel_form" +
  84.                         " 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" +
  85.                         " vacation_begin>='" + TxtBeginTime.Text + "' and  vacation_begin<='" + TxtEndTime.Text + "' and off_type=1 order by name,emp_name";
  86.                 cmd.Connection = con;
  87.                 SqlDataReader dr = cmd.ExecuteReader();
  88.                 while (dr.Read())
  89.                 {
  90.                     array_2 = new ArrayList();
  91.                     Table1.Visible = true;
  92.                     TableRow tr = new TableRow();
  93.                     TableCell td = new TableCell();
  94.                     td.BorderWidth = Unit.Pixel(1);
  95.                     td.Text = dr["form_id"].ToString();
  96.                     array_2.Add(Convert.ToString(dr["form_id"]));
  97.                     tr.Cells.Add(td);
  98.                     td = new TableCell();
  99.                     td.BorderWidth = Unit.Pixel(1);
  100.                     td.Text = dr["name"].ToString();
  101.                     array_2.Add(Convert.ToString(dr["name"]));
  102.                     tr.Cells.Add(td);
  103.                     td = new TableCell();
  104.                     td.BorderWidth = Unit.Pixel(1);
  105.                     td.Text = dr["emp_name"].ToString();
  106.                     array_2.Add(Convert.ToString(dr["emp_name"]));
  107.                     tr.Cells.Add(td);
  108.                     td = new TableCell();
  109.                     td.BorderWidth = Unit.Pixel(1);
  110.                     td.Text = dr["business_begin"].ToString();
  111.                     array_2.Add(Convert.ToString(dr["business_begin"]));
  112.                     tr.Cells.Add(td);
  113.                     td = new TableCell();
  114.                     td.BorderWidth = Unit.Pixel(1);
  115.                     td.Text = dr["business_end"].ToString();
  116.                     array_2.Add(Convert.ToString(dr["business_end"]));
  117.                     tr.Cells.Add(td);
  118.                     td = new TableCell();
  119.                     td.BorderWidth = Unit.Pixel(1);
  120.                     td.Text = dr["days"].ToString() + "天";
  121.                     array_2.Add(Convert.ToString(td.Text));
  122.                     tr.Cells.Add(td);
  123.                     Table1.Rows.Add(tr);
  124.                     array_1.Add(array_2);
  125.                 }
  126.                 dr.Close();
  127.             }
  128.             else
  129.             {
  130.                 array_1 = new ArrayList();
  131.                 if (DrpDownType.SelectedValue.ToString().Equals("2"))
  132.                 {
  133.                     cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.days from oa_ch_business_form " +
  134.                         " 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" +
  135.                         " begin_time>='" + TxtBeginTime.Text + "' and  begin_time<='" + TxtEndTime.Text + "' order by name,emp_name";
  136.                 }
  137.                 else if (DrpDownType.SelectedValue.ToString().Equals("3"))
  138.                 {
  139.                     cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.hours from oa_ch_off_form " +
  140.                         " 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" +
  141.                         " begin_time>='" + TxtBeginTime.Text + "' and  begin_time<='" + TxtEndTime.Text + "' order by name,emp_name";
  142.                 }
  143.                 cmd.Connection = con;
  144.                 SqlDataReader dr = cmd.ExecuteReader();
  145.                 while (dr.Read())
  146.                 {
  147.                     array_2 = new ArrayList();
  148.                     Table1.Visible = true;
  149.                     TableRow tr = new TableRow();
  150.                     TableCell td = new TableCell();
  151.                     td.BorderWidth = Unit.Pixel(1);
  152.                     td.Text = dr["form_id"].ToString();
  153.                     array_2.Add(Convert.ToString(dr["form_id"]));
  154.                     tr.Cells.Add(td);
  155.                     td = new TableCell();
  156.                     td.BorderWidth = Unit.Pixel(1);
  157.                     td.Text = dr["name"].ToString();
  158.                     array_2.Add(Convert.ToString(dr["name"]));
  159.                     tr.Cells.Add(td);
  160.                     td = new TableCell();
  161.                     td.BorderWidth = Unit.Pixel(1);
  162.                     td.Text = dr["emp_name"].ToString();
  163.                     array_2.Add(Convert.ToString(dr["emp_name"]));
  164.                     tr.Cells.Add(td);
  165.                     td = new TableCell();
  166.                     td.BorderWidth = Unit.Pixel(1);
  167.                     td.Text = dr["begin_time"].ToString();
  168.                     array_2.Add(Convert.ToString(dr["begin_time"]));
  169.                     tr.Cells.Add(td);
  170.                     td = new TableCell();
  171.                     td.BorderWidth = Unit.Pixel(1);
  172.                     td.Text = dr["end_time"].ToString();
  173.                     array_2.Add(Convert.ToString(dr["end_time"]));
  174.                     tr.Cells.Add(td);
  175.                     if (DrpDownType.SelectedValue.ToString().Equals("2"))
  176.                     {
  177.                         td = new TableCell();
  178.                         td.BorderWidth = Unit.Pixel(1);
  179.                         td.Text = dr["days"].ToString() + "天";
  180.                         array_2.Add(Convert.ToString(td.Text));
  181.                     }
  182.                     else if (DrpDownType.SelectedValue.ToString().Equals("3"))
  183.                     {
  184.                         td = new TableCell();
  185.                         td.BorderWidth = Unit.Pixel(1);
  186.                         td.Text = dr["hours"].ToString() + "小時";
  187.                         array_2.Add(Convert.ToString(td.Text));
  188.                     }
  189.                     tr.Cells.Add(td);
  190.                     Table1.Rows.Add(tr);
  191.                     array_1.Add(array_2);
  192.                 }
  193.                 dr.Close();
  194.             }
  195.             con.Close();
  196.         }
  197.         else
  198.         {
  199.             Response.Write("<script>alert('日期不能為空!')</script>");
  200.         }
  201.     }
  202.     public void getexcel()
  203.     {
  204.         ExcelApplication exc = new ExcelApplication();
  205.          exc.Visible = false;
  206.         exc.UserControl = false;
  207.         Workbooks workbooks = exc.Workbooks;
  208.         _Workbook workbook = workbooks.Add(true);
  209.         Sheets shs = workbook.Sheets;
  210.         _Worksheet sh = (_Worksheet)shs.get_Item(1);
  211.         Range rang = sh.get_Range(sh.Cells[1, 1], sh.Cells[1, 11]);
  212.         rang.Merge(true);
  213.         rang.Value2 = "差假統計表";
  214.         sh.Cells[2, 1] = "單號";
  215.         sh.Cells[2, 2] = "部門";
  216.         sh.Cells[2, 3] = "姓名";
  217.         sh.Cells[2, 4] = "日期起";
  218.         sh.Cells[2, 5] = "日期迄";
  219.         sh.Cells[2, 6] = "總計";
  220.         rang.HorizontalAlignment = XlHAlign.xlHAlignCenter;
  221.         int n=3;
  222.         int m=1;
  223.         foreach(ArrayList i in array_1)
  224.         {
  225.             m = 1;
  226.             foreach (string j in i)
  227.             {
  228.                 Range rang1 = sh.get_Range(sh.Cells[n,m],sh.Cells[n,m]);
  229.                 rang1.Value2 = j;
  230.                 m++;
  231.             }
  232.             n++;
  233.         }
  234.         exc.Visible = true;
  235.         exc.UserControl = true;
  236.         ReleaseCom(sh);
  237.         ReleaseCom(shs);
  238.         ReleaseCom(workbook);
  239.         ReleaseCom(workbooks);
  240.         ReleaseCom(exc);
  241.     }
  242.     protected void Button1_Click(object sender, EventArgs e)
  243.     {
  244.         getnum();
  245.     }
  246.     private void ReleaseCom(object pComObj)
  247.     {
  248.         try
  249.         {
  250.             if (pComObj != null)
  251.             {
  252.                 System.Runtime.InteropServices.Marshal.ReleaseComObject(pComObj);
  253.             }
  254.         }
  255.         catch
  256.         {
  257.         }
  258.         finally
  259.         {
  260.             pComObj = null;
  261.         }
  262.     }
  263.     protected void Button2_Click(object sender, EventArgs e)
  264.     {
  265.         getnum();
  266.         getexcel();
  267.     }
  268. }