public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtLoginPwd.Text.Trim().Length == 0) { strErr += "LoginPwd不能为空!\\n"; } if (this.txtName.Text.Trim().Length == 0) { strErr += "Name不能为空!\\n"; } if (this.txtAddress.Text.Trim().Length == 0) { strErr += "Address不能为空!\\n"; } if (this.txtPhone.Text.Trim().Length == 0) { strErr += "Phone不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Id = int.Parse(this.lblId.Text); string LoginId = this.lblLoginId.Text; string LoginPwd = this.txtLoginPwd.Text; string Name = this.txtName.Text; string Address = this.txtAddress.Text; string Phone = this.txtPhone.Text; string Mail = this.lblMail.Text; int UserRoleId = int.Parse(this.ddlUserRole.SelectedValue); int UserStateId = int.Parse(this.ddlUserState.SelectedValue); OLBookstore.Model.Users model = new OLBookstore.Model.Users(); model.Id = Id; model.LoginId = LoginId; model.LoginPwd = LoginPwd; model.Name = Name; model.Address = Address; model.Phone = Phone; model.Mail = Mail; model.UserRoleId = UserRoleId; model.UserStateId = UserStateId; OLBookstore.BLL.UsersManager bll = new OLBookstore.BLL.UsersManager(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int Id) { OLBookstore.BLL.UsersManager bll = new OLBookstore.BLL.UsersManager(); OLBookstore.Model.Users model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.lblLoginId.Text = model.LoginId; this.lblLoginPwd.Text = model.LoginPwd; this.lblName.Text = model.Name; this.lblAddress.Text = model.Address; this.lblPhone.Text = model.Phone; this.lblMail.Text = model.Mail; this.lblUserRoleId.Text = model.UserRoleId.ToString(); this.lblUserStateId.Text = model.UserStateId.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(OLBookstore.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Users set "); strSql.Append("LoginPwd=@LoginPwd,"); strSql.Append("Name=@Name,"); strSql.Append("Address=@Address,"); strSql.Append("Phone=@Phone,"); strSql.Append("UserRoleId=@UserRoleId,"); strSql.Append("UserStateId=@UserStateId, "); strSql.Append("Mail=@Mail"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@LoginPwd", SqlDbType.NVarChar, 50), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Address", SqlDbType.NVarChar, 200), new SqlParameter("@Phone", SqlDbType.NVarChar, 100), new SqlParameter("@UserRoleId", SqlDbType.Int, 4), new SqlParameter("@UserStateId", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@LoginId", SqlDbType.NVarChar, 50), new SqlParameter("@Mail", SqlDbType.NVarChar, 100) }; parameters[0].Value = model.LoginPwd; parameters[1].Value = model.Name; parameters[2].Value = model.Address; parameters[3].Value = model.Phone; parameters[4].Value = model.UserRoleId; parameters[5].Value = model.UserStateId; parameters[6].Value = model.Id; parameters[7].Value = model.LoginId; parameters[8].Value = model.Mail; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public OLBookstore.Model.Users DataRowToModel(DataRow row) { OLBookstore.Model.Users model = new OLBookstore.Model.Users(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["LoginId"] != null) { model.LoginId = row["LoginId"].ToString(); } if (row["LoginPwd"] != null) { model.LoginPwd = row["LoginPwd"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Address"] != null) { model.Address = row["Address"].ToString(); } if (row["Phone"] != null) { model.Phone = row["Phone"].ToString(); } if (row["Mail"] != null) { model.Mail = row["Mail"].ToString(); } if (row["UserRoleId"] != null && row["UserRoleId"].ToString() != "") { model.UserRoleId = int.Parse(row["UserRoleId"].ToString()); } if (row["UserStateId"] != null && row["UserStateId"].ToString() != "") { model.UserStateId = int.Parse(row["UserStateId"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(OLBookstore.Model.Users model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Users("); strSql.Append("LoginId,LoginPwd,Name,Address,Phone,Mail,UserRoleId,UserStateId)"); strSql.Append(" values ("); strSql.Append("@LoginId,@LoginPwd,@Name,@Address,@Phone,@Mail,@UserRoleId,@UserStateId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@LoginId", SqlDbType.NVarChar, 50), new SqlParameter("@LoginPwd", SqlDbType.NVarChar, 50), new SqlParameter("@Name", SqlDbType.NVarChar, 50), new SqlParameter("@Address", SqlDbType.NVarChar, 200), new SqlParameter("@Phone", SqlDbType.NVarChar, 100), new SqlParameter("@Mail", SqlDbType.NVarChar, 100), new SqlParameter("@UserRoleId", SqlDbType.Int, 4), new SqlParameter("@UserStateId", SqlDbType.Int, 4) }; parameters[0].Value = model.LoginId; parameters[1].Value = model.LoginPwd; parameters[2].Value = model.Name; parameters[3].Value = model.Address; parameters[4].Value = model.Phone; parameters[5].Value = model.Mail; parameters[6].Value = model.UserRoleId; parameters[7].Value = model.UserStateId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
public OLBookstore.Model.Users GetModel(string loginid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,LoginId,LoginPwd,Name,Address,Phone,Mail,UserRoleId,UserStateId from Users "); strSql.Append(" where LoginId=@LoginId"); SqlParameter[] parameters = { new SqlParameter("@LoginId", SqlDbType.NVarChar, 20) }; parameters[0].Value = loginid; OLBookstore.Model.Users model = new OLBookstore.Model.Users(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtLoginId.Text.Trim().Length == 0) { strErr += "登录名不能为空!\\n"; } if (this.txtLoginPwd.Text.Trim().Length == 0) { strErr += "登录密码不能为空!\\n"; } if (this.txtName.Text.Trim().Length == 0) { strErr += "真实姓名不能为空!\\n"; } if (this.txtAddress.Text.Trim().Length == 0) { strErr += "地址不能为空!\\n"; } if (this.txtPhone.Text.Trim().Length == 0) { strErr += "联系方式不能为空!\\n"; } if (this.txtMail.Text.Trim().Length == 0) { strErr += "电子邮箱不能为空!\\n"; } if (ddlUserRole.SelectedValue == "0") { strErr += "用户角色不能为空!\\n"; } if (ddlUserState.SelectedValue == "0") { strErr += "用户状态不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } if (!AuthCode1.IsMatch) { MessageBox.Show(this, "验证码有误,请重新输入。"); return; } string LoginId = this.txtLoginId.Text; string LoginPwd = this.txtLoginPwd.Text; string Name = this.txtName.Text; string Address = this.txtAddress.Text; string Phone = this.txtPhone.Text; string Mail = this.txtMail.Text; int UserRoleId = int.Parse(ddlUserRole.SelectedValue); int UserStateId = int.Parse(ddlUserState.SelectedValue); OLBookstore.Model.Users model = new OLBookstore.Model.Users(); model.LoginId = LoginId; model.LoginPwd = LoginPwd; model.Name = Name; model.Address = Address; model.Phone = Phone; model.Mail = Mail; model.UserRoleId = UserRoleId; model.UserStateId = UserStateId; OLBookstore.BLL.UsersManager bll = new OLBookstore.BLL.UsersManager(); bll.Add(model); MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }