banbie_test.aspx.cs
资源名称:web.rar [点击查看]
上传用户:xrffrp
上传日期:2022-03-25
资源大小:22155k
文件大小:6k
源码类别:
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;
- public partial class web_banbie_test : System.Web.UI.Page
- {
- SqlConnection sqlcon;
- SqlCommand sqlcom;
- string strCon = "Data Source=(local);Database=oa1;Uid=sa;Pwd=lerado";
- string time = "";
- ArrayList array = new ArrayList();
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- DateMgr date = new DateMgr();
- time = date.getDate();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- 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);
- try
- {
- Label1.Text = comm.ExecuteScalar().ToString();
- }
- catch
- {
- }
- bind();
- conn.Close();
- }
- Button1.Visible = true;
- }
- public void bind()
- {
- int id = 1;
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- DataSet ds = new DataSet();
- DataTable dt = new DataTable();
- dt.Columns.Add(new DataColumn("编号", typeof(int)));
- 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("ID", typeof(int)));
- SqlCommand comm = new SqlCommand("select id,type,bengin_time,end_time from oa_pos_type where department='" + Label1.Text + "'order by id", conn);
- SqlDataReader dr = comm.ExecuteReader();
- if (dr.HasRows)
- {
- while (dr.Read())
- {
- DataRow row = dt.NewRow();
- row["编号"] = id;
- row["班别"] = dr["type"].ToString();
- row["开始时间"]=dr["bengin_time"].ToString();
- row["结束时间"] = dr["end_time"].ToString();
- row["ID"] = dr["id"].ToString();
- id = id + 1;
- dt.Rows.Add(row);
- }
- }
- ds.Tables.Add(dt);
- GridView1.DataSource = ds;
- GridView1.DataKeyNames = new string[] { "ID" };
- GridView1.DataBind();
- dr.Close();
- conn.Close();
- }
- protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
- {
- GridView1.EditIndex = e.NewEditIndex;
- bind();
- }
- //删除
- protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
- {
- int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
- string sqlstr = "delete from oa_pos_type where id='" + id + "'and department='" + Label1.Text + "'";
- sqlcon = new SqlConnection(strCon);
- sqlcom = new SqlCommand(sqlstr, sqlcon);
- sqlcon.Open();
- sqlcom.ExecuteNonQuery();
- sqlcon.Close();
- bind();
- }
- //更新
- protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
- {
- try
- {
- DateMgr date = new DateMgr();
- time = date.getDate();
- string str_1=((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString();
- string str_2 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
- string str_3 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
- int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- 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);
- comm.ExecuteNonQuery();
- conn.Close();
- GridView1.EditIndex = -1;
- bind();
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- }
- }
- //取消
- protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
- {
- GridView1.EditIndex = -1;
- bind();
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {
- int i;
- //执行循环,保证每条数据都可以更新
- for (i = -1; i < GridView1.Rows.Count; i++)
- {
- //首先判断是否是数据行
- if (e.Row.RowType == DataControlRowType.DataRow)
- {
- //当鼠标停留时更改背景色
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
- //当鼠标移开时还原背景色
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
- }
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- int id=1;
- DateMgr date = new DateMgr();
- time = date.getDate();
- SqlConnection conn = dbConnection.getConnection();
- conn.Open();
- SqlCommand comm = new SqlCommand("select max(id) from oa_pos_type",conn);
- try
- {
- id = Convert.ToInt32(comm.ExecuteScalar()) + 1;
- }
- catch
- {
- }
- SqlCommand sqlcom = new SqlCommand("insert into oa_pos_type(id,department,type,bengin_time,end_time,emp_id,emp_date)values('" + id + "','"
- + Label1.Text + "','请按编辑添加','00:00 ','00:00 ','" + Session["user_id"] + "','" + time + "')", conn);
- sqlcom.ExecuteNonQuery();
- conn.Close();
- bind();
- this.GridView1.EditIndex = GridView1.Rows.Count - 1;
- }
- }