-
Notifications
You must be signed in to change notification settings - Fork 0
/
wfVerBitacoras.aspx.cs
548 lines (456 loc) · 20 KB
/
wfVerBitacoras.aspx.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
namespace AplicacionesEnatrel.Bitacoras
{
public partial class wfVerBitacoras : System.Web.UI.Page
{
string aplicacion = Properties.Settings.Default.aplicacion;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
llenarModulo();
}
}
private void BindDropDownList(ASPxComboBox ddl, string query, string text, string value, string defaultText)
{
u_static.setConx(aplicacion);
//string conString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(u_static.getConString()))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
con.Open();
ddl.DataSource = cmd.ExecuteReader();
ddl.TextField = text;
ddl.ValueField = value;
ddl.DataBind();
con.Close();
}
}
ddl.Items.Insert(0, new ListEditItem(defaultText, "0"));
ddl.SelectedIndex = 0;
}
private void llenarModulo()
{
string query =
"SELECT DISTINCT " +
"ab.modulo AS nombre, " +
"ab.modulo AS valor " +
"FROM Bitacora.AdmonBitacoras ab " +
"WHERE ab.estado = 1 ";
BindDropDownList(this.cbModulo, query, "nombre", "valor", "Seleccionar Módulo");
this.cbBD.Enabled = false;
this.cbEsquema.Enabled = false;
this.cbTabla.Enabled = false;
this.cbFiltro.Enabled = false;
//btVer.Enabled = false;
this.tbFechaIni.Enabled = false;
this.tbFechaFin.Enabled = false;
cbBD.Items.Insert(0, new ListEditItem("Seleccionar Base de Datos", "0"));
cbEsquema.Items.Insert(0, new ListEditItem("Seleccionar Esquema", "0"));
cbTabla.Items.Insert(0, new ListEditItem("Seleccionar Tabla", "0"));
cbFiltro.Items.Insert(0, new ListEditItem("Seleccionar Filtro", "0"));
Session["col"] = "col";
}
protected void Modulo_Changed(object sender, EventArgs e)
{
this.cbBD.Enabled = false;
this.cbEsquema.Enabled = false;
this.cbTabla.Enabled = false;
this.cbFiltro.Enabled = false;
this.tbFechaIni.Enabled = false;
this.tbFechaFin.Enabled = false;
//btVer.Enabled = false;
cbBD.Items.Clear();
cbEsquema.Items.Clear();
cbTabla.Items.Clear();
cbFiltro.Items.Clear();
tbFechaFin.Text = string.Empty;
tbFechaIni.Text = string.Empty;
cbBD.Items.Insert(0, new ListEditItem("Seleccionar Base de Datos", "0"));
cbEsquema.Items.Insert(0, new ListEditItem("Seleccionar Esquema", "0"));
cbTabla.Items.Insert(0, new ListEditItem("Seleccionar Tabla", "0"));
cbFiltro.Items.Insert(0, new ListEditItem("Seleccionar Filtro", "0"));
string ModuloId = cbModulo.SelectedItem.Value.ToString();
if (ModuloId != "")
{
string query =
string.Format(
" SELECT DISTINCT "+
" ab.bd AS nombre, "+
" ab.bd AS valor "+
" FROM Bitacora.AdmonBitacoras ab "+
" WHERE ab.estado = 1 "+
" AND ab.modulo = '{0}'", ModuloId);
BindDropDownList(this.cbBD, query, "nombre", "valor", "Seleccionar Base de Datos");
this.cbBD.Enabled = true;
}
}
protected void bd_Changed(object sender, EventArgs e)
{
this.cbEsquema.Enabled = false;
this.cbTabla.Enabled = false;
this.cbFiltro.Enabled = false;
this.tbFechaIni.Enabled = false;
this.tbFechaFin.Enabled = false;
//btVer.Enabled = false;
cbEsquema.Items.Clear();
cbTabla.Items.Clear();
cbFiltro.Items.Clear();
cbEsquema.Items.Insert(0, new ListEditItem("Seleccionar Esquema", "0"));
cbTabla.Items.Insert(0, new ListEditItem("Seleccionar Tabla", "0"));
cbFiltro.Items.Insert(0, new ListEditItem("Seleccionar Filtro", "0"));
string ModuloId = cbModulo.SelectedItem.Value.ToString();
string BDId = cbBD.SelectedItem.Value.ToString();
if (BDId != "" && ModuloId != "" )
{
object[] val = { ModuloId, BDId };
string query =
string.Format(
" SELECT DISTINCT " +
" ab.esquema AS nombre, " +
" ab.esquema AS valor " +
" FROM Bitacora.AdmonBitacoras ab " +
" WHERE ab.estado = 1 " +
" AND ab.modulo = '{0}' "+
" AND ab.bd = '{1}'", val );
BindDropDownList(this.cbEsquema, query, "nombre", "valor", "Seleccionar Esquema");
this.cbEsquema.Enabled = true;
}
}
protected void Esquema_Changed(object sender, EventArgs e)
{
this.cbTabla.Enabled = false;
this.cbFiltro.Enabled = false;
this.tbFechaIni.Enabled = false;
this.tbFechaFin.Enabled = false;
//btVer.Enabled = false;
cbTabla.Items.Clear();
cbFiltro.Items.Clear();
cbTabla.Items.Insert(0, new ListEditItem("Seleccionar Tabla", "0"));
cbFiltro.Items.Insert(0, new ListEditItem("Seleccionar Filtro", "0"));
string ModuloId = cbModulo.SelectedItem.Value.ToString();
string BDId = cbBD.SelectedItem.Value.ToString();
string EsquemaId = cbEsquema.SelectedItem.Value.ToString();
if (BDId != "" && ModuloId != "" && EsquemaId != "")
{
object[] val = { ModuloId, BDId, EsquemaId };
string query =
string.Format(
" SELECT DISTINCT " +
" ab.tabla AS nombre, " +
" ab.tabla AS valor " +
" FROM Bitacora.AdmonBitacoras ab " +
" WHERE ab.estado = 1 " +
" AND ab.modulo = '{0}' " +
" AND ab.bd = '{1}' " +
" AND ab.esquema = '{2}'", val);
BindDropDownList(this.cbTabla, query, "nombre", "valor", "Seleccionar Tabla");
this.cbTabla.Enabled = true;
}
}
protected void Tabla_Changed(object sender, EventArgs e)
{
this.cbFiltro.Enabled = false;
this.tbFechaIni.Enabled = false;
this.tbFechaFin.Enabled = false;
//btVer.Enabled = false;
cbFiltro.Items.Clear();
cbFiltro.Items.Insert(0, new ListEditItem("Seleccionar Filtro", "0"));
string ModuloId = cbModulo.SelectedItem.Value.ToString();
string BDId = cbBD.SelectedItem.Value.ToString();
string EsquemaId = cbEsquema.SelectedItem.Value.ToString();
string TablaId = cbTabla.SelectedItem.Value.ToString();
if (BDId != "" && ModuloId != "" && EsquemaId != "" && TablaId != "")
{
object[] val = { ModuloId, BDId, EsquemaId, TablaId };
string query =
string.Format(
" SELECT * "+
" FROM "+
" ( "+
" SELECT "+
" 'Fecha Doc.' as nombre, " +
" ab.fechaDoc as valor "+
" FROM Bitacora.AdmonBitacoras ab "+
" WHERE ab.estado = 1 "+
" AND ab.modulo = '{0}' "+
" AND ab.bd = '{1}' "+
" AND ab.esquema = '{2}' "+
" AND ab.tabla = '{3}' "+
" UNION "+
" SELECT "+
" 'Fecha Bit.' as nombre, " +
" ab.fechaBitacora as valor "+
" FROM Bitacora.AdmonBitacoras ab "+
" WHERE ab.estado = 1 "+
" AND ab.modulo = '{0}' "+
" AND ab.bd = '{1}' "+
" AND ab.esquema = '{2}' "+
" AND ab.tabla = '{3}' "+
" ) TABLA "+
" WHERE TABLA.valor IS NOT NULL "
, val);
BindDropDownList(this.cbFiltro, query, "nombre", "valor", "Seleccionar Filtro");
this.cbFiltro.Enabled = true;
}
}
protected void CbFiltro_Changed(object sender, EventArgs e)
{
string ModuloId = cbModulo.SelectedItem.Value.ToString();
string BDId = cbBD.SelectedItem.Value.ToString();
string EsquemaId = cbEsquema.SelectedItem.Value.ToString();
string TablaId = cbTabla.SelectedItem.Value.ToString();
string Filtro = cbFiltro.SelectedItem.Value.ToString();
string campo = null;
string cbit = null;
if (cbFiltro.SelectedItem.Text.Contains("Fecha Doc."))
{
campo = "fechaDoc";
cbit = "fechaDocxDia";
}
else
{
campo = "fechaBitacora";
cbit = "fechaBitxDia";
}
if (BDId != "" && ModuloId != "" && EsquemaId != "" && TablaId != "" && Filtro != "")
{
object[] val = {cbit, ModuloId, BDId, EsquemaId, TablaId, campo, Filtro };
string query =
string.Format(
" SELECT "+
" ab.{0} " +
" FROM Bitacora.AdmonBitacoras ab "+
" WHERE ab.estado = 1 "+
" AND ab.modulo = '{1}' "+
" AND ab.bd = '{2}' "+
" AND ab.esquema = '{3}' "+
" AND ab.tabla = '{4}' "+
" AND ab.{5} = '{6}' "
, val);
u_static.setConx(aplicacion);
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(u_static.getConString());
SqlDataAdapter da = new SqlDataAdapter(query, con);
da.Fill(ds, "Tabla");
if (ds.Tables[0].Rows.Count > 0)
{
this.tbFechaIni.Enabled = true;
if (bool.Parse(ds.Tables[0].Rows[0][0].ToString()) == true)
tbFechaFin.Enabled = false;
else
tbFechaFin.Enabled = true;
}
//btVer.Enabled = true;
}
}
private void verificarTablaDetalle()
{
string BDId = cbBD.SelectedItem.Value.ToString();
string EsquemaId = cbEsquema.SelectedItem.Value.ToString();
string TablaId = cbTabla.SelectedItem.Value.ToString();
string modulo = cbModulo.SelectedItem.Value.ToString();
string query =
" SELECT * " +
" FROM " +
" ( " +
" SELECT " +
" ab.tablaDetalle, " +
" ab.cPrincipal, " +
" ab.cDetalle " +
" FROM " +
" Bitacora.AdmonBitacoras ab " +
" WHERE " +
" ab.modulo = '" + modulo + "' AND " +
" ab.bd = '"+BDId+"' AND " +
" ab.esquema = '" + EsquemaId + "' AND " +
" ab.tabla = '" + TablaId + "' " +
" ) t " +
" where t.tablaDetalle IS NOT NULL ";
u_static.setConx(aplicacion);
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(u_static.getConString());
SqlDataAdapter da = new SqlDataAdapter(query, con);
da.SelectCommand.CommandTimeout = 0;
da.Fill(ds, "Tabla");
if (ds.Tables[0].Rows.Count > 0)
{
gvBit.KeyFieldName = ds.Tables[0].Rows[0]["cPrincipal"].ToString();
gvBit.SettingsDetail.ShowDetailRow = true;
hfTabla.Value = BDId + "." + EsquemaId + "." + ds.Tables[0].Rows[0]["tablaDetalle"].ToString();
hfCampo.Value = ds.Tables[0].Rows[0]["cDetalle"].ToString();
}
else
{
gvBit.KeyFieldName = string.Empty;
gvBit.SettingsDetail.ShowDetailRow = false;
hfTabla.Value = "";
hfCampo.Value = "";
}
}
private DataSet GetDetalle(string tabla, string campo, string id)
{
DataSet ds = new DataSet();
String query = "SELECT * FROM " + tabla + " WHERE " + campo + "=" + id;
u_static.setConx(aplicacion);
SqlConnection cn = new SqlConnection(u_static.getConString());
SqlDataAdapter da = new SqlDataAdapter(query, cn);
da.Fill(ds, "Detalle");
return ds;
}
private bool verificarControles()
{
bool control = false;
int cont = 0;
if (cbBD.SelectedIndex < 1)
cont += 1;
if (cbEsquema.SelectedIndex < 1)
cont += 1;
if (cbTabla.SelectedIndex < 1)
cont += 1;
if (cbFiltro.SelectedIndex < 1)
cont += 1;
DateTime d1 = DateTime.Today;
DateTime d2 = DateTime.Today;
if (tbFechaIni.Enabled == false)
cont += 1;
if (!DateTime.TryParse(tbFechaIni.Text.Trim(), out d1))
{
cont += 1;
}
if (tbFechaFin.Enabled == true)
{
if (!DateTime.TryParse(tbFechaFin.Text.Trim(), out d2))
{
cont += 1;
}
}
if (cont == 0)
control = true;
return control;
}
private DataTable getSource()
{
DataTable dt = new DataTable();
string BDId = cbBD.SelectedItem.Value.ToString();
string EsquemaId = cbEsquema.SelectedItem.Value.ToString();
string TablaId = cbTabla.SelectedItem.Value.ToString();
string Filtro = cbFiltro.SelectedItem.Value.ToString();
string fechaIni = tbFechaIni.Text;
string fechaFin = tbFechaFin.Text;
object[] val = { BDId, EsquemaId, TablaId, Filtro, fechaIni, fechaFin };
string query = string.Empty;
if (tbFechaFin.Enabled == true)
query = string.Format(
" SELECT * " +
" FROM {0}.{1}.{2} AS x " +
" WHERE x.{3} BETWEEN '{4}' AND '{5}' "
, val);
else
query = string.Format(
" SELECT * " +
" FROM {0}.{1}.{2} AS x " +
" WHERE x.{3} = '{4}' "
, val);
u_static.setConx(aplicacion);
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(u_static.getConString());
SqlDataAdapter da = new SqlDataAdapter(query, con);
da.SelectCommand.CommandTimeout = 0;
da.Fill(dt);
verificarTablaDetalle();
return dt;
}
protected void btVer_Click(object sender, ImageClickEventArgs e)
{
try
{
if (verificarControles())
{
gvBit.Columns.Clear();
gvBit.DataBind();
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert('Seleccione las opciones y fechas requeridas');", true);
}
catch { }
}
protected void btRegresar_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/Management/opciones.aspx");
}
protected void btExportar_Click(object sender, ImageClickEventArgs e)
{
try
{
this.gvExporter.WriteXlsToResponse();
}
catch { }
}
protected void gvDetalle_BeforePerformDataSelect(object sender, EventArgs e)
{
try
{
ASPxGridView detailGridView = (ASPxGridView)sender;
detailGridView.DataSource = GetDetalle(hfTabla.Value, hfCampo.Value, detailGridView.GetMasterRowKeyValue().ToString());
hfIdMaster.Value = detailGridView.GetMasterRowKeyValue().ToString();
}
catch { }
}
protected void gvBit_BeforePerformDataSelect(object sender, EventArgs e)
{
try
{
if (verificarControles())
{
(sender as ASPxGridView).DataSource = getSource();
//verificarTablaDetalle();
}
}
catch { }
}
protected void gvBit_Load(object sender, EventArgs e)
{
try
{
if (verificarControles())
{
(sender as ASPxGridView).AutoGenerateColumns = true;
(sender as ASPxGridView).DataBind();
}
}
catch { }
}
bool bnd = false;
protected void gvBit_PageIndexChanged(object sender, EventArgs e)
{
//try
//{
// if (IsPostBack && bnd != true)
// {
// // gvBit.Columns.Clear();
// gvBit.DataBind();
// bnd = true;
// }
//}
//catch
//{
//}
//flag = true;
//gvBit.DataBind();
//flag = false;
}
}
}