From 6fdf59074c55a52b6670557b8fa59abb1b13f1c4 Mon Sep 17 00:00:00 2001 From: Ernesto Abarca Ortiz Date: Tue, 31 Jul 2018 12:29:17 +0200 Subject: [PATCH] =?UTF-8?q?Log=20se=20actualiza=20en=20tiempo=20real=20inc?= =?UTF-8?q?luyendo=20errores=20SQL=20A=C3=B1adido=20checkbox=20para=20borr?= =?UTF-8?q?ar=20o=20no=20el=20log=20del=20fichador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- LectorVerdnatura/Program.cs | 2 + LectorVerdnatura/database.cs | 7 +- LectorVerdnatura/frmPrincipal.Designer.cs | 79 ++++++++++++++--------- LectorVerdnatura/frmPrincipal.cs | 34 +++++++--- LectorVerdnatura/sdklector.cs | 15 +++-- 6 files changed, 91 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 5301a1e..7106364 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ LectorVerdnatura/bin -LectorVerdnatura/obj \ No newline at end of file +LectorVerdnatura/obj +/.vs/LectorVerdnatura diff --git a/LectorVerdnatura/Program.cs b/LectorVerdnatura/Program.cs index 7573288..3679da9 100644 --- a/LectorVerdnatura/Program.cs +++ b/LectorVerdnatura/Program.cs @@ -10,6 +10,8 @@ namespace LectorVerdnatura /// /// Punto de entrada principal para la aplicación. /// + /// + [STAThread] static void Main() { diff --git a/LectorVerdnatura/database.cs b/LectorVerdnatura/database.cs index 1b60a99..85ef50b 100644 --- a/LectorVerdnatura/database.cs +++ b/LectorVerdnatura/database.cs @@ -51,6 +51,11 @@ namespace LectorVerdnatura return this.hayconexion; } + public String GetDBConnectionDescription() + { + return conn.ConnectionString + " Server: " + conn.DataSource.ToString() + " Database: " + conn.Database.ToString(); + } + public Boolean insertarbd(int idemple_lector, String fecha, int warehouseFk) // Esta funcion ya no se debe usar, se inserta directamente la fichada con TODOS los datos. { Boolean retorno = false; @@ -132,7 +137,7 @@ namespace LectorVerdnatura reader.Read(); int interval; DateTime hora = reader.GetDateTime(0); - logevent.logeventwritefile("Próxima ejecución a las: " + hora.TimeOfDay.ToString()); + logevent.logeventwritefile("Próxima descarga de fichajes a las: " + hora.TimeOfDay.ToString()); DateTime ahora = System.DateTime.Now; TimeSpan diferencia = hora.Subtract(ahora); interval = (diferencia.Hours * 3600 + diferencia.Minutes * 60 + diferencia.Seconds) * 1000; diff --git a/LectorVerdnatura/frmPrincipal.Designer.cs b/LectorVerdnatura/frmPrincipal.Designer.cs index 9c38d60..e06556c 100644 --- a/LectorVerdnatura/frmPrincipal.Designer.cs +++ b/LectorVerdnatura/frmPrincipal.Designer.cs @@ -32,9 +32,9 @@ namespace LectorVerdnatura { this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmPrincipal)); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.RecogerFichajes = new System.Windows.Forms.ToolStripMenuItem(); @@ -51,6 +51,7 @@ namespace LectorVerdnatura this.name = ((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.chkBorrarLogs = new System.Windows.Forms.CheckBox(); this.contextMenuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit(); this.SuspendLayout(); @@ -100,38 +101,38 @@ namespace LectorVerdnatura // this.dataGrid1.AllowUserToAddRows = false; this.dataGrid1.AllowUserToDeleteRows = false; - dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle4.NullValue = "Texto"; - dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGrid1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle1.NullValue = "Texto"; + dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGrid1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.dataGrid1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGrid1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Texto}); - dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.dataGrid1.DefaultCellStyle = dataGridViewCellStyle5; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dataGrid1.DefaultCellStyle = dataGridViewCellStyle2; this.dataGrid1.Location = new System.Drawing.Point(12, 142); this.dataGrid1.Name = "dataGrid1"; this.dataGrid1.ReadOnly = true; - dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGrid1.RowHeadersDefaultCellStyle = dataGridViewCellStyle6; - this.dataGrid1.Size = new System.Drawing.Size(612, 429); + dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGrid1.RowHeadersDefaultCellStyle = dataGridViewCellStyle3; + this.dataGrid1.Size = new System.Drawing.Size(841, 441); this.dataGrid1.TabIndex = 0; // // Texto @@ -154,7 +155,7 @@ namespace LectorVerdnatura // // btnActualizarLog // - this.btnActualizarLog.Location = new System.Drawing.Point(486, 109); + this.btnActualizarLog.Location = new System.Drawing.Point(486, 72); this.btnActualizarLog.Name = "btnActualizarLog"; this.btnActualizarLog.Size = new System.Drawing.Size(138, 27); this.btnActualizarLog.TabIndex = 3; @@ -209,7 +210,7 @@ namespace LectorVerdnatura // // btnDescargarFichajes // - this.btnDescargarFichajes.Location = new System.Drawing.Point(486, 46); + this.btnDescargarFichajes.Location = new System.Drawing.Point(486, 42); this.btnDescargarFichajes.Name = "btnDescargarFichajes"; this.btnDescargarFichajes.Size = new System.Drawing.Size(138, 28); this.btnDescargarFichajes.TabIndex = 7; @@ -217,11 +218,24 @@ namespace LectorVerdnatura this.btnDescargarFichajes.UseVisualStyleBackColor = true; this.btnDescargarFichajes.Click += new System.EventHandler(this.btnDescargarFichajes_Click); // + // chkBorrarLogs + // + this.chkBorrarLogs.AutoSize = true; + this.chkBorrarLogs.Checked = true; + this.chkBorrarLogs.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkBorrarLogs.Location = new System.Drawing.Point(492, 112); + this.chkBorrarLogs.Name = "chkBorrarLogs"; + this.chkBorrarLogs.Size = new System.Drawing.Size(132, 17); + this.chkBorrarLogs.TabIndex = 8; + this.chkBorrarLogs.Text = "Borrar Logs fichadores"; + this.chkBorrarLogs.UseVisualStyleBackColor = true; + // // frmPrincipal // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(636, 580); + this.ClientSize = new System.Drawing.Size(865, 595); + this.Controls.Add(this.chkBorrarLogs); this.Controls.Add(this.btnDescargarFichajes); this.Controls.Add(this.lvFichadores); this.Controls.Add(this.label1); @@ -259,6 +273,7 @@ namespace LectorVerdnatura private System.Windows.Forms.ColumnHeader fichador_ip; private System.Windows.Forms.Button btnDescargarFichajes; private System.Windows.Forms.DataGridViewTextBoxColumn Texto; + private System.Windows.Forms.CheckBox chkBorrarLogs; public CancelEventHandler contextMenuStrip1_Opening { get; private set; } } diff --git a/LectorVerdnatura/frmPrincipal.cs b/LectorVerdnatura/frmPrincipal.cs index 89edb74..08f0e46 100644 --- a/LectorVerdnatura/frmPrincipal.cs +++ b/LectorVerdnatura/frmPrincipal.cs @@ -35,14 +35,32 @@ namespace LectorVerdnatura lector = new sdklector(); this.Text = this.Text + " v. " + Application.ProductVersion.ToString(); - logevent.logeventwritefile(" ===== Aplicacion inicializada ===== En 10 segundos se intentaran descargar los registros de todos los fichadores de la lista..."); - ActualizarLog(); + if (Debugger.IsAttached) + { + logevent.logeventwritefile(" ===== Detectado Debugger.IsAttached: modo pruebas? Desactivamos opcion de borrar logs del fichador!"); + chkBorrarLogs.Checked = false; + } + else + { + logevent.logeventwritefile(" ===== Debugger.IsAttached NO detectado. Se borraran los logs del lector tras la lectura."); + chkBorrarLogs.Checked = true; + } + db = new database(); + logevent.logeventwritefile("Usando BDD: " + db.GetDBConnectionDescription()); CargarFichadores(); - timer1.Interval = 10000; - timer1.Enabled = true; - timer1.Start(); + //obtengo la siguiente hora que se tiene que ejecutar para obtener los fichajes + String HoraActual = DateTime.Now.ToString("HH:mm"); + timer1.Interval = db.proximotimer(HoraActual); + if (db.Gethayconexion()) db.CerrarConexion(); + + //logevent.logeventwritefile(" ===== Aplicacion inicializada ===== En 10 segundos se intentaran descargar los registros de todos los fichadores de la lista..."); + //timer1.Interval = 10000; + //timer1.Enabled = true; + //timer1.Start(); + + ActualizarLog(); notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick); } @@ -108,13 +126,13 @@ namespace LectorVerdnatura logevent.logeventwritefile("Descargando fichajes..."); ActualizarLog(); lector.ObtenerFichajes(dataGrid1); - if (Debugger.IsAttached) + if (chkBorrarLogs.Checked) { - logevent.logeventwritefile(" ===== Detectado Debugger.IsAttached, modo pruebas? no borramos los logs del lector!"); + lector.BorrarLogLector(); } else { - lector.BorrarLogLector(); + logevent.logeventwritefile(" ===== Detectado Debugger.IsAttached o casilla Borrar logs Fichadores desactivada: modo pruebas? no borramos los logs del lector!"); } lector.ActualizarFechaLector(); lector.DesconexionLector(); diff --git a/LectorVerdnatura/sdklector.cs b/LectorVerdnatura/sdklector.cs index dc2f6ca..c14138b 100644 --- a/LectorVerdnatura/sdklector.cs +++ b/LectorVerdnatura/sdklector.cs @@ -62,7 +62,7 @@ namespace LectorVerdnatura int idwWorkcode = 0; int idwErrorCode = 0; - + string nuevoregistro = ""; if (hayconexion) { @@ -77,12 +77,7 @@ namespace LectorVerdnatura out idwInOutMode, out idwYear, out idwMonth, out idwDay, out idwHour, out idwMinute, out idwSecond, ref idwWorkcode)) { String FechaRegistro = idwYear.ToString() + "-" + String.Format("{0:0#}", idwMonth) + "-" + String.Format("{0:0#}", idwDay) + " " + String.Format("{0:0#}", idwHour) + ":" + String.Format("{0:0#}", idwMinute) + ":" + String.Format("{0:0#}", idwSecond); - string nuevoregistro = "Registro --> " + sdwEnrollNumber + " --> WH: " + warehouseFk.ToString() + " --> " + FechaRegistro; - logevent.logeventwritefile(nuevoregistro); - - dg.Rows.Add(DateTime.Now.ToString() + " " + nuevoregistro); - dg.FirstDisplayedScrollingRowIndex = dg.Rows.Count - 1; - dg.Refresh(); + nuevoregistro = "Registro --> " + sdwEnrollNumber + " --> WH: " + warehouseFk.ToString() + " --> " + FechaRegistro; DateTime fecha = DateTime.Parse(FechaRegistro); @@ -108,13 +103,19 @@ namespace LectorVerdnatura { // Ignoramos el error, la base de datos esta preparada para esto. // logevent.logeventwritefile("Error SQL 2601: Registro con clave duplicada. Ignorando!. SQL: " + SqlInsert); + nuevoregistro += " Nota: Error SQL 2601: registro duplicado en la BDD. Ignorando..."; } catch (Exception ex) { logevent.logeventwritefile("error al ejecutar " + SqlInsert); logevent.logeventwritefile("Error: " + ex.ToString()); } + logevent.logeventwritefile(nuevoregistro); + // Apaño para actualizar el log en tiempo real + dg.Rows.Add(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " " + nuevoregistro); + dg.FirstDisplayedScrollingRowIndex = dg.Rows.Count - 1; + dg.Refresh(); } Application.DoEvents(); }