private void boton_guardar_Click(object sender, EventArgs e) { nombre = txt_nom.Text; apellido = txt_ape.Text; edad = comboBox_edad.Text; peso = txt_peso.Text; temperatura = txt_temp.Text; telefono = txt_numero.Text; alergico = r_si.Text; alergico = r_no.Text; medicamento = txt_medi.Text; direccion = direc.Text; DialogResult xguardar = MessageBox.Show("¿Desea Guardar los Datos?", "PROGRAMACION II", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == xguardar) { ConexionDB StrConexionServer = new ConexionDB(); string StrCnnString = StrConexionServer.cadenaconexion(); SqlConnection conexion = new SqlConnection(StrCnnString); string insertarReg = "insert into DATOS (Nombre,Apellidos,Edad,peso,temperatura,Telefono,alergico,medicamento,direccion)" + "values ('" + nombre.ToString() + "' , '" + apellido.ToString() + "' , '" + edad.ToString() + "' , '" + peso.ToString() + "', '" + temperatura.ToString() + "' , '" + telefono.ToString() + "' , '" + alergico.ToString() + "' , '" + medicamento.ToString() + "' , '" + direccion.ToString() + "')"; SqlCommand Sql = new SqlCommand(insertarReg, conexion); try { if ((nombre == "" || apellido == "" || telefono == "" || direccion == "" || peso == "" || temperatura == "")) { MessageBox.Show("Por favor llenar todos los campos Obligatorios", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txt_nom.Focus(); } //else { MessageBox.Show("Datos almacenados Correctamente", "Almacenado", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { conexion.Open(); Sql.ExecuteNonQuery(); MessageBox.Show("LOS DATOS SE HAN ALACENADO CORRECTAMENTE", "Consultorio", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conexion.Dispose(); } } }
private void button1_Click_1(object sender, EventArgs e) { string Usuario = txtusuario.Text.Trim(); string Password = txtpassword.Text.Trim(); string usu = "u"; string pass = "******"; ConexionDB StrConexionServer = new ConexionDB(); String strCnnString = StrConexionServer.cadenaconexion(); SqlConnection conexion1 = new SqlConnection(strCnnString); SqlConnection conexion2 = new SqlConnection(strCnnString); try { string consulta = "SELECT * FROM Acceso WHERE Usuario ='" + Usuario + "'"; conexion1.Open(); SqlCommand sql = new SqlCommand(consulta, conexion1); SqlDataReader buscar_registro = sql.ExecuteReader(); Int32 filas = Convert.ToInt32(buscar_registro.HasRows); buscar_registro.Dispose(); if (filas > 0) { //MessageBox.Show("Usuario Corecto, Encontrado", "LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SqlDataAdapter adaptador = new SqlDataAdapter(consulta, conexion1); DataTable tb1 = new DataTable(); adaptador.Fill(tb1); txtusuario.Text = usu.ToString(); } else { MessageBox.Show("Usuario Incorrecto, NO ENCONTRADO", "SOFTWARE MEDICO", MessageBoxButtons.OK, MessageBoxIcon.Information); txtpassword.Text = ""; txtusuario.Text = ""; txtusuario.Focus(); } string consulta1 = "SELECT * FROM Acceso WHERE Password ='******'"; conexion2.Open(); SqlCommand sql1 = new SqlCommand(consulta1, conexion2); SqlDataReader buscar_registro1 = sql1.ExecuteReader(); Int32 filas1 = Convert.ToInt32(buscar_registro1.HasRows); buscar_registro1.Dispose(); if (filas1 > 0) { //MessageBox.Show("Password Correcto, Encontrado", "LOGIN", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SqlDataAdapter adaptador = new SqlDataAdapter(consulta1, conexion2); DataTable tb2 = new DataTable(); adaptador.Fill(tb2); txtpassword.Text = pass.ToString(); } else { MessageBox.Show("Password Incorrecto, NO ENCONTRADO", "SOFTWARE MEDICO", MessageBoxButtons.OK, MessageBoxIcon.Information); txtpassword.Text = ""; txtusuario.Text = ""; txtusuario.Focus(); } if ((usu == txtusuario.Text) && (pass == txtpassword.Text)) { MessageBox.Show("Bienvenido " + Usuario, " Login", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); } } catch { MessageBox.Show("ERROR DE CONEXION \n\n DIGITE SU USUARIO Y CONTRASEÑA CORRECTA", "SOFTWARE MEDICO", MessageBoxButtons.OK, MessageBoxIcon.Information); } }