Atualizando para utilizar parametros nos comandos SQL
This commit is contained in:
parent
dab453279b
commit
43ed54c5fe
@ -9,6 +9,7 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using iText.Kernel.Pdf;
|
||||
using iText.Kernel.Utils;
|
||||
using Org.BouncyCastle.Asn1.Cmp;
|
||||
|
||||
public class Fatura
|
||||
{
|
||||
@ -55,7 +56,7 @@
|
||||
|
||||
public JsonElement.ArrayEnumerator Agrupada_children { get; private set; }
|
||||
|
||||
public void Processar(OleDbCommand cmd)
|
||||
public void Processar(OleDbConnection conn)
|
||||
{
|
||||
// Variavel para armazenar os dados a serem lancados para a TUSD no BD
|
||||
RecordSet dadosTusd = new ();
|
||||
@ -68,50 +69,64 @@
|
||||
string uc = new Regex("^0+").Replace(parsedResult.locationNumber, string.Empty).Replace("/", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty);
|
||||
|
||||
// Vinculo da fatura com os dados cadastrais
|
||||
string selectSQL = $"SELECT COUNT (Cod_Smart_unidade) FROM Dados_cadastrais WHERE Codigo_Instalacao = '{uc}'";
|
||||
|
||||
cmd.CommandText = selectSQL;
|
||||
|
||||
int? unidades = (int?)cmd.ExecuteScalar();
|
||||
|
||||
if (unidades == 1)
|
||||
string selectSQL = $"SELECT COUNT (Cod_Smart_unidade) FROM Dados_cadastrais WHERE Codigo_Instalacao = '@uc'";
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE Codigo_Instalacao = '{uc}'";
|
||||
}
|
||||
else
|
||||
{
|
||||
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE (CNPJ_CPF LIKE '{parsedResult.customer.cnpj?.Substring(0, 8) ?? "NAN"}%' AND Codigo_Instalacao = '{uc}') OR (Razao_Social LIKE '{parsedResult.customer.name.Replace("'", "''")}' AND Codigo_Instalacao = '{uc}')";
|
||||
cmd.Parameters.AddWithValue("@uc", uc);
|
||||
|
||||
int? unidades = (int?)cmd.ExecuteScalar();
|
||||
|
||||
if (unidades == 1)
|
||||
{
|
||||
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE Codigo_Instalacao = '{uc}'";
|
||||
}
|
||||
else
|
||||
{
|
||||
selectSQL = $"SELECT Cod_Smart_unidade, Cliente, Unidade, PerfilCCEE, Submercado, Status_unidade, Grupo, Distribuidora, ICMS_TUSD, Demanda_P, Demanda_FP, Caminho_NFs FROM Dados_cadastrais WHERE (CNPJ_CPF LIKE '@CNPJ%' AND Codigo_Instalacao = '@uc') OR (Razao_Social LIKE '@Razao_Social' AND Codigo_Instalacao = '@uc')";
|
||||
}
|
||||
}
|
||||
|
||||
cmd.CommandText = selectSQL;
|
||||
|
||||
OleDbDataReader reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
// Dados cadastrais
|
||||
dadosTusd.Cod_Smart_unidade = long.Parse(reader["Cod_Smart_unidade"].ToString() !);
|
||||
dadosTusd.Perfil_CliqCCEE = reader["PerfilCCEE"].ToString();
|
||||
dadosTusd.Submercado = reader["Submercado"].ToString();
|
||||
dadosTusd.Ambiente = reader["Status_unidade"].ToString();
|
||||
dadosTusd.Grupo = reader["Grupo"].ToString();
|
||||
dadosTusd.Distribuidora = reader["Distribuidora"].ToString();
|
||||
dadosTusd.ICMS = float.Parse(reader["ICMS_TUSD"].ToString() !);
|
||||
dadosTusd.Dem_Cont_P = float.Parse(reader["Demanda_P"].ToString() !);
|
||||
dadosTusd.Dem_Cont_FP = float.Parse(reader["Demanda_FP"].ToString() !);
|
||||
this.pastaMiddle = reader["Caminho_NFs"].ToString();
|
||||
this.empresa = reader["Cliente"].ToString();
|
||||
this.unidade = reader["Unidade"].ToString();
|
||||
}
|
||||
cmd.Parameters.AddWithValue("@CNPJ", parsedResult.customer.cnpj?[..8] ?? "NAN");
|
||||
cmd.Parameters.AddWithValue("@uc", uc);
|
||||
cmd.Parameters.AddWithValue("@Razao_Social", parsedResult.customer.name.Replace("'", "''"));
|
||||
|
||||
reader.Close();
|
||||
using (OleDbDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
// Dados cadastrais
|
||||
dadosTusd.Cod_Smart_unidade = long.Parse(reader["Cod_Smart_unidade"].ToString() !);
|
||||
dadosTusd.Perfil_CliqCCEE = reader["PerfilCCEE"].ToString();
|
||||
dadosTusd.Submercado = reader["Submercado"].ToString();
|
||||
dadosTusd.Ambiente = reader["Status_unidade"].ToString();
|
||||
dadosTusd.Grupo = reader["Grupo"].ToString();
|
||||
dadosTusd.Distribuidora = reader["Distribuidora"].ToString();
|
||||
dadosTusd.ICMS = float.Parse(reader["ICMS_TUSD"].ToString() !);
|
||||
dadosTusd.Dem_Cont_P = float.Parse(reader["Demanda_P"].ToString() !);
|
||||
dadosTusd.Dem_Cont_FP = float.Parse(reader["Demanda_FP"].ToString() !);
|
||||
this.pastaMiddle = reader["Caminho_NFs"].ToString();
|
||||
this.empresa = reader["Cliente"].ToString();
|
||||
this.unidade = reader["Unidade"].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Verifica se a fatura ja foi lançada
|
||||
selectSQL = $"SELECT Cod_TUSD FROM Dados_TUSD WHERE Cod_TUSD = {long.Parse(dadosTusd.Cod_Smart_unidade.ToString() + dadosTusd.Mes.ToString())}";
|
||||
cmd.CommandText = selectSQL;
|
||||
reader = cmd.ExecuteReader();
|
||||
bool tusdLanc = reader.HasRows;
|
||||
reader.Close();
|
||||
bool tusdLanc;
|
||||
|
||||
selectSQL = $"SELECT Cod_TUSD FROM Dados_TUSD WHERE Cod_TUSD = @Cod_TUSD";
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@Cod_TUSD", long.Parse(dadosTusd.Cod_Smart_unidade.ToString() + dadosTusd.Mes.ToString()));
|
||||
|
||||
using (OleDbDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
tusdLanc = reader.HasRows;
|
||||
}
|
||||
}
|
||||
|
||||
if (dadosTusd.Cod_Smart_unidade == 0)
|
||||
{
|
||||
this.Status = "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD";
|
||||
@ -127,20 +142,23 @@
|
||||
else
|
||||
{
|
||||
// PIS e Cofins
|
||||
string pisSQL = $"SELECT Distribuidoras_PIS.PIS, Distribuidoras_PIS.COFINS FROM Distribuidoras_geral INNER JOIN Distribuidoras_PIS ON Distribuidoras_geral.ID_dist = Distribuidoras_PIS.ID_dist WHERE Distribuidoras_PIS.Mes='{dadosTusd.Mes}' AND Distribuidoras_geral.Distribuidora='{dadosTusd.Distribuidora}'";
|
||||
string pisSQL = $"SELECT Distribuidoras_PIS.PIS, Distribuidoras_PIS.COFINS FROM Distribuidoras_geral INNER JOIN Distribuidoras_PIS ON Distribuidoras_geral.ID_dist = Distribuidoras_PIS.ID_dist WHERE Distribuidoras_PIS.Mes='@mes' AND Distribuidoras_geral.Distribuidora='@distribuidora'";
|
||||
|
||||
cmd.CommandText = pisSQL;
|
||||
|
||||
reader = cmd.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
using (OleDbCommand cmd = new OleDbCommand(pisSQL, conn))
|
||||
{
|
||||
// PIS e Cofins
|
||||
dadosTusd.PIS = float.Parse(reader["PIS"].ToString() !);
|
||||
dadosTusd.COFINS = float.Parse(reader["COFINS"].ToString() !);
|
||||
}
|
||||
cmd.Parameters.AddWithValue("@mes", dadosTusd.Mes);
|
||||
cmd.Parameters.AddWithValue("@distribuidora", dadosTusd.Distribuidora);
|
||||
|
||||
reader.Close();
|
||||
using (OleDbDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
// PIS e Cofins
|
||||
dadosTusd.PIS = float.Parse(reader["PIS"].ToString() !);
|
||||
dadosTusd.COFINS = float.Parse(reader["COFINS"].ToString() !);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dados da fatura processada
|
||||
dadosTusd.Cod_TUSD = long.Parse(dadosTusd.Cod_Smart_unidade.ToString() + dadosTusd.Mes.ToString());
|
||||
@ -191,7 +209,7 @@
|
||||
float? dem_Reg_FP = null;
|
||||
float? consumo_Reg_FP = null;
|
||||
|
||||
List<string> insertOthers = new List<string>();
|
||||
List<(string, float)> insertOthers = new List<(string, float)>();
|
||||
foreach (Item item in parsedResult.items)
|
||||
{
|
||||
switch (item.type, item.period)
|
||||
@ -224,42 +242,46 @@
|
||||
dadosTusd.Consumo_FP = dadosTusd.Consumo_FP + (item.billed / 1000);
|
||||
break;
|
||||
|
||||
// Demanda Ponta
|
||||
case ("demand", "peak"):
|
||||
// Demanda
|
||||
case ("demand", _):
|
||||
|
||||
if (item.contract != 0)
|
||||
{
|
||||
dadosTusd.Dem_Cont_P = item.contract;
|
||||
if (dadosTusd.Perfil == "AZUL")
|
||||
if (item.period == "peak")
|
||||
{
|
||||
cmd.CommandText = $"UPDATE Dados_cadastrais SET Demanda_P = {item.contract} WHERE Cod_Smart_unidade = {dadosTusd.Cod_Smart_unidade}";
|
||||
dadosTusd.Dem_Cont_P = item.contract;
|
||||
}
|
||||
else if (dadosTusd.Perfil == "VERDE")
|
||||
else if (item.period == "off-peak")
|
||||
{
|
||||
cmd.CommandText = $"UPDATE Dados_cadastrais SET Demanda_P = {item.contract}, Demanda_FP = {item.contract} WHERE Cod_Smart_unidade = {dadosTusd.Cod_Smart_unidade}";
|
||||
dadosTusd.Dem_Cont_FP = item.contract;
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Demanda Fora de Ponta
|
||||
case ("demand", "off-peak"):
|
||||
|
||||
if (item.contract != 0)
|
||||
{
|
||||
dadosTusd.Dem_Cont_FP = item.contract;
|
||||
if (dadosTusd.Perfil == "AZUL")
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
cmd.CommandText = $"UPDATE Dados_cadastrais SET Demanda_FP = {item.contract} WHERE Cod_Smart_unidade = {dadosTusd.Cod_Smart_unidade}";
|
||||
}
|
||||
else if (dadosTusd.Perfil == "VERDE")
|
||||
{
|
||||
cmd.CommandText = $"UPDATE Dados_cadastrais SET Demanda_P = {item.contract}, Demanda_FP = {item.contract} WHERE Cod_Smart_unidade = {dadosTusd.Cod_Smart_unidade}";
|
||||
}
|
||||
if (dadosTusd.Perfil == "AZUL")
|
||||
{
|
||||
if (item.period == "peak")
|
||||
{
|
||||
selectSQL = $"UPDATE Dados_cadastrais SET Demanda_P = @demanda WHERE Cod_Smart_unidade = @cod_smart_unidade";
|
||||
cmd.Parameters.AddWithValue("@demanda", item.contract);
|
||||
cmd.Parameters.AddWithValue("@cod_smart_unidade", dadosTusd.Cod_Smart_unidade);
|
||||
}
|
||||
else if (item.period == "off-peak")
|
||||
{
|
||||
selectSQL = $"UPDATE Dados_cadastrais SET Demanda_FP = @demanda WHERE Cod_Smart_unidade = @cod_smart_unidade";
|
||||
cmd.Parameters.AddWithValue("@demanda", item.contract);
|
||||
cmd.Parameters.AddWithValue("@cod_smart_unidade", dadosTusd.Cod_Smart_unidade);
|
||||
}
|
||||
}
|
||||
else if (dadosTusd.Perfil == "VERDE")
|
||||
{
|
||||
selectSQL = $"UPDATE Dados_cadastrais SET Demanda_P = @demanda, Demanda_FP = @demanda WHERE Cod_Smart_unidade = @cod_smart_unidade";
|
||||
cmd.Parameters.AddWithValue("@demanda", item.contract);
|
||||
cmd.Parameters.AddWithValue("@cod_smart_unidade", dadosTusd.Cod_Smart_unidade);
|
||||
}
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
@ -291,13 +313,15 @@
|
||||
// Exclui os items lançados anteriormente para a fatura e cria a instrução SQL para inserir os novos items
|
||||
if (j == 1)
|
||||
{
|
||||
string deleteOthers = $"DELETE FROM Dados_TUSD_aux WHERE Cod_TUSD = {dadosTusd.Cod_TUSD}";
|
||||
cmd.CommandText = deleteOthers;
|
||||
cmd.ExecuteNonQuery();
|
||||
string deleteOthers = $"DELETE FROM Dados_TUSD_aux WHERE Cod_TUSD = @cod_tusd";
|
||||
using (OleDbCommand cmd = new OleDbCommand(deleteOthers, conn))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@cod_tusd", dadosTusd.Cod_TUSD);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
insertOthers.Add("INSERT INTO Dados_TUSD_aux (Cod_TUSD,Id,Nome,Valor,Cod_lanc) VALUES (" + dadosTusd.Cod_TUSD + "," + j + ",'" + item.name + "'," + item.charge.ToString(new CultureInfo("en-US")) + "," + 0 + ")");
|
||||
|
||||
insertOthers.Add((item.name, item.charge));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -401,11 +425,16 @@
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
// Inseri os itens classificados como "othes" após criar o registro da TUSD devido as relação entre as tabelas
|
||||
foreach (string insert in insertOthers)
|
||||
foreach ((string name, float valor) in insertOthers)
|
||||
{
|
||||
if (insert.Length != 0)
|
||||
j++;
|
||||
selectSQL = "INSERT INTO Dados_TUSD_aux (Cod_TUSD,Id,Nome,Valor,Cod_lanc) VALUES ( @cod_tusd, @j,'@name',@valor,0)";
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
cmd.CommandText = insert;
|
||||
cmd.Parameters.AddWithValue("@cod_tusd", dadosTusd.Cod_TUSD);
|
||||
cmd.Parameters.AddWithValue("@j", j);
|
||||
cmd.Parameters.AddWithValue("@name", name);
|
||||
cmd.Parameters.AddWithValue("@valor", valor);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
@ -457,11 +486,16 @@
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
// Inseri os itens classificados como "othes" após criar o registro da TUSD devido as relação entre as tabelas
|
||||
foreach (string insert in insertOthers)
|
||||
foreach ((string name, float valor) in insertOthers)
|
||||
{
|
||||
if (insert.Length != 0)
|
||||
j++;
|
||||
selectSQL = "INSERT INTO Dados_TUSD_aux (Cod_TUSD,Id,Nome,Valor,Cod_lanc) VALUES ( @cod_tusd, @j,'@name',@valor,0)";
|
||||
using (OleDbCommand cmd = new OleDbCommand(selectSQL, conn))
|
||||
{
|
||||
cmd.CommandText = insert;
|
||||
cmd.Parameters.AddWithValue("@cod_tusd", dadosTusd.Cod_TUSD);
|
||||
cmd.Parameters.AddWithValue("@j", j);
|
||||
cmd.Parameters.AddWithValue("@name", name);
|
||||
cmd.Parameters.AddWithValue("@valor", valor);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,8 +18,6 @@
|
||||
#endif
|
||||
public const string CaminhoDB = "X:/Middle/Informativo Setorial/Modelo Word/BD1_dados cadastrais e faturas.accdb";
|
||||
private static HttpClient httpClient = new ();
|
||||
private static OleDbConnection conn = new (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21");
|
||||
private static OleDbCommand cmd = new ();
|
||||
private static StreamReader sr = new (LogFaturas);
|
||||
private static StreamWriter sw = new (LogFaturas2);
|
||||
private static string? fatura;
|
||||
@ -27,103 +25,104 @@
|
||||
public static void Main()
|
||||
{
|
||||
// Abre a conexao com o banco de dados
|
||||
conn.Open();
|
||||
cmd.Connection = conn;
|
||||
|
||||
// Loop entre as faturas pendentes
|
||||
while ((fatura = sr.ReadLine()) != null)
|
||||
using (OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + CaminhoDB + ";Jet OLEDB:Database Password=gds21"))
|
||||
{
|
||||
string fatura_ID = fatura.Split(",")[0];
|
||||
string fatura_status = fatura.Split(",")[1];
|
||||
string fatura_arquivo = fatura.Split(",")[2];
|
||||
conn.Open();
|
||||
|
||||
// Verifica se a fatura foi processada e atualiza os valores para banco de dados
|
||||
if (fatura_status == "DELAYED" | fatura_status == "MULTACTIONABLE" | fatura_status == "ACTIONABLE" | fatura_status == string.Empty | fatura_status == "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD")
|
||||
// Loop entre as faturas pendentes
|
||||
while ((fatura = sr.ReadLine()) != null)
|
||||
{
|
||||
if (fatura_status == "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD" && !File.Exists(fatura_arquivo))
|
||||
string fatura_ID = fatura.Split(",")[0];
|
||||
string fatura_status = fatura.Split(",")[1];
|
||||
string fatura_arquivo = fatura.Split(",")[2];
|
||||
|
||||
// Verifica se a fatura foi processada e atualiza os valores para banco de dados
|
||||
if (fatura_status == "DELAYED" | fatura_status == "MULTACTIONABLE" | fatura_status == "ACTIONABLE" | fatura_status == string.Empty | fatura_status == "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD")
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura_arquivo);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Verifica se a fatura foi processada e atualiza os valores para o banco de dados
|
||||
Fatura fatura = new Fatura(fatura_ID, fatura_arquivo, httpClient);
|
||||
|
||||
if (fatura.Status == "SUCCESS" & !fatura.Agrupada)
|
||||
if (fatura_status == "UNIDADE CONSUMIDORA NÃO LOCALIZADA NO BD" && !File.Exists(fatura_arquivo))
|
||||
{
|
||||
fatura.Processar(cmd);
|
||||
try
|
||||
{
|
||||
fatura.Mover(separar: false);
|
||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura.Arquivo);
|
||||
}
|
||||
}
|
||||
else if (fatura.Status == "SUCCESS" & fatura.Agrupada)
|
||||
{
|
||||
foreach (JsonElement individual_ID in fatura.Agrupada_children)
|
||||
{
|
||||
Fatura faturaIndividual = new (individual_ID.ToString(), fatura_arquivo, httpClient);
|
||||
|
||||
if (faturaIndividual.Status == "SUCCESS")
|
||||
{
|
||||
faturaIndividual.Processar(cmd);
|
||||
try
|
||||
{
|
||||
faturaIndividual.Mover(separar: true);
|
||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(individual_ID.ToString() + "," + "ARQUIVO NÃO LOCALIZADO" + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
faturaIndividual.Mover(separar: true);
|
||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(individual_ID.ToString() + "," + "ARQUIVO NÃO LOCALIZADO" + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fatura.Arquivo!.Delete();
|
||||
}
|
||||
else if (fatura.Status == "INVALID")
|
||||
{
|
||||
try
|
||||
{
|
||||
fatura.Mover(separar: false);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura.Arquivo);
|
||||
}
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura_arquivo);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
||||
// Verifica se a fatura foi processada e atualiza os valores para o banco de dados
|
||||
Fatura fatura = new Fatura(fatura_ID, fatura_arquivo, httpClient);
|
||||
|
||||
if (fatura.Status == "SUCCESS" & !fatura.Agrupada)
|
||||
{
|
||||
fatura.Processar(conn);
|
||||
try
|
||||
{
|
||||
fatura.Mover(separar: false);
|
||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura.Arquivo);
|
||||
}
|
||||
}
|
||||
else if (fatura.Status == "SUCCESS" & fatura.Agrupada)
|
||||
{
|
||||
foreach (JsonElement individual_ID in fatura.Agrupada_children)
|
||||
{
|
||||
Fatura faturaIndividual = new (individual_ID.ToString(), fatura_arquivo, httpClient);
|
||||
|
||||
if (faturaIndividual.Status == "SUCCESS")
|
||||
{
|
||||
faturaIndividual.Processar(conn);
|
||||
try
|
||||
{
|
||||
faturaIndividual.Mover(separar: true);
|
||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(individual_ID.ToString() + "," + "ARQUIVO NÃO LOCALIZADO" + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
faturaIndividual.Mover(separar: true);
|
||||
sw.WriteLine(individual_ID.ToString() + "," + faturaIndividual.Status + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(individual_ID.ToString() + "," + "ARQUIVO NÃO LOCALIZADO" + "," + faturaIndividual.Arquivo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fatura.Arquivo!.Delete();
|
||||
}
|
||||
else if (fatura.Status == "INVALID")
|
||||
{
|
||||
try
|
||||
{
|
||||
fatura.Mover(separar: false);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + "ARQUIVO NÃO LOCALIZADO" + "," + fatura.Arquivo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine(fatura_ID + "," + fatura.Status + "," + fatura_arquivo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine(fatura);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sw.WriteLine(fatura);
|
||||
}
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
sr.Close();
|
||||
sw.Close();
|
||||
File.Move(LogFaturas2, LogFaturas, true);
|
||||
sr.Close();
|
||||
sw.Close();
|
||||
File.Move(LogFaturas2, LogFaturas, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user