protected void btnModPwd_Click(object sender, EventArgs e) { try { QPS.NEW.BLL.Enterprise Buser = new QPS.NEW.BLL.Enterprise(); QPS.NEW.Model.Enterprise Muser = Buser.GetModel(userid); // === modified by jeffery //if (txfOriginalPwd.Value != Buser.GetModel(userid).Password) if (QPS.NEW.BLL.MD5Helper.Encode(txfOriginalPwd.Value) != Muser.Password) // === { Response.Write("<script>alert('原始密码错误,请重新输入')</script>"); return; } if (txfModPwd.Value != txfRepwd.Value) { Response.Write("<script>alert('确认密码与修改密码不一致,请重新输入')</script>"); return; } if (txfModPwd.Value == string.Empty) { Response.Write("<script>alert('确认密码不能为空,请重新输入')</script>"); return; } Muser.Password = txfModPwd.Value; Buser.Update(Muser); Response.Write("<script>alert('密码修改成功! ')</script>"); } catch (Exception ex) { Response.Write("<script>alert('修改失败!')</script>"); } }
public QPS.NEW.Model.Enterprise GetModel(int Id) { QPS.NEW.Model.Enterprise user = null; DataTable dt = sqlHelper_.GetDataTable( "select * from Enterprise where Id=@id", CommandType.Text, new System.Data.SqlClient.SqlParameter[] { new SqlParameter("@id", Id) } ); if (dt != null && dt.Rows.Count > 0) { user = new Model.Enterprise(); user.Id = Convert.ToInt32(dt.Rows[0]["Id"]); user.Username = dt.Rows[0]["Username"].ToString(); user.Password = dt.Rows[0]["Password"].ToString(); user.Nickname = dt.Rows[0]["Nickname"].ToString(); user.Phone = dt.Rows[0]["Phone"].ToString(); user.Address = dt.Rows[0]["Address"].ToString(); user.Mail = dt.Rows[0]["Mail"].ToString(); user.IfChecked = Convert.ToInt32(dt.Rows[0]["IfChecked"]); } return(user); }
public int Add(QPS.NEW.Model.Enterprise model) { int checkUsername = -1; enterprise_ = model; checkUsername = Convert.ToInt32( sqlHelper_.GetSingle("select count(*) from Enterprise where Username=@username", CommandType.Text, new System.Data.SqlClient.SqlParameter[]{ new System.Data.SqlClient.SqlParameter("@username",enterprise_.Username) } ) ); if (checkUsername != 0) { throw new Exception("Error:用户名已经存在"); } else { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Username != null) { filedName[Count] = "Username"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Password"; paramName[Count] = "@" + filedName[Count]; string md5Pwd = MD5Helper.Encode(model.Password); sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd); Count++; } if (model.Nickname != null) { filedName[Count] = "Nickname"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Mail"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } if (model.IfChecked != -999) { filedName[Count] = "IfChecked"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfChecked); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Enterprise("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { throw new Exception("Error:写入数据库失败"); } } return 1; }
public int Add(QPS.NEW.Model.Enterprise model) { int checkUsername = -1; enterprise_ = model; checkUsername = Convert.ToInt32( sqlHelper_.GetSingle("select count(*) from Enterprise where Username=@username", CommandType.Text, new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@username", enterprise_.Username) } ) ); if (checkUsername != 0) { throw new Exception("Error:用户名已经存在"); } else { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Username != null) { filedName[Count] = "Username"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Password"; paramName[Count] = "@" + filedName[Count]; string md5Pwd = MD5Helper.Encode(model.Password); sqlParams[Count] = new SqlParameter(paramName[Count], md5Pwd); Count++; } if (model.Nickname != null) { filedName[Count] = "Nickname"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Mail"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } if (model.IfChecked != -999) { filedName[Count] = "IfChecked"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfChecked); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Enterprise("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { throw new Exception("Error:写入数据库失败"); } } return(1); }
public bool Update(QPS.NEW.Model.Enterprise model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) { return(false); } if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Username != null) { filedName[Count] = "Username"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Username); Count++; } if (model.Password != null) { filedName[Count] = "Password"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Password); Count++; } if (model.Nickname != null) { filedName[Count] = "Nickname"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Nickname); Count++; } if (model.Phone != null) { filedName[Count] = "Phone"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Phone); Count++; } if (model.Address != null) { filedName[Count] = "Address"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Address); Count++; } if (model.Mail != null) { filedName[Count] = "Mail"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Mail); Count++; } if (model.IfChecked != -999) { filedName[Count] = "IfChecked"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.IfChecked); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Enterprise set "); for (int i = 1; i < Count; i++) // i begin with 0 !!! { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return(res); }
protected void Page_Load(object sender, EventArgs e) { QPS.NEW.BLL.Users Buser = new QPS.NEW.BLL.Users(); QPS.NEW.Model.Users Uuser = new QPS.NEW.Model.Users(); QPS.NEW.BLL.Enterprise Euser = new QPS.NEW.BLL.Enterprise(); QPS.NEW.Model.Enterprise Muser = new QPS.NEW.Model.Enterprise(); int result = -1; string userType=Request.QueryString["type"].ToString(); string username = Request.QueryString["username"].ToString(); string address = Request.QueryString["add"].ToString(); string mail = Request.QueryString["mail"].ToString(); string pwd=Request.QueryString["pwd"].ToString(); string phone = Request.QueryString["phone"].ToString(); string nickname = Request.QueryString["nickname"].ToString(); if (userType == "user") { Uuser.Username = username; Uuser.Address = address; Uuser.Mail = mail; Uuser.Password = pwd; Uuser.Phone = phone; Uuser.Nickname = nickname; Uuser.Action = "regist"; Uuser.Sign = "48c93e18ffbe4878b344cc1749ff6dc8"; Uuser.Usertype = 0; result = Buser.Add(Uuser); if (result == 1) { Response.Write("1"); } else if (result == -1) { Response.Write("0"); } else { Response.Write("-1"); } } if (userType == "enterprise") { Muser.Username = username; Muser.Address = address; Muser.Mail = mail; Muser.Password = pwd; Muser.Phone = phone; Muser.Nickname = nickname; Muser.IfChecked = 0; result = Euser.Add(Muser); if (result == 1) { Response.Write("1"); } else if (result == -1) { Response.Write("0"); } else { Response.Write("-1"); } } }
protected void Page_Load(object sender, EventArgs e) { QPS.NEW.BLL.Users Buser = new QPS.NEW.BLL.Users(); QPS.NEW.Model.Users Uuser = new QPS.NEW.Model.Users(); QPS.NEW.BLL.Enterprise Euser = new QPS.NEW.BLL.Enterprise(); QPS.NEW.Model.Enterprise Muser = new QPS.NEW.Model.Enterprise(); int result = -1; string userType = Request.QueryString["type"].ToString(); string username = Request.QueryString["username"].ToString(); string address = Request.QueryString["add"].ToString(); string mail = Request.QueryString["mail"].ToString(); string pwd = Request.QueryString["pwd"].ToString(); string phone = Request.QueryString["phone"].ToString(); string nickname = Request.QueryString["nickname"].ToString(); if (userType == "user") { Uuser.Username = username; Uuser.Address = address; Uuser.Mail = mail; Uuser.Password = pwd; Uuser.Phone = phone; Uuser.Nickname = nickname; Uuser.Action = "regist"; Uuser.Sign = "48c93e18ffbe4878b344cc1749ff6dc8"; Uuser.Usertype = 0; result = Buser.Add(Uuser); if (result == 1) { Response.Write("1"); } else if (result == -1) { Response.Write("0"); } else { Response.Write("-1"); } } if (userType == "enterprise") { Muser.Username = username; Muser.Address = address; Muser.Mail = mail; Muser.Password = pwd; Muser.Phone = phone; Muser.Nickname = nickname; Muser.IfChecked = 0; result = Euser.Add(Muser); if (result == 1) { Response.Write("1"); } else if (result == -1) { Response.Write("0"); } else { Response.Write("-1"); } } }