Вы находитесь на странице: 1из 11

AP7-AA4-Ev1-Desarrollo de aplicaciones Windows con C# y Visual Studio .

NET

EDNA ROCIO PARRA GOMEZ

Análisis y Desarrollo de Sistemas de Información SENA

Bogotá, Colombia

2019
AP7-AA4-Ev1-Desarrollo de aplicaciones Windows con C# y Visual Studio .NET

1. Creación de base de datos


create table usuario (id_usuario int identity primary key,
nombre_usuario varchar (30),
contraseña varchar (200));

create table jugadores (id_jugador int identity primary key,


nombre_completo varchar (50),
cedula varchar(10),
telefono varchar(20),
posicion varchar(20),
estado varchar(20));

insert into usuario(nombre_usuario, contraseña)


values('rocio' , '1234');

select *from usuario;

insert into jugadores(nombre_completo, cedula, telefono, posicion,estado)


values('James Rodriguez', '1546456456', '321456454','Extremo Isq','lesion');
select * from jugadores;
2. Creación de interfaz grafítica
3. Métodos de loguear Form1.cs

4. using System;
5. using System.Collections.Generic;
6. using System.ComponentModel;
7. using System.Data;
8. using System.Drawing;
9. using System.Linq;
10. using System.Text;
11. using System.Threading.Tasks;
12. using System.Windows.Forms;
13.
14. namespace Maneger
15. {
16. public partial class Form1 : Form
17. {
18. public Form1()
19. {
20. InitializeComponent();
21. }
22. controlador con = new controlador();
23. private void btniniciar_Click(object sender, EventArgs e)
24. {
25. con.loguear(txtnombreu.Text, txtcontraseña.Text);
26. }
27.
28. private void Form1_Load(object sender, EventArgs e)
29. {
30. con.conetar();
31. }
32. }
33. }

4. Controlados cs conexión base de datos , loguear, insertar datos, modificar y eliminar

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Maneger
{
class controlador
{
SqlConnection con = new SqlConnection("Data Source=.;Initial
Catalog=eqipo;Integrated Security=true");
private SqlCommandBuilder cmb;
public SqlDataAdapter da;
public DataSet ds = new DataSet();
public SqlCommand comando;
public SqlDataReader lector;

public void conetar()


{
try
{
con.Open();
MessageBox.Show("Conexion a Base de Datos Ok");
}
catch
{
MessageBox.Show("Error de conexion");
}
finally
{
con.Close();
}

}
public void loguear(string nombre_usuario, string contraseña)
{
bool confirmacion_de_ingreso = false;
con.Open();
string consulta = "select * from usuario";
comando = new SqlCommand(consulta, con);
lector = comando.ExecuteReader();
try
{
while (lector.Read())
if (lector.GetString(1).Equals(nombre_usuario) &&
lector.GetString(2).Equals(contraseña))
confirmacion_de_ingreso = true;
vista.manager manag = new vista.manager();
manag.ShowDialog();
}
catch (Exception error)
{
MessageBox.Show(error.Message);
}
finally
{
if (confirmacion_de_ingreso == false)
{
MessageBox.Show("No se encuentra registrdo en el sistema");
}
}
con.Close();
}
public void consultar(string sql, string tabla)
{
ds.Tables.Clear();
da = new SqlDataAdapter(sql, con);
cmb = new SqlCommandBuilder(da);
da.Fill(ds, tabla);
}
public bool insertar_jugador(String nombre_completo, String cedula, string
telefono, String posicion, string estado)
{
con.Open();
string insertar = "insert into jugadores(nombre_completo, cedula,
telefono, posicion, estado) values(@nombre,@cedula,@telefono,@posicion,@estado)";
comando = new SqlCommand(insertar, con);

comando.Parameters.Add("@nombre", SqlDbType.VarChar);
comando.Parameters.Add("@cedula", SqlDbType.VarChar);
comando.Parameters.Add("@telefono", SqlDbType.VarChar);
comando.Parameters.Add("@posicion", SqlDbType.VarChar);
comando.Parameters.Add("@estado", SqlDbType.VarChar);

comando.Parameters["@nombre"].Value = nombre_completo;
comando.Parameters["@cedula"].Value = cedula;
comando.Parameters["@telefono"].Value = telefono;
comando.Parameters["@posicion"].Value = posicion;
comando.Parameters["@estado"].Value = estado;

int x = comando.ExecuteNonQuery();
con.Close();
if (x > 0)
{
return true;
}
else
{
return false;
}

public bool modificar(string tabla, string campos, string condicion)


{
con.Open();
string modifica = " update " + tabla + " set " + campos + " where " +
condicion;
comando = new SqlCommand(modifica, con);
int x = comando.ExecuteNonQuery();
con.Close();
if (x > 0)
{
return true;
}
else
{
return false;
}
}
public bool eliminar(string tabla, string condicion)
{
con.Open();
string elimina = "delete from " + tabla + "where" + condicion;
comando = new SqlCommand(elimina, con);
int x = comando.ExecuteNonQuery();
con.Close();
if (x > 0)
{
return true;
}
else
{
return false;
}
}
}
}

5. Manager.sc conexión a base de datos para modificación de datos

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Maneger.vista
{
public partial class manager : Form
{

public manager()
{
InitializeComponent();
}
controlador con = new controlador();
private void btnnuevo_Click(object sender, EventArgs e)
{
btncrearjugador.Enabled = true;
btneliminarjugador.Enabled = false;
btnmodificarjugado.Enabled = false;
txtcedula.Enabled = true;
txtNombres.Enabled = true;
txtestado.Enabled = true;
txttelefono.Enabled = true;
txtposicion.Enabled = true;

txtNombres.Clear();
txtcedula.Clear();
txttelefono.Clear();
txtposicion.Clear();
txtestado.Clear();

private void btnmodificar_Click(object sender, EventArgs e)


{
btncrearjugador.Enabled = false;
btnmodificarjugado.Enabled = true;
txtcedula.Enabled = false;
txtNombres.Enabled = false;
txtestado.Enabled = true;
txttelefono.Enabled = true;
txtposicion.Enabled = true;

private void btneliminar_Click(object sender, EventArgs e)


{
btncrearjugador.Enabled = false;
btnmodificarjugado.Enabled = false;
btneliminarjugador.Enabled = true;
txtcedula.Enabled = false;
txtNombres.Enabled = false;
txtestado.Enabled = true;
txttelefono.Enabled = true;
txtposicion.Enabled = true;
}

private void btnsalir_Click(object sender, EventArgs e)


{
this.Close();
}

private void manager_Load(object sender, EventArgs e)


{
mostrarDatos();
}
public void mostrarDatos()
{
con.consultar("select * from jugadores", "jugadores");
dataGridView1.DataSource = con.ds.Tables["jugadores"];

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{
DataGridViewRow dgv = dataGridView1.Rows[e.RowIndex];
txtid.Text = dgv.Cells[0].Value.ToString();
txtNombres.Text = dgv.Cells[1].Value.ToString();
txtcedula.Text = dgv.Cells[2].Value.ToString();
txttelefono.Text = dgv.Cells[3].Value.ToString();
txtposicion.Text = dgv.Cells[4].Value.ToString();
txtestado.Text = dgv.Cells[5].Value.ToString();

private void btncrearjugador_Click(object sender, EventArgs e)


{

if(con.insertar_jugador(txtNombres.Text,txtcedula.Text,txttelefono.Text,txtposicion.
Text,txtestado.Text))
{
MessageBox.Show("Datos agregados correctamente");
mostrarDatos();
}
else
{
MessageBox.Show("Error al agregar datos");
}
}

private void btnmodificarjugado_Click(object sender, EventArgs e)


{
string modifica = "telefono='" + txttelefono.Text + "', posicion='" +
txtposicion.Text + "', estado= '" + txtestado.Text + "'";
if (con.modificar("jugadores", modifica, "id_jugador=" + txtid.Text + "
"))
{
MessageBox.Show("Datos de jugador cargados correctamente");
mostrarDatos();
}
else
{
MessageBox.Show("Error al cargar datos");
}
}

private void btneliminarjugador_Click(object sender, EventArgs e)


{
if (con.eliminar(" jugadores ", " id_jugador = " + txtid.Text))
{
MessageBox.Show("Registro del jugador eliminado");
mostrarDatos();
}
else
{
MessageBox.Show("Error al eliminar");
}
}
}
}
6. Documentación gráfica de la aplicación

6.1. Mensaje de conexión a base de datos

6.2. Inicio de sesión


6.3. Grilla de aplicación

Вам также может понравиться