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

OA系统

开发平台:

ASP/ASPX

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Configuration;
  5. using System.Collections;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Web.UI.HtmlControls;
  12. using Microsoft.Reporting.WebForms;
  13. using System.Reflection;
  14. using System.Runtime.InteropServices;
  15. using DataTable = System.Data.DataTable;
  16. public partial class web_show : System.Web.UI.Page
  17. {
  18.     int no = 0;
  19.     ArrayList array1 = new ArrayList();
  20.     ArrayList array2 = new ArrayList();
  21.     ArrayList array3 = new ArrayList();
  22.     ArrayList array_1 = new ArrayList();
  23.     DataTable dt = new DataTable("dataname");
  24.     protected void Page_Load(object sender, EventArgs e)
  25.     {
  26.         dt.Columns.Add(new DataColumn("所屬部門", typeof(string)));
  27.         dt.Columns.Add(new DataColumn("姓名", typeof(string)));
  28.         dt.Columns.Add(new DataColumn("員工編號", typeof(string)));
  29.         dt.Columns.Add(new DataColumn("日期", typeof(string)));
  30.         dt.Columns.Add(new DataColumn("星期", typeof(string)));
  31.         dt.Columns.Add(new DataColumn("早上上班", typeof(string)));
  32.         dt.Columns.Add(new DataColumn("中午下班", typeof(string)));
  33.         dt.Columns.Add(new DataColumn("下午上班", typeof(string)));
  34.         dt.Columns.Add(new DataColumn("下午下班", typeof(string)));
  35.         dt.Columns.Add(new DataColumn("簽到時數", typeof(string)));
  36.         ReportViewer1.Visible = false;
  37.         DropDownList1.Visible = true;
  38.     }
  39.     public void getid()
  40.     {
  41.         int flag = 0;
  42.         int emp_where = 0;
  43.         string str = "";
  44.         string user_id = "";
  45.         DropDownList1.Items.Clear();
  46.         DropDownList1.Items.Add("所有部門");
  47.         if (Session["user_id"] != null)
  48.         {
  49.             user_id = Session["user_id"].ToString();
  50.         }
  51.         ReportViewer1.Visible = false;
  52.         SqlConnection conn = dbConnection.getConnection();
  53.         conn.Open();
  54.         SqlCommand sqlcom1 = new SqlCommand("select emp_where from OA_EMPLOYEE where id='" + user_id + "'", conn);
  55.         emp_where = Convert.ToInt32(sqlcom1.ExecuteScalar());
  56.         if (emp_where == 1)
  57.         {
  58.             str = "中山隆成啟航商貿有限公司";
  59.         }
  60.         else if (emp_where == 2)
  61.         {
  62.             str = "中山捷盟貿易有限公司";
  63.         }
  64.         else
  65.         {
  66.         }
  67.         SqlCommand comm1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + str + "'", conn);
  68.         no = Convert.ToInt32(comm1.ExecuteScalar());
  69.         SqlCommand sqlcom2 = new SqlCommand("select id,name from OA_DEPARTMENT where last_id='" + no + "'and out='0'", conn);
  70.         SqlDataReader comm2 = sqlcom2.ExecuteReader();
  71.         while (comm2.Read())
  72.         {
  73.             array1.Add(Convert.ToInt32(comm2["id"]));
  74.             for (int i = 0; i < DropDownList1.Items.Count; i++)
  75.             {
  76.                 if (Convert.ToString(comm2["name"]).Equals(DropDownList1.Items[i]))
  77.                 {
  78.                     flag = flag + 1;
  79.                 }
  80.             }
  81.             if (flag == 0)
  82.             {
  83.                 DropDownList1.Items.Add(Convert.ToString(comm2["name"]));
  84.             }
  85.         }
  86.         comm2.Close();
  87.         foreach (int i in array1)
  88.         {
  89.             ArrayList array5 = new ArrayList();
  90.             array5.Add(i);
  91.             SqlCommand sqlcom3 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + i + "'", conn);
  92.             SqlDataReader comm3 = sqlcom3.ExecuteReader();
  93.             if (comm3.HasRows)
  94.             {
  95.                 while (comm3.Read())
  96.                 {
  97.                     array5.Add(Convert.ToInt32(comm3["id"]));
  98.                     SqlConnection conn1 = dbConnection.getConnection();
  99.                     conn1.Open();
  100.                     SqlCommand sqlcom4 = new SqlCommand("select id ,name from OA_DEPARTMENT where last_id='" + Convert.ToInt32(comm3["id"]) + "'", conn1);
  101.                     SqlDataReader comm4 = sqlcom4.ExecuteReader();
  102.                     if (comm4.HasRows)
  103.                     {
  104.                         while (comm4.Read())
  105.                         {
  106.                             array5.Add(Convert.ToInt32(comm4["id"]));
  107.                         }
  108.                     }
  109.                     comm4.Close();
  110.                     conn1.Close();
  111.                 }
  112.             }
  113.             comm3.Close();
  114.             array2.Add(array5);
  115.         }
  116.         conn.Close();
  117.     }
  118.     public void getnum()
  119.     {
  120.         int k = 0;
  121.         string name = "";
  122.         string emp_name = "";
  123.         string nul = " ";
  124.         string department = "";
  125.         double sum = 0;
  126.         string time1 = "";
  127.         string time2 = "";
  128.         string time3 = "";
  129.         string time4 = "";
  130.         DataRow row = dt.NewRow();
  131.         SqlConnection conn1 = dbConnection.getConnection();
  132.         conn1.Open();
  133.         foreach (ArrayList i in array2)
  134.         {
  135.             ArrayList array6 = new ArrayList();
  136.             foreach (int j in i)
  137.             {
  138.                 SqlCommand sqlcom1 = new SqlCommand("select emp_no from OA_EMPLOYEE where department_id='" + j + "'and dimission_date=''", conn1);
  139.                 SqlDataReader comm1 = sqlcom1.ExecuteReader();
  140.                 if (comm1.HasRows)
  141.                 {
  142.                     while (comm1.Read())
  143.                     {
  144.                         array6.Add(Convert.ToString(comm1["emp_no"]));
  145.                     }
  146.                 }
  147.                 comm1.Close();
  148.             }
  149.             array3.Add(array6);
  150.         }
  151.         foreach (ArrayList i in array3)
  152.         {
  153.             if (k < array1.Count)
  154.             {
  155.                 foreach (string j in i)
  156.                 {
  157.                     SqlConnection conn2 = dbConnection.getConnection();
  158.                     conn2.Open();
  159.                     SqlCommand sqlcom2 = new SqlCommand("select name from OA_DEPARTMENT where id='" + array1[k] + "'", conn2);
  160.                     name = Convert.ToString(sqlcom2.ExecuteScalar());
  161.                     SqlCommand sqlcom4 = new SqlCommand("select f.name as name from OA_DEPARTMENT as f , OA_EMPLOYEE as g where f.id=g.department_id and g.emp_no='" + j + "'", conn2);
  162.                     department = Convert.ToString(sqlcom4.ExecuteScalar());
  163.                     SqlCommand sqlcom3 = new SqlCommand("select emp_name from OA_EMPLOYEE where emp_no='" + j + "'", conn2);
  164.                     emp_name = Convert.ToString(sqlcom3.ExecuteScalar());
  165.                     SqlCommand sqlcom5 = new SqlCommand("select distinct data from OA_KAOQIN_JL where data between'" + TextBox1.Text + "'and'" + TextBox2.Text + "'order by data", conn2);
  166.                     SqlDataReader comm5 = sqlcom5.ExecuteReader();
  167.                     while (comm5.Read())
  168.                     {
  169.                         row = dt.NewRow();
  170.                         row["所屬部門"] = name;
  171.                         row["姓名"] = emp_name;
  172.                         row["員工編號"] = j;
  173.                         row["日期"] = Convert.ToString(comm5["data"]);
  174.                         row["星期"] = getweekday(Convert.ToDateTime(comm5["data"]));
  175.                         SqlConnection conn5 = dbConnection.getConnection();
  176.                         conn5.Open();
  177.                         SqlCommand sqlcom8 = new SqlCommand("select f.zao as zao,f.wan as wan,f.wuxia as wuxia,f.wushang as wushang from OA_KAOQIN_JL as f,OA_EMPLOYEE as g where f.card_id=g.work_card_no1 and g.emp_no='" + j + "'and data='" + Convert.ToString(comm5["data"]) + "'", conn5);
  178.                         SqlDataReader comm8 = sqlcom8.ExecuteReader();
  179.                         if (comm8.HasRows)
  180.                         {
  181.                             while (comm8.Read())
  182.                             {
  183.                                 time1 = Convert.ToString(comm8["zao"]);
  184.                                 time2 = Convert.ToString(comm8["wan"]);
  185.                                 time3 = Convert.ToString(comm8["wuxia"]);
  186.                                 time4 = Convert.ToString(comm8["wushang"]);
  187.                                 if (time1.Equals(""))
  188.                                 {
  189.                                     row["早上上班"] = nul;
  190.                                 }
  191.                                 else
  192.                                 {
  193.                                     row["早上上班"] = time1;
  194.                                 }
  195.                                 if (time3.Equals(""))
  196.                                 {
  197.                                     row["中午下班"] = nul; 
  198.                                 }
  199.                                 else
  200.                                 {
  201.                                     row["中午下班"] = time3;
  202.                                 }
  203.                                 if (time4.Equals(""))
  204.                                 {
  205.                                     row["下午上班"] = nul;
  206.                                 }
  207.                                 else
  208.                                 {
  209.                                     row["下午上班"] = time4; 
  210.                                 }
  211.                                 if (time2.Equals(""))
  212.                                 {
  213.                                     row["下午下班"] = nul;
  214.                                 }
  215.                                 else
  216.                                 {
  217.                                     row["下午下班"] = time2; 
  218.                                 }
  219.                                 if (time1.Length == 5)
  220.                                 {
  221.                                     time1 = "0" + time1;
  222.                                 }
  223.                                 if (time2.Length == 5)
  224.                                 {
  225.                                     time2 = "0" + time2;
  226.                                 }
  227.                                 if (!(time1.Equals("")) && (!time2.Equals("")))
  228.                                 {
  229.                                     sum = (double)(Convert.ToInt32(time2.Substring(0, 2)) - Convert.ToInt32(time1.Substring(0, 2)) - 1.5 + (double)(Convert.ToInt32(time2.Substring(2, 2)) - Convert.ToInt32(time1.Substring(2, 2))) / 60);
  230.                                     sum = Round(sum, 2);
  231.                                     row["簽到時數"] = Convert.ToString(sum);
  232.                                 }
  233.                                 else
  234.                                 {
  235.                                     row["簽到時數"] = nul;
  236.                                 }
  237.                             }
  238.                         }
  239.                         else
  240.                         {
  241.                             row["早上上班"] = nul;
  242.                             row["中午下班"] = nul;
  243.                             row["下午上班"] = nul;
  244.                             row["下午下班"] = nul;
  245.                             row["簽到時數"] = nul;
  246.                         }
  247.                         comm8.Close();
  248.                         conn5.Close();
  249.                         dt.Rows.Add(row);
  250.                     }
  251.                     comm5.Close();
  252.                     conn2.Close();
  253.                 }
  254.                 k++;
  255.             }
  256.         }
  257.         conn1.Close();
  258.     }
  259.     public void getnum1()
  260.     {
  261.         int id = 0;
  262.         string name="";
  263.         string department = "";
  264.         string emp_name = "";
  265.         double sum = 0;
  266.         string time1 = "";
  267.         string time2 = "";
  268.         string time3 = "";
  269.         string time4 = "";
  270.         string nul = "";
  271.         int emp_where = 0;
  272.         string str = "";
  273.         string user_id = "";
  274.         int last_id = 0;
  275.         if (Session["user_id"] != null)
  276.         {
  277.             user_id = Session["user_id"].ToString();
  278.         }
  279.         DataRow row = dt.NewRow();
  280.         name = DropDownList1.Text;
  281.         SqlConnection conn1 = dbConnection.getConnection();
  282.         conn1.Open();
  283.         SqlCommand sqlcom8 = new SqlCommand("select emp_where from OA_EMPLOYEE where id='" + user_id + "'", conn1);
  284.         emp_where = Convert.ToInt32(sqlcom8.ExecuteScalar());
  285.         if (emp_where == 1)
  286.         {
  287.             str = "中山隆成啟航商貿有限公司";
  288.         }
  289.         else if (emp_where == 2)
  290.         {
  291.             str = "中山捷盟貿易有限公司";
  292.         }
  293.         else
  294.         {
  295.         }
  296.         SqlCommand comm1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + str + "'", conn1);
  297.         last_id = Convert.ToInt32(comm1.ExecuteScalar());
  298.         SqlCommand sqlcom1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + DropDownList1.Text + "'and last_id='" + last_id + "'and out='0'", conn1);
  299.         id = Convert.ToInt32(sqlcom1.ExecuteScalar());
  300.         array_1.Add(id);
  301.         SqlCommand sqlcom2 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + id + "'and out='0'", conn1);
  302.         SqlDataReader comm2 = sqlcom2.ExecuteReader();
  303.         if (comm2.HasRows)
  304.         {
  305.             while (comm2.Read())
  306.             {
  307.                 array_1.Add(Convert.ToInt32(comm2["id"]));
  308.                 SqlConnection conn2 = dbConnection.getConnection();
  309.                 conn2.Open();
  310.                 SqlCommand sqlcom3 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + Convert.ToInt32(comm2["id"]) + "'", conn2);
  311.                 SqlDataReader comm3 = sqlcom3.ExecuteReader();
  312.                 if (comm3.HasRows)
  313.                 {
  314.                     while (comm3.Read())
  315.                     {
  316.                         array_1.Add(Convert.ToInt32(comm3["id"]));
  317.                     }
  318.                 }
  319.                 comm3.Close();
  320.                 conn2.Close();
  321.             }
  322.         }
  323.         comm2.Close();
  324.         conn1.Close();
  325.         ArrayList array6 = new ArrayList();
  326.         SqlConnection conn3 = dbConnection.getConnection();
  327.         conn3.Open();
  328.         foreach (int i in array_1)
  329.         {
  330.             SqlCommand sqlcom4 = new SqlCommand("select emp_no from OA_EMPLOYEE where department_id='" + i + "'and dimission_date=''", conn3);
  331.             SqlDataReader comm4 = sqlcom4.ExecuteReader();
  332.             if (comm4.HasRows)
  333.             {
  334.                 while (comm4.Read())
  335.                 {
  336.                     array6.Add(Convert.ToString(comm4["emp_no"]));
  337.                 }
  338.             }
  339.             comm4.Close();
  340.         }
  341.         foreach (string i in array6)
  342.         {
  343.             SqlCommand sqlcom5 = new SqlCommand("select emp_name from OA_EMPLOYEE where emp_no='" + i + "'", conn3);
  344.             emp_name = Convert.ToString(sqlcom5.ExecuteScalar());
  345.             SqlCommand sqlcom6 = new SqlCommand("select distinct data from OA_KAOQIN_JL where data between'" + TextBox1.Text + "'and'" + TextBox2.Text + "'order by data", conn3);
  346.             SqlDataReader comm6 = sqlcom6.ExecuteReader();
  347.             while (comm6.Read())
  348.             {
  349.                 row = dt.NewRow();
  350.                 row["所屬部門"] = name;
  351.                 row["姓名"] = emp_name;
  352.                 row["員工編號"] = i;
  353.                 row["日期"] = Convert.ToString(comm6["data"]);
  354.                 row["星期"] = getweekday(Convert.ToDateTime(comm6["data"]));
  355.                 SqlConnection conn4 = dbConnection.getConnection();
  356.                 conn4.Open();
  357.                 SqlCommand sqlcom7 = new SqlCommand("select f.zao as zao,f.wan as wan,f.wuxia as wuxia,f.wushang as wushang from OA_KAOQIN_JL as f,OA_EMPLOYEE as g where f.card_id=g.work_card_no1 and g.emp_no='" + i + "'and data='" + Convert.ToString(comm6["data"]) + "'", conn4);
  358.                 SqlDataReader comm7 = sqlcom7.ExecuteReader();
  359.                 if (comm7.HasRows)
  360.                 {
  361.                     while (comm7.Read())
  362.                     {
  363.                         time1 = Convert.ToString(comm7["zao"]);
  364.                         time2 = Convert.ToString(comm7["wan"]);
  365.                         time3 = Convert.ToString(comm7["wuxia"]);
  366.                         time4 = Convert.ToString(comm7["wushang"]);
  367.                         if (time1.Equals(""))
  368.                         {
  369.                             row["早上上班"] = nul;
  370.                         }
  371.                         else
  372.                         {
  373.                             row["早上上班"] = time1;
  374.                         }
  375.                         if (time3.Equals(""))
  376.                         {
  377.                             row["中午下班"] = nul;
  378.                         }
  379.                         else
  380.                         {
  381.                             row["中午下班"] = time3;
  382.                         }
  383.                         if (time4.Equals(""))
  384.                         {
  385.                             row["下午上班"] = nul;
  386.                         }
  387.                         else
  388.                         {
  389.                             row["下午上班"] = time4;
  390.                         }
  391.                         if (time2.Equals(""))
  392.                         {
  393.                             row["下午下班"] = nul;
  394.                         }
  395.                         else
  396.                         {
  397.                             row["下午下班"] = time2;
  398.                         }
  399.                         if (time1.Length == 5)
  400.                         {
  401.                             time1 = "0" + time1;
  402.                         }
  403.                         if (time2.Length == 5)
  404.                         {
  405.                             time2 = "0" + time2;
  406.                         }
  407.                         if (!(time1.Equals("")) && (!time2.Equals("")))
  408.                         {
  409.                             sum = (double)(Convert.ToInt32(time2.Substring(0, 2)) - Convert.ToInt32(time1.Substring(0, 2)) - 1.5 + (double)(Convert.ToInt32(time2.Substring(2, 2)) - Convert.ToInt32(time1.Substring(2, 2))) / 60);
  410.                             sum = Round(sum, 2);
  411.                             row["簽到時數"] = Convert.ToString(sum);
  412.                         }
  413.                         else
  414.                         {
  415.                             row["簽到時數"] = nul;
  416.                         }
  417.                     }
  418.                 }
  419.                 else
  420.                 {
  421.                     row["早上上班"] = nul;
  422.                     row["中午下班"] = nul;
  423.                     row["下午上班"] = nul;
  424.                     row["下午下班"] = nul;
  425.                     row["簽到時數"] = nul;
  426.                 }
  427.                 comm7.Close();
  428.                 conn4.Close();
  429.                 dt.Rows.Add(row);
  430.             }
  431.             comm6.Close();
  432.         }
  433.         conn3.Close();
  434.     }
  435.     public double Round(double v, int x)
  436.     {
  437.         bool flat = false;
  438.         if (v < 0)
  439.         {
  440.             flat = true;
  441.             v = -v;
  442.         }
  443.         int ivalue = 1;
  444.         for (int i = 1; i <= x; i++)
  445.         {
  446.             ivalue = 10 * ivalue;
  447.         }
  448.         double num = Math.Round(v * ivalue + 0.5, 0);
  449.         v = num / ivalue;
  450.         if (flat)
  451.         {
  452.             v = -v;
  453.         }
  454.         return v;
  455.     }
  456.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  457.     {
  458.         if (Calendar1.Visible == true)
  459.         {
  460.             Calendar1.Visible = false;
  461.             Calendar1.Focus();
  462.         }
  463.         else
  464.         {
  465.             Calendar1.Visible = true;
  466.             Calendar1.Focus();
  467.         }
  468.         getid();
  469.     }
  470.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  471.     {
  472.         if (Calendar2.Visible == true)
  473.         {
  474.             Calendar2.Visible = false;
  475.             Calendar2.Focus();
  476.         }
  477.         else
  478.         {
  479.             Calendar2.Visible = true;
  480.             Calendar2.Focus();
  481.         }
  482.         getid();
  483.     }
  484.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  485.     {
  486.         Calendar1.Visible = false;
  487.         string year = Calendar1.SelectedDate.Year.ToString();
  488.         string month = Calendar1.SelectedDate.Month.ToString();
  489.         if (month.Length == 1)
  490.         {
  491.             month = "0" + month;
  492.         }
  493.         string day = Calendar1.SelectedDate.Day.ToString();
  494.         if (day.Length == 1)
  495.         {
  496.             day = "0" + day;
  497.         }
  498.         TextBox1.Text = year + "-" + month + "-" + day;
  499.         TextBox1.Focus();
  500.     }
  501.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  502.     {
  503.         Calendar2.Visible = false;
  504.         string year = Calendar2.SelectedDate.Year.ToString();
  505.         string month = Calendar2.SelectedDate.Month.ToString();
  506.         if (month.Length == 1)
  507.         {
  508.             month = "0" + month;
  509.         }
  510.         string day = Calendar2.SelectedDate.Day.ToString();
  511.         if (day.Length == 1)
  512.         {
  513.             day = "0" + day;
  514.         }
  515.         TextBox2.Text = year + "-" + month + "-" + day;
  516.         TextBox2.Focus();
  517.     }
  518.     public string getweekday(DateTime data)
  519.     {
  520.         string str = null;
  521.         switch (data.DayOfWeek.ToString())
  522.         {
  523.             case "Monday":
  524.                 str = "星期一";
  525.                 break;
  526.             case "Tuesday":
  527.                 str = "星期二";
  528.                 break;
  529.             case "Wednesday":
  530.                 str = "星期三";
  531.                 break;
  532.             case "Thursday":
  533.                 str = "星期四";
  534.                 break;
  535.             case "Friday":
  536.                 str = "星期五";
  537.                 break;
  538.             case "Saturday":
  539.                 str = "星期六";
  540.                 break;
  541.             case "Sunday":
  542.                 str = "星期日";
  543.                 break;
  544.         }
  545.         return str;
  546.     }
  547.     protected void Button1_Click(object sender, EventArgs e)
  548.     {
  549.         if (DropDownList1.Text.Equals("所有部門"))
  550.         {
  551.             getid();
  552.             getnum();
  553.         }
  554.         else
  555.         {
  556.             array_1 = new ArrayList();
  557.             getnum1();
  558.         }
  559.         ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
  560.         ReportViewer1.LocalReport.DataSources.Clear();
  561.         ReportViewer1.LocalReport.DataSources.Add(rds);
  562.         ReportViewer1.LocalReport.Refresh();
  563.         ReportViewer1.Visible = true;
  564.     }
  565.     protected void TextBox1_TextChanged(object sender, EventArgs e)
  566.     {
  567.     }
  568.     protected void TextBox2_TextChanged(object sender, EventArgs e)
  569.     {
  570.     }
  571. }