From c3f4165e7ea727db67f969ba2d8f458ea87963f1 Mon Sep 17 00:00:00 2001 From: michele Date: Thu, 31 Oct 2024 12:03:18 +0100 Subject: [PATCH] clonazione repository --- .gitattributes | 63 ++ .gitignore | 340 +++++++++++ App.config | 6 + CSVToXML_DEKRA.csproj | 83 +++ CSVToXML_DEKRA.sln | 25 + Program.cs | 22 + frmCSVToXML.Designer.cs | 187 ++++++ frmCSVToXML.cs | 1261 +++++++++++++++++++++++++++++++++++++++ frmCSVToXML.resx | 123 ++++ 9 files changed, 2110 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 App.config create mode 100644 CSVToXML_DEKRA.csproj create mode 100644 CSVToXML_DEKRA.sln create mode 100644 Program.cs create mode 100644 frmCSVToXML.Designer.cs create mode 100644 frmCSVToXML.cs create mode 100644 frmCSVToXML.resx diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ce6fdd --- /dev/null +++ b/.gitignore @@ -0,0 +1,340 @@ +## 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 + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# 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 + +# 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/ + +# 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 + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# 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 +# 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 + +# 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 +*- Backup*.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/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# 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 \ No newline at end of file diff --git a/App.config b/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CSVToXML_DEKRA.csproj b/CSVToXML_DEKRA.csproj new file mode 100644 index 0000000..a9d3485 --- /dev/null +++ b/CSVToXML_DEKRA.csproj @@ -0,0 +1,83 @@ + + + + + Debug + AnyCPU + {A4667921-71E9-4050-9744-6DB88844C01C} + WinExe + CSVToXML + CSVToXML + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + frmCSVToXML.cs + + + + + frmCSVToXML.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/CSVToXML_DEKRA.sln b/CSVToXML_DEKRA.sln new file mode 100644 index 0000000..96ff843 --- /dev/null +++ b/CSVToXML_DEKRA.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29519.87 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSVToXML_DEKRA", "CSVToXML_DEKRA.csproj", "{A4667921-71E9-4050-9744-6DB88844C01C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A4667921-71E9-4050-9744-6DB88844C01C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4667921-71E9-4050-9744-6DB88844C01C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4667921-71E9-4050-9744-6DB88844C01C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4667921-71E9-4050-9744-6DB88844C01C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4D7CFBB0-D9BA-437D-9D4E-2633ECDC5713} + EndGlobalSection +EndGlobal diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..8cef12b --- /dev/null +++ b/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CSVToXML +{ + static class Program + { + /// + /// Punto di ingresso principale dell'applicazione. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new frmCSVToXML()); + } + } +} diff --git a/frmCSVToXML.Designer.cs b/frmCSVToXML.Designer.cs new file mode 100644 index 0000000..c6af3e9 --- /dev/null +++ b/frmCSVToXML.Designer.cs @@ -0,0 +1,187 @@ +namespace CSVToXML +{ + partial class frmCSVToXML + { + /// + /// Variabile di progettazione necessaria. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Pulire le risorse in uso. + /// + /// ha valore true se le risorse gestite devono essere eliminate, false in caso contrario. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Codice generato da Progettazione Windows Form + + /// + /// Metodo necessario per il supporto della finestra di progettazione. Non modificare + /// il contenuto del metodo con l'editor di codice. + /// + private void InitializeComponent() + { + this.txtArea = new System.Windows.Forms.TextBox(); + this.lblCSV = new System.Windows.Forms.Label(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.txtFile = new System.Windows.Forms.TextBox(); + this.btnCercaFile = new System.Windows.Forms.Button(); + this.btnConverti = new System.Windows.Forms.Button(); + this.lblCodAzi = new System.Windows.Forms.Label(); + this.lblData = new System.Windows.Forms.Label(); + this.txtCodAzi = new System.Windows.Forms.TextBox(); + this.dtpAnnoMese = new System.Windows.Forms.DateTimePicker(); + this.btnXmlInv = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // txtArea + // + this.txtArea.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.txtArea.Location = new System.Drawing.Point(17, 181); + this.txtArea.Multiline = true; + this.txtArea.Name = "txtArea"; + this.txtArea.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.txtArea.Size = new System.Drawing.Size(604, 324); + this.txtArea.TabIndex = 7; + // + // lblCSV + // + this.lblCSV.AutoSize = true; + this.lblCSV.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblCSV.Location = new System.Drawing.Point(15, 91); + this.lblCSV.Name = "lblCSV"; + this.lblCSV.Size = new System.Drawing.Size(124, 15); + this.lblCSV.TabIndex = 1; + this.lblCSV.Text = "File CSV da convertire:"; + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + this.openFileDialog1.InitialDirectory = "@\"C:\\\""; + this.openFileDialog1.RestoreDirectory = true; + // + // txtFile + // + this.txtFile.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.txtFile.Location = new System.Drawing.Point(17, 109); + this.txtFile.Name = "txtFile"; + this.txtFile.Size = new System.Drawing.Size(516, 23); + this.txtFile.TabIndex = 3; + // + // btnCercaFile + // + this.btnCercaFile.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnCercaFile.Location = new System.Drawing.Point(540, 109); + this.btnCercaFile.Name = "btnCercaFile"; + this.btnCercaFile.Size = new System.Drawing.Size(82, 23); + this.btnCercaFile.TabIndex = 4; + this.btnCercaFile.Text = "Cerca"; + this.btnCercaFile.UseVisualStyleBackColor = true; + this.btnCercaFile.Click += new System.EventHandler(this.btnCercaFile_Click); + // + // btnConverti + // + this.btnConverti.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnConverti.Location = new System.Drawing.Point(18, 148); + this.btnConverti.Name = "btnConverti"; + this.btnConverti.Size = new System.Drawing.Size(79, 27); + this.btnConverti.TabIndex = 5; + this.btnConverti.Text = "Genera XML"; + this.btnConverti.UseVisualStyleBackColor = true; + this.btnConverti.Click += new System.EventHandler(this.btnConverti_Click); + // + // lblCodAzi + // + this.lblCodAzi.AutoSize = true; + this.lblCodAzi.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblCodAzi.Location = new System.Drawing.Point(15, 15); + this.lblCodAzi.Name = "lblCodAzi"; + this.lblCodAzi.Size = new System.Drawing.Size(92, 15); + this.lblCodAzi.TabIndex = 6; + this.lblCodAzi.Text = "Codice Azienda:"; + // + // lblData + // + this.lblData.AutoSize = true; + this.lblData.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblData.Location = new System.Drawing.Point(15, 57); + this.lblData.Name = "lblData"; + this.lblData.Size = new System.Drawing.Size(75, 15); + this.lblData.TabIndex = 7; + this.lblData.Text = "Data calcolo:"; + // + // txtCodAzi + // + this.txtCodAzi.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.txtCodAzi.Location = new System.Drawing.Point(113, 12); + this.txtCodAzi.MaxLength = 4; + this.txtCodAzi.Name = "txtCodAzi"; + this.txtCodAzi.Size = new System.Drawing.Size(98, 23); + this.txtCodAzi.TabIndex = 1; + this.txtCodAzi.Leave += new System.EventHandler(this.txtCodAzi_Leave); + // + // dtpAnnoMese + // + this.dtpAnnoMese.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.dtpAnnoMese.Location = new System.Drawing.Point(113, 53); + this.dtpAnnoMese.Name = "dtpAnnoMese"; + this.dtpAnnoMese.Size = new System.Drawing.Size(194, 23); + this.dtpAnnoMese.TabIndex = 2; + // + // btnXmlInv + // + this.btnXmlInv.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btnXmlInv.Location = new System.Drawing.Point(103, 148); + this.btnXmlInv.Name = "btnXmlInv"; + this.btnXmlInv.Size = new System.Drawing.Size(84, 27); + this.btnXmlInv.TabIndex = 6; + this.btnXmlInv.Text = "XML Inv."; + this.btnXmlInv.UseVisualStyleBackColor = true; + this.btnXmlInv.Click += new System.EventHandler(this.btnXmlInv_Click); + // + // frmCSVToXML + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(633, 517); + this.Controls.Add(this.btnXmlInv); + this.Controls.Add(this.dtpAnnoMese); + this.Controls.Add(this.txtCodAzi); + this.Controls.Add(this.lblData); + this.Controls.Add(this.lblCodAzi); + this.Controls.Add(this.btnConverti); + this.Controls.Add(this.btnCercaFile); + this.Controls.Add(this.txtFile); + this.Controls.Add(this.lblCSV); + this.Controls.Add(this.txtArea); + this.Name = "frmCSVToXML"; + this.ShowIcon = false; + this.Text = "Converti da CSV a XML"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.TextBox txtArea; + private System.Windows.Forms.Label lblCSV; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.TextBox txtFile; + private System.Windows.Forms.Button btnCercaFile; + private System.Windows.Forms.Button btnConverti; + private System.Windows.Forms.Label lblCodAzi; + private System.Windows.Forms.Label lblData; + private System.Windows.Forms.TextBox txtCodAzi; + private System.Windows.Forms.DateTimePicker dtpAnnoMese; + private System.Windows.Forms.Button btnXmlInv; + } +} + diff --git a/frmCSVToXML.cs b/frmCSVToXML.cs new file mode 100644 index 0000000..3070e7b --- /dev/null +++ b/frmCSVToXML.cs @@ -0,0 +1,1261 @@ +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 CreaOggettiPerConversioni() + { + List listPartenza = new List(); + + List listaOrdinata = new List(); + + //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 NumeroFileXMLDaProdurre(List listaRigheCsv) + { + StringBuilder sb = new StringBuilder(); + + List appoggio = new List(); + + 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 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(); + var numberXml = 1; + var path = string.Empty; + var pathCompleto = string.Empty; + //questo sarà il contenuto del tag xml + //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(); + 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(); + 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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append($""); + + stringCONT.Append(""); + stringCONT.Append(""); + + 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(""); + stringDATA.Append(""); + + 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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append($""); + + //txtArea.Text += Environment.NewLine + //+ $"Finito {numberXml}"; + numberXml++; + + //FILE CONT + stringCONT.Append(""); + stringCONT.Append($"{1/*recordcount*/}"); + stringCONT.Append(""); + stringCONT.Append(""); + 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(""); + stringCONT.Append(""); + } + + //possibile soluzione + //recordcount += listaFiltrata.Count(); + + foreach (var item in listaFiltrata) + { + //UTILIZZATO SOLO PER VEDERE CHE DATO RIPARTIZIONE FOSSE (NON SERVE) + //myStringbuilder.Append(""); + //myStringbuilder.Append($"{app.codice}"); + //myStringbuilder.Append(""); + + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append("S"); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + + if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0) + { + stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}"); + } + else + { + stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}"); + } + + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + } + } + + stringDATA.Append(""); + stringDATA.Append(""); + 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(""); + //30/05/2022 pare che questo sia un dato fisso a 1 + stringCONT.Append($"{1/*recordcount*/}"); + stringCONT.Append(""); + stringCONT.Append(""); + 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 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(); + var numberXml = 1; + var path = string.Empty; + var pathCompleto = string.Empty; + + //questo sarà il contenuto del tag xml + //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(); + 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(); + 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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append($""); + + stringCONT.Append(""); + stringCONT.Append(""); + + 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(""); + stringDATA.Append(""); + + 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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append($""); + + numberXml++; + + //FILE CONT + stringCONT.Append(""); + stringCONT.Append($"{1/*recordcount*/}"); + stringCONT.Append(""); + stringCONT.Append(""); + 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(""); + stringCONT.Append(""); + } + + //possibile soluzione + //recordcount += listaFiltrata.Count(); + + foreach (var item in listaFiltrata) + { + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append("S"); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + if (Convert.ToDecimal(item.ImportoDare.Replace(",", ".")) > 0) + { + stringDATA.Append($"{item.ImportoDare.Replace(",", ".")}"); + } + else + { + stringDATA.Append($"{item.ImportoAvere.Replace(",", ".")}"); + } + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + //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(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + stringDATA.Append(""); + } + } + + stringDATA.Append(""); + stringDATA.Append(""); + 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(""); + //30/05/2022 pare che questo sia un dato fisso a 1 + stringCONT.Append($"{1/*recordcount*/}"); + stringCONT.Append(""); + stringCONT.Append(""); + 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 + +} diff --git a/frmCSVToXML.resx b/frmCSVToXML.resx new file mode 100644 index 0000000..9bad2f5 --- /dev/null +++ b/frmCSVToXML.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file