private void toolDiagnostico_Click(object sender, EventArgs e)
 {
     frmVisorReportes vr = new frmVisorReportes();
     vr._noReporte = 11;
     vr._inicioPeriodo = _inicioPeriodo;
     vr._empleadoInicio = idTrabajador;
     vr.Show();
 }
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            int existeNullCodeQR = 0;
            fecha = "";
            fechafin = "";

            cnx = new SqlConnection(cdn);
            cmd = new SqlCommand();
            cmd.Connection = cnx;
            CalculoNomina.Core.NominaHelper nh = new CalculoNomina.Core.NominaHelper();
            nh.Command = cmd;

            for (int i = 0; i < lstvPeriodos.SelectedItems.Count; i++)
            {
                fecha = lstvPeriodos.SelectedItems[i].Text;
                fechafin = lstvPeriodos.SelectedItems[i].SubItems[1].Text;
            }

            try
            {
                cnx.Open();
                existeNullCodeQR = nh.existeNullQR(GLOBALES.IDEMPRESA, DateTime.Parse(fecha).Date, DateTime.Parse(fechafin).Date);
                cnx.Close();
            }
            catch (Exception error)
            {
                MessageBox.Show("Error: Al obtener existencia de nulos Code QR. " + error.Message, "Error");
                cnx.Dispose();
                return;
            }

            if (existeNullCodeQR != 0)
            {
                List<CalculoNomina.Core.CodigoBidimensional> lstXml = new List<CalculoNomina.Core.CodigoBidimensional>();
                try
                {
                    cnx.Open();
                    lstXml = nh.obtenerListaQr(GLOBALES.IDEMPRESA, DateTime.Parse(fecha).Date, DateTime.Parse(fechafin).Date);
                    cnx.Close();
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: Al obtener el listado de XMLs." + error.Message, "Error");
                    cnx.Dispose();
                    return;
                }

                string codigoQR = "";
                string[] valores = null;
                string numero = "";
                string vEntero = "";
                string vDecimal = "";

                for (int i = 0; i < lstXml.Count; i++)
                {
                    numero = lstXml[i].tt.ToString();
                    valores = numero.Split('.');
                    vEntero = valores[0];
                    vDecimal = valores[1];
                    codigoQR = string.Format("?re={0}&rr={1}&tt={2}.{3}&id={4}", lstXml[i].re, lstXml[i].rr,
                        vEntero.PadLeft(10, '0'), vDecimal.PadRight(6, '0'), lstXml[i].uuid);
                    var qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                    var qrCode = qrEncoder.Encode(codigoQR);
                    var renderer = new GraphicsRenderer(new FixedModuleSize(2, QuietZoneModules.Two), Brushes.Black, Brushes.White);

                    using (var stream = new FileStream(lstXml[i].uuid + ".png", FileMode.Create))
                        renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);

                    Bitmap bmp = new Bitmap(lstXml[i].uuid + ".png");
                    Byte[] qr = GLOBALES.IMAGEN_BYTES(bmp);
                    bmp.Dispose();
                    File.Delete(lstXml[i].uuid + ".png");
                    try
                    {
                        cnx.Open();
                        nh.actualizaXml(GLOBALES.IDEMPRESA, DateTime.Parse(fecha).Date, DateTime.Parse(fechafin).Date, lstXml[i].idtrabajador, qr);
                        cnx.Close();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error: Al actualizar el código QR.", "Error");
                        cnx.Dispose();
                        return;
                    }
                }
            }

            if (todos)
            {
                for (int i = 0; i < lstvPeriodos.SelectedItems.Count; i++)
                    fecha = lstvPeriodos.SelectedItems[i].Text;
                idEmpleados = "";
                frmVisorReportes vr = new frmVisorReportes();
                vr._tipoNomina = (cmbTipoNomina.SelectedIndex == 0 ? GLOBALES.NORMAL : GLOBALES.EXTRAORDINARIO_NORMAL);
                vr._departamentos = idDepartamentos;
                vr._empleados = idEmpleados;
                vr._todos = todos;
                vr._noReporte = 10;
                vr._inicioPeriodo = DateTime.Parse(fecha).Date;
                vr._periodo = periodo;
                vr.Show();
            }
            else {
                idEmpleados = "";
                for (int i = 0; i < lstvEmpleados.Items.Count; i++)
                {
                    if (lstvEmpleados.Items[i].Checked)
                        idEmpleados += lstvEmpleados.Items[i].Text + ",";
                }

                fecha = "";
                if (idEmpleados != "")
                {
                    for (int i = 0; i < lstvPeriodos.SelectedItems.Count; i++)
                        fecha = lstvPeriodos.SelectedItems[i].Text;
                    idEmpleados = idEmpleados.Substring(0, idEmpleados.Length - 1);
                    frmVisorReportes vr = new frmVisorReportes();
                    vr._tipoNomina = (cmbTipoNomina.SelectedIndex == 0 ? GLOBALES.NORMAL : GLOBALES.EXTRAORDINARIO_NORMAL);
                    vr._departamentos = idDepartamentos;
                    vr._empleados = idEmpleados;
                    vr._todos = todos;
                    vr._noReporte = 10;
                    vr._periodo = periodo;
                    vr._inicioPeriodo = DateTime.Parse(fecha).Date;
                    vr.Show();
                }
            }
        }
        void r_OnReporte(string netocero, string orden, int noreporte, int empleadoinicial, int empleadofinal)
        {
            NetoCero = "";
            Orden = "";
            NetoCero = netocero;
            Orden = orden;

            if (noreporte == 6)
                workExcel.RunWorkerAsync();
            else if (noreporte == 11)
                workerGravadosExentos.RunWorkerAsync();
            else {
                frmVisorReportes vr = new frmVisorReportes();
                vr._noReporte = noreporte;
                vr._inicioPeriodo = periodoInicio.Date;
                vr._finPeriodo = periodoFin.Date;
                vr._orden = orden;
                vr._netoCero = netocero;
                vr._noReporte = noreporte;
                vr._tipoNomina = _tipoNomina;
                vr._empleadoInicio = empleadoinicial;
                vr._empleadoFin = empleadofinal;
                vr._periodo = _periodo;
                vr.Show();
            }
        }
 private void toolCaratula_Click(object sender, EventArgs e)
 {
     frmVisorReportes vr = new frmVisorReportes();
     vr._noReporte = 0;
     vr._periodo = _periodo;
     vr._tipoNomina = _tipoNomina;
     vr._inicioPeriodo = periodoInicio.Date;
     vr._finPeriodo = periodoFin.Date;
     vr.Show();
 }
Exemple #5
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            if (!_ReportePreNomina)
            {
                if (noReporte != 6 && noReporte != 9)
                {
                    if (noReporte == 8)
                    {
                        int existeNullCodeQR = 0;
                        cnx = new SqlConnection(cdn);
                        cmd = new SqlCommand();
                        cmd.Connection = cnx;
                        nh = new CalculoNomina.Core.NominaHelper();
                        nh.Command = cmd;

                        #region EXISTENCIA DE NULOS EN TABLA xmlCabecera
                        try
                        {
                            cnx.Open();
                            existeNullCodeQR = nh.existeNullQR(GLOBALES.IDEMPRESA, dtpInicioPeriodo.Value.Date, dtpFinPeriodo.Value.Date);
                            cnx.Close();
                        }
                        catch (Exception error)
                        {
                            MessageBox.Show("Error: Al obtener existencia de nulos Code QR." + error.Message, "Error");
                            cnx.Dispose();
                            return;
                        }
                        #endregion

                        #region GENERACION DE CODIGO QR SI EXISTEN NULOS
                        if (existeNullCodeQR != 0)
                        {
                            List<CalculoNomina.Core.CodigoBidimensional> lstXml = new List<CalculoNomina.Core.CodigoBidimensional>();
                            try
                            {
                                cnx.Open();
                                lstXml = nh.obtenerListaQr(GLOBALES.IDEMPRESA, dtpInicioPeriodo.Value.Date, dtpFinPeriodo.Value.Date);
                                cnx.Close();
                            }
                            catch (Exception error)
                            {
                                MessageBox.Show("Error: Al obtener el listado de los XML." + error.Message, "Error");
                                cnx.Dispose();
                                return;
                            }

                            string codigoQR = "";
                            string[] valores = null;
                            string numero = "";
                            string vEntero = "";
                            string vDecimal = "";
                            for (int i = 0; i < lstXml.Count; i++)
                            {
                                numero = lstXml[i].tt.ToString();
                                valores = numero.Split('.');
                                vEntero = valores[0];
                                vDecimal = valores[1];
                                codigoQR = string.Format("?re={0}&rr={1}&tt={2}.{3}&id={4}", lstXml[i].re, lstXml[i].rr,
                                    vEntero.PadLeft(10, '0'), vDecimal.PadRight(6, '0'), lstXml[i].uuid);
                                var qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
                                var qrCode = qrEncoder.Encode(codigoQR);
                                var renderer = new GraphicsRenderer(new FixedModuleSize(2, QuietZoneModules.Two), Brushes.Black, Brushes.White);

                                using (var stream = new FileStream(lstXml[i].uuid + ".png", FileMode.Create))
                                    renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);

                                Bitmap bmp = new Bitmap(lstXml[i].uuid + ".png");
                                Byte[] qr = GLOBALES.IMAGEN_BYTES(bmp);
                                bmp.Dispose();
                                File.Delete(lstXml[i].uuid + ".png");
                                try
                                {
                                    cnx.Open();
                                    nh.actualizaXml(GLOBALES.IDEMPRESA, dtpInicioPeriodo.Value.Date, dtpFinPeriodo.Value.Date, lstXml[i].idtrabajador, qr);
                                    cnx.Close();
                                }
                                catch (Exception)
                                {
                                    MessageBox.Show("Error: Al actualizar el código QR.", "Error");
                                    cnx.Dispose();
                                    return;
                                }
                            }
                        }
                        #endregion
                    }

                    frmVisorReportes vr = new frmVisorReportes();
                    vr._inicioPeriodo = dtpInicioPeriodo.Value;
                    vr._finPeriodo = dtpFinPeriodo.Value;
                    if (_ReportePreNomina)
                        vr._tipoNomina = _tipoNomina;
                    else
                        vr._tipoNomina = tipoNomina;
                    vr._noReporte = noReporte;
                    vr._deptoInicio = int.Parse(cmbDeptoInicial.SelectedValue.ToString());
                    vr._deptoFin = int.Parse(cmbDeptoFinal.SelectedValue.ToString());
                    vr._empleadoInicio = int.Parse(cmbEmpleadoInicial.SelectedValue.ToString());
                    vr._empleadoFin = int.Parse(cmbEmpleadoFinal.SelectedValue.ToString());
                    vr._netoCero = netocero;
                    vr._orden = orden;
                    vr._periodo = periodo;
                    vr.Show();
                }
                else
                {
                    if (noReporte == 6)
                        excelTabular();
                    if (noReporte == 9)
                        excelGravadosExentos();
                }
            }
            else
            {
                int empleadoInicial = 0, empleadoFinal = 0;
                if (_noReporte == 9 || _noReporte == 1)
                {
                    empleadoInicial = int.Parse(cmbEmpleadoInicial.SelectedValue.ToString());
                    empleadoFinal = int.Parse(cmbEmpleadoFinal.SelectedValue.ToString());
                }
                if (OnReporte != null)
                    OnReporte(netocero, orden, _noReporte, empleadoInicial, empleadoFinal);
            }
        }