/// <summary> /// 增加一条数据 /// </summary> public int Add(ZhangWei.Model.Employee model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Employee("); strSql.Append("UserName,PassWord,Dept_ID,Name,Duty,Gender,BirthDate,HireDate,MatureDate,IdentityCard,Address,Phone,Email)"); strSql.Append(" values ("); strSql.Append("@UserName,@PassWord,@Dept_ID,@Name,@Duty,@Gender,@BirthDate,@HireDate,@MatureDate,@IdentityCard,@Address,@Phone,@Email)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.NVarChar, 50), new SqlParameter("@PassWord", SqlDbType.NVarChar, 50), new SqlParameter("@Dept_ID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 30), new SqlParameter("@Duty", SqlDbType.VarChar, 20), new SqlParameter("@Gender", SqlDbType.VarChar, 6), new SqlParameter("@BirthDate", SqlDbType.DateTime), new SqlParameter("@HireDate", SqlDbType.DateTime), new SqlParameter("@MatureDate", SqlDbType.DateTime), new SqlParameter("@IdentityCard", SqlDbType.VarChar, 20), new SqlParameter("@Address", SqlDbType.VarChar, 250), new SqlParameter("@Phone", SqlDbType.VarChar, 25), new SqlParameter("@Email", SqlDbType.VarChar, 30) }; parameters[0].Value = model.UserName; parameters[1].Value = model.PassWord; parameters[2].Value = model.Dept_ID; parameters[3].Value = model.Name; parameters[4].Value = model.Duty; parameters[5].Value = model.Gender; parameters[6].Value = model.BirthDate; parameters[7].Value = model.HireDate; parameters[8].Value = model.MatureDate; parameters[9].Value = model.IdentityCard; parameters[10].Value = model.Address; parameters[11].Value = model.Phone; parameters[12].Value = model.Email; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
private void ShowInfo(int Employee_ID) { ZhangWei.BLL.Employee bll = new ZhangWei.BLL.Employee(); ZhangWei.Model.Employee model = bll.GetModel(Employee_ID); this.lblEmployee_ID.Text = model.Employee_ID.ToString(); this.txtDept_ID.Text = model.Dept_ID.ToString(); this.txtName.Text = model.Name; this.txtDuty.Text = model.Duty; this.txtGender.Text = model.Gender; this.txtBirthDate.Text = model.BirthDate.ToString(); this.txtHireDate.Text = model.HireDate.ToString(); this.txtMatureDate.Text = model.MatureDate.ToString(); this.txtIdentityCard.Text = model.IdentityCard; this.txtAddress.Text = model.Address; this.txtPhone.Text = model.Phone; this.txtEmail.Text = model.Email; }
/// <summary> /// 验证个人用户信息 /// </summary> /// <param name="userName">用户名</param> /// <param name="userPwd">用户密码</param> private void ChecPersonalkUser(string userName, string userPwd) { //ZhangWei.BLL.Employee bll = new ZhangWei.BLL.Employee(); //ZhangWei.Model.Employee model = new ZhangWei.Model.Employee(); ZhangWei.Model.Employee user = new ZhangWei.BLL.Employee().GetModelByUN(userName); if (user == null) { Response.Write("<script>top.location.href=\"/login.aspx\"</script>"); } else { if (user.PassWord == userPwd) { UserModel = user; } else { Response.Write("<script>top.location.href=\"/login.aspx\"</script>"); } } }
/// <summary> /// 得到一个对象实体,根据用户名 /// </summary> public ZhangWei.Model.Employee GetModelByUN(string UserName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Employee_ID,UserName,PassWord,Dept_ID,Name,Duty,Gender,BirthDate,HireDate,MatureDate,IdentityCard,Address,Phone,Email from Employee "); strSql.Append(" where UserName=@UserName"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar, 50) }; parameters[0].Value = UserName; ZhangWei.Model.Employee model = new ZhangWei.Model.Employee(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Employee_ID"] != null && ds.Tables[0].Rows[0]["Employee_ID"].ToString() != "") { model.Employee_ID = int.Parse(ds.Tables[0].Rows[0]["Employee_ID"].ToString()); } if (ds.Tables[0].Rows[0]["UserName"] != null && ds.Tables[0].Rows[0]["UserName"].ToString() != "") { model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString(); } if (ds.Tables[0].Rows[0]["PassWord"] != null && ds.Tables[0].Rows[0]["PassWord"].ToString() != "") { model.PassWord = ds.Tables[0].Rows[0]["PassWord"].ToString(); } if (ds.Tables[0].Rows[0]["Dept_ID"] != null && ds.Tables[0].Rows[0]["Dept_ID"].ToString() != "") { model.Dept_ID = int.Parse(ds.Tables[0].Rows[0]["Dept_ID"].ToString()); } if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "") { model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); } if (ds.Tables[0].Rows[0]["Duty"] != null && ds.Tables[0].Rows[0]["Duty"].ToString() != "") { model.Duty = ds.Tables[0].Rows[0]["Duty"].ToString(); } if (ds.Tables[0].Rows[0]["Gender"] != null && ds.Tables[0].Rows[0]["Gender"].ToString() != "") { model.Gender = ds.Tables[0].Rows[0]["Gender"].ToString(); } if (ds.Tables[0].Rows[0]["BirthDate"] != null && ds.Tables[0].Rows[0]["BirthDate"].ToString() != "") { model.BirthDate = DateTime.Parse(ds.Tables[0].Rows[0]["BirthDate"].ToString()); } if (ds.Tables[0].Rows[0]["HireDate"] != null && ds.Tables[0].Rows[0]["HireDate"].ToString() != "") { model.HireDate = DateTime.Parse(ds.Tables[0].Rows[0]["HireDate"].ToString()); } if (ds.Tables[0].Rows[0]["MatureDate"] != null && ds.Tables[0].Rows[0]["MatureDate"].ToString() != "") { model.MatureDate = DateTime.Parse(ds.Tables[0].Rows[0]["MatureDate"].ToString()); } if (ds.Tables[0].Rows[0]["IdentityCard"] != null && ds.Tables[0].Rows[0]["IdentityCard"].ToString() != "") { model.IdentityCard = ds.Tables[0].Rows[0]["IdentityCard"].ToString(); } if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"].ToString() != "") { model.Address = ds.Tables[0].Rows[0]["Address"].ToString(); } if (ds.Tables[0].Rows[0]["Phone"] != null && ds.Tables[0].Rows[0]["Phone"].ToString() != "") { model.Phone = ds.Tables[0].Rows[0]["Phone"].ToString(); } if (ds.Tables[0].Rows[0]["Email"] != null && ds.Tables[0].Rows[0]["Email"].ToString() != "") { model.Email = ds.Tables[0].Rows[0]["Email"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ZhangWei.Model.Employee model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Employee set "); strSql.Append("UserName=@UserName,"); strSql.Append("PassWord=@PassWord,"); strSql.Append("Dept_ID=@Dept_ID,"); strSql.Append("Name=@Name,"); strSql.Append("Duty=@Duty,"); strSql.Append("Gender=@Gender,"); strSql.Append("BirthDate=@BirthDate,"); strSql.Append("HireDate=@HireDate,"); strSql.Append("MatureDate=@MatureDate,"); strSql.Append("IdentityCard=@IdentityCard,"); strSql.Append("Address=@Address,"); strSql.Append("Phone=@Phone,"); strSql.Append("Email=@Email"); strSql.Append(" where Employee_ID=@Employee_ID"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.NVarChar, 50), new SqlParameter("@PassWord", SqlDbType.NVarChar, 50), new SqlParameter("@Dept_ID", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.VarChar, 30), new SqlParameter("@Duty", SqlDbType.VarChar, 20), new SqlParameter("@Gender", SqlDbType.VarChar, 6), new SqlParameter("@BirthDate", SqlDbType.DateTime), new SqlParameter("@HireDate", SqlDbType.DateTime), new SqlParameter("@MatureDate", SqlDbType.DateTime), new SqlParameter("@IdentityCard", SqlDbType.VarChar, 20), new SqlParameter("@Address", SqlDbType.VarChar, 250), new SqlParameter("@Phone", SqlDbType.VarChar, 25), new SqlParameter("@Email", SqlDbType.VarChar, 30), new SqlParameter("@Employee_ID", SqlDbType.Int, 4) }; parameters[0].Value = model.UserName; parameters[1].Value = model.PassWord; parameters[2].Value = model.Dept_ID; parameters[3].Value = model.Name; parameters[4].Value = model.Duty; parameters[5].Value = model.Gender; parameters[6].Value = model.BirthDate; parameters[7].Value = model.HireDate; parameters[8].Value = model.MatureDate; parameters[9].Value = model.IdentityCard; parameters[10].Value = model.Address; parameters[11].Value = model.Phone; parameters[12].Value = model.Email; parameters[13].Value = model.Employee_ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; //if(!PageValidate.IsNumber(txtDept_ID.Text)) //{ // strErr+="Dept_ID格式错误!\\n"; //} if (this.txtName.Text.Trim().Length == 0) { strErr += "Name不能为空!\\n"; } if (this.txtDuty.Text.Trim().Length == 0) { strErr += "Duty不能为空!\\n"; } //if(this.txtGender.Text.Trim().Length==0) //{ // strErr+="Gender不能为空!\\n"; //} if (!PageValidate.IsDateTime(txtBirthDate.Text)) { strErr += "BirthDate格式错误!\\n"; } if (!PageValidate.IsDateTime(txtHireDate.Text)) { strErr += "HireDate格式错误!\\n"; } if (!PageValidate.IsDateTime(txtMatureDate.Text)) { strErr += "MatureDate格式错误!\\n"; } if (this.txtIdentityCard.Text.Trim().Length == 0) { strErr += "IdentityCard不能为空!\\n"; } if (this.txtAddress.Text.Trim().Length == 0) { strErr += "Address不能为空!\\n"; } if (this.txtPhone.Text.Trim().Length == 0) { strErr += "Phone不能为空!\\n"; } if (this.txtEmail.Text.Trim().Length == 0) { strErr += "Email不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Dept_ID = int.Parse(this.DropDownList1.SelectedValue); string Name = this.txtName.Text; string Duty = this.txtDuty.Text; string Gender = this.RadioButtonList1.SelectedValue; DateTime BirthDate = DateTime.Parse(this.txtBirthDate.Text); DateTime HireDate = DateTime.Parse(this.txtHireDate.Text); DateTime MatureDate = DateTime.Parse(this.txtMatureDate.Text); string IdentityCard = this.txtIdentityCard.Text; string Address = this.txtAddress.Text; string Phone = this.txtPhone.Text; string Email = this.txtEmail.Text; ZhangWei.Model.Employee model = new ZhangWei.Model.Employee(); model.Dept_ID = Dept_ID; model.Name = Name; model.Duty = Duty; model.Gender = Gender; model.BirthDate = BirthDate; model.HireDate = HireDate; model.MatureDate = MatureDate; model.IdentityCard = IdentityCard; model.Address = Address; model.Phone = Phone; model.Email = Email; ZhangWei.BLL.Employee bll = new ZhangWei.BLL.Employee(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }