-
Notifications
You must be signed in to change notification settings - Fork 0
/
Usuarios_Datos.cs
96 lines (87 loc) · 3.08 KB
/
Usuarios_Datos.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using MySql.Data.MySqlClient;
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 DeepTec
{
public partial class Usuarios_Datos : Form
{
public Usuarios_Datos()
{
InitializeComponent();
}
private void btnAgregar_Click(object sender, EventArgs e)
{
try
{
frmMenu mn = new frmMenu();
string query = "Insert Into usuarios Values('"+txtID.Text+"', '"+txtUsuario.Text+"', '"+txtContraseña.Text+"', '"+txtRango.Text+"') ;";
MySqlConnection MyConn2 = new MySqlConnection(mn.ConexDBGlobal);
MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2);
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();
MessageBox.Show("Datos Guardados!");
this.Close();
while (MyReader2.Read())
{
}
MyConn2.Close();
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void CargarDatos(string id)
{
txtID.ReadOnly = true;
frmMenu mn = new frmMenu();
var c = new MySqlConnection(mn.ConexDBGlobal);
string cif = "SELECT * FROM usuarios WHERE id_usuario='" + id + "'";
MySqlCommand cmd = new MySqlCommand(cif, c);
MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
string vcif = string.Empty;
try
{
DataRow row = dt.Rows[0];
txtID.Text = row["id_usuario"].ToString();
txtUsuario.Text = row["usuario"].ToString();
txtContraseña.Text = row["contra"].ToString();
txtRango.Text = row["rango"].ToString();
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnEditar_Click(object sender, EventArgs e)
{
try
{
frmMenu mn = new frmMenu();
string query = "Update usuarios Set usuario='"+txtUsuario.Text+ "', contra='"+txtContraseña.Text+ "', rango='"+txtRango.Text+"' where id_usuario='"+txtID.Text+"';";
MySqlConnection conn = new MySqlConnection(mn.ConexDBGlobal);
MySqlCommand cmd = new MySqlCommand(query, conn);
MySqlDataReader Read;
conn.Open();
Read = cmd.ExecuteReader();
MessageBox.Show("Datos Actualizados");
while (Read.Read())
{
}
conn.Close();
this.Close();
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}