📄 dutystaffmain.aspx.cs
字号:
using System;
using System.Data;
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 DutyStaffMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
bindDropDown();
bindUser();
}
}
private void bindDropDown()
{
DataSet ds = DepartmentDao.dsDepartment();
this.DropDownList2.DataSource = ds.Tables[0];
this.DropDownList2.DataTextField = ds.Tables[0].Columns[1].ToString();
this.DropDownList2.DataValueField = ds.Tables[0].Columns[0].ToString();
this.DropDownList2.DataBind();
}
private void bindUser()
{
if (StaffDao.dsStaff() == null || (StaffDao.dsStaff()).Tables[0].Rows.Count == 0)
{
this.Label1.Visible = true;
this.GridView1.Visible = false;
}
else
{
this.GridView1.Visible = true;
this.GridView1.DataSource = StaffDao.dsStaff();
this.GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(this.TextBox1.Text))
{
this.Label2.Text = "姓名不能为空!";
}
else if (string.IsNullOrEmpty(this.TextBox2.Text))
{
this.Label2.Text = "编号不能为空!";
}
else
{
this.Label2.Text = "";
StaffPo sp = new StaffPo();
sp.DepartId = int.Parse(this.DropDownList2.SelectedValue.ToString());
sp.UserId = this.TextBox2.Text;
sp.Sex = byte.Parse(this.DropDownList1.SelectedValue);
sp.UserName = this.TextBox1.Text;
StaffDao.insertStaff(sp);
bindUser();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
bindUser();
DropDownList ddl = (DropDownList)this.GridView1.Rows[e.NewEditIndex].FindControl("dl");
ddl.Items.Add(new ListItem("男", "0"));
ddl.Items.Add(new ListItem("女", "1"));
DropDownList ddlt = (DropDownList)this.GridView1.Rows[e.NewEditIndex].FindControl("DropDownList3");
ddlt.DataSource = DepartmentDao.dsDepartment().Tables[0];
ddlt.DataTextField = DepartmentDao.dsDepartment().Tables[0].Columns[1].ToString();
ddlt.DataValueField = DepartmentDao.dsDepartment().Tables[0].Columns[0].ToString();
ddlt.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
this.GridView1.EditIndex = -1;
string userName = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
byte sex = byte.Parse(((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[2].Controls[1]).SelectedValue.ToString());
int departId = int.Parse(((DropDownList)this.GridView1.Rows[e.RowIndex].Cells[3].Controls[1]).SelectedValue.ToString());
string userId = ((TextBox)this.GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
int keyId = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
StaffPo sp = new StaffPo();
sp.UserName = userName;
sp.UserId = userId;
sp.Sex = sex;
sp.DepartId = departId;
StaffDao.updateStaff(sp,keyId);
bindUser();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
bindUser();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int keyId = Int32.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
StaffDao.deleteStaff(keyId);
bindUser();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -