using EFCDesk.Classes; using Microsoft.VisualBasic.ApplicationServices; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace EFCDesk.Forms { public partial class FormConfiguracionExpediente : Form { SQLiteHelper sqliteHelper = new SQLiteHelper(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "historico.db")); public FormConfiguracionExpediente() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private string convertir(double size) { try { string[] unit = new string[] { "B", "KB", "MB", "GB", "TB", "PB" }; double i = Math.Floor(Math.Log(size, 1024)); double y = Math.Pow(1024, i); double r = Math.Round(size / y); return r.ToString() + " " + unit[Convert.ToInt32(i)]; } catch (Exception e) { } return "0" + " " + "KB"; } //private void getCapacidad() //{ // var config = ConfiguracionJSON.LoadFromJson(); // string crypUser = General.CodificarBase64(config.UsuarioExp); // dynamic root = config.Consulta(config.DominioExp + "/api/getLicencia/" + crypUser); // if (root is XmlElement) // { // XmlNodeList nodes = root.SelectNodes("/xml/item"); // if (root.InnerText != "") // { // foreach (XmlNode node in nodes) // { // double u = Convert.ToDouble(node["usado"].InnerText); // double c = Convert.ToDouble(node["capacidad"].InnerText); // int porcentaje = 0; // if (c > 0) // { // porcentaje = Convert.ToInt32((u * 100) / c); // } // string usado = convertir(u); // string capacidad = convertir(c); // labelEspacioUsado.Text = porcentaje.ToString() + "% de " + capacidad + " usado"; // labelUsuario.Text = "Usuario: " + config.UsuarioExp; // } // } // } //} private void FormConfiguracionExpediente_Load(object sender, EventArgs e) { Globales.configJson = ConfiguracionJSON.LoadFromJson(); labelUsuario.Text = "Usuario: " + Globales.configJson.UsuarioExp ?? "No definido"; TabPage? tabOculta; tabOculta = tabControl1.TabPages["tabPage3"]; if (tabOculta != null) { tabControl1.TabPages.Remove(tabOculta); } var config = ConfiguracionExpediente.ObtenerDesdeBaseDeDatos(sqliteHelper); textBoxFolderExpediente.Text = config.FolderParaGenerarExpediente; if (config.DepurarExpediente) { checkBoxDepurarFolderExpediente.Checked = true; } textBoxFolderExpedienteDepuracion.Text = config.FolderParaDepurarExpediente; if (config.UsarEstructuraPedimentosWinsaai) { checkBoxPedimentosWinsaai.Checked = true; } if (config.UsarExpedienteLogistico) { checkBoxExpedienteLogistico.Checked = true; } textBoxServidorFTP.Text = config.ServidorFTP; textBoxUsuarioFTP.Text = config.UsuarioFTP; textBoxPasswordFTP.Text = config.PasswordFTP; textBoxPuertoFTP.Text = config.PuertoFTP.ToString(); if (config.ModoPasivoFTP) { checkBoxModoPasivoFTP.Checked = true; } // getCapacidad(); } private void button4_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxFolderExpediente.Text)) { MessageBox.Show("Favor de seleccionar una ruta para su expediente."); return; } var config = new ConfiguracionExpediente(); var configJson = new ConfiguracionJSON(); configJson.FolderExpediente = textBoxFolderExpediente.Text; config.FolderParaGenerarExpediente = textBoxFolderExpediente.Text; if (checkBoxDepurarFolderExpediente.Checked) { config.DepurarExpediente = true; } config.FolderParaDepurarExpediente = textBoxFolderExpedienteDepuracion.Text; if (checkBoxPedimentosWinsaai.Checked) { config.UsarEstructuraPedimentosWinsaai = true; configJson.ExpWinsaai = 1; Properties.Settings.Default.ExpWinsaai = 1; Properties.Settings.Default.Save(); } else { configJson.ExpWinsaai = 0; Properties.Settings.Default.ExpWinsaai = 0; Properties.Settings.Default.Save(); } if (checkBoxExpedienteLogistico.Checked) { config.UsarExpedienteLogistico = true; configJson.ExpWinsaai = 3; Properties.Settings.Default.ExpLogistico = 3; Properties.Settings.Default.Save(); } else { Properties.Settings.Default.ExpLogistico = 0; configJson.ExpWinsaai = 0; Properties.Settings.Default.Save(); } config.ServidorFTP = textBoxServidorFTP.Text; config.UsuarioFTP = textBoxUsuarioFTP.Text; config.PasswordFTP = textBoxPasswordFTP.Text; if (int.TryParse(textBoxPuertoFTP.Text, out int numero)) { config.PuertoFTP = numero; } config.ModoPasivoFTP = checkBoxModoPasivoFTP.Checked; config.GuardarEnBaseDeDatos(sqliteHelper); Properties.Settings.Default.urlEFC = txtDiminioEFC.Text; Properties.Settings.Default.Save(); configJson.DominioExp = txtDiminioEFC.Text.Trim(); configJson.SaveToJson(); Application.Restart(); } private void buttonCambiarFolderExpediente_Click(object sender, EventArgs e) { using (var fbd = new FolderBrowserDialog()) { DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { textBoxFolderExpediente.Text = fbd.SelectedPath.ToString(); } } } private void buttonCambiarFolderDepuracion_Click(object sender, EventArgs e) { using (var fbd = new FolderBrowserDialog()) { DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { textBoxFolderExpedienteDepuracion.Text = fbd.SelectedPath.ToString(); } } } private void textBoxServidorFTP_TextChanged(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { SecureDataHandler.DeleteData(); Application.Restart(); } private void button5_Click(object sender, EventArgs e) { this.Close(); } private void FormConfiguracionExpediente_Shown(object sender, EventArgs e) { var configJson = new ConfiguracionJSON(); configJson = ConfiguracionJSON.LoadFromJson(); string? urlEFC = configJson.DominioExp; txtDiminioEFC.Text = urlEFC; } } }