banbie_test.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_banbie_test : System.Web.UI.Page
  13. {
  14.     SqlConnection sqlcon;
  15.     SqlCommand sqlcom;
  16.     string strCon = "Data Source=(local);Database=oa1;Uid=sa;Pwd=lerado";
  17.     string time = "";
  18.     ArrayList array = new ArrayList();
  19.     protected void Page_Load(object sender, EventArgs e)
  20.     {
  21.         if (!IsPostBack)
  22.         {
  23.             DateMgr date = new DateMgr();
  24.             time = date.getDate();
  25.             SqlConnection conn = dbConnection.getConnection();
  26.             conn.Open();
  27.             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='" + Session["user_id"] + "'", conn);
  28.             try
  29.             {
  30.                 Label1.Text = comm.ExecuteScalar().ToString();
  31.             }
  32.             catch
  33.             {
  34.             }
  35.             bind();
  36.             conn.Close();
  37.         }
  38.             Button1.Visible = true;
  39.     }
  40.     public void bind()
  41.     {
  42.         int id = 1;
  43.         SqlConnection conn = dbConnection.getConnection();
  44.         conn.Open();
  45.         DataSet ds = new DataSet();
  46.         DataTable dt = new DataTable();
  47.         dt.Columns.Add(new DataColumn("编号", typeof(int)));
  48.         dt.Columns.Add(new DataColumn("班别", typeof(string)));
  49.         dt.Columns.Add(new DataColumn("开始时间", typeof(string)));
  50.         dt.Columns.Add(new DataColumn("结束时间", typeof(string)));
  51.         dt.Columns.Add(new DataColumn("ID", typeof(int)));
  52.         SqlCommand comm = new SqlCommand("select id,type,bengin_time,end_time from oa_pos_type where department='" + Label1.Text + "'order by id", conn);
  53.         SqlDataReader dr = comm.ExecuteReader();
  54.         if (dr.HasRows)
  55.         {
  56.             while (dr.Read())
  57.             {
  58.                 DataRow row = dt.NewRow();
  59.                 row["编号"] = id;
  60.                 row["班别"] = dr["type"].ToString();
  61.                 row["开始时间"]=dr["bengin_time"].ToString();
  62.                 row["结束时间"] = dr["end_time"].ToString();
  63.                 row["ID"] = dr["id"].ToString();
  64.                 id = id + 1;
  65.                 dt.Rows.Add(row);
  66.             }
  67.         }
  68.         ds.Tables.Add(dt);
  69.         GridView1.DataSource = ds;
  70.         GridView1.DataKeyNames = new string[] { "ID" };
  71.         GridView1.DataBind();
  72.         dr.Close();
  73.         conn.Close();
  74.     }
  75.     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
  76.     {
  77.         GridView1.EditIndex = e.NewEditIndex;
  78.         bind();
  79.     }
  80.     //删除
  81.     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
  82.     {
  83.         int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
  84.         string sqlstr = "delete from oa_pos_type where id='" + id + "'and department='" + Label1.Text + "'";
  85.         sqlcon = new SqlConnection(strCon);
  86.         sqlcom = new SqlCommand(sqlstr, sqlcon);
  87.         sqlcon.Open();
  88.         sqlcom.ExecuteNonQuery();
  89.         sqlcon.Close();
  90.         bind();
  91.     }
  92.     //更新
  93.     protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  94.     {
  95.         try
  96.         {
  97.             DateMgr date = new DateMgr();
  98.             time = date.getDate();
  99.             string str_1=((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
  100.             string str_2 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
  101.             string str_3 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
  102.             int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
  103.             SqlConnection conn = dbConnection.getConnection();
  104.             conn.Open();
  105.             SqlCommand comm = new SqlCommand("update oa_pos_type set type='" +str_1+" ', bengin_time='" +str_2+ "',end_time='" + str_3 + "',emp_id='" + Session["user_id"].ToString() + "',emp_date='" + time + "' where id=" + id + " and department='" + Label1.Text + "'", conn);
  106.             comm.ExecuteNonQuery();
  107.             conn.Close();
  108.             GridView1.EditIndex = -1;
  109.             bind();
  110.         }
  111.         catch (Exception ex)
  112.         {
  113.             Response.Write(ex.Message);
  114.         }
  115.     }
  116.     //取消
  117.     protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
  118.     {
  119.         GridView1.EditIndex = -1;
  120.         bind();
  121.     }
  122.     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  123.     {
  124.         int i;
  125.         //执行循环,保证每条数据都可以更新
  126.         for (i = -1; i < GridView1.Rows.Count; i++)
  127.         {
  128.             //首先判断是否是数据行
  129.             if (e.Row.RowType == DataControlRowType.DataRow)
  130.             {
  131.                 //当鼠标停留时更改背景色
  132.                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
  133.                 //当鼠标移开时还原背景色
  134.                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
  135.             }
  136.         }
  137.     }
  138.     protected void Button1_Click(object sender, EventArgs e)
  139.     {
  140.         int id=1;
  141.         DateMgr date = new DateMgr();
  142.         time = date.getDate();
  143.         SqlConnection conn = dbConnection.getConnection();
  144.         conn.Open();
  145.         SqlCommand comm = new SqlCommand("select max(id) from oa_pos_type",conn);
  146.         try
  147.         {
  148.             id = Convert.ToInt32(comm.ExecuteScalar()) + 1;
  149.         }
  150.         catch
  151.         {
  152.         }
  153.         SqlCommand sqlcom = new SqlCommand("insert into oa_pos_type(id,department,type,bengin_time,end_time,emp_id,emp_date)values('" + id + "','"
  154.              + Label1.Text + "','请按编辑添加','00:00 ','00:00 ','" + Session["user_id"] + "','" + time + "')", conn);
  155.         sqlcom.ExecuteNonQuery();
  156.         conn.Close();
  157.         bind();
  158.         this.GridView1.EditIndex = GridView1.Rows.Count - 1;
  159.     }
  160. }