show.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:22k
源码类别:
OA系统
开发平台:
ASP/ASPX
- using System;
- using System.Data;
- using System.Data.SqlClient;
- 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 Microsoft.Reporting.WebForms;
- using System.Reflection;
- using System.Runtime.InteropServices;
- using DataTable = System.Data.DataTable;
- public partial class web_show : System.Web.UI.Page
- {
- int no = 0;
- ArrayList array1 = new ArrayList();
- ArrayList array2 = new ArrayList();
- ArrayList array3 = new ArrayList();
- ArrayList array_1 = new ArrayList();
- DataTable dt = new DataTable("dataname");
- protected void Page_Load(object sender, EventArgs e)
- {
- dt.Columns.Add(new DataColumn("所屬部門", typeof(string)));
- dt.Columns.Add(new DataColumn("姓名", typeof(string)));
- dt.Columns.Add(new DataColumn("員工編號", typeof(string)));
- dt.Columns.Add(new DataColumn("日期", typeof(string)));
- dt.Columns.Add(new DataColumn("星期", typeof(string)));
- dt.Columns.Add(new DataColumn("早上上班", typeof(string)));
- dt.Columns.Add(new DataColumn("中午下班", typeof(string)));
- dt.Columns.Add(new DataColumn("下午上班", typeof(string)));
- dt.Columns.Add(new DataColumn("下午下班", typeof(string)));
- dt.Columns.Add(new DataColumn("簽到時數", typeof(string)));
- ReportViewer1.Visible = false;
- DropDownList1.Visible = true;
- }
- public void getid()
- {
- int flag = 0;
- int emp_where = 0;
- string str = "";
- string user_id = "";
- DropDownList1.Items.Clear();
- DropDownList1.Items.Add("所有部門");
- if (Session["user_id"] != null)
- {
- user_id = Session["user_id"].ToString();
- }
- ReportViewer1.Visible = false;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand sqlcom1 = new SqlCommand("select emp_where from OA_EMPLOYEE where id='" + user_id + "'", conn);
- emp_where = Convert.ToInt32(sqlcom1.ExecuteScalar());
- if (emp_where == 1)
- {
- str = "中山隆成啟航商貿有限公司";
- }
- else if (emp_where == 2)
- {
- str = "中山捷盟貿易有限公司";
- }
- else
- {
- }
- SqlCommand comm1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + str + "'", conn);
- no = Convert.ToInt32(comm1.ExecuteScalar());
- SqlCommand sqlcom2 = new SqlCommand("select id,name from OA_DEPARTMENT where last_id='" + no + "'and out='0'", conn);
- SqlDataReader comm2 = sqlcom2.ExecuteReader();
- while (comm2.Read())
- {
- array1.Add(Convert.ToInt32(comm2["id"]));
- for (int i = 0; i < DropDownList1.Items.Count; i++)
- {
- if (Convert.ToString(comm2["name"]).Equals(DropDownList1.Items[i]))
- {
- flag = flag + 1;
- }
- }
- if (flag == 0)
- {
- DropDownList1.Items.Add(Convert.ToString(comm2["name"]));
- }
- }
- comm2.Close();
- foreach (int i in array1)
- {
- ArrayList array5 = new ArrayList();
- array5.Add(i);
- SqlCommand sqlcom3 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + i + "'", conn);
- SqlDataReader comm3 = sqlcom3.ExecuteReader();
- if (comm3.HasRows)
- {
- while (comm3.Read())
- {
- array5.Add(Convert.ToInt32(comm3["id"]));
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom4 = new SqlCommand("select id ,name from OA_DEPARTMENT where last_id='" + Convert.ToInt32(comm3["id"]) + "'", conn1);
- SqlDataReader comm4 = sqlcom4.ExecuteReader();
- if (comm4.HasRows)
- {
- while (comm4.Read())
- {
- array5.Add(Convert.ToInt32(comm4["id"]));
- }
- }
- comm4.Close();
- conn1.Close();
- }
- }
- comm3.Close();
- array2.Add(array5);
- }
- conn.Close();
- }
- public void getnum()
- {
- int k = 0;
- string name = "";
- string emp_name = "";
- string nul = " ";
- string department = "";
- double sum = 0;
- string time1 = "";
- string time2 = "";
- string time3 = "";
- string time4 = "";
- DataRow row = dt.NewRow();
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- foreach (ArrayList i in array2)
- {
- ArrayList array6 = new ArrayList();
- foreach (int j in i)
- {
- SqlCommand sqlcom1 = new SqlCommand("select emp_no from OA_EMPLOYEE where department_id='" + j + "'and dimission_date=''", conn1);
- SqlDataReader comm1 = sqlcom1.ExecuteReader();
- if (comm1.HasRows)
- {
- while (comm1.Read())
- {
- array6.Add(Convert.ToString(comm1["emp_no"]));
- }
- }
- comm1.Close();
- }
- array3.Add(array6);
- }
- foreach (ArrayList i in array3)
- {
- if (k < array1.Count)
- {
- foreach (string j in i)
- {
- SqlConnection conn2 = dbConnection.getConnection();
- conn2.Open();
- SqlCommand sqlcom2 = new SqlCommand("select name from OA_DEPARTMENT where id='" + array1[k] + "'", conn2);
- name = Convert.ToString(sqlcom2.ExecuteScalar());
- 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);
- department = Convert.ToString(sqlcom4.ExecuteScalar());
- SqlCommand sqlcom3 = new SqlCommand("select emp_name from OA_EMPLOYEE where emp_no='" + j + "'", conn2);
- emp_name = Convert.ToString(sqlcom3.ExecuteScalar());
- SqlCommand sqlcom5 = new SqlCommand("select distinct data from OA_KAOQIN_JL where data between'" + TextBox1.Text + "'and'" + TextBox2.Text + "'order by data", conn2);
- SqlDataReader comm5 = sqlcom5.ExecuteReader();
- while (comm5.Read())
- {
- row = dt.NewRow();
- row["所屬部門"] = name;
- row["姓名"] = emp_name;
- row["員工編號"] = j;
- row["日期"] = Convert.ToString(comm5["data"]);
- row["星期"] = getweekday(Convert.ToDateTime(comm5["data"]));
- SqlConnection conn5 = dbConnection.getConnection();
- conn5.Open();
- 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);
- SqlDataReader comm8 = sqlcom8.ExecuteReader();
- if (comm8.HasRows)
- {
- while (comm8.Read())
- {
- time1 = Convert.ToString(comm8["zao"]);
- time2 = Convert.ToString(comm8["wan"]);
- time3 = Convert.ToString(comm8["wuxia"]);
- time4 = Convert.ToString(comm8["wushang"]);
- if (time1.Equals(""))
- {
- row["早上上班"] = nul;
- }
- else
- {
- row["早上上班"] = time1;
- }
- if (time3.Equals(""))
- {
- row["中午下班"] = nul;
- }
- else
- {
- row["中午下班"] = time3;
- }
- if (time4.Equals(""))
- {
- row["下午上班"] = nul;
- }
- else
- {
- row["下午上班"] = time4;
- }
- if (time2.Equals(""))
- {
- row["下午下班"] = nul;
- }
- else
- {
- row["下午下班"] = time2;
- }
- if (time1.Length == 5)
- {
- time1 = "0" + time1;
- }
- if (time2.Length == 5)
- {
- time2 = "0" + time2;
- }
- if (!(time1.Equals("")) && (!time2.Equals("")))
- {
- 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);
- sum = Round(sum, 2);
- row["簽到時數"] = Convert.ToString(sum);
- }
- else
- {
- row["簽到時數"] = nul;
- }
- }
- }
- else
- {
- row["早上上班"] = nul;
- row["中午下班"] = nul;
- row["下午上班"] = nul;
- row["下午下班"] = nul;
- row["簽到時數"] = nul;
- }
- comm8.Close();
- conn5.Close();
- dt.Rows.Add(row);
- }
- comm5.Close();
- conn2.Close();
- }
- k++;
- }
- }
- conn1.Close();
- }
- public void getnum1()
- {
- int id = 0;
- string name="";
- string department = "";
- string emp_name = "";
- double sum = 0;
- string time1 = "";
- string time2 = "";
- string time3 = "";
- string time4 = "";
- string nul = "";
- int emp_where = 0;
- string str = "";
- string user_id = "";
- int last_id = 0;
- if (Session["user_id"] != null)
- {
- user_id = Session["user_id"].ToString();
- }
- DataRow row = dt.NewRow();
- name = DropDownList1.Text;
- SqlConnection conn1 = dbConnection.getConnection();
- conn1.Open();
- SqlCommand sqlcom8 = new SqlCommand("select emp_where from OA_EMPLOYEE where id='" + user_id + "'", conn1);
- emp_where = Convert.ToInt32(sqlcom8.ExecuteScalar());
- if (emp_where == 1)
- {
- str = "中山隆成啟航商貿有限公司";
- }
- else if (emp_where == 2)
- {
- str = "中山捷盟貿易有限公司";
- }
- else
- {
- }
- SqlCommand comm1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + str + "'", conn1);
- last_id = Convert.ToInt32(comm1.ExecuteScalar());
- SqlCommand sqlcom1 = new SqlCommand("select id from OA_DEPARTMENT where name='" + DropDownList1.Text + "'and last_id='" + last_id + "'and out='0'", conn1);
- id = Convert.ToInt32(sqlcom1.ExecuteScalar());
- array_1.Add(id);
- SqlCommand sqlcom2 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + id + "'and out='0'", conn1);
- SqlDataReader comm2 = sqlcom2.ExecuteReader();
- if (comm2.HasRows)
- {
- while (comm2.Read())
- {
- array_1.Add(Convert.ToInt32(comm2["id"]));
- SqlConnection conn2 = dbConnection.getConnection();
- conn2.Open();
- SqlCommand sqlcom3 = new SqlCommand("select id from OA_DEPARTMENT where last_id='" + Convert.ToInt32(comm2["id"]) + "'", conn2);
- SqlDataReader comm3 = sqlcom3.ExecuteReader();
- if (comm3.HasRows)
- {
- while (comm3.Read())
- {
- array_1.Add(Convert.ToInt32(comm3["id"]));
- }
- }
- comm3.Close();
- conn2.Close();
- }
- }
- comm2.Close();
- conn1.Close();
- ArrayList array6 = new ArrayList();
- SqlConnection conn3 = dbConnection.getConnection();
- conn3.Open();
- foreach (int i in array_1)
- {
- SqlCommand sqlcom4 = new SqlCommand("select emp_no from OA_EMPLOYEE where department_id='" + i + "'and dimission_date=''", conn3);
- SqlDataReader comm4 = sqlcom4.ExecuteReader();
- if (comm4.HasRows)
- {
- while (comm4.Read())
- {
- array6.Add(Convert.ToString(comm4["emp_no"]));
- }
- }
- comm4.Close();
- }
- foreach (string i in array6)
- {
- SqlCommand sqlcom5 = new SqlCommand("select emp_name from OA_EMPLOYEE where emp_no='" + i + "'", conn3);
- emp_name = Convert.ToString(sqlcom5.ExecuteScalar());
- SqlCommand sqlcom6 = new SqlCommand("select distinct data from OA_KAOQIN_JL where data between'" + TextBox1.Text + "'and'" + TextBox2.Text + "'order by data", conn3);
- SqlDataReader comm6 = sqlcom6.ExecuteReader();
- while (comm6.Read())
- {
- row = dt.NewRow();
- row["所屬部門"] = name;
- row["姓名"] = emp_name;
- row["員工編號"] = i;
- row["日期"] = Convert.ToString(comm6["data"]);
- row["星期"] = getweekday(Convert.ToDateTime(comm6["data"]));
- SqlConnection conn4 = dbConnection.getConnection();
- conn4.Open();
- 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);
- SqlDataReader comm7 = sqlcom7.ExecuteReader();
- if (comm7.HasRows)
- {
- while (comm7.Read())
- {
- time1 = Convert.ToString(comm7["zao"]);
- time2 = Convert.ToString(comm7["wan"]);
- time3 = Convert.ToString(comm7["wuxia"]);
- time4 = Convert.ToString(comm7["wushang"]);
- if (time1.Equals(""))
- {
- row["早上上班"] = nul;
- }
- else
- {
- row["早上上班"] = time1;
- }
- if (time3.Equals(""))
- {
- row["中午下班"] = nul;
- }
- else
- {
- row["中午下班"] = time3;
- }
- if (time4.Equals(""))
- {
- row["下午上班"] = nul;
- }
- else
- {
- row["下午上班"] = time4;
- }
- if (time2.Equals(""))
- {
- row["下午下班"] = nul;
- }
- else
- {
- row["下午下班"] = time2;
- }
- if (time1.Length == 5)
- {
- time1 = "0" + time1;
- }
- if (time2.Length == 5)
- {
- time2 = "0" + time2;
- }
- if (!(time1.Equals("")) && (!time2.Equals("")))
- {
- 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);
- sum = Round(sum, 2);
- row["簽到時數"] = Convert.ToString(sum);
- }
- else
- {
- row["簽到時數"] = nul;
- }
- }
- }
- else
- {
- row["早上上班"] = nul;
- row["中午下班"] = nul;
- row["下午上班"] = nul;
- row["下午下班"] = nul;
- row["簽到時數"] = nul;
- }
- comm7.Close();
- conn4.Close();
- dt.Rows.Add(row);
- }
- comm6.Close();
- }
- conn3.Close();
- }
- public double Round(double v, int x)
- {
- bool flat = false;
- if (v < 0)
- {
- flat = true;
- v = -v;
- }
- int ivalue = 1;
- for (int i = 1; i <= x; i++)
- {
- ivalue = 10 * ivalue;
- }
- double num = Math.Round(v * ivalue + 0.5, 0);
- v = num / ivalue;
- if (flat)
- {
- v = -v;
- }
- return v;
- }
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar1.Visible == true)
- {
- Calendar1.Visible = false;
- Calendar1.Focus();
- }
- else
- {
- Calendar1.Visible = true;
- Calendar1.Focus();
- }
- getid();
- }
- protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
- {
- if (Calendar2.Visible == true)
- {
- Calendar2.Visible = false;
- Calendar2.Focus();
- }
- else
- {
- Calendar2.Visible = true;
- Calendar2.Focus();
- }
- getid();
- }
- protected void Calendar1_SelectionChanged(object sender, EventArgs e)
- {
- Calendar1.Visible = false;
- 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;
- }
- TextBox1.Text = year + "-" + month + "-" + day;
- TextBox1.Focus();
- }
- protected void Calendar2_SelectionChanged(object sender, EventArgs e)
- {
- Calendar2.Visible = false;
- 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;
- }
- TextBox2.Text = year + "-" + month + "-" + day;
- TextBox2.Focus();
- }
- public string getweekday(DateTime data)
- {
- string str = null;
- switch (data.DayOfWeek.ToString())
- {
- case "Monday":
- str = "星期一";
- break;
- case "Tuesday":
- str = "星期二";
- break;
- case "Wednesday":
- str = "星期三";
- break;
- case "Thursday":
- str = "星期四";
- break;
- case "Friday":
- str = "星期五";
- break;
- case "Saturday":
- str = "星期六";
- break;
- case "Sunday":
- str = "星期日";
- break;
- }
- return str;
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- if (DropDownList1.Text.Equals("所有部門"))
- {
- getid();
- getnum();
- }
- else
- {
- array_1 = new ArrayList();
- getnum1();
- }
- ReportDataSource rds = new ReportDataSource("DataSet1_DataTable1", dt);
- ReportViewer1.LocalReport.DataSources.Clear();
- ReportViewer1.LocalReport.DataSources.Add(rds);
- ReportViewer1.LocalReport.Refresh();
- ReportViewer1.Visible = true;
- }
- protected void TextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- protected void TextBox2_TextChanged(object sender, EventArgs e)
- {
- }
- }