public static Model.Login ConvertToModel(User user) { Model.Login login = new Model.Login(); try { login.Email = user.email; login.Password = user.password; login.CurrentAddress = user.currentAddress; login.CurrentCity = user.currentCity; login.CurrentCountryId = user.currentCountryId; login.CurrentStateId = user.currentStateId; login.DateOfBirth = user.dateOfBirth; login.FirstName = user.firstName; login.GenderId = user.genderId; login.gender = user.genderId == 1 ? "Male" : "Female"; login.LastName = user.lastName; login.PermanentAddress = user.permanentAddress; login.PermanentCity = user.permanentCity; login.PermanentCountryId = user.permanentCountryId; login.CurrentState = user.State.name; login.CurrentCountry = user.Country1.name; login.PermanentCountry = user.Country.name; login.ImageArray = user.image; return(login); } catch (Exception ex) { return(null); } }
//登录事件 private void btnLogin_Click(object sender, EventArgs e) { Model.Login lg = new Model.Login(); lg.Username = tbUsername.Text.Trim(); lg.Password = tbPassword.Text.Trim(); //实例化BLL(业务层)类库的Login类并传入参数 string a = BLL.LoginBLL.sysLogin(lg); //获取用户名 SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, "select * from View_Admin where 学号工号='" + lg.Username + "' and 密码='" + lg.Password + "'"); while (dr.Read()) { user = dr["姓名"].ToString(); } //--------------------------------超级管理员---------------------------------------- if (a == "超级管理员登录成功" && cbType.Text == "管理员") { // MessageBox.Show(a, "提示", MessageBoxButtons.OK); this.Hide(); frmMain fm = new frmMain(2, user); fm.ShowDialog(); } else if (a == "超级管理员登录成功" && cbType.Text == "读者") { // MessageBox.Show("读者登录成功", "提示", MessageBoxButtons.OK); this.Hide(); } //--------------------------------普通管理员---------------------------------------- else if (a == "普通管理员登录成功" && cbType.Text == "管理员") { // MessageBox.Show(a, "提示", MessageBoxButtons.OK); this.Hide(); frmMain fm = new frmMain(1, user); fm.ShowDialog(); } else if (a == "普通管理员登录成功" && cbType.Text == "读者") { MessageBox.Show("读者登录成功", "提示", MessageBoxButtons.OK); this.Hide(); } //--------------------------------读者---------------------------------------------- else if (a == "读者登录成功" && cbType.Text == "读者") { //MessageBox.Show(a, "提示", MessageBoxButtons.OK); this.Hide(); } //--------------------------------失败---------------------------------------------- else { MessageBox.Show("登录失败", "提示"); } }
public frmCadastroLogin(UsuarioEnum Enum, Login Login) { if (Login != null) { LOGIN = Login; } ENUM = Enum; InitializeComponent(); }
/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public static bool Login(ref Model.Login login, out string errMsg) { try { errMsg = ""; string sql = "select Id,Name,Role,IsEnable from [User] where (Phone = @LogName and Password = @LogPassword) or (Email = @LogName and Password = @LogPassword)"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@LogName", login.LogName.Trim()), new SqlParameter("@LogPassword", login.LogPassword) }; DataTable dtUser = DBHelper.ExecuteGetDataTable(CommandType.Text, sql, para); if (dtUser.Rows.Count > 0) { DataRow dr = dtUser.Rows[0]; if ((bool)dr["IsEnable"]) { login.LogId = (int)dr["Id"]; login.IsPassed = true; EventLog e = new EventLog(); e.TargetIds = login.LogId.ToString(); e.CodeTag = "Login"; e.LogName = "用户登录"; EventLogService.AddEventLog <Model.Login>(e, login); return(true); } else { errMsg = "该用户已被禁用"; login.IsPassed = false; return(false); } } else { errMsg = "用户名或密码不正确"; login.IsPassed = false; return(false); } } catch (Exception ex) { errMsg = ex.Message; ErrorLog e = new ErrorLog(); e.TargetIds = login.LogId.ToString(); e.CodeTag = "Login"; e.LogName = "用户登录"; e.ErrorMsg = ex.Message.ToString(); ErrorLogService.AddErrorLog <Model.Login>(e, login); return(false); } }
protected void btn_login_Click(object sender, EventArgs e) { //封装实体对象 //封装实体对象 int UserName = Convert.ToInt32(Request.Form["txt_username"]); string PassWord = Request.Form["txt_password"].ToString(); Model.Login user = new Model.Login() { UserName = UserName, PassWord = PassWord }; //调用BLL层方法,返回一个新的user对象 user = new LoginManage().LoginService(user); //根据返回的数据进行操作 if (user == null) { Literal1.Text = "<script type='text/javascript'>alert('账号密码错误')</script>"; } else { Session["CurrentUser"] = user; if (user.type == 1) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/stu_index.aspx'</script>"; } if (user.type == 2) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/xueshengchu_index.aspx'</script>"; } if (user.type == 3) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/jiaowuchu_index.aspx'</script>"; } if (user.type == 4) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/teacherindex.aspx'</script>"; } if (user.type == 5) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/college_index.aspx'</script>"; } if (user.type == 6) { Literal1.Text = "<script type='text/javascript'>alert('登陆成功');location.href='StudentsInfo/Guanliyuan_index.aspx'</script>"; } } }
private void btn_Logar_Click(object sender, EventArgs e) { try { KeyGenDAO keygenDao = new KeyGenDAO(); keygenDao.InsertData(); if (keygenDao.selectQuantidadeData() >= 30) { frmAtivacao fom = new frmAtivacao(); fom.Show(); this.Hide(); } else { Login login = new Login { Nome = txt_Nome.Text, Senha = txt_Senha.Text }; if (loginDao.SelectLogin(login)) { string NomeComSubstring = txt_Nome.Text.ToUpper(); NomeLoginGlobal.Nome = NomeComSubstring; NomeLoginGlobal.Permicao = loginDao.SelectPermissaoPorUsuario(NomeComSubstring).Rows[0]["Permicao"].ToString().ToUpper(); frmMenu chamaMenu = new frmMenu(); chamaMenu.Show(); this.Hide(); } else { Message("Login Enexistente, Crie Um Login E Tente Novamente", "Aviso"); FocoNoLogin(); LimparTxt(); } } } catch (Exception Erro) { Message("Erro Ao Tentar Acessar O Menu: " + Erro.Message, "Erro"); LimparTxt(); FocoNoLogin(); } }
private void btnCadastrar_Click(object sender, EventArgs e) { if (txtLogin.Text == "") { MessageBox.Show("O campo 'Login' deve ser preenchido.", "Erro de Cadastro de login", MessageBoxButtons.OK, MessageBoxIcon.Error); txtLogin.Focus(); } else if (txtSenha.Text == "") { MessageBox.Show("O campo 'Senha' deve ser preenchido.", "Erro de Cadastro de login", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSenha.Focus(); } else if (txtConfirmaSenha.Text == "") { MessageBox.Show("O campo 'Confirma Senha' deve ser preenchido.", "Erro de Cadastro de login", MessageBoxButtons.OK, MessageBoxIcon.Error); txtConfirmaSenha.Focus(); } else if (txtSenha.Text != txtConfirmaSenha.Text) { MessageBox.Show("Os campos 'Senha' e 'Confirma Senha' não conferem.", "Erro de Cadastro de login", MessageBoxButtons.OK, MessageBoxIcon.Question); txtConfirmaSenha.Text = string.Empty; txtConfirmaSenha.Focus(); } else { login = new Login { Nome = txtLogin.Text, Senha = txtSenha.Text, CSenha = txtConfirmaSenha.Text }; if (comando.InsertLogin(login)) { MessageBox.Show("Senha Cadastrada Com Sucesso!", ""); this.DialogResult = DialogResult.Yes; this.Hide(); frmLogin chamaNovamente = new frmLogin(); chamaNovamente.Show(); } else { MessageBox.Show("Não Foi Possível Cadastrar O Usuario, Verifique Se O Usuario Já Exite","Aviso"); LimparTxt(); } } }
private void btn_Cancelar_Click(object sender, EventArgs e) { if (txt_Nome.Text.Length > 0 && txt_Senha.Text.Length > 0) { try { Login login = new Login { Nome = txt_Nome.Text, Senha = txt_Senha.Text, Permissao = cbb_Permicao.Text.ToUpper() }; if (login.Senha.Equals(txt_ConfirmaSenha.Text)) { if (loginDao.InsertLogin(login)) { Message("Login Cadastrado Com Sucesso!", "Aviso"); frmLogin chamaLogin = new frmLogin(); chamaLogin.Show(); this.Hide(); } else { Message("Não Foi Possível Cadastrar O Login, Dados Incorretos Ou Login Já Existente", ""); } } else { Message("Senhas Incorretas", "Aviso"); LimparTxtSenhas(); } } catch (Exception Erro) { Message("Erro Ao Cadastrar O Login: "******"Erro"); LimparTxtSenhas(); } } else { Message("Existem Campos Em Branco, Para Cadastrar Um Úsuario è Necessario Preencher Todos Os Campos", "Aviso"); } }
public bool Logar(Login login) { try { LimparParametros(); AdicionaParametro("@Nome",login.Nome); AdicionaParametro("@Senha", login.Senha); if (ExecutaComando(CommandType.StoredProcedure,"[dbo].[aspLogar]") != null) { return true; } return false; } catch (Exception Erro) { throw new Exception(Erro.Message); } }
public static string sysLogin(Model.Login l) //返回一个String型的数据出去 { string str = "proc_Login"; //存储过程名称 SqlParameter[] Parameter = { new SqlParameter("@username", SqlDbType.NVarChar), new SqlParameter("@password", SqlDbType.NVarChar), new SqlParameter("@BackValue", SqlDbType.NVarChar, 50) }; Parameter[0].Value = l.Username; Parameter[1].Value = l.Password; Parameter[2].Direction = ParameterDirection.Output; //获取数据库的返回值 SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, str, Parameter); //获取返回值 return(Convert.ToString(Parameter[2].Value.ToString())); }
private void btnEntrar_Click(object sender, EventArgs e) { login = new Login { Nome = txtLogin.Text, Senha = txtSenha.Text }; if (comando.Logar(login)) { this.Hide(); frmPrincipal abrir = new frmPrincipal(); abrir.Show(); } else { MessageBox.Show("Não Foi Póssivel Logar, Verifique Usuario E Senha", "Aviso"); } }
protected void Button1_Click1(object sender, EventArgs e) { if (IsPostBack) { string youxiang = this.TextBox1.Text; string yhm = this.TextBox2.Text; string mima = this.TextBox3.Text; if (youxiang.Trim() == "") { Response.Write("<script>alert('邮箱不能为空')</script>"); } else if (yhm.Trim() == "") { Response.Write("<script>alert('用户名不能为空')</script>"); } else if (mima.Trim() == "") { Response.Write("<script>alert('密码不能为空')</script>"); } else if (this.CheckBox1.Checked == false) { Response.Write("<script>alert('注册必须同意协议')</script>"); } else { Model.Login zhuce = new Model.Login(); zhuce.YHM = yhm; zhuce.YouXiang = youxiang; zhuce.MIMA = mima; zhuce.Zhuceshijian = Convert.ToDateTime(DateTime.Now.ToString()); zhuce.Userpic = "touxiang_23.gif"; if (LoginBLL.AddUser(zhuce)) { Response.Write("<script>alert('注册成功!')</script>"); Response.Redirect("登录.aspx"); } else { Response.Write("<script>alert('注册失败!')</script>"); } } } }
protected void btn_alterpass_Click(object sender, EventArgs e) { string oldPassWord = txt_pwd.Text.Trim(); string newPassWord = txt_newpwd.Text.Trim(); string newPassWord2 = txt_renewpwd.Text.Trim(); if (newPassWord != newPassWord2) { Response.Write("<script type='text/javascript'>alert('两次输入的密码不一致')</script>"); return; } int UserName = Convert.ToInt32(((Model.Login)Session["CurrentUser"]).UserName); Model.Login user = new Model.Login() { UserName = UserName, PassWord = oldPassWord }; user = new LoginManage().LoginService(user); if (user == null) { Response.Write("<script type='text/javascript'>alert('原密码错误')</script>"); return; } Model.Login newuser = new Model.Login() { UserName = UserName, PassWord = newPassWord }; int res = new LoginManage().AlterPwd(newuser); if (res > 0) { Response.Write("<script type='text/javascript'>alert('更新成功');</script>"); } else { Response.Write("<script type='text/javascript'>alert('更新失败')</script>"); } }
public bool InsertLogin(Login login) { try { LimparParametros(); AdicionaParametro("@Nome", login.Nome); AdicionaParametro("@Senha", login.Senha); AdicionaParametro("@Permicao", login.Permissao.ToUpper()); if ( ExecutaComando(CommandType.StoredProcedure, "[dbo].[_aspInsertLogin]") != null) { return true; } else { return false; } } catch (Exception Erro) { throw new Exception(Erro.Message); } }
public Login SelectILinhaPorNome(string Nome) { try { Login log = new Login(); LimparParametros(); AdicionaParametro("@Nome",Nome); DataRow Linha = ExecutaConsulta(CommandType.StoredProcedure, "[dbo].[_aspSelectLoginPorNome]").Rows[0]; if (Linha != null) { log.Id = Convert.ToInt32(Linha["ID"]); log.Nome = Linha["Nome"].ToString(); log.Permissao = Linha["Permicao"].ToString(); log.Senha = Linha["Senha"].ToString(); } return log; } catch (Exception Erro) { throw new Exception(Erro.Message); } }
public Login JogaTxtParaObjeto() { try { Login login = new Login(); if (LOGIN != null) { login.Id = LOGIN.Id; } login.Nome = txt_Nome.Text; login.Senha = txt_Senha.Text; login.Permissao = cbb_Permicao.Text; return login; } catch (Exception Erro) { Message("Erro Ao Atribuir Valores Para Os Campos: "+Erro.Message,"Erro"); LimparTxtSenhas(); txt_Nome.Text = string.Empty; return null; } }
/// <summary> /// 用户登录 /// </summary> /// <returns></returns> public static bool Login(ref Model.Login model, out string errMsg) { return(UserService.Login(ref model, out errMsg)); }
public ActionResult Profile() { Model.Login login = new Model.Login(); login = _accountManager.GetUserInfo(User.Identity.Name); return(View(login)); }