903 lines
44 KiB
C#
903 lines
44 KiB
C#
// See https://aka.ms/new-console-template for more information
|
|
using Newtonsoft.Json;
|
|
using Npgsql;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Data.SqlClient;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Net.Sockets;
|
|
using System.Security.Authentication;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Xml;
|
|
|
|
internal class Plat_integ {
|
|
//tempo medio de execucao para processamente sincrono: 15 dias: 5,4s / 30 dias:10,0s / 60 dias:16,2s
|
|
|
|
static string PG_CONN_STRING_DEV = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartimptest; User Id = postgres; Password = VfHml#Z78!%kvvNM;";
|
|
static string PG_CONN_STRING_PROD = "Server = smart-energia-dev-pgsql.cykff7tj7mik.us-east-1.rds.amazonaws.com; Port = 5432; Database = smartenergiaprod; User Id = postgres; Password = VfHml#Z78!%kvvNM;";
|
|
static string ENVIRONMENT = "prod"; // "dev" | "prod"
|
|
|
|
static string ACCESS_DB_LOCATION = @"X:\Middle\Informativo Setorial\Modelo Word\BD1_dados cadastrais e faturas.accdb";
|
|
|
|
static string ACCESS_DB_LOCATION_APP = @"X:\Middle\Informativo Setorial\Modelo Word\BD_APP.accdb";
|
|
|
|
static void Main(string[] args) {
|
|
|
|
bool Consolidada = true; //True = econ consolidada; False = econ estimada
|
|
|
|
DateTime searchFromMonth = DateTime.Now.AddMonths(-24);
|
|
DateTime searchFrom = new DateTime(searchFromMonth.Year, searchFromMonth.Month, 1);
|
|
string searchFromString = searchFrom.ToString("yMM");
|
|
|
|
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
|
|
//transfere_PLD();
|
|
|
|
if (Consolidada)
|
|
{
|
|
Console.WriteLine("Iniciando importação dos dados cadastrais");
|
|
transfere_DC();
|
|
Console.WriteLine("Finalizando importação dos dados cadastrais");
|
|
|
|
Console.WriteLine("Iniciando importação dos dados TE");
|
|
transfere_TE(searchFromString);
|
|
Console.WriteLine("Finalizando importação dos dados TE");
|
|
|
|
Console.WriteLine("Iniciando importação dos dados de economia");
|
|
transfere_econ(searchFromString);
|
|
Console.WriteLine("Finalizando importação dos dados de economia");
|
|
}
|
|
else
|
|
{
|
|
//args -> limit & offset
|
|
string limit = "1000"; //args[0];
|
|
string offset = "0"; // args[1];
|
|
int limitInt = Int32.Parse(limit);
|
|
int offsetInt = Int32.Parse(offset);
|
|
Console.WriteLine("Iniciando importação dos dados estimados de economia");
|
|
transfere_econ_estimado(searchFromString, limitInt, offsetInt);
|
|
Console.WriteLine("Finalizando importação dos dados estimados de economia");
|
|
}
|
|
Environment.Exit(0);
|
|
return;
|
|
}
|
|
|
|
private static void transfere_econ(string searchFromString) {
|
|
string strCOM_ac, strCOM_ac_list;
|
|
|
|
long cod_econ, cod_smart_unidade;
|
|
string mes;
|
|
double custo_cativo, custo_livre, economia_mensal, economia_acumulada, custo_unit;
|
|
|
|
//abre conexao com o Accesss
|
|
OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ACCESS_DB_LOCATION + ";Jet OLEDB:Database Password=gds21");
|
|
conn_access.Open();
|
|
|
|
//dados >= 2021-01-01
|
|
strCOM_ac_list = "SELECT DISTINCT cod_smart_unidade FROM Economia WHERE mes >= " + searchFromString;
|
|
|
|
OleDbCommand tbList = new(strCOM_ac_list, conn_access);
|
|
OleDbDataReader reader_access_list = tbList.ExecuteReader();
|
|
|
|
//abre a conexao com o PG
|
|
NpgsqlConnection conn_pg;
|
|
if (ENVIRONMENT is "dev") {
|
|
conn_pg = new(PG_CONN_STRING_DEV);
|
|
} else {
|
|
conn_pg = new(PG_CONN_STRING_PROD);
|
|
}
|
|
conn_pg.Open();
|
|
|
|
Console.WriteLine("Excluindo dados existentes de economia");
|
|
string pg_strCOM = $"DELETE FROM economia WHERE mes::INTEGER >= {searchFromString}"; //TODO: ESTUDAR TROCA PARA TRUNCATE
|
|
NpgsqlCommand pg_tcSCDE = new(pg_strCOM, conn_pg);
|
|
NpgsqlDataReader pg_reader = pg_tcSCDE.ExecuteReader();
|
|
pg_reader.Close();
|
|
Console.WriteLine("Dados de economia excluídos");
|
|
|
|
using (var pg_writer = conn_pg.BeginBinaryImport("COPY economia (cod_econ, cod_smart_unidade, mes, custo_cativo, custo_livre, economia_mensal, economia_acumulada, custo_unit, dad_estimado) FROM STDIN (FORMAT BINARY)")) {
|
|
while (reader_access_list.Read())
|
|
{
|
|
string idUni = reader_access_list["cod_smart_unidade"].ToString()!;
|
|
strCOM_ac = $"SELECT calendario_aamm.data, IIf(a.custo_cativo IS NULL, 0.001, a.custo_cativo) AS custo_cativo, IIf(a.custo_livre IS NULL, 0.001, a.custo_livre) AS custo_livre, IIf(a.economia_mensal IS NULL, 0, a.economia_mensal) AS economia_mensal, IIf(a.economia_acumul IS NULL, 0, a.economia_acumul) AS economia_acumul, IIf(a.Custo_unit IS NULL, 0, a.Custo_unit) AS Custo_unit FROM calendario_aamm LEFT JOIN (SELECT * FROM economia WHERE cod_smart_unidade = {idUni} ORDER BY mes) AS a ON calendario_aamm.data = a.mes WHERE calendario_aamm.data >= {searchFromString} And calendario_aamm.data <= (SELECT MAX(mes) FROM economia WHERE cod_smart_unidade = {idUni})";
|
|
|
|
OleDbCommand tbEC = new(strCOM_ac, conn_access);
|
|
OleDbDataReader reader_access = tbEC.ExecuteReader();
|
|
while (reader_access.Read())
|
|
{
|
|
//Console.WriteLine(reader_access["Data"]);
|
|
//Console.ReadKey();
|
|
mes = reader_access["data"].ToString()!;
|
|
|
|
double.TryParse(reader_access["Custo_cativo"].ToString(), out custo_cativo);
|
|
double.TryParse(reader_access["Custo_livre"].ToString(), out custo_livre);
|
|
double.TryParse(reader_access["Economia_mensal"].ToString(), out economia_mensal);
|
|
double.TryParse(reader_access["Economia_acumul"].ToString(), out economia_acumulada);
|
|
double.TryParse(reader_access["Custo_unit"].ToString(), out custo_unit);
|
|
long.TryParse(String.Concat(idUni, mes), out cod_econ);
|
|
long.TryParse(idUni, out cod_smart_unidade);
|
|
|
|
//COMENTADO SO DEV -> Random rnd = new Random();
|
|
//COMENTADO SO DEV -> custo_unit = 500 + rnd.NextDouble()*200;
|
|
|
|
//strCOM_pg = "INSERT INTO economia (cod_econ, cod_smart_unidade, mes, custo_cativo, custo_livre, economia_mensal, economia_acumulada, custo_unit, dad_estimado)";
|
|
//strCOM_pg += $" VALUES ({cod_econ}, {cod_smart_unidade},'{mes}', {custo_cativo}, {custo_livre}, {economia_mensal}, {economia_acumulada}, {custo_unit}, {false});";
|
|
pg_writer.StartRow();
|
|
pg_writer.Write(cod_econ, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(cod_smart_unidade, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(mes);
|
|
pg_writer.Write(custo_cativo, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(custo_livre, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(economia_mensal, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(economia_acumulada, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(custo_unit, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(false, NpgsqlTypes.NpgsqlDbType.Boolean);
|
|
|
|
//try {
|
|
// NpgsqlCommand tcDC = new(strCOM_pg, conn_pg);
|
|
// using (NpgsqlDataReader reader = tcDC.ExecuteReader()) {
|
|
// };
|
|
//} catch (Exception ex) {
|
|
// Console.WriteLine(ex.Message);
|
|
// Console.WriteLine(strCOM_pg);
|
|
// //Console.ReadKey();
|
|
//}
|
|
}
|
|
reader_access.Close();
|
|
}
|
|
pg_writer.Complete();
|
|
}
|
|
|
|
conn_access.Close();
|
|
conn_pg.Close();
|
|
|
|
}
|
|
|
|
private static void transfere_TE(string searchFromString) {
|
|
string strCOM_ac, strCOM_pg;
|
|
|
|
long cod_TE, cod_smart_unidade;
|
|
string mes, operacao, tipo, perfil_contr;
|
|
double montante_nf, preco_nf, nf_c_icms;
|
|
|
|
//abre conexao com o Accesss
|
|
OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ACCESS_DB_LOCATION + ";Jet OLEDB:Database Password=gds21");
|
|
conn_access.Open();
|
|
|
|
//dados >= 2022-01-01
|
|
strCOM_ac = "SELECT * FROM Dados_TE WHERE mes >= " + searchFromString;
|
|
OleDbCommand tbTE = new(strCOM_ac, conn_access);
|
|
OleDbDataReader reader_access = tbTE.ExecuteReader();
|
|
|
|
//abre a conexao com o PG
|
|
NpgsqlConnection conn_pg;
|
|
if (ENVIRONMENT is "dev") {
|
|
conn_pg = new(PG_CONN_STRING_DEV);
|
|
} else {
|
|
conn_pg = new(PG_CONN_STRING_PROD);
|
|
}
|
|
conn_pg.Open();
|
|
|
|
Console.WriteLine("Excluindo dados existentes de TE");
|
|
string pg_strCOM = $"DELETE FROM dados_te WHERE mes::INTEGER >= {searchFromString}"; //TODO: ESTUDAR TROCA PARA TRUNCATE
|
|
NpgsqlCommand pg_tcSCDE = new(pg_strCOM, conn_pg);
|
|
NpgsqlDataReader pg_reader = pg_tcSCDE.ExecuteReader();
|
|
pg_reader.Close();
|
|
Console.WriteLine("Dados de TE excluídos");
|
|
|
|
using (var pg_writer = conn_pg.BeginBinaryImport("COPY dados_te (cod_te, cod_smart_unidade, mes, operacao, tipo, montante_nf, preco_nf, nf_c_icms, perfil_contr) FROM STDIN (FORMAT BINARY)")) {
|
|
while (reader_access.Read()) {
|
|
//Console.WriteLine(reader_access["Data"]);
|
|
//Console.ReadKey();
|
|
mes = reader_access["Mes"].ToString();
|
|
operacao = reader_access["Operacao"].ToString();
|
|
tipo = reader_access["Tipo"].ToString();
|
|
perfil_contr = reader_access["Perfil_Contr"].ToString();
|
|
|
|
double.TryParse(reader_access["Montante_NF"].ToString(), out montante_nf);
|
|
double.TryParse(reader_access["Preco_NF"].ToString(), out preco_nf);
|
|
double.TryParse(reader_access["NF_c_ICMS"].ToString(), out nf_c_icms);
|
|
long.TryParse(reader_access["Cod_TE"].ToString(), out cod_TE);
|
|
long.TryParse(reader_access["Cod_Smart_unidade"].ToString(), out cod_smart_unidade);
|
|
|
|
//strCOM_pg = "INSERT INTO dados_te (cod_te, cod_smart_unidade, mes, operacao, tipo, montante_nf, preco_nf, nf_c_icms, perfil_contr)";
|
|
//strCOM_pg += $" VALUES ({cod_TE}, {cod_smart_unidade},'{mes}', '{operacao}','{tipo}',{montante_nf},{preco_nf},{nf_c_icms},'{perfil_contr}');";
|
|
|
|
pg_writer.StartRow();
|
|
pg_writer.Write(cod_TE, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(cod_smart_unidade, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(mes);
|
|
pg_writer.Write(operacao);
|
|
pg_writer.Write(tipo);
|
|
pg_writer.Write(montante_nf, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(preco_nf, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(nf_c_icms, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(perfil_contr);
|
|
|
|
//try {
|
|
// NpgsqlCommand tcDC = new(strCOM_pg, conn_pg);
|
|
// using (NpgsqlDataReader reader = tcDC.ExecuteReader()) {
|
|
// };
|
|
//} catch (Exception ex) {
|
|
// Console.WriteLine(ex.Message);
|
|
// Console.WriteLine(strCOM_pg);
|
|
// //Console.ReadKey();
|
|
// //Console.WriteLine("Codigo unidade: {0}", cod_smart_unidade);
|
|
//}
|
|
}
|
|
pg_writer.Complete();
|
|
}
|
|
|
|
conn_access.Close();
|
|
conn_pg.Close();
|
|
|
|
}
|
|
|
|
private static void transfere_DC() {
|
|
string strCOM_ac, strCOM_pg;
|
|
long cod_smart_unidade, cod_smart_cliente;
|
|
string cliente, unidade, codigo_scde, status_empresa, status_unidade;
|
|
double demanda_p, demanda_fp, data_de_migracao;
|
|
bool isInsert;
|
|
NpgsqlCommand tcDC;
|
|
|
|
//abre conexao com o Accesss
|
|
OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ACCESS_DB_LOCATION + ";Jet OLEDB:Database Password=gds21");
|
|
conn_access.Open();
|
|
|
|
strCOM_ac = "SELECT * FROM Dados_cadastrais WHERE Unidade_gerenciada = True";
|
|
OleDbCommand tbDC = new(strCOM_ac, conn_access);
|
|
OleDbDataReader reader_access = tbDC.ExecuteReader();
|
|
|
|
//abre a conexao com o PG
|
|
NpgsqlConnection conn_pg;
|
|
if (ENVIRONMENT is "dev") {
|
|
conn_pg = new(PG_CONN_STRING_DEV);
|
|
} else {
|
|
conn_pg = new(PG_CONN_STRING_PROD);
|
|
}
|
|
conn_pg.Open();
|
|
|
|
//using (var pg_writer = conn_pg.BeginBinaryImport("COPY dados_cadastrais (cod_smart_unidade, cod_smart_cliente, cliente, unidade, codigo_scde, status_empresa, status_unidade,demanda_p, demanda_fp, data_de_migracao) FROM STDIN (FORMAT BINARY)")) {
|
|
while (reader_access.Read()) {
|
|
//Console.WriteLine(reader_access["Data"]);
|
|
//Console.ReadKey();
|
|
cliente = reader_access["Cliente"].ToString();
|
|
unidade = reader_access["Unidade"].ToString();
|
|
//DEV ONLY -> cliente = "Cliente " + reader_access["Cod_Smart_cliente"].ToString();
|
|
//DEV ONLY -> unidade = "Unidade " + reader_access["Cod_Smart_unidade"].ToString();
|
|
codigo_scde = reader_access["Codigo_SCDE"].ToString() + "P";
|
|
status_empresa = reader_access["Status_empresa"].ToString();
|
|
status_unidade = reader_access["Status_unidade"].ToString();
|
|
|
|
double.TryParse(reader_access["Demanda_P"].ToString(), out demanda_p);
|
|
double.TryParse(reader_access["Demanda_FP"].ToString(), out demanda_fp);
|
|
double.TryParse(reader_access["Data_de_migracao"].ToString(), out data_de_migracao);
|
|
|
|
long.TryParse(reader_access["Cod_Smart_unidade"].ToString(), out cod_smart_unidade);
|
|
long.TryParse(reader_access["Cod_Smart_cliente"].ToString(), out cod_smart_cliente);
|
|
|
|
//VERIFICAR SE É NECESSÁRIO CADASTRAR OU ATUALIZAR
|
|
string SQL_selectDCExists = $"SELECT * FROM dados_cadastrais WHERE cod_smart_unidade = {cod_smart_unidade}";
|
|
isInsert = true;
|
|
tcDC = new(SQL_selectDCExists, conn_pg);
|
|
using (NpgsqlDataReader reader = tcDC.ExecuteReader()) {
|
|
while (reader.Read()) {
|
|
isInsert = false;
|
|
}
|
|
};
|
|
if (isInsert) {
|
|
strCOM_pg = "INSERT INTO dados_cadastrais (cod_smart_unidade, cod_smart_cliente, cliente, unidade, codigo_scde, status_empresa, status_unidade,demanda_p, demanda_fp, data_de_migracao)";
|
|
strCOM_pg += $" VALUES ({cod_smart_unidade}, {cod_smart_cliente} ,'{cliente}', '{unidade}','{codigo_scde}', '{status_empresa}', '{status_unidade}', {demanda_p}, {demanda_fp}, {data_de_migracao});";
|
|
Console.WriteLine("Unidade {0} inserida", cod_smart_unidade);
|
|
} else {
|
|
strCOM_pg = $"UPDATE dados_cadastrais SET cod_smart_cliente = {cod_smart_cliente}, cliente = '{cliente}', unidade = '{unidade}', codigo_scde = '{codigo_scde}', status_empresa = '{status_empresa}', status_unidade = '{status_unidade}', demanda_p = {demanda_p}, demanda_fp = {demanda_fp}, data_de_migracao = {data_de_migracao} WHERE cod_smart_unidade = {cod_smart_unidade}";
|
|
Console.WriteLine("Unidade {0} atualizada", cod_smart_unidade);
|
|
}
|
|
//pg_writer.StartRow();
|
|
//pg_writer.Write(cod_smart_unidade, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
//pg_writer.Write(cod_smart_cliente, NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
//pg_writer.Write(cliente);
|
|
//pg_writer.Write(unidade);
|
|
//pg_writer.Write(codigo_scde);
|
|
//pg_writer.Write(status_empresa);
|
|
//pg_writer.Write(status_unidade);
|
|
//pg_writer.Write(demanda_p, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
//pg_writer.Write(demanda_fp, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
//pg_writer.Write(data_de_migracao, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
|
|
try {
|
|
tcDC = new(strCOM_pg, conn_pg);
|
|
using (NpgsqlDataReader reader = tcDC.ExecuteReader()) {
|
|
};
|
|
} catch (Exception ex) {
|
|
Console.WriteLine(ex.Message);
|
|
Console.WriteLine(strCOM_pg);
|
|
//Console.ReadKey();
|
|
}
|
|
}
|
|
//pg_writer.Complete();
|
|
//}
|
|
conn_access.Close();
|
|
conn_pg.Close();
|
|
|
|
}
|
|
|
|
//private static void transfere_PLD() {
|
|
// string strCOM_ac, caminho_BD, strCOM_pg;
|
|
// double valor_pld, dia_num, hora, dia_da_semana;
|
|
// string submercado, mes_ref;
|
|
|
|
|
|
// caminho_BD = @"X:\Middle\Informativo Setorial\Modelo Word\BD_SCDE.accdb";
|
|
|
|
|
|
// //abre conexao com o Accesss
|
|
// OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
|
|
// conn_access.Open();
|
|
|
|
// //dados >= 2022-01-01
|
|
// strCOM_ac = "SELECT * FROM PLD_comp WHERE data >= 44562";
|
|
// OleDbCommand tbPLD = new(strCOM_ac, conn_access);
|
|
// OleDbDataReader reader_access = tbPLD.ExecuteReader();
|
|
|
|
// //abre a conexao com o PG
|
|
// NpgsqlConnection conn_pg = new("Server = 127.0.0.1; Port = 5432; Database = development_db; User Id = postgres; Password = bdnp;");
|
|
// conn_pg.Open();
|
|
|
|
// while (reader_access.Read()) {
|
|
// submercado= reader_access["Submercado"].ToString();
|
|
// mes_ref = reader_access["Mes_ref"].ToString();
|
|
// //Console.WriteLine(reader_access["Data"]);
|
|
// //Console.ReadKey();
|
|
// double.TryParse(reader_access["Data"].ToString(), out dia_num);
|
|
// double.TryParse(reader_access["Hora"].ToString(), out hora);
|
|
// double.TryParse(reader_access["Dia_da_semana"].ToString(), out dia_da_semana);
|
|
// double.TryParse(reader_access["Valor"].ToString(), out valor_pld);
|
|
|
|
// strCOM_pg = "INSERT INTO pld (dia_num, hora, submercado, valor, mes_ref, dia_da_semana)";
|
|
// strCOM_pg += $" VALUES ({dia_num}, {hora} ,'{submercado}', {valor_pld},'{mes_ref}', {dia_da_semana});";
|
|
|
|
// NpgsqlCommand tcMed = new(strCOM_pg, conn_pg);
|
|
// using (NpgsqlDataReader reader = tcMed.ExecuteReader()) {
|
|
// };
|
|
// }
|
|
|
|
// conn_access.Close();
|
|
// conn_pg.Close();
|
|
|
|
//}
|
|
|
|
//private static void transfere_Med5min() {
|
|
// string strCOM_ac, caminho_BD, strCOM_pg;
|
|
// double valor_pld, dia_num, hora, dia_da_semana;
|
|
// string submercado, mes_ref;
|
|
|
|
// caminho_BD = @"X:\Middle\Informativo Setorial\Modelo Word\BD_SCDE.accdb"; //TODO CHANGE
|
|
|
|
// //abre conexao com o Accesss
|
|
// OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + caminho_BD + ";Jet OLEDB:Database Password=gds21");
|
|
// conn_access.Open();
|
|
|
|
// //dados >= 2022-01-01
|
|
// strCOM_ac = "SELECT * FROM PLD_comp WHERE data >= 44562";
|
|
// OleDbCommand tbPLD = new(strCOM_ac, conn_access);
|
|
// OleDbDataReader reader_access = tbPLD.ExecuteReader();
|
|
|
|
// //abre a conexao com o PG
|
|
// NpgsqlConnection conn_pg;
|
|
// if (ENVIRONMENT is "dev") {
|
|
// conn_pg = new(PG_CONN_STRING_DEV);
|
|
// } else {
|
|
// conn_pg = new(PG_CONN_STRING_PROD);
|
|
// }
|
|
// conn_pg.Open();
|
|
|
|
// using (var pg_writer = conn_pg.BeginBinaryImport("COPY dados_te (cod_te, cod_smart_unidade, mes, operacao, tipo, montante_nf, preco_nf, nf_c_icms, perfil_contr) FROM STDIN (FORMAT BINARY)")) {
|
|
// while (reader_access.Read()) {
|
|
// submercado = reader_access["Submercado"].ToString();
|
|
// mes_ref = reader_access["Mes_ref"].ToString();
|
|
// //Console.WriteLine(reader_access["Data"]);
|
|
// //Console.ReadKey();
|
|
// double.TryParse(reader_access["Data"].ToString(), out dia_num);
|
|
// double.TryParse(reader_access["Hora"].ToString(), out hora);
|
|
// double.TryParse(reader_access["Dia_da_semana"].ToString(), out dia_da_semana);
|
|
// double.TryParse(reader_access["Valor"].ToString(), out valor_pld);
|
|
|
|
// //strCOM_pg = "INSERT INTO pld (dia_num, hora, submercado, valor, mes_ref, dia_da_semana)";
|
|
// //strCOM_pg += $" VALUES ({dia_num}, {hora} ,'{submercado}', {valor_pld},'{mes_ref}', {dia_da_semana});";
|
|
|
|
// pg_writer.StartRow();
|
|
// pg_writer.Write(dia_num);
|
|
// pg_writer.Write(hora, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
// pg_writer.Write(submercado, NpgsqlTypes.NpgsqlDbType.Integer);
|
|
// pg_writer.Write(valor_pld, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
// pg_writer.Write(mes_ref, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
// pg_writer.Write(dia_da_semana, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
// //NpgsqlCommand tcMed = new(strCOM_pg, conn_pg);
|
|
// //using (NpgsqlDataReader reader = tcMed.ExecuteReader()) {
|
|
// //};
|
|
// }
|
|
// pg_writer.Complete();
|
|
// }
|
|
|
|
// conn_access.Close();
|
|
// conn_pg.Close();
|
|
|
|
//}
|
|
|
|
/*
|
|
- mes -> DateTime.Now.toString("y") + (
|
|
- Jan -> 01
|
|
- Fev -> 02
|
|
- Mar -> 03
|
|
- Abr -> 04
|
|
- Mai -> 05
|
|
- Jun -> 06
|
|
- Jul -> 07
|
|
- Ago -> 08
|
|
- Set -> 09
|
|
- Out -> 10
|
|
- Nov -> 11
|
|
- Dez -> 12
|
|
)
|
|
|
|
COLUNAS DE INTERESSE
|
|
ECONOMIA ACUMULADA
|
|
- EA_Jan
|
|
- EA_Fev
|
|
- EA_Mar
|
|
- EA_Abr
|
|
- EA_Mai
|
|
- EA_Jun
|
|
- EA_Jul
|
|
- EA_Ago
|
|
- EA_Set
|
|
- EA_Out
|
|
- EA_Nov
|
|
- EA_Dez
|
|
|
|
ECONOMIA MENSAL
|
|
- EM_Jan
|
|
- EM_Fev
|
|
- EM_Mar
|
|
- EM_Abr
|
|
- EM_Mai
|
|
- EM_Jun
|
|
- EM_Jul
|
|
- EM_Ago
|
|
- EM_Set
|
|
- EM_Out
|
|
- EM_Nov
|
|
- EM_Dez
|
|
|
|
CUSTO CATIVO ESTIMADO
|
|
- CCE_Jan
|
|
- CCE_Fev
|
|
- CCE_Mar
|
|
- CCE_Abr
|
|
- CCE_Mai
|
|
- CCE_Jun
|
|
- CCE_Jul
|
|
- CCE_Ago
|
|
- CCE_Set
|
|
- CCE_Out
|
|
- CCE_Nov
|
|
- CCE_Dez
|
|
|
|
CUSTO LIVRE ESTIMADO
|
|
- CLE_Jan
|
|
- CLE_Fev
|
|
- CLE_Mar
|
|
- CLE_Abr
|
|
- CLE_Mai
|
|
- CLE_Jun
|
|
- CLE_Jul
|
|
- CLE_Ago
|
|
- CLE_Set
|
|
- CLE_Out
|
|
- CLE_Nov
|
|
- CLE_Dez
|
|
|
|
Custo estimado?
|
|
*/
|
|
|
|
/*
|
|
CONDIÇÕES SELEÇÃO
|
|
- Ult_ver <> 0
|
|
|
|
Passos
|
|
|
|
Para cada unidade (Postgres)
|
|
-> Puxar maior dado consolidado de economia disponível
|
|
-> -> A partir de dado consolidado, carregar dados de economia estimados (BD_APP ACCESS DB)
|
|
-> -> Gravar registros (Postgres)
|
|
-> -> -> custo_unit = 0
|
|
-> -> -> dad_estimado = true
|
|
*/
|
|
//IMPORTANTE, DEVE RODAR APOS IMPORTACAO DE ECONOMIA CONSOLIDADA
|
|
private static void transfere_econ_estimado(string searchFromString, int limitInt, int offsetInt) {
|
|
//abre conexao com o Accesss
|
|
OleDbConnection conn_access = new("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ACCESS_DB_LOCATION_APP + ";Jet OLEDB:Database Password=gds21");
|
|
conn_access.Open();
|
|
|
|
List<string> acc_em_data_types = new List<string>();
|
|
acc_em_data_types.Add("EM_Jan");
|
|
acc_em_data_types.Add("EM_Fev");
|
|
acc_em_data_types.Add("EM_Mar");
|
|
acc_em_data_types.Add("EM_Abr");
|
|
acc_em_data_types.Add("EM_Mai");
|
|
acc_em_data_types.Add("EM_Jun");
|
|
acc_em_data_types.Add("EM_Jul");
|
|
acc_em_data_types.Add("EM_Ago");
|
|
acc_em_data_types.Add("EM_Set");
|
|
acc_em_data_types.Add("EM_Out");
|
|
acc_em_data_types.Add("EM_Nov");
|
|
acc_em_data_types.Add("EM_Dez");
|
|
|
|
List<string> acc_ea_data_types = new List<string>();
|
|
acc_ea_data_types.Add("EE_Jan");
|
|
acc_ea_data_types.Add("EE_Fev");
|
|
acc_ea_data_types.Add("EE_Mar");
|
|
acc_ea_data_types.Add("EE_Abr");
|
|
acc_ea_data_types.Add("EE_Mai");
|
|
acc_ea_data_types.Add("EE_Jun");
|
|
acc_ea_data_types.Add("EE_Jul");
|
|
acc_ea_data_types.Add("EE_Ago");
|
|
acc_ea_data_types.Add("EE_Set");
|
|
acc_ea_data_types.Add("EE_Out");
|
|
acc_ea_data_types.Add("EE_Nov");
|
|
acc_ea_data_types.Add("EE_Dez");
|
|
|
|
List<string> acc_cce_data_types = new List<string>();
|
|
acc_cce_data_types.Add("CCE_Jan");
|
|
acc_cce_data_types.Add("CCE_Fev");
|
|
acc_cce_data_types.Add("CCE_Mar");
|
|
acc_cce_data_types.Add("CCE_Abr");
|
|
acc_cce_data_types.Add("CCE_Mai");
|
|
acc_cce_data_types.Add("CCE_Jun");
|
|
acc_cce_data_types.Add("CCE_Jul");
|
|
acc_cce_data_types.Add("CCE_Ago");
|
|
acc_cce_data_types.Add("CCE_Set");
|
|
acc_cce_data_types.Add("CCE_Out");
|
|
acc_cce_data_types.Add("CCE_Nov");
|
|
acc_cce_data_types.Add("CCE_Dez");
|
|
|
|
List<string> acc_cle_data_types = new List<string>();
|
|
acc_cle_data_types.Add("CLE_Jan");
|
|
acc_cle_data_types.Add("CLE_Fev");
|
|
acc_cle_data_types.Add("CLE_Mar");
|
|
acc_cle_data_types.Add("CLE_Abr");
|
|
acc_cle_data_types.Add("CLE_Mai");
|
|
acc_cle_data_types.Add("CLE_Jun");
|
|
acc_cle_data_types.Add("CLE_Jul");
|
|
acc_cle_data_types.Add("CLE_Ago");
|
|
acc_cle_data_types.Add("CLE_Set");
|
|
acc_cle_data_types.Add("CLE_Out");
|
|
acc_cle_data_types.Add("CLE_Nov");
|
|
acc_cle_data_types.Add("CLE_Dez");
|
|
|
|
//abre a conexao com o PG
|
|
NpgsqlConnection conn_pg, conn_writer, conn_check_last;
|
|
if (ENVIRONMENT is "dev") {
|
|
conn_pg = new(PG_CONN_STRING_DEV);
|
|
conn_writer = new(PG_CONN_STRING_DEV);
|
|
conn_check_last = new(PG_CONN_STRING_DEV);
|
|
} else {
|
|
conn_pg = new(PG_CONN_STRING_PROD);
|
|
conn_writer = new(PG_CONN_STRING_PROD);
|
|
conn_check_last = new(PG_CONN_STRING_PROD);
|
|
}
|
|
conn_pg.Open();
|
|
conn_writer.Open();
|
|
conn_check_last.Open();
|
|
|
|
//só executa na leitura inicial
|
|
if (offsetInt == 0) {
|
|
Console.WriteLine("Excluindo dados existentes de economia estimada");
|
|
string pg_strCOM_delete = $"DELETE FROM economia WHERE dad_estimado = true AND mes::INTEGER >= {searchFromString}"; //TODO: ESTUDAR TROCA PARA TRUNCATE
|
|
NpgsqlCommand pg_tcSCDE_delete = new(pg_strCOM_delete, conn_pg);
|
|
NpgsqlDataReader pg_reader_delete = pg_tcSCDE_delete.ExecuteReader();
|
|
pg_reader_delete.Close();
|
|
Console.WriteLine("Dados de economia estimada excluídos");
|
|
}
|
|
|
|
string pgsql_select_for_each_client_unity = "SELECT cod_smart_cliente, cod_smart_unidade, unidade FROM dados_cadastrais;";
|
|
NpgsqlCommand pg_tcSCDE = new(pgsql_select_for_each_client_unity, conn_pg);
|
|
NpgsqlDataReader pg_reader_unities = pg_tcSCDE.ExecuteReader();
|
|
//Para cada unidade
|
|
|
|
string unidade, cod_smart_unidade, cod_smart_cliente;
|
|
|
|
int from, to, i;
|
|
i = 0;
|
|
from = offsetInt;
|
|
to = offsetInt + limitInt - 1;
|
|
// limit 100, offset 0 -> registros de 0 a 99
|
|
// limit 100, offset 100 -> registros de 100 a 199
|
|
// limit 100, offset 200 -> registros de 200 a 299
|
|
// limit 100, offset 300 -> registros de 300 a 399
|
|
// limit 100, offset 400 -> registros de 400 a 499
|
|
// limit 100, offset 500 -> registros de 500 a 599
|
|
try
|
|
{
|
|
using (var pg_writer = conn_writer.BeginBinaryImport("COPY economia (cod_econ, cod_smart_unidade, mes, custo_cativo, custo_livre, economia_mensal, economia_acumulada, custo_unit, dad_estimado) FROM STDIN (FORMAT BINARY)"))
|
|
{
|
|
while (pg_reader_unities.Read())
|
|
{
|
|
i++;
|
|
if (i < (from + 1) || i > (to + 1))
|
|
{
|
|
continue;
|
|
}
|
|
unidade = pg_reader_unities["unidade"].ToString();
|
|
cod_smart_unidade = pg_reader_unities["cod_smart_unidade"].ToString();
|
|
cod_smart_cliente = pg_reader_unities["cod_smart_cliente"].ToString();
|
|
|
|
//Carrega último mês que os dados consolidados estão disponíveis atualmente
|
|
string pgsql_select_max_year_month_unity_real_data = $"SELECT TO_CHAR(max(TO_DATE(mes, 'YYMM')), 'MM')::INTEGER AS max_month FROM economia WHERE cod_smart_unidade = {cod_smart_unidade} AND dad_estimado = false;";
|
|
NpgsqlCommand pg_command_pgsql_select_max_year_month_unity_real_data = new(pgsql_select_max_year_month_unity_real_data, conn_check_last);
|
|
NpgsqlDataReader pg_reader_month_unity = pg_command_pgsql_select_max_year_month_unity_real_data.ExecuteReader();
|
|
int last_month = 1;
|
|
string last_month_string = "";
|
|
while (pg_reader_month_unity.Read())
|
|
{
|
|
if (pg_reader_month_unity["max_month"] != null)
|
|
{
|
|
last_month_string = pg_reader_month_unity["max_month"].ToString();
|
|
if (last_month_string == "")
|
|
{
|
|
last_month = -1;
|
|
}
|
|
else
|
|
{
|
|
last_month = Int32.Parse(last_month_string);
|
|
}
|
|
}
|
|
}
|
|
pg_reader_month_unity.Close();
|
|
|
|
if (last_month == -1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (last_month == null)
|
|
{
|
|
last_month = 1;
|
|
}
|
|
if (last_month < 12)
|
|
{
|
|
//BASE SELECT
|
|
Console.WriteLine("Lendo dados do cliente {0} unidade {1} - Operação {2}", cod_smart_cliente, cod_smart_unidade, i);
|
|
string accessdb_select_max_year_month_unity_real_data_base = $"SELECT Valor FROM Dados_APP WHERE Ult_ver <> 0 AND Cod_Smart_cliente = {cod_smart_cliente} AND Unidade = '{unidade}' AND Tipo_dado = 'REPLACEDATATYPE'";
|
|
//PARA CADA MÊS ATÉ O FINAL DO ANO
|
|
for (int month = last_month; month < 12; month++)
|
|
{
|
|
Console.WriteLine("Buscando dados de economia a partir do mês {0}", month + 1);
|
|
//CARREGA ECONOMIA ACUMULADA
|
|
//Console.WriteLine("Iniciando EA do mês {0}", month + 1);
|
|
string accessdb_select_ea = accessdb_select_max_year_month_unity_real_data_base.Replace("REPLACEDATATYPE", acc_ea_data_types[month]);
|
|
OleDbCommand access_select_ea = new(accessdb_select_ea, conn_access);
|
|
OleDbDataReader reader_access_ea = access_select_ea.ExecuteReader();
|
|
string value_ea = "0";
|
|
while (reader_access_ea.Read())
|
|
{
|
|
if (reader_access_ea["Valor"] != null)
|
|
{
|
|
value_ea = reader_access_ea["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_ea.Close();
|
|
//Console.WriteLine("Finalizando EA do mês {0}", month + 1);
|
|
//CARREGA ECONOMIA MENSAL
|
|
//Console.WriteLine("Iniciando EM do mês {0}", month + 1);
|
|
string accessdb_select_em = accessdb_select_max_year_month_unity_real_data_base.Replace("REPLACEDATATYPE", acc_em_data_types[month]);
|
|
OleDbCommand access_select_em = new(accessdb_select_em, conn_access);
|
|
OleDbDataReader reader_access_em = access_select_em.ExecuteReader();
|
|
string value_em = "0";
|
|
while (reader_access_em.Read())
|
|
{
|
|
if (reader_access_em["Valor"] != null)
|
|
{
|
|
value_em = reader_access_em["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_em.Close();
|
|
//Console.WriteLine("Finalizando EM do mês {0}", month + 1);
|
|
//CARREGA CUSTO LIVRE ESTIMADO
|
|
//Console.WriteLine("Iniciando CLE do mês {0}", month + 1);
|
|
string accessdb_select_cle = accessdb_select_max_year_month_unity_real_data_base.Replace("REPLACEDATATYPE", acc_cle_data_types[month]);
|
|
OleDbCommand access_select_cle = new(accessdb_select_cle, conn_access);
|
|
OleDbDataReader reader_access_cle = access_select_cle.ExecuteReader();
|
|
string value_cle = "0";
|
|
while (reader_access_cle.Read())
|
|
{
|
|
if (reader_access_cle["Valor"] != null)
|
|
{
|
|
value_cle = reader_access_cle["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_cle.Close();
|
|
//Console.WriteLine("Finalizando CLE do mês {0}", month + 1);
|
|
//CARREGA CUSTO CATIVO ESTIMADO
|
|
//Console.WriteLine("Iniciando CCE do mês {0}", month + 1);
|
|
string accessdb_select_cce = accessdb_select_max_year_month_unity_real_data_base.Replace("REPLACEDATATYPE", acc_cce_data_types[month]);
|
|
OleDbCommand access_select_cce = new(accessdb_select_cce, conn_access);
|
|
OleDbDataReader reader_access_cce = access_select_cce.ExecuteReader();
|
|
string value_cce = "0";
|
|
while (reader_access_cce.Read())
|
|
{
|
|
if (reader_access_cce["Valor"] != null)
|
|
{
|
|
value_cce = reader_access_cce["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_cce.Close();
|
|
//Console.WriteLine("Finalizando CCE do mês {0}", month + 1);
|
|
|
|
DateTime currentMonthInserted = new DateTime(DateTime.Now.Year, month + 1, 1);
|
|
string currentMonthString = currentMonthInserted.ToString("yMM");
|
|
|
|
double cce = value_cce == "" ? 0 : Double.Parse(value_cce.Replace(",", "."));
|
|
double cle = value_cle == "" ? 0 : Double.Parse(value_cle.Replace(",", "."));
|
|
double em = value_em == "" ? 0 : Double.Parse(value_em.Replace(",", "."));
|
|
double ea = value_ea == "" ? 0 : Double.Parse(value_ea.Replace(",", "."));
|
|
|
|
//INSERE DADOS DE ECONOMIA ESTIMADA
|
|
pg_writer.StartRow();
|
|
pg_writer.Write(Int64.Parse(cod_smart_unidade + currentMonthString), NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(Int64.Parse(cod_smart_unidade), NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(currentMonthString);
|
|
pg_writer.Write(cce, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(cle, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(em, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(ea, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(0, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(true, NpgsqlTypes.NpgsqlDbType.Boolean);
|
|
//Console.WriteLine("Dados do mês {0} adicionados para o Writer", month + 1);
|
|
}
|
|
}
|
|
//ECONOMIA PROXIMOS 5 ANOS
|
|
//Carrega último ano que os dados consolidados estão disponíveis atualmente
|
|
string pgsql_select_max_year_unity_real_data = $"SELECT TO_CHAR(max(TO_DATE(mes, 'YYMM')), 'yy')::INTEGER AS max_year FROM economia WHERE cod_smart_unidade = {cod_smart_unidade} AND dad_estimado = false;";
|
|
NpgsqlCommand pg_command_pgsql_select_max_year_unity_real_data = new(pgsql_select_max_year_unity_real_data, conn_check_last);
|
|
NpgsqlDataReader pg_reader_year_unity = pg_command_pgsql_select_max_year_unity_real_data.ExecuteReader();
|
|
int last_year = 1;
|
|
string last_year_string = "";
|
|
while (pg_reader_year_unity.Read())
|
|
{
|
|
if (pg_reader_year_unity["max_year"] != null)
|
|
{
|
|
last_year_string = pg_reader_year_unity["max_year"].ToString();
|
|
if (last_year_string == "")
|
|
{
|
|
last_year = -1;
|
|
}
|
|
else
|
|
{
|
|
last_year = Int32.Parse(last_year_string);
|
|
}
|
|
}
|
|
}
|
|
pg_reader_year_unity.Close();
|
|
Console.WriteLine("Lendo dados do cliente {0} unidade {1} - Operação {2}", cod_smart_cliente, cod_smart_unidade, i);
|
|
string accessdb_select_max_year_unity_real_data_base = $"SELECT Valor FROM Dados_APP WHERE Ult_ver <> 0 AND Cod_Smart_cliente = {cod_smart_cliente} AND Unidade = '{unidade}' AND Tipo_dado = 'REPLACEDATATYPE'";
|
|
for (int year = 1; year < 6; year++)
|
|
{
|
|
Console.WriteLine("Buscando dados de economia a partir do ano {0}", year);
|
|
//CARREGA ECONOMIA ACUMULADA
|
|
//Console.WriteLine("Iniciando EA do mês {0}", month + 1);
|
|
string accessdb_select_ea = accessdb_select_max_year_unity_real_data_base.Replace("REPLACEDATATYPE", "EE_Ano" + year);
|
|
OleDbCommand access_select_ea = new(accessdb_select_ea, conn_access);
|
|
OleDbDataReader reader_access_ea = access_select_ea.ExecuteReader();
|
|
string value_ea = "0";
|
|
while (reader_access_ea.Read())
|
|
{
|
|
if (reader_access_ea["Valor"] != null)
|
|
{
|
|
value_ea = reader_access_ea["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_ea.Close();
|
|
//Console.WriteLine("Finalizando EA do mês {0}", month + 1);
|
|
//CARREGA ECONOMIA MENSAL
|
|
//Console.WriteLine("Iniciando EM do mês {0}", month + 1);
|
|
string accessdb_select_em = accessdb_select_max_year_unity_real_data_base.Replace("REPLACEDATATYPE", "EM_Ano" + year);
|
|
OleDbCommand access_select_em = new(accessdb_select_em, conn_access);
|
|
OleDbDataReader reader_access_em = access_select_em.ExecuteReader();
|
|
string value_em = "0";
|
|
while (reader_access_em.Read())
|
|
{
|
|
if (reader_access_em["Valor"] != null)
|
|
{
|
|
value_em = reader_access_em["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_em.Close();
|
|
//Console.WriteLine("Finalizando EM do mês {0}", month + 1);
|
|
//CARREGA CUSTO LIVRE ESTIMADO
|
|
//Console.WriteLine("Iniciando CLE do mês {0}", month + 1);
|
|
string accessdb_select_cle = accessdb_select_max_year_unity_real_data_base.Replace("REPLACEDATATYPE", "CLE_Ano" + year);
|
|
OleDbCommand access_select_cle = new(accessdb_select_cle, conn_access);
|
|
OleDbDataReader reader_access_cle = access_select_cle.ExecuteReader();
|
|
string value_cle = "0";
|
|
while (reader_access_cle.Read())
|
|
{
|
|
if (reader_access_cle["Valor"] != null)
|
|
{
|
|
value_cle = reader_access_cle["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_cle.Close();
|
|
//Console.WriteLine("Finalizando CLE do mês {0}", month + 1);
|
|
//CARREGA CUSTO CATIVO ESTIMADO
|
|
//Console.WriteLine("Iniciando CCE do mês {0}", month + 1);
|
|
string replaceCCE = "CCE_Ano" + year;
|
|
if (year == 1)
|
|
{
|
|
//replaceCCE = "CCE_2301";
|
|
replaceCCE = "CCE_Ano" + year;
|
|
}
|
|
string accessdb_select_cce = accessdb_select_max_year_unity_real_data_base.Replace("REPLACEDATATYPE", replaceCCE);
|
|
OleDbCommand access_select_cce = new(accessdb_select_cce, conn_access);
|
|
OleDbDataReader reader_access_cce = access_select_cce.ExecuteReader();
|
|
string value_cce = "0";
|
|
while (reader_access_cce.Read())
|
|
{
|
|
if (reader_access_cce["Valor"] != null)
|
|
{
|
|
value_cce = reader_access_cce["Valor"].ToString();
|
|
}
|
|
}
|
|
reader_access_cce.Close();
|
|
//Console.WriteLine("Finalizando CCE do mês {0}", month + 1);
|
|
|
|
DateTime currentMonthInserted = new DateTime((DateTime.Now.Year + year), 12, 1);
|
|
string currentMonthString = currentMonthInserted.ToString("yMM");
|
|
|
|
double cce = value_cce == "" ? 0 : Double.Parse(value_cce.Replace(",", "."));
|
|
double cle = value_cle == "" ? 0 : Double.Parse(value_cle.Replace(",", "."));
|
|
double em = value_em == "" ? 0 : Double.Parse(value_em.Replace(",", "."));
|
|
double ea = value_ea == "" ? 0 : Double.Parse(value_ea.Replace(",", "."));
|
|
|
|
//INSERE DADOS DE ECONOMIA ESTIMADA
|
|
pg_writer.StartRow();
|
|
pg_writer.Write(Int64.Parse(cod_smart_unidade + currentMonthString), NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(Int64.Parse(cod_smart_unidade), NpgsqlTypes.NpgsqlDbType.Bigint);
|
|
pg_writer.Write(currentMonthString);
|
|
pg_writer.Write(cce, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(cle, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(em, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(ea, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(0, NpgsqlTypes.NpgsqlDbType.Numeric);
|
|
pg_writer.Write(true, NpgsqlTypes.NpgsqlDbType.Boolean);
|
|
//Console.WriteLine("Dados do mês {0} adicionados para o Writer", month + 1);
|
|
}
|
|
|
|
}
|
|
var a = pg_writer.Complete();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine(e.Message);
|
|
}
|
|
pg_reader_unities.Close();
|
|
|
|
conn_access.Close();
|
|
conn_pg.Close();
|
|
conn_writer.Close();
|
|
|
|
}
|
|
|
|
} |