-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mara
authored and
Mara
committed
Oct 2, 2024
1 parent
ed811f8
commit 05cedce
Showing
13 changed files
with
1,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
|
||
using System.Data.SqlClient; | ||
using System.Windows.Forms; | ||
using System.Data; | ||
|
||
|
||
namespace Libreta_Contactos | ||
{ | ||
internal class Contactos | ||
{ | ||
private int id; | ||
private string nombre; | ||
private string correo; | ||
private string fono; | ||
private string tipo; | ||
|
||
SqlConnection cn = new SqlConnection("Data Source=MARA-LLORET\\MSSQLSERVER02;Initial Catalog=BD_Contactos;Integrated Security=True"); | ||
|
||
public Contactos(int id, string nombre, string correo, string fono, string tipo) | ||
{ | ||
this.id = id; | ||
this.nombre = nombre; | ||
this.correo = correo; | ||
this.fono = fono; | ||
this.tipo = tipo; | ||
} | ||
|
||
public Contactos() { } | ||
|
||
|
||
public Contactos(int id) { | ||
this.id = id; | ||
|
||
} | ||
|
||
public int AgregarContacto() { | ||
cn.Open(); | ||
SqlCommand consulta = new SqlCommand("INSERT INTO tb_contactos VALUES (@nombre, @correo, @fono, @tipo)", cn); | ||
|
||
consulta.Parameters.AddWithValue("nombre", nombre); | ||
consulta.Parameters.AddWithValue("correo", correo); | ||
consulta.Parameters.AddWithValue("fono", fono); | ||
consulta.Parameters.AddWithValue("tipo", tipo); | ||
|
||
int filasAfectadas = consulta.ExecuteNonQuery(); | ||
cn.Close(); | ||
|
||
return filasAfectadas; | ||
|
||
} | ||
|
||
public void CargarContacos(DataGridView dtg) { | ||
|
||
string consulta = "SELECT * FROM tb_contactos"; | ||
cn.Open(); | ||
|
||
//ejecutar consulta en un adaptador, se guarda la info | ||
SqlDataAdapter data = new SqlDataAdapter(consulta, cn); | ||
|
||
//tabla virtual | ||
DataTable dt = new DataTable(); | ||
|
||
//llena la tabla con la info | ||
data.Fill(dt); | ||
|
||
//fuente de datos sea igual que la tabla virtual | ||
dtg.DataSource = dt; | ||
|
||
|
||
|
||
|
||
} | ||
|
||
public int EliminarContacto() { | ||
|
||
cn.Open(); | ||
SqlCommand consulta = new SqlCommand("DELETE FROM tb_contactos WHERE id = @codigo", cn); | ||
consulta.Parameters.AddWithValue("codigo", id); | ||
int filasAfectadas = consulta.ExecuteNonQuery(); | ||
cn.Close(); | ||
|
||
|
||
return filasAfectadas; | ||
|
||
} | ||
|
||
public int EditarContacto() { | ||
|
||
cn.Open(); | ||
SqlCommand consulta = new SqlCommand("UPDATE tb_Contactos SET nombre = @nombreContacto, correo = @email, fono = @tele, tipo = @tipoCliente WHERE id = @cod", cn); | ||
consulta.Parameters.AddWithValue("cod", id); | ||
consulta.Parameters.AddWithValue("nombreContacto", nombre); | ||
consulta.Parameters.AddWithValue("email", correo); | ||
consulta.Parameters.AddWithValue("tele", fono); | ||
consulta.Parameters.AddWithValue("tipoCliente", tipo); | ||
|
||
int filasAfectadas = consulta.ExecuteNonQuery(); | ||
cn.Close(); | ||
return filasAfectadas; | ||
|
||
} | ||
|
||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.