diff --git a/.vs/Final_OOP/DesignTimeBuild/.dtbcache.v2 b/.vs/Final_OOP/DesignTimeBuild/.dtbcache.v2 index 3194ca1..5493c2e 100644 Binary files a/.vs/Final_OOP/DesignTimeBuild/.dtbcache.v2 and b/.vs/Final_OOP/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/Final_OOP/v17/.futdcache.v2 b/.vs/Final_OOP/v17/.futdcache.v2 index 09e37f6..b8b85f8 100644 Binary files a/.vs/Final_OOP/v17/.futdcache.v2 and b/.vs/Final_OOP/v17/.futdcache.v2 differ diff --git a/Final_OOP.sln b/Final_OOP.sln index b8f8f5f..a81924f 100644 --- a/Final_OOP.sln +++ b/Final_OOP.sln @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.6.33829.357 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Controladora", "Controladora\Controladora.csproj", "{7168B549-F229-4D49-8C53-AF1CEB9BBB6B}" + ProjectSection(ProjectDependencies) = postProject + {6C83A4AB-C70D-4D4E-A879-5E960C4A103A} = {6C83A4AB-C70D-4D4E-A879-5E960C4A103A} + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entidades", "Entidades\Entidades.csproj", "{78A331E5-86D4-427E-AA45-5879F9E5E98B}" EndProject @@ -14,6 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vista", "Vista\Vista.csproj {7168B549-F229-4D49-8C53-AF1CEB9BBB6B} = {7168B549-F229-4D49-8C53-AF1CEB9BBB6B} EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Informes", "Informes\Informes.csproj", "{6C83A4AB-C70D-4D4E-A879-5E960C4A103A}" + ProjectSection(ProjectDependencies) = postProject + {78A331E5-86D4-427E-AA45-5879F9E5E98B} = {78A331E5-86D4-427E-AA45-5879F9E5E98B} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -36,6 +44,10 @@ Global {8C9E8090-5D8F-42AE-9813-C68D384C6863}.Debug|Any CPU.Build.0 = Debug|Any CPU {8C9E8090-5D8F-42AE-9813-C68D384C6863}.Release|Any CPU.ActiveCfg = Release|Any CPU {8C9E8090-5D8F-42AE-9813-C68D384C6863}.Release|Any CPU.Build.0 = Release|Any CPU + {6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6C83A4AB-C70D-4D4E-A879-5E960C4A103A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Informes/ConfigEmail.cs b/Informes/ConfigEmail.cs new file mode 100644 index 0000000..0b6e860 --- /dev/null +++ b/Informes/ConfigEmail.cs @@ -0,0 +1,10 @@ +namespace Informes +{ + public class ConfigEmail + { + public string EmailAddr { get; set; } + public string EmailPass { get; set; } + public List EmailTarget { get; set; } + + } +} \ No newline at end of file diff --git a/Informes/InformeEmail.cs b/Informes/InformeEmail.cs new file mode 100644 index 0000000..de6952d --- /dev/null +++ b/Informes/InformeEmail.cs @@ -0,0 +1,133 @@ +using System.Diagnostics; +using System.Net.Mail; +using System.Net; +using System.Text.Json; + +using Entidades; +namespace Informes +{ + public class InformeEmail + { + /// + /// Envia Informes por Email + /// + + private static InformeEmail instance = new(); + public static InformeEmail Instance + { + get { return instance; } + } + + public string EnviarEmailFactura(string titulo, List desc) + { + string? ret = null; + string json; + ConfigEmail config; + try + { // leemos el archivo de configuracion para obtener los certificados y mails destino de los informes + json = File.ReadAllText("settings.json"); + config = JsonSerializer.Deserialize(json); + + } + catch (IOException) + { + ret = "No se pudo leer el archivo \"settings.json\""; + throw; + } + + foreach (var i in config.EmailTarget) + { + if (String.IsNullOrWhiteSpace(i)) return "Hay Emails mal cargados"; + + } + + SmtpClient smtp = new SmtpClient(); + smtp.Host = "smtp.gmail.com"; + smtp.Port = 587; + smtp.Credentials = new NetworkCredential(config.EmailAddr, config.EmailPass); + smtp.DeliveryMethod = SmtpDeliveryMethod.Network; + smtp.EnableSsl = true; + + MailMessage mail = new MailMessage(); + mail.Subject = titulo; + mail.IsBodyHtml = true; + mail.Body = GenerarTabla(desc); + mail.Sender = new MailAddress(config.EmailAddr); + foreach (var i in config.EmailTarget) mail.To.Add(i); + mail.From = new MailAddress(config.EmailAddr); + + try + { + #if DEBUG + Console.WriteLine($"From: {config.EmailAddr}, Title: {titulo}"); + #endif + smtp.Send(mail); + mail.Dispose(); + } + catch (Exception) + { + ret = "No se pudo comunicar con el server SMTP"; + throw; + } + + //Decimos que se envio el email correctamente si el valor del retorno sigue siendo nulo en otro caso tendra la descripcion del error. + return (ret == null) ? + "Se envio el Email Correctamente": + ret; + // + } + + private string GenerarTabla(List desc) + { + // Esta seccion es el armado del mail html + string body = + @" + + + + "; + + foreach (var i in desc) + { + body += + @$" + + + + + + "; + } + + body += + @$" + + + + + + +
Producto + Cantidad + Precio CU + Subtotal +
{i.Producto.Nombre}{i.Cantidad}{i.Producto.Precio}{i.Producto.Precio * i.Cantidad}
Total{CalcularTotal(desc)}
+ "; + return body; + } + private double CalcularTotal(List desc) + { + double total = 0; + foreach (var i in desc) + { + total += i.Producto.Precio * i.Cantidad; + } + return total; + } + + } +} diff --git a/Informes/Informes.csproj b/Informes/Informes.csproj new file mode 100644 index 0000000..495dfff --- /dev/null +++ b/Informes/Informes.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Informes/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs b/Informes/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs new file mode 100644 index 0000000..ed92695 --- /dev/null +++ b/Informes/obj/Debug/net6.0/.NETCoreApp,Version=v6.0.AssemblyAttributes.cs @@ -0,0 +1,4 @@ +// +using System; +using System.Reflection; +[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] diff --git a/Informes/obj/Debug/net6.0/Informes.AssemblyInfoInputs.cache b/Informes/obj/Debug/net6.0/Informes.AssemblyInfoInputs.cache new file mode 100644 index 0000000..f8aafb3 --- /dev/null +++ b/Informes/obj/Debug/net6.0/Informes.AssemblyInfoInputs.cache @@ -0,0 +1 @@ +55f9793ce92bee586e65f5b38a3a7676261de34c diff --git a/Informes/obj/Debug/net6.0/Informes.GeneratedMSBuildEditorConfig.editorconfig b/Informes/obj/Debug/net6.0/Informes.GeneratedMSBuildEditorConfig.editorconfig new file mode 100644 index 0000000..cbe7f99 --- /dev/null +++ b/Informes/obj/Debug/net6.0/Informes.GeneratedMSBuildEditorConfig.editorconfig @@ -0,0 +1,11 @@ +is_global = true +build_property.TargetFramework = net6.0 +build_property.TargetPlatformMinVersion = +build_property.UsingMicrosoftNETSdkWeb = +build_property.ProjectTypeGuids = +build_property.InvariantGlobalization = +build_property.PlatformNeutralAssembly = +build_property.EnforceExtendedAnalyzerRules = +build_property._SupportedPlatformList = Linux,macOS,Windows +build_property.RootNamespace = Informes +build_property.ProjectDir = C:\Users\fedpo\Downloads\Final\Final\Informes\ diff --git a/Informes/obj/Debug/net6.0/Informes.GlobalUsings.g.cs b/Informes/obj/Debug/net6.0/Informes.GlobalUsings.g.cs new file mode 100644 index 0000000..8578f3d --- /dev/null +++ b/Informes/obj/Debug/net6.0/Informes.GlobalUsings.g.cs @@ -0,0 +1,8 @@ +// +global using global::System; +global using global::System.Collections.Generic; +global using global::System.IO; +global using global::System.Linq; +global using global::System.Net.Http; +global using global::System.Threading; +global using global::System.Threading.Tasks; diff --git a/Informes/obj/Debug/net6.0/Informes.assets.cache b/Informes/obj/Debug/net6.0/Informes.assets.cache new file mode 100644 index 0000000..102657e Binary files /dev/null and b/Informes/obj/Debug/net6.0/Informes.assets.cache differ diff --git a/Informes/obj/Debug/net6.0/Informes.csproj.AssemblyReference.cache b/Informes/obj/Debug/net6.0/Informes.csproj.AssemblyReference.cache new file mode 100644 index 0000000..6b73921 Binary files /dev/null and b/Informes/obj/Debug/net6.0/Informes.csproj.AssemblyReference.cache differ diff --git a/Informes/obj/Informes.csproj.nuget.dgspec.json b/Informes/obj/Informes.csproj.nuget.dgspec.json new file mode 100644 index 0000000..6fc7e54 --- /dev/null +++ b/Informes/obj/Informes.csproj.nuget.dgspec.json @@ -0,0 +1,124 @@ +{ + "format": 1, + "restore": { + "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj": {} + }, + "projects": { + "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj", + "projectName": "Entidades", + "projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj", + "packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\", + "outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\obj\\", + "projectStyle": "PackageReference", + "configFilePaths": [ + "C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net6.0" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {}, + "https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {} + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "projectReferences": {} + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json" + } + } + }, + "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj", + "projectName": "Informes", + "projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj", + "packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\", + "outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\obj\\", + "projectStyle": "PackageReference", + "configFilePaths": [ + "C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net6.0" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {}, + "https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {} + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "projectReferences": { + "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": { + "projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj" + } + } + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json" + } + } + } + } +} \ No newline at end of file diff --git a/Informes/obj/Informes.csproj.nuget.g.props b/Informes/obj/Informes.csproj.nuget.g.props new file mode 100644 index 0000000..89bfc77 --- /dev/null +++ b/Informes/obj/Informes.csproj.nuget.g.props @@ -0,0 +1,15 @@ + + + + True + NuGet + $(MSBuildThisFileDirectory)project.assets.json + $(UserProfile)\.nuget\packages\ + C:\Users\fedpo\.nuget\packages\ + PackageReference + 6.6.0 + + + + + \ No newline at end of file diff --git a/Informes/obj/Informes.csproj.nuget.g.targets b/Informes/obj/Informes.csproj.nuget.g.targets new file mode 100644 index 0000000..3dc06ef --- /dev/null +++ b/Informes/obj/Informes.csproj.nuget.g.targets @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Informes/obj/project.assets.json b/Informes/obj/project.assets.json new file mode 100644 index 0000000..bcbf1fc --- /dev/null +++ b/Informes/obj/project.assets.json @@ -0,0 +1,92 @@ +{ + "version": 3, + "targets": { + "net6.0": { + "Entidades/1.0.0": { + "type": "project", + "framework": ".NETCoreApp,Version=v6.0", + "compile": { + "bin/placeholder/Entidades.dll": {} + }, + "runtime": { + "bin/placeholder/Entidades.dll": {} + } + } + } + }, + "libraries": { + "Entidades/1.0.0": { + "type": "project", + "path": "../Entidades/Entidades.csproj", + "msbuildProject": "../Entidades/Entidades.csproj" + } + }, + "projectFileDependencyGroups": { + "net6.0": [ + "Entidades >= 1.0.0" + ] + }, + "packageFolders": { + "C:\\Users\\fedpo\\.nuget\\packages\\": {} + }, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj", + "projectName": "Informes", + "projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj", + "packagesPath": "C:\\Users\\fedpo\\.nuget\\packages\\", + "outputPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\obj\\", + "projectStyle": "PackageReference", + "configFilePaths": [ + "C:\\Users\\fedpo\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + ], + "originalTargetFrameworks": [ + "net6.0" + ], + "sources": { + "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, + "https://api.nuget.org/v3/index.json": {}, + "https://fedesrv.ddns.net/git/api/packages/fede/nuget/index.json": {} + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "projectReferences": { + "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj": { + "projectPath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Entidades\\Entidades.csproj" + } + } + } + }, + "warningProperties": { + "warnAsError": [ + "NU1605" + ] + } + }, + "frameworks": { + "net6.0": { + "targetAlias": "net6.0", + "imports": [ + "net461", + "net462", + "net47", + "net471", + "net472", + "net48", + "net481" + ], + "assetTargetFallback": true, + "warn": true, + "frameworkReferences": { + "Microsoft.NETCore.App": { + "privateAssets": "all" + } + }, + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\7.0.306\\RuntimeIdentifierGraph.json" + } + } + } +} \ No newline at end of file diff --git a/Informes/obj/project.nuget.cache b/Informes/obj/project.nuget.cache new file mode 100644 index 0000000..a5a3860 --- /dev/null +++ b/Informes/obj/project.nuget.cache @@ -0,0 +1,8 @@ +{ + "version": 2, + "dgSpecHash": "0ffqkIvM7yuJgCFn+/y+/ChgFN4B08rK4q2o0qfR2mjDbPa/G9BYCj14N+kvE/m1MgKnQvlnSGf4GAaYLGJr8w==", + "success": true, + "projectFilePath": "C:\\Users\\fedpo\\Downloads\\Final\\Final\\Informes\\Informes.csproj", + "expectedPackageFiles": [], + "logs": [] +} \ No newline at end of file