private static void ActualizarVencimiento(FactVencimiento vencimiento, GrupoVencimiento grupo, NpgsqlConnection conn) { string sqlString = "SELECT id_grupo_vencimiento, minimo_dias, maximo_dias " + "FROM dim_grupo_vencimiento;"; NpgsqlCommand cmd = new NpgsqlCommand(sqlString, conn); cmd.ExecuteNonQuery(); }
private void AddFactVencido(FactVencimiento fact, NpgsqlConnection conn) { NpgsqlCommand cmd; string sqlString = "INSERT INTO fact_vencido(id_cliente, id_grupo_vencimiento, saldo_vencido)" + "VALUES(@cliente, @grupo, @saldo);"; cmd = new NpgsqlCommand(sqlString, conn); cmd.Parameters.Add("@cliente", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@grupo", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Numeric); cmd.Parameters["@cliente"].Value = fact.Cliente.IdCliente; cmd.Parameters["@grupo"].Value = fact.GrupoVencimiento.IdGrupo; cmd.Parameters["@saldo"].Value = fact.Saldo; cmd.ExecuteNonQuery(); }
private void UpdateFactVencido(FactVencimiento fact, NpgsqlConnection conn) { NpgsqlCommand cmd; string sqlString = "UPDATE fact_vencido SET " + "saldo_vencido = @saldo " + "WHERE id_cliente = @cliente AND id_grupo_vencimiento = @grupo;"; cmd = new NpgsqlCommand(sqlString, conn); cmd.Parameters.Add("@cliente", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@grupo", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@saldo", NpgsqlTypes.NpgsqlDbType.Numeric); cmd.Parameters["@cliente"].Value = fact.Cliente.IdCliente; cmd.Parameters["@grupo"].Value = fact.GrupoVencimiento.IdGrupo; cmd.Parameters["@saldo"].Value = fact.Saldo; cmd.ExecuteNonQuery(); }
public static void GrabarVencimientos(List <FactVencimiento> vencimientos, GrupoVencimiento grupo, string USDTag) { List <FactVencimiento> listAllFactVencimientosInDB = new List <FactVencimiento>(); string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.JASPER].ConnectionString; using (NpgsqlConnection pgConnection = new NpgsqlConnection(connectionString)) { pgConnection.Open(); NpgsqlDataReader dr; NpgsqlCommand cmd; string sqlString = "SELECT id_cliente, id_grupo_vencimiento, saldo_vencido " + "FROM fact_vencido" + USDTag + ";"; cmd = new NpgsqlCommand(sqlString, pgConnection); dr = cmd.ExecuteReader(); while (dr.Read()) { FactVencimiento oFactVencimiento = new FactVencimiento(); DimCliente dCliente = new DimCliente(); dCliente.IdCliente = int.Parse(dr["id_cliente"].ToString()); oFactVencimiento.Cliente = dCliente; oFactVencimiento.IdVencimiento = int.Parse(dr["id_grupo_vencimiento"].ToString()); oFactVencimiento.Importe = double.Parse(dr["saldo_vencido"].ToString()); listAllFactVencimientosInDB.Add(oFactVencimiento); } dr.Close(); cmd.Dispose(); pgConnection.Close(); } lGrabarVencimientos(vencimientos, grupo, listAllFactVencimientosInDB, USDTag); }
private bool VencidoExists(FactVencimiento fact, NpgsqlConnection conn) { NpgsqlCommand cmd; string sqlString = "SELECT id_cliente " + "FROM fact_vencido " + "WHERE id_cliente = @cliente AND id_grupo_vencimiento = @grupo;"; cmd = new NpgsqlCommand(sqlString, conn); cmd.Parameters.Add("@cliente", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters.Add("@grupo", NpgsqlTypes.NpgsqlDbType.Integer); cmd.Parameters["@cliente"].Value = fact.Cliente.IdCliente; cmd.Parameters["@grupo"].Value = fact.GrupoVencimiento.IdGrupo; NpgsqlDataReader dr = cmd.ExecuteReader(); bool result = dr.Read(); dr.Close(); return(result); }
private static void lGrabarVencimientos(List <FactVencimiento> vencimientos, GrupoVencimiento grupo, List <FactVencimiento> listAllFactVencimientosInDB, string USDTag) { string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.JASPER].ConnectionString; // Para cada ID Doco en la BD de postgres using (NpgsqlConnection pgConnection = new NpgsqlConnection(connectionString)) { try { pgConnection.Open(); using (NpgsqlTransaction transaction = pgConnection.BeginTransaction()) { try { foreach (FactVencimiento vencimiento in vencimientos) { NpgsqlCommand theCommand; FactVencimiento oFactVencimientToPersist = vencimiento; // Check if record exists. bool exists = false; foreach (FactVencimiento record in listAllFactVencimientosInDB) { if (record.Cliente.IdCliente == vencimiento.Cliente.IdCliente) { exists = true; break; } } // if record exists, update the record. string updateString = ""; if (exists) { updateString = "UPDATE fact_vencido" + USDTag + " " + "SET saldo_vencido=@saldo_vencido " + "WHERE id_cliente=@id_cliente and id_grupo_vencimiento=@id_grupo_vencimiento;"; } // if record does not exists, insert the record else { updateString = "INSERT INTO fact_vencido" + USDTag + "(" + "id_cliente, id_grupo_vencimiento, saldo_vencido) " + "VALUES (@id_cliente, @id_grupo_vencimiento, @saldo_vencido);"; } theCommand = new NpgsqlCommand(updateString, pgConnection); theCommand.Parameters.Add("@saldo_vencido", NpgsqlTypes.NpgsqlDbType.Numeric); theCommand.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer); theCommand.Parameters.Add("@id_grupo_vencimiento", NpgsqlTypes.NpgsqlDbType.Integer); theCommand.Parameters["@saldo_vencido"].Value = oFactVencimientToPersist.Importe; theCommand.Parameters["@id_cliente"].Value = oFactVencimientToPersist.Cliente.IdCliente; theCommand.Parameters["@id_grupo_vencimiento"].Value = grupo.Id; theCommand.ExecuteNonQuery(); } transaction.Commit(); } catch (Exception ex) { if (transaction != null) { transaction.Rollback(); } throw ex; } } } catch (Exception ex) { throw ex; } pgConnection.Close(); } }
public static void GrabarPorVencer(List <FactVencimiento> porvencer, GrupoVencimiento grupo, string USDTag) { List <FactVencimiento> listAllFactPorVencerInDB = new List <FactVencimiento>(); string connectionString = ConfigurationManager.ConnectionStrings[Config.Common.JASPER].ConnectionString; using (NpgsqlConnection pgConnection = new NpgsqlConnection(connectionString)) { pgConnection.Open(); NpgsqlDataReader dr; NpgsqlCommand cmd; string sqlString = "SELECT id_cliente, id_grupo_vencimiento, saldo_por_vencer " + "FROM fact_por_vencer" + USDTag + ";"; cmd = new NpgsqlCommand(sqlString, pgConnection); dr = cmd.ExecuteReader(); while (dr.Read()) { FactVencimiento oFactPorVencer = new FactVencimiento(); DimCliente dCliente = new DimCliente(); dCliente.IdCliente = int.Parse(dr["id_cliente"].ToString()); oFactPorVencer.Cliente = dCliente; oFactPorVencer.IdVencimiento = int.Parse(dr["id_grupo_vencimiento"].ToString()); oFactPorVencer.Importe = double.Parse(dr["saldo_por_vencer"].ToString()); listAllFactPorVencerInDB.Add(oFactPorVencer); } dr.Close(); cmd.Dispose(); pgConnection.Close(); } // Para cada ID Doco en la BD de postgres using (NpgsqlConnection pgConnection = new NpgsqlConnection(connectionString)) { try { pgConnection.Open(); using (NpgsqlTransaction transaction = pgConnection.BeginTransaction()) { try { foreach (FactVencimiento currentPorVencer in porvencer) { NpgsqlCommand theCommand; FactVencimiento oFactPorVencerToPersist = currentPorVencer; // Check if record exists. bool exists = false; foreach (FactVencimiento record in listAllFactPorVencerInDB) { if (record.Cliente.IdCliente == currentPorVencer.Cliente.IdCliente) { exists = true; break; } } //FactPorVencer oFactPorVencerExistente = listAllFactPorVencerInDB.First(record => record.IdCliente == currentPorVencer.IdCliente && record.IdEmpresa == currentPorVencer.IdEmpresa && record.IdVencimiento == currentPorVencer.IdVencimiento); // if record exists, update the record. if (exists) { string sqlUpdateVencimiento = "UPDATE fact_por_vencer" + USDTag + " " + "SET saldo_por_vencer=@saldo_por_vencer " + "WHERE id_cliente=@id_cliente and id_grupo_vencimiento=@id_grupo_vencimiento;"; theCommand = new NpgsqlCommand(sqlUpdateVencimiento, pgConnection); } // if record does not exists, insert the record else { string sqlUpdateVencimiento = "INSERT INTO fact_por_vencer" + USDTag + "(" + "id_cliente, id_grupo_vencimiento, saldo_por_vencer) " + "VALUES (@id_cliente, @id_grupo_vencimiento, @saldo_por_vencer);"; theCommand = new NpgsqlCommand(sqlUpdateVencimiento, pgConnection); } theCommand.Parameters.Add("@saldo_por_vencer", NpgsqlTypes.NpgsqlDbType.Double); theCommand.Parameters.Add("@id_cliente", NpgsqlTypes.NpgsqlDbType.Integer); theCommand.Parameters.Add("@id_grupo_vencimiento", NpgsqlTypes.NpgsqlDbType.Integer); theCommand.Parameters["@saldo_por_vencer"].Value = oFactPorVencerToPersist.Importe; theCommand.Parameters["@id_cliente"].Value = oFactPorVencerToPersist.Cliente.IdCliente; theCommand.Parameters["@id_grupo_vencimiento"].Value = grupo.Id; theCommand.ExecuteNonQuery(); } transaction.Commit(); } catch (Exception ex) { if (transaction != null) { transaction.Rollback(); } throw ex; } } } catch (Exception ex) { throw ex; } pgConnection.Close(); } }