Exferia/Exferia_GestionDocumental/Test/Form1.cs

449 lines
21 KiB
C#

using Exferia_Aplicacion.General;
using Exferia_Aplicacion.ProgramaExterno;
using Exferia_Aplicacion.Visualizacion;
using Exferia_General;
using Exferia_GestionDocumental;
using Exferia_GestionDocumental._0_Modelos;
using Exferia_GestionDocumental._3_Vistas;
using Exferia_GestionDocumental.General;
using iTextSharp.text.pdf;
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Management;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace Test
{
public partial class Form1 : Form
{
private string g_str_RUTA = Variables.G_STR_LIBRERIA_RUTAINICIAL + @"\XML_DatosPrueba.xml";
private string g_str_idUsuario = "";
public Form1()
{
InitializeComponent();
if (!File.Exists(g_str_RUTA))
{
CrearXML();
}
else
{
Cargar_ValoresXML();
lbl_Servidor.Text = Variables.G_STR_CONEXION_SERVIDOR;
lbl_BaseDatos.Text = Variables.G_STR_CONEXION_BASEDATOS;
lbl_Perfil.Text = g_str_idUsuario;
}
Variables.G_STR_CONEXION_SERVIDOR_KAIROSPRO = "1.trialia.es,42158";
Variables.G_STR_CONEXION_BASEDATOS_KAIROSPRO = "KairosPro_pruebas";
Variables.G_STR_CONEXION_USUARIO_KAIROSPRO = "sa";
Variables.G_STR_CONEXION_CLAVE_KAIROSPRO = "SQL_Exferia";
//Asignar Colores de Exferia ..................................................................
Colores.G_COLOR_FONDO_BOTON = Color.Transparent;
Colores.G_COLOR_PRINCIPAL_BASE = ColorTranslator.FromHtml("#A19CC3");
Colores.G_COLOR_PRINCIPAL_OSCURO = ColorTranslator.FromHtml("#504888");
Colores.G_COLOR_PRINCIPAL_ATENUADO = ColorTranslator.FromHtml("#CBC8DF");
Colores.G_COLOR_PRINCIPAL_CLARO = ColorTranslator.FromHtml("#EDECF4");
Colores.G_COLOR_PRINCIPAL_TRASLUCIDO = Color.FromArgb(50, 191, 186, 225);
Colores.G_COLOR_SECUNDARIO_BASE = ColorTranslator.FromHtml("#FFF2C4");
Colores.G_COLOR_SECUNDARIO_CLARO = ColorTranslator.FromHtml("#FFF9E1");
Colores.G_COLOR_FONDO_BASE = ColorTranslator.FromHtml("#FFFFFF");
Colores.G_COLOR_TEXTO_ESCRITO = ColorTranslator.FromHtml("#000000");
Colores.G_COLOR_ATENCION = ColorTranslator.FromHtml("#c40909");
Colores.G_COLOR_FONDO_BARRAPROGRESO_RELLENA = ColorTranslator.FromHtml("#504888");
//Listados
Colores.G_COLOR_LISTADO_FILTROS = Color.FromArgb(50, 161, 156, 195);
Colores.G_COLOR_LISTADO_FILTROS_CONTROLESPERSONALIZADOS = Color.FromArgb(70, 161, 156, 195);
//Usuario Validado .......................................................
INTERNO_UsuarioValidado_Modelo mdl_INTERNO_UsuarioValidado_Modelo = new INTERNO_UsuarioValidado_Modelo();
mdl_INTERNO_UsuarioValidado_Modelo.id = long.Parse(g_str_idUsuario != "" ? g_str_idUsuario : "0");//410
mdl_INTERNO_UsuarioValidado_Modelo.idPerfil = null;
mdl_INTERNO_UsuarioValidado_Modelo.nombre = "admin";
mdl_INTERNO_UsuarioValidado_Modelo.sincronizacionAthos = false;
mdl_INTERNO_UsuarioValidado_Modelo.esSuperUsuario = false;
Variables.G_MDL_USUARIOVALIDADO_MODELO = mdl_INTERNO_UsuarioValidado_Modelo;
//Delegacion
Variables.G_DTT_FECHA_INICIAL_PORDEFECTO = new DateTime(2022, 08, 01);
Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO = null;
INTERNO_ValoresGenerales_Modelo mdl_INTERNO_ValoresGenerales_Modelo = Datos_Generales.GEN_ValoresGenerales_Obtener_Por_IdUsuario(Variables.G_MDL_USUARIOVALIDADO_MODELO.id);
if (mdl_INTERNO_ValoresGenerales_Modelo != null)
{
mdl_INTERNO_ValoresGenerales_Modelo = Datos_Generales.GEN_EjerciciosActivos_Empresa_Validar(mdl_INTERNO_ValoresGenerales_Modelo, Variables.G_DTT_FECHA_INICIAL_PORDEFECTO);
if (mdl_INTERNO_ValoresGenerales_Modelo != null)
{
Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO = mdl_INTERNO_ValoresGenerales_Modelo;
}
}
//Cargar XML Configuracion pantallas
Funciones_FicherosXML.CargarDatosXML_ConfiguracionPantallas();
Funciones.Rellenar_OpcionTablaCampoCodigo();
Datos_Generales.GEN_Configuracion_CampoCodigo_Rellenar_Listado();
//LISTADO DE RUTAS Cargamos el ensamblado #########################################################################################################################################################################
//Assembly m_assembly_1 = Assembly.LoadFrom(@"C:\Users\Exferia\Documents\Visual Studio 2015\Projects\DLL\" + Variables.G_STR_LIBRERIA_INFORMES + ".dll");
Assembly m_assembly_1 = Assembly.LoadFrom($@"..\..\..\..\..\DLL\{Variables.G_STR_LIBRERIA_INFORMES}.dll");
//Assembly m_assembly_1 = Assembly.LoadFrom(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + Variables.G_STR_LIBRERIA_INFORMES + ".dll");
//Obtenemos el tipo de la clase
Type m_type_1 = m_assembly_1.GetType("" + Variables.G_STR_LIBRERIA_INFORMES + "." + Variables.G_STR_LIBRERIA_DATOSINFORMES);
//creamos la instancia
var obj_Clase_1 = Activator.CreateInstance(m_type_1);
//Cargamos el metodo solicitado
MethodInfo obj_MethodInfo_1 = obj_Clase_1.GetType().GetMethod(Variables.G_STR_LIBRERIA_DATOSINFORMES_PROCEDIMIENTO_INFRUTAS_RELLENARLISTADO, BindingFlags.Instance | BindingFlags.NonPublic);
//Obtener valores
object[] arr_Parametros_1 = { };
obj_MethodInfo_1.Invoke(obj_Clase_1, arr_Parametros_1);
//##############################################################################################################################################################################################
Datos_Generales.PRV_OpcionesDetalle_Cargar();
Datos_Generales.PRV_Productos_Cargar();
Repintar.Empezar(this);
//Variable con el codigo del cliente de la ExferiaStore
Variables.G_LNG_IDCLIENTE_LICENCIAVALIDADO = 88;// 37;
Variables.G_SPL_PANTALLASPRINCIPAL = spl_Principal;
Variables.G_PNL_PANTALLASEMPOTRADAS = spl_Principal.Panel1;
Variables.G_PNL_PANTALLASEMPOTRADAS_SECUNDARIA = spl_Principal.Panel2;
Variables.G_EMS_CONTROL_MENUSUPERIOR = ex_msp_Menu;
Funciones_PanelSecundario.Rellenar_Listados_ArbolSecundarioSeleccion();
//calcular distancia del splitter
spl_Principal.SplitterDistance = this.Width / 2;
spl_Principal.Panel2Collapsed = true;
Datos_Generales.Permisos_Cargar();
Variables.G_BOL_CONEXION_SINCRONIZACIONCRM_ACTIVA = true;
#region Cargar Clave
//Cargamos el ensamblado
Assembly m_assembly = Assembly.LoadFrom(Variables.G_STR_LIBRERIA_RUTAINICIAL + @"\" + Variables.G_STR_LIBRERIA_GESTIONDOCUMENTAL + ".dll");
//Obtenemos el tipo de la clase
Type m_type = m_assembly.GetType(Variables.G_STR_LIBRERIA_GESTIONDOCUMENTAL + "." + Variables.G_STR_LIBRERIA_DATOSGESTIONDOCUMENTAL);
//creamos la instancia
var obj_Clase = Activator.CreateInstance(m_type);
//Cargamos el metodo solicitado
MethodInfo obj_MethodInfo = obj_Clase.GetType().GetMethod(Variables.G_STR_LIBRERIA_DATOSGESTIONDOCUMENTAL_PROCEDIMIENTO_GTDVALORESPORDEFECTO_CARGAR, BindingFlags.Instance | BindingFlags.NonPublic);
//Obtener valores
object[] arr_Parametros = {};
//Pasamos los parametros al metodo y lo ejecutamos
obj_MethodInfo.Invoke(obj_Clase, arr_Parametros);
#endregion
}
private void btn_Abrir_Listado_Click(object sender, EventArgs e)
{
string str_NombreLibreria = txt_Listado_Libreria.Text;
string str_Opcion = cbo_Listado_Opcion.Text;
//Cargamos el ensamblado
Assembly m_assembly = Assembly.LoadFrom(Variables.G_STR_LIBRERIA_RUTAINICIAL + @"\" + str_NombreLibreria + ".dll");
//Obtenemos el tipo de la clase
Type m_type = m_assembly.GetType(str_NombreLibreria + "." + Variables.G_STR_LIBRERIA_OPCIONES);
//creamos la instancia
var obj_Clase = Activator.CreateInstance(m_type);
//Cargamos el metodo solicitado
MethodInfo obj_MethodInfo = obj_Clase.GetType().GetMethod(Variables.G_STR_LIBRERIA_OPCIONES_PROCEDIMIENTO_CARGAR_LISTADO, BindingFlags.Instance | BindingFlags.NonPublic);
//Obtener valores
object[] arr_Parametros = { str_Opcion, false, 0, null, Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO, Variables.G_DTT_FECHA_INICIAL_PORDEFECTO, "", "", false, false, null, null, null, null, null,null };
//Pasamos los parametros al metodo y lo ejecutamos
obj_MethodInfo.Invoke(obj_Clase, arr_Parametros);
}
private void btn_Abrir_Mantenimiento_Click(object sender, EventArgs e)
{
string str_NombreLibreria = txt_Mantenimiento_Libreria.Text;
string str_Opcion = cbo_Mantenimiento_Opcion.Text;
INTERNO_OpcionesDetalle_Modelo mdl_INTERNO_OpcionesDetalle_Modelo = Datos_Generales.PRV_Opciones_Buscar_Detalles(str_Opcion);
//Cargamos el ensamblado
Assembly m_assembly = Assembly.LoadFrom(Variables.G_STR_LIBRERIA_RUTAINICIAL + @"\" + str_NombreLibreria + ".dll");
//Obtenemos el tipo de la clase
Type m_type = m_assembly.GetType(str_NombreLibreria + "." + Variables.G_STR_LIBRERIA_OPCIONES);
//creamos la instancia
var obj_Clase = Activator.CreateInstance(m_type);
//Cargamos el metodo solicitado
MethodInfo obj_MethodInfo = obj_Clase.GetType().GetMethod(Variables.G_STR_LIBRERIA_OPCIONES_PROCEDIMIENTO_MOSTRAR_EN_MANTENIMIENTO, BindingFlags.Instance | BindingFlags.NonPublic);
object[] arr_Parametros = { str_Opcion,
null,
null,
Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO,
Variables.G_DTT_FECHA_INICIAL_PORDEFECTO,
mdl_INTERNO_OpcionesDetalle_Modelo,
102638,
"",
"" ,
null,
null};
//Pasamos los parametros al metodo y lo ejecutamos
obj_MethodInfo.Invoke(obj_Clase, arr_Parametros);
}
private void btn_CodigoPrueba_Click(object sender, EventArgs e)
{
try
{
//Buscar datos del Fichero XML
INTERNO_DatosProgramaExternoRecibidos_Modelo mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo = Funciones_DatosProgramaExterno.Cargar_XML(@"C:\Pruebas\prueba\XML_LlamadaSigmaPlatform.xml");
if (mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo != null)
{
#region GTD
if (mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo.GTD != null)
{
//Consultas
if (mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo.GTD.Consultas != null &&
mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo.GTD.Consultas.Count > 0)
{
foreach (INTERNO_DatosProgramaExternoRecibidos_GTD_Consulta_Modelo mdl_INTERNO_DatosProgramaExternoRecibidos_GTD_Consulta_Modelo in mdl_INTERNO_DatosProgramaExternoRecibidos_Modelo.GTD.Consultas)
{
INTERNO_OpcionesDetalle_Modelo mdl_INTERNO_OpcionesDetalle_Modelo = Datos_Generales.PRV_Opciones_Buscar_Detalles(Variables.G_STR_OPCION_GTD_BUSCARDOCUMENTOS);
//Cargamos el ensamblado
Assembly m_assembly = Assembly.LoadFrom(Variables.G_STR_LIBRERIA_RUTAINICIAL + @"\" + Variables.G_STR_LIBRERIA_GESTIONDOCUMENTAL + ".dll");
//Obtenemos el tipo de la clase
Type m_type = m_assembly.GetType(Variables.G_STR_LIBRERIA_GESTIONDOCUMENTAL + "." + Variables.G_STR_LIBRERIA_OPCIONES);
//creamos la instancia
var obj_Clase = Activator.CreateInstance(m_type);
//Cargamos el metodo solicitado
MethodInfo obj_MethodInfo = obj_Clase.GetType().GetMethod(Variables.G_STR_LIBRERIA_OPCIONES_PROCEDIMIENTO_MOSTRAR_EN_MANTENIMIENTO, BindingFlags.Instance | BindingFlags.NonPublic);
object[] arr_Parametros = { mdl_INTERNO_OpcionesDetalle_Modelo.opcion,
null,
null,
Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO,
Variables.G_DTT_FECHA_INICIAL_PORDEFECTO,
mdl_INTERNO_OpcionesDetalle_Modelo,
-1,
"",
"" ,
mdl_INTERNO_DatosProgramaExternoRecibidos_GTD_Consulta_Modelo,
null};
//Pasamos los parametros al metodo y lo ejecutamos
obj_MethodInfo.Invoke(obj_Clase, arr_Parametros);
Thread.Sleep(500);
}
}
}
#endregion
}
//ExceltoPdf();
//INTERNO_OpcionesDetalle_Modelo mdl_INTERNO_OpcionesDetalle_Modelo = Datos_Generales.PRV_Opciones_Buscar_Detalles(Variables.G_STR_OPCION_COM_DEVOLUCIONPAGO);
// P_AlmacenarDocumentos frm = new P_AlmacenarDocumentos(Variables.G_MDL_INTERNO_VALORESGENERALES_MODELO, Variables.G_DTT_FECHA_INICIAL_PORDEFECTO, mdl_INTERNO_OpcionesDetalle_Modelo);
// frm.Show();
/* Datos_Maestros obj_Datos_Maestros = new Datos_Maestros();
obj_Datos_Maestros.Articulo_Obtener_EmbalajesPrecios(30517);*/
/* List<long> lst_cliente = new List<long>();
lst_cliente.Add(72497);
lst_cliente.Add(72499);
lst_cliente.Add(72503);
obj_Datos_Maestros.AgrupacionesLineas_ExistenRepetidos(Variables.G_STR_OPCION_MAE_AGRUPACIONCLIENTELINEA,null,33, lst_cliente);*/
/* MAE_Tesorerias_Datos obj_MAE_Tesorerias_Datos = new MAE_Tesorerias_Datos();
List<long> lst_ = new List<long>();
lst_.Add(190);
lst_.Add(191);
lst_.Add(215);
obj_MAE_Tesorerias_Datos.Obtener_ModeloListado_Por_Ids(lst_, true, true, true, true, true, true, true, true, true, true);*/
}
catch (Exception ex)
{
string g = ex.Message;
}
}
/*
public bool ExportWorkbookToPdf(string workbookPath, string outputPath)
{
// If either required string is null or empty, stop and bail out
if (string.IsNullOrEmpty(workbookPath) || string.IsNullOrEmpty(outputPath))
{
return false;
}
// Create COM Objects
Microsoft.Office.Interop.Excel.Application excelApplication;
Microsoft.Office.Interop.Excel.Workbook excelWorkbook;
// Create new instance of Excel
excelApplication = new Microsoft.Office.Interop.Excel.Application();
// Make the process invisible to the user
excelApplication.ScreenUpdating = false;
// Make the process silent
excelApplication.DisplayAlerts = false;
// Open the workbook that you wish to export to PDF
excelWorkbook = excelApplication.Workbooks.Open(workbookPath);
// If the workbook failed to open, stop, clean up, and bail out
if (excelWorkbook == null)
{
excelApplication.Quit();
excelApplication = null;
excelWorkbook = null;
return false;
}
var exportSuccessful = true;
try
{
// Call Excel's native export function (valid in Office 2007 and Office 2010, AFAIK)
excelWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, outputPath);
}
catch (System.Exception ex)
{
// Mark the export as failed for the return value...
exportSuccessful = false;
// Do something with any exceptions here, if you wish...
// MessageBox.Show...
}
finally
{
// Close the workbook, quit the Excel, and clean up regardless of the results...
excelWorkbook.Close();
excelApplication.Quit();
excelApplication = null;
excelWorkbook = null;
}
// You can use the following method to automatically open the PDF after export if you wish
// Make sure that the file actually exists first...
if (System.IO.File.Exists(outputPath))
{
System.Diagnostics.Process.Start(outputPath);
}
return exportSuccessful;
}*/
private void CrearXML()
{
FileStream fls_CrearFichero = null;
try
{
//Creamos el fichero
fls_CrearFichero = new FileStream(g_str_RUTA, FileMode.Create);
fls_CrearFichero.Close();
//Ahora crearemos la estructura del XML
XmlDocument Documento = new XmlDocument();
XmlNode xn_Declaration = Documento.CreateXmlDeclaration("1.0", "UTF-8", "yes");
Documento.AppendChild(xn_Declaration);
//Nodo Padre
XmlNode xn_NodoPrincipal = Documento.CreateElement("Datos");
Documento.AppendChild(xn_NodoPrincipal);
//Nodos Hijos
XmlNode xn_Servidor = Documento.CreateElement("servidor");
XmlNode xn_BaseDatos = Documento.CreateElement("basedatos");
XmlNode xn_Usuario = Documento.CreateElement("usuario");
XmlNode xn_Clave = Documento.CreateElement("clave");
XmlNode xn_Perfil = Documento.CreateElement("idusuario");
xn_NodoPrincipal.AppendChild(xn_Servidor);
xn_NodoPrincipal.AppendChild(xn_BaseDatos);
xn_NodoPrincipal.AppendChild(xn_Usuario);
xn_NodoPrincipal.AppendChild(xn_Clave);
xn_NodoPrincipal.AppendChild(xn_Perfil);
Documento.Save(g_str_RUTA);
AbrirPantallaConexion();
}
catch (Exception)
{
}
}
private void Cargar_ValoresXML()
{
XmlDocument Documento = new XmlDocument();
Documento.Load(g_str_RUTA);
//Nodo principal
XmlNode obj_NodoPadre = Documento.GetElementsByTagName("Datos")[0];
Variables.G_STR_CONEXION_SERVIDOR = obj_NodoPadre["servidor"].InnerText;
Variables.G_STR_CONEXION_BASEDATOS = obj_NodoPadre["basedatos"].InnerText;
Variables.G_STR_CONEXION_USUARIO = obj_NodoPadre["usuario"].InnerText;
Variables.G_STR_CONEXION_CLAVE = obj_NodoPadre["clave"].InnerText;
g_str_idUsuario = obj_NodoPadre["idusuario"].InnerText;
if (Variables.G_STR_CONEXION_SERVIDOR.Equals("") || g_str_idUsuario.Equals(""))
{
AbrirPantallaConexion();
}
}
private void btn_CambiarConexion_Click(object sender, EventArgs e)
{
AbrirPantallaConexion();
}
private void AbrirPantallaConexion()
{
Form2 frm_Conexion = new Form2(Variables.G_STR_CONEXION_SERVIDOR, Variables.G_STR_CONEXION_BASEDATOS, Variables.G_STR_CONEXION_USUARIO, Variables.G_STR_CONEXION_CLAVE, g_str_idUsuario);
frm_Conexion.StartPosition = FormStartPosition.CenterParent;
frm_Conexion.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}