Skip to content

Commit

Permalink
Fix load configuration from json file
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Sep 29, 2017
1 parent a752992 commit b52661f
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 13 deletions.
42 changes: 34 additions & 8 deletions Homologador/ConfigurationForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void ConfigurationForm_Load(object sender, EventArgs e)

private void btnCertificate_Click(object sender, EventArgs e)
{
var open = new OpenFileDialog {Filter = @"Pfx Files (*.pfx)|*.pfx"};
var open = new OpenFileDialog {Filter = Resources.SettingFilterFilesPfx};
if (open.ShowDialog() != DialogResult.OK)
return;

Expand Down Expand Up @@ -85,12 +85,12 @@ private bool ValidarCredenciales()
try
{
if (RucAuth.Validate(txtRuc.Text, txtUser.Text, txtClave.Text)) return true;
MetroMessageBox.Show(this, "Credenciales invalidas", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MetroMessageBox.Show(this, "Credenciales invalidas", Resources.SettingTitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
txtRuc.Focus();
}
catch (Exception e)
{
MetroMessageBox.Show(this, e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MetroMessageBox.Show(this, e.Message, Resources.SettingTitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return false;
}
Expand All @@ -107,7 +107,29 @@ private void btnLoadConfig_Click(object sender, EventArgs e)
return;
}

var jsonText = File.ReadAllText(dialog.FileName);
try
{
LoadConfig(dialog.FileName);
MetroMessageBox.Show(this,
Resources.SettingMsgLoadSuccess,
Resources.SettingTitleSucces,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
catch (Exception)
{
MetroMessageBox.Show(this,
Resources.SettingMsgLoadError,
Resources.SettingTitleError,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}


private void LoadConfig(string filename)
{
var jsonText = File.ReadAllText(filename);
dynamic obj = JObject.Parse(jsonText);

txtRuc.Text = obj.Ruc;
Expand All @@ -123,9 +145,9 @@ private void btnLoadConfig_Click(object sender, EventArgs e)
txtClave.Text = obj.Clave;
txtClaveCert.Text = obj.ClaveCert;
chkProveedor.Checked = obj.EsProveedor;
if (!string.IsNullOrEmpty(obj.Certificado))
if (!string.IsNullOrEmpty((string)obj.Certificado))
{
txtPathCertify.Tag = obj.Certificado;
txtPathCertify.Tag = obj.Certificado.ToString();
txtPathCertify.Text = @"Certificado Cargado";
}
}
Expand All @@ -135,7 +157,7 @@ private void btnSaveConfig_Click(object sender, EventArgs e)
var dialog = new SaveFileDialog
{
Filter = Resources.FileFilterJson,
FileName = "homologador_settings.json"
FileName = Resources.SettingFilenamDefault
};

if (dialog.ShowDialog() != DialogResult.OK)
Expand Down Expand Up @@ -169,7 +191,11 @@ private void btnSaveConfig_Click(object sender, EventArgs e)
}

File.WriteAllText(dialog.FileName, obj.ToString());
MetroMessageBox.Show(this, "Configuracion Guardada", "Exito", MessageBoxButtons.OK, MessageBoxIcon.Information);
MetroMessageBox.Show(this,
Resources.SettingMsgSaved,
Resources.SettingTitleSucces,
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
}
1 change: 1 addition & 0 deletions Homologador/Homologador.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="Compartir-50.ico" />
<None Include="Resources\github.png" />
<None Include="Resources\Sincronizar.png" />
<None Include="Resources\ajustes.png" />
<None Include="Resources\play.png" />
Expand Down
18 changes: 18 additions & 0 deletions Homologador/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Homologador/MainForm.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -513,6 +514,11 @@ private void btnSync_Click(object sender, EventArgs e)
Init();
}

private void pictGithub_Click(object sender, EventArgs e)
{
Process.Start(Resources.GibhubLinkProject);
}

#region Notas

private async void menuNota_Click(object sender, EventArgs e)
Expand Down
82 changes: 82 additions & 0 deletions Homologador/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 32 additions & 5 deletions Homologador/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,47 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Factura50" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Factura50.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="SettingFilenamDefault" xml:space="preserve">
<value>homologador_settings.json</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="play" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\play.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ajustes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ajustes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="SettingFilterFilesPfx" xml:space="preserve">
<value>Pfx Files (*.pfx)|*.pfx</value>
</data>
<data name="SettingTitleError" xml:space="preserve">
<value>Error</value>
</data>
<data name="SettingMsgLoadSuccess" xml:space="preserve">
<value>Configuración Cargada</value>
</data>
<data name="SettingMsgSaved" xml:space="preserve">
<value>Configuracion Guardada</value>
</data>
<data name="SettingTitleSucces" xml:space="preserve">
<value>Exito</value>
</data>
<data name="Sincronizar" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Sincronizar.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Factura50" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Factura50.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="FileFilterJson" xml:space="preserve">
<value>Json Files (*.json)|*.json|All Files (*.*)|*.*</value>
</data>
<data name="ajustes" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ajustes.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="SettingMsgLoadError" xml:space="preserve">
<value>No se pudo cargar la configuracion</value>
</data>
<data name="github" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\github.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="GibhubLinkProject" xml:space="preserve">
<value>https://github.com/giansalex/homologadorSunat</value>
</data>
</root>
Binary file added Homologador/Resources/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Third/formulario.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b52661f

Please sign in to comment.