Example #1
0
        private static void LoadDim(string empresa, int idEmpresa, CatSeller cat, NpgsqlConnection conn)
        {
            NpgsqlCommand cmd;

            string sqlString = "INSERT INTO dim_sellers (ap_id, agent_code, agent_name, empresa, id_empresa)" +
                               "VALUES(@ap_id, @codigo, @nombre, @empresa, @idEmpresa);";


            cmd = new NpgsqlCommand(sqlString, conn);

            cmd.Parameters.Add("@ap_id", NpgsqlTypes.NpgsqlDbType.Integer);
            cmd.Parameters.Add("@codigo", NpgsqlTypes.NpgsqlDbType.Varchar, 10);
            cmd.Parameters.Add("@nombre", NpgsqlTypes.NpgsqlDbType.Varchar, 150);
            cmd.Parameters.Add("@empresa", NpgsqlTypes.NpgsqlDbType.Varchar, 150);
            cmd.Parameters.Add("@idEmpresa", NpgsqlTypes.NpgsqlDbType.Integer);

            cmd.Parameters["@ap_id"].Value  = cat.IdVendedor;
            cmd.Parameters["@codigo"].Value = cat.CodigoVendedor;
            cmd.Parameters["@nombre"].Value = cat.NombreVendedor;

            cmd.Parameters["@empresa"].Value   = empresa;
            cmd.Parameters["@idEmpresa"].Value = idEmpresa;

            cmd.ExecuteNonQuery();
        }
Example #2
0
        private static void UpdateDim(string empresa, CatSeller cat, DimSellers dim, NpgsqlConnection conn)
        {
            NpgsqlCommand cmd;

            string sqlString = "UPDATE dim_sellers " +
                               "SET agent_code=@codigo, " +
                               "agent_name=@nombre " +
                               "WHERE seller_id=@id;";


            cmd = new NpgsqlCommand(sqlString, conn);

            cmd.Parameters.Add("@codigo", NpgsqlTypes.NpgsqlDbType.Varchar, 10);
            cmd.Parameters.Add("@nombre", NpgsqlTypes.NpgsqlDbType.Varchar, 150);
            cmd.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Integer);

            cmd.Parameters["@codigo"].Value = cat.CodigoVendedor;
            cmd.Parameters["@nombre"].Value = cat.NombreVendedor;
            cmd.Parameters["@id"].Value     = dim.IdSeller;

            cmd.ExecuteNonQuery();
        }
Example #3
0
        public void MineMonitors(EventLog log)
        {
            var configuredClients = ConfigurationManager.AppSettings as NameValueCollection;

            if (configuredClients == null)
            {
                log.WriteEntry("Unable to load the configuration file.", EventLogEntryType.Warning, 13, 1);
                return;
            }

            if (configuredClients.Count == 0)
            {
                log.WriteEntry("No keys detected in configuration file.", EventLogEntryType.Warning, 14, 1);
                return;
            }

            //PgDbCollector.CleanFactDocument();

            foreach (var key in configuredClients.AllKeys)
            {
                string configuredClient = configuredClients.GetValues(key).FirstOrDefault();
                if ("libDir".Equals(key.ToString()))
                {
                    continue;
                }

                EnterpriseSection clientConfig = (EnterpriseSection)System.Configuration.ConfigurationManager.GetSection("Empresas/" + configuredClient);

                if (clientConfig == null)
                {
                    log.WriteEntry("Client configuration not found for Empresas/" + configuredClient + ".", EventLogEntryType.Warning, 15, 1);
                    continue;
                }

                Empresa empresa = PgDbCollector.GetCompanyByName(clientConfig.NombreEmpresa);
                log.WriteEntry("Client configuration found in database: " + clientConfig.NombreEmpresa + "; " + empresa.Ruta);

                NpgsqlConnection conn             = new NpgsqlConnection();
                string           connectionString = ConfigurationManager.ConnectionStrings[Config.Common.JASPER].ConnectionString;
                conn = new NpgsqlConnection(connectionString);
                conn.Open();

                if (empresa != null)
                {
                    log.WriteEntry("Invoice codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosFactura + "]", EventLogEntryType.Information, 16, 1);
                    log.WriteEntry("Payment codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosPago + "]", EventLogEntryType.Information, 17, 1);
                    log.WriteEntry("Sale codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosVenta + "]", EventLogEntryType.Information, 17, 1);
                    log.WriteEntry("Return codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosDevolucion + "]", EventLogEntryType.Information, 17, 1);
                    string[] facturas   = clientConfig.CodigosFactura.Split(',');
                    string[] abonos     = clientConfig.CodigosPago.Split(',');
                    string[] venta      = clientConfig.CodigosVenta.Split(',');
                    string[] devolucion = clientConfig.CodigosDevolucion.Split(',');
                    try
                    {
                        //AdminPaqImpl.DownloadMonitors(venta, devolucion, facturas, abonos, empresa, log);

                        log.WriteEntry("Downloading from AdminPaq: " + empresa.Ruta, EventLogEntryType.Information, 8, 2);
                        // DIM ETLs
                        List <CatCliente> clientes = CatCliente.GetClientes(empresa.Ruta);
                        log.WriteEntry(clientes.Count + " clientes found for " + empresa.Nombre + " in AdminPaq", EventLogEntryType.Information, 9, 2);
                        ETLClientes.Execute(empresa.Id, empresa.Nombre, clientes, conn);

                        List <CatSeller> sellers = CatSeller.GetSellers(empresa.Ruta);
                        log.WriteEntry(sellers.Count + " agents found for " + empresa.Nombre + " in AdminPaq", EventLogEntryType.Information, 10, 2);
                        ETLSellers.Execute(empresa.Id, empresa.Nombre, sellers, conn);

                        ETLMeses.Execute(conn);

                        // FACT Preparation
                        FactVencido vencido = new FactVencido();
                        vencido.Prepare(empresa.Id, empresa.Ruta, conn);
                        log.WriteEntry(string.Format("Prepared due documents for {0}", empresa.Nombre), EventLogEntryType.Information, 11, 2);

                        FactPorVencer porVencer = new FactPorVencer();
                        porVencer.Prepare(empresa.Id, empresa.Ruta, conn);
                        log.WriteEntry(string.Format("Prepared documents about to due for {0}", empresa.Nombre), EventLogEntryType.Information, 12, 2);

                        FactCobranza cobranza = new FactCobranza();
                        cobranza.Prepare(empresa.Id, empresa.Ruta, conn);
                        log.WriteEntry(string.Format("Prepared collection documents for {0}", empresa.Nombre), EventLogEntryType.Information, 13, 2);

                        FactSales factSale = new FactSales();
                        factSale.Prepare(empresa.Id, empresa.Ruta, conn);
                        log.WriteEntry(string.Format("Prepared sale documents for {0}", empresa.Nombre), EventLogEntryType.Information, 14, 2);

                        // FILL FACTS
                        DocsMiner dMiner = new DocsMiner();
                        dMiner.Vencidos  = vencido.GruposVencimiento;
                        dMiner.PorVencer = porVencer.GruposVencimiento;
                        dMiner.Cobranza  = cobranza.GruposCobranza;
                        dMiner.Ventas    = factSale.GruposVenta;

                        log.WriteEntry(string.Format("Mining documents for {0} started", empresa.Nombre), EventLogEntryType.Information, 15, 2);

                        dMiner.Execute(empresa, facturas, abonos, venta, devolucion, log);
                        log.WriteEntry(string.Format("Mining documents for {0} completed", empresa.Nombre), EventLogEntryType.Information, 16, 2);

                        MainLoader loader = new MainLoader();
                        loader.Vencidos  = dMiner.Vencidos;
                        loader.PorVencer = dMiner.PorVencer;
                        loader.Cobranza  = dMiner.Cobranza;
                        loader.Ventas    = dMiner.Ventas;

                        log.WriteEntry(string.Format("Loading documents for {0} started", empresa.Nombre), EventLogEntryType.Information, 17, 2);
                        loader.Load(empresa.Id, conn);
                        log.WriteEntry(string.Format("Loading documents for {0} completed", empresa.Nombre), EventLogEntryType.Information, 18, 2);
                    }catch (Exception ex) {
                        log.WriteEntry("Exception while mining monitors: " + ex.Message + " || " + ex.StackTrace, EventLogEntryType.Error, 19, 2);
                    }
                }
                conn.Close();
            }
        }