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

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. public partial class web_class : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.         if (IsPostBack)
  17.         {
  18.             shift_table.Visible = false;
  19.             SqlConnection conn = dbConnection.getConnection();
  20.             conn.Open();
  21.             SqlCommand comm = new SqlCommand("select f.name as name from oa_department as f, oa_employee as g where f.id=g.department_id and g.id='156'", conn);
  22.             try
  23.             {
  24.                 Label1.Text = comm.ExecuteScalar().ToString();
  25.             }
  26.             catch
  27.             {
  28.             }
  29.             conn.Close();
  30.             set_table();
  31.         }
  32.     }
  33.     private void set_table()
  34.     {
  35.         int num = 1;
  36.         shift_table.Visible = true;
  37.         SqlConnection conn = dbConnection.getConnection();
  38.         conn.Open();
  39.         TableRow tr = new TableRow();
  40.         TableCell td = new TableCell();
  41.         td.Text = "工号";
  42.         tr.Cells.Add(td);
  43.         td = new TableCell();
  44.         td.Text = "姓名";
  45.         tr.Cells.Add(td);
  46.         SqlCommand sqlcom1 = new SqlCommand("select day_of_month,the_day from time_demo where the_year='" + dr_year.SelectedValue.ToString() + "'and the_month='" + dr_month.SelectedValue.ToString() + "'", conn);
  47.         SqlDataReader dr1 = sqlcom1.ExecuteReader();
  48.         if (dr1.HasRows)
  49.         {
  50.             while (dr1.Read())
  51.             {
  52.                 td = new TableCell();
  53.                 if ((dr1["the_day"].ToString().Equals("星期日")) || (dr1["the_day"].ToString().Equals("星期六")))
  54.                 {
  55.                     td.Text = dr1["day_of_month"].ToString() + "<br>" + dr1["the_day"].ToString();
  56.                     td.ForeColor = System.Drawing.Color.Red;
  57.                 }
  58.                 else
  59.                 {
  60.                    td.Text = dr1["day_of_month"].ToString() + "<br>" + dr1["the_day"].ToString();
  61.                 }
  62.                 tr.Cells.Add(td);
  63.                 num = num + 1;
  64.             }
  65.         }
  66.         shift_table.Rows.Add(tr);
  67.         dr1.Close();
  68.         SqlCommand sqlcom2 = new SqlCommand("select f.emp_no as emp_no,f.emp_name as emp_name from oa_employee as f , oa_department as g where f.department_id=g.id and g.name='" + Label1.Text + "'", conn);
  69.         SqlDataReader dr2 = sqlcom2.ExecuteReader();
  70.         if (dr2.HasRows)
  71.         {
  72.             while (dr2.Read())
  73.             {
  74.                 TableRow tr_1 = new TableRow();
  75.                 TableCell td_1 = new TableCell();
  76.                 td_1.Text = dr2["emp_no"].ToString();
  77.                 tr_1.Cells.Add(td_1);
  78.                 td_1 = new TableCell();
  79.                 td_1.Text = dr2["emp_name"].ToString();
  80.                 tr_1.Cells.Add(td_1);
  81.                 for (int i = 0; i < (num-1); i++)
  82.                 {
  83.                     TableCell td_2 = new TableCell();
  84.                     DropDownList dl = new DropDownList();
  85.                     dl.Items.Add("");
  86.                     SqlConnection sqlcon = dbConnection.getConnection();
  87.                     sqlcon.Open();
  88.                     SqlCommand sqlcom = new SqlCommand("select type from oa_pos_type where department='" + Label1.Text + "'", sqlcon);
  89.                     SqlDataReader dr = sqlcom.ExecuteReader();
  90.                     if (dr.HasRows)
  91.                     {
  92.                         while (dr.Read())
  93.                         {
  94.                             dl.Items.Add(dr["type"].ToString());
  95.                         }
  96.                     }
  97.                     dr.Close();
  98.                     td_2.Controls.Add(dl);
  99.                     tr_1.Cells.Add(td_2);
  100.                     sqlcon.Close();
  101.                 }
  102.                 shift_table.Rows.Add(tr_1);
  103.             }
  104.         }
  105.     }
  106.     protected void Button1_Click(object sender, EventArgs e)
  107.     {
  108.         SqlConnection conn = dbConnection.getConnection();
  109.         conn.Open();
  110.         for (int i = 1; i < shift_table.Rows.Count; i++)
  111.         {
  112.             for (int j = 2; j < shift_table.Rows[i].Cells.Count; j++)
  113.             {
  114.                 string str = dr_year.SelectedValue.ToString();
  115.                 if (dr_month.SelectedValue.ToString().Length == 1)
  116.                 {
  117.                     str = str + "0" + dr_month.SelectedValue.ToString();
  118.                 }
  119.                 else
  120.                 {
  121.                     str = str + dr_month.SelectedValue.ToString();
  122.                 }
  123.                 string str_1 = shift_table.Rows[0].Cells[j].Text.ToString();
  124.                 string [] str_2 = str_1.Split('<');
  125.                 if (str[0].ToString().Length == 1)
  126.                 {
  127.                     str = str + "0" +str_2[0];
  128.                 }
  129.                 else
  130.                 {
  131.                     str = str + str_2[0];
  132.                 }
  133.                 if (!(((DropDownList)(shift_table.Rows[i].Cells[j].Controls[0])).SelectedValue.ToString().Equals("")))
  134.                 {
  135.                     SqlCommand comm = new SqlCommand("insert into oa_kaoqin_pbb (data,name,emp_no,banbie) values('" + str + "','" + shift_table.Rows[i].Cells[1].Text.ToString() + "','" + shift_table.Rows[i].Cells[0].Text.ToString() + "','" +((DropDownList)(shift_table.Rows[i].Cells[j].Controls[0])).SelectedValue.ToString() + "')", conn);
  136.                     comm.ExecuteNonQuery();
  137.                 }
  138.                 else
  139.                 {
  140.                     continue;
  141.                 }
  142.             }
  143.         }
  144.         conn.Close();
  145.     }
  146. }