private void Inicializar(string Titulim) { Text = Titulim; txtNomeCompleto.TextChanged += TxtNomeCompleto_TextChanged; // Instacias Inicias prog = new Progress_Bar(); this.FormClosing += new FormClosingEventHandler(FrmModelos_FormClosing); // Chamadas dos Botões btnNovo.Click += new EventHandler(BtnNovo_TextChangedAsync); btnGuardadr.Click += new EventHandler(BtnGuardadr_TextChanged); btnApagar.Click += new EventHandler(BtnApagar_Click); txtCodigo.TextChanged += new EventHandler(TxtCodigo_TextChanged); this.Load += frmModern__LoadAsync; brnRefresk.Click += delegate { Listar_Tudo(); }; txtCodigo.ButtonClick += delegate { try { Cursor = Cursors.WaitCursor; dataGridView1.Rows.Clear(); foreach (var item in UsuariosInstaciaList) { dataGridView1.Rows.Add(item.UsuariosId, item.UsuarioNomeCompleto); } flyoutPanel1.ShowBeakForm(); txtPesquisa_Flag.Focus(); } catch (System.Exception exception) { MessageBox.Show("Erro " + exception, "Erro de SQL", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } }; dataGridView1.MouseDoubleClick += delegate { if (dataGridView1.Rows.Count > 0) { txtCodigo.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); flyoutPanel1.HidePopup(); Edit(Convert.ToInt32(txtCodigo.Text), ""); } ; }; txtPesquisa_Flag.TextChanged += TxtPesquisa_Flag_TextChanged; #region Validações Rapidas dos Campos txtGrupos.TextChanged += delegate { if (!txtGrupos.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtGrupos, "Atenção Este campo tem que ter valores"); } }; txtNomeCompleto.TextChanged += delegate { if (!txtNomeCompleto.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtNomeCompleto, "Atenção Este campo tem que ter valores"); } }; txtApelido.TextChanged += delegate { if (!txtApelido.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtApelido, "Atenção Este campo tem que ter valores"); } }; txtLogin.TextChanged += delegate { if (!txtLogin.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtLogin, "Atenção Este campo tem que ter valores"); } }; txtSenha.TextChanged += delegate { if (!txtSenha.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtSenha, "Atenção Este campo tem que ter valores"); } }; txtRepetir_Senha.TextChanged += delegate { if (!txtRepetir_Senha.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtRepetir_Senha, "Atenção Este campo tem que ter valores"); } }; txtPIN.TextChanged += delegate { if (!txtPIN.Text.Equals(string.Empty)) { errorProvider1.Clear(); } else { errorProvider1.SetError(txtPIN, "Atenção Este campo tem que ter valores"); } }; #endregion //txtSenha.Validating += delegate { // OnValidatePassword(new object(), // new ValidatePasswordEventArgs("", txtSenha.Text, true)); //}; txtEmail.Validating += TxtEmail_Validating; // Validações dos Valores da PAssword 1 txtSenha.GotFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { isNew = true; } else { txtSenha.Text = string.Empty; } }; txtSenha.LostFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { return; } else if (!string.IsNullOrWhiteSpace(UserPassword) && string.IsNullOrWhiteSpace(txtSenha.Text)) { txtSenha.Text = UserPassword; isNew = false; } else { isNew = true; } }; // Validações dos Valores da PAssword 2 txtRepetir_Senha.GotFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { isNew = true; } else { txtRepetir_Senha.Text = string.Empty; } }; txtRepetir_Senha.LostFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { return; } else if (!string.IsNullOrWhiteSpace(UserPassword) && string.IsNullOrWhiteSpace(txtRepetir_Senha.Text)) { txtRepetir_Senha.Text = UserPassword; isNew = false; } else { isNew = true; } }; // Validações dos Valores da PIN txtPIN.GotFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { isNew = true; } else { txtPIN.Text = string.Empty; } }; txtPIN.LostFocus += delegate { if (string.IsNullOrWhiteSpace(UserPassword)) { return; } else if (!string.IsNullOrWhiteSpace(UserPassword) && string.IsNullOrWhiteSpace(txtPIN.Text)) { txtPIN.Text = UserPassword; isNew = false; } else { isNew = true; } }; txtPIN.TextChanged += delegate { #region Validar //string actualdata = string.Empty; //char[] entereddata = txtPIN.Text.ToCharArray(); //foreach (char aChar in entereddata.AsEnumerable()) //{ // if (Char.IsDigit(aChar)) // { // actualdata = actualdata + aChar; // // MessageBox.Show(aChar.ToString()); // } // else // { // MessageBox.Show(aChar + " is not numeric"); // actualdata.Replace(aChar, ' '); // actualdata.Trim(); // } //} //txtPIN.Text = actualdata; #endregion }; txtPIN.KeyPress += (sender, e) => { #region Validar // Text string text = ((Control)sender).Text; // Is Negative Number? if (e.KeyChar == '-' && text.Length == 0) { e.Handled = false; return; } // Is Float Number? if (e.KeyChar == '.' && text.Length > 0 && !text.Contains(".")) { e.Handled = false; return; } // Is Digit? e.Handled = (!char.IsDigit(e.KeyChar)); #endregion }; txtPIN.Validating += (sender, e) => { var t = Encriptar.GetMD5Hash(txtEmail.Text); var result = UsuariosInstaciaList.Where(x => x.Pin == t && x.GrupoId == (int)txtGrupos.EditValue) .FirstOrDefault(); if (result != null) { if (!string.IsNullOrWhiteSpace(txtCodigo.Text) || !txtCodigo.Text.Equals("0")) { if (result.UsuariosId != int.Parse(txtCodigo.Text)) { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "PIN Indisponivel", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); } } else { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "PIN Indisponivel", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); } } }; txtNomeCompleto.KeyDown += TxtNomeCompleto_KeyDown1; ListGeral(); }
bool Validar1(int Metodo1ou2) { if (txtGrupos.Text.Equals("[Por Favor selecione o seu grupo por favor!...]")) { XtraMessageBox.Show("Selecione o grupo aque vai pertencer este Usuário!... preencha por favor!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtGrupos, "Grupo invalido"); txtGrupos.ShowPopup(); txtGrupos.Focus(); return(false); } if (txtNomeCompleto.Text.Trim().Equals(string.Empty)) { XtraMessageBox.Show("Digite o nome do Usuário por favor!... \npreencha por favor!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtNomeCompleto, "Usuário invalido"); txtNomeCompleto.Focus(); return(false); } else if (txtSenha.Text.Trim().Equals(string.Empty)) { XtraMessageBox.Show("Digite a senha do usuário por favor!... \npreencha por favor!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtSenha, "Password inválido"); txtSenha.Focus(); return(false); } else if (txtRepetir_Senha.Text.Trim().Equals(string.Empty)) { XtraMessageBox.Show("Pepita a senha por favor!... preencha por favor!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtRepetir_Senha, "Senha invalido"); txtRepetir_Senha.Focus(); return(false); } else if (txtPIN.Text.Trim().Equals(string.Empty)) { XtraMessageBox.Show("Digite o pin Por favor!... preencha por favor!", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtPIN, "PIN invalido"); txtPIN.Focus(); return(false); } else if (txtSenha.Text.Trim().Length <= 4) { XtraMessageBox.Show("Desculpe não é permitido palavra passe com menos de 6 Caracter\n tente colocar uma com mais caracter!...", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtSenha, "Senha invalido"); errorProvider1.SetError(txtRepetir_Senha, "Senha invalido"); txtRepetir_Senha.SelectAll(); txtSenha.SelectAll(); txtSenha.Focus(); return(false); } else if (txtPIN.Text.Length < 0) { XtraMessageBox.Show("Desculpe mais não permitimos pin com menos de 2 Caracter", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtPIN, "PIN invalido"); txtPIN.SelectAll(); txtPIN.Focus(); return(false); } else if (!txtSenha.Text.Trim().Equals(txtRepetir_Senha.Text)) { XtraMessageBox.Show("Desculpe mais os 2 Campos da senha não Conscidem \n tente colocar senhas iguas para os 2 Campos!...", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error); errorProvider1.SetError(txtSenha, "Senha invalido"); errorProvider1.SetError(txtRepetir_Senha, "Senha invalido"); txtRepetir_Senha.SelectAll(); txtSenha.SelectAll(); txtSenha.Focus(); return(false); } #region Validação 2 // Validar Email var result = UsuariosInstaciaList.ToList(); if (!EmailValidade.GetIstance().IsValidEmail(txtEmail.Text.Trim())) { XtraMessageBox.Show("Email Inválido coloque um email válido", "Erro de Email", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.SelectAll(); txtEmail.Focus(); return(false); } else { if (Metodo1ou2 == 1) { var result12 = result.Where(x => x.Email == txtEmail.Text).FirstOrDefault(); if (result12 != null) { if (!string.IsNullOrWhiteSpace(txtCodigo.Text) || !txtCodigo.Text.Equals("0")) { if (result12.UsuariosId != int.Parse(txtCodigo.Text)) { XtraMessageBox.Show("Lamentamos mais este E-Mail já Existe no Sistema", "Erro de Email", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } else { XtraMessageBox.Show("Lamentamos mais este E-Mail já Existe no Sistema", "Erro de Email", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } // Pin var t = Encriptar.GetMD5Hash(txtPIN.Text.Trim()); var result1 = result.Where(x => x.Pin == t && x.GrupoId == (int)(txtGrupos.EditValue as Grupos).GrupoId).FirstOrDefault(); if (result1 != null) { if (!string.IsNullOrWhiteSpace(txtCodigo.Text) || !txtCodigo.Text.Equals("0")) { if (result1.UsuariosId != int.Parse(txtCodigo.Text)) { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "Erro de PIN", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } else { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "Erro de PIN", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } } else { // Pin var t = Encriptar.GetMD5Hash(txtPIN.Text); var result1 = result.Where(x => x.Pin == t && x.GrupoId == (int)(txtGrupos.EditValue as Grupos).GrupoId).FirstOrDefault(); if (result.Where(x => x.Pin == t && x.GrupoId == (int)(txtGrupos.EditValue as Grupos).GrupoId).Count() > 1) { if (!string.IsNullOrWhiteSpace(txtCodigo.Text) || !txtCodigo.Text.Equals("0")) { if (result1.UsuariosId != int.Parse(txtCodigo.Text)) { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "Erro de PIN", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } else { XtraMessageBox.Show("Lamentamos mais este PIN Esta Indisponivel!...", "Erro de PIN", MessageBoxButtons.OK, MessageBoxIcon.Error); txtEmail.Focus(); return(false); } } } } return(true); #endregion }
private async void Atualizar_RegistroAsync() { try { if (Validar1(2)) { Cursor = Cursors.WaitCursor; if (!(GetExistingData() > 1)) { if (MessageBox.Show("Estas preste a alterar o valor do (" + txtNomeCompleto.Text + ")! pretendes continuar?", "Alteração de dados", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { string Pass1; string Pass2; if (isNew) { Pass1 = Encriptar.GetMD5Hash(txtSenha.Text); Pass2 = Encriptar.GetMD5Hash(txtPIN.Text); } else { Pass1 = txtSenha.Text; Pass2 = txtPIN.Text; } var cursos = new Usuarios { UsuariosId = Convert.ToInt32(txtCodigo.Text), UsuarioNomeCompleto = txtNomeCompleto.Text, Apelido = txtApelido.Text, Login = txtLogin.Text, Senha = Pass1, DataNascimento = Convert.ToDateTime(dateEdit1.EditValue), Email = txtEmail.Text, Pin = Pass2, Estado = (bool)checkEdit1.EditValue, GrupoId = Convert.ToInt32(txtGrupos.EditValue), Perfil = (byte[])ImagemTratamento.ImageToByteArray(ImagemPictureEdit.Image) }; if ((await UsuariosControllers.GetInstacia().Update(cursos)).IsSucess) { XtraMessageBox.Show("Serviço Atualizado com Sucesso!...", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); ListGeral(); limpar_Campos(); } else { XtraMessageBox.Show("Este Valor já existe tente novamente", "Má conclusão", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { XtraMessageBox.Show("Lamentamos mais já existe este login no Sistema\n Não pode existir PIN ou login com o mesmo acesso", "Má conclusão", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (System.Exception exe) { XtraMessageBox.Show(exe.Message, "Arro de Actualização", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } }
private void button7_Click(object sender, EventArgs e) { if (Globales.llamadas == "1") { try { //**** calculamos el valor de la coluna numerador // var ultimocod = bd.Ususarios.OrderByDescending(x => x.cod).First().cod; //****GRABA LOS DATOS EN LA TABLA var nuevoUsuario = new Ususarios(); nuevoUsuario.numerousuario = Convert.ToInt32(label1.Text); nuevoUsuario.nombre = textBox1.Text; // encriptamos la contaraseña con la clase encriptar nuevoUsuario.login = Encriptar.codificar(maskedTextBox1.Text); if (radioButton1.Checked == true) { nuevoUsuario.activo = true; } else { nuevoUsuario.activo = false; } nuevoUsuario.grupo = comboBox1.Text; nuevoUsuario.pregunta = textBox2.Text; nuevoUsuario.respuesta = Encriptar.codificar(textBox3.Text); if (arbol.Nodes[0].Checked == true) { nuevoUsuario.sistema = true; } else { nuevoUsuario.sistema = false; } if (arbol.Nodes[0].Nodes[0].Checked == true) { nuevoUsuario.misdatos = true; } else { nuevoUsuario.misdatos = false; } if (arbol.Nodes[0].Nodes[1].Checked == true) { nuevoUsuario.usuarios = true; } else { nuevoUsuario.usuarios = false; } if (arbol.Nodes[0].Nodes[1].Nodes[0].Checked == true) { nuevoUsuario.gusuarios = true; } else { nuevoUsuario.gusuarios = false; } if (arbol.Nodes[0].Nodes[2].Checked == true) { nuevoUsuario.impuestos = true; } else { nuevoUsuario.impuestos = false; } if (arbol.Nodes[0].Nodes[3].Checked == true) { nuevoUsuario.rutas = true; } else { nuevoUsuario.rutas = false; } if (arbol.Nodes[1].Checked == true) { nuevoUsuario.clientes = true; } else { nuevoUsuario.clientes = false; } if (arbol.Nodes[1].Nodes[0].Checked == true) { nuevoUsuario.gclientes = true; } else { nuevoUsuario.gclientes = false; } if (arbol.Nodes[1].Nodes[1].Checked == true) { nuevoUsuario.Escaner = true; } else { nuevoUsuario.Escaner = false; } if (arbol.Nodes[2].Checked == true) { nuevoUsuario.facturas = true; } if (arbol.Nodes[2].Nodes[0].Checked == true) { nuevoUsuario.fmensual = true; } if (arbol.Nodes[2].Nodes[1].Checked == true) { nuevoUsuario.fmanual = true; } if (arbol.Nodes[3].Checked == true) { nuevoUsuario.albaranes = true; } if (arbol.Nodes[3].Nodes[0].Checked == true) { nuevoUsuario.galbaranes = true; } if (arbol.Nodes[4].Checked == true) { nuevoUsuario.facturas = true; } if (arbol.Nodes[4].Nodes[0].Checked == true) { nuevoUsuario.gfacturas = true; } if (arbol.Nodes[5].Checked == true) { nuevoUsuario.csb19 = true; } if (arbol.Nodes[6].Checked == true) { nuevoUsuario.contaplus = true; } if (arbol.Nodes[7].Checked == true) { nuevoUsuario.listados = true; } if (arbol.Nodes[8].Checked == true) { nuevoUsuario.copiaseguridad = true; } if (arbol.Nodes[9].Checked == true) { nuevoUsuario.agenda = true; } if (arbol.Nodes[10].Checked == true) { nuevoUsuario.avisos = true; } if (arbol.Nodes[10].Nodes[0].Checked == true) { nuevoUsuario.gavisos = true; } bd.Ususarios.Add(nuevoUsuario); //guardamos los cambios bd.SaveChanges(); } catch (Exception) { MessageBox.Show("No ha sido posible grabar los datos", "Error 101"); } } if (Globales.llamadas == "2") { try { //extraemos los datos correspondientes de la tabla en el objeto var usuarioAmodificar = bd.Ususarios.SingleOrDefault(codusuario => codusuario.cod == Globales.modificar); //modificamos los valores usuarioAmodificar.nombre = textBox1.Text; usuarioAmodificar.login = Encriptar.codificar(maskedTextBox1.Text); usuarioAmodificar.pregunta = textBox2.Text; usuarioAmodificar.respuesta = Encriptar.codificar(textBox3.Text); usuarioAmodificar.grupo = comboBox1.Text; if (radioButton1.Checked == true) { usuarioAmodificar.activo = true; } else { usuarioAmodificar.activo = false; } if (arbol.Nodes[0].Checked == true) { usuarioAmodificar.sistema = true; } else { usuarioAmodificar.sistema = false; } if (arbol.Nodes[0].Nodes[0].Checked == true) { usuarioAmodificar.misdatos = true; } else { usuarioAmodificar.misdatos = false; } if (arbol.Nodes[0].Nodes[1].Checked == true) { usuarioAmodificar.usuarios = true; } else { usuarioAmodificar.usuarios = false; } if (arbol.Nodes[0].Nodes[1].Nodes[0].Checked == true) { usuarioAmodificar.gusuarios = true; } else { usuarioAmodificar.gusuarios = false; } if (arbol.Nodes[0].Nodes[2].Checked == true) { usuarioAmodificar.impuestos = true; } else { usuarioAmodificar.impuestos = false; } if (arbol.Nodes[1].Checked == true) { usuarioAmodificar.clientes = true; } if (arbol.Nodes[1].Nodes[0].Checked == true) { usuarioAmodificar.gclientes = true; } if (arbol.Nodes[1].Nodes[1].Checked == true) { usuarioAmodificar.Escaner = true; } else { usuarioAmodificar.Escaner = false; } if (arbol.Nodes[2].Checked == true) { usuarioAmodificar.facturas = true; } if (arbol.Nodes[2].Nodes[0].Checked == true) { usuarioAmodificar.fmensual = true; } if (arbol.Nodes[2].Nodes[1].Checked == true) { usuarioAmodificar.fmanual = true; } if (arbol.Nodes[3].Checked == true) { usuarioAmodificar.albaranes = true; } if (arbol.Nodes[3].Nodes[0].Checked == true) { usuarioAmodificar.galbaranes = true; } if (arbol.Nodes[4].Checked == true) { usuarioAmodificar.facturas = true; } if (arbol.Nodes[4].Nodes[0].Checked == true) { usuarioAmodificar.gfacturas = true; } if (arbol.Nodes[5].Checked == true) { usuarioAmodificar.csb19 = true; } if (arbol.Nodes[6].Checked == true) { usuarioAmodificar.contaplus = true; } if (arbol.Nodes[7].Checked == true) { usuarioAmodificar.listados = true; } if (arbol.Nodes[8].Checked == true) { usuarioAmodificar.copiaseguridad = true; } if (arbol.Nodes[9].Checked == true) { usuarioAmodificar.agenda = true; } if (arbol.Nodes[10].Checked == true) { usuarioAmodificar.avisos = true; } if (arbol.Nodes[10].Nodes[0].Checked == true) { usuarioAmodificar.gavisos = true; } //guardamos los cambios bd.SaveChanges(); } catch (Exception) { MessageBox.Show("No ha sido posible grabar los datos", "Error 102"); } } // Close(); }
public string codificar(string cadena) { return(Encriptar.Encrypt(cadena)); }
/// <summary> /// Realiza el proceso de creación de un usuario en la base de datos /// </summary> /// <param name="usuario">Información del usuario que se desea crear</param> public override void Crear(DTOUsuarios usuario) { try { String Message = String.Empty; Message = this.ValidaUsuario(usuario, usuario.Cliente); if (String.IsNullOrEmpty(Message)) { ManagerDb db = new ManagerDb(); DataTable tbl = db.ObtenerDatos("SELECT 1 FROM USUARIOS WHERE USU_USUARIO = @USUARIO", new SqlParameter("@USUARIO", usuario.Usuario)); if (tbl.Rows.Count > 0) { throw new CustomException("<li>El nombre de usuario ingresado ya se encuentra registrado en la base de datos, por favor corrigalo e intentelo de nuevo"); } else { String query = "INSERT INTO USUARIOS (USU_USUARIO, USU_PASSWORD, USU_NOMBRES, USU_APELLIDOS, USU_CORREO, USU_ROL)"; query += "VALUES (@USU_USUARIO, @USU_PASSWORD, @USU_NOMBRES, @USU_APELLIDOS, @USU_CORREO, @USU_ROL);"; db.Ejecutar(query, new SqlParameter("@USU_USUARIO", usuario.Usuario), new SqlParameter("@USU_PASSWORD", Encriptar.EncriptaContrasena(usuario.Password)), new SqlParameter("@USU_NOMBRES", usuario.Nombres), new SqlParameter("@USU_APELLIDOS", usuario.Apellidos), new SqlParameter("@USU_CORREO", usuario.Correo), new SqlParameter("@USU_ROL", usuario.Rol)); if (usuario.Rol == 2) { int codigoUsuario = db.ObtenerDatos("SELECT IDENT_CURRENT('USUARIOS')").AsEnumerable().Select(x => Convert.ToInt32(x.Field <Object>(0))).FirstOrDefault(); query = "INSERT INTO CLIENTES (CLI_DOCUMENTO, CLI_TIPODOCUMENTO, CLI_FECHANACIMIENTO, USU_CODIGO)"; query += "VALUES (@CLI_DOCUMENTO, @CLI_TIPODOCUMENTO, @CLI_FECHANACIMIENTO, @USU_CODIGO)"; db.Ejecutar(query, new SqlParameter("@CLI_DOCUMENTO", usuario.Cliente.Documento), new SqlParameter("@CLI_TIPODOCUMENTO", usuario.Cliente.TipoDocumento), new SqlParameter("@CLI_FECHANACIMIENTO", usuario.Cliente.FechaNacimiento), new SqlParameter("@USU_CODIGO", codigoUsuario)); } } } else { throw new CustomException("<ul>" + Message + "</ul>"); } } catch (CustomException ex) { throw new CustomException(ex.Message); } catch (Exception ex) { Exception ex1 = ex; while (ex1.InnerException != null) { ex1 = ex1.InnerException; } throw new Exception(ex1.Message); } }
private void Usuario_Load(object sender, EventArgs e) { if (Globales.llamadas == "2") { // muestra los datos del registro seleccionado. try { //busca en la tabla la fila con el registro suminstrado //y si lo carga los datos en el formulario var amodificar = bd.Ususarios.SingleOrDefault(codusuario => codusuario.cod == Globales.modificar); if (amodificar != null) { label1.Text = Convert.ToString(amodificar.cod); textBox1.Text = amodificar.nombre; maskedTextBox1.Text = Encriptar.Descodificar(amodificar.login); maskedTextBox2.Text = Encriptar.Descodificar(amodificar.login); textBox2.Text = amodificar.pregunta; textBox3.Text = Encriptar.Descodificar(amodificar.respuesta); comboBox1.Text = amodificar.grupo; if (Convert.ToBoolean(amodificar.activo) == true) { radioButton1.Checked = true; } else { radioButton2.Checked = true; } if (amodificar.sistema == true) { arbol.Nodes[0].Checked = true; } else { arbol.Nodes[0].Checked = false; } if (amodificar.misdatos == true) { arbol.Nodes[0].Nodes[0].Checked = true; } else { arbol.Nodes[0].Nodes[1].Checked = false; } if (amodificar.usuarios == true) { arbol.Nodes[0].Nodes[1].Checked = true; } else { arbol.Nodes[0].Nodes[1].Checked = false; } if (amodificar.gusuarios == true) { arbol.Nodes[0].Nodes[1].Nodes[0].Checked = true; } else { arbol.Nodes[0].Nodes[1].Nodes[0].Checked = false; } if (amodificar.impuestos == true) { arbol.Nodes[0].Nodes[2].Checked = true; } else { arbol.Nodes[0].Nodes[2].Checked = false; } if (amodificar.clientes == true) { arbol.Nodes[1].Checked = true; } else { arbol.Nodes[1].Checked = false; } if (amodificar.gclientes == true) { arbol.Nodes[1].Nodes[0].Checked = true; } else { arbol.Nodes[1].Nodes[0].Checked = false; } if (amodificar.facturas == true) { arbol.Nodes[2].Checked = true; } else { arbol.Nodes[2].Checked = false; } if (amodificar.fmensual == true) { arbol.Nodes[2].Nodes[0].Checked = true; } else { arbol.Nodes[2].Nodes[0].Checked = false; } if (amodificar.fmanual == true) { arbol.Nodes[2].Nodes[1].Checked = true; } else { arbol.Nodes[2].Nodes[1].Checked = false; } if (amodificar.albaranes == true) { arbol.Nodes[3].Checked = true; } else { arbol.Nodes[3].Checked = false; } if (amodificar.galbaranes == true) { arbol.Nodes[3].Nodes[0].Checked = true; } else { arbol.Nodes[3].Nodes[0].Checked = false; } if (amodificar.facturas == true) { arbol.Nodes[4].Checked = true; } else { arbol.Nodes[4].Checked = false; } if (amodificar.gfacturas == true) { arbol.Nodes[4].Nodes[0].Checked = true; } else { arbol.Nodes[4].Nodes[0].Checked = false; } if (amodificar.csb19 == true) { arbol.Nodes[5].Checked = true; } else { arbol.Nodes[5].Checked = false; } if (amodificar.contaplus == true) { arbol.Nodes[6].Checked = true; } else { arbol.Nodes[6].Checked = false; } if (amodificar.listados == true) { arbol.Nodes[7].Checked = true; } else { arbol.Nodes[7].Checked = false; } if (amodificar.copiaseguridad == true) { arbol.Nodes[8].Checked = true; } else { arbol.Nodes[8].Checked = false; } if (amodificar.agenda == true) { arbol.Nodes[9].Checked = true; } else { arbol.Nodes[9].Checked = true; } if (amodificar.avisos == true) { arbol.Nodes[10].Checked = true; } else { arbol.Nodes[10].Checked = false; } if (amodificar.gavisos == true) { arbol.Nodes[10].Nodes[0].Checked = true; } else { arbol.Nodes[10].Nodes[0].Checked = false; } if (amodificar.agenda == true) { arbol.Nodes[9].Checked = true; } else { arbol.Nodes[9].Checked = false; } if (amodificar.avisos == true) { arbol.Nodes[10].Checked = true; } else { arbol.Nodes[10].Checked = false; } if (amodificar.gavisos == true) { arbol.Nodes[10].Nodes[0].Checked = true; } else { arbol.Nodes[10].Nodes[0].Checked = false; } } } catch (Exception) { MessageBox.Show("No ha sido posible cargar los datos", "Error 202"); } } if (Globales.llamadas == "1") { string cod; //**** calculamos el valor de la coluna numerador var ultimocod = bd.Ususarios.OrderByDescending(x => x.cod).ToList();// First().cod; if (ultimocod.Count == 0) { cod = "1"; } else { cod = (ultimocod.First().cod + 1).ToString(); } label1.Text = cod; } }
private void botModificar_Click(object sender, EventArgs e) { int cant_roles = 0; foreach (int indice in checkedListBox1.CheckedIndices) { cant_roles++; } if (FuncionesUtiles.estanVacios(new List <TextBox> { textPassword }) || cant_roles == 0) { string mensaje = "Debe completar los siguientes campos:"; if (FuncionesUtiles.estaVacio(textPassword)) { mensaje += "\n-Password"; } if (cant_roles == 0) { mensaje += "\n-Roles"; } MessageBox.Show(mensaje, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand); } else { SqlDataReader reader; SqlConnection con = Conexion.conectar(); con.Open(); SqlCommand com = new SqlCommand("delete ntvc.usuario_rol where cod_usuario = @cod_usuario", con); com.Parameters.AddWithValue("@cod_usuario", cod_usuario_); com.ExecuteNonQuery(); com = new SqlCommand("update ntvc.usuario set password = @password, habilitado = @habilitado where cod_usuario = @cod_usuario", con); com.Parameters.AddWithValue("@password", Encriptar.sha256(textPassword.Text)); com.Parameters.AddWithValue("@cod_usuario", cod_usuario_); if (chkHabilitado.Checked) { com.Parameters.AddWithValue("@habilitado", "1"); } else { com.Parameters.AddWithValue("@habilitado", "0"); } com.ExecuteNonQuery(); string cod_rol = ""; foreach (int indice in checkedListBox1.CheckedIndices) { com = new SqlCommand("select cod_rol from ntvc.rol where nombre = @nombre_rol", con); com.Parameters.AddWithValue("@nombre_rol", checkedListBox1.GetItemText(checkedListBox1.Items[indice]).ToString().Trim()); reader = com.ExecuteReader(); if (reader.Read()) { cod_rol = reader["cod_rol"].ToString().Trim(); } reader.Close(); com = new SqlCommand("insert into ntvc.usuario_rol (cod_rol, cod_usuario) values(@cod_rol, @cod_usuario)", con); com.Parameters.AddWithValue("@cod_rol", cod_rol); com.Parameters.AddWithValue("@cod_usuario", cod_usuario_); com.ExecuteNonQuery(); } this.Close(); MessageBox.Show("El usuario ha sido modificado.", "Modificación exitosa", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None); } }
public Usuario UsuarioConsultarPorUsuarioYContrsena(string correo, string contrasena) { string contrasenaEncryptar = Encriptar.encryptar(contrasena); return(Datos.UsuarioConsultarPorUsuarioYContrsena(correo, contrasenaEncryptar)); }
public bool loginUser(string user, string pass) { UsuarioDAL userDAL = new UsuarioDAL(); return(userDAL.Login(Encriptar.encriptar3DES(user, Encriptar.llave), Encriptar.encriptarMD5(pass))); }
public object[] Login() { listUsuarios = new List <TUsuarios>(); if (_textBox[0].Text.Equals("")) { _label[0].Text = "Correo Electrónico: Este campo es requerido"; _label[0].ForeColor = Color.Red; _textBox[0].Focus(); } else if (_textBox[1].Text.Equals("")) { _label[1].Text = "Contraseña: Este campo es requerido"; _label[1].ForeColor = Color.Red; _textBox[1].Focus(); } else { listUsuarios = TUsuarios.Where(u => u.Email.Equals(_textBox[0].Text)).ToList(); // Verificar que el email ya está registrado if (!listUsuarios.Count.Equals(0)) { // Verificar que el usuario está activo if (listUsuarios[0].Estado) { var encriptar = new Encriptar(); String password = encriptar.DecryptData(listUsuarios[0].Password, _textBox[0].Text); //pass.Equals(_textBox[1].Text) //listUsuarios[0].Password.Equals(_textBox[1].Text) if (password.Equals(_textBox[1].Text)) { BeginTransactionAsync(); try { var hdd = Ordenador.Serial(); TUsuarios.Where(u => u.IdUsuario.Equals(listUsuarios[0].IdUsuario)) .Set(u => u.Is_active, true) .Update(); var dataOrdenador = Tordenadores.Where(u => u.Ordenador.Equals(hdd)).ToList(); if (dataOrdenador.Count.Equals(0)) { Tordenadores.Value(u => u.Ordenador, hdd) .Value(u => u.Is_active, true) .Value(u => u.Usuario, listUsuarios[0].Email) .Value(u => u.InFecha, DateTime.Now) .Value(u => u.IdUsuario, listUsuarios[0].IdUsuario) .Insert(); } else { Tordenadores.Where(u => u.IdOrdenador.Equals(dataOrdenador[0].IdOrdenador)) .Set(u => u.Is_active, true) .Set(u => u.Usuario, listUsuarios[0].Email) .Set(u => u.InFecha, DateTime.Now) .Update(); } CommitTransaction(); } catch (Exception ex) { RollbackTransaction(); MessageBox.Show(ex.Message); } } else { _label[1].Text = "Contraseña incorrecta"; _label[1].ForeColor = Color.Red; _textBox[1].Focus(); listUsuarios.Clear(); } } else { listUsuarios.Clear(); MessageBox.Show("El usuario no está disponible", "Estado", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { _label[0].Text = "El email no está registrado"; _label[0].ForeColor = Color.Red; _textBox[0].Focus(); listUsuarios.Clear(); } } object[] objects = { listUsuarios }; return(objects); }
private void button7_Click(object sender, EventArgs e) { //SI ENTRAMOS DESDE AÑADIR NUEVO REGISTRO. if (Globales.llamadas == "1") { try { //**** calculamos el valor de la coluna numerador // var ultimocod = bd.Ususarios.OrderByDescending(x => x.cod).First().cod; //****GRABA LOS DATOS EN LA TABLA var nuevoUsuario = new Usantes(); nuevoUsuario.numerador = Convert.ToInt32(label1.Text); nuevoUsuario.nombre = textBox1.Text; // encriptamos la contaraseña con la clase encriptar nuevoUsuario.password = Encriptar.codificar(maskedTextBox1.Text); nuevoUsuario.nivel = comboBox1.Text; if (radioButton1.Checked == true) { nuevoUsuario.activo = true; } else { nuevoUsuario.activo = false; } nuevoUsuario.pregunta = textBox2.Text; nuevoUsuario.respuesta = Encriptar.codificar(textBox3.Text); bd.Usantes.Add(nuevoUsuario); //guardamos los cambios bd.SaveChanges(); } catch (Exception) { MessageBox.Show("No ha sido posible grabar los datos", "Error 101"); } } if (Globales.llamadas == "2") { try { //extraemos los datos correspondientes de la tabla en el objeto var usuarioAmodificar = bd.Usantes.SingleOrDefault(codusuario => codusuario.numerador == Globales.modificar); //modificamos los valores usuarioAmodificar.nombre = textBox1.Text; usuarioAmodificar.password = Encriptar.codificar(maskedTextBox1.Text); usuarioAmodificar.pregunta = textBox2.Text; usuarioAmodificar.respuesta = Encriptar.codificar(textBox3.Text); usuarioAmodificar.nivel = comboBox1.Text; if (radioButton1.Checked == true) { usuarioAmodificar.activo = true; } else { usuarioAmodificar.activo = false; } //guardamos los cambios bd.SaveChanges(); } catch (Exception) { MessageBox.Show("No ha sido posible modificar los datos", "Error 102"); } } Close(); }