protected void Modify_Click(object sender, EventArgs e) { EmployeeModel employee = new EmployeeModel(); employee.ID = int.Parse(Request.QueryString["ID"]); employee.EmlpoyeeName = txtName.Text.Trim(); employee.Arrage = txtArrage.Text.Trim(); employee.Address = txtAddress.Text.Trim(); employee.Tel = txtTel.Text.Trim(); employee.Mobile = txtMobile.Text.Trim(); if (path == "") { employee.PhotoPath = @"~\Admin\UserHeadImages\Default.jpg"; } else { employee.PhotoPath = path; } bool flag = bll.UpdateEmployee(employee); if (flag) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('修改成功');location.href='EmployeeInfo.aspx';</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('修改失败');</script>"); } }
public int InsertEmployee(EmployeeModel employee, UserModel user) { SqlParameter[] param = { new SqlParameter("@Name", SqlDbType.VarChar, 20), new SqlParameter("@Sex", SqlDbType.SmallInt), new SqlParameter("@Arrage",SqlDbType.VarChar,20),new SqlParameter("@Address",SqlDbType.VarChar,30), new SqlParameter("@Tel",SqlDbType.VarChar,12),new SqlParameter("@Mobile",SqlDbType.VarChar,12), new SqlParameter("@CardID",SqlDbType.VarChar,18),new SqlParameter("@PhotoPath",SqlDbType.VarChar,255) }; param[0].Value = employee.EmlpoyeeName; param[1].Value = employee.Sex; param[2].Value = employee.Arrage; param[3].Value = employee.Address; param[4].Value = employee.Tel; param[5].Value = employee.Mobile; param[6].Value = employee.CardID; param[7].Value = employee.PhotoPath; SqlParameter[] param1 = { new SqlParameter("@UID", SqlDbType.VarChar, 20), new SqlParameter("@Password", SqlDbType.VarChar,20), new SqlParameter("@UserType",SqlDbType.SmallInt),new SqlParameter("@SubID",SqlDbType.Int) }; param1[0].Value = user.UID; param1[1].Value = user.Password; param1[2].Value = user.UserType; param1[3].Value = user.SubID; string[] commandText = { "prc_InsertEmployee", "prc_InsertUser" }; SqlParameter[][] paramArray = { param, param1 }; int result = SqlHelp.ExecuteNonQueryTransaction(commandText, CommandType.StoredProcedure, paramArray); return result; }
protected void Page_Load(object sender, EventArgs e) { user = (UserModel)Session["User"]; if (Session["User"] == null || Session["User"].ToString() == "" || user.UserType != 1) Response.Redirect("../Login.aspx"); else { if (!IsPostBack) { int id = int.Parse(Request.QueryString["ID"]); EmployeeModel employee = new EmployeeModel(); employee = bll.GetEmployeeByID(id); txtName.Text = employee.EmlpoyeeName; if (employee.Sex == 0) lbSex.Text = "男"; else lbSex.Text = "女"; lbID.Text = employee.CardID; txtArrage.Text = employee.Arrage; txtTel.Text = employee.Tel; txtMobile.Text = employee.Mobile; txtAddress.Text = employee.Address; path = employee.PhotoPath; Photo.ImageUrl = path; } } }
protected void Add_Click(object sender, EventArgs e) { EmployeeBLL bll = new EmployeeBLL(); EmployeeModel employee = new EmployeeModel(); UserModel addUser = new UserModel(); UsersBLL userbll = new UsersBLL(); employee.EmlpoyeeName = txtName.Text.Trim(); employee.Sex=Convert.ToInt32(RBLSex.SelectedValue); employee.Arrage = txtArrage.Text.Trim(); employee.Address = txtAddress.Text.Trim(); employee.Tel = txtTel.Text.Trim(); employee.Mobile = txtMobile.Text.Trim(); employee.CardID = txtID.Text.Trim(); if (path == "") { employee.PhotoPath = @"~\Admin\UserHeadImages\Default.jpg"; } else { employee.PhotoPath = path; } if (txtUID.Text.Trim() == "") { addUser.UID = txtID.Text.Trim(); } else { addUser.UID = txtUID.Text.Trim(); } if (txtPassword.Text.Trim() == "") { addUser.Password = txtID.Text.Trim(); } else { addUser.Password = txtPassword.Text.Trim(); } addUser.UserType = 1; addUser.SubID = bll.GetMaxID() + 1; if (userbll.CheckUserByUID(addUser.UID)) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('用户名已存在!');</script>"); return; } else { bool flag = bll.InsertEmployee(employee, addUser); if (flag) { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加成功');location.href='EmployeeInfo.aspx';</script>"); } else { Page.ClientScript.RegisterStartupScript(GetType(), "OnSubmit", "<script>alert('添加失败');</script>"); } } }
public bool InsertEmployee(EmployeeModel employee, UserModel user) { int result; try { result = dal.InsertEmployee(employee, user); } catch { return false; } return result == 0 ? false : true; }
public List<EmployeeModel> ShowEmployee() { SqlDataReader dr= SqlHelp.ExecuteReader("prc_ShowEmployee", CommandType.StoredProcedure); List<EmployeeModel> list = new List<EmployeeModel>(); while (dr.Read()) { EmployeeModel employee = new EmployeeModel(); employee.EmlpoyeeName = dr[0].ToString(); employee.Sex = Convert.ToInt32(dr[1]); employee.Arrage = dr[2].ToString(); employee.Tel = dr[3].ToString(); employee.PhotoPath = dr[4].ToString(); list.Add(employee); } dr.Close(); return list; }
public EmployeeModel GetEmployeeByID(int id) { SqlParameter param = new SqlParameter("@ID", SqlDbType.Int); param.Value = id; SqlDataReader dr = SqlHelp.ExecuteReader("prc_GetEmployeeByID", CommandType.StoredProcedure,param); dr.Read(); EmployeeModel employee = new EmployeeModel(); if(dr.HasRows) { employee.EmlpoyeeName = dr[0].ToString(); employee.Sex = Convert.ToInt32(dr[1]); employee.Arrage = dr[2].ToString(); employee.Tel = dr[3].ToString(); employee.Mobile = dr[4].ToString(); employee.PhotoPath = dr[5].ToString(); employee.ID = Convert.ToInt32(dr[6]); employee.Address = dr[7].ToString(); employee.CardID = dr[8].ToString(); } dr.Close(); return employee; }
public int UpdateEmployee(EmployeeModel employee) { SqlParameter[] param = { new SqlParameter("@Name", SqlDbType.VarChar, 20), new SqlParameter("@ID", SqlDbType.Int), new SqlParameter("@Arrage",SqlDbType.VarChar,20),new SqlParameter("@Address",SqlDbType.VarChar,30), new SqlParameter("@Tel",SqlDbType.VarChar,12),new SqlParameter("@Mobile",SqlDbType.VarChar,12), new SqlParameter("@PhotoPath",SqlDbType.VarChar,255) }; param[0].Value = employee.EmlpoyeeName; param[1].Value = employee.ID; param[2].Value = employee.Arrage; param[3].Value = employee.Address; param[4].Value = employee.Tel; param[5].Value = employee.Mobile; param[6].Value = employee.PhotoPath; int result = SqlHelp.ExecuteNonQuery("prc_UpdateEmployee", CommandType.StoredProcedure, param); return result; }
public bool UpdateEmployee(EmployeeModel employee) { int result = dal.UpdateEmployee(employee); return result == 0 ? false : true; }