public void UpdateAccounts(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; } foreach (var key in configuredClients.AllKeys) { string configuredClient = configuredClients.GetValues(key).FirstOrDefault(); 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); if (empresa != null) { log.WriteEntry("Payment codes found for " + clientConfig.NombreEmpresa + " as [" + clientConfig.CodigosPago + "]", EventLogEntryType.Information, 17, 1); string[] abonos = clientConfig.CodigosPago.Split(','); List <int> accounts = PgDbCollector.GetAccointIds(empresa.Id); log.WriteEntry("Updating " + accounts.Count + " Accounts", EventLogEntryType.Information, 19, 1); int connection = AdminPaqLib.dbLogIn("", empresa.Ruta); if (connection == 0) { throw new Exception("No fue posible establecer la conexión con la base de datos de la empresa en la ruta: " + empresa.Ruta); } foreach (int accountId in accounts) { Account account = PgDbCollector.GetAccountById(accountId); AdminPaqImpl.DownloadCollectable(account, abonos, connection); } accounts.Clear(); accounts = null; AdminPaqLib.dbLogOut(connection); } } }
public void DownloadAllAccounts(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; } 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); 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); string[] facturas = clientConfig.CodigosFactura.Split(','); string[] abonos = clientConfig.CodigosPago.Split(','); AdminPaqImpl.DownloadAllCollectables(facturas, abonos, empresa, log); } } }
private void frmMain_Load(object sender, EventArgs e) { api = new AdminPaqImpl(); api.InitializeSDK(); timer1.Start(); }
public static void UpdateAccount(Account account, bool isCancelled) { if (isCancelled) { CloseAccount(account.DocId); return; } string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.MONFOLL].ConnectionString; NpgsqlConnection conn; conn = new NpgsqlConnection(connectionString); conn.Open(); string sqlString = "UPDATE ctrl_cuenta " + "SET F_DOCUMENTO = @f_documento, " + "F_VENCIMIENTO = @f_vencimiento, " + "ID_CLIENTE = @id_cliente, " + "SERIE_DOCO = @serie_doco, " + "FOLIO_DOCO = @folio_doco, " + "TIPO_DOCUMENTO = @tipo_documento, " + "FACTURADO = @facturado, " + "SALDO = @saldo, " + "MONEDA = @moneda, " + "F_COBRO = @collect_date, " + "TIPO_COBRO = @collect_type, " + "OBSERVACIONES = @obs_note, " + "TS_DESCARGADO = CURRENT_TIMESTAMP " + "WHERE ap_id = @id AND enterprise_id = @enterprise"; NpgsqlCommand cmd = new NpgsqlCommand(sqlString, conn); cmd.Parameters.Add("@f_documento", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@f_vencimiento", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@serie_doco", NpgsqlTypes.NpgsqlDbType.Varchar, 4); cmd.Parameters.Add("@folio_doco", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@tipo_documento", NpgsqlTypes.NpgsqlDbType.Varchar, 150); cmd.Parameters.Add("@facturado", NpgsqlTypes.NpgsqlDbType.Money); cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Money); cmd.Parameters.Add("@moneda", NpgsqlTypes.NpgsqlDbType.Varchar, 50); cmd.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@enterprise", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@collect_date", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@collect_type", NpgsqlTypes.NpgsqlDbType.Varchar, 100); cmd.Parameters.Add("@obs_note", NpgsqlTypes.NpgsqlDbType.Varchar, 250); cmd.Parameters["@f_documento"].Value = account.DocDate; cmd.Parameters["@f_vencimiento"].Value = account.DueDate; int coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId); if (coId == 0) { Company company = AdminPaqImpl.GetCompany(account.Company.ApId, account.Company.EnterprisePath, account.Company.EnterpriseId); if (company != null) { AddCompany(conn, company); } else { conn.Close(); return; } coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId); if (coId == 0) { conn.Close(); return; } } cmd.Parameters["@id_cliente"].Value = coId; cmd.Parameters["@serie_doco"].Value = account.Serie; cmd.Parameters["@folio_doco"].Value = account.Folio; cmd.Parameters["@tipo_documento"].Value = account.DocType; cmd.Parameters["@facturado"].Value = account.Amount; cmd.Parameters["@saldo"].Value = account.Balance; cmd.Parameters["@moneda"].Value = account.Currency; cmd.Parameters["@id"].Value = account.ApId; cmd.Parameters["@enterprise"].Value = account.Company.EnterpriseId; cmd.Parameters["@collect_date"].Value = account.CollectDate; cmd.Parameters["@collect_type"].Value = account.CollectType; cmd.Parameters["@obs_note"].Value = account.Note; cmd.ExecuteNonQuery(); conn.Close(); }
public static void AddAccount(Account account, EventLog log) { string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.MONFOLL].ConnectionString; NpgsqlConnection conn; conn = new NpgsqlConnection(connectionString); conn.Open(); string sqlString = "INSERT INTO ctrl_cuenta (ap_id, enterprise_id, F_DOCUMENTO, F_VENCIMIENTO, F_COBRO, ID_CLIENTE, SERIE_DOCO, FOLIO_DOCO, TIPO_DOCUMENTO, TIPO_COBRO, FACTURADO, " + "SALDO, MONEDA, OBSERVACIONES) " + "VALUES( @id, @enterprise, @f_documento, @f_vencimiento, @f_cobro, @id_cliente, @serie_doco, @folio_doco, @tipo_documento, @tipo_cobro, @facturado, @saldo, " + "@moneda, @observaciones);"; NpgsqlCommand cmd = new NpgsqlCommand(sqlString, conn); cmd.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@enterprise", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@f_documento", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@f_vencimiento", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@f_cobro", NpgsqlTypes.NpgsqlDbType.Date); cmd.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@serie_doco", NpgsqlTypes.NpgsqlDbType.Varchar, 4); cmd.Parameters.Add("@folio_doco", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@tipo_documento", NpgsqlTypes.NpgsqlDbType.Varchar, 150); cmd.Parameters.Add("@tipo_cobro", NpgsqlTypes.NpgsqlDbType.Varchar, 100); cmd.Parameters.Add("@facturado", NpgsqlTypes.NpgsqlDbType.Money); cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Money); cmd.Parameters.Add("@moneda", NpgsqlTypes.NpgsqlDbType.Varchar, 50); cmd.Parameters.Add("@observaciones", NpgsqlTypes.NpgsqlDbType.Varchar, 250); cmd.Parameters["@id"].Value = account.ApId; cmd.Parameters["@enterprise"].Value = account.Company.EnterpriseId; cmd.Parameters["@f_documento"].Value = account.DocDate; cmd.Parameters["@f_vencimiento"].Value = account.DueDate; cmd.Parameters["@f_cobro"].Value = account.CollectDate; int coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId); if (coId == 0) { log.WriteEntry("Unable to find client apId: " + account.Company.ApId + "; enterprise: " + account.Company.EnterpriseId, EventLogEntryType.Warning); Company company = AdminPaqImpl.GetCompany(account.Company.ApId, account.Company.EnterprisePath, account.Company.EnterpriseId); if (company != null) { AddCompany(conn, company); } else { log.WriteEntry("Unable to find client in adminPaq", EventLogEntryType.Warning); conn.Close(); return; } coId = CompanyId(conn, account.Company.ApId, account.Company.EnterpriseId); if (coId == 0) { conn.Close(); return; } } cmd.Parameters["@id_cliente"].Value = coId; cmd.Parameters["@serie_doco"].Value = account.Serie; cmd.Parameters["@folio_doco"].Value = account.Folio; cmd.Parameters["@tipo_documento"].Value = account.DocType; cmd.Parameters["@tipo_cobro"].Value = account.CollectType; cmd.Parameters["@facturado"].Value = account.Amount; cmd.Parameters["@saldo"].Value = account.Balance; cmd.Parameters["@moneda"].Value = account.Currency; cmd.Parameters["@observaciones"].Value = account.Note; cmd.ExecuteNonQuery(); conn.Close(); }