/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbUserName.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "", "用户名不能为空!"); tbUserName.Focus(); return; } else if (string.IsNullOrEmpty(tbRealName.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "", "真实姓名不能为空!"); tbRealName.Focus(); return; } else if (string.IsNullOrEmpty(tbPassword.Text.Trim())) { Common.JShelper.JSAlert(this.Page, "", "密码不能为空!"); tbPassword.Focus(); return; } else { if (!EBut.IsExistUserName(tbUserName.Text.Trim()))//用户名已经存在,不能注册 { Common.JShelper.JSAlert(this.Page, "", "用户名已经存在!"); tbUserName.Text = ""; tbUserName.Focus(); return; } else { //往用户表里添加信息 LabMS.Model.UserTable Mut = new LabMS.Model.UserTable(); DataSet ds = new DataSet(); Mut.CreateTime = DateTime.Now; Mut.UserName = tbUserName.Text.Trim(); Mut.Password = tbPassword.Text.Trim(); Mut.PCode = tb.Text.Trim(); ds = EBut.GetTeacherByPCode(tb.Text.Trim()); //Mut.Email = ds.Tables[0].Rows[0]["Email"].ToString(); //Mut.Tel = ds.Tables[0].Rows[0]["Tel"].ToString(); if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["Staff_Birth"].ToString())) { DateTime d1 = DateTime.Parse(ds.Tables[0].Rows[0]["Staff_Birth"].ToString()); DateTime d2 = DateTime.Now; Mut.Age = d2.Year - d1.Year; } Mut.SexCode = ds.Tables[0].Rows[0]["Staff_Sex"].ToString(); LabMS.BLL.UserTable But = new LabMS.BLL.UserTable(); hiddenAddUserID.Value=But.Add(Mut).ToString(); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('新增用户成功!');window.location.href='UserDefault.aspx';</script>"); AddRole.Visible = true;//显示“添加角色按钮” PanRole.Visible = true; } } }
//��ȡStaffID protected int GetStaffIDCodeByUserID(int ID) { LabMS.BLL.UserTable usertable = new LabMS.BLL.UserTable(); LabMS.Model.UserTable usertableModel = new LabMS.Model.UserTable(); LabMS.BLL.Staff staff = new LabMS.BLL.Staff(); List<LabMS.Model.Staff> staffModelList = new List<LabMS.Model.Staff>(); usertableModel = usertable.GetModel(ID); staffModelList = staff.GetModelList("Staff_Code='" + usertableModel.PCode + "'"); if (staffModelList.Count > 0) { return staffModelList[0].ID; } else return 0; }
/* /// <summary> /// ��ҳ��ȡ�����б� /// </summary> public DataSet GetList(int PageSize,int PageIndex,string strWhere) { SqlParameter[] parameters = { new SqlParameter("@tblName", SqlDbType.VarChar, 255), new SqlParameter("@fldName", SqlDbType.VarChar, 255), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@IsReCount", SqlDbType.Bit), new SqlParameter("@OrderType", SqlDbType.Bit), new SqlParameter("@strWhere", SqlDbType.VarChar,1000), }; parameters[0].Value = "UserTable"; parameters[1].Value = "ID"; parameters[2].Value = PageSize; parameters[3].Value = PageIndex; parameters[4].Value = 0; parameters[5].Value = 0; parameters[6].Value = strWhere; return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); }*/ /// <summary> /// ��¼��֤ /// </summary> /// <param name="strPeople"></param> /// <param name="strPass"></param> /// <returns></returns> public override object ValidatePeople(string strPeople, string strPass) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from UserTable"); strSql.Append(" where UserName=@UserName and Password=@Password "); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.VarChar,50), new SqlParameter("@Password", SqlDbType.VarChar,50)}; parameters[0].Value = strPeople; parameters[1].Value = strPass; DataSet ds = new DataSet(); try { ds = DbHelperSQL.Query(strSql.ToString(), parameters); } catch { throw (new Exception("���ݿ���ʴ���!")); } LabMS.Model.UserTable model = new LabMS.Model.UserTable(); try { if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["UserId"].ToString() != "") { model.UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } model.Password = ds.Tables[0].Rows[0]["Password"].ToString(); model.PCode = ds.Tables[0].Rows[0]["PCode"].ToString(); if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } if (ds.Tables[0].Rows[0]["Age"].ToString() != "") { model.Age = int.Parse(ds.Tables[0].Rows[0]["Age"].ToString()); } model.SexCode = ds.Tables[0].Rows[0]["SexCode"].ToString(); model.Email = ds.Tables[0].Rows[0]["Email"].ToString(); model.Tel = ds.Tables[0].Rows[0]["Tel"].ToString(); model.UserName = ds.Tables[0].Rows[0]["UserName"].ToString(); return model; } else { return null; } } catch { throw (new Exception("datasetTOobjectת������!")); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LabMS.Model.UserTable GetModel(int UserId) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 UserId,Password,PCode,CreateTime,Age,SexCode,Email,Tel,UserName from UserTable "); strSql.Append(" where UserId=@UserId "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int,4)}; parameters[0].Value = UserId; LabMS.Model.UserTable model=new LabMS.Model.UserTable(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["UserId"].ToString()!="") { model.UserId=int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); } model.Password=ds.Tables[0].Rows[0]["Password"].ToString(); model.PCode=ds.Tables[0].Rows[0]["PCode"].ToString(); if(ds.Tables[0].Rows[0]["CreateTime"].ToString()!="") { model.CreateTime=DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } if(ds.Tables[0].Rows[0]["Age"].ToString()!="") { model.Age=int.Parse(ds.Tables[0].Rows[0]["Age"].ToString()); } model.SexCode=ds.Tables[0].Rows[0]["SexCode"].ToString(); model.Email=ds.Tables[0].Rows[0]["Email"].ToString(); model.Tel=ds.Tables[0].Rows[0]["Tel"].ToString(); model.UserName=ds.Tables[0].Rows[0]["UserName"].ToString(); return model; } else { return null; } }
protected void Save_OnClick(object sender, EventArgs e) { #region if (String.IsNullOrEmpty(UserPasswordTBX.Text.Trim())) { Common.JShelper.JSAlert(Page, "script", "请输入旧密码!"); return; } if (UserPasswordTBX.Text.Length > 50) { Common.JShelper.JSAlert(Page, "script", "旧密码长度输入过长!"); return; } if (String.IsNullOrEmpty(NewPasswordTBX.Text.Trim())) { Common.JShelper.JSAlert(Page, "script", "请输入新密码密码!"); return; } if (NewPasswordTBX.Text.Length > 50) { Common.JShelper.JSAlert(Page, "script", "新密码长度输入过长!"); return; } if (!Regex.IsMatch(NewPasswordTBX.Text.Trim(), @"^\w+$")) { Common.JShelper.JSAlert(Page, "script", "新密码输入不合法(只能为数字、英文或下划线的组合)!"); return; } //if (String.IsNullOrEmpty(RePasswordTBX.Text.Trim())) //{ // Common.JShelper.JSAlert(Page, "script", "请重复输入新密码!"); //} //if (RePasswordTBX.Text.Length > 50) //{ // Common.JShelper.JSAlert(Page, "script", "重复新密码长度输入过长!"); //} //if (!Regex.IsMatch(RePasswordTBX.Text.Trim(), @"^\w+$")) //{ // Common.JShelper.JSAlert(Page, "script", "重复新密码输入不合法(只能为数字、英文或下划线的组合)!"); //} if (String.Compare(RePasswordTBX.Text, NewPasswordTBX.Text) != 0) { Common.JShelper.JSAlert(Page, "script", "两次新密码输入不一致!"); return; } //验证用户名和密码输入是否正确 if (!IsUserNameAndPassword()) { Common.JShelper.JSAlert(Page, "script", "用户名和密码输入不匹配!"); return; } #endregion if (!String.IsNullOrEmpty(UserID)) { int ID; if (int.TryParse(UserID, out ID)) { if (UserType == "mana") { LabMS.BLL.UserTable userTable = new LabMS.BLL.UserTable(); LabMS.Model.UserTable userTableModel = new LabMS.Model.UserTable(); userTableModel = userTable.GetModel(ID); userTableModel.Password = NewPasswordTBX.Text.Trim(); try { userTable.Update(userTableModel); Common.JShelper.JsAlertAndClose(Page, "script", "密码修改成功!"); } catch { Common.JShelper.JsAlertAndClose(Page, "script", "密码修改失败!"); } } else if (UserType == "teacher") { LabMS.BLL.Teacher userTable = new LabMS.BLL.Teacher(); LabMS.Model.Teacher userTableModel = new LabMS.Model.Teacher(); userTableModel = userTable.GetModel(ID); userTableModel.Password = NewPasswordTBX.Text.Trim(); try { userTable.Update(userTableModel); Common.JShelper.JsAlertAndClose(Page, "script", "密码修改成功!"); } catch { Common.JShelper.JsAlertAndClose(Page, "script", "密码修改失败!"); } } else { LabMS.BLL.Student userTable = new LabMS.BLL.Student(); LabMS.Model.Student userTableModel = new LabMS.Model.Student(); userTableModel = userTable.GetModel(ID); userTableModel.Student_Pass = NewPasswordTBX.Text.Trim(); try { userTable.Update(userTableModel); Common.JShelper.JsAlertAndClose(Page, "script", "密码修改成功!"); } catch { Common.JShelper.JsAlertAndClose(Page, "script", "密码修改失败!"); } } } else { Common.JShelper.JsAlertAndClose(Page, "script", "用户ID存储不合法,请退出系统,重新登录后进行修改密码!"); } } else { Common.JShelper.JsAlertAndClose(Page, "script", "用户Session丢失,请退出系统,重新登录后进行修改密码!"); } }