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

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.     protected void Page_Load(object sender, EventArgs e)
  22.     {
  23.     }
  24.     protected void Button1_Click(object sender, EventArgs e)
  25.     {
  26.         if (!TxtBeginTime.Text.ToString().Equals("") &&!TxtEndTime.Text.ToString().Equals(""))
  27.         {
  28.             SqlConnection con = dbConnection.getConnection();
  29.             con.Open();
  30.             SqlCommand cmd = new SqlCommand();
  31.             if (DrpDownType.SelectedValue.ToString().Equals("1"))
  32.             
  33.             {
  34.                 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" +
  35.                     " 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" +
  36.                     " vacation_begin>='" + TxtBeginTime.Text + "' and  vacation_begin<='" + TxtEndTime.Text + "' and off_type<>1 order by name,emp_name";
  37.                 cmd.Connection = con;
  38.                 SqlDataReader dr = cmd.ExecuteReader();
  39.                 while (dr.Read())
  40.                 {
  41.                     ArrayList array_2 = new ArrayList();
  42.                     Table1.Visible = true;
  43.                     TableRow tr = new TableRow();
  44.                     TableCell td = new TableCell();
  45.                     td.BorderWidth = Unit.Pixel(1);
  46.                     td.Text = dr["form_id"].ToString();
  47.                     array_2.Add(Convert.ToString(dr["form_id"]));
  48.                     tr.Cells.Add(td);
  49.                      td = new TableCell();
  50.                      td.BorderWidth = Unit.Pixel(1);
  51.                     td.Text = dr["name"].ToString();
  52.                     array_2.Add(Convert.ToString(dr["name"]));
  53.                     tr.Cells.Add(td);
  54.                      td = new TableCell();
  55.                      td.BorderWidth = Unit.Pixel(1);
  56.                     td.Text = dr["emp_name"].ToString();
  57.                     tr.Cells.Add(td);
  58.                      td = new TableCell();
  59.                      td.BorderWidth = Unit.Pixel(1);
  60.                     td.Text = dr["vacation_begin"].ToString();
  61.                     tr.Cells.Add(td);
  62.                      td = new TableCell();
  63.                      td.BorderWidth = Unit.Pixel(1);
  64.                     td.Text = dr["vacation_end"].ToString();
  65.                     tr.Cells.Add(td);
  66.                      td = new TableCell();
  67.                      td.BorderWidth = Unit.Pixel(1);
  68.                     td.Text = dr["days"].ToString()+"天";
  69.                     tr.Cells.Add(td);
  70.                     Table1.Rows.Add(tr);
  71.                     array_1.Add(array_2);
  72.                 }
  73.                 dr.Close();
  74.             }
  75.             else if (DrpDownType.SelectedValue.ToString().Equals("4"))
  76.             {
  77.                 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" +
  78.                         " 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" +
  79.                         " vacation_begin>='" + TxtBeginTime.Text + "' and  vacation_begin<='" + TxtEndTime.Text + "' and off_type=1 order by name,emp_name";
  80.                 cmd.Connection = con;
  81.                 SqlDataReader dr = cmd.ExecuteReader();
  82.                 while (dr.Read())
  83.                 {
  84.                     Table1.Visible = true;
  85.                     TableRow tr = new TableRow();
  86.                     TableCell td = new TableCell();
  87.                     td.BorderWidth = Unit.Pixel(1);
  88.                     td.Text = dr["form_id"].ToString();
  89.                     tr.Cells.Add(td);
  90.                     td = new TableCell();
  91.                     td.BorderWidth = Unit.Pixel(1);
  92.                     td.Text = dr["name"].ToString();
  93.                     tr.Cells.Add(td);
  94.                     td = new TableCell();
  95.                     td.BorderWidth = Unit.Pixel(1);
  96.                     td.Text = dr["emp_name"].ToString();
  97.                     tr.Cells.Add(td);
  98.                     td = new TableCell();
  99.                     td.BorderWidth = Unit.Pixel(1);
  100.                     td.Text = dr["business_begin"].ToString();
  101.                     tr.Cells.Add(td);
  102.                     td = new TableCell();
  103.                     td.BorderWidth = Unit.Pixel(1);
  104.                     td.Text = dr["business_end"].ToString();
  105.                     tr.Cells.Add(td);
  106.                     td = new TableCell();
  107.                     td.BorderWidth = Unit.Pixel(1);
  108.                     td.Text = dr["days"].ToString() + "天";
  109.                     tr.Cells.Add(td);
  110.                     Table1.Rows.Add(tr);
  111.                 }
  112.                 dr.Close();
  113.             }
  114.             else
  115.             {
  116.                 if (DrpDownType.SelectedValue.ToString().Equals("2"))
  117.                 {
  118.                     cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.days from oa_ch_business_form " +
  119.                         " 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" +
  120.                         " begin_time>='" + TxtBeginTime.Text + "' and  begin_time<='" + TxtEndTime.Text + "' order by name,emp_name";
  121.                 }
  122.                 else if (DrpDownType.SelectedValue.ToString().Equals("3"))
  123.                 {
  124.                     cmd.CommandText = "select f.form_id,e.emp_name,d.name,f.begin_time,f.end_time,f.hours from oa_ch_off_form " +
  125.                         " 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" +
  126.                         " begin_time>='" + TxtBeginTime.Text + "' and  begin_time<='" + TxtEndTime.Text + "' order by name,emp_name";
  127.                 }
  128.                 cmd.Connection = con;
  129.                 SqlDataReader dr = cmd.ExecuteReader();
  130.                 while (dr.Read())
  131.                 {
  132.                     Table1.Visible = true;
  133.                     TableRow tr = new TableRow();
  134.                     TableCell td = new TableCell();
  135.                     td.BorderWidth = Unit.Pixel(1);
  136.                     td.Text = dr["form_id"].ToString();
  137.                     tr.Cells.Add(td);
  138.                     td = new TableCell();
  139.                     td.BorderWidth = Unit.Pixel(1);
  140.                     td.Text = dr["name"].ToString();
  141.                     tr.Cells.Add(td);
  142.                     td = new TableCell();
  143.                     td.BorderWidth = Unit.Pixel(1);
  144.                     td.Text = dr["emp_name"].ToString();
  145.                     tr.Cells.Add(td);
  146.                     td = new TableCell();
  147.                     td.BorderWidth = Unit.Pixel(1);
  148.                     td.Text = dr["begin_time"].ToString();
  149.                     tr.Cells.Add(td);
  150.                     td = new TableCell();
  151.                     td.BorderWidth = Unit.Pixel(1);
  152.                     td.Text = dr["end_time"].ToString();
  153.                     tr.Cells.Add(td);
  154.                     if (DrpDownType.SelectedValue.ToString().Equals("2"))
  155.                     {
  156.                         td = new TableCell();
  157.                         td.BorderWidth = Unit.Pixel(1);
  158.                         td.Text = dr["days"].ToString() + "天";
  159.                     }
  160.                     else if (DrpDownType.SelectedValue.ToString().Equals("3"))
  161.                     {
  162.                         td = new TableCell();
  163.                         td.BorderWidth = Unit.Pixel(1);
  164.                         td.Text = dr["hours"].ToString() + "小時";
  165.                     }
  166.                     tr.Cells.Add(td);
  167.                     Table1.Rows.Add(tr);
  168.                 }
  169.                 dr.Close();
  170.             }
  171.             con.Close();
  172.            
  173.         }
  174.         else
  175.         {
  176.             Response.Write("<script>alert('日期不能為空!')</script>");
  177.         }
  178.     }
  179.     protected void Button2_Click(object sender, EventArgs e)
  180.     {
  181.         foreach (ArrayList i in array_1)
  182.         {
  183.             foreach (string j in i)
  184.             {
  185.                 Response.Write(j);
  186.             }
  187.         }
  188.         ExcelApplication exc = new ExcelApplication();
  189.         Workbooks workbooks = exc.Workbooks;
  190.         _Workbook workbook = workbooks.Add(true);
  191.         Sheets shs = workbook.Sheets;
  192.         _Worksheet sh = (_Worksheet)shs.get_Item(1);
  193.         Range rang = sh.get_Range(sh.Cells[1, 1], sh.Cells[1, 11]);
  194.         rang.Merge(true);
  195.         rang.Value2 = "差假統計表";
  196.         rang.HorizontalAlignment = XlHAlign.xlHAlignCenter;
  197.        
  198.         for (int i = 0; i < Table1.Rows.Count; i++)
  199.         {
  200.             for (int j = 0; j < Table1.Rows[i].Cells.Count; j++)
  201.             {
  202.                 Range rang1 = sh.get_Range(sh.Cells[i+1, j+2], sh.Cells[i+1, j+2]);
  203.                 rang1.Value2 = Table1.Rows[i].Cells[j].Text;
  204.                 
  205.             }
  206.         }
  207.       /*  int n=3;
  208.         int m=1;
  209.         foreach(ArrayList i in array_1)
  210.         {
  211.             foreach (string j in i)
  212.             {
  213.                 Response.Write(j);
  214.                 Range rang1 = sh.get_Range(sh.Cells[n,m],sh.Cells[n,m]);
  215.                 rang1.Value2 = j;
  216.                 m++;
  217.             }
  218.             n++;
  219.         }*/
  220.         exc.Visible = true;
  221.         exc.UserControl = true;
  222.     }
  223. }