protected void Logando(object sender, EventArgs e) { if (txtlogin.Text.Equals("") || txtSenha.Text.Equals("")) { EnviarMensagem(); } else { var usuarios = new Usuarios(); Usuario usuario = usuarios.ObterAcesso(txtlogin.Text, txtSenha.Text); if (usuario != null) { Session["UsuarioLogadoId"] = usuario.Id; Session["TipoUsuarioId"] = usuario.TipoUsuario.Id; if (usuario.Senha == "123456") Response.Redirect("/AlterarSenha.aspx"); else Response.Redirect("/Login.aspx"); } else { Notificacao = "Usuário e/ou senha incorreta. Tente novamente."; EnviarMensagem(); } } }
/// <summary> /// Virifica se o usuario existe /// </summary> /// <param name="login">Nome do Usuario</param> /// <param name="senha">Senha do Usuario</param> /// <returns>Se o usuario e senha existir retorna com verdadeiro</returns> public bool IsValid(string login, string senha) { var usuarios = new Usuarios(); var usuario = usuarios.ObterAcesso(login, senha); //Melhorar if (usuario == null || usuario.TipoUsuario.Id != (int) TipoUsuarioEnum.Administrador) { return false; } else { Nome = usuario.Nome; return true; } }
public void h_importar_usuario_coorporativo_do_excel() { string _conectionstring; _conectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;"; _conectionstring += String.Format("Data Source={0};", "D:\\Coorporativo.xls"); _conectionstring += "Extended Properties='Excel 8.0;HDR=NO;'"; OleDbConnection cn = new OleDbConnection(_conectionstring); OleDbCommand cmd = new OleDbCommand("Select * from [Usuarios$]", cn); cn.Open(); OleDbDataReader reader = cmd.ExecuteReader(); List<UsuarioCoorporativoExcel> usuariosExcel = new List<UsuarioCoorporativoExcel>(); int i = 0; while (reader.Read()) { if (i == 2) { if (reader[0] == DBNull.Value) break; UsuarioCoorporativoExcel usuarioExcel = new UsuarioCoorporativoExcel(); usuarioExcel.Usuario = (string)reader[0]; usuarioExcel.Login = (string)reader[1]; usuarioExcel.NomeSetor = (string)reader[3]; usuarioExcel.CodCentro = (string)reader[5]; usuarioExcel.Descricao = (string)reader[6]; usuariosExcel.Add(usuarioExcel); } i++; } var novo = usuariosExcel; Setores setores = new Setores(); CentrosDeCusto centrosDeCusto = new CentrosDeCusto(); TipoUsuarios tipoUsuarios = new TipoUsuarios(); var tipoUsuario = tipoUsuarios.Obter<TipoUsuario>(3); var repositorioUsuarios = new Usuarios(); foreach (var usuarioExcel in usuariosExcel) { Usuario usuario = repositorioUsuarios.ObterAcesso(usuarioExcel.Login, 123456.ToString()); if (usuario == null) { usuario = new Usuario(); usuario.TipoUsuario = tipoUsuario; usuario.Nome = usuarioExcel.Usuario; usuario.Login = usuarioExcel.Login; usuario.Senha = "123456"; } Setor setor = setores.ObterPor(usuarioExcel.NomeSetor); if (setor == null) { setor = new Setor(usuarioExcel.NomeSetor); } if (usuario.Departamentos == null || !usuario.Departamentos.Any(d => d.Nome == setor.Nome)) usuario.ParticiparDe(setor); var centroDecusto = centrosDeCusto.ObterPor(usuarioExcel.CodCentro); if (centroDecusto == null) { setores.Salvar(setor); centroDecusto = new CentroDeCusto(usuarioExcel.Descricao) { CodigoDoCentroDeCusto = usuarioExcel.CodCentro }; centrosDeCusto.Salvar(centroDecusto); } if (setor.CentrosDeCusto == null || setor.CentrosDeCusto.Count == 0 || setor.CentrosDeCusto != null && setor.CentrosDeCusto.Count > 0 && !setor.CentrosDeCusto.Any(c => c.CodigoDoCentroDeCusto == centroDecusto.CodigoDoCentroDeCusto)) setor.AdicionarCentroDeCusto(centroDecusto); //ServicoSalvarDepartamento servico = new ServicoSalvarDepartamento(); //servico.Salvar(setor); setores.Salvar(setor); repositorioUsuarios.Salvar(usuario); } }
public void g_importar_usuario_do_excel() { string _conectionstring; _conectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;"; _conectionstring += String.Format("Data Source={0};", "D:\\Hospital2.xls"); _conectionstring += "Extended Properties='Excel 8.0;HDR=NO;'"; OleDbConnection cn = new OleDbConnection(_conectionstring); OleDbCommand cmd = new OleDbCommand("Select * from [LISTAS - OUTRAS DESPESAS$]", cn); cn.Open(); OleDbDataReader reader = cmd.ExecuteReader(); List<UsuarioExcel> usuariosExcel = new List<UsuarioExcel>(); int i = 0; while (reader.Read()) { if (i > 1) { if (reader[0] == DBNull.Value) break; UsuarioExcel usuarioExcel = new UsuarioExcel(); usuarioExcel.Usuario = (string)reader[0]; usuarioExcel.Login = (string)reader[1]; usuarioExcel.Hospital = (string)reader[3]; usuariosExcel.Add(usuarioExcel); } i++; } Hospitais hospitais = new Hospitais(); TipoUsuarios tipoUsuarios = new TipoUsuarios(); var tipoUsuario = tipoUsuarios.Obter<TipoUsuario>(2); var repositorioUsuarios = new Usuarios(); foreach (var usuarioExcel in usuariosExcel) { Usuario usuario = repositorioUsuarios.ObterAcesso(usuarioExcel.Login, 123456.ToString()); if (usuario == null) { usuario = new Usuario(); usuario.TipoUsuario = tipoUsuario; usuario.Nome = usuarioExcel.Usuario; usuario.Login = usuarioExcel.Login; usuario.Senha = "123456"; } Hospital hospital = hospitais.ObterPor(usuarioExcel.Hospital); usuario.ParticiparDe(hospital); repositorioUsuarios.Salvar(usuario); } }