Añadido: borrar logs si > XXX registros
This commit is contained in:
parent
640d63ec31
commit
fb939eb25b
|
@ -52,6 +52,8 @@ namespace LectorVerdnatura
|
||||||
this.fichador_ip = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
this.fichador_ip = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||||
this.btnDescargarFichajes = new System.Windows.Forms.Button();
|
this.btnDescargarFichajes = new System.Windows.Forms.Button();
|
||||||
this.chkBorrarLogs = new System.Windows.Forms.CheckBox();
|
this.chkBorrarLogs = new System.Windows.Forms.CheckBox();
|
||||||
|
this.btnForzarBorrarLog = new System.Windows.Forms.Button();
|
||||||
|
this.txtMaxRegistros = new System.Windows.Forms.TextBox();
|
||||||
this.contextMenuStrip1.SuspendLayout();
|
this.contextMenuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
|
@ -225,16 +227,37 @@ namespace LectorVerdnatura
|
||||||
this.chkBorrarLogs.CheckState = System.Windows.Forms.CheckState.Checked;
|
this.chkBorrarLogs.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||||
this.chkBorrarLogs.Location = new System.Drawing.Point(492, 112);
|
this.chkBorrarLogs.Location = new System.Drawing.Point(492, 112);
|
||||||
this.chkBorrarLogs.Name = "chkBorrarLogs";
|
this.chkBorrarLogs.Name = "chkBorrarLogs";
|
||||||
this.chkBorrarLogs.Size = new System.Drawing.Size(132, 17);
|
this.chkBorrarLogs.Size = new System.Drawing.Size(247, 17);
|
||||||
this.chkBorrarLogs.TabIndex = 8;
|
this.chkBorrarLogs.TabIndex = 8;
|
||||||
this.chkBorrarLogs.Text = "Borrar Logs fichadores";
|
this.chkBorrarLogs.Text = "Borrar Logs fichadores si > : registros";
|
||||||
this.chkBorrarLogs.UseVisualStyleBackColor = true;
|
this.chkBorrarLogs.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
|
// btnForzarBorrarLog
|
||||||
|
//
|
||||||
|
this.btnForzarBorrarLog.Location = new System.Drawing.Point(631, 13);
|
||||||
|
this.btnForzarBorrarLog.Name = "btnForzarBorrarLog";
|
||||||
|
this.btnForzarBorrarLog.Size = new System.Drawing.Size(131, 27);
|
||||||
|
this.btnForzarBorrarLog.TabIndex = 9;
|
||||||
|
this.btnForzarBorrarLog.Text = "Borrar log fichador";
|
||||||
|
this.btnForzarBorrarLog.UseVisualStyleBackColor = true;
|
||||||
|
this.btnForzarBorrarLog.Click += new System.EventHandler(this.btnForzarBorrarLog_Click);
|
||||||
|
//
|
||||||
|
// txtMaxRegistros
|
||||||
|
//
|
||||||
|
this.txtMaxRegistros.Location = new System.Drawing.Point(644, 109);
|
||||||
|
this.txtMaxRegistros.Name = "txtMaxRegistros";
|
||||||
|
this.txtMaxRegistros.Size = new System.Drawing.Size(45, 20);
|
||||||
|
this.txtMaxRegistros.TabIndex = 10;
|
||||||
|
this.txtMaxRegistros.Text = "300";
|
||||||
|
this.txtMaxRegistros.Leave += new System.EventHandler(this.txtMaxRegistros_Leave);
|
||||||
|
//
|
||||||
// frmPrincipal
|
// frmPrincipal
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(865, 595);
|
this.ClientSize = new System.Drawing.Size(865, 595);
|
||||||
|
this.Controls.Add(this.txtMaxRegistros);
|
||||||
|
this.Controls.Add(this.btnForzarBorrarLog);
|
||||||
this.Controls.Add(this.chkBorrarLogs);
|
this.Controls.Add(this.chkBorrarLogs);
|
||||||
this.Controls.Add(this.btnDescargarFichajes);
|
this.Controls.Add(this.btnDescargarFichajes);
|
||||||
this.Controls.Add(this.lvFichadores);
|
this.Controls.Add(this.lvFichadores);
|
||||||
|
@ -274,6 +297,8 @@ namespace LectorVerdnatura
|
||||||
private System.Windows.Forms.Button btnDescargarFichajes;
|
private System.Windows.Forms.Button btnDescargarFichajes;
|
||||||
private System.Windows.Forms.DataGridViewTextBoxColumn Texto;
|
private System.Windows.Forms.DataGridViewTextBoxColumn Texto;
|
||||||
private System.Windows.Forms.CheckBox chkBorrarLogs;
|
private System.Windows.Forms.CheckBox chkBorrarLogs;
|
||||||
|
private System.Windows.Forms.Button btnForzarBorrarLog;
|
||||||
|
private System.Windows.Forms.TextBox txtMaxRegistros;
|
||||||
|
|
||||||
public CancelEventHandler contextMenuStrip1_Opening { get; private set; }
|
public CancelEventHandler contextMenuStrip1_Opening { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,14 @@ namespace LectorVerdnatura
|
||||||
lector.ObtenerFichajes(dataGrid1);
|
lector.ObtenerFichajes(dataGrid1);
|
||||||
if (chkBorrarLogs.Checked)
|
if (chkBorrarLogs.Checked)
|
||||||
{
|
{
|
||||||
lector.BorrarLogLector();
|
if (lector.NumRegistros() > int.Parse(txtMaxRegistros.Text.ToString()))
|
||||||
|
{
|
||||||
|
lector.BorrarLogLector();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
logevent.logeventwritefile("Por seguridad: Log no borrado por ser inferior a " + txtMaxRegistros.Text.ToString() + " registros...");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -251,5 +258,41 @@ namespace LectorVerdnatura
|
||||||
ActualizarLog();
|
ActualizarLog();
|
||||||
timer1_Tick(null,null);
|
timer1_Tick(null,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnForzarBorrarLog_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string mensajeterminal = "";
|
||||||
|
|
||||||
|
if (this.lvFichadores.SelectedItems.Count != 1)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Debe de seleccionar un UNICO lector para realizar el borrado"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lector.Lipaddr = this.lvFichadores.SelectedItems[0].SubItems[2].Text;
|
||||||
|
logevent.logeventwritefile("Conectando a fichador: " + lector.Lipaddr.ToString() + " ...");
|
||||||
|
ActualizarLog();
|
||||||
|
|
||||||
|
if (!lector.conexionlector()) mensajeterminal = "No hay conexión con el terminal";
|
||||||
|
|
||||||
|
mensajeterminal = "Encontrados: " + lector.ContarRecordsLector() + " registros, borrando...";
|
||||||
|
logevent.logeventwritefile(mensajeterminal);
|
||||||
|
ActualizarLog();
|
||||||
|
|
||||||
|
lector.BorrarLogLector();
|
||||||
|
|
||||||
|
logevent.logeventwritefile("Registros borrados");
|
||||||
|
ActualizarLog();
|
||||||
|
|
||||||
|
lector.DesconexionLector();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void txtMaxRegistros_Leave(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (! int.TryParse(txtMaxRegistros.Text.ToString(), out int numero))
|
||||||
|
{
|
||||||
|
MessageBox.Show("El valor del numero maximo de registros no es un numero valido y se ha cambiado a 300");
|
||||||
|
txtMaxRegistros.Text = "300";
|
||||||
|
}
|
||||||
|
}
|
||||||
}//lector
|
}//lector
|
||||||
}//namespace
|
}//namespace
|
||||||
|
|
|
@ -28,7 +28,13 @@ namespace LectorVerdnatura
|
||||||
get { return warehouseFk; }
|
get { return warehouseFk; }
|
||||||
set { warehouseFk = value; }
|
set { warehouseFk = value; }
|
||||||
}
|
}
|
||||||
private int nrecords = 0; //registro que hay en el lector
|
|
||||||
|
public int NumRegistros()
|
||||||
|
{
|
||||||
|
return nrecords;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int nrecords = -1; //registros que hay en el lector (-1 = desconocido)
|
||||||
|
|
||||||
public sdklector() { }
|
public sdklector() { }
|
||||||
|
|
||||||
|
@ -138,6 +144,7 @@ namespace LectorVerdnatura
|
||||||
int idwErrorCode = 0;
|
int idwErrorCode = 0;
|
||||||
|
|
||||||
if (nrecords == 0) { logevent.logeventwritefile("No hay Logs para borrar del terminal " + Lipaddr); return;}
|
if (nrecords == 0) { logevent.logeventwritefile("No hay Logs para borrar del terminal " + Lipaddr); return;}
|
||||||
|
if (nrecords == -1) { logevent.logeventwritefile("No se ha comprobado *antes* si hay Logs para borrar del terminal " + Lipaddr + " pero borramos"); return; }
|
||||||
if (!hayconexion) { logevent.logeventwritefile("No hay conexión con el lector " + Lipaddr); return; }
|
if (!hayconexion) { logevent.logeventwritefile("No hay conexión con el lector " + Lipaddr); return; }
|
||||||
|
|
||||||
if (clector.ClearGLog(iddevice))
|
if (clector.ClearGLog(iddevice))
|
||||||
|
@ -152,7 +159,7 @@ namespace LectorVerdnatura
|
||||||
}
|
}
|
||||||
}//borrarloglector
|
}//borrarloglector
|
||||||
|
|
||||||
private int ContarRecordsLector()
|
public int ContarRecordsLector()
|
||||||
{
|
{
|
||||||
int contreglector=0;
|
int contreglector=0;
|
||||||
int idwErrorCode = 0;
|
int idwErrorCode = 0;
|
||||||
|
@ -230,7 +237,9 @@ namespace LectorVerdnatura
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
clector.EnableDevice(iddevice, true);//habilito el lector
|
clector.EnableDevice(iddevice, true);//habilito el lector
|
||||||
clector.Disconnect(); }
|
clector.Disconnect();
|
||||||
|
nrecords = -1;
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logevent.logeventwritefile("Error al desconectar el lector " + ex.ToString());
|
logevent.logeventwritefile("Error al desconectar el lector " + ex.ToString());
|
||||||
|
|
Reference in New Issue