Inicial - Upload Economia estimada
This commit is contained in:
commit
a760aaab82
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
###############################################################################
|
||||||
|
# Set default behavior to automatically normalize line endings.
|
||||||
|
###############################################################################
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set default behavior for command prompt diff.
|
||||||
|
#
|
||||||
|
# This is need for earlier builds of msysgit that does not have it on by
|
||||||
|
# default for csharp files.
|
||||||
|
# Note: This is only used by command line
|
||||||
|
###############################################################################
|
||||||
|
#*.cs diff=csharp
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set the merge driver for project and solution files
|
||||||
|
#
|
||||||
|
# Merging from the command prompt will add diff markers to the files if there
|
||||||
|
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||||
|
# the diff markers are never inserted). Diff markers may cause the following
|
||||||
|
# file extensions to fail to load in VS. An alternative would be to treat
|
||||||
|
# these files as binary and thus will always conflict and require user
|
||||||
|
# intervention with every merge. To do so, just uncomment the entries below
|
||||||
|
###############################################################################
|
||||||
|
#*.sln merge=binary
|
||||||
|
#*.csproj merge=binary
|
||||||
|
#*.vbproj merge=binary
|
||||||
|
#*.vcxproj merge=binary
|
||||||
|
#*.vcproj merge=binary
|
||||||
|
#*.dbproj merge=binary
|
||||||
|
#*.fsproj merge=binary
|
||||||
|
#*.lsproj merge=binary
|
||||||
|
#*.wixproj merge=binary
|
||||||
|
#*.modelproj merge=binary
|
||||||
|
#*.sqlproj merge=binary
|
||||||
|
#*.wwaproj merge=binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# behavior for image files
|
||||||
|
#
|
||||||
|
# image files are treated as binary by default.
|
||||||
|
###############################################################################
|
||||||
|
#*.jpg binary
|
||||||
|
#*.png binary
|
||||||
|
#*.gif binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# diff behavior for common document formats
|
||||||
|
#
|
||||||
|
# Convert binary document formats to text before diffing them. This feature
|
||||||
|
# is only available from the command line. Turn it on by uncommenting the
|
||||||
|
# entries below.
|
||||||
|
###############################################################################
|
||||||
|
#*.doc diff=astextplain
|
||||||
|
#*.DOC diff=astextplain
|
||||||
|
#*.docx diff=astextplain
|
||||||
|
#*.DOCX diff=astextplain
|
||||||
|
#*.dot diff=astextplain
|
||||||
|
#*.DOT diff=astextplain
|
||||||
|
#*.pdf diff=astextplain
|
||||||
|
#*.PDF diff=astextplain
|
||||||
|
#*.rtf diff=astextplain
|
||||||
|
#*.RTF diff=astextplain
|
||||||
363
.gitignore
vendored
Normal file
363
.gitignore
vendored
Normal file
@ -0,0 +1,363 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Mono auto generated files
|
||||||
|
mono_crash.*
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Ww][Ii][Nn]32/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Oo]ut/
|
||||||
|
[Ll]og/
|
||||||
|
[Ll]ogs/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUnit
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
nunit-*.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# ASP.NET Scaffolding
|
||||||
|
ScaffoldingReadMe.txt
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Coverlet is a free, cross platform Code Coverage Tool
|
||||||
|
coverage*.json
|
||||||
|
coverage*.xml
|
||||||
|
coverage*.info
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# NuGet Symbol Packages
|
||||||
|
*.snupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
*.appxbundle
|
||||||
|
*.appxupload
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- [Bb]ackup.rdl
|
||||||
|
*- [Bb]ackup ([0-9]).rdl
|
||||||
|
*- [Bb]ackup ([0-9][0-9]).rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
|
|
||||||
|
# Backup folder for Package Reference Convert tool in Visual Studio 2017
|
||||||
|
MigrationBackup/
|
||||||
|
|
||||||
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
|
.ionide/
|
||||||
|
|
||||||
|
# Fody - auto-generated XML schema
|
||||||
|
FodyWeavers.xsd
|
||||||
885
Program.cs
Normal file
885
Program.cs
Normal file
@ -0,0 +1,885 @@
|
|||||||
|
// 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) {
|
||||||
|
//
|
||||||
|
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();
|
||||||
|
|
||||||
|
//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");
|
||||||
|
|
||||||
|
//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_pg;
|
||||||
|
|
||||||
|
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 = "SELECT * FROM Economia WHERE mes >= " + searchFromString;
|
||||||
|
OleDbCommand tbEC = new(strCOM_ac, conn_access);
|
||||||
|
OleDbDataReader reader_access = tbEC.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.Read()) {
|
||||||
|
//Console.WriteLine(reader_access["Data"]);
|
||||||
|
//Console.ReadKey();
|
||||||
|
mes = reader_access["Mes"].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(reader_access["Cod_econ"].ToString(), out cod_econ);
|
||||||
|
long.TryParse(reader_access["Cod_Smart_unidade"].ToString(), 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();
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
Properties/launchSettings.json
Normal file
8
Properties/launchSettings.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"Transfer_ac_pg": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"commandLineArgs": "2 0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
Transfer_ac_pg.csproj
Normal file
29
Transfer_ac_pg.csproj
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<COMReference Include="WinHttp">
|
||||||
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
|
<VersionMinor>1</VersionMinor>
|
||||||
|
<VersionMajor>5</VersionMajor>
|
||||||
|
<Guid>662901fc-6951-4854-9eb2-d9a2570f2b2e</Guid>
|
||||||
|
<Lcid>0</Lcid>
|
||||||
|
<Isolated>false</Isolated>
|
||||||
|
<EmbedInteropTypes>true</EmbedInteropTypes>
|
||||||
|
</COMReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||||
|
<PackageReference Include="Npgsql" Version="6.0.4" />
|
||||||
|
<PackageReference Include="System.Data.OleDb" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
25
Transfer_ac_pg.sln
Normal file
25
Transfer_ac_pg.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.1.32319.34
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Transfer_ac_pg", "Transfer_ac_pg.csproj", "{56A09F0E-9427-430A-B3BD-A82F0D776F6F}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{56A09F0E-9427-430A-B3BD-A82F0D776F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{56A09F0E-9427-430A-B3BD-A82F0D776F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{56A09F0E-9427-430A-B3BD-A82F0D776F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{56A09F0E-9427-430A-B3BD-A82F0D776F6F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {3278A61E-CF76-4A41-BDD1-FF058556EB86}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Loading…
x
Reference in New Issue
Block a user