Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using MetroFramework;
- using MetroFramework.Drawing;
- using MetroFramework.Forms;
- using System.Windows.Forms;
- using System.Drawing;
- using System.IO;
- using Microsoft.Office.Interop.Excel;
- using System.Reflection;
- using System.Drawing.Printing;
- using System.Security.Cryptography.X509Certificates;
- using Universidad_ITEC.Clases;
- using System.Net.Mail;
- using System.Net.Mime;
- using System.Net;
- using MultiFacturas.PAC;
- using System.Net.NetworkInformation;
- using System.Net.Security;
- using Universidad_ITEC.Utils;
- namespace Universidad_ITEC
- {
- public static class Global
- {
- public static class MENSAJES
- {
- public static string EJECUTANDO = "WM_EJECUTANDO";
- }
- public static readonly string STR_NOMBRE_SISTEMA = "Universidad itec";
- public static readonly string STR_MYSQL_SERVER = Properties.Settings.Default.host;//"127.0.0.1";
- public static readonly string STR_MYSQL_USERNAME = Properties.Settings.Default.user;//"root";
- public static readonly string STR_MYSQL_PASSWORD = Properties.Settings.Default.password;//"s3cr3t";/*"mysql";*/
- public static readonly string STR_MYSQL_DATABASE = Properties.Settings.Default.database;//"itec";
- public const int DOWN = 0;
- public const int UP = 1;
- public const int HOVER = 2;
- public const int LEAVE = 3;
- public static float PERCENTAJE = (float)0.5;
- private static readonly string[] Alphabit = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
- "N", "O","P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z","AA","AB","AC","AD","AE","AF","AG","AH","AI","AJ","AK","AL","AM","AN","AO","AP","AQ","AR","AS","AT","AU","AV","AW","AX","AY","AZ" };
- #region Facturacion
- public static readonly string NOMBRE_FISCAL = "UNIVERSIDAD ITEC";
- public static readonly string DIRECCION_FISCAL = "LEON 160 SUR";
- public static readonly string COLONIA_FISCAL = "TEPIC CENTRO";
- public static readonly string MUNICIPIO_FISCAL = "TEPIC";
- public static readonly string NoEXTERIOR_FISCAL = "160 SUR";
- public static readonly string ESTADO_FISCAL = "NAYARIT";
- public static readonly string PAIS_FISCAL = "MÉXICO";
- public static readonly string CODIGO_POSTAL_FISCAL = "63000";
- public static readonly string RFC_FISCAL = "ITS100910B60";//"AAA010101AAA";//
- public static readonly string TELEFONO_FISCAL = "3112130744";
- public static readonly string RFC_PUBLICO_GENERAL_NACIONAL = "XAXX010101000";
- public static readonly string RFC_PUBLICO_GENERAL_EXTRANJERO = "XEXX010101000";
- public static readonly string NOMBRE_FISCAL_PUBLICO_GENERAL = "PÚBLICO GENERAL";
- private static readonly string USER_EMAIL = "itec.tepic.contabilidad@gmail.com";//"facturacion@itectepic.edu.mx";
- private static readonly string PASS_EMAIL = "CHIPUCHI";//"ITEC1009";
- private static readonly string USER_TIMBRADO = "ITS100910B60";//"ITS100910B60";//"checksystems";//"ITS100910B60";//"DEMO700101XXX";//
- private static readonly string PASS_TIMBRADO = "1T3c";//"1T3c";//"Ch3cksyst3ms";//"1T3c";//"DEMO700101XXX";//
- public static readonly ComboBoxItem[] METODOS_DE_PAGO = new ComboBoxItem[] { new ComboBoxItem("Efectivo", new MetodoPago(01, "Efectivo")),
- new ComboBoxItem("Cheque nominativo", new MetodoPago(02, "Cheque nominativo")),new ComboBoxItem("Transferencia electrónica de fondos", new MetodoPago(03, "Transferencia electrónica de fondos")),new ComboBoxItem("Tarjeta de Crédito", new MetodoPago(04, "Tarjeta de Crédito")),
- new ComboBoxItem("Tarjeta de Débito", new MetodoPago(28, "Tarjeta de Débito"))};
- public static readonly ComboBoxItem[] NIVEL_EDUCATIVO = new ComboBoxItem[] { new ComboBoxItem("Profesional técnico", "Profesional técnico"),
- new ComboBoxItem("Bachillerato o su equivalente", "Bachillerato o su equivalente"),new ComboBoxItem("Licenciatura", "Licenciatura"),
- new ComboBoxItem("Maestria", "Maestria"),new ComboBoxItem("Especialidad", "Especialidad")};
- public static readonly ComboBoxItem[] GRADO_Y_GRUPO = new ComboBoxItem[] { new ComboBoxItem("1 A", "1 A"),new ComboBoxItem("1 B", "1 B"),new ComboBoxItem("1 C", "1 C"),
- new ComboBoxItem("2 A", "2 A"),new ComboBoxItem("2 B", "2 B"),new ComboBoxItem("2 C", "2 C"),
- new ComboBoxItem("3 A", "3 A"),new ComboBoxItem("3 B", "3 B"),new ComboBoxItem("3 C", "3 C"),
- new ComboBoxItem("4 A", "4 A"),new ComboBoxItem("4 B", "4 B"),new ComboBoxItem("4 C", "4 C"),
- new ComboBoxItem("5 A", "5 A"),new ComboBoxItem("5 B", "5 B"),new ComboBoxItem("5 C", "5 C")};
- private static readonly string clientID = "966254033375-9vfh3bja168517plbgcqclve50637rhg.apps.googleusercontent.com";
- private static readonly string clientSecret = "PnlMASvaYAKoyK18eRMtGyoC";
- private static readonly string redirectURL = "urn:ietf:wg:oauth:2.0:oob";
- private static string acessToken = string.Empty;
- private static string refreshtoken = string.Empty;
- public static DateTime _dtDefaultDateTime = new DateTime(1900, 1, 1);
- public static readonly string CORTE_CAJA = "universidaditec@itectepic.edu.mx,kvin.bw@gmail.com,marsol19452010@hotmail.com,contabilidad@itectepic.edu.mx";
- public static string getEmailPublicoGeneral()
- {
- return USER_EMAIL;
- }
- public static string getUserTimbrado()
- {
- return USER_TIMBRADO;
- }
- public static string getClientId
- {
- get
- {
- return clientID;
- }
- }
- public static string RedirectURL
- {
- get
- {
- return redirectURL;
- }
- }
- public static string getClientSecret
- {
- get
- {
- return clientSecret;
- }
- }
- public static string getPassTimbrado()
- {
- return PASS_TIMBRADO;
- }
- public static string Access_Token
- {
- get
- {
- return acessToken;
- }
- set
- {
- acessToken = value;
- }
- }
- public static string Refresh_Token
- {
- get
- {
- return refreshtoken;
- }
- set
- {
- refreshtoken = value;
- }
- }
- //https://www.google.com/settings/security/lesssecureapps
- public static bool enviarFactura(string correo, string pathxml, string pathpdf)
- {
- try
- {
- return Utility.enviarFactura(correo, pathxml, pathpdf);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.ToString());
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- return false;
- }
- //public static bool enviarFactura(string correo, string pathxml, string pathpdf)
- //{
- // try
- // {
- // string EMAIL_BODY = string.Empty;
- // using (var resource = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Universidad_ITEC.ResourcesFacturacion.plantilla_correo.html"))
- // {
- // using (StreamReader r = new StreamReader(resource))
- // {
- // EMAIL_BODY = r.ReadToEnd();
- // r.Dispose();
- // }
- // using (MailMessage mail = new MailMessage())
- // {
- // mail.From = new MailAddress(USER_EMAIL);
- // mail.To.Add(correo.Replace(";",","));
- // mail.Subject = "Envio de factura UNIVERSIDAD ITEC TEPIC";
- // mail.Body = EMAIL_BODY;
- // mail.IsBodyHtml = true;
- // mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
- // using (var img = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Universidad_ITEC.Resources.itec.fw.png"))
- // {
- // var inlineLogo = new LinkedResource(img, MediaTypeNames.Image.Jpeg);
- // inlineLogo.ContentId = "logo";
- // var view = AlternateView.CreateAlternateViewFromString(EMAIL_BODY, null, MediaTypeNames.Text.Html);
- // view.LinkedResources.Add(inlineLogo);
- // mail.AlternateViews.Add(view);
- // if (File.Exists(pathpdf))
- // {
- // mail.Attachments.Add(new Attachment(pathpdf));
- // }
- // if (File.Exists(pathxml))
- // {
- // mail.Attachments.Add(new Attachment(pathxml));
- // }
- // using (SmtpClient smtp = new SmtpClient("mail.itectepic.edu.mx", 26))
- // {
- // smtp.EnableSsl = true;
- // smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- // smtp.UseDefaultCredentials = false;
- // smtp.Credentials = new NetworkCredential(USER_EMAIL, PASS_EMAIL);
- // ServicePointManager.ServerCertificateValidationCallback = delegate(object s
- // , X509Certificate certificate
- // , X509Chain chai
- // , SslPolicyErrors sslPolicyErrors)
- // { return true; };
- // smtp.Send(mail);
- // }
- // }
- // }
- // return true;
- // }
- // }
- // catch (SmtpFailedRecipientException e)
- // {
- // MessageBox.Show(e.ToString());
- // return false;
- // }
- // catch (Exception e)
- // {
- // MessageBox.Show(e.ToString());
- // System.Diagnostics.Debug.WriteLine(e.ToString());
- // }
- // return false;
- //}
- public static bool enviarCorte(string corteNormal, string corteComplementario, DateTime fecha)
- {
- try
- {
- try
- {
- return Utility.enviarCorteDeCaja(CORTE_CAJA, fecha, corteNormal, corteComplementario);
- }
- catch (Exception e)
- {
- MessageBox.Show(e.ToString());
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- return true;
- }
- catch (SmtpFailedRecipientException e)
- {
- MessageBox.Show(e.ToString());
- return false;
- }
- catch (Exception e)
- {
- MessageBox.Show(e.ToString());
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- return false;
- }
- //public static bool enviarCorte(string corteNormal, string corteComplementario, DateTime fecha)
- //{
- // try
- // {
- // string EMAIL_BODY = string.Empty;
- // using (var resource = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Universidad_ITEC.ResourcesFacturacion.plantilla_cortecaja.html"))
- // {
- // using (StreamReader r = new StreamReader(resource))
- // {
- // EMAIL_BODY = string.Format(r.ReadToEnd(), fecha.ToString("dd/MM/yyyy"));
- // r.Dispose();
- // }
- // using (MailMessage mail = new MailMessage())
- // {
- // mail.From = new MailAddress(USER_EMAIL);
- // mail.To.Add("universidaditec@itectepic.edu.mx,kvin.bw@gmail.com,marsol19452010@hotmail.com,contabilidad@itectepic.edu.mx");
- // mail.Subject = "Envio de corte de caja del dia " + fecha.ToString("dd/MM/yyyy");
- // mail.Body = EMAIL_BODY;
- // mail.IsBodyHtml = true;
- // mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
- // using (var img = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Universidad_ITEC.Resources.itec.fw.png"))
- // {
- // var inlineLogo = new LinkedResource(img, MediaTypeNames.Image.Jpeg);
- // inlineLogo.ContentId = "logo";
- // var view = AlternateView.CreateAlternateViewFromString(EMAIL_BODY, null, MediaTypeNames.Text.Html);
- // view.LinkedResources.Add(inlineLogo);
- // mail.AlternateViews.Add(view);
- // if (File.Exists(corteNormal))
- // {
- // mail.Attachments.Add(new Attachment(corteNormal));
- // }
- // if (File.Exists(corteComplementario))
- // {
- // mail.Attachments.Add(new Attachment(corteComplementario));
- // }
- // using (SmtpClient smtp = new SmtpClient("mail.itectepic.edu.mx", 26))
- // {
- // smtp.EnableSsl = true;
- // smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- // smtp.UseDefaultCredentials = false;
- // smtp.Credentials = new NetworkCredential(USER_EMAIL, PASS_EMAIL);
- // ServicePointManager.ServerCertificateValidationCallback = delegate(object s
- // , X509Certificate certificate
- // , X509Chain chai
- // , SslPolicyErrors sslPolicyErrors)
- // { return true; };
- // smtp.Send(mail);
- // }
- // }
- // }
- // return true;
- // }
- // }
- // catch (SmtpFailedRecipientException e)
- // {
- // MessageBox.Show(e.ToString());
- // return false;
- // }
- // catch (Exception e)
- // {
- // MessageBox.Show(e.ToString());
- // System.Diagnostics.Debug.WriteLine(e.ToString());
- // }
- // return false;
- //}
- public static void obtenerLugarDeExpedicion(string sucursal, ref XSDs.cfdv32.t_Ubicacion ubicacion)
- {
- if (frmPrincipal._UbicacionFiscal != null)
- {
- if (frmPrincipal._UbicacionFiscal.Calle.Length > 0)
- {
- ubicacion.calle = frmPrincipal._UbicacionFiscal.Calle;
- }
- if (frmPrincipal._UbicacionFiscal.CodigoPostal.Length > 0)
- {
- ubicacion.codigoPostal = frmPrincipal._UbicacionFiscal.CodigoPostal;
- }
- if (frmPrincipal._UbicacionFiscal.Colonia.Length > 0)
- {
- ubicacion.colonia = frmPrincipal._UbicacionFiscal.Colonia;
- }
- if (frmPrincipal._UbicacionFiscal.Estado.Length > 0)
- {
- ubicacion.estado = frmPrincipal._UbicacionFiscal.Estado;
- }
- if (frmPrincipal._UbicacionFiscal.Localidad.Length > 0)
- {
- ubicacion.localidad = frmPrincipal._UbicacionFiscal.Localidad;
- }
- if (frmPrincipal._UbicacionFiscal.Municipio.Length > 0)
- {
- ubicacion.municipio = frmPrincipal._UbicacionFiscal.Municipio;
- }
- if (frmPrincipal._UbicacionFiscal.NumeroExterior.Length > 0)
- {
- ubicacion.noExterior = frmPrincipal._UbicacionFiscal.NumeroExterior;
- }
- else
- {
- ubicacion.noExterior = "S/N";
- }
- if (frmPrincipal._UbicacionFiscal.NumeroInterior.Length > 0)
- {
- ubicacion.noInterior = frmPrincipal._UbicacionFiscal.NumeroInterior;
- }
- else
- {
- ubicacion.noInterior = "S/N";
- }
- ubicacion.pais = frmPrincipal._UbicacionFiscal.Pais;
- }
- else
- {
- if (frmPrincipal._Empresa.Calle.Length > 0)
- {
- ubicacion.calle = frmPrincipal._Empresa.Calle;
- }
- if (frmPrincipal._Empresa.CodigoPostal.Length > 0)
- {
- ubicacion.codigoPostal = frmPrincipal._Empresa.CodigoPostal;
- }
- if (frmPrincipal._Empresa.Colonia.Length > 0)
- {
- ubicacion.colonia = frmPrincipal._Empresa.Colonia;
- }
- if (frmPrincipal._Empresa.Estado.Length > 0)
- {
- ubicacion.estado = frmPrincipal._Empresa.Estado;
- }
- if (frmPrincipal._Empresa.Ciudad.Length > 0)
- {
- ubicacion.localidad = frmPrincipal._Empresa.Ciudad;
- ubicacion.municipio = frmPrincipal._Empresa.Ciudad;
- }
- if (frmPrincipal._Empresa.NumeroExterior.Length > 0)
- {
- ubicacion.noExterior = frmPrincipal._Empresa.NumeroExterior;
- }
- else
- {
- ubicacion.noExterior = "S/N";
- }
- if (frmPrincipal._Empresa.NumeroInterior.Length > 0)
- {
- ubicacion.noInterior = frmPrincipal._Empresa.NumeroInterior;
- }
- else
- {
- ubicacion.noInterior = "S/N";
- }
- ubicacion.pais = frmPrincipal._Empresa.Pais;
- }
- }
- public static string obtenerLugarDeExpedicion()
- {
- if (frmPrincipal._UbicacionFiscal != null)
- {
- return frmPrincipal._UbicacionFiscal.Municipio + ", " + frmPrincipal._UbicacionFiscal.Estado;
- }
- else
- {
- return frmPrincipal._Empresa.Ciudad + ", " + frmPrincipal._Empresa.Estado;
- }
- }
- public static bool CancelarFactura(FacturaDigital factura, ref string message, ref int error)
- {
- return CancelacionFactura(factura, ref message, ref error);
- }
- private static bool CancelacionFactura(FacturaDigital factura, ref string message, ref int error)
- {
- try
- {
- Certificados certificado = frmPrincipal._BaseDatos.ObtenerRequisitosFacturacion();
- if (certificado == null)
- {
- FrmCertificadosDigitales requisitos = new FrmCertificadosDigitales();
- if (requisitos.ShowDialog() == DialogResult.OK)
- {
- certificado = requisitos.obtenerCertificado();
- }
- }
- else
- {
- certificado = frmPrincipal._BaseDatos.ObtenerRequisitosFacturacion();
- }
- if (File.Exists(certificado.RutaCertificado) && File.Exists(certificado.RutaClave))
- {
- if (esCertificadoValido(certificado, ref error))
- {
- Random r = new Random();
- int ntimes = 0;
- string pac = string.Empty;
- Again:
- try
- {
- pac = r.Next(1, 9).ToString();
- WSMFRespuesta respuesta = WSMultifacturas.Cancelar(pac, Global.getUserTimbrado(), Global.getPassTimbrado(), factura.No, certificado.RutaCertificado, certificado.RutaClave, certificado.ContraseñaClave);
- if (CultureInfo.CurrentCulture.CompareInfo.IndexOf(respuesta.CodigoMFTexto, "UUID CANCELADO CORRECTAMENTE", CompareOptions.IgnoreCase) != -1)
- {
- return true;
- }
- else
- {
- if (ntimes < 8)
- {
- ntimes++;
- goto Again;
- }
- else
- {
- message = "La factura no se ha podido cancelar debido a " + mensajeErroWEbService(respuesta.CodigoMFNumero, respuesta.codigo_mf_texto);
- return false;
- }
- }
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- if (ntimes < 8)
- {
- ntimes++;
- goto Again;
- }
- else
- {
- message = "La factura no se ha podido cancelar debido a " + e.ToString();
- return false;
- }
- }
- }
- else
- {
- if (error == 1)
- {
- message = "La factura no pudo ser generada debido a que el certificado digital no corresponde al del rfc fiscal del emisor.\nFavor de asignar el certificado digital correspondiente al emisor.";
- }
- else
- {
- error = 1;
- message = "La factura no ha sido cancelada debido a que el certificado digital no es válido o ha expirado.\nFavor de proporcionar un certificado válido.\nVaya a Reportes, seleccione Facturas e intente nuevamente.";
- }
- }
- }
- else
- {
- if (error == 1)
- {
- message = "La factura no pudo ser generada debido a que el certificado digital no corresponde al del rfc fiscal del emisor.\nFavor de asignar el certificado digital correspondiente al emisor.";
- }
- else
- {
- error = 1;
- message = "La factura no ha sido cancelada debido a que el certificado y/o la llave digital no existe(n).\nFavor de proporcionar un certificado y/o llave digital válida.\nVaya a Reportes, seleccione Facturas e intente nuevamente.";
- }
- }
- return false;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- return false;
- }
- private static string mensajeErroWEbService(string code, string exception)
- {
- string error = string.Empty;
- switch (code)
- {
- case "0":
- error = exception;
- break;
- case "1":
- error = "saldo insufuciente con su servicio de timbrado.\nFavor de consultar su saldo con su disribuidor de servicio de timbrado.";
- break;
- case "2":
- error = "un error al timbrar.\n" + exception;
- break;
- case "3":
- error = "un error al conectarse al servidor de timbrado.\nCheque su conexión a internet e intentelo más tarde.";
- break;
- case "4":
- error = "un error de autentificación con su servicio de timbrado.\nFavor de reportarlo con su distribuidor de servicio de timbrado.\nEspere un momento (entre 10-20 min) e intente nuevamente.";
- break;
- case "5":
- error = "un error de autentificación con su servicio de timbrado.\nFavor de verificar que su usuario y contraseña\nsean los mismos que los le proporcionó su\ndistribuidor de servicio de timbrado.";
- break;
- case "6":
- error = "un error al timbrar por parte de su distribuidor de servicio de timbrado.\nfavor de reportarlo con su distribuidor.\nEspere un momento (entre 10-20 min) e intente nuevamente.";
- break;
- case "7":
- error = "un error interno del servidor.\n" + exception;
- break;
- case "8":
- error = "un error al generar el ticket.";
- break;
- }
- return error;
- }
- public static bool esCertificadoValido(Certificados certificado, ref int error)
- {
- X509Certificate2 x509 = null;
- try
- {
- x509 = new X509Certificate2(certificado.RutaCertificado);
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- if (x509 != null)
- {
- DateTime dtExpiration = x509.NotAfter;
- DateTime dtNow = DateTime.Now;
- if (dtExpiration.Year >= dtNow.Year)
- {
- string RFC = frmPrincipal._Empresa.DatosVerificados ? frmPrincipal._Empresa.RFC : Global.RFC_FISCAL;
- if (dtExpiration.Year > dtNow.Year)
- {
- if (CultureInfo.CurrentCulture.CompareInfo.IndexOf(x509.Subject, RFC, CompareOptions.IgnoreCase) != -1)
- {
- return true;
- }
- else
- {
- error = 1;
- return false;
- }
- }
- else
- {
- if (CultureInfo.CurrentCulture.CompareInfo.IndexOf(x509.Subject, RFC, CompareOptions.IgnoreCase) != -1)
- {
- if (dtExpiration.Month > dtNow.Month)
- {
- return true;
- }
- else
- {
- if (dtExpiration.Month == dtNow.Month)
- {
- if (dtExpiration.Day >= dtNow.Day)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- error = 1;
- return false;
- }
- }
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- #endregion facturacion
- public static bool hayInternet(bool mostrarMensaje)
- {
- NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
- foreach (NetworkInterface nic in nics)
- {
- if (string.Compare(nic.Name, "hamachi", true) == 0)
- {
- continue;
- }
- if (
- (nic.NetworkInterfaceType != NetworkInterfaceType.Loopback && nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel) &&
- nic.OperationalStatus == OperationalStatus.Up)
- {
- return true;
- }
- }
- if (mostrarMensaje)
- {
- MessageBox.Show("Hay una falla en su conexión de internet.\nFavor de verificar su conexión de internet e intente más tarde.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Stop);
- }
- return false;
- }
- public static string CadenaConexion
- {
- get
- {
- return Properties.Settings.Default.CadenaConexion;
- }
- }
- public static string Usuario
- {
- get
- {
- return Properties.Settings.Default.Usuario;
- }
- }
- public static double Descuento
- {
- get
- {
- return Properties.Settings.Default.Descuento;
- }
- }
- //public static DevExpress.Utils.WaitDialogForm WaitDialog { get; set; }
- public static DateTime MinDate
- {
- get
- {
- return new DateTime(1900, 1, 1);
- }
- }
- public static bool EsFolioId(object strText, ref string id)
- {
- bool bIsNumber = false;
- if (Convert.ToString(strText).Trim().Length > 0)
- {
- long lValue = 0;
- bIsNumber = long.TryParse(Convert.ToString(strText).Trim(), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out lValue);
- if (lValue > 0)
- {
- id = lValue.ToString();
- }
- else
- {
- id = strText.ToString();
- }
- }
- return bIsNumber;
- }
- public static void moveFocusToNextControl(System.Windows.Forms.Keys KeyCode)
- {
- if (KeyCode == System.Windows.Forms.Keys.Enter)
- {
- System.Windows.Forms.SendKeys.Send("{TAB}");
- }
- }
- public static void moveFocusToNextControl()
- {
- System.Windows.Forms.SendKeys.Send("{TAB}");
- }
- public static void imgEfects(System.Windows.Forms.PictureBox pb, int option)
- {
- switch (option)
- {
- case DOWN:
- pb.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- break;
- case UP:
- pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- break;
- case HOVER:
- pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
- break;
- case LEAVE:
- pb.BorderStyle = System.Windows.Forms.BorderStyle.None;
- break;
- }
- }
- public static string DoubleToString(double dNumero)
- {
- return dNumero.ToString("N2", NumberFormatInfo.InvariantInfo);
- }
- public static double StringToDouble(string strNumero)
- {
- double dResultado = 0;
- double.TryParse(strNumero.Trim(), NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out dResultado);
- return dResultado;
- }
- public static bool esPrestamoExcedido(DateTime fecha)
- {
- if (DateTime.Now.Year > fecha.Year)
- {
- return true;
- }
- else
- {
- if (DateTime.Now.Month > fecha.Month)
- {
- return true;
- }
- else
- {
- if (DateTime.Now.Day > fecha.Day)
- {
- return true;
- }
- }
- }
- return false;
- }
- public static int diasPrestamoExcedido(DateTime fecha)
- {
- return -Convert.ToInt32((fecha - DateTime.Now).TotalDays);
- }
- public static int diasPrestamo(DateTime fechaInicio, DateTime fechaFin)
- {
- return Convert.ToInt32((fechaFin - fechaInicio).TotalDays);
- }
- public static bool esFechaEntregaValida(DateTime fechaInicio, DateTime fechaEntrega)
- {
- if (fechaInicio > fechaEntrega)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public static void updateStyleSelectedowsPercentajeGrid(MetroFramework.Controls.MetroGrid grid)
- {
- float _offset = Global.PERCENTAJE;
- grid.DefaultCellStyle.SelectionBackColor = ControlPaint.Light(MetroPaint.GetStyleColor(grid.Style), _offset);
- grid.DefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17);
- grid.DefaultCellStyle.SelectionBackColor = ControlPaint.Light(MetroPaint.GetStyleColor(grid.Style), _offset);
- grid.DefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17);
- grid.RowHeadersDefaultCellStyle.SelectionBackColor = ControlPaint.Light(MetroPaint.GetStyleColor(grid.Style), _offset);
- grid.RowHeadersDefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17);
- grid.ColumnHeadersDefaultCellStyle.SelectionBackColor = ControlPaint.Light(MetroPaint.GetStyleColor(grid.Style), _offset);
- grid.ColumnHeadersDefaultCellStyle.SelectionForeColor = Color.FromArgb(17, 17, 17);
- }
- public static string ObtenerImpresoraTickets()
- {
- string strResultado = string.Empty;
- long lPreferenciasId = frmPrincipal._BaseDatos.ObtenerPreferenciasId();
- Preferencias preferencias = frmPrincipal._BaseDatos.ObtenerPreferencias(lPreferenciasId);
- if (preferencias != null)
- {
- strResultado = preferencias.ImpresoraTickets;
- }
- bool bSeleccionarImpresora = false;
- if (strResultado == string.Empty)
- {
- bSeleccionarImpresora = true;
- }
- else
- {
- if (!EsImpresoraValida(strResultado))
- {
- bSeleccionarImpresora = true;
- }
- }
- if (bSeleccionarImpresora)
- {
- FrmImpresora frm = new FrmImpresora();
- if (frm.ShowDialog() == DialogResult.OK)
- {
- strResultado = frm.ObtenerImpresora();
- if (strResultado != string.Empty)
- {
- frmPrincipal._BaseDatos.ActualizarPreferenciasImpresoraTickets(lPreferenciasId, strResultado);
- }
- }
- }
- return strResultado;
- }
- public static string ObtenerImpresoraFacturas()
- {
- string strResultado = string.Empty;
- long lPreferenciasId = frmPrincipal._BaseDatos.ObtenerPreferenciasId();
- Preferencias preferencias = frmPrincipal._BaseDatos.ObtenerPreferencias(lPreferenciasId);
- if (preferencias != null)
- {
- strResultado = preferencias.ImpresoraFacturas;
- }
- bool bSeleccionarImpresora = false;
- if (strResultado == string.Empty)
- {
- bSeleccionarImpresora = true;
- }
- else
- {
- if (!EsImpresoraValida(strResultado))
- {
- bSeleccionarImpresora = true;
- }
- }
- if (bSeleccionarImpresora)
- {
- FrmImpresora frm = new FrmImpresora();
- if (frm.ShowDialog() == DialogResult.OK)
- {
- strResultado = frm.ObtenerImpresora();
- if (strResultado != string.Empty)
- {
- frmPrincipal._BaseDatos.ActualizarPreferenciasImpresoraFacturas(lPreferenciasId, strResultado);
- }
- }
- }
- return strResultado;
- }
- public static List<string> ObtenerImpresoras()
- {
- List<string> lstImpresoras = new List<string>();
- foreach (string strImpresoraInstalada in PrinterSettings.InstalledPrinters)
- {
- lstImpresoras.Add(strImpresoraInstalada);
- }
- return lstImpresoras;
- }
- public static bool EsImpresoraValida(string strImpresora)
- {
- List<string> lstImpresoras = ObtenerImpresoras();
- if (lstImpresoras.Contains(strImpresora))
- {
- return true;
- }
- return false;
- }
- public static bool exportToExcel(MetroFramework.Controls.MetroGrid grid, string tituloReporte, bool corteCaja)
- {
- if (grid.RowCount > 0)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Title = "Export To Excel";
- sfd.Filter = "To Excel (Xlsx)|*.xlsx";
- sfd.FileName = "*.xlsx";
- bool result = false;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string filename = sfd.FileName;
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- if (grid.Rows[j].Cells[i].Value != null)
- {
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = true;
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = null;
- if (Range_Letter.CompareTo("J") == 0)
- {
- rng2 = oSheet.get_Range("B2", "D" + Range_Row);
- Range rngConcepto = rng2.Columns[8];
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- Range rngconcepto = oSheet.get_Range("E2", "J" + Range_Row);
- rngconcepto.WrapText = true;
- rngconcepto.Font.Size = 6;
- rngconcepto.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rngconcepto.Cells.Borders.Color = System.Drawing.Color.Black;
- rngconcepto.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rngconcepto.EntireColumn.AutoFit();
- rngconcepto.EntireRow.AutoFit();
- }
- else
- {
- rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- }
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- if (!corteCaja)
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- }
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //SetRowHeight(ref rng3);
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 40);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- oBook.SaveAs(filename);
- oBook.Close();
- oApp.Quit();
- result = true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- //sfd.OpenFile();
- }
- sfd.Dispose();
- return result;
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro a exportar.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- public static bool exportToExcelCorteCaja(MetroFramework.Controls.MetroGrid grid, string tituloReporte, bool complementario)
- {
- if (grid.RowCount > 0)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Title = "Export To Excel";
- sfd.Filter = "To Excel (Xlsx)|*.xlsx";
- sfd.FileName = "*.xlsx";
- bool result = false;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string filename = sfd.FileName;
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- if (grid.Rows[j].Cells[i].Value != null)
- {
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = true;
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = true;
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- if (complementario)
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte Complementario: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- oBook.SaveAs(filename);
- oBook.Close();
- oApp.Quit();
- result = true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- //sfd.OpenFile();
- }
- sfd.Dispose();
- return result;
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro a exportar.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- public static bool exportToExcelCorteCajaParaCorreo(MetroFramework.Controls.MetroGrid grid, string tituloReporte, bool complementario, ref string path)
- {
- if (grid.RowCount > 0)
- {
- bool result = false;
- {
- string filename = string.Empty;
- if (complementario)
- {
- filename = crearDirectorioCortesCaja() + "\\CorteComplementario_" + DateTime.Now.ToString("dd-MM-yyyy") + ".xlsx";
- }
- else
- {
- filename = crearDirectorioCortesCaja() + "\\CorteNormal_" + DateTime.Now.ToString("dd-MM-yyyy") + ".xlsx";
- }
- path = filename;
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- if (grid.Rows[j].Cells[i].Value != null)
- {
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //SetRowHeight(ref rng3);
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- //Bitmap image = new Bitmap((Bitmap)Properties.Resources.itecExport, 100, 100);
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- //rng4.EntireColumn.AutoFit();
- //rng4.EntireRow.AutoFit();
- // SetRowHeight(ref rng4);
- // oSheet.Cells.Columns.EntireColumn.AutoFit();
- //oSheet.Rows.AutoFit();
- //oSheet.Range["B1", Range_Letter + "2"].AutoFit();
- oBook.SaveAs(filename);
- oBook.Close();
- oApp.Quit();
- result = true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- //sfd.OpenFile();
- }
- return result;
- }
- return false;
- }
- public static bool exportAlumnosToExcel(MetroFramework.Controls.MetroGrid grid, string tituloReporte,string header, bool corteCaja)
- {
- if (grid.RowCount > 0)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Title = "Export To Excel";
- sfd.Filter = "To Excel (Xlsx)|*.xlsx";
- sfd.FileName = "*.xlsx";
- bool result = false;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string filename = sfd.FileName;
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = true;
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = true;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- string range = "2";
- if (header.Length > 0)
- {
- range = "3";
- }
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + range).EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- if (!corteCaja)
- {
- if (header.Length > 0)
- {
- oSheet.Cells[1, 3] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt") + "\r\n" + header;
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- }
- Range rng3 = oSheet.get_Range("B1", Range_Letter + range);
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //SetRowHeight(ref rng3);
- oSheet.get_Range("B1", Range_Letter + range).EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + range);
- rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- //rng4.EntireColumn.AutoFit();
- //rng4.EntireRow.AutoFit();
- // SetRowHeight(ref rng4);
- // oSheet.Cells.Columns.EntireColumn.AutoFit();
- //oSheet.Rows.AutoFit();
- //oSheet.Range["B1", Range_Letter + "2"].AutoFit();
- oBook.SaveAs(filename);
- oBook.Close();
- oApp.Quit();
- result = true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- //sfd.OpenFile();
- }
- sfd.Dispose();
- return result;
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro a exportar.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- public static bool exportToExcel2(MetroFramework.Controls.MetroGrid grid, string tituloReporte, bool corteCaja)
- {
- if (grid.RowCount > 0)
- {
- SaveFileDialog sfd = new SaveFileDialog();
- sfd.Title = "Export To Excel";
- sfd.Filter = "To Excel (Xlsx)|*.xlsx";
- sfd.FileName = "*.xlsx";
- bool result = false;
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- string filename = sfd.FileName;
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = true;
- rng1.Font.Size = 7;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = true;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- if (!corteCaja)
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- }
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //SetRowHeight(ref rng3);
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- System.Windows.Forms.Clipboard.SetDataObject((Bitmap)Properties.Resources.itecExport, true);
- oSheet.Paste(oRange, (Bitmap)Properties.Resources.itecExport);
- //rng4.EntireColumn.AutoFit();
- //rng4.EntireRow.AutoFit();
- // SetRowHeight(ref rng4);
- // oSheet.Cells.Columns.EntireColumn.AutoFit();
- //oSheet.Rows.AutoFit();
- //oSheet.Range["B1", Range_Letter + "2"].AutoFit();
- oBook.SaveAs(filename);
- oBook.Close();
- oApp.Quit();
- result = true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- //sfd.OpenFile();
- }
- sfd.Dispose();
- return result;
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro a exportar.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- private static void SetRowHeight(ref Microsoft.Office.Interop.Excel.Range myMergedCells)
- {
- // autofit does not set the row height if the row contains merged cells.
- // this is adapted from a post by Peer Moretti on MSDN forums.
- Microsoft.Office.Interop.Excel.Range mySingleCell = myMergedCells.get_Offset(0, 100);
- double dblPointsWidth;
- // set our variables to the ranges concerned
- // and make sure the single cell has exactly the same font style, size, etc.
- // work out the width of the merged cells in points
- // this requires myMergedCells to be all the columns
- dblPointsWidth = 0;
- mySingleCell.Font.Name = myMergedCells.Font.Name;
- mySingleCell.Font.Size = myMergedCells.Font.Size;
- mySingleCell.Font.Bold = myMergedCells.Font.Bold;
- foreach (Microsoft.Office.Interop.Excel.Range myColumn in myMergedCells.Columns)
- {
- dblPointsWidth = dblPointsWidth + (double)myColumn.Width;
- }
- // set the single cell to the same width as the merged cells in points
- // mySingleCell.ColumnWidth = (double)mySingleCell.ColumnWidth * dblPointsWidth / (double)mySingleCell.Width;
- // put the information from the merged cell in to the single cell
- mySingleCell.Value2 = myMergedCells.Value2;
- // now autofit
- //mySingleCell.Rows.AutoFit();
- mySingleCell.Columns.AutoFit();
- mySingleCell.Columns.Hidden = true;
- // set the height of the merged cell to the height of the single cell
- //myMergedCells.RowHeight = mySingleCell.RowHeight;
- myMergedCells.ColumnWidth = mySingleCell.ColumnWidth;
- }
- public static bool imprimirArchivo(MetroFramework.Controls.MetroGrid grid, string impresora, string tituloReporte, bool corteCaja)
- {
- if (grid.RowCount > 0)
- {
- if (impresora.Length > 0)
- {
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- oSheet.Columns.WrapText = true;
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value;
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = true;
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- Range rng2 = null;
- if (Range_Letter.CompareTo("J") == 0)
- {
- rng2 = oSheet.get_Range("B2", "D" + Range_Row);
- Range rngConcepto = rng2.Columns[8];
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- Range rngconcepto = oSheet.get_Range("E2", "J" + Range_Row);
- rngconcepto.WrapText = true;
- rngconcepto.Font.Size = 6;
- rngconcepto.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rngconcepto.Cells.Borders.Color = System.Drawing.Color.Black;
- rngconcepto.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rngconcepto.EntireColumn.AutoFit();
- rngconcepto.EntireRow.AutoFit();
- }
- else
- {
- rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- }
- oSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
- if (corteCaja)
- {
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- }
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- rng4.Merge(Missing.Value);
- rng4.WrapText = true;
- rng4.Font.Size = 14;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- if (corteCaja)
- {
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- }
- else
- {
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 40);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- }
- //rng3.Interior.Color = System.Drawing.Color.LightSkyBlue;
- string filename = crearDirectorioImpresiones() + "\\" + DateTime.Now.Ticks.ToString() + ".xlsx";
- if (!File.Exists(filename))
- {
- oBook.SaveAs(filename);
- }
- oBook.PrintOutEx(Type.Missing, Type.Missing, Type.Missing, Type.Missing, impresora, Type.Missing, Type.Missing, Type.Missing);
- oBook.Close();
- oApp.Quit();
- try
- {
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- }
- catch (Exception) { }
- return true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningúna impresora seleccionada.\r\nFavor de seleccionar una impresora.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro para imprimir.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- public static bool imprimirCorteCaja(MetroFramework.Controls.MetroGrid grid, string impresora, string tituloReporte, bool complementario)
- {
- if (grid.RowCount > 0)
- {
- if (impresora.Length > 0)
- {
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- oSheet.Cells.WrapText = true;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- if (grid.Rows[j].Cells[i].Value != null)
- {
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value.ToString();
- }
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.WrapText = false;
- rng1.Font.Size = 8;
- rng1.Font.Bold = true;
- //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", "G" + Range_Row);
- Range rngConcepto = rng2.Columns[8];
- rng2.WrapText = false;
- rng2.Font.Size = 6;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rng2.Cells.Borders.Color = System.Drawing.Color.Black;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- Range rngconcepto = oSheet.get_Range("B2", "H" + Range_Row);
- rngconcepto.WrapText = true;
- rngconcepto.Font.Size = 6;
- rngconcepto.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rngconcepto.Cells.Borders.Color = System.Drawing.Color.Black;
- rngconcepto.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rngconcepto.EntireColumn.AutoFit();
- rngconcepto.EntireRow.AutoFit();
- Range rngtotal = oSheet.get_Range("B2", "I" + Range_Row);
- rngtotal.WrapText = true;
- rngtotal.Font.Size = 6;
- rngtotal.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- rngtotal.Cells.Borders.Color = System.Drawing.Color.Black;
- rngtotal.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rngtotal.EntireColumn.AutoFit();
- rngtotal.EntireRow.AutoFit();
- //Add a header row
- oSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 2] = "Fecha: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- //rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //SetRowHeight(ref rng3);
- oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- //rng4.WrapText = true;
- rng4.Merge(Missing.Value);
- rng4.Font.Size = 16;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- //Bitmap image = new Bitmap((Bitmap)Properties.Resources.itecExport, 100, 100);
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- string filename = crearDirectorioImpresiones() + "\\" + DateTime.Now.Ticks.ToString() + ".xlsx";
- if (!File.Exists(filename))
- {
- oBook.SaveAs(filename);
- }
- oBook.PrintOutEx(Type.Missing, Type.Missing, Type.Missing, Type.Missing, impresora, Type.Missing, Type.Missing, Type.Missing);
- oBook.Close();
- oApp.Quit();
- try
- {
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- }
- catch (Exception) { }
- return true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningúna impresora seleccionada.\r\nFavor de seleccionar una impresora.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro para imprimir.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- //public static bool imprimirCorteCaja(MetroFramework.Controls.MetroGrid grid, string impresora, string tituloReporte, bool complementario)
- //{
- // if (grid.RowCount > 0)
- // {
- // if (impresora.Length > 0)
- // {
- // try
- // {
- // string Range_Letter = Alphabit[grid.Columns.Count];
- // string Range_Row = (grid.Rows.Count + 1).ToString();
- // Microsoft.Office.Interop.Excel.Application oApp;
- // Microsoft.Office.Interop.Excel.Worksheet oSheet;
- // Microsoft.Office.Interop.Excel.Workbook oBook;
- // oApp = new Microsoft.Office.Interop.Excel.Application();
- // oBook = oApp.Workbooks.Add();
- // oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- // oSheet.Columns.WrapText = true;
- // int columns = grid.Columns.Count;
- // for (int x = 0; x < columns; x++)
- // {
- // // creating Columns :
- // oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- // }
- // oSheet.Cells.NumberFormat = "@";
- // int rows = grid.Rows.Count;
- // for (int i = 0; i < columns; i++)
- // {
- // for (int j = 0; j < rows; j++)
- // {
- // // creating rows :
- // oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value;
- // }
- // }
- // //Add some formatting
- // Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- // rng1.WrapText = true;
- // rng1.Font.Size = 8;
- // rng1.Font.Bold = true;
- // //rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- // rng1.Cells.Borders.Color = System.Drawing.Color.Black;
- // rng1.Font.Color = System.Drawing.Color.Black;
- // rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- // //rng1.Interior.Color = System.Drawing.Color.LightGray;
- // Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- // rng2.WrapText = false;
- // rng2.Font.Size = 6;
- // rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- // //rng2.Cells.Borders.Color = System.Drawing.Color.DeepSkyBlue;
- // rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- // //rng2.Interior.Color = System.Drawing.Color.Azure;
- // rng2.EntireColumn.AutoFit();
- // rng2.EntireRow.AutoFit();
- // oSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
- // oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- // if (complementario)
- // {
- // oSheet.Cells[1, 2] = "Fecha del Corte COmplementario: " + DateTime.Now.ToString("dd/MMMM/yyy");
- // }
- // else
- // {
- // oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- // }
- // Range rng3 = oSheet.get_Range("B1", Range_Letter + "2");
- // rng3.WrapText = true;
- // rng3.Merge(Missing.Value);
- // rng3.Font.Size = 11;
- // rng3.Font.Color = System.Drawing.Color.Black;
- // rng3.Font.Bold = true;
- // rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- // rng3.EntireColumn.AutoFit();
- // rng3.EntireRow.AutoFit();
- // //Add a header row
- // oSheet.get_Range("B1", Range_Letter + "2").EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- // oSheet.Cells[1, 3] = tituloReporte;
- // Range rng4 = oSheet.get_Range("B1", Range_Letter + "2");
- // rng4.Merge(Missing.Value);
- // rng4.WrapText = true;
- // rng4.Font.Size = 14;
- // rng4.Font.Color = System.Drawing.Color.Black;
- // rng4.Font.Bold = true;
- // rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- // Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- // Bitmap image = new Bitmap((Bitmap)Properties.Resources.itecExport, 84,84);
- // System.Windows.Forms.Clipboard.SetDataObject(image, true);
- // oSheet.Paste(oRange, image);
- // string filename = crearDirectorioImpresiones() + "\\" + DateTime.Now.Ticks.ToString() + ".xlsx";
- // if (!File.Exists(filename))
- // {
- // oBook.SaveAs(filename);
- // }
- // oBook.PrintOutEx(Type.Missing, Type.Missing, Type.Missing, Type.Missing, impresora, Type.Missing, Type.Missing, Type.Missing);
- // oBook.Close();
- // oApp.Quit();
- // try
- // {
- // if (File.Exists(filename))
- // {
- // File.Delete(filename);
- // }
- // }
- // catch (Exception) { }
- // return true;
- // }
- // catch (Exception e)
- // {
- // System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- // }
- // }
- // else
- // {
- // System.Windows.Forms.MessageBox.Show("No hay ningúna impresora seleccionada.\r\nFavor de seleccionar una impresora.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // }
- // }
- // else
- // {
- // System.Windows.Forms.MessageBox.Show("No hay ningún registro para imprimir.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- // }
- // return false;
- //}
- public static bool imprimirArchivoAlumnos(MetroFramework.Controls.MetroGrid grid, string impresora, string tituloReporte, string header, bool corteCaja)
- {
- if (grid.RowCount > 0)
- {
- if (impresora.Length > 0)
- {
- try
- {
- string Range_Letter = Alphabit[grid.Columns.Count];
- string Range_Row = (grid.Rows.Count + 1).ToString();
- Microsoft.Office.Interop.Excel.Application oApp;
- Microsoft.Office.Interop.Excel.Worksheet oSheet;
- Microsoft.Office.Interop.Excel.Workbook oBook;
- oApp = new Microsoft.Office.Interop.Excel.Application();
- oBook = oApp.Workbooks.Add();
- oSheet = (Microsoft.Office.Interop.Excel.Worksheet)oBook.Worksheets.get_Item(1);
- int columns = grid.Columns.Count;
- for (int x = 0; x < columns; x++)
- {
- // creating Columns :
- oSheet.Cells[1, x + 2] = grid.Columns[x].HeaderText;
- }
- oSheet.Cells.NumberFormat = "@";
- int rows = grid.Rows.Count;
- for (int i = 0; i < columns; i++)
- {
- for (int j = 0; j < rows; j++)
- {
- // creating rows :
- oSheet.Cells[j + 2, i + 2] = grid.Rows[j].Cells[i].Value;
- }
- }
- //Add some formatting
- Range rng1 = oSheet.get_Range("B1", Range_Letter + "1");
- rng1.Font.Size = 10;
- rng1.Font.Bold = true;
- rng1.Cells.Borders.LineStyle = XlLineStyle.xlDouble;
- //rng1.Cells.Borders.Color = System.Drawing.Color.DeepSkyBlue;
- rng1.Font.Color = System.Drawing.Color.Black;
- rng1.HorizontalAlignment = XlHAlign.xlHAlignCenter;
- //rng1.Interior.Color = System.Drawing.Color.LightGray;
- Range rng2 = oSheet.get_Range("B2", Range_Letter + Range_Row);
- rng2.WrapText = false;
- rng2.Font.Size = 9;
- rng2.Cells.Borders.LineStyle = XlLineStyle.xlContinuous;
- //rng2.Cells.Borders.Color = System.Drawing.Color.DeepSkyBlue;
- rng2.VerticalAlignment = XlVAlign.xlVAlignCenter;
- //rng2.Interior.Color = System.Drawing.Color.Azure;
- rng2.EntireColumn.AutoFit();
- rng2.EntireRow.AutoFit();
- oSheet.PageSetup.Orientation = XlPageOrientation.xlLandscape;
- string range = "2";
- if (header.Length > 0)
- {
- range = "3";
- }
- oSheet.get_Range("B1", Range_Letter + range).EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- if (corteCaja)
- {
- //Add a header row
- oSheet.Cells[1, 2] = "Fecha del Corte: " + DateTime.Now.ToString("dd/MMMM/yyy");
- }
- else
- {
- if (header.Length > 0)
- {
- oSheet.Cells[1, 3] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt") + "\r\n" + header;
- }
- else
- {
- oSheet.Cells[1, 2] = "Fecha del Reporte: " + DateTime.Now.ToString("dd/MM/yyy h:mm tt");
- }
- }
- Range rng3 = oSheet.get_Range("B1", Range_Letter + range);
- rng3.WrapText = true;
- rng3.Merge(Missing.Value);
- rng3.Font.Size = 11;
- rng3.Font.Color = System.Drawing.Color.Black;
- rng3.Font.Bold = true;
- rng3.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng3.EntireColumn.AutoFit();
- rng3.EntireRow.AutoFit();
- //Add a header row
- oSheet.get_Range("B1", Range_Letter + range).EntireRow.Insert(XlInsertShiftDirection.xlShiftDown, Missing.Value);
- oSheet.Cells[1, 3] = tituloReporte;
- Range rng4 = oSheet.get_Range("B1", Range_Letter + range);
- rng4.Merge(Missing.Value);
- rng4.WrapText = true;
- rng4.Font.Size = 14;
- rng4.Font.Color = System.Drawing.Color.Black;
- rng4.Font.Bold = true;
- rng4.VerticalAlignment = XlVAlign.xlVAlignCenter;
- rng4.HorizontalAlignment = XlVAlign.xlVAlignCenter;
- Microsoft.Office.Interop.Excel.Range oRange = (Microsoft.Office.Interop.Excel.Range)oSheet.Cells[1, 2];
- Bitmap image = new Bitmap((Bitmap)Properties.Resources.uniitec, 150, 80);
- System.Windows.Forms.Clipboard.SetDataObject(image, true);
- oSheet.Paste(oRange, image);
- //rng3.Interior.Color = System.Drawing.Color.LightSkyBlue;
- string filename = crearDirectorioImpresiones() + "\\" + DateTime.Now.Ticks.ToString() + ".xlsx";
- if (!File.Exists(filename))
- {
- oBook.SaveAs(filename);
- }
- oBook.PrintOutEx(Type.Missing, Type.Missing, Type.Missing, Type.Missing, impresora, Type.Missing, Type.Missing, Type.Missing);
- oBook.Close();
- oApp.Quit();
- try
- {
- if (File.Exists(filename))
- {
- File.Delete(filename);
- }
- }
- catch (Exception) { }
- return true;
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine("ERROR AL EXPORTAR A EXCEL:" + e.ToString());
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningúna impresora seleccionada.\r\nFavor de seleccionar una impresora.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- else
- {
- System.Windows.Forms.MessageBox.Show("No hay ningún registro para imprimir.", Global.STR_NOMBRE_SISTEMA, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- return false;
- }
- private static string crearDirectorioImpresiones()
- {
- string strFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Universidad_Itec";
- string strDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Universidad_Itec";
- if (!System.IO.Directory.Exists(strDirectory))
- {
- System.IO.Directory.CreateDirectory(strDirectory);
- }
- strDirectory = strDirectory + "\\Temp";
- if (!System.IO.Directory.Exists(strDirectory))
- {
- System.IO.Directory.CreateDirectory(strDirectory);
- }
- return strDirectory;
- }
- private static string crearDirectorioCortesCaja()
- {
- string strFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Universidad_Itec";
- string strDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Universidad_Itec";
- if (!System.IO.Directory.Exists(strDirectory))
- {
- System.IO.Directory.CreateDirectory(strDirectory);
- }
- strDirectory = strDirectory + "\\CortesCaja";
- if (!System.IO.Directory.Exists(strDirectory))
- {
- System.IO.Directory.CreateDirectory(strDirectory);
- }
- return strDirectory;
- }
- public static string ObtenerDomicilio(string strCalle, string strNumero, string strNumeroInterior, string strColonia, string strCodigoPostal, string estado, string ciudad, string pais)
- {
- string strResultado = strCalle;
- if (strNumero != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += "No. " + strNumero;
- }
- if (strNumeroInterior != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += "Interior " + strNumeroInterior;
- }
- if (strColonia != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += strColonia;
- }
- if (strCodigoPostal != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += "C.P. " + strCodigoPostal;
- }
- if (ciudad != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += ciudad + ", ";
- }
- if (estado != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += estado;
- }
- if (pais != string.Empty)
- {
- if (strResultado != string.Empty) { strResultado += " "; }
- strResultado += pais;
- }
- return strResultado;
- }
- public static string NumeroALetras(string num)
- {
- string res, dec = "";
- Int64 entero;
- int decimales;
- double nro;
- try
- {
- nro = StringToDouble(num);
- }
- catch
- {
- return "";
- }
- entero = Convert.ToInt64(Math.Truncate(nro));
- decimales = Convert.ToInt32(Math.Round((nro - entero) * 100, 2));
- if (decimales < 10)
- {
- dec = " PESOS CON 0" + decimales.ToString() + "/100 MN";
- }
- else
- {
- dec = " PESOS CON " + decimales.ToString() + "/100 MN";
- }
- res = toText(Convert.ToDouble(entero)) + dec;
- return res;
- }
- private static string toText(double value)
- {
- string Num2Text = "";
- value = Math.Truncate(value);
- if (value == 0) Num2Text = "CERO";
- else if (value == 1) Num2Text = "UNO";
- else if (value == 2) Num2Text = "DOS";
- else if (value == 3) Num2Text = "TRES";
- else if (value == 4) Num2Text = "CUATRO";
- else if (value == 5) Num2Text = "CINCO";
- else if (value == 6) Num2Text = "SEIS";
- else if (value == 7) Num2Text = "SIETE";
- else if (value == 8) Num2Text = "OCHO";
- else if (value == 9) Num2Text = "NUEVE";
- else if (value == 10) Num2Text = "DIEZ";
- else if (value == 11) Num2Text = "ONCE";
- else if (value == 12) Num2Text = "DOCE";
- else if (value == 13) Num2Text = "TRECE";
- else if (value == 14) Num2Text = "CATORCE";
- else if (value == 15) Num2Text = "QUINCE";
- else if (value < 20) Num2Text = "DIECI" + toText(value - 10);
- else if (value == 20) Num2Text = "VEINTE";
- else if (value < 30) Num2Text = "VEINTI" + toText(value - 20);
- else if (value == 30) Num2Text = "TREINTA";
- else if (value == 40) Num2Text = "CUARENTA";
- else if (value == 50) Num2Text = "CINCUENTA";
- else if (value == 60) Num2Text = "SESENTA";
- else if (value == 70) Num2Text = "SETENTA";
- else if (value == 80) Num2Text = "OCHENTA";
- else if (value == 90) Num2Text = "NOVENTA";
- else if (value < 100) Num2Text = toText(Math.Truncate(value / 10) * 10) + " Y " + toText(value % 10);
- else if (value == 100) Num2Text = "CIEN";
- else if (value < 200) Num2Text = "CIENTO " + toText(value - 100);
- else if ((value == 200) || (value == 300) || (value == 400) || (value == 600) || (value == 800)) Num2Text = toText(Math.Truncate(value / 100)) + "CIENTOS";
- else if (value == 500) Num2Text = "QUINIENTOS";
- else if (value == 700) Num2Text = "SETECIENTOS";
- else if (value == 900) Num2Text = "NOVECIENTOS";
- else if (value < 1000) Num2Text = toText(Math.Truncate(value / 100) * 100) + " " + toText(value % 100);
- else if (value == 1000) Num2Text = "MIL";
- else if (value < 2000) Num2Text = "MIL " + toText(value % 1000);
- else if (value < 1000000)
- {
- Num2Text = toText(Math.Truncate(value / 1000)) + " MIL";
- if ((value % 1000) > 0) Num2Text = Num2Text + " " + toText(value % 1000);
- }
- else if (value == 1000000) Num2Text = "UN MILLON";
- else if (value < 2000000) Num2Text = "UN MILLON " + toText(value % 1000000);
- else if (value < 1000000000000)
- {
- Num2Text = toText(Math.Truncate(value / 1000000)) + " MILLONES ";
- if ((value - Math.Truncate(value / 1000000) * 1000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000) * 1000000);
- }
- else if (value == 1000000000000) Num2Text = "UN BILLON";
- else if (value < 2000000000000) Num2Text = "UN BILLON " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);
- else
- {
- Num2Text = toText(Math.Truncate(value / 1000000000000)) + " BILLONES";
- if ((value - Math.Truncate(value / 1000000000000) * 1000000000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);
- }
- return Num2Text;
- }
- public static byte[] ImageToByte(System.Drawing.Image pImagen)
- {
- byte[] mImage = null;
- System.IO.MemoryStream ms = new System.IO.MemoryStream();
- pImagen.Save(ms, pImagen.RawFormat);
- mImage = ms.GetBuffer();
- ms.Close();
- return mImage;
- }
- public static bool hayInternet()
- {
- NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
- foreach (NetworkInterface nic in nics)
- {
- if (string.Compare(nic.Name, "hamachi", true) == 0)
- {
- continue;
- }
- if (
- (nic.NetworkInterfaceType != NetworkInterfaceType.Loopback && nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel) &&
- nic.OperationalStatus == OperationalStatus.Up)
- {
- return true;
- }
- }
- return false;
- }
- public static bool refreshToken()
- {
- bool result = false;
- if (hayInternet())
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
- request.Method = "POST";
- request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
- request.Timeout = 10000;
- request.Headers.Add("Accept-Language", "en-us,en;q=0.5");
- request.ContentType = "application/x-www-form-urlencoded";
- request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
- request.KeepAlive = true;
- string strPosData = "client_id=" + clientID + "&client_secret=" + clientSecret + "&refresh_token=" + Refresh_Token + "&grant_type=refresh_token";
- request.ContentLength = strPosData.Length;
- StreamWriter sw3 = new StreamWriter(request.GetRequestStream());
- sw3.Write(strPosData);
- sw3.Close();
- try
- {
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- string strHTML = string.Empty;
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- strHTML = reader.ReadToEnd();
- reader.Close();
- string token = Utility.GetRegExParsedValue("access_token\" : \"(?<RetVal>.*?)\"", strHTML);
- if (token.Length > 0)
- {
- Access_Token = token;
- result = true;
- Tokens t = new Tokens();
- t.AccessToken = token;
- t.RefreshToken = Refresh_Token;
- frmPrincipal._BaseDatos.InsertarTokens(t);
- t = null;
- }
- }
- }
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- }
- return result;
- }
- public static bool IsValidToken()
- {
- bool result = false;
- if (hayInternet())
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + Access_Token);
- request.Method = "GET";
- request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
- request.Timeout = 10000;
- request.Headers.Add("Accept-Language", "en-us,en;q=0.5");
- //request.ContentType = "application/x-www-form-urlencoded";
- request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
- request.KeepAlive = true;
- try
- {
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- string strHTML = string.Empty;
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- strHTML = reader.ReadToEnd();
- reader.Close();
- string email = Utility.GetRegExParsedValue("email\": \"(?<RetVal>.*?)\"", strHTML);
- if (email.Length > 0)
- {
- result = true;
- }
- }
- }
- }
- catch (Exception e)
- {
- System.Diagnostics.Debug.WriteLine(e.ToString());
- }
- }
- return result;
- }
- }
- public class MetodoPago
- {
- private int clave;
- private string definicion;
- public MetodoPago(int clave, string definicion)
- {
- this.clave = clave;
- this.definicion = definicion;
- }
- public int Clave
- {
- get { return clave; }
- set { clave = value; }
- }
- public string Definicion
- {
- get { return definicion; }
- set { definicion = value; }
- }
- public override string ToString()
- {
- return clave.ToString("D2") + " " + definicion;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement