Пример #1
0
        public void EnvioFTP()
        {
            EmpresasBL empBL = new EmpresasBL();

            empBL.SetParameters(db);
            ComprobantesBL compBL = new ComprobantesBL();

            compBL.SetParameters(db);

            Empresas empresa = empBL.GetObject(GeneralSettings.Instance.IdEmpresaDefault) as Empresas;

            if (empresa != null)
            {
                Ftp FtpClient = new Ftp();
                FtpClient.HostAddress = FTPHost;
                FtpClient.Port        = FTPPort;
                FtpClient.Username    = FTPName;
                FtpClient.Password    = FTPPass;
                FtpClient.Timeout     = FTPTimeOut;
                FtpClient.Connect();

                string       fileName = empresa.Cuit + "_" + DateTime.Now.ToString("yyyyMMdd_hhmm") + ".txt";
                StreamWriter tw       = File.CreateText(fileName);

                FtpClient.MoveDirectory(empresa.Cuit);
                int cantidadEmitidos = 0;
                foreach (Comprobantes comp in compBL.GetDataSource())
                {
                    if (comp.IsEmitido)
                    {
                        tw.Write(compBL.GetResumeStream(comp));
                        cantidadEmitidos++;
                    }
                }
                tw.Write("Cantidad de facturas emitidas: " + cantidadEmitidos.ToString() + "\r\n");
                tw.Close();

                FtpClient.PutFile(fileName);
                FtpClient.Quit();

                File.Delete(fileName);
            }
        }
Пример #2
0
        public bool IsValidLicense()
        {
            if (!lastLicenseCheck.HasValue || lastLicenseCheck.Value.AddMonths(1) < DateTime.Today)
            {
                EmpresasBL empBL = new EmpresasBL();
                empBL.SetParameters(db);
                ComprobantesBL compBL = new ComprobantesBL();
                compBL.SetParameters(db);

                Empresas empresa = empBL.GetObject(GeneralSettings.Instance.IdEmpresaDefault) as Empresas;
                if (empresa != null)
                {
                    Ftp FtpClient = new Ftp();
                    FtpClient.HostAddress = FTPHost;
                    FtpClient.Port        = FTPPort;
                    FtpClient.Username    = FTPName;
                    FtpClient.Password    = FTPPass;
                    FtpClient.Timeout     = FTPTimeOut;
                    FtpClient.Connect();

                    string fileName = empresa.Cuit;

                    FtpClient.MoveDirectory("Licencias");
                    FtpItemCollection fic = new FtpItemCollection();
                    FtpClient.FileList(ref fic);
                    foreach (FtpItem item in fic)
                    {
                        if (item.Name.ToLower() == fileName.ToLower())
                        {
                            lastLicenseCheck = DateTime.Today;
                            return(true);
                        }
                    }
                    FtpClient.Quit();
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }