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

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_pos_c_show_work : 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.     protected void Page_Load(object sender, EventArgs e)
  24.     {
  25.         ReportViewer1.Visible = false;
  26.         SqlConnection conn = dbConnection.getConnection();
  27.         conn.Open();
  28.         SqlCommand comm1 = new SqlCommand("select id from OA_DEPARTMENT where name='中山隆成啟航商貿有限公司'", conn);
  29.         no = Convert.ToInt32(comm1.ExecuteScalar());
  30.         SqlCommand sqlcom2 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + no + "'", conn);
  31.         SqlDataReader comm2 = sqlcom2.ExecuteReader();
  32.         while (comm2.Read())
  33.         {
  34.             array1.Add(Convert.ToInt32(comm2["id"]));
  35.         }
  36.         comm2.Close();
  37.         foreach (int i in array1)
  38.         {
  39.             ArrayList array5 = new ArrayList();
  40.             array5.Add(i);
  41.             SqlCommand sqlcom3 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + i + "'and id!='144'and id!='145'and id!='146'and id!='147'and id!='194'and id!='197'", conn);
  42.             SqlDataReader comm3 = sqlcom3.ExecuteReader();
  43.             if (comm3.HasRows)
  44.             {
  45.                 while (comm3.Read())
  46.                 {
  47.                     array5.Add(Convert.ToInt32(comm3["id"]));
  48.                     SqlConnection conn1 = dbConnection.getConnection();
  49.                     conn1.Open();
  50.                     SqlCommand sqlcom4 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + Convert.ToInt32(comm3["id"]) + "'", conn1);
  51.                     SqlDataReader comm4 = sqlcom4.ExecuteReader();
  52.                     if (comm4.HasRows)
  53.                     {
  54.                         while (comm4.Read())
  55.                         {
  56.                             array5.Add(Convert.ToInt32(comm4["id"]));
  57.                         }
  58.                     }
  59.                     comm4.Close();
  60.                     conn1.Close();
  61.                 }
  62.             }
  63.             comm3.Close();
  64.             array2.Add(array5);
  65.         }
  66.         conn.Close();
  67.     }
  68.     public void getnum()
  69.     {
  70.        int k=0;
  71.        string name = "";
  72.        string emp_name = "";
  73.         string nul=" ";
  74.         string department="";
  75.         double sum=0;
  76.         string time1="";
  77.         string time2="";
  78.         string time3 = "";
  79.         string time4 = "";
  80.         ArrayList array_2 = new ArrayList();
  81.         SqlConnection conn1 = dbConnection.getConnection();
  82.         conn1.Open();
  83.         foreach (ArrayList i in array2)
  84.         {
  85.             ArrayList array6 = new ArrayList();
  86.             foreach (int j in i)
  87.             {
  88.                 SqlCommand sqlcom1 = new SqlCommand("select emp_no from OA_EMPLOYEE where department_id='" + j + "'", conn1);
  89.                 SqlDataReader comm1 = sqlcom1.ExecuteReader();
  90.                 if (comm1.HasRows)
  91.                 {
  92.                     while (comm1.Read())
  93.                     {
  94.                         array6.Add(Convert.ToString(comm1["emp_no"]));
  95.                     }
  96.                 }
  97.                 comm1.Close();
  98.             }
  99.             array3.Add(array6);
  100.         }
  101.         foreach (ArrayList i in array3)
  102.         {
  103.             if (k < array1.Count)
  104.             {
  105.                 foreach (string j in i)
  106.                 {
  107.                     SqlConnection conn2 = dbConnection.getConnection();
  108.                     conn2.Open();
  109.                     SqlCommand sqlcom2 = new SqlCommand("select name from OA_DEPARTMENT where id='" + array1[k] + "'", conn2);
  110.                     name = Convert.ToString(sqlcom2.ExecuteScalar());
  111.                     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);
  112.                     department = Convert.ToString(sqlcom4.ExecuteScalar());
  113.                     SqlCommand sqlcom3 = new SqlCommand("select emp_name from OA_EMPLOYEE where emp_no='" + j + "'", conn2);
  114.                     emp_name = Convert.ToString(sqlcom3.ExecuteScalar());
  115.                     SqlCommand sqlcom5 = new SqlCommand("select distinct data from OA_KAOQIN_JL where data between'" + TextBox1.Text + "'and'" + TextBox2.Text + "'order by data", conn2);
  116.                     SqlDataReader comm5 = sqlcom5.ExecuteReader();
  117.                     while (comm5.Read())
  118.                     {
  119.                         array_2.Add(name);
  120.                         array_2.Add(emp_name);
  121.                         array_2.Add(j);
  122.                         array_2.Add(Convert.ToString(comm5["data"]));
  123.                         array_2.Add(getweekday(Convert.ToDateTime(comm5["data"])));
  124.                         SqlConnection conn5 = dbConnection.getConnection();
  125.                         conn5.Open();
  126.                         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);
  127.                         SqlDataReader comm8 = sqlcom8.ExecuteReader();
  128.                         if (comm8.HasRows)
  129.                         {
  130.                             while (comm8.Read())
  131.                             {
  132.                                 time1 = Convert.ToString(comm8["zao"]);
  133.                                 time2 = Convert.ToString(comm8["wan"]);
  134.                                 time3 = Convert.ToString(comm8["wuxia"]);
  135.                                 time4 = Convert.ToString(comm8["wushang"]);
  136.                                 if (time1.Equals(""))
  137.                                 {
  138.                                     array_2.Add(nul);
  139.                                 }
  140.                                 else
  141.                                 {
  142.                                     array_2.Add(time1);
  143.                                 }
  144.                                 if (time3.Equals(""))
  145.                                 {
  146.                                     array_2.Add(nul);
  147.                                 }
  148.                                 else
  149.                                 {
  150.                                     array_2.Add(time3);
  151.                                 }
  152.                                 if (time4.Equals(""))
  153.                                 {
  154.                                     array_2.Add(nul);
  155.                                 }
  156.                                 else
  157.                                 {
  158.                                     array_2.Add(time4);
  159.                                 }
  160.                                 if (time2.Equals(""))
  161.                                 {
  162.                                     array_2.Add(nul);
  163.                                 }
  164.                                 else
  165.                                 {
  166.                                     array_2.Add(nul);
  167.                                 }
  168.                                 if (time1.Length == 5)
  169.                                 {
  170.                                     time1 = "0" + time1;
  171.                                 }
  172.                                 if (time2.Length == 5)
  173.                                 {
  174.                                     time2 = "0" + time2;
  175.                                 }
  176.                                 if (!(time1.Equals("")) && (!time2.Equals("")))
  177.                                 {
  178.                                     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);
  179.                                     sum = Round(sum, 2);
  180.                                     array_2.Add(Convert.ToString(sum));
  181.                                 }
  182.                                 else
  183.                                 {
  184.                                     array_2.Add(nul);
  185.                                 }
  186.                             }
  187.                         }
  188.                         else
  189.                         {
  190.                             array_2.Add(nul);
  191.                             array_2.Add(nul);
  192.                             array_2.Add(nul);
  193.                             array_2.Add(nul);
  194.                             array_2.Add(nul);
  195.                         }
  196.                         comm8.Close();
  197.                         conn5.Close();
  198.                         array_1.Add(array_2);
  199.                     }
  200.                     comm5.Close();
  201.                     conn2.Close();
  202.                 }
  203.                 k++;
  204.             }
  205.         }
  206.         conn1.Close();
  207.     }
  208.     public double Round(double v, int x)
  209.     {
  210.         bool flat = false;
  211.         if (v < 0)
  212.         {
  213.             flat = true;
  214.             v = -v;
  215.         }
  216.         int ivalue = 1;
  217.         for (int i = 1; i <= x; i++)
  218.         {
  219.             ivalue = 10 * ivalue;
  220.         }
  221.         double num = Math.Round(v * ivalue + 0.5, 0);
  222.         v = num / ivalue;
  223.         if (flat)
  224.         {
  225.             v = -v;
  226.         }
  227.         return v;
  228.     }
  229.     protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  230.     {
  231.         if (Calendar1.Visible == true)
  232.         {
  233.             Calendar1.Visible = false;
  234.             Calendar1.Focus();
  235.         }
  236.         else
  237.         {
  238.             Calendar1.Visible = true;
  239.             Calendar1.Focus();
  240.         }
  241.     }
  242.     protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
  243.     {
  244.         if (Calendar2.Visible == true)
  245.         {
  246.             Calendar2.Visible = false;
  247.             Calendar2.Focus();
  248.         }
  249.         else
  250.         {
  251.             Calendar2.Visible = true;
  252.             Calendar2.Focus();
  253.         }
  254.     }
  255.     protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  256.     {
  257.         Calendar1.Visible = false;
  258.         string year = Calendar1.SelectedDate.Year.ToString();
  259.         string month = Calendar1.SelectedDate.Month.ToString();
  260.         if (month.Length == 1)
  261.         {
  262.             month = "0" + month;
  263.         }
  264.         string day = Calendar1.SelectedDate.Day.ToString();
  265.         if (day.Length == 1)
  266.         {
  267.             day = "0" + day;
  268.         }
  269.         TextBox1.Text = year + "-" + month + "-" + day;
  270.         TextBox1.Focus();
  271.     }
  272.     protected void Calendar2_SelectionChanged(object sender, EventArgs e)
  273.     {
  274.         Calendar2.Visible = false;
  275.         string year = Calendar2.SelectedDate.Year.ToString();
  276.         string month = Calendar2.SelectedDate.Month.ToString();
  277.         if (month.Length == 1)
  278.         {
  279.             month = "0" + month;
  280.         }
  281.         string day = Calendar2.SelectedDate.Day.ToString();
  282.         if (day.Length == 1)
  283.         {
  284.             day = "0" + day;
  285.         }
  286.         TextBox2.Text = year + "-" + month + "-" + day;
  287.         TextBox2.Focus();
  288.     }
  289.     public string getweekday(DateTime data)
  290.     {
  291.         string str = null;
  292.         switch (data.DayOfWeek.ToString())
  293.         {
  294.             case"Monday":
  295.                 str="星期一";
  296.                 break;
  297.             case"Tuesday":
  298.                 str = "星期二";
  299.                 break;
  300.             case"Wednesday":
  301.                 str = "星期三";
  302.                 break;
  303.             case"Thursday":
  304.                 str = "星期四";
  305.                 break;
  306.             case"Friday":
  307.                 str = "星期五";
  308.                 break;
  309.             case"Saturday":
  310.                 str = "星期六";
  311.                 break;
  312.             case"Sunday":
  313.                 str = "星期日";
  314.                 break;
  315.         }
  316.         return str;
  317.     }
  318.     protected void Button1_Click(object sender, EventArgs e)
  319.     {
  320.         getnum();
  321.         foreach (ArrayList i in array_1)
  322.         {
  323.             foreach (string j in i)
  324.             {
  325.                 Response.Write(j);
  326.             }
  327.         }
  328.         /*DataTable dt = GetData();
  329.         ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
  330.         ReportViewer1.LocalReport.DataSources.Clear();
  331.         ReportViewer1.LocalReport.DataSources.Add(rds);
  332.         ReportViewer1.LocalReport.Refresh();
  333.         ReportViewer1.Visible = true;*/
  334.     }
  335.     private DataTable GetData()
  336.     {
  337.         DataTable dt = new DataTable("dataname");
  338.         dt.Columns.Add(new DataColumn("所屬部門", typeof(string)));
  339.         dt.Columns.Add(new DataColumn("姓名", typeof(string)));
  340.         dt.Columns.Add(new DataColumn("員工編號", typeof(string)));
  341.         dt.Columns.Add(new DataColumn("日期", typeof(string)));
  342.         dt.Columns.Add(new DataColumn("星期", typeof(string)));
  343.         dt.Columns.Add(new DataColumn("早上上班", typeof(string)));
  344.         dt.Columns.Add(new DataColumn("中午下班", typeof(string)));
  345.         dt.Columns.Add(new DataColumn("下午上班", typeof(string)));
  346.         dt.Columns.Add(new DataColumn("下午下班", typeof(string)));
  347.         dt.Columns.Add(new DataColumn("簽到時數", typeof(string)));
  348.         DataRow row = dt.NewRow();
  349.         foreach (ArrayList i in array_1)
  350.         {
  351.             int n = 0;
  352.             foreach (string j in i)
  353.             {
  354.                 row = dt.NewRow();
  355.                 if (n < 10)
  356.                 {
  357.                     switch (n)
  358.                     {
  359.                         case 0:
  360.                             row["所屬部門"] = j;
  361.                             break;
  362.                         case 1:
  363.                             row["姓名"] = j;
  364.                             break;
  365.                         case 2:
  366.                             row["員工編號"] = j;
  367.                             break;
  368.                         case 3:
  369.                             row["日期"] = j;
  370.                             break;
  371.                         case 4:
  372.                             row["星期"] = j;
  373.                             break;
  374.                         case 5:
  375.                             row["早上上班"] = j;
  376.                             break;
  377.                         case 6:
  378.                             row["中午下班"] = j;
  379.                             break;
  380.                         case 7:
  381.                             row["下午上班"] = j;
  382.                             break;
  383.                         case 8:
  384.                             row["下午下班"] = j;
  385.                             break;
  386.                         case 9:
  387.                             row["簽到時數"] = j;
  388.                             break;
  389.                     }
  390.                     n++;
  391.                 }
  392.                 else
  393.                 {
  394.                     break;
  395.                 }
  396.             }
  397.             dt.Rows.Add(row);
  398.         }
  399.         return dt;
  400.     }
  401.     protected void TextBox1_TextChanged(object sender, EventArgs e)
  402.     {
  403.     }
  404.     protected void TextBox2_TextChanged(object sender, EventArgs e)
  405.     {
  406.     }
  407. }