1262 lines
64 KiB
C#
1262 lines
64 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml;
|
|
using System.Xml.Linq;
|
|
|
|
|
|
namespace CSVToXML
|
|
{
|
|
public partial class frmCSVToXML : Form
|
|
{
|
|
//valori costanti dell'xml
|
|
//path destinazione è il perscorso dove verranno salvati i file xml generati.
|
|
//viene letto nel file XmlConfigFile.xml dentro alla cartella bin del progetto
|
|
public static string pathDestinazione = string.Empty;
|
|
|
|
public frmCSVToXML()
|
|
{
|
|
InitializeComponent();
|
|
ReadXML();
|
|
}
|
|
|
|
#region METODI
|
|
|
|
public void ReadXML()
|
|
{
|
|
try
|
|
{
|
|
//cicla gli elementi del file .xml passato al Load, guardando i nodi (Items) e relativi sottnodi del nodo padre (item)
|
|
//foreach (var item in XElement.Load(@"XMLFile1.xml").Descendants("Items").Elements("Item"))
|
|
foreach (var item in XElement.Load(@"XmlConfigFile.xml").Descendants("Items").Elements("Item"))
|
|
{
|
|
//se l'elemento non ha attributi
|
|
if (!item.Attributes().Any())
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var nome = item.Attribute("name").Value;
|
|
var valore = item.Attribute("value").Value;
|
|
|
|
switch (nome)
|
|
{
|
|
case "diOutput":
|
|
pathDestinazione = valore;
|
|
//txtArea.Text = $"{pathDestinazione}";
|
|
break;
|
|
default:
|
|
txtArea.Text = $"nome: {nome} valore: {valore}";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
txtArea.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void CercaNeiFile()
|
|
{
|
|
//creo oggetto openFileDialog1
|
|
OpenFileDialog openFileDialog1 = new OpenFileDialog();
|
|
|
|
//apro finestra per selezionare il file
|
|
DialogResult res = openFileDialog1.ShowDialog();
|
|
|
|
if (res == DialogResult.OK)
|
|
{
|
|
string nomeFileTrovato = openFileDialog1.FileName;
|
|
|
|
txtFile.Text = nomeFileTrovato;
|
|
|
|
txtArea.Text = $"Premere Genera XML/XML Inv. per iniziare la procedura di conversione."
|
|
+ Environment.NewLine;
|
|
}
|
|
}
|
|
|
|
//metodo che legge file csv e restituiscs lista di oggetti delle righe del csv
|
|
private List<CSVFileObject> CreaOggettiPerConversioni()
|
|
{
|
|
List<CSVFileObject> listPartenza = new List<CSVFileObject>();
|
|
|
|
List<CSVFileObject> listaOrdinata = new List<CSVFileObject>();
|
|
|
|
//var listaRighe = File.ReadAllLines(txtFile.Text).Where(x => !string.IsNullOrEmpty(x)).Skip(1).ToList();
|
|
|
|
//leggo le righe del file CSV(ReadLines())
|
|
//filtro per le righe che non sono nulle (where).
|
|
//skippo la prima che ha i titoli delle colonne (skip(1)).
|
|
//per ogni riga creo un oggetto
|
|
listPartenza = File.ReadLines(txtFile.Text).Where(x => !string.IsNullOrEmpty(x)).Skip(1).Select(x => CSVFileObject.FromCsvGigante(x)).ToList();
|
|
|
|
ControllaDareAvere(listPartenza);
|
|
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//listaOrdinata = listPartenza.OrderBy(x => x.IntCodiceDatoRipartizione4).ToList();
|
|
listaOrdinata = listPartenza.OrderBy(x => x.intCodificaDellaRipartizione3).ToList();
|
|
|
|
return listaOrdinata;
|
|
}
|
|
|
|
private List<Appoggio> NumeroFileXMLDaProdurre(List<CSVFileObject> listaRigheCsv)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
List<Appoggio> appoggio = new List<Appoggio>();
|
|
|
|
var app = new Appoggio();
|
|
|
|
app.numFileXml = 1;
|
|
|
|
//var listaDistinct = listaRigheCsv.Select(o => o.CodiceConto)/*.Distinct()*/.ToList();
|
|
|
|
//faccio il distinct della lista per vedere quanti sono i codici dato ripartizione 4
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//var listaDistinct = listaRigheCsv.Select(o => o.CodiceDatoRipartizione4).Distinct().ToList();
|
|
var listaDistinct = listaRigheCsv.Select(o => o.CodificaDellaRipartizione3).Distinct().ToList();
|
|
|
|
var count = 0;
|
|
|
|
var parz = 0;
|
|
|
|
if (listaDistinct != null && listaDistinct.Any())
|
|
{
|
|
foreach (var item in listaDistinct)
|
|
{
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//parz = listaRigheCsv.Where(x => x.CodiceDatoRipartizione4.Equals(item)).Count();
|
|
parz = listaRigheCsv.Where(x => x.CodificaDellaRipartizione3.Equals(item)).Count();
|
|
count += parz;
|
|
sb.AppendLine(count.ToString());
|
|
//appoggio.Add(app);
|
|
|
|
app.codice = item;
|
|
|
|
if (count > 999/* || item == listaDistinct.Last()*/)
|
|
{
|
|
app.numFileXml += 1;
|
|
|
|
appoggio.Add(new Appoggio { codice = app.codice, numFileXml = app.numFileXml });
|
|
|
|
sb.AppendLine("TROVATO!!!!");
|
|
//count = 0;
|
|
count = parz;
|
|
}
|
|
else
|
|
{
|
|
appoggio.Add(new Appoggio { codice = app.codice, numFileXml = app.numFileXml });
|
|
}
|
|
}
|
|
}
|
|
|
|
return appoggio;
|
|
//return listaDistinct;
|
|
}
|
|
|
|
private void ControllaDareAvere(List<CSVFileObject> list)
|
|
{
|
|
decimal TotDare = 0;
|
|
decimal TotAvere = 0;
|
|
|
|
foreach (var item in list)
|
|
{
|
|
TotDare += item.DoubleImportoDare;
|
|
TotAvere += item.DoubleImportoAvere;
|
|
}
|
|
var differenza = TotDare - TotAvere;
|
|
|
|
if (differenza != 0)
|
|
{
|
|
var strErrore = MessageBox.Show($"LA differenza tra gli importi in DARE e gli importi in AVERE deve essere ZERO.",
|
|
"Erore differenza importi dare/avere",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region EVENTI
|
|
|
|
private void btnCercaFile_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
CercaNeiFile();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
txtArea.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
private void btnConverti_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//controllo che codice azienda sia inserito da input, senò non genero l'xml
|
|
//la data non la controllo perchè se non la modifico prende la data di oggi
|
|
if (txtCodAzi.Text.Length == 4 && !string.IsNullOrEmpty(txtCodAzi.Text))
|
|
{
|
|
txtArea.Clear();
|
|
|
|
txtArea.Text = $"Premere Genera XML/XML Inv. per iniziare la procedura di conversione."
|
|
+ Environment.NewLine;
|
|
|
|
var list = CreaOggettiPerConversioni();
|
|
|
|
var listaAppoggio = NumeroFileXMLDaProdurre(list);
|
|
var listaXml = new List<Appoggio>();
|
|
var numberXml = 1;
|
|
var path = string.Empty;
|
|
var pathCompleto = string.Empty;
|
|
//questo sarà il contenuto del tag xml <recordcount>
|
|
//30/05/2022 pare che tag recordcount debba essere fisso a 1 quindi commento tutto ciò che lo riguarda
|
|
//var recordcount = 0;
|
|
var dateString = string.Empty;
|
|
|
|
//12/07/2024 - Il cliente ha chiesto un alert che non blocchi la creazione del file XML ma che mostri quali dipendenti
|
|
//non hanno valorizzati i campi "codice dato ripartizione 4" e "codice dato ripartizione 5" dentro il csv.
|
|
var listaNomiAlert = new List<string>();
|
|
var nomeDipNoValore = string.Empty;
|
|
|
|
//data per gli attributi del tag E1FIKPF per i file DATA
|
|
var dateTimePeaker = dtpAnnoMese;
|
|
var dateBLDAT = dtpAnnoMese.Value.ToString("yyyyMMdd");
|
|
var dateBUDAT = dtpAnnoMese.Value.ToString("yyyyMMdd");
|
|
var dateXBLNRYear = dtpAnnoMese.Value.Year.ToString();
|
|
var dateXBLNRMonth = dtpAnnoMese.Value.Month.ToString();
|
|
|
|
if (dateXBLNRMonth.Length == 1)
|
|
{
|
|
dateXBLNRMonth = "0" + dateXBLNRMonth;
|
|
}
|
|
|
|
var dateBKTXTYear = dtpAnnoMese.Value.Year.ToString();
|
|
var dateBKTXTMonth = dtpAnnoMese.Value.Month.ToString();
|
|
|
|
if (dateBKTXTMonth.Length == 1)
|
|
{
|
|
dateBKTXTMonth = "0" + dateBKTXTMonth;
|
|
}
|
|
|
|
var erroreTrovato = 0;
|
|
var msgDato = 0;
|
|
|
|
//Controllo che per ogni codifica della ripartizione 3 ci sia uno e uno solo codice dipendete
|
|
foreach (var item in listaAppoggio)
|
|
{
|
|
//filtro la lista così ad ogni iterata avrò solo le righe della lista con codifica della ripartizione 3 = a quello
|
|
//dell'elemento della listaAppoggio che sto ciclando. coì per ogni "codifica" posso crearmi il suo xml
|
|
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//var listaFiltrata = list.Where(x => x.CodiceDatoRipartizione4.Equals(app.codice)).ToList();
|
|
var listaFiltrata = list.Where(x => x.CodificaDellaRipartizione3.Equals(item.codice)).ToList();
|
|
|
|
//controllo che alla stessa codifica della ripartizione 3 non appartengano più codici dipendenti
|
|
var codiceDipendente = listaFiltrata.First().CodiceDipendente;
|
|
var listaNomiErrori = new List<string>();
|
|
var nomeDipendente = string.Empty;
|
|
|
|
foreach (var elem in listaFiltrata)
|
|
{
|
|
if (elem.CodiceDatoRipartizione4.Equals("\"\"") || elem.CodiceDatoRipartizione5.Equals("\"\""))
|
|
{
|
|
nomeDipNoValore = elem.CodiceDipendente + " - " + elem.Nome + " " + elem.Cognome;
|
|
listaNomiAlert.Add(nomeDipNoValore);
|
|
}
|
|
|
|
//if (codiceDipendente != elem.CodiceDipendente)
|
|
if (string.IsNullOrEmpty(elem.CodiceDatoRipartizione3/*CodificaDellaRipartizione3*/))
|
|
{
|
|
nomeDipendente = elem.Cognome + " " + elem.Nome;
|
|
|
|
var trovato = 0;
|
|
|
|
foreach (var nomeDip in listaNomiErrori)
|
|
{
|
|
var nome1 = nomeDipendente.Replace(" ", "");
|
|
var nome2 = nomeDip.Replace(" ", "");
|
|
if (nome1.Equals(nome2))
|
|
{
|
|
trovato = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (trovato != 1)
|
|
{
|
|
listaNomiErrori.Add(nomeDipendente);
|
|
}
|
|
|
|
erroreTrovato = 1;
|
|
}
|
|
}
|
|
|
|
if (erroreTrovato == 1)
|
|
{
|
|
if (msgDato == 0)
|
|
{
|
|
//var codifRip3 = elem.CodificaDellaRipartizione3;
|
|
txtArea.Text += Environment.NewLine +
|
|
"GENERAZIONE XML NON AVVENUTA.";
|
|
txtArea.Text += Environment.NewLine
|
|
+ Environment.NewLine
|
|
+ $"Controllare le codifiche della ripartizione 3 per i seguenti dipendenti:"
|
|
+ Environment.NewLine;
|
|
|
|
var str = MessageBox.Show($"Non ci possono essere dipendenti con CODICE DELLA RIPARTIZIONE 3 vuoto." +
|
|
Environment.NewLine +
|
|
$"Correggere per poter creare l'XML",
|
|
"IL CODICE DELLA RIPARTIZIONE 3 VUOTO.",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
msgDato = 1;
|
|
}
|
|
|
|
foreach (var nomi in listaNomiErrori)
|
|
{
|
|
txtArea.Text += $"- {nomi}"
|
|
+ Environment.NewLine;
|
|
}
|
|
}
|
|
}
|
|
|
|
//FILE DATA string builder
|
|
StringBuilder stringDATA = new StringBuilder();
|
|
//FILE CONT string builder
|
|
StringBuilder stringCONT = new StringBuilder();
|
|
|
|
if (listaNomiAlert.Count != 0)
|
|
{
|
|
//mostro a video l'elenco dei dipendenti che hanno l'alert.
|
|
txtArea.Text += Environment.NewLine +
|
|
"I seguenti dipendenti non hanno valorizzati i Codice dato ripartizione 4 o Codice dato ripartizione 5:"
|
|
+ Environment.NewLine;
|
|
|
|
foreach (var nomiDip in listaNomiAlert)
|
|
{
|
|
txtArea.Text += $"- {nomiDip.Replace("\"", "")}"
|
|
+ Environment.NewLine;
|
|
}
|
|
}
|
|
|
|
//list.Where(x => x.CodiceDatoRipartizione4.Contains("1")).ToList();
|
|
if (list != null && list.Any() && erroreTrovato == 0)
|
|
{
|
|
stringDATA.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringDATA.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
stringDATA.Append("<PostingDocument>");
|
|
stringDATA.Append($"<E1FIKPF BUKRS=\"{txtCodAzi.Text}\" BLART=\"GE\" BLDAT=\"{dateBLDAT}\" BUDAT=\"{dateBUDAT}\" XBLNR=\"HR - {dateXBLNRYear} - {dateXBLNRMonth}\" " +
|
|
$"BKTXT=\"Payroll - Salary - {dateBKTXTYear} - {dateBKTXTMonth}\" WAERS=\"EUR\" />");
|
|
|
|
stringCONT.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringCONT.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\" targetNamespace=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
|
|
foreach (var app in listaAppoggio)
|
|
{
|
|
//filtro la lista così ad ogni iterata avrò solo le righe della lista con codice ripartizione uguale a quello
|
|
//dell'elemento della listaAppoggio che sto ciclando. così per ogni "codice" posso crearmi il suo xml
|
|
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//var listaFiltrata = list.Where(x => x.CodiceDatoRipartizione4.Equals(app.codice)).ToList();
|
|
|
|
var listaFiltrata = list.Where(x => x.CodificaDellaRipartizione3.Equals(app.codice)).ToList();
|
|
|
|
if (app.numFileXml != numberXml)
|
|
{
|
|
//txtArea.Text += Environment.NewLine
|
|
//+ $"Finito {numberXml}";
|
|
|
|
stringDATA.Append("</PostingDocument>");
|
|
stringDATA.Append("</ns0:MT_PostingDocument2_V1>");
|
|
|
|
Thread.Sleep(1000);
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
//Thread.Sleep(1000);
|
|
|
|
//path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_DATA.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_DATA.xml";
|
|
//path = $@"C:\Users\miche\Desktop\FileXML\d10015_52905_{dateString}_DATA.xml";
|
|
|
|
//scrivo file xml
|
|
File.WriteAllText(path, stringDATA.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
//pulisco stringbuilder
|
|
stringDATA.Clear();
|
|
|
|
//riapro tag del nuovo file xml DATA
|
|
stringDATA.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringDATA.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
stringDATA.Append("<PostingDocument>");
|
|
stringDATA.Append($"<E1FIKPF BUKRS=\"{txtCodAzi.Text}\" BLART=\"GE\" BLDAT=\"{dateBLDAT}\" BUDAT=\"{dateBUDAT}\" " +
|
|
$"XBLNR=\"HR - {dateXBLNRYear} - {dateXBLNRMonth}\" BKTXT=\"Payroll - Salary - {dateBKTXTYear} - {dateBKTXTMonth}\" WAERS=\"EUR\" />");
|
|
|
|
//txtArea.Text += Environment.NewLine
|
|
//+ $"Finito {numberXml}";
|
|
numberXml++;
|
|
|
|
//FILE CONT
|
|
stringCONT.Append("<recordcount>");
|
|
stringCONT.Append($"{1/*recordcount*/}");
|
|
stringCONT.Append("</recordcount>");
|
|
stringCONT.Append("</ns0:MT_PostingDocument2_V1>");
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_CONT.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_CONT.xml";
|
|
//path = $@"C:\Users\miche\Desktop\FileXML\d10015_52905_{dateString}_CONT.xml";
|
|
|
|
File.WriteAllText(path, stringCONT.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
//recordcount = 0;
|
|
|
|
//pulisco stringbuilder
|
|
stringCONT.Clear();
|
|
|
|
//riapro i tag del nuovo file xml CONT
|
|
stringCONT.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringCONT.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\" targetNamespace=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
}
|
|
|
|
//possibile soluzione
|
|
//recordcount += listaFiltrata.Count();
|
|
|
|
foreach (var item in listaFiltrata)
|
|
{
|
|
//UTILIZZATO SOLO PER VEDERE CHE DATO RIPARTIZIONE FOSSE (NON SERVE)
|
|
//myStringbuilder.Append("<DATORIPARTIZIONE>");
|
|
//myStringbuilder.Append($"{app.codice}");
|
|
//myStringbuilder.Append("</DATORIPARTIZIONE>");
|
|
|
|
stringDATA.Append("<E1FISEG>");
|
|
stringDATA.Append("<KOART>");
|
|
stringDATA.Append("S");
|
|
stringDATA.Append("</KOART>");
|
|
stringDATA.Append("<SHKZG>");
|
|
//prima dell'if sostituisco la , col . per poter castare a decimale la stringa
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
//13/01/2023 MODIFICATO
|
|
//stringDATA.Append("H");
|
|
stringDATA.Append("S");
|
|
}
|
|
else
|
|
{
|
|
//13/01/2023 MODIFICATO
|
|
//stringDATA.Append("S");
|
|
stringDATA.Append("H");
|
|
|
|
}
|
|
|
|
stringDATA.Append("</SHKZG>");
|
|
stringDATA.Append("<MWSKZ />");
|
|
stringDATA.Append("<DMBTR>");
|
|
//var impo = item.ImportoDare.Replace(",", ".");
|
|
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}");
|
|
}
|
|
else
|
|
{
|
|
stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}");
|
|
}
|
|
|
|
stringDATA.Append("</DMBTR>");
|
|
stringDATA.Append("<WRBTR>");
|
|
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}");
|
|
}
|
|
else
|
|
{
|
|
stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}");
|
|
}
|
|
|
|
stringDATA.Append("</WRBTR>");
|
|
stringDATA.Append("<ALUT />");
|
|
stringDATA.Append("<ZUONR />");
|
|
stringDATA.Append("<SGTXT />");
|
|
stringDATA.Append("<VBUND />");
|
|
stringDATA.Append("<BEWAR />");
|
|
stringDATA.Append("<KOSTL />");
|
|
stringDATA.Append("<AUFNR>");
|
|
//28/03/2022 chiesto di modificare da Gastone con CodificaDellaRipartizione3(col. AJ su Excel) anzichè CodiceDatoRipartizione3 (col. AI su Excel)
|
|
//21/10/2022 chiesto da modificare da Gastone e rimettere CodiceDatoRipartizione3 (col. AI su Excel) anzichè CodificaDellaRipartizione3(col. AJ su Excel)
|
|
stringDATA.Append($"{item./*CodificaDellaRipartizione3*/CodiceDatoRipartizione3.Replace("\"", "")}");
|
|
stringDATA.Append("</AUFNR>");
|
|
stringDATA.Append("<HKONT>");
|
|
//MF 03/10/2023 DOPO CALL CON GASTONE DECISO DI RIMETTERE CODICE CONTO E TOGLIERE CODICE CONTROPARTITA PERCHè SENò SPUTTANA S E H PER DARE E AVERE
|
|
//MF 29/07/2024 COMMENTATA PERCHEè USA LA RIGA SOTTO
|
|
//stringDATA.Append($"{item.CodiceConto/*CodiceContropartita*/}");
|
|
//MF 29/07/2024 MESSO REPLACE PERCHè LA STRUTTURA CSV NEL CAMPO CONTO COMPARE COME \"
|
|
stringDATA.Append($"{item.CodiceConto.Replace("\"","")/*CodiceContropartita*/}");
|
|
stringDATA.Append("</HKONT>");
|
|
stringDATA.Append("<FKBER />");
|
|
stringDATA.Append("<UMSKZ />");
|
|
stringDATA.Append("<KUNNR />");
|
|
stringDATA.Append("<ZLSCH />");
|
|
stringDATA.Append("<ZTERM />");
|
|
stringDATA.Append("<ZLSPR />");
|
|
stringDATA.Append("<FWBAS />");
|
|
stringDATA.Append("<LIFNR />");
|
|
stringDATA.Append("<E1FISET>");
|
|
stringDATA.Append("<MWSKZ />");
|
|
stringDATA.Append("<HWBAS />");
|
|
stringDATA.Append("<HWSTE />");
|
|
stringDATA.Append("<FWSTE />");
|
|
stringDATA.Append("</E1FISET>");
|
|
stringDATA.Append("</E1FISEG>");
|
|
}
|
|
}
|
|
|
|
stringDATA.Append("</PostingDocument>");
|
|
stringDATA.Append("</ns0:MT_PostingDocument2_V1>");
|
|
Thread.Sleep(1000);
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_DATA.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_DATA.xml";
|
|
|
|
File.WriteAllText(path, stringDATA.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
stringCONT.Append("<recordcount>");
|
|
//30/05/2022 pare che questo sia un dato fisso a 1
|
|
stringCONT.Append($"{1/*recordcount*/}");
|
|
stringCONT.Append("</recordcount>");
|
|
stringCONT.Append("</ns0:MT_PostingDocument2_V1>");
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
//path = $@"C:\ProgettiVisualStudio\OutputXML\filexml_{numberXml}.xml";
|
|
Thread.Sleep(1000);
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_CONT.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_CONT.xml";
|
|
//path = $@"C:\Users\miche\Desktop\FileXML\d10015_52905_{dateString}_CONT.xml";
|
|
|
|
File.WriteAllText(path, stringCONT.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"Procedura terminata."
|
|
+ Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
}
|
|
}
|
|
else if (txtCodAzi.Text.Length != 4 && !string.IsNullOrEmpty(txtCodAzi.Text))
|
|
{
|
|
var str = MessageBox.Show($"Il codice azienda deve essere lungo quattro ",
|
|
"CODICE AZIENDA ERRATO",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
txtCodAzi.BackColor = Color.FromArgb(255, 102, 102);
|
|
}
|
|
else
|
|
{
|
|
var str = MessageBox.Show($"Inserire il codice azienda prima di poter generare L'XML ",
|
|
"CODICE AZIENDA MANCANTE",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
txtCodAzi.BackColor = Color.FromArgb(255, 102, 102);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//txtArea.Text = ex.Message;
|
|
var str = MessageBox.Show($"{ex.Message}",
|
|
"File CSV non specificato",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
//20/07/2022 - Aggiunto questo bottone perchè hanno bisogno di creare degli xml che abbiano nel tag <SHKZG> i valori S e H
|
|
//invertiti rispetto agli xml che vengono generati con l'altro bottone.
|
|
//la verifica viene fatta in base ai valori del dare/avere.
|
|
private void btnXmlInv_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//controllo che codice azienda sia inserito da input, senò non genero l'xml
|
|
//la data non la controllo perchè se non la modifico prende la data di oggi
|
|
if (txtCodAzi.Text.Length == 4 && !string.IsNullOrEmpty(txtCodAzi.Text))
|
|
{
|
|
txtArea.Clear();
|
|
txtArea.Text = $"Premere Genera XML/XML Inv. per iniziare la procedura di conversione."
|
|
+ Environment.NewLine;
|
|
|
|
var list = CreaOggettiPerConversioni();
|
|
|
|
var listaAppoggio = NumeroFileXMLDaProdurre(list);
|
|
var listaXml = new List<Appoggio>();
|
|
var numberXml = 1;
|
|
var path = string.Empty;
|
|
var pathCompleto = string.Empty;
|
|
|
|
//questo sarà il contenuto del tag xml <recordcount>
|
|
//30/05/2022 pare che tag recordcount debba essere fisso a 1 quindi commento tutto ciò che lo riguarda
|
|
//var recordcount = 0;
|
|
var dateString = string.Empty;
|
|
|
|
//12/07/2024 - Il cliente ha chiesto un alert che non blocchi la creazione del file XML ma che mostri quali dipendenti
|
|
//non hanno valorizzati i campi "codice dato ripartizione 4" e "codice dato ripartizione 5" dentro il csv.
|
|
var listaNomiAlert = new List<string>();
|
|
var nomeDipNoValore = string.Empty;
|
|
|
|
//data per gli attributi del tag E1FIKPF per i file DATA
|
|
var dateTimePeaker = dtpAnnoMese;
|
|
var dateBLDAT = dtpAnnoMese.Value.ToString("yyyyMMdd");
|
|
var dateBUDAT = dtpAnnoMese.Value.ToString("yyyyMMdd");
|
|
var dateXBLNRYear = dtpAnnoMese.Value.Year.ToString();
|
|
var dateXBLNRMonth = dtpAnnoMese.Value.Month.ToString();
|
|
|
|
if (dateXBLNRMonth.Length == 1)
|
|
{
|
|
dateXBLNRMonth = "0" + dateXBLNRMonth;
|
|
}
|
|
|
|
var dateBKTXTYear = dtpAnnoMese.Value.Year.ToString();
|
|
var dateBKTXTMonth = dtpAnnoMese.Value.Month.ToString();
|
|
|
|
if (dateBKTXTMonth.Length == 1)
|
|
{
|
|
dateBKTXTMonth = "0" + dateBKTXTMonth;
|
|
}
|
|
|
|
var erroreTrovato = 0;
|
|
var msgDato = 0;
|
|
|
|
//Controllo che per ogni codifica della ripartizione 3 ci sia uno e uno solo codice dipendete
|
|
foreach (var item in listaAppoggio)
|
|
{
|
|
//filtro la lista così ad ogni iterata avrò solo le righe della lista con codifica della ripartizione 3 = a quello
|
|
//dell'elemento della listaAppoggio che sto ciclando. coì per ogni "codifica" posso crearmi il suo xml
|
|
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//var listaFiltrata = list.Where(x => x.CodiceDatoRipartizione4.Equals(app.codice)).ToList();
|
|
var listaFiltrata = list.Where(x => x.CodificaDellaRipartizione3.Equals(item.codice)).ToList();
|
|
|
|
//controllo che alla stessa codifica della ripartizione 3 non appartengano più codici dipendenti
|
|
var codiceDipendente = listaFiltrata.First().CodiceDipendente;
|
|
var listaNomiErrori = new List<string>();
|
|
var nomeDipendente = string.Empty;
|
|
|
|
foreach (var elem in listaFiltrata)
|
|
{
|
|
if (elem.CodiceDatoRipartizione4.Equals("\"\"") || elem.CodiceDatoRipartizione5.Equals("\"\""))
|
|
{
|
|
nomeDipNoValore = elem.CodiceDipendente + " - " + elem.Nome + " " + elem.Cognome;
|
|
listaNomiAlert.Add(nomeDipNoValore.Replace(" ", ""));
|
|
}
|
|
|
|
//if (codiceDipendente != elem.CodiceDipendente)
|
|
if (string.IsNullOrEmpty(elem.CodiceDatoRipartizione3/*CodificaDellaRipartizione3*/))
|
|
{
|
|
nomeDipendente = elem.Cognome + " " + elem.Nome;
|
|
|
|
var trovato = 0;
|
|
|
|
foreach (var nomeDip in listaNomiErrori)
|
|
{
|
|
var nome1 = nomeDipendente.Replace(" ", "");
|
|
var nome2 = nomeDip.Replace(" ", "");
|
|
if (nome1.Equals(nome2))
|
|
{
|
|
trovato = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (trovato != 1)
|
|
{
|
|
listaNomiErrori.Add(nomeDipendente);
|
|
}
|
|
|
|
erroreTrovato = 1;
|
|
|
|
//break;
|
|
}
|
|
}
|
|
|
|
if (erroreTrovato == 1)
|
|
{
|
|
if (msgDato == 0)
|
|
{
|
|
//var codifRip3 = elem.CodificaDellaRipartizione3;
|
|
txtArea.Text += Environment.NewLine +
|
|
"GENERAZIONE XML NON AVVENUTA.";
|
|
txtArea.Text += Environment.NewLine
|
|
+ Environment.NewLine
|
|
+ $"Controllare le codifiche della ripartizione 3 per i seguenti dipendenti:"
|
|
+ Environment.NewLine;
|
|
|
|
var str = MessageBox.Show($"Non ci possono essere dipendenti con CODICE DELLA RIPARTIZIONE 3 vuoto." +
|
|
Environment.NewLine +
|
|
$"Correggere per poter creare l'XML",
|
|
"IL CODICE DELLA RIPARTIZIONE 3 VUOTO.",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
msgDato = 1;
|
|
}
|
|
|
|
foreach (var nomi in listaNomiErrori)
|
|
{
|
|
txtArea.Text += $"- {nomi}"
|
|
+ Environment.NewLine;
|
|
}
|
|
}
|
|
}
|
|
|
|
//FILE DATA string builder
|
|
StringBuilder stringDATA = new StringBuilder();
|
|
//FILE CONT string builder
|
|
StringBuilder stringCONT = new StringBuilder();
|
|
|
|
if (listaNomiAlert.Count != 0)
|
|
{
|
|
//mostro a video l'elenco dei dipendenti che hanno l'alert.
|
|
txtArea.Text += Environment.NewLine +
|
|
"I seguenti dipendenti non hanno valorizzati i Codice dato ripartizione 4 o Codice dato ripartizione 5:"
|
|
+ Environment.NewLine;
|
|
|
|
foreach (var nomiDip in listaNomiAlert)
|
|
{
|
|
txtArea.Text += $"- {nomiDip.Replace("\"", "")}"
|
|
+ Environment.NewLine;
|
|
}
|
|
}
|
|
|
|
//list.Where(x => x.CodiceDatoRipartizione4.Contains("1")).ToList();
|
|
if (list != null && list.Any() && erroreTrovato == 0)
|
|
{
|
|
stringDATA.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringDATA.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
stringDATA.Append("<PostingDocument>");
|
|
stringDATA.Append($"<E1FIKPF BUKRS=\"{txtCodAzi.Text}\" BLART=\"GE\" BLDAT=\"{dateBLDAT}\" BUDAT=\"{dateBUDAT}\" XBLNR=\"HR - {dateXBLNRYear} - {dateXBLNRMonth}\" " +
|
|
$"BKTXT=\"Payroll - Salary - {dateBKTXTYear} - {dateBKTXTMonth}\" WAERS=\"EUR\" />");
|
|
|
|
stringCONT.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringCONT.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\" targetNamespace=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
|
|
foreach (var app in listaAppoggio)
|
|
{
|
|
//filtro la lista così ad ogni iterata avrò solo le righe della lista con codice ripartizione = a quello
|
|
//dell'elemento della listaAppoggio che sto ciclando. coì per ogni "codice" posso crearmi il suo xml
|
|
//28/03/2022 commentato perchè si deve usare codifica della ripartizione 3 come elementi di rottura.
|
|
//var listaFiltrata = list.Where(x => x.CodiceDatoRipartizione4.Equals(app.codice)).ToList();
|
|
var listaFiltrata = list.Where(x => x.CodificaDellaRipartizione3.Equals(app.codice)).ToList();
|
|
|
|
if (app.numFileXml != numberXml)
|
|
{
|
|
stringDATA.Append("</PostingDocument>");
|
|
stringDATA.Append("</ns0:MT_PostingDocument2_V1>");
|
|
|
|
Thread.Sleep(1000);
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_DATA.xml";
|
|
|
|
//scrivo file xml
|
|
File.WriteAllText(path, stringDATA.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
//pulisco stringbuilder
|
|
stringDATA.Clear();
|
|
|
|
//riapro tag del nuovo file xml DATA
|
|
stringDATA.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringDATA.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
stringDATA.Append("<PostingDocument>");
|
|
stringDATA.Append($"<E1FIKPF BUKRS=\"{txtCodAzi.Text}\" BLART=\"GE\" BLDAT=\"{dateBLDAT}\" BUDAT=\"{dateBUDAT}\" " +
|
|
$"XBLNR=\"HR - {dateXBLNRYear} - {dateXBLNRMonth}\" BKTXT=\"Payroll - Salary - {dateBKTXTYear} - {dateBKTXTMonth}\" WAERS=\"EUR\" />");
|
|
|
|
numberXml++;
|
|
|
|
//FILE CONT
|
|
stringCONT.Append("<recordcount>");
|
|
stringCONT.Append($"{1/*recordcount*/}");
|
|
stringCONT.Append("</recordcount>");
|
|
stringCONT.Append("</ns0:MT_PostingDocument2_V1>");
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_CONT.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_CONT.xml";
|
|
|
|
File.WriteAllText(path, stringCONT.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
//recordcount = 0;
|
|
|
|
//pulisco stringbuilder
|
|
stringCONT.Clear();
|
|
|
|
//riapro i tag del nuovo file xml CONT
|
|
stringCONT.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
|
stringCONT.Append("<ns0:MT_PostingDocument2_V1 xmlns:ns0=\"urn:dekra:pi:nonsap:fico:it:Invoice\" targetNamespace=\"urn:dekra:pi:nonsap:fico:it:Invoice\">");
|
|
}
|
|
|
|
//possibile soluzione
|
|
//recordcount += listaFiltrata.Count();
|
|
|
|
foreach (var item in listaFiltrata)
|
|
{
|
|
stringDATA.Append("<E1FISEG>");
|
|
stringDATA.Append("<KOART>");
|
|
stringDATA.Append("S");
|
|
stringDATA.Append("</KOART>");
|
|
stringDATA.Append("<SHKZG>");
|
|
//IN QUESTO CONTROLLO HO INVERTITO I VALORI DI S E H
|
|
//prima dell'if sostituisco la , col . per poter castare a decimale la stringa
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
stringDATA.Append("H");
|
|
//stringDATA.Append("S"); //13/01/2023 modificato di nuovo (rimesso com'era prima)
|
|
}
|
|
else
|
|
{
|
|
stringDATA.Append("S");
|
|
//stringDATA.Append("H"); //13/01/2023 modificato di nuovo (rimesso com'era prima)
|
|
}
|
|
stringDATA.Append("</SHKZG>");
|
|
stringDATA.Append("<MWSKZ />");
|
|
stringDATA.Append("<DMBTR>");
|
|
//var impo = item.ImportoDare.Replace(",", ".");
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}");
|
|
}
|
|
else
|
|
{
|
|
stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}");
|
|
}
|
|
stringDATA.Append("</DMBTR>");
|
|
stringDATA.Append("<WRBTR>");
|
|
if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0)
|
|
{
|
|
stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}");
|
|
}
|
|
else
|
|
{
|
|
stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}");
|
|
}
|
|
stringDATA.Append("</WRBTR>");
|
|
stringDATA.Append("<ALUT />");
|
|
stringDATA.Append("<ZUONR />");
|
|
stringDATA.Append("<SGTXT />");
|
|
stringDATA.Append("<VBUND />");
|
|
stringDATA.Append("<BEWAR />");
|
|
stringDATA.Append("<KOSTL />");
|
|
stringDATA.Append("<AUFNR>");
|
|
//28/03/2022 chiesto di modificare da Gastone con CodificaDellaRipartizione3(col. AJ su Excel) anzichè CodiceDatoRipartizione3 (col. AI su Excel)
|
|
//21/10/2022 chiesto da modificare da Gastone e rimettere CodiceDatoRipartizione3 (col. AI su Excel) anzichè CodificaDellaRipartizione3(col. AJ su Excel)
|
|
stringDATA.Append($"{item./*CodificaDellaRipartizione3*/CodiceDatoRipartizione3.Replace("\"","")}");
|
|
stringDATA.Append("</AUFNR>");
|
|
stringDATA.Append("<HKONT>");
|
|
//MF 03/10/2023 DOPO CALL CON GASTONE DECISO DI RIMETTERE CODICE CONTO E TOGLIERE CODICE CONTROPARTITA PERCHè SENò SPUTTANA S E H PER DARE E AVERE
|
|
stringDATA.Append($"{item.CodiceConto.Replace("\"", "")/*CodiceContropartita*/}");
|
|
stringDATA.Append("</HKONT>");
|
|
stringDATA.Append("<FKBER />");
|
|
stringDATA.Append("<UMSKZ />");
|
|
stringDATA.Append("<KUNNR />");
|
|
stringDATA.Append("<ZLSCH />");
|
|
stringDATA.Append("<ZTERM />");
|
|
stringDATA.Append("<ZLSPR />");
|
|
stringDATA.Append("<FWBAS />");
|
|
stringDATA.Append("<LIFNR />");
|
|
stringDATA.Append("<E1FISET>");
|
|
stringDATA.Append("<MWSKZ />");
|
|
stringDATA.Append("<HWBAS />");
|
|
stringDATA.Append("<HWSTE />");
|
|
stringDATA.Append("<FWSTE />");
|
|
stringDATA.Append("</E1FISET>");
|
|
stringDATA.Append("</E1FISEG>");
|
|
}
|
|
}
|
|
|
|
stringDATA.Append("</PostingDocument>");
|
|
stringDATA.Append("</ns0:MT_PostingDocument2_V1>");
|
|
Thread.Sleep(1000);
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
//Thread.Sleep(1000);
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_DATA.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_DATA.xml";
|
|
|
|
File.WriteAllText(path, stringDATA.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_DATA.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
|
|
stringCONT.Append("<recordcount>");
|
|
//30/05/2022 pare che questo sia un dato fisso a 1
|
|
stringCONT.Append($"{1/*recordcount*/}");
|
|
stringCONT.Append("</recordcount>");
|
|
stringCONT.Append("</ns0:MT_PostingDocument2_V1>");
|
|
dateString = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
Thread.Sleep(1000);
|
|
path = $@"C:\ProgettiVisualStudio\OutputXML\d10015_52905_{dateString}_CONT.xml";
|
|
path = $@"{pathDestinazione}\d10015_52905_{dateString}_CONT.xml";
|
|
|
|
File.WriteAllText(path, stringCONT.ToString());
|
|
|
|
//controllo se il file è stato creato.
|
|
if (File.Exists(path))
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml creato correttamente" +
|
|
Environment.NewLine;
|
|
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"Procedura terminata."
|
|
+ Environment.NewLine;
|
|
}
|
|
else
|
|
{
|
|
txtArea.Text += Environment.NewLine
|
|
+ $"File d10015_52905_{dateString}_CONT.xml NON creato" +
|
|
Environment.NewLine;
|
|
}
|
|
}
|
|
}
|
|
else if (txtCodAzi.Text.Length != 4 && !string.IsNullOrEmpty(txtCodAzi.Text))
|
|
{
|
|
var str = MessageBox.Show($"Il codice azienda deve essere lungo quattro ",
|
|
"CODICE AZIENDA ERRATO",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
txtCodAzi.BackColor = Color.FromArgb(255, 102, 102);
|
|
}
|
|
else
|
|
{
|
|
var str = MessageBox.Show($"Inserire il codice azienda prima di poter generare L'XML ",
|
|
"CODICE AZIENDA MANCANTE",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
txtCodAzi.BackColor = Color.FromArgb(255, 102, 102);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
var str = MessageBox.Show($"{ex.Message}",
|
|
"File CSV non specificato",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void txtCodAzi_Leave(object sender, EventArgs e)
|
|
{
|
|
if (txtCodAzi.Text.Length == 4 && !string.IsNullOrEmpty(txtCodAzi.Text))
|
|
{
|
|
txtCodAzi.BackColor = Color.White;
|
|
}
|
|
else
|
|
{
|
|
txtCodAzi.BackColor = Color.FromArgb(255, 102, 102);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
#region CLASSI
|
|
|
|
//classe con i campi del file csv che leggo
|
|
public class CSVFileObject
|
|
{
|
|
public string CodiceAzienda;
|
|
public string Denominazione;
|
|
public string DalMese;
|
|
public string TipoCedolinoDal;
|
|
public string AlMese;
|
|
public string TipoCedolinoAl;
|
|
public string RegimeContabile;
|
|
public string ProgressivoRipartizione;
|
|
public string DescrizioneProgressivoRipartizione;
|
|
public string ContabilitaDestinazione;
|
|
public string DescrizioneContabilitaDestinazione;
|
|
public string CodiceConto;
|
|
public string DescrizioneConto;
|
|
public string CodiceDipendente;
|
|
public string Cognome;
|
|
public string Nome;
|
|
public string NumeroRegistrazione;
|
|
public string TipoCausale;
|
|
public string DescrizioneTipoCausale;
|
|
public string Causale;
|
|
public string DescrizioneCausale;
|
|
public string TipoElemento;
|
|
public string DescrizioneTipoElemento;
|
|
public string CodiceContropartita;
|
|
public string DescrizioneContropartita;
|
|
public string ImportoDare;
|
|
public string ImportoAvere;
|
|
public string CodiceTipoDatoRipartizione1;
|
|
public string CodiceDatoRipartizione1;
|
|
public string CodificaDellaRipartizione1;
|
|
public string CodiceTipoDatoRipartizione2;
|
|
public string CodiceDatoRipartizione2;
|
|
public string CodificaDellaRipartizione2;
|
|
public string CodiceTipoDatoRipartizione3;
|
|
public string CodiceDatoRipartizione3;
|
|
public string CodificaDellaRipartizione3;
|
|
public string CodiceTipoDatoRipartizione4;
|
|
public string CodiceDatoRipartizione4;
|
|
public string CodificaDellaRipartizione4;
|
|
public string CodiceTipoDatoRipartizione5;
|
|
public string CodiceDatoRipartizione5;
|
|
public string CodificaDellaRipartizione5;
|
|
public string CodiceTipoDatoRipartizione6;
|
|
public string CodiceDatoRipartizione6;
|
|
public string CodificaDellaRipartizione6;
|
|
public string CodiceTipoDatoRipartizione7;
|
|
public string CodiceDatoRipartizione7;
|
|
public string CodificaDellaRipartizione7;
|
|
public string CodiceTipoDatoRipartizione8;
|
|
public string CodiceDatoRipartizione8;
|
|
public string CodificaDellaRipartizione8;
|
|
|
|
//aggiungo una propery per gestire la colonna CodiceDatoRipartizione4 perchè mi serve averla come intero per poter ordinare la lista.
|
|
//nel try - catch che c'è sotto imporrò che se non è valorizzato il campo prenderà 0. questo avverà solo in fase di test perchè il centro di costo
|
|
//nel file di input dovrà esserci sempre. questo perchè senò potrebbe sputtanarsi il calcolo del dare/avere che deve essere 0
|
|
public int IntCodiceDatoRipartizione4;
|
|
public int intCodificaDellaRipartizione3;
|
|
|
|
public decimal DoubleImportoDare;
|
|
public decimal DoubleImportoAvere;
|
|
|
|
public DateTime DateDalMese;
|
|
|
|
public static CSVFileObject FromCsvGigante(string csvLine)
|
|
{
|
|
CSVFileObject valore = new CSVFileObject();
|
|
|
|
string[] val = csvLine.Split(';');
|
|
|
|
valore.CodiceAzienda = Convert.ToString(val[0]);
|
|
valore.Denominazione = Convert.ToString(val[1]);
|
|
valore.DalMese = Convert.ToString(val[2]);
|
|
valore.TipoCedolinoDal = Convert.ToString(val[3]);
|
|
valore.AlMese = Convert.ToString(val[4]);
|
|
valore.TipoCedolinoAl = Convert.ToString(val[5]);
|
|
valore.RegimeContabile = Convert.ToString(val[6]);
|
|
valore.ProgressivoRipartizione = Convert.ToString(val[7]);
|
|
valore.DescrizioneProgressivoRipartizione = Convert.ToString(val[8]);
|
|
valore.ContabilitaDestinazione = Convert.ToString(val[9]);
|
|
valore.DescrizioneContabilitaDestinazione = Convert.ToString(val[10]);
|
|
valore.CodiceConto = Convert.ToString(val[11]);
|
|
valore.DescrizioneConto = Convert.ToString(val[12]);
|
|
valore.CodiceDipendente = Convert.ToString(val[13]);
|
|
valore.Cognome = Convert.ToString(val[14]);
|
|
valore.Nome = Convert.ToString(val[15]);
|
|
valore.NumeroRegistrazione = Convert.ToString(val[16]);
|
|
valore.TipoCausale = Convert.ToString(val[17]);
|
|
valore.DescrizioneTipoCausale = Convert.ToString(val[18]);
|
|
valore.Causale = Convert.ToString(val[19]);
|
|
valore.DescrizioneCausale = Convert.ToString(val[20]);
|
|
valore.TipoElemento = Convert.ToString(val[21]);
|
|
valore.DescrizioneTipoElemento = Convert.ToString(val[22]);
|
|
valore.CodiceContropartita = Convert.ToString(val[23]);
|
|
valore.DescrizioneContropartita = Convert.ToString(val[24]);
|
|
valore.ImportoDare = Convert.ToString(val[25]);
|
|
valore.ImportoAvere = Convert.ToString(val[26]);
|
|
valore.CodiceTipoDatoRipartizione1 = Convert.ToString(val[27]);
|
|
valore.CodiceDatoRipartizione1 = Convert.ToString(val[28]);
|
|
valore.CodificaDellaRipartizione1 = Convert.ToString(val[29]);
|
|
valore.CodiceTipoDatoRipartizione2 = Convert.ToString(val[30]);
|
|
valore.CodiceDatoRipartizione2 = Convert.ToString(val[31]);
|
|
valore.CodificaDellaRipartizione2 = Convert.ToString(val[32]);
|
|
valore.CodiceTipoDatoRipartizione3 = Convert.ToString(val[33]);
|
|
valore.CodiceDatoRipartizione3 = Convert.ToString(val[34]);
|
|
valore.CodificaDellaRipartizione3 = Convert.ToString(val[35]);
|
|
valore.CodiceTipoDatoRipartizione4 = Convert.ToString(val[36]);
|
|
valore.CodiceDatoRipartizione4 = Convert.ToString(val[37]);
|
|
valore.CodificaDellaRipartizione4 = Convert.ToString(val[38]);
|
|
valore.CodiceTipoDatoRipartizione5 = Convert.ToString(val[39]);
|
|
valore.CodiceDatoRipartizione5 = Convert.ToString(val[40]);
|
|
valore.CodificaDellaRipartizione5 = Convert.ToString(val[41]);
|
|
valore.CodiceTipoDatoRipartizione6 = Convert.ToString(val[42]);
|
|
valore.CodiceDatoRipartizione6 = Convert.ToString(val[43]);
|
|
valore.CodificaDellaRipartizione6 = Convert.ToString(val[44]);
|
|
valore.CodiceTipoDatoRipartizione7 = Convert.ToString(val[45]);
|
|
valore.CodiceDatoRipartizione7 = Convert.ToString(val[46]);
|
|
valore.CodificaDellaRipartizione7 = Convert.ToString(val[47]);
|
|
valore.CodiceTipoDatoRipartizione8 = Convert.ToString(val[48]);
|
|
valore.CodiceDatoRipartizione8 = Convert.ToString(val[49]);
|
|
valore.CodificaDellaRipartizione8 = Convert.ToString(val[50]);
|
|
|
|
try
|
|
{
|
|
valore.IntCodiceDatoRipartizione4 = Convert.ToInt32(val[37]);
|
|
valore.intCodificaDellaRipartizione3 = Convert.ToInt32(val[35]);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
valore.IntCodiceDatoRipartizione4 = 0;
|
|
valore.intCodificaDellaRipartizione3 = 0;
|
|
}
|
|
|
|
//convertiti in decimal perchè con il double faceva casino con gli arrotondamenti
|
|
//e non funzionava il controllo della differenza dare/avere
|
|
valore.DoubleImportoDare = Convert.ToDecimal/*ToDouble*/(val[25]);
|
|
valore.DoubleImportoAvere = Convert.ToDecimal/*ToDouble*/(val[26]);
|
|
|
|
valore.DateDalMese = Convert.ToDateTime(val[2]);
|
|
|
|
return valore;
|
|
|
|
}
|
|
}
|
|
|
|
//classe per il file csv bil_sal_dtc_ott21
|
|
public class ValoriCSV
|
|
{
|
|
public string codiceAzienda;
|
|
public string denominazione;
|
|
public string dalMese;
|
|
public string dalTipoCedolino;
|
|
public string alMese;
|
|
public string alTipoCedolino;
|
|
public string regimeContabile;
|
|
public string progressivoRipartizione;
|
|
public string descrizioneProgressivoRipartizione;
|
|
public string contabilitaDiDestinazione;
|
|
public string descrizioneContabilitaDestinazione;
|
|
public string modalitaDiStampa;
|
|
public string codiceConto;
|
|
public string descrizioneConto;
|
|
public string importoDare;
|
|
public string importoAvere;
|
|
public string importoSaldo;
|
|
|
|
public static ValoriCSV FromCsv(string csvLine)
|
|
{
|
|
string[] val = csvLine.Split(';');
|
|
|
|
ValoriCSV valoreCsv = new ValoriCSV();
|
|
|
|
valoreCsv.codiceAzienda = Convert.ToString(val[0]);
|
|
valoreCsv.denominazione = Convert.ToString(val[1]);
|
|
valoreCsv.dalMese = Convert.ToString(val[2]);
|
|
valoreCsv.dalTipoCedolino = Convert.ToString(val[3]);
|
|
valoreCsv.alMese = Convert.ToString(val[4]);
|
|
valoreCsv.alTipoCedolino = Convert.ToString(val[5]);
|
|
valoreCsv.regimeContabile = Convert.ToString(val[6]);
|
|
valoreCsv.progressivoRipartizione = Convert.ToString(val[7]);
|
|
valoreCsv.descrizioneProgressivoRipartizione = Convert.ToString(val[8]);
|
|
valoreCsv.contabilitaDiDestinazione = Convert.ToString(val[9]);
|
|
valoreCsv.descrizioneContabilitaDestinazione = Convert.ToString(val[10]);
|
|
valoreCsv.modalitaDiStampa = Convert.ToString(val[11]);
|
|
valoreCsv.codiceConto = Convert.ToString(val[12]);
|
|
valoreCsv.descrizioneConto = Convert.ToString(val[13]);
|
|
valoreCsv.importoDare = Convert.ToString(val[14]);
|
|
valoreCsv.importoAvere = Convert.ToString(val[15]);
|
|
valoreCsv.importoSaldo = Convert.ToString(val[16]);
|
|
|
|
return valoreCsv;
|
|
}
|
|
}
|
|
|
|
public class Appoggio
|
|
{
|
|
public string codice { get; set; }
|
|
public int numFileXml { get; set; }
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|