Exferia/Exferia_Formularios/Exferia_Formularios/P_Base.cs

550 lines
20 KiB
C#

using Exferia_Aplicacion.General;
using Exferia_Aplicacion.Modelos_Listado_Filtros;
using Exferia_Controles;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Exferia_Aplicacion.General.Enumerados;
namespace Exferia_Formularios
{
public partial class P_Base : Form
{
#region Librerias Externas
[DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
#endregion
//Variables para saber en todo momento la pantalla con que empresa seleccionada se abrio y que fecha de trabajo .....................................
public INTERNO_ValoresGenerales_Modelo P_Base_ValoresGenerales
{
set;
get;
}
public DateTime P_Base_FechaTrabajo
{
set;
get;
}
//Propiedad que se Utiliza para si se desea Guardar la captura de la pantalla o no ..................................................................
public bool P_Base_GuardarCaptura
{
set;
get;
}
//Propiedad para mostrar o no el boton de cerrar .................................................................................................
private bool g_bol_MostrarBotonCerrar = true;
public bool P_Base_MostrarBotonCerrar
{
set
{
g_bol_MostrarBotonCerrar = value;
btn_Salir.Visible = g_bol_MostrarBotonCerrar;
Invalidate();
}
get
{
return g_bol_MostrarBotonCerrar;
}
}
//Propiedad que define el color del titulo y los bordes dde la pantalla ...........................................................................
public Color P_Base_ColorTituloyBordes
{
set
{
lbl_Titulo.BackColor = value;
pnl_Titulo.BackColor = value;
}
get
{
return lbl_Titulo.BackColor;
}
}
//Propiedad que define el color inicial del fondo para el degradado ................................................................................
private Color g_clr_ColorFondo_Inicial = Color.White;
public Color P_Base_ColorFondo_Inicial
{
set
{
g_clr_ColorFondo_Inicial = value;
}
get
{
return g_clr_ColorFondo_Inicial;
}
}
//Propiedad que define el color final del fondo para el degradado ................................................................................
private Color g_clr_ColorFondo_Final = Color.White;
public Color P_Base_ColorFondo_Final
{
set
{
g_clr_ColorFondo_Final = value;
}
get
{
return g_clr_ColorFondo_Final;
}
}
//Propiedad que se pasa al resto de las pantallas para poder tener el total del listado sin Filtrar ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Listado
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder tener el total del listado sin Filtrar ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Listado_AUX1
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder tener el total del listado sin Filtrar ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Listado_AUX2
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder hacer los filtros ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Filtrados
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder hacer los filtros ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Filtrados_AUX1
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder hacer los filtros ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Filtrados_AUX2
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder hacer los filtros ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Filtrados_AUX3
{
get;
set;
}
//Propiedad que se pasa al resto de las pantallas para poder hacer los filtros ..............................
public List<INTERNO_Listado_CamposClave_Modelo> P_Base_Objetos_Filtrados_AUX4
{
get;
set;
}
//Propiedades para almacenar el id de un registro ............................................................
public long P_Base_id
{
get;
set;
}
public long P_Base_idAuxiliar { get; set; }
public long P_Base_idAuxiliar2 { get; set; }
public string P_Base_Campo_1 { get; set; }
public string P_Base_Campo_2 { get; set; }
//propiedad que defeine el Tipo de pantalla -1-> Listado ,0-> Añadir , 1-> Modificar .......................................
private int g_int_TipoApertura = -1;
public int P_Base_TipoAperturaPantalla
{
get
{
return g_int_TipoApertura;
}
set
{
g_int_TipoApertura = value;
}
}
//Propiedad que define el Titulo de la pantalla
public string P_Base_TituloPantalla
{
set
{
lbl_Titulo.Text = value;
}
get
{
return lbl_Titulo.Text;
}
}
public string P_Base_CamposMostrarTituloMantenimiento { get; set; }
private string g_str_TituloPantalla_CaminoHormigas = "";
public string P_Base_TituloPantalla_CaminoHormigas
{
set
{
g_str_TituloPantalla_CaminoHormigas = value;
}
get
{
return g_str_TituloPantalla_CaminoHormigas;
}
}
//Propiedad para saber COntrol de origen .....................................................
public Exferia_F3 P_Base_F3Origen { get; set; }
//Propiedad para saber pantalla de origen .....................................................
public P_Base P_Base_PantallaOrigen { get; set; }
public string P_Base_PantallaPadre_Nombre { get; set; }
public string P_Base_PantallaPadre_IdentificadorTAG { get; set; }
public long P_Base_PantallaPadre_id { get; set; }
//Propiedades de Control para saber si se modifico algo ........................................
private bool bol_SeModificoDatosPantalla = false;
public bool P_Base_SeModificoDatosPantalla
{
get
{
return bol_SeModificoDatosPantalla;
}
set
{
if (!P_Base_EstadoDocumento.Equals(Variables.G_STR_ESTADO_CONTABILIDAD_CERRADO) &&
!P_Base_EstadoDocumento.Equals(Variables.G_STR_ESTADO_CONTABILIDAD_VOLCADO))
{
bol_SeModificoDatosPantalla = value;
}
}
}
//Propiedades de Control para saber si esta cerrado el documento
private string str_EstadoDocumento = Variables.G_STR_ESTADO_CONTABILIDAD_ABIERTO;
public string P_Base_EstadoDocumento
{
get
{
return str_EstadoDocumento;
}
set
{
str_EstadoDocumento = value;
}
}
//Propiedades de Control para poeder mostrar una advertencia antes de cerrar ........................................
private bool bol_MensajeAdvertenciaError_SeguirEjecutandose = true;
public bool P_Base_MensajeAdvertenciaError_SeguirEjecutandose
{
get
{
return bol_MensajeAdvertenciaError_SeguirEjecutandose;
}
set
{
bol_MensajeAdvertenciaError_SeguirEjecutandose = value;
}
}
#region Constructores
public P_Base()
{
g_bol_HabilitarSombra = false;
FormBorderStyle = FormBorderStyle.None;
InitializeComponent();
//No bloqueables o que no se pueden poner en solo lectura
btn_Salir.Exferia_Button_Bloqueable = false;
ex_btn_Salir.Exferia_Button_Bloqueable = false;
}
#endregion
#region Procedimientos Virtuales para heredar desde la pantalla que hereda esta
/// <summary>
/// Funcion que actualiza el listado con el registro recogido
/// </summary>
/// <param name="_lng_id"></param>
/// <param name="_enum_TipoAccion"></param>
public virtual void P_Base_ActualizarRegistro(long _lng_id, G_ENUM_TIPOACCION _enum_TipoAccion)
{}
public virtual void P_Base_ActualizarRegistro(List<long> _lst_id, G_ENUM_TIPOACCION _enum_TipoAccion)
{ }
public virtual void P_Base_ActualizarRegistros_Campo(List<INTERNO_ActualizarCampoListadoGeneral_Modelo> _lst_CamposActualizar, G_ENUM_TIPOACCION _enum_TipoAccion)
{ }
public virtual void P_Base_ActualizarRegistro_ConObjeto(object _obj, G_ENUM_TIPOACCION _enum_TipoAccion)
{ }
public virtual void P_Base_ActualizarRegistro(long _lng_id, G_ENUM_TIPOACCION _enum_TipoAccion,string _str_Opcion)
{ }
public virtual void P_Base_RecargarListado()
{ }
public virtual void P_Base_EjecutarFuncion(int _int_Tipo)
{ }
#endregion
#region Control Grafico de la Pantalla
protected override void WndProc(ref Message m)
{
//Sombra de la pantalla ..................................................
if (m.Msg == WM_NCPAINT)// box shadow
{
if (g_bol_HabilitarSombra)
{
var v = 2;
DwmSetWindowAttribute(Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 1,
rightWidth = 1,
topHeight = 1
};
DwmExtendFrameIntoClientArea(Handle, ref margins);
}
}
base.WndProc(ref m);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
if (ClientRectangle.Height != 0 || ClientRectangle.Width != 0)
{
var brush = new LinearGradientBrush(ClientRectangle, P_Base_ColorFondo_Inicial, P_Base_ColorFondo_Final, 90F);
e.Graphics.FillRectangle(brush, ClientRectangle);
}
}
private void P_Base_Resize(object sender, EventArgs e)
{
pnl_Titulo.Size = new Size(Width - 4, pnl_Titulo.Height);
//Botones
btn_Salir.Location = new Point(Size.Width - 45, btn_Salir.Location.Y);
ex_btn_Salir.Location = new Point(Size.Width - 43, Size.Height - 48);
}
#endregion
#region Crear Sombra de la pantalla
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
private bool g_bol_HabilitarSombra; // variables for box shadow
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVATEAPP = 0x001C;
public struct MARGINS // struct for box shadow
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
private const int WM_NCHITTEST = 0x84; // variables for dragging the form
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override CreateParams CreateParams
{
get
{
g_bol_HabilitarSombra = CheckAeroEnabled();
CreateParams cp = base.CreateParams;
if (!g_bol_HabilitarSombra)
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0;
DwmIsCompositionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
#endregion
#region Boton y Funciones de Salir
public event EventHandler P_Base_Evento_ClickSalir;
public event EventHandler P_Base_Evento_AntesSalir;
private void btn_Salir_Click(object sender, EventArgs e)
{
Salir_P_Base_EjecutandoEvento();
}
private void ex_btn_Salir_Click(object sender, EventArgs e)
{
Salir_P_Base_EjecutandoEvento();
}
public void Salir_P_Base_EjecutandoEvento()
{
P_Base_Evento_AntesSalir?.Invoke(this, null);
if (bol_MensajeAdvertenciaError_SeguirEjecutandose)
{
if (P_Base_SeModificoDatosPantalla)
{
if (Mensajes.MostrarMensaje_Pregunta(Mensajes.G_STR_MENSAJES_GENERAL_SALIR()))
{
P_Base_Evento_ClickSalir?.Invoke(this, null);
Close();
}
}
else
{
P_Base_Evento_ClickSalir?.Invoke(this, null);
Close();
}
}
}
public void Salir_P_Base()
{
if (P_Base_SeModificoDatosPantalla)
{
if (Mensajes.MostrarMensaje_Pregunta(Mensajes.G_STR_MENSAJES_GENERAL_SALIR()))
{
Close();
}
}
else
{
Close();
}
}
public event EventHandler P_Base_Evento_Pantalla_Close;
private void P_Base_FormClosed(object sender, FormClosedEventArgs e)
{
if (Tag != null)
{
//Ver primero si es una pantalla puesta en el panel secundario
if (Variables.G_DCT_PANTALLASABIERTAS_SECUNDARIAS_Y_NODOQUELASABRIO != null &&
Variables.G_DCT_PANTALLASABIERTAS_SECUNDARIAS_Y_NODOQUELASABRIO.Keys.ToList().Exists(m=>m.Equals(Tag.ToString())))
{
Funciones_PanelSecundario.Borrar_Pantalla(Tag.ToString());
}
else
{
Variables.G_EMS_CONTROL_MENUSUPERIOR.Delete(Tag.ToString());
Variables.G_EMS_CONTROL_MENUSUPERIOR.Seleccionar_Pantalla(P_Base_PantallaPadre_IdentificadorTAG);
Funciones_PanelSecundario.Borrar_Pantalla_DesdePrincipal(Tag.ToString(),true);
}
}
P_Base_Evento_Pantalla_Close?.Invoke(this, e);
}
public event EventHandler P_Base_Evento_Pantalla_Dejar;
private void P_Base_Leave(object sender, EventArgs e)
{
//NO TE ENFADES ALEXIS por poner esto aquí
//Obtenemos la pantalla en cuestion y la añadimos al DCT de pantallas abierta, Esto no deberia ir aquí, pero no se donde ponerlo
//ademas que en el SigmaERP2012 esta en este procedimiento.
if (Variables.G_LST_PANTALLASABIERTAS.Equals(Tag.ToString()))
{
Bitmap bmp_Captura = null;
try
{
//Creamor un BitMap del tamaño de nuestra pantalla
bmp_Captura = new Bitmap(Width, Height);
//Creamos el grafico en base al BitMap
Graphics obj_Graphics = Graphics.FromImage(bmp_Captura);
//transferimos la captura al objeto objGrafico en
//base a las medidas del bitmap
obj_Graphics.CopyFromScreen(Location.X + -8 + 281 + 10, Location.Y + -8 + 49 + 25, 0, 0, bmp_Captura.Size);
//Liberamos el gráfico de memoria
obj_Graphics.Flush();
//Comprobar si la Pantalla ya esta abierta para sustituir la imagen
string str_Descripcion_Corta = P_Base_TituloPantalla.ToUpper() + Environment.NewLine;
string str_Descripcion_Larga = P_Base_TituloPantalla.ToUpper() + Environment.NewLine;
string str_EmpresaActual = "";
//Ver si tiene Empresa Seleccionada
if(P_Base_ValoresGenerales != null && P_Base_ValoresGenerales.lng_idEmpresa != -1)
{
str_EmpresaActual = P_Base_ValoresGenerales.str_Empresa_Codigo + " " + P_Base_ValoresGenerales.str_Empresa_Descripcion.ToUpper() + Environment.NewLine;
}
if(Variables.G_DCT_PANTALLASABIERTAS_CAPTURAS.Count > 0 && Variables.G_DCT_PANTALLASABIERTAS_CAPTURAS.ContainsKey(Tag.ToString()))
{
INTERNO_MenuSuperior_Modelo mdl_INTERNO_MenuSuperior_Modelo = new INTERNO_MenuSuperior_Modelo(Tag.ToString(), str_EmpresaActual, str_Descripcion_Corta,"","",str_Descripcion_Larga, bmp_Captura);
Variables.G_DCT_PANTALLASABIERTAS_CAPTURAS[Tag.ToString()] = mdl_INTERNO_MenuSuperior_Modelo;
}
else
{
Variables.G_DCT_PANTALLASABIERTAS_CAPTURAS.Add(Tag.ToString(), new INTERNO_MenuSuperior_Modelo(Tag.ToString(), str_EmpresaActual, str_Descripcion_Corta, "", "", str_Descripcion_Larga, bmp_Captura));
}
}
catch (Exception ex)
{
Control_Errores.Errores_Log("", ex, nameof(P_Base) + "/" + nameof(P_Base_Leave));
}
}
P_Base_Evento_Pantalla_Dejar?.Invoke(this, e);
}
#endregion
}
}