-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfrmMain.cs
407 lines (334 loc) · 14.7 KB
/
frmMain.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinControl_ELR_NET;
namespace SysProcesosERP
{
public partial class frmMain : Form
{
List<Proceso> procesosList = new List<Proceso>();
List<Tarea> tareaList = new List<Tarea>();
ELRUtils objUtil = new ELRUtils();
DataTable DTData = null;
DataTable DTTareasPendientes = null;
DataDB_ELR_NET.DataDB db = new DataDB_ELR_NET.DataDB();
string mensajeError = "";
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
Proceso myProc = new Proceso();
try
{
dtpFeDesde.Value = DateTime.Now.Date;
dtpFeHasta.Value = DateTime.Now.Date;
dtpError1.Value = DateTime.Now.Date;
dtpError2.Value = DateTime.Now.Date;
db.NOMBRE_USUARIO = objUtil.nombreUsuarioPC;
lblEnEjecusion.Text = "EN EJECUSION DESDE: " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt");
//Marcamos las tareas no completada para entrar en cola otra vez
myProc.colocarPendienteACola();
llenarListTarea();
chkAutoRefresh.Checked = true;
showHistorial();
timerEjecutaProcesos.Start();
}
catch (Exception ex)
{
mensajeError = ex.Message;
}
}
void llenarListTarea()
{
tareaList = new List<Tarea>();
tareaList.Add(new Tarea("BK", "REALIZAR BACKUP"));
tareaList.Add(new Tarea("COPER", "CERRAR OPERACIONES"));
tareaList.Add(new Tarea("CONTA", "GENERAR ASIENTOS CONTABLE"));
tareaList.Add(new Tarea("DEMORA", "GENERAR DEMORA"));
tareaList.Add(new Tarea("AF-DEPRE", "DEPRECIACION DE ACTIVOS FIJOS"));
tareaList.Add(new Tarea("PGO-GTOS-FIJOS", "PAGO DE GASTOS FIJOS"));
tareaList.Add(new Tarea("SP", "EJECUTAR STORE PROCEDURE"));
//ANADIMOS TAREA DE MANTENIMIENTO DE LA BASE DE DATOS
tareaList.Add(new Tarea("CLS-TBL-TEMP", "LIMPIAR TABLAS TEMPORALES"));
tareaList.Add(new Tarea("LIMPIAR_LOG_DB", "LIMPIAR LOG FILE DATABASE"));
tareaList.Add(new Tarea("DFOLDER_BK", "ELIMINAR ARCHIVOS BACKUP"));
tareaList.Add(new Tarea("RB-DB-INDICES", "RECONSTRUIR INDICES"));
cboTareas.DataSource = tareaList;
cboTareas.ValueMember = "codigo";
cboTareas.DisplayMember = "nombre";
cboTareas.DropDownStyle = ComboBoxStyle.DropDownList;
}
void showHistorial()
{
Proceso procSys = new Proceso();
int index = -1, colId = -1;
try
{
if (dtgHistorico.RowCount > 0)
{
index = dtgHistorico.CurrentRow.Index;
colId = dtgHistorico.CurrentCell.ColumnIndex;
}
this.Cursor = Cursors.WaitCursor;
DTData = procSys.GetHistorico(dtpFeDesde.Value, dtpFeHasta.Value);
dtgHistorico.AutoGenerateColumns = false;
dtgHistorico.DataSource = DTData;
if (dtgHistorico.RowCount - 1 >= index)
{
dtgHistorico.CurrentCell = dtgHistorico[colId, index];
dtgHistorico.CurrentCell.Selected = true;
}
}
catch (Exception)
{
//objUtil.MostrarMensajeError(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
void showErrores()
{
Proceso procSys = new Proceso();
try
{
this.Cursor = Cursors.WaitCursor;
DTData = procSys.GetErrorHistorico(dtpError1.Value, dtpError2.Value);
dtgErrores.AutoGenerateColumns = false;
dtgErrores.DataSource = DTData;
}
catch (Exception)
{
//objUtil.MostrarMensajeError(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
void addTarea()
{
Proceso myProceso = new Proceso();
string codigo = "", descripcion = "";
try
{
codigo = cboTareas.SelectedValue.ToString();
descripcion = cboTareas.Text;
if (codigo == "SP") return;
tabControl1.SelectedIndex = 0;
myProceso.addProceso(codigo, descripcion);
showHistorial();
}
catch (Exception ex)
{
objUtil.MostrarMensajeError(ex.Message);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void btnBackup_Click(object sender, EventArgs e)
{
}
private void btnBuscar_Click(object sender, EventArgs e)
{
showHistorial();
}
private void timerEjecutaProcesos_Tick(object sender, EventArgs e)
{
string codigo = "";
int valorUnico = 0, tareaId = 0;
DateTime feActual = DateTime.Now;
try
{
if (chkAutoRefresh.Checked)
{
dtpFeDesde.Value = feActual.Date;
dtpFeHasta.Value = feActual.Date;
}
//Agregamos la tareas a la cola de ejecusion
addTareasACola();
//Buscamos las tareas pendientes
db.LimpiarFiltros();
db.AddFiltroNoIgualA("Codigo", "PI");
db.AddFiltroIgualA("Estatus_Id", "0");
db.AddFiltroIsNull("Fecha_Completado");
db.AddFiltroIsNull("Fecha_Fin");
db.AddFiltroOrderBY("Unico");
DTTareasPendientes = db.GetAll("TSISTEMA_PROCESOS_LOG", -1, db.Filtros);
stLabelFecha.Text = "FECHA: " + feActual.ToLongDateString().ToUpper() + " " + feActual.ToLongTimeString().ToUpper();
foreach (DataRow item in DTTareasPendientes.Rows)
{
valorUnico = db.GetAsInt("Unico", item);
tareaId = db.GetAsInt("Tarea_Id", item);
codigo = db.GetAsString("Codigo", item).ToUpper().Trim();
Proceso myProc = new Proceso();
myProc.fecha = db.GetAsDate("Fecha", item);
myProc.identificadorId = db.GetAsInt("Identificador_Id", item);
myProc.codigo = codigo;
myProc.tareaId = tareaId;
myProc.nombre = db.GetAsString("Descripcion", item).ToUpper().Trim();
myProc.nombreSP = db.GetAsString("NombreSP", item).Trim();
//Marcamos la tarea como en proceso
myProc.setEstatus(1, valorUnico);
//if (codigo == "COPER") myProc.esReinicioOnError = true;
if (codigo == "BK")myProc.t = new Thread(myProc.realizarBackup);
if (codigo == "COPER") myProc.t = new Thread(myProc.realizarCierreOPE);
if (codigo == "DEMORA") myProc.t = new Thread(myProc.generarDemora);
if (codigo == "CONTA") myProc.t = new Thread(myProc.generarContabilidad);
if (codigo == "LIMPIAR_LOG_DB") myProc.t = new Thread(myProc.limpiarLogDB);
if (codigo == "DFOLDER_BK") myProc.t = new Thread(myProc.borrarFilesBK);
if (codigo == "CLS-TBL-TEMP") myProc.t = new Thread(myProc.limpiarTablasTemporales);
if(codigo == "PGO-GTOS-FIJOS") myProc.t = new Thread(myProc.GenerarPagoGastosFijos);
if(codigo == "AF-DEPRE") myProc.t = new Thread(myProc.GenerarAFDepreciacion);
if(codigo == "RB-DB-INDICES") myProc.t = new Thread(myProc.RebuildDBIndices);
if (codigo == "SP" && myProc.nombreSP != "") myProc.t = new Thread(myProc.EjecutaSP);
if (myProc.t != null)
{
myProc.t.Start();
procesosList.Add(myProc);
}
}
for (int i = 0; i < procesosList.Count; i++)
{
if (procesosList[i].estatusId != 0 && procesosList[i].estatusId != 1) procesosList.Remove(procesosList[i]);
}
lblCantidadActivos.Text = "CANTIDAD PROCESOS ACTIVOS: " + procesosList.Count.ToString("N0");
ptbProcess.Visible = procesosList.Count > 0;
if (chkAutoRefresh.Checked) showHistorial();
}
catch (Exception ex)
{
mensajeError = ex.Message;
}
}
private void salirToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void btnErrorBuscar_Click(object sender, EventArgs e)
{
showErrores();
}
private void btnAgregarTarea_Click(object sender, EventArgs e)
{
addTarea();
}
private void ejecutarToolStripMenuItem_Click(object sender, EventArgs e)
{
FormSchedule frm = new FormSchedule();
frm.nombreUsuario = objUtil.nombreUsuarioPC;
frm.empresaID = 1;
frm.oficinaID = 0;
frm.EnEjecusion = true;
frm.tareaList = tareaList;
frm.ShowDialog();
}
void addTareasACola()
{
DateTime feActual = DateTime.Now;
int hh = 0, mm = 0, ss = 00, conteo = 0, tareaId = 0;
int cantSgdoRepite = 0, cantSgdoTranscurrido = 0, cantSegundosEnCola = 0;
int diaActual = 0, diaIni = 0, diaFin = 0;
bool esEjecutado = false;
string SSQL = "";
string sHora = "00:00:00";
string codigo = "", nombre = "";
Proceso myProc = new Proceso();
DataTable DTData = null;
int valorUnico = 0;
DateTime feUltEjecutado = DateTime.Now;
bool onlyOnce = true;
try
{
hh = feActual.Hour;
mm = feActual.Minute;
ss = feActual.Second;
diaActual = feActual.Day;
sHora = hh.ToString().PadLeft(2, '0') + ":";
sHora += mm.ToString().PadLeft(2, '0') + ":";
sHora += ss.ToString().PadLeft(2, '0');
//Buscamos la fecha de trabajo para agregar el cierre automatico si la fecha actual es mayor a fecha trabajo
db.GetFechasOficina();
if(db.DateToInt(feActual) > db.DateToInt(db.FECHA_TRABAJO))
{
SSQL = "SELECT COUNT(*) as Conteo FROM TSISTEMA_PROCESOS_LOG WHERE Codigo = 'COPER' and Estatus_Id >= 0 AND Cast(Fecha as Date) = '" + db.DateToInt(db.FECHA_TRABAJO).ToString() + "' ";
DTData = db.GetSQL(SSQL);
conteo = db.GetAsInt("Conteo", DTData.Rows[0]);
if (conteo <= 0) myProc.addProceso("COPER", "CIERRE OPERACIONES");
}
SSQL = "SELECT * FROM VSISTEMA_PROCESOS_SCHEDULE WHERE EsActivo = 1 And Fecha_Ult_Cola IS NULL";
SSQL += " And '" + sHora + "' between Hora_Inicio and Hora_Fin ";
//Filtramos por dia de la semana
switch (feActual.DayOfWeek)
{
case DayOfWeek.Sunday:
SSQL += " And EsDomingo = 1 ";
break;
case DayOfWeek.Monday:
SSQL += " And EsLunes = 1 ";
break;
case DayOfWeek.Tuesday:
SSQL += " And EsMartes = 1 ";
break;
case DayOfWeek.Wednesday:
SSQL += " And EsMiercoles = 1 ";
break;
case DayOfWeek.Thursday:
SSQL += " And EsJueves = 1 ";
break;
case DayOfWeek.Friday:
SSQL += " And EsViernes = 1 ";
break;
case DayOfWeek.Saturday:
SSQL += " And EsSabado = 1 ";
break;
default:
break;
}
//Buscamos la data y la insertamos en cola
DTData = db.GetSQL(SSQL);
foreach (DataRow item in DTData.Rows)
{
valorUnico = db.GetAsInt("Unico", item);
tareaId = db.GetAsInt("Tarea_Id", item);
cantSgdoRepite = db.GetAsInt("CantSegundoRepite", item);
cantSgdoTranscurrido = db.GetAsInt("segundosTrascurridos", item);
cantSegundosEnCola = db.GetAsInt("CantSegundosEnCola", item);
feUltEjecutado = db.GetAsDate("Fecha_Ultima_Ejecusion", item, true);
onlyOnce = db.GetAsBoolean("onlyOnce", item);
esEjecutado = db.GetAsBoolean("EsEjecutado", item);
diaIni = db.GetAsInt("Dia_Inicio", item);
diaFin = db.GetAsInt("Dia_Fin", item);
if (onlyOnce && db.DateToInt(feUltEjecutado) >= db.DateToInt(feActual)) continue;
if (cantSgdoRepite > 0 && cantSgdoTranscurrido < cantSgdoRepite && esEjecutado) continue;
if(diaFin > 0 && diaIni > 0)
{
if(!(diaActual >= diaIni && diaActual <= diaFin)) continue;
}
//Actulizamos con la fecha en que se coloco en cola
SSQL = "UPDATE TSISTEMA_PROCESOS_SCHEDULE SET Fecha_Ult_Cola = GetDate() WHERE Unico = " + valorUnico.ToString();
db.EjecutarSQL(SSQL);
codigo = db.GetAsString("codigo", item);
nombre = db.GetAsString("Descripcion", item);
myProc.addProceso(codigo, nombre, tareaId);
}
}
catch (Exception ex)
{
mensajeError = ex.Message;
}
}
}
}