-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trasplantes_Datos.cs
125 lines (116 loc) · 4.14 KB
/
Trasplantes_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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 Trasplantes_Datos : Form
{
public Trasplantes_Datos()
{
InitializeComponent();
}
private int StrToInt(string s)
{
if(s == "Exitosa")
{
return 1;
}
else
{
return 0;
}
}
private void btnAgregar_Click(object sender, EventArgs e)
{
try
{
frmMenu mn = new frmMenu();
string query = "Insert Into trasplante Values('"+txtID.Text+"', '"+txtIdOrgano.Text+"', '"+txtIdDonador.Text+"', '"+txtIdReceptor.Text+"', '"+txtCedulaDoctor.Text+"', '"+txtFecha.Text+"', b'"+ StrToInt(cmbEstado.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();
this.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void CargaDatos(string id)
{
txtID.ReadOnly = true;
frmMenu mn = new frmMenu();
var c = new MySqlConnection(mn.ConexDBGlobal);
string cif = "SELECT * FROM trasplante WHERE clave_trasplante='" + 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["clave_trasplante"].ToString();
txtIdOrgano.Text = row["id_organo"].ToString();
txtIdDonador.Text = row["id_donador"].ToString();
txtIdReceptor.Text = row["id_receptor"].ToString();
txtCedulaDoctor.Text = row["cedula_doctor"].ToString();
DateTime d = Convert.ToDateTime( row["fecha_cirugia"]);
txtFecha.Text = d.ToString("yyyy/MM/dd");
if(row["estatus_cirugia"].ToString() == "1")
{
cmbEstado.Text = "Exitosa";
}
else
{
cmbEstado.Text = "Fallida";
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnModificar_Click(object sender, EventArgs e)
{
try
{
frmMenu mn = new frmMenu();
string query = "Update trasplante Set id_organo='" + txtIdOrgano.Text + "', id_donador='" + txtIdDonador.Text
+ "', id_receptor='" + txtIdReceptor.Text + "', cedula_doctor='" + txtCedulaDoctor.Text + "', fecha_cirugia='" + txtFecha.Text +
"', estatus_cirugia=b'" + StrToInt(cmbEstado.Text)
+ "' where clave_trasplante='"+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);
}
}
}
}