-
Notifications
You must be signed in to change notification settings - Fork 1
/
Check.cs
220 lines (188 loc) · 9.35 KB
/
Check.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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;
using MySql.Data.MySqlClient;
namespace MasterCheck2._0
{
public partial class Check : Form
{
public Check()
{
InitializeComponent();
}
BaseDeDatos db = new BaseDeDatos();
string cnn = @"SERVER=localhost; DATABASE=mastercheck; UID=root; PASSWORD=12345";
private void Check_Load(object sender, EventArgs e)
{
Eliminar.Start();
Insertar.Start();
}
private void btnEx_Click(object sender, EventArgs e)
{
/*
string sql = "select count(*) from checks where (ID = @ID)";
// string sql2 = "select count(*) from checks where (ID = @IDS) and (Entrada=@Entrada)";
using (MySqlConnection cn = new MySqlConnection(cnn))
{
cn.Open();
using (MySqlCommand cmd = new MySqlCommand(sql, cn))
{
cmd.Parameters.AddWithValue("@ID", textBox1.Text);
var result = Convert.ToInt32(cmd.ExecuteScalar());
if (result > 0)
{
string alter = string.Format("update checks set Salida ='{0}' where ID='{1}'", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), textBox1.Text);
string his = string.Format("insert into salida values('{0}','{1}')", textBox1.Text ,DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.executecommand(alter);
db.executecommand(his);
lblNom.Text= textBox1.Text;
lblSal.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
lblEnt.Visible = true;
lblEntrada.Visible = true;
lblID.Visible = true;
lblNom.Visible = true;
lblSal.Visible = true;
lblSalida.Visible = true;
}
else
{
//
var cn2 = new MySqlConnection(cnn);
cn2.Open();
MySqlCommand cmd2 = cn.CreateCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "select * from registros where idrfid='" + textBox1.Text + "'";
cmd2.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd2);
da.Fill(dt);
foreach(DataRow dr in dt.Rows)
{
lblNom.Text = dr["Nombre"].ToString();
lbldepartamento.Text = dr["Departamento"].ToString();
}
//
string add = string.Format("insert into checks (`ID`,`Entrada`,`Salida`) values ('{0}','{1}','{2}')", textBox1.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "");
string historial = string.Format("insert into entrada values ('{0}','{1}')", textBox1.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "");
string asistencia = string.Format("update registros set Asistencias = Asistencias + 1 where idrfid = 1");
db.executecommand(asistencia);
db.executecommand(add);
db.executecommand(historial);
lblEnt.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
mensaje.Enabled = true;
mensaje.Start();
}
}
}
*/
}
private void mensaje_Tick(object sender, EventArgs e)
{
lblEnt.Text = "";
lblNom.Text = "";
lblSal.Text = "";
lbldepartamento.Text = "";
textBox1.Text = "";
dataGridView1.DataSource = null;
}
private void btnhistorial_Click(object sender, EventArgs e)
{
string his = string.Format("select * from entrada where id='{0}'", textBox1.Text);
dataGridView1.DataSource = db.SelectDataTable(his);
}
private void Insertar_Tick(object sender, EventArgs e)
{
string sql = "select count(*) from checks where (ID = @ID)";
// MessageBox.Show("Se inserto dato",textBox1.Text);
using (MySqlConnection cn = new MySqlConnection(cnn))
{
cn.Open();
using (MySqlCommand cmd = new MySqlCommand(sql, cn))
{
cmd.Parameters.AddWithValue("@ID", textBox1.Text);
var result = Convert.ToInt32(cmd.ExecuteScalar());
if (result > 0)
{
string alter = string.Format("update checks set Salida ='{0}' where ID='{1}'", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), textBox1.Text);
string his = string.Format("insert into salida values('{0}','{1}')", textBox1.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.executecommand(alter);
db.executecommand(his);
//
var cn2 = new MySqlConnection(cnn);
cn2.Open();
MySqlCommand cmd2 = cn.CreateCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "select * from registros where idrfid='" + textBox1.Text + "'";
cmd2.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd2);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
lblNom.Text = dr["Nombre"].ToString();
lbldepartamento.Text = dr["Departamento"].ToString();
lblSal.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
//
lblEnt.Visible = true;
lblEntrada.Visible = true;
lblID.Visible = true;
lblNom.Visible = true;
lblSal.Visible = true;
lblSalida.Visible = true;
mensaje.Start();
string hist = string.Format("select id, sal as salida from salida where id='{0}'", textBox1.Text);
dataGridView1.DataSource = db.SelectDataTable(hist);
}
else
{
//
var cn2 = new MySqlConnection(cnn);
cn2.Open();
MySqlCommand cmd2 = cn.CreateCommand();
cmd2.CommandType = CommandType.Text;
cmd2.CommandText = "select * from registros where idrfid='" + textBox1.Text + "'";
cmd2.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd2);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
lblNom.Text = dr["Nombre"].ToString();
lbldepartamento.Text = dr["Departamento"].ToString();
lblEnt.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
//
string add = string.Format("insert into checks (`ID`,`Entrada`,`Salida`) values ('{0}','{1}','{2}')", textBox1.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "");
string historial = string.Format("insert into entrada values ('{0}','{1}')", textBox1.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "");
string asistencia = string.Format("update registros set Asistencias = Asistencias + 1 where idrfid = 1");
db.executecommand(asistencia);
db.executecommand(add);
db.executecommand(historial);
// mensaje.Enabled = true;
mensaje.Start();
string hist = string.Format("select * from entrada where id='{0}'", textBox1.Text);
dataGridView1.DataSource = db.SelectDataTable(hist);
}
}
}
}
private void Eliminar_Tick(object sender, EventArgs e)
{
string el = string.Format("delete table checks");
if (db.executecommand(el))
{
MessageBox.Show("se borraron los registros");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}