gridSecundariasPredefinidos.cs
1 using System;
2 using System.ComponentModel;
3 using System.Drawing;
4 using System.Data;
5 using System.Linq;
6 using System.Windows.Forms;
7 using sage.ew.objetos;
8 using sage.ew.global;
10 using sage.ew.ewbase;
11 using sage.ew.functions;
12 using sage.ew.botones;
14 using System.Collections.Generic;
16 
17 namespace sage.ew.contabilidad.UserControls
18 {
22  public partial class gridSecundariasPredefinido : UserControl
23  {
27  public bool ModoPlantilla
28  {
29  get { return _lModoPlantilla; }
30  set
31  {
32  var hayCambio = (value != _lModoPlantilla);
33  _lModoPlantilla = value;
34 
35  if (hayCambio) //Reconfiguro el grid
36  {
37  ConfigurarGridSecundarias();
38  }
39  }
40  }
41  private bool _lModoPlantilla = false;
42 
43  # region Constructor
48  {
49  InitializeComponent();
50 
51  if (!DesignMode)
52  {
53  _nDecimales = Convert.ToInt32(EW_GLOBAL._GetVariable("wn_decimales"));
54  _lSecundar = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_secundar")); // Indica si trabaja con secundarias
55  _lSecManual = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_secman")); // Introducción manual de cuentas secundarias
56  _lSecRepAsiAutomatico = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_repasi")); // Introducción automático de cuentas secundarias
57  _lSecRepPorcentaje = Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_distsec")); // Utilizar % de distribución automático
58  _lTodacuen = (Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_todacuen")));
59  _lSoloNivelesDefinidos = (Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_solonivdef")));
60 
61  _lColNivel2Visible = !Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_Secunico")); // Trabajar con un único nivel analítico
62 
63  _nAnchoCodigoAnaliticoCompleto = Convert.ToInt16(Convert.ToInt16(EW_GLOBAL._Empresa != null ? EW_GLOBAL._GetLenCampo(KeyDiccionarioLenCampos.wn_analiticocompleto) : 9));
64 
65  InstanciarBotones();
66 
67  _Grid = mantegridSecundarias._Grid; // Referenciamos la grid
68 
69  ewtextboxTotalSecundarias.ReadOnly = true;
70  ewlabelTotalNA2.Visible = _lColNivel2Visible;
71  ewtextboxTotalSecundarias1.Visible = _lColNivel2Visible;
72 
73  if (_lSecundar)
74  {
75  ConfigurarSecundarias();
76  SubscripcionEventos();
77  }
78  }
79  }
80  # endregion Constructor
81 
82  # region Propiedades privadas
83  int _nDecimales = 0; // Decimales de la moneda
84  private bool _lSecManual = false; // Introducción manual de cuentas secundarias
85  private bool _lSecundar = true; // Indica si trabaja con secundarias. Inicialmente asignamos un true
86  private bool _lSecRepAsiAutomatico = false; // Indica si tiene reparto de secundarias automático
87  private bool _lSecRepPorcentaje = false;
88  private bool _lColNivel2Visible = true; // Trabajar con un único nivel analítico
89  private ewbutton _oBotonOpciones = null; // Referencia al botón de opciones
90 
91  private bool _bReadOnly = false; // Gestión de readonly
92  private bool _lFocusLineasAsiento = false; // Control de pasar el foco a la grid de secundarias
93  private ewMascara _oMascaraImport = new ewMascara(KeyDiccionarioMascara.wc_total); // Máscara utilizada para los totales
94  private ewMascara _oMascaraTpc = new ewMascara("999.99");
95  private btBrowSecundar _btBrowSecundar = null; // Referencia al botón de browser de secundarias
96  private btManteSecundar _btManteSecundar = null; // Referencia al mantenimiento del browser de scundarias
97  private string _lcPlanContable = string.Empty;
98  private int _nPlanAnalitico = 1;
99  private int _nAnchoCodigoAnaliticoCompleto = 5; // Asignamos un valor inicial
100 
104  private bool _lTodacuen = false;
108  private bool _lSoloNivelesDefinidos = (Convert.ToBoolean(EW_GLOBAL._GetVariable("wl_solonivdef")));
109  private bool _lColPorcentajeVisible = Convert.ToBoolean(EW_GLOBAL._GetVariable("Wl_DistSec"));
110 
114  private int _nLenAnalitica
115  {
116  get { return Convert.ToInt32(EW_GLOBAL._GetLenCampo(KeyDiccionarioLenCampos.wn_secundarias)); }
117  }
118 
123  private int _nAnchoColumnaAnalitica
124  {
125  get
126  {
127  int lnDigitos = 0, lnLongCuentaAnalitica = 0;
128 
129  if (_lPlanAnaliticoCompleto)
130  lnDigitos = _nLenAnalitica;
131  else
132  lnDigitos = Convert.ToInt32(EW_GLOBAL._GetLenCampo(KeyDiccionarioLenCampos.wn_secundarias));
133 
134  lnLongCuentaAnalitica = Convert.ToInt32(Math.Max(lnDigitos, 8) * mantegridSecundarias._Grid.Font.Size);
135 
136  return lnLongCuentaAnalitica;
137  }
138  }
139 
144  private bool _lPlanAnaliticoCompleto
145  {
146  get { return ((EW_GLOBAL._Empresa != null ? (EW_GLOBAL._Empresa._ImputarPor == 0) : false)); }
147  }
148 
152  private string _cHeaderCodigoPlanAnaliticoCompleto
153  {
154  get
155  {
156  if (_oNegocio != null)
157  return (_nPlanAnalitico == 1 ? SecundariasPredefinidos._EmpresaNombrePlanAnalitico1.Trim() : SecundariasPredefinidos._EmpresaNombrePlanAnalitico2.Trim());
158 
159  return "";
160  }
161  }
162 
166  private string _cHeaderDefiniciónPlanAnaliticoCompleto
167  {
168  get
169  {
170  return "Nombre del " + _cHeaderCodigoPlanAnaliticoCompleto;
171  }
172  }
173 
174  # endregion Propiedades privadas
175 
176  # region Propiedades públicas
177  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
181  public ewgrid _Grid;
182 
186  public bool _ReadOnly
187  {
188  get { return _bReadOnly; }
189  set
190  {
191  _bReadOnly = value;
192 
193  mantegridSecundarias._ReadOnly = _bReadOnly;
194 
195  if (_lSecundar)
196  {
197  //if (_oBotonOpciones != null)
198  // _oBotonOpciones.Enabled = !_bReadOnly;
199 
200  if (!_lSecManual)
201  {
202  mantegridSecundarias._Grid.Columns["CuentaNA1"].ReadOnly = true; // No dejamos modificar el código de secundarias
203 
204  if (!_lPlanAnaliticoCompleto)
205  mantegridSecundarias._Grid.Columns["CuentaNA2"].ReadOnly = true; // No dejamos modificar el código de secundarias
206  }
207 
208  mantegridSecundarias._Grid.Columns["NombreNA1"].ReadOnly = true;
209 
210  if (!_lPlanAnaliticoCompleto)
211  mantegridSecundarias._Grid.Columns["NombreNA2"].ReadOnly = true;
212  }
213  }
214  }
215 
219  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
220  public SecundariasPredefinidos _Negocio
221  {
222  get
223  {
224  return _oNegocio;
225  }
226  set
227  {
228  _oNegocio = value;
229 
230  Binding(); //Que recargue
231  RefrescarDescripcionNivelAnalitico();
232  }
233  }
234  private SecundariasPredefinidos _oNegocio = null;
235 
239  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
240  public string _PlanContable
241  {
242  get
243  {
244  if (_Negocio != null)
245  return _cPlanContable;
246  else
247  return "";
248  }
249  set
250  {
251  _lcPlanContable = value;
252 
253  if (_lPlanAnaliticoCompleto) // De momento le asignamos el valor exclusivamente para plan analítico completo
254  _btBrowSecundar._Plan = value;
255 
256  _cPlanContable = value;
257 
258  Binding();
259  RefrescarDescripcionNivelAnalitico();
260  }
261  }
262  private string _cPlanContable = string.Empty;
263 
264  private BindingList<SecundariasPredefinidos.Secundaria> GetLineas()
265  {
266  return _Negocio.GetLineasPlan(_PlanContable);
267  }
268 
273  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
274  public int _PlanAnalitico
275  {
276  get
277  {
278  return _nPlanAnalitico;
279  }
280  set
281  {
282  if (value >= 1 && value <= 2 && // No debería de pasar nunca
283  _nPlanAnalitico != value)
284  {
285  _nPlanAnalitico = value;
286  }
287  }
288  }
292  //[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
293  //public bool _SinBotones
294  //{
295  // get
296  // {
297  // return _lPresentacion;
298  // }
299  // set
300  // {
301  // _lPresentacion = value;
302 
303  // if (value)
304  // {
305  // mantegridSecundarias._Borrar_Visible = false;
306  // mantegridSecundarias._Anadir_Visible = false;
307  // mantegridSecundarias._MostrarBrowMante = false;
308  // mantegridSecundarias._Insertar_Visible = false;
309 
310  // if (_oBotonOpciones != null)
311  // _oBotonOpciones.Visible = false;
312  // }
313  // }
314  //}
315  # endregion Propiedades públicas
316 
317  #region EVENTOS
318  public event _FocusLineaRelacionadaHandler _FocusLineaRelacionada;
322 
326  public delegate void _FocusLineaRelacionadaHandler();
327 
331  public event _RefreshImagenPlanAnaliticoHandler _RefreshImagenPlanAnalitico;
332 
336  public delegate void _RefreshImagenPlanAnaliticoHandler();
337 
338  #endregion EVENTOS
339 
340  #region Métodos privados
341  private void InstanciarBotones()
345  {
346  if (_lSecundar)
347  {
348  _btBrowSecundar = new btBrowSecundar(); // Referencia al botón de browser de secundarias
349  _btManteSecundar = new btManteSecundar(); // Referencia al mantenimiento del browser de secundarias
350  }
351  }
352 
356  private void Binding()
357  {
358  if (string.IsNullOrWhiteSpace(_PlanContable))
359  {
360  mantegridSecundarias._Grid.DataSource = new BindingList<SecundariasPredefinidos.Secundaria>();
361  }
362  else
363  {
364  //if (!_oNegocioLinea._DatosNivelesAnaliticos.ContainsKey(_PlanContable))
365  //{
366  // _oNegocioLinea._DatosNivelesAnaliticos.Add(_PlanContable, new BindingList<AnaliticaDeAsientoPredefinidoLinea>());
367  //}
368  //else
369  //{
370  mantegridSecundarias._Grid.DataSource = _Negocio.GetLineasPlan(_PlanContable);
371  //}
372  }
373 
374  ConfigurarGridSecundarias();
375  RefrescarTotalSecundarias();
376  }
377 
383  private void NumeriUpDownColProperties(Mantegrid.DataGridViewNumericUpDownColumn toCol, ewMascara toMascara)
384  {
385  // Propietats de la cell
386  toCol.ValueType = typeof(decimal);
387  toCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
388  toCol.DefaultCellStyle.Format = toMascara._Mascara_Net;
389 
390  // Propietats del NumericUpDown
391  toCol.DecimalPlaces = toMascara._Num_Decimales;
392  toCol.Maximum = toMascara._Rango_Max;
393  toCol.Minimum = toMascara._Rango_Min;
394  toCol.Increment = 1;
395  toCol.ThousandsSeparator = false;
396  }
397 
401  private void RefrescarTotalSecundarias()
402  {
403  decimal lnTotalSecundarias = 0;
404  decimal lnTotalSecundarias1 = 0;
405  Color loColor;
406 
407  if (!string.IsNullOrWhiteSpace(_PlanContable))
408  {
409  lnTotalSecundarias = TotalSecundariasN1();
410  lnTotalSecundarias1 = TotalSecundariasN2();
411  }
412 
413  //El modo de trabajo marca la máscara a utilizar
414  var mascara = ModoPlantilla ? _oMascaraTpc : _oMascaraImport;
415 
416  //nivel analítico 1
417  if (SecundariasDescuadradas(tnNA: 1)) // Si hay descuadre se debe de presentar en color rojo
418  loColor = Color.Red;
419  else
420  loColor = SystemColors.ControlText;
421 
422  if (ewtextboxTotalSecundarias._PropiedadesDeEstilos._ColorFuenteBloqueado != loColor)
423  ewtextboxTotalSecundarias._PropiedadesDeEstilos._ColorFuenteBloqueado = loColor;
424 
425  ewtextboxTotalSecundarias.Text = lnTotalSecundarias.ToString(mascara._Mascara_Net);
426 
427  //nivel analítico 2
428  if (SecundariasDescuadradas(tnNA: 2)) // Si hay descuadre se debe de presentar en color rojo
429  loColor = Color.Red;
430  else
431  loColor = SystemColors.ControlText;
432 
433  if (ewtextboxTotalSecundarias1._PropiedadesDeEstilos._ColorFuenteBloqueado != loColor)
434  ewtextboxTotalSecundarias1._PropiedadesDeEstilos._ColorFuenteBloqueado = loColor;
435 
436  ewtextboxTotalSecundarias1.Text = lnTotalSecundarias1.ToString(mascara._Mascara_Net);
437  }
438 
442  private void SubscripcionEventos()
443  {
444  if (!_lSecundar)
445  return;
446 
447  if (_lSecManual)
448  {
449  mantegridSecundarias._DataSource_Row_New_Event += new Mantegrid._DataSource_Row_New_Event_Handler(MantegridSecundarias__DataSource_Row_New_Event); // Añadimos una secundaria
450  mantegridSecundarias._DataSource_Row_Delete_Event += new Mantegrid._DataSource_Row_Delete_Event_Handler(MantegridSecundarias__DataSource_Row_Delete_Event); // Gestión de borrado de una línea de secundaria
451 
452  // Captura de selección múltiple de secundarias
453  if (_lSecundar)
454  {
455  _btBrowSecundar._Click_After += new btBrowser._Click_After_Handler(_btBrowSecundar__Click_After);
456  _btBrowSecundar._Click_Before += new btBrowser._Click_Before_Handler(_btBrowSecundar__Click_Before);
457  }
458 
459  btBrowser lobtBrowser = BuscarBotonBrowser();
460  if (lobtBrowser != null)
461  {
462  lobtBrowser._Click_After += new btBrowser._Click_After_Handler(GridSecundariasAsiento__Click_After);
463  lobtBrowser._Click_Before += new btBrowser._Click_Before_Handler(GridSecundariasAsiento__Click_Before);
464  }
465 
466  mantegridSecundarias._Row_New_After += new Mantegrid._Row_New_After_Handler(MantegridSecundarias__Row_New_After);
467  mantegridSecundarias._Row_New_Before += new Mantegrid._Row_New_Before_Handler(MantegridSecundarias__Row_New_Before);
468  }
469 
470  Validating += new CancelEventHandler(Secundarias_Validating); // Validación del importe de las secundarias
471 
472  mantegridSecundarias._Grid.CellValueChanged += new DataGridViewCellEventHandler(MantegridSecundariasCellValueChanged); // Para refrescar los totales
473  mantegridSecundarias._Grid.CellBeginEdit += new DataGridViewCellCancelEventHandler(MantegridSecundariasCellBeginEdit); // No permitimos modificar el importe si no tenemos cuenta secundaria
474  mantegridSecundarias._BeforeColChange += new Mantegrid._BeforeColChange_Handler(MantegridSecundarias__BeforeColChange); // Control para devolver el foco a la grid de asientos
475  //mantegridSecundarias._Grid.Leave += new EventHandler(mantegridSecundariasLeave); // Cuando pierda el foco que se quede deseleccionada la celda activa de las secundarias
476 
477  if (_lPlanAnaliticoCompleto)
478  {
479  mantegridSecundarias._Row_New_Before += MantegridSecundarias__Row_New_BeforeAnaliticaCompleta;
480  mantegridSecundarias._Grid.EditingControlShowing += MantegridSecundarias_EditingControlShowing;
481  }
482  else
483  mantegridSecundarias._Grid.RowPrePaint += new DataGridViewRowPrePaintEventHandler(_Grid_RowPrePaint);
484 
485  mantegridSecundarias._DataSource_Row_Delete_Event += MantegridSecundarias__DataSource_Row_Delete_Event_PlanAnalitico;
486  }
487 
491  private void CancelarSubscripcionEventos()
492  {
493  if (!_lSecundar)
494  return;
495 
496  if (_lSecManual)
497  {
498  mantegridSecundarias._DataSource_Row_New_Event -= new Mantegrid._DataSource_Row_New_Event_Handler(MantegridSecundarias__DataSource_Row_New_Event); // Añadimos una secundaria
499  mantegridSecundarias._DataSource_Row_Delete_Event -= new Mantegrid._DataSource_Row_Delete_Event_Handler(MantegridSecundarias__DataSource_Row_Delete_Event); // Gestión de borrado de una línea de secundaria
500 
501  // Captura de selección múltiple de secundarias
502  _btBrowSecundar._Click_After -= new btBrowser._Click_After_Handler(_btBrowSecundar__Click_After);
503  _btBrowSecundar._Click_Before -= new btBrowser._Click_Before_Handler(_btBrowSecundar__Click_Before);
504 
505  btBrowser lobtBrowser = BuscarBotonBrowser();
506  if (lobtBrowser != null)
507  {
508  lobtBrowser._Click_After -= new btBrowser._Click_After_Handler(GridSecundariasAsiento__Click_After);
509  lobtBrowser._Click_Before -= new btBrowser._Click_Before_Handler(GridSecundariasAsiento__Click_Before);
510  }
511 
512  mantegridSecundarias._Row_New_After -= new Mantegrid._Row_New_After_Handler(MantegridSecundarias__Row_New_After);
513  mantegridSecundarias._Row_New_Before -= new Mantegrid._Row_New_Before_Handler(MantegridSecundarias__Row_New_Before);
514  }
515 
516  Validating -= new CancelEventHandler(Secundarias_Validating); // Validación del importe de las secundarias
517 
518  mantegridSecundarias._Grid.CellValueChanged -= new DataGridViewCellEventHandler(MantegridSecundariasCellValueChanged); // Para refrescar los totales
519  mantegridSecundarias._Grid.CellBeginEdit -= new DataGridViewCellCancelEventHandler(MantegridSecundariasCellBeginEdit); // No permitimos modificar el importe si no tenemos cuenta secundaria
520  mantegridSecundarias._BeforeColChange -= new Mantegrid._BeforeColChange_Handler(MantegridSecundarias__BeforeColChange); // Control para devolver el foco a la grid de asientos
521  //mantegridSecundarias._Grid.Leave -= new EventHandler(mantegridSecundariasLeave); // Cuando pierda el foco que se quede deseleccionada la celda activa de las secundarias
522 
523  if (_lPlanAnaliticoCompleto)
524  {
525  mantegridSecundarias._Row_New_Before -= MantegridSecundarias__Row_New_BeforeAnaliticaCompleta;
526  mantegridSecundarias._Grid.EditingControlShowing -= MantegridSecundarias_EditingControlShowing;
527  }
528  else
529  mantegridSecundarias._Grid.RowPrePaint -= new DataGridViewRowPrePaintEventHandler(_Grid_RowPrePaint);
530  }
531 
538  void MantegridSecundarias__Row_New_Before(ref bool tlOk, bool tlInsert = false)
539  {
540  if (_lSecManual == false)
541  {
542  tlOk = false;
543  return;
544  }
545 
546  // Si se pasa por aquí es por que se trabaja con secundarias manuales.
547  // Si estoy insertando (ojo, insertando, no añadiendo, hablo del nuevo botón Insertar) un nuevo registro de nivel 2, tengo que estar ya situado en un registro de nivel 2 por que se insertará debajo,
548  // y se arrastrará la cuenta de nivel 1 al nuevo registro (en el campo invisible que hay para tal proposito).
549  if (tlInsert)
550  {
551  // No colocar este control al principio de este metodo pues impediria "Añadir" el primer registro de secundarias.
552  if (mantegridSecundarias._Grid.CurrentCell == null)
553  {
554  FUNCTIONS._MessageBox("Para insertar un nuevo registro de nivel 2 debe estar situado previamente en un registro con nivel 2 declarado.", "Niveles analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop);
555  tlOk = false;
556  return;
557  }
558 
559  // Fila de la grid secundarias
560  int lnFilaGridSecundarias = mantegridSecundarias._Grid.CurrentCell.RowIndex;
561  DataGridViewRow loRow = mantegridSecundarias._Grid.Rows[lnFilaGridSecundarias];
562  SecundariasPredefinidos.Secundaria loIAsientosSecundarias = (SecundariasPredefinidos.Secundaria)loRow.DataBoundItem;
563 
564  if (string.IsNullOrWhiteSpace(loIAsientosSecundarias._Secundaria) || string.IsNullOrWhiteSpace(loIAsientosSecundarias._Secnivel2))
565  {
566  FUNCTIONS._MessageBox("Para insertar un nuevo registro de nivel 2 debe estar situado previamente en un registro con nivel 2 declarado.", "Niveles analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop);
567  tlOk = false;
568  return;
569  }
570  }
571 
572  return;
573  }
574 
580  void MantegridSecundarias__Row_New_After(DataGridViewRow tdgvRowLastInsert, bool tlInsert)
581  {
582  if (mantegridSecundarias._Grid.CurrentRow == null)
583  return;
584 
585  // Si el registro se creó via inserción y no añadiendo al final seguro que lo que toca es editar la cuenta de nivel 2 por tanto
586  // lo envio directamente hacia esa columna, caso contrario (añadir normal) nos situamos en la primera columna.
587  if (!tlInsert)
588  {
589  if (tdgvRowLastInsert.Index == 0) // Si es la primera fila que le agrego la pongo el foco a la primera columna.
590  mantegridSecundarias._Grid.CurrentCell = mantegridSecundarias._Grid.CurrentRow.Cells["CuentaNA1"];
591  }
592  else
593  {
594  // Como el insert se hace debajo de la linea activa, la celda activa continua siendo la inicial, hay que seleccionar la celda
595  // CuentaNiv2 de la siguiente fila.
596  int lnFilaDesdeInsert = mantegridSecundarias._Grid.CurrentCell.RowIndex;
597  lnFilaDesdeInsert++;
598  if (lnFilaDesdeInsert <= mantegridSecundarias._Grid.Rows.Count && !_lPlanAnaliticoCompleto)
599  mantegridSecundarias._Grid.CurrentCell = mantegridSecundarias._Grid.Rows[lnFilaDesdeInsert].Cells["CuentaNA2"];
600  else
601  mantegridSecundarias._Grid.CurrentCell = mantegridSecundarias._Grid.CurrentRow.Cells["CuentaNA1"];
602  }
603  }
604 
611  private void MantegridSecundarias_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
612  {
613  if (mantegridSecundarias._Grid.CurrentCell == null)
614  return;
615 
616  string lcColumna = ColumnaActual();
617 
618  if (lcColumna == "CuentaNA1")
619  {
620  e.Control.PreviewKeyDown -= Control_PreviewKeyDownNivel;
621  e.Control.PreviewKeyDown += Control_PreviewKeyDownNivel;
622  }
623  }
624 
629  private void MantegridSecundarias__DataSource_Row_Delete_Event_PlanAnalitico(DataGridViewRow trRowDelete)
630  {
631  RefreshImagenPlanAnalitico();
632  }
633 
639  private void MantegridSecundarias__Row_New_BeforeAnaliticaCompleta(ref bool tlOk, bool tlInsert = false)
640  {
641  if (mantegridSecundarias._Grid.CurrentCell == null)
642  return;
643 
644  string lcColumna = ColumnaActual();
645 
646  if (lcColumna == "CuentaNA1")
647  {
648  var linea = ObteneLineaDatosSecundarias(); ;
649 
650  if (linea != null && string.IsNullOrWhiteSpace(linea._Secundaria))
651  tlOk = false;
652  }
653  }
654 
660  private SecundariasPredefinidos.Secundaria ObteneLineaDatosSecundarias(bool tlPrimeraLinea = false)
661  {
662  if (mantegridSecundarias._Grid.CurrentCell == null)
663  return null;
664 
665  int lnFilaGridSecundarias = mantegridSecundarias._Grid.CurrentCell.RowIndex;
666  DataGridViewRow loRow = mantegridSecundarias._Grid.Rows[lnFilaGridSecundarias];
667 
669 
670  return linea;
671  }
672 
678  private void Control_PreviewKeyDownNivel(object sender, PreviewKeyDownEventArgs e)
679  {
680  string lcColumna = ColumnaActual();
681 
682  string lcCodigo = string.Empty;
683  DataGridViewTextBoxEditingControl loTextbox = null;
684  List<Keys> lstKeys = new List<Keys>() { Keys.Enter, Keys.Tab, Keys.Up, Keys.Down, Keys.Right, Keys.Left };
685 
686  if (lstKeys.Contains(e.KeyCode))
687  {
688  loTextbox = (DataGridViewTextBoxEditingControl)sender;
689  lcCodigo = loTextbox.Text.Trim();
690  }
691 
692  switch (lcColumna)
693  {
694  case "CuentaNA1":
695  if (!string.IsNullOrWhiteSpace(lcCodigo) && lcCodigo.Length != _nAnchoCodigoAnaliticoCompleto && lcCodigo.All(c => char.IsDigit(c)) && !ExisteNivelAnalitico(lcCodigo))
696  loTextbox.Text = BrowserRaizNivelAnalitico(lcCodigo);
697 
698  break;
699 
700  default:
701  break;
702  }
703 
704  lstKeys.Clear();
705  lstKeys = null;
706  }
707 
713  private string BrowserRaizNivelAnalitico(string tcRaiz)
714  {
715  _btBrowSecundar._CondicionAutomaticaActiva = true;
716  _btBrowSecundar._CondicionAutomatica = tcRaiz;
717 
718  _btBrowSecundar.PerformClick();
719 
720  _btBrowSecundar._CondicionAutomaticaActiva = false;
721  _btBrowSecundar._CondicionAutomatica = "";
722 
723  return _btBrowSecundar._Codigo;
724  }
725 
731  private bool ExisteNivelAnalitico(string tcRaiz)
732  {
733  if (_btBrowSecundar == null)
734  return false;
735 
736  if (_btBrowSecundar._DatatablePersonalizado == null)
737  _btBrowSecundar._RefreshDatatablePersonalizado();
738 
739  if (_btBrowSecundar._DatatablePersonalizado == null)
740  return false;
741 
742  var loExiste = _btBrowSecundar._DatatablePersonalizado.AsEnumerable().Where(row => Convert.ToString(row.Field<string>("codigo")).Trim() == tcRaiz).FirstOrDefault();
743 
744  return (loExiste != null && !string.IsNullOrWhiteSpace(Convert.ToString(loExiste["codigo"])));
745  }
746 
750  private void RefrescarDescripcionNivelAnalitico()
751  {
752  if (!string.IsNullOrWhiteSpace(_PlanContable))
753  {
754  ewPanelTituloSecundarias.Visible = true;
755  ewPanelTituloSecundarias._MostrarLineaTitulo = false;
756 
757  string lcNombre = string.Empty;
758 
759  if (_lPlanAnaliticoCompleto)
760  {
761  lcNombre = _PlanAnalitico == 1 ? SecundariasPredefinidos._EmpresaNombrePlanAnalitico1 : SecundariasPredefinidos._EmpresaNombrePlanAnalitico2;
762 
763  if (_lSecManual)
764  ewPanelTituloSecundarias._Titulo = $"CA cta. {_Negocio._Cuenta}, {lcNombre}";
765  else
766  ewPanelTituloSecundarias._Titulo = $"Códigos analíticos cta. {_Negocio._Cuenta}, {lcNombre}";
767  }
768  else
769  {
770  //lcNombre = _Negocio.CurrentPlan.NombrePlan;
771  lcNombre = SecundariasPredefinidos._DefinicionPlanAnalitico(_PlanContable);
772 
773  if (_lSecManual)
774  ewPanelTituloSecundarias._Titulo = $"NA cta. {_Negocio._Cuenta}, {lcNombre}";
775  else
776  ewPanelTituloSecundarias._Titulo = $"Niveles analíticos cta. {_Negocio._Cuenta}, {lcNombre}";
777  }
778  }
779  else
780  {
781  ewPanelTituloSecundarias.Visible = false;
782  }
783  }
784 
790  void _Grid_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
791  {
792  DataGridViewRow loRow = mantegridSecundarias._Grid.Rows[e.RowIndex];
794 
795  if (string.IsNullOrWhiteSpace(linea._Secundaria))
796  {
797  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.Format = "#";
798  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.Format = "#";
799  }
800  else
801  {
802  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.Format = mantegridSecundarias._Grid.DefaultCellStyle.Format;
803  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.Format = mantegridSecundarias._Grid.DefaultCellStyle.Format;
804  }
805 
806  if (string.IsNullOrWhiteSpace(linea._Secnivel2))
807  {
808  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.Format = "#";
809  //mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.Format = "#";
810  }
811  else
812  {
813  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.Format = mantegridSecundarias._Grid.DefaultCellStyle.Format;
814  //mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.Format = mantegridSecundarias._Grid.DefaultCellStyle.Format;
815  }
816 
817  if(ModoPlantilla) //En modo plantilla pese a poder estar en blanco el 2º porcentaje se opera con él
818  {
819  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.Format = mantegridSecundarias._Grid.DefaultCellStyle.Format;
820  }
821  else //Lleno o vacio el NA2 da igual pq no es visible
822  {
823  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.Format = "#";
824  }
825 
826  var esPrimeraSecunadaria = _Negocio.EsPrimeraSecundaria(linea);
827  if (!esPrimeraSecunadaria)
828  {
829  //No editables
830  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].Style.ForeColor =mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
831  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].ReadOnly = true;
832  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
833 
834  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].Style.ForeColor =mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
835  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].ReadOnly = true;
836  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
837 
838  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
839  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].ReadOnly = true;
840  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
841 
842  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.ForeColor =mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
843  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].ReadOnly = true;
844  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
845 
846  //Editables
847  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
848  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].ReadOnly = false;
849  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
850 
851  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
852  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].ReadOnly = false;
853  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
854  }
855  else
856  {
857  if (esPrimeraSecunadaria)
858  {
859  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
860  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].ReadOnly = !_lSecManual;
861  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["CuentaNA1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
862 
863  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
864  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].ReadOnly = true;
865  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["NombreNA1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
866 
867  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
868  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].ReadOnly = false;
869  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
870 
871  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
872  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].ReadOnly = _lColNivel2Visible;
873  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
874 
875  if (string.IsNullOrWhiteSpace(linea._Secnivel2))
876  {
877  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
878  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].ReadOnly = true;
879  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
880 
881 
882  }
883  else
884  {
885  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
886  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].ReadOnly = false;
887  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Importe1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
888  }
889 
890  if(ModoPlantilla) //Modo plantilla permite operar con el segundo porcentaje
891  {
892  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.ForeColor;
893  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].ReadOnly = false;
894  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionForeColor;
895  }
896  else
897  {
898  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.ForeColor = mantegridSecundarias._Grid.DefaultCellStyle.BackColor;
899  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].ReadOnly = true;
900  mantegridSecundarias._Grid.Rows[e.RowIndex].Cells["Porcentaje1"].Style.SelectionForeColor = mantegridSecundarias._Grid.DefaultCellStyle.SelectionBackColor;
901  }
902  }
903  }
904 
905  }
906 
911  private btBrowser BuscarBotonBrowser()
912  {
913  btBrowser loBoton = null;
914 
915  Control[] loBotonBrowserCol = mantegridSecundarias.Controls.Find("btBrowserCol", true);
916 
917  if (loBotonBrowserCol != null && loBotonBrowserCol.Count() > 0 && loBotonBrowserCol[0] is btBrowser)
918  loBoton = ((btBrowser)loBotonBrowserCol[0]);
919 
920  return loBoton;
921  }
922 
928  private void MantegridSecundarias__BeforeColChange(DataGridViewColumn tdgvCurrentCol, ref bool tlOk)
929  {
930  RefreshImagenPlanAnalitico();
931 
932  if (!_lFocusLineasAsiento)
933  {
934  DataGridViewCell loCell = mantegridSecundarias._Grid.CurrentCell;
935  if (loCell.OwningColumn.Name == "Importe1")
936  {
937  if ((_FocusLineaRelacionada != null) && SecundariasRepartidas()) // Al modificar las secundarias si las tenemos cuadradas podemos salir
938  _lFocusLineasAsiento = true;
939  }
940  }
941 
942  if (_lFocusLineasAsiento)
943  {
944  _lFocusLineasAsiento = false; // Restauramos el valor
945  tlOk = false; // De este modo no queda seleccionada la grid de secundarias, únicamente pasamos el foco nuevamente a la grid de asientos
946  _FocusLineaRelacionada();
947  }
948  }
949 
955  private void MantegridSecundariasCellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
956  {
957  string lcColumna = ColumnaActual();
958 
959  if (lcColumna == "Importe" || lcColumna == "Porcentaje")
960  {
961  var linea = ObtenerNegocioDeLaLinea();
962 
963  if (linea != null && string.IsNullOrWhiteSpace(linea._Secundaria))
964  e.Cancel = true;
965  }
966 
967  if (lcColumna == "Importe1")
968  {
969  var linea = ObtenerNegocioDeLaLinea();
970 
971  if (linea != null && string.IsNullOrWhiteSpace(linea._Secnivel2))
972  e.Cancel = true;
973  }
974 
975  if (lcColumna == "Porcentaje1")
976  {
977  var linea = ObtenerNegocioDeLaLinea();
978 
979  if (linea != null && string.IsNullOrWhiteSpace(linea._Secnivel2) && !linea._PrimeraSecundaria)
980  e.Cancel = true;
981  }
982 
983  if (lcColumna == "Importe" || lcColumna == "Importe1")
984  {
985  if (EsLineaDeCuadreEnModoEjecucion())
986  {
987  string lcDefMens = (_lPlanAnaliticoCompleto ? "código" : "nivel");
988  string lcDefMensUp = lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower();
989 
990  FUNCTIONS._MessageBox("Esta analítica corresponde a una línea de cuadre. El importe se calculará automáticamente.", lcDefMensUp.Trim() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
991  e.Cancel = true;
992  }
993  }
994 
995 
996  if (!e.Cancel)
997  RefreshImagenPlanAnalitico();
998  }
999 
1000  private bool EsLineaDeCuadreEnModoEjecucion()
1001  {
1002  var linea = ObtenerNegocioDeLaLinea();
1003 
1004  if (!ModoPlantilla && linea.PerteneceLineaCuadre())
1005  return true;
1006 
1007  return false;
1008  }
1009 
1013  private void RefreshImagenPlanAnalitico()
1014  {
1015  _RefreshImagenPlanAnalitico?.Invoke();
1016  }
1017 
1023  private void MantegridSecundariasCellValueChanged(object sender, DataGridViewCellEventArgs e)
1024  {
1025  string lcColumna = string.Empty;
1026  bool llRefrescarTotal = false;
1027  bool llFocus = false;
1028 
1029  DataGridViewCell loCell = mantegridSecundarias._Grid.CurrentCell;
1030 
1031  if (loCell == null)
1032  return;
1033 
1034  lcColumna = loCell.OwningColumn.Name;
1035 
1036  switch (lcColumna)
1037  {
1038  case "CuentaNA1":
1039  SecundariasPredefinidos.Secundaria linea = (SecundariasPredefinidos.Secundaria)loCell.OwningRow.DataBoundItem;
1040 
1041  if (string.IsNullOrWhiteSpace(linea._Secundaria))
1042  {
1043  if (!string.IsNullOrWhiteSpace(linea._Nombre))
1044  {
1045  linea._Nombre = string.Empty;
1046  llRefrescarTotal = true;
1047  }
1048 
1049  if (linea._ImporteNA1 != 0)
1050  {
1051  linea._ImporteNA1 = 0;
1052  llRefrescarTotal = true;
1053  }
1054  }
1055 
1056  break;
1057 
1058  case "CuentaNA2":
1059  SecundariasPredefinidos.Secundaria lineax = (SecundariasPredefinidos.Secundaria)loCell.OwningRow.DataBoundItem;
1060 
1061  if (string.IsNullOrWhiteSpace(lineax._Secnivel2))
1062  {
1063  if (!string.IsNullOrWhiteSpace(lineax._Nombre))
1064  {
1065  lineax._Nombre2 = string.Empty;
1066  llRefrescarTotal = true;
1067  }
1068 
1069  lineax._ImporteNA2 = lineax._ImporteNA1; //es guarda l'import dels dos nivells.
1070 
1071  llRefrescarTotal = true;
1072  }
1073  break;
1074 
1075  case "Importe":
1076  llRefrescarTotal = true;
1077  break;
1078 
1079  case "Importe1":
1080  llRefrescarTotal = true;
1081  llFocus = true;
1082  break;
1083 
1084  case "Porcentaje":
1085  llRefrescarTotal = true;
1086  break;
1087 
1088  case "Porcentaje1":
1089  llRefrescarTotal = true;
1090  llFocus = true;
1091  break;
1092 
1093  default:
1094  break;
1095  }
1096 
1097  if (llRefrescarTotal)
1098  {
1099  RefrescarTotalSecundarias();
1100 
1101  if ((_FocusLineaRelacionada != null) && llFocus && SecundariasRepartidas()) // Al modificar las secundarias si las tenemos cuadradas podemos salir
1102  _lFocusLineasAsiento = true;
1103  }
1104  }
1105 
1110  private string ColumnaActual()
1111  {
1112  string lcColumna = string.Empty;
1113 
1114  if (mantegridSecundarias._Grid.CurrentRow != null)
1115  {
1116  DataGridViewCell loCell = mantegridSecundarias._Grid.CurrentCell;
1117 
1118  int lnIndice = mantegridSecundarias._Grid.CurrentRow.Index;
1119 
1120  lcColumna = loCell.OwningColumn.Name;
1121  }
1122 
1123  return lcColumna;
1124  }
1125 
1131  private void MantegridSecundariasLeave(object sender, EventArgs e)
1132  {
1133  DataGridViewSelectionMode oldmode = mantegridSecundarias._Grid.SelectionMode;
1134  mantegridSecundarias._Grid.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
1135  mantegridSecundarias._Grid.ClearSelection();
1136  mantegridSecundarias._Grid.SelectionMode = oldmode;
1137 
1138  mantegridSecundarias._Grid.FirstDisplayedCell = null;
1139  }
1140 
1145  private void GridSecundariasAsiento__Click_After(bool tlAceptar)
1146  {
1147  Control[] loBotonBrowserCol = mantegridSecundarias.Controls.Find("btBrowserCol", true);
1148 
1149  if (loBotonBrowserCol != null && loBotonBrowserCol.Count() > 0 && loBotonBrowserCol[0] is btBrowser)
1150  {
1151  RecuperarSecundariasSeleccionadas((btBrowser)loBotonBrowserCol[0]);
1152  }
1153  }
1154 
1159  private void _btBrowSecundar__Click_After(bool tlAceptar)
1160  {
1161  RecuperarSecundariasSeleccionadas(_btBrowSecundar);
1162  }
1163 
1169  private void GridSecundariasAsiento__Click_Before(ref bool tlOk)
1170  {
1171  btBrowser lobtBrowser = BuscarBotonBrowser();
1172 
1173  if (lobtBrowser != null)
1174  {
1175  btBrowser lobtBrowSecundar = ConfigurarBrowserSecundarias(lobtBrowser);
1176  if (lobtBrowSecundar != null)
1177  {
1178  lobtBrowser._CondicionAutomaticaActiva = false;
1179  lobtBrowser._DatatablePersonalizado = lobtBrowSecundar._DatatablePersonalizado;
1180  }
1181  }
1182  }
1183 
1189  private void _btBrowSecundar__Click_Before(ref bool tlOk)
1190  {
1191  btBrowser lobtBrowSecundar = ConfigurarBrowserSecundarias(_btBrowSecundar);
1192  if (lobtBrowSecundar != null)
1193  {
1194  _btBrowSecundar._CondicionAutomaticaActiva = false;
1195  _btBrowSecundar._DatatablePersonalizado = lobtBrowSecundar._DatatablePersonalizado;
1196  }
1197  }
1198 
1204  private btBrowser ConfigurarBrowserSecundarias(btBrowser toBrowSecundar)
1205  {
1206  string lcColumna = string.Empty;
1207 
1208  if (_lSoloNivelesDefinidos)
1209  {
1210  int lnNivel = _nPlanAnalitico;
1211 
1212  if (_lPlanAnaliticoCompleto)
1213  lcColumna = (_nPlanAnalitico == 1 ? "CuentaNA1" : "CuentaNA2");
1214  else
1215  {
1216  lcColumna = ColumnaActual();
1217  if (lcColumna == "CuentaNA1")
1218  lnNivel = 1;
1219  else if (lcColumna == "CuentaNA2")
1220  lnNivel = 2;
1221  }
1222 
1223  bool llBrowSecundar = (toBrowSecundar is btBrowSecundar);
1224 
1225  btBrowSecundar loBrowSecundar;
1226 
1227  if (llBrowSecundar)
1228  loBrowSecundar = (btBrowSecundar)toBrowSecundar; // Si es el browser de secundarias podemos utilizar la misma instancia. Si pulsamos F4 pasará por aquí pues tenemos asignado al F4 el "btBrowSecundar"
1229  else
1230  loBrowSecundar = new btBrowSecundar(); // Necesitamos utilizar la "btBrowSecundar", es donde tenemos toda la lógica de los niveles y de los planes. Cuando no viene mediante el F4 utiliza "btBrowser"
1231 
1232  loBrowSecundar._Condicion = "";
1233  loBrowSecundar._Nivel = lnNivel;
1234  loBrowSecundar._Plan = _PlanContable;
1235  loBrowSecundar._RefreshDatatablePersonalizado();
1236 
1237  toBrowSecundar = loBrowSecundar;
1238  }
1239  else
1240  {
1241  lcColumna = ColumnaActual();
1242 
1243  string lcNivel = string.Empty;
1244 
1245  if (lcColumna == "CuentaNA1")
1246  lcNivel = "1";
1247  else if (lcColumna == "CuentaNA2")
1248  lcNivel = "2";
1249 
1250  if (toBrowSecundar._DatatablePersonalizado != null)
1251  toBrowSecundar._DatatablePersonalizado = null;
1252 
1253  toBrowSecundar._Condicion = " nivel = " + lcNivel;
1254  }
1255 
1256  if (_lPlanAnaliticoCompleto)
1257  toBrowSecundar._Titulo = TituloPlanAnaliticoCompleto(lcColumna);
1258 
1259  return toBrowSecundar;
1260  }
1265  private string TituloPlanAnaliticoCompleto(string lcColumna)
1266  {
1267  string lcDescripcionPlan = string.Empty;
1268 
1269  switch (lcColumna)
1270  {
1271  case "CuentaNA1":
1272  lcDescripcionPlan = SecundariasPredefinidos._EmpresaNombrePlanAnalitico1;
1273  break;
1274 
1275  case "CuentaNA2":
1276  lcDescripcionPlan = SecundariasPredefinidos._EmpresaNombrePlanAnalitico2;
1277  break;
1278 
1279  default:
1280  break;
1281  }
1282 
1283  return "Listado de códigos analíticos del plan " + lcDescripcionPlan;
1284  }
1285 
1290  private void RecuperarSecundariasSeleccionadas(btBrowser toBtBrowser)
1291  {
1292  // Recuperamos las secundarias múltiples seleccionadas
1293  if (toBtBrowser._Codigo_List != null && toBtBrowser._Codigo_List.Count > 0)
1294  {
1295  foreach (string lcSecundaria in toBtBrowser._Codigo_List.Keys) // Recorremos las secundarias
1296  {
1297  //_oNegocio._AddSecundaria(_PlanContable);
1298  }
1299  }
1300  }
1301 
1308  private bool SecundariasRepartidas(bool tlMensaje = false, bool tlSinReparto = false)
1309  {
1310  //if (ModoPlantilla)
1311  //{
1312  return (!SecundariasDescuadradas(tlMensaje) && (tlSinReparto || TotalSecundariasN1() != 0 || TotalSecundariasN2() != 0));
1313  //}
1314  //else
1315  //{
1316  // return (!SecundariasDescuadradas(tlMensaje) && (tlSinReparto || TotalSecundariasN1() != 0 || TotalSecundariasN2() != 0));
1317  //}
1318  }
1319 
1327  private bool SecundariasDescuadradas(bool tlMensaje = false, int tnNA = 0)
1328  {
1329  bool llDescuadre = false;
1330  decimal importeSecNivel1 = 0M;
1331  decimal importeSecNivel2 = 0M;
1332  string lcMensaje = "";
1333  string lcSimbolo = "";
1334  string lcDefMens = (_lPlanAnaliticoCompleto ? "código" : "nivel");
1335  string lcDefMensUp = lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower();
1336 
1337 
1338  decimal importeLinea = TotalMaximoDeseado();
1339  if (tnNA == 0)
1340  {
1341  importeSecNivel1 = TotalSecundariasN1();
1342  importeSecNivel2 = TotalSecundariasN2();
1343  }
1344  else
1345  {
1346  importeSecNivel1 = importeSecNivel2 = (tnNA == 1 ? TotalSecundariasN1() : TotalSecundariasN2());
1347  }
1348 
1349  llDescuadre = (importeSecNivel1 != 0 && (importeLinea != importeSecNivel1 || importeLinea != importeSecNivel2));
1350 
1351  if (tlMensaje && llDescuadre)
1352  {
1353  lcMensaje = "";
1354  lcSimbolo = "";
1355 
1356  if (ModoPlantilla) //Porcentaje
1357  {
1358  var errorPoncentajeExcecido = $"La suma del porcentaje del plan analítico {_PlanContable.Trim()} debe ser 100";
1359  //_Negocio.SetErrorMessage(errorPoncentajeExcecido);
1360  FUNCTIONS._MessageBox(errorPoncentajeExcecido, lcDefMensUp.Trim() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
1361  }
1362  else //Importes
1363  {
1364  if (importeLinea != importeSecNivel1)
1365  {
1366  if (_lPlanAnaliticoCompleto)
1367  {
1368  lcMensaje = $" Plan {NombreDelPlan(_PlanContable)} Códigos analíticos Importe " + importeSecNivel1.ToString(_oMascaraImport._Mascara_Net) + lcSimbolo + Environment.NewLine;
1369  }
1370  else
1371  {
1372  lcMensaje = " Plan " + _PlanContable.Trim() + " Nivel analítico 1 Importe " + importeSecNivel1.ToString(_oMascaraImport._Mascara_Net) + lcSimbolo + Environment.NewLine;
1373  }
1374  }
1375 
1376  if (_lColNivel2Visible && !_lPlanAnaliticoCompleto)
1377  {
1378  if (importeLinea != importeSecNivel2)
1379  {
1380  lcMensaje = lcMensaje + " Plan " + _PlanContable.Trim() + " Nivel analítico 2 Importe " + importeSecNivel2.ToString(_oMascaraImport._Mascara_Net) + lcSimbolo;
1381  }
1382  }
1383 
1384  var lcMensajeImp = string.Empty;
1385  if (_lPlanAnaliticoCompleto)
1386  {
1387  lcMensajeImp = "El importe de los códigos analíticos declarados no coincide con el importe de la cuenta " + _Negocio._Cuenta.Trim() +
1388  " Importe " + TotalMaximoDeseado().ToString(_oMascaraImport._Mascara_Net) + lcSimbolo + ".";
1389  }
1390  else
1391  {
1392  lcMensajeImp = "El importe de los niveles analíticos declarados no coincide con el importe de la cuenta " + _Negocio._Cuenta.Trim() +
1393  " Importe " + TotalMaximoDeseado().ToString(_oMascaraImport._Mascara_Net) + lcSimbolo + ".";
1394  }
1395 
1396  lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
1397  lcDefMensUp = lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower();
1398 
1399 
1400 
1401  FUNCTIONS._MessageBox(lcMensajeImp + Environment.NewLine + Environment.NewLine +
1402  lcMensaje, lcDefMensUp.Trim() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);
1403  }
1404  }
1405 
1406  HayDescuadre = llDescuadre;
1407  return llDescuadre;
1408  }
1409 
1410  private string NombreDelPlan(string codigoPlan)
1411  {
1412  return codigoPlan.Trim().Equals(SecundariasPredefinidos._EmpresaPlanAnalitico1) ? SecundariasPredefinidos._EmpresaNombrePlanAnalitico1 : SecundariasPredefinidos._EmpresaNombrePlanAnalitico2;
1413  }
1414 
1418  public bool HayDescuadre { get; private set; }
1419 
1426  private void Secundarias_Validating(object sender, CancelEventArgs e)
1427  {
1428  RefreshImagenPlanAnalitico();
1429 
1430  //if (SecundariasDescuadradas(true))
1431  if (!ModoPlantilla && SecundariasDescuadradas(true)) //Para modo plantilla (que va ligado a plantilla y como tal soporta incoherencia de datos) no presento mensajes al salir del control para no interferir con el mante
1432  {
1433  //e.Cancel = true;
1434 
1436  //if (FindForm() != null) FindForm().ActiveControl = this;
1437 
1438  //FocusGrid(); // Pasamos el foco a la grid
1439  }
1440  }
1441 
1445  private void FocusGrid()
1446  {
1447  DataGridViewCell loCell = mantegridSecundarias._Grid.CurrentCell;
1448 
1449  if (loCell != null)
1450  {
1451  int lnRow = mantegridSecundarias._Grid.CurrentRow.Index;
1452  string lcColumna = loCell.OwningColumn.Name;
1453 
1454  if (mantegridSecundarias._Grid.Rows.Count > 0)
1455  mantegridSecundarias._Grid.Rows[lnRow].Cells[lcColumna].Selected = true;
1456  }
1457  else
1458  _Grid.Focus();
1459  }
1460 
1465  private void MantegridSecundarias__DataSource_Row_Delete_Event(DataGridViewRow trRowDelete)
1466  {
1467  DialogResult loResult;
1468 
1469  loResult = FUNCTIONS._MessageBox("¿Seguro que desea borrar la línea seleccionada?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, DialogResult.No);
1470 
1471  if (loResult == DialogResult.Yes)
1472  {
1473  var linea = ObtenerNegocioDeLaLinea();
1474 
1475  if (linea != null)
1476  {
1477  //linea._Delete();
1478  //_Negocio.CurrentPlan.Lineas.Remove(linea);
1479  _Negocio._Items.Remove(linea);
1480  Binding();
1481  GestionFocoAsiento();
1482  }
1483  }
1484  }
1485 
1490  private void GestionFocoAsiento()
1491  {
1492  if (_lPlanAnaliticoCompleto)
1493  {
1494  if (((BindingList<SecundariasPredefinidos.Secundaria>)mantegridSecundarias._Grid.DataSource).Count == 0)
1495  {
1496  _ReadOnly = true;
1497  PasarFocoGrid();
1498  }
1499  }
1500  }
1501 
1505  private void PasarFocoGrid()
1506  {
1507  Timer loTimer = new Timer
1508  {
1509  Interval = 10
1510  };
1511  loTimer.Tick += TimerPasarFocoGrid_Tick;
1512  loTimer.Start();
1513  }
1514 
1520  private void TimerPasarFocoGrid_Tick(object sender, EventArgs e)
1521  {
1522  ((Timer)sender).Stop();
1523  ((Timer)sender).Dispose();
1524  try
1525  {
1526  _FocusLineaRelacionada();
1527  }
1528  catch(Exception)
1529  {
1530  //No quiero poner referencia a la DB en la capa visual
1531  }
1532  }
1533 
1538  private void MantegridSecundarias__DataSource_Row_New_Event(int tnInsertLinea)
1539  {
1540  _Negocio._AddSecundaria(_PlanContable, tnInsertLinea);
1541  Binding();
1542 
1543  }
1544 
1549  private SecundariasPredefinidos.Secundaria ObtenerNegocioDeLaLinea()
1550  {
1551  SecundariasPredefinidos.Secundaria loIAsientosLineaSecundaria = null;
1552 
1553  if (mantegridSecundarias._Grid.CurrentRow != null)
1554  {
1555  DataGridViewCell loCell = mantegridSecundarias._Grid.CurrentCell;
1556 
1557  if (loCell != null)
1558  loIAsientosLineaSecundaria = (SecundariasPredefinidos.Secundaria)loCell.OwningRow.DataBoundItem;
1559  }
1560 
1561  return loIAsientosLineaSecundaria;
1562  }
1563 
1567  private void NavegarMantenimientoNivelesAnaliticos()
1568  {
1569  string lcColumna = ColumnaActual();
1570  string lcCodigo = string.Empty;
1571 
1572  var linea = ObtenerNegocioDeLaLinea();
1573 
1574  if (linea != null)
1575  {
1576  switch (lcColumna)
1577  {
1578  case "CuentaNA1":
1579  lcCodigo = linea._Secundaria;
1580  break;
1581 
1582  case "CuentaNA2":
1583  lcCodigo = linea._Secnivel2;
1584  break;
1585  }
1586  }
1587 
1588  _btManteSecundar._Codigo = lcCodigo;
1589  _btManteSecundar.PerformClick();
1590  }
1591 
1596  private void AddButtonOpciones()
1597  {
1598  Control loBotonInsertar = mantegridSecundarias.Controls["btInsertar"]; // Colocaremos el control en la misma posición donde tenemos el botón de insertar
1599  if (loBotonInsertar != null)
1600  {
1601  _oBotonOpciones = new ewbutton();
1602  _oBotonOpciones._PropiedadesDeEstilos._AplicarEstilos = false;
1603  _oBotonOpciones.FlatStyle = FlatStyle.Flat;
1604  _oBotonOpciones.FlatAppearance.BorderSize = 0;
1605  _oBotonOpciones.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
1606  _oBotonOpciones.Image = sage.ew.images.Properties.Resources.settings_16;
1607  _oBotonOpciones._Tooltip = "Opciones planes analíticos";
1608  _oBotonOpciones.Click += new EventHandler(Opciones_Click);
1609 
1610  _oBotonOpciones.UseVisualStyleBackColor = true;
1611 
1612  mantegridSecundarias.Controls.Add(_oBotonOpciones);
1613 
1614  Size loSize = loBotonInsertar.Size;
1615 
1616  loSize.Width = 28;
1617  _oBotonOpciones.Size = loSize;
1618 
1619  Point loPoint = loBotonInsertar.Location;
1620  loPoint.X = loPoint.X + (loBotonInsertar.Size.Width - loSize.Width);
1621 
1622  _oBotonOpciones.Location = loPoint;
1623  }
1624  }
1625 
1633  private void Opciones_Click(object sender, EventArgs e)
1634  {
1635  ewcontextmenustrip loMenuContext_Opciones = new ewcontextmenustrip();
1636  string lcColumna = ColumnaActual();
1637 
1638  int lnItem = 0;
1639 
1640  if (ModoPlantilla)
1641  {
1642  if (_lColPorcentajeVisible) //Sólo si reparto automático porcentual
1643  {
1644  loMenuContext_Opciones.Items.Add("Repartir porcentaje");
1645  loMenuContext_Opciones.Items[lnItem].Name = "Reparto";
1646  loMenuContext_Opciones.Items["Reparto"].Click += new EventHandler(RepartoPorcentajeSecundarias_Click);
1647  loMenuContext_Opciones.Items["Reparto"].ToolTipText = "Reparto proporcional del porcentaje en niveles analíticos";
1648  loMenuContext_Opciones.Items["Reparto"].Enabled = !_ReadOnly;
1649  lnItem++;
1650  }
1651 
1652  if (_lSecManual) //Bug 177142
1653  {
1654  loMenuContext_Opciones.Items.Add("Añadir desglose analítico de plan");
1655  loMenuContext_Opciones.Items[lnItem].Name = "InsertarTodas";
1656  loMenuContext_Opciones.Items["InsertarTodas"].Click += new EventHandler(InsertarTodas_Click);
1657  loMenuContext_Opciones.Items["InsertarTodas"].ToolTipText = "Añade los registros de desglose analítico asociados al plan";
1658  loMenuContext_Opciones.Items["InsertarTodas"].Enabled = !_ReadOnly;
1659  lnItem++;
1660 
1661  loMenuContext_Opciones.Items.Add("Añadir desglose analítico de cuenta");
1662  loMenuContext_Opciones.Items[lnItem].Name = "DesgloseCuenta";
1663  loMenuContext_Opciones.Items["DesgloseCuenta"].Click += new EventHandler(DesgloseCuenta_Click);
1664  loMenuContext_Opciones.Items["DesgloseCuenta"].ToolTipText = "Añade los registros de desglose analítico asociados a la cuenta";
1665  loMenuContext_Opciones.Items["DesgloseCuenta"].Enabled = !_ReadOnly;
1666  lnItem++;
1667 
1668  loMenuContext_Opciones.Items.Add("Borrar todos");
1669  loMenuContext_Opciones.Items[lnItem].Name = "BorrarTodas";
1670  loMenuContext_Opciones.Items["BorrarTodas"].Click += new EventHandler(BorrarTodas_Click);
1671  loMenuContext_Opciones.Items["BorrarTodas"].ToolTipText = "Borra todos los registros de los niveles analíticos";
1672  loMenuContext_Opciones.Items["BorrarTodas"].Enabled = !_ReadOnly;
1673  lnItem++;
1674  }
1675 
1676  if (_lSecManual && _lColNivel2Visible && !_lPlanAnaliticoCompleto)
1677  {
1678  loMenuContext_Opciones.Items.Add("Insertar");
1679  loMenuContext_Opciones.Items[lnItem].Name = "Insertar";
1680  loMenuContext_Opciones.Items["Insertar"].Click += new EventHandler(Insertar_Click);
1681  loMenuContext_Opciones.Items["Insertar"].ToolTipText = "Insertar registro de cuenta de nivel 2 bajo registro de nivel 1";
1682  loMenuContext_Opciones.Items["Insertar"].Enabled = !_ReadOnly;
1683  lnItem++;
1684  }
1685 
1686  loMenuContext_Opciones.Items.Add("Desglose");
1687  loMenuContext_Opciones.Items[lnItem].Name = "Desglose";
1688  loMenuContext_Opciones.Items["Desglose"].Click += new EventHandler(VerDesglose_Click);
1689  loMenuContext_Opciones.Items["Desglose"].ToolTipText = "Muestra el desglose analítico del plan";
1690  loMenuContext_Opciones.Items["Desglose"].Enabled = _ReadOnly;
1691  lnItem++;
1692  }
1693  else
1694  {
1695  loMenuContext_Opciones.Items.Add("Reparto proporcional");
1696  loMenuContext_Opciones.Items[lnItem].Name = "Reparto";
1697  loMenuContext_Opciones.Items["Reparto"].Click += new EventHandler(RepartoImporteSecundarias_Click);
1698  loMenuContext_Opciones.Items["Reparto"].ToolTipText = "Reparto proporcional de importe de cuenta en niveles analíticos";
1699  loMenuContext_Opciones.Items["Reparto"].Enabled = !_ReadOnly;
1700  lnItem++;
1701 
1702  if (_lSecManual)
1703  {
1704  loMenuContext_Opciones.Items.Add("Añadir desglose analítico de cuenta");
1705  loMenuContext_Opciones.Items[lnItem].Name = "DesgloseCuenta";
1706  loMenuContext_Opciones.Items["DesgloseCuenta"].Click += new EventHandler(DesgloseCuenta_Click);
1707  loMenuContext_Opciones.Items["DesgloseCuenta"].ToolTipText = "Añade los registros de desglose analítico asociados a la cuenta";
1708  loMenuContext_Opciones.Items["DesgloseCuenta"].Enabled = !_ReadOnly;
1709  lnItem++;
1710 
1711  loMenuContext_Opciones.Items.Add("Borrar todos");
1712  loMenuContext_Opciones.Items[lnItem].Name = "BorrarTodos";
1713  loMenuContext_Opciones.Items["BorrarTodos"].Click += new EventHandler(BorrarTodas_Click);
1714  loMenuContext_Opciones.Items["BorrarTodos"].ToolTipText = "Borra todos los registros de los niveles analíticos";
1715  loMenuContext_Opciones.Items["BorrarTodos"].Enabled = !_ReadOnly;
1716  lnItem++;
1717 
1718  if (_lColNivel2Visible && !_lPlanAnaliticoCompleto)
1719  {
1720  loMenuContext_Opciones.Items.Add("Insertar");
1721  loMenuContext_Opciones.Items[lnItem].Name = "Insertar";
1722  loMenuContext_Opciones.Items["Insertar"].Click += new EventHandler(Insertar_Click);
1723  loMenuContext_Opciones.Items["Insertar"].ToolTipText = "Insertar registro de cuenta de nivel 2 bajo registro de nivel 1";
1724  loMenuContext_Opciones.Items["Insertar"].Enabled = !_ReadOnly;
1725  lnItem++;
1726  }
1727  }
1728 
1729  if (!_lSecManual)
1730  {
1731  loMenuContext_Opciones.Items.Add("Mantenimiento de niveles analíticos");
1732  loMenuContext_Opciones.Items[lnItem].Name = "Mantenimiento";
1733  loMenuContext_Opciones.Items["Mantenimiento"].Click += new EventHandler(NavegarMantenimientoNivelesAnaliticos_Click);
1734  loMenuContext_Opciones.Items["Mantenimiento"].ToolTipText = "Mantenimiento de niveles analíticos";
1735  loMenuContext_Opciones.Items["Mantenimiento"].Enabled = (lcColumna == "CuentaNA1" || lcColumna == "CuentaNA2");
1736  loMenuContext_Opciones.Items["Mantenimiento"].Enabled = !_ReadOnly;
1737  lnItem++;
1738  }
1739  }
1740 
1741  loMenuContext_Opciones.Show(Cursor.Position.X, Cursor.Position.Y);
1742  }
1743 
1749  private void Insertar_Click(object sender, EventArgs e)
1750  {
1751  _Grid.Focus();
1752  mantegridSecundarias._Fila_Insert();
1753  }
1754 
1760  private void RepartoPorcentajeSecundarias_Click(object sender, EventArgs e)
1761  {
1762  RepartirPorcentaje(accionDeUsuario: true);
1763  Binding();
1764  }
1765 
1771  private void InsertarTodas_Click(object sender, EventArgs e)
1772  {
1773  _Negocio._InsertarTodas(_PlanContable);
1774  Binding();
1775  RefreshImagenPlanAnalitico();
1776  }
1777 
1783  private void DesgloseCuenta_Click(object sender, EventArgs e)
1784  {
1785  //Si no tengo cta completa aviso
1786  if (!_Negocio.CuentaCompleta())
1787  {
1788  string lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
1789  FUNCTIONS._MessageBox("Se requiere una cuenta completa para poder cargar su detalle analítico.", lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
1790  return;
1791  }
1792 
1793  //Si no tengo datos aviso
1794  if(!_Negocio.TengoDatosDelPlanEnCuentas(_Negocio._Cuenta, _PlanContable))
1795  {
1796  string lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
1797  var plan = _lPlanAnaliticoCompleto ? NombreDelPlan(_PlanContable) : _PlanContable; //Código o nombre
1798  FUNCTIONS._MessageBox($"La cuenta no tiene desglose analítico para el plan {plan}.", lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
1799  return;
1800  }
1801 
1802  _Negocio._InsertarRestoDesdeCuentas(_PlanContable);
1803  Binding();
1804  RefreshImagenPlanAnalitico();
1805  }
1806 
1807 
1813  private void BorrarTodas_Click(object sender, EventArgs e)
1814  {
1815  if (string.IsNullOrWhiteSpace(_PlanContable))
1816  return;
1817 
1818  if (_Negocio.GetLineasPlan(_PlanContable).Count() == 0)
1819  {
1820  FUNCTIONS._MessageBox("No hay registros de niveles analíticos para borrar.", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2, DialogResult.OK);
1821  return;
1822  }
1823 
1824  if ((FUNCTIONS._MessageBox("¿Seguro que desea borrar todos los registros de los niveles analíticos?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, DialogResult.Yes) == DialogResult.Yes))
1825  {
1826  //_Negocio._BorrarTodas(_PlanContable, accionDeUsuario: true);
1827  _Negocio._BorrarTodas(_PlanContable);
1828  Binding();
1829  RefreshImagenPlanAnalitico();
1830  }
1831  _Grid.Focus();
1832 
1833  GestionFocoAsiento();
1834  }
1835 
1841  private void VerDesglose_Click(object sender, EventArgs e)
1842  {
1843  if(string.IsNullOrWhiteSpace(_PlanContable) || _Negocio._Items.Count == 0)
1844  {
1845  string lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
1846  FUNCTIONS._MessageBox($"No hay datos para mostrar desglose.", lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
1847  return;
1848  }
1849  _Negocio._VerDesglose(_PlanContable);
1850  }
1851 
1857  private void RepartoImporteSecundarias_Click(object sender, EventArgs e)
1858  {
1859  RepartirImporte(accionDeUsuario: true);
1860  }
1861 
1867  private void NavegarMantenimientoNivelesAnaliticos_Click(object sender, EventArgs e)
1868  {
1869  NavegarMantenimientoNivelesAnaliticos();
1870  }
1871 
1872 
1876  private void ConfigurarSecundarias()
1877  {
1878  mantegridSecundarias._Grid.AllowUserToOrderColumns = false; // No dejamos mover las columnas
1879 
1880  if (_lSecundar)
1881  {
1882  mantegridSecundarias._RecuadroVisible = false; // No presentamos el recuadro
1883 
1884  AddButtonOpciones();
1885 
1886  if (_lSecManual)
1887  {
1888  mantegridSecundarias._MostrarBrowMante = true;
1889  //mantegridSecundarias._Insertar_Visible = _lColNivel2Visible;
1890  //mantegridSecundarias._Insertar_Tooltip = "Insertar registro de cuenta de nivel 2 bajo registro de nivel 1";
1891  }
1892  else
1893  {
1894  // Introducción manual de cuentas secundarias, si una cuenta contable tiene cuentas secundarias en su ficha
1895  // si este opcflag está activado, no se añadiran automaticamente, sino que será el usuario quien las añada manualmente
1896  // Si no está activado el opcflag, se añadirán automaticamente.
1897  Point loPoint = mantegridSecundarias._Grid.Location;
1898  Size loSize = mantegridSecundarias._Grid.Size;
1899 
1900  mantegridSecundarias._MostrarBrowMante = false;
1901  mantegridSecundarias._Borrar_Visible = false;
1902  mantegridSecundarias._Anadir_Visible = false;
1903 
1904  // Resturamos la posición de la grid y el tamaño
1905  mantegridSecundarias._Grid.Location = loPoint;
1906  mantegridSecundarias._Grid.Size = loSize;
1907 
1908  //Movemos el título para que ocupe un lugar mas a la izquierda
1909  ewPanelTituloSecundarias.Location = new Point(loPoint.X, ewPanelTituloSecundarias.Location.Y);
1910  }
1911 
1912  ConfigurarGridSecundarias();
1913  }
1914  }
1915 
1919  private void RevisarTextTotales()
1920  {
1921 
1922  if (_lPlanAnaliticoCompleto)
1923  ewlabelTotalNA2.Text = ModoPlantilla ? "Total % CA:" : "Total CA:";
1924  else
1925  {
1926  ewlabelTotalNA1.Text = ModoPlantilla ? "Total % NA1:" : "Total NA1:";
1927  ewlabelTotalNA2.Text = ModoPlantilla ? "Total % NA2:" : "Total NA2:";
1928  }
1929  }
1930 
1934  private void ConfigurarGridSecundarias()
1935  {
1936  if (!_lSecundar)
1937  return;
1938 
1939  mantegridSecundarias._Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
1940  mantegridSecundarias._Grid.AutoGenerateColumns = false;
1941 
1942  string lcCaption = "";
1943 
1944  ConfigurarGridSecundariasNivelAnalitico1(lcCaption);
1945 
1946  if (!_lPlanAnaliticoCompleto)
1947  ConfigurarGridSecundariasNivelAnalitico2(lcCaption);
1948 
1949  RevisarTextTotales();
1950  if(ModoPlantilla)
1951  {
1952  //Controles de totales sólo visibles si repartimos porcentajes
1953  ewlabelTotalNA1.Visible = _lSecRepPorcentaje && !_lPlanAnaliticoCompleto;
1954  ewlabelTotalNA2.Visible = _lSecRepPorcentaje;
1955  ewtextboxTotalSecundarias.Visible = _lSecRepPorcentaje && !_lPlanAnaliticoCompleto;
1956  ewtextboxTotalSecundarias1.Visible = _lSecRepPorcentaje;
1957  }
1958  }
1959 
1960 
1965  private void ConfigurarGridSecundariasNivelAnalitico1(string tcCaption)
1966  {
1967  // Agregamos las columnas a presentar en la pantalla de asientos
1968  if (!mantegridSecundarias._Grid.Columns.Contains("CuentaNA1"))
1969  Documento_Add_Columna_Analitica_Grid(tnDisplayIndex: 0);
1970 
1971  if (mantegridSecundarias._Grid.Columns.Contains("NombreNA1"))
1972  mantegridSecundarias._Grid.Columns.Remove("NombreNA1");
1973 
1974  //Definim columna de definición
1976  {
1977  ldgtbColDefinicion1.Name = "NombreNA1";
1978  ldgtbColDefinicion1.DataPropertyName = _lPlanAnaliticoCompleto ? "_NombreNA1NA2" : "_Nombre";
1979  ldgtbColDefinicion1.HeaderText = "Nombre";
1980  ldgtbColDefinicion1.ValueType = typeof(string);
1981  ldgtbColDefinicion1.MinimumWidth = 200;
1982  ldgtbColDefinicion1.DisplayIndex = 1;
1983  ldgtbColDefinicion1._NoParar = true;
1984  ldgtbColDefinicion1.ReadOnly = true;
1985 
1986  if (_lPlanAnaliticoCompleto)
1987  ldgtbColDefinicion1.ToolTipText = "Nombre analítico";
1988  else
1989  ldgtbColDefinicion1.ToolTipText = "Nombre del nivel analítico 1";
1990 
1991  ldgtbColDefinicion1.SortMode = DataGridViewColumnSortMode.NotSortable;
1992  mantegridSecundarias._Grid.Columns.Add(ldgtbColDefinicion1);
1993  }
1994 
1995  // Importe
1996  if (mantegridSecundarias._Grid.Columns.Contains("Importe"))
1997  mantegridSecundarias._Grid.Columns.Remove("Importe");
1998 
2000  {
2001  ldgtbColImporte.Name = "Importe";
2002  ldgtbColImporte.DataPropertyName = _lPlanAnaliticoCompleto ? "_ImporteNA2" : "_ImporteNA1"; // Con la opción de planes analítico completo se ha de bindear com _ImporteNA2
2003  ldgtbColImporte.HeaderText = "Importe " + tcCaption;
2004  ldgtbColImporte.MinimumWidth = 100;
2005  ldgtbColImporte.DisplayIndex = 2;
2006  ldgtbColImporte.Visible = !ModoPlantilla;
2007 
2008  NumeriUpDownColProperties(ldgtbColImporte, _oMascaraImport);
2009 
2010  ldgtbColImporte.SortMode = DataGridViewColumnSortMode.NotSortable;
2011 
2012  mantegridSecundarias._Grid.Columns.Add(ldgtbColImporte);
2013  }
2014 
2015  if (mantegridSecundarias._Grid.Columns.Contains("Porcentaje"))
2016  mantegridSecundarias._Grid.Columns.Remove("Porcentaje");
2017 
2018  var propiedad = "_Porcentaje";
2019  if (_lPlanAnaliticoCompleto)
2020  propiedad = "_Porcentaje"; //Directamente con el porcentaje
2021  else
2022  {
2023  if(_lColNivel2Visible)
2024  propiedad = "_Porcentaje1";
2025  else
2026  propiedad = "_Porcentaje";
2027  }
2029  {
2030  ldgtbColPorcentaje.Name = "Porcentaje";
2031  ldgtbColPorcentaje.DataPropertyName = propiedad; // Con la opción de planes analítico completo se ha de bindear com _PorcentajeNA2
2032  ldgtbColPorcentaje.HeaderText = _lPlanAnaliticoCompleto ? $"% código analítico" : $"% C.NA1";
2033  ldgtbColPorcentaje.MinimumWidth = 100;
2034  ldgtbColPorcentaje.DisplayIndex = 3;
2035  ldgtbColPorcentaje.Visible = ModoPlantilla && _lColPorcentajeVisible;
2036  ldgtbColPorcentaje.ReadOnly = _lColNivel2Visible && !_lPlanAnaliticoCompleto; //Si el segundo % esta visible este es meramente informativo
2037 
2038  NumeriUpDownColProperties(ldgtbColPorcentaje, _oMascaraTpc);
2039 
2040  ldgtbColPorcentaje.SortMode = DataGridViewColumnSortMode.NotSortable;
2041 
2042  mantegridSecundarias._Grid.Columns.Add(ldgtbColPorcentaje);
2043  }
2044  }
2045 
2050  private void ConfigurarGridSecundariasNivelAnalitico2(string tcCaption)
2051  {
2052  //codigo nivel analítico 2
2053  if (!mantegridSecundarias._Grid.Columns.Contains("CuentaNA2"))
2054  {
2056  {
2057  ldgtbColCuenta2.Name = "CuentaNA2";
2058  ldgtbColCuenta2.DataPropertyName = "_Secnivel2";
2059  ldgtbColCuenta2.HeaderText = "C.NA2";
2060  ldgtbColCuenta2.ValueType = typeof(string);
2061  ldgtbColCuenta2.MinimumWidth = _nAnchoColumnaAnalitica; // De momento no utilizamos el PreferedSize. Si es necesario afinar más, se puede implementar;
2062  ldgtbColCuenta2.DisplayIndex = 4;
2063  ldgtbColCuenta2.ToolTipText = "Código nivel analítico 2";
2064  ldgtbColCuenta2.SortMode = DataGridViewColumnSortMode.NotSortable;
2065  ldgtbColCuenta2.Visible = _lColNivel2Visible;
2066  ldgtbColCuenta2.MaxInputLength = _nLenAnalitica;
2067 
2068  if (_lSecManual)
2069  {
2070  mantegridSecundarias._TeclaF4("CuentaNA2", _btBrowSecundar);
2071  mantegridSecundarias._TeclaF5("CuentaNA2", _btManteSecundar);
2072  }
2073 
2074  mantegridSecundarias._Grid.Columns.Add(ldgtbColCuenta2);
2075  }
2076  }
2077 
2078  //Definim columna de definición nivel analítico 2
2079  if (mantegridSecundarias._Grid.Columns.Contains("NombreNA2"))
2080  mantegridSecundarias._Grid.Columns.Remove("NombreNA2");
2081 
2083  {
2084  ldgtbColDefinicion2.Name = "NombreNA2";
2085  ldgtbColDefinicion2.DataPropertyName = "_Nombre2";
2086  ldgtbColDefinicion2.HeaderText = "Nombre";
2087  ldgtbColDefinicion2.ValueType = typeof(string);
2088  ldgtbColDefinicion2.MinimumWidth = 200;
2089  ldgtbColDefinicion2.DisplayIndex = 5;
2090  ldgtbColDefinicion2._NoParar = true;
2091  ldgtbColDefinicion2.ReadOnly = true;
2092  ldgtbColDefinicion2.Visible = _lColNivel2Visible;
2093 
2094  ldgtbColDefinicion2.ToolTipText = "Nombre del nivel analítico 2";
2095  ldgtbColDefinicion2.SortMode = DataGridViewColumnSortMode.NotSortable;
2096  mantegridSecundarias._Grid.Columns.Add(ldgtbColDefinicion2);
2097  }
2098 
2099  // Importe nivel analítico 2
2100  if (mantegridSecundarias._Grid.Columns.Contains("Importe1"))
2101  mantegridSecundarias._Grid.Columns.Remove("Importe1");
2102 
2104  {
2105  ldgtbColImporte1.Name = "Importe1";
2106  ldgtbColImporte1.DataPropertyName = "_ImporteNA2";
2107  ldgtbColImporte1.HeaderText = "Importe " + tcCaption;
2108  ldgtbColImporte1.MinimumWidth = 100;
2109  ldgtbColImporte1.DisplayIndex = 6;
2110  ldgtbColImporte1.Visible = _lColNivel2Visible && !ModoPlantilla;
2111 
2112  NumeriUpDownColProperties(ldgtbColImporte1, _oMascaraImport);
2113 
2114  ldgtbColImporte1.SortMode = DataGridViewColumnSortMode.NotSortable;
2115 
2116  mantegridSecundarias._Grid.Columns.Add(ldgtbColImporte1);
2117  }
2118 
2119  // Porcentaje nivel analítico 2
2120  if (mantegridSecundarias._Grid.Columns.Contains("Porcentaje1"))
2121  mantegridSecundarias._Grid.Columns.Remove("Porcentaje1");
2122 
2124  {
2125  ldgtbColPorcentaje1.Name = "Porcentaje1";
2126  ldgtbColPorcentaje1.DataPropertyName = "_Porcentaje";
2127  ldgtbColPorcentaje1.HeaderText = $"% C.NA2";
2128  ldgtbColPorcentaje1.MinimumWidth = 100;
2129  ldgtbColPorcentaje1.DisplayIndex = 7;
2130  ldgtbColPorcentaje1.Visible = _lColNivel2Visible && ModoPlantilla && _lColPorcentajeVisible;
2131 
2132  NumeriUpDownColProperties(ldgtbColPorcentaje1, _oMascaraTpc);
2133 
2134  ldgtbColPorcentaje1.SortMode = DataGridViewColumnSortMode.NotSortable;
2135 
2136  mantegridSecundarias._Grid.Columns.Add(ldgtbColPorcentaje1);
2137  }
2138  }
2139 
2145  private void Documento_Add_Columna_Analitica_Grid(int tnDisplayIndex = 0)
2146  {
2147  string lcName = string.Empty;
2148  string lcDataPropertyName = string.Empty;
2149  string lcHeaderText = string.Empty;
2150  string lcToolTipText = string.Empty;
2151 
2152  ConfigurarPropiedadesColumnaAnalitica(ref lcName, ref lcDataPropertyName, ref lcHeaderText, ref lcToolTipText);
2153 
2154  using (Mantegrid.ewDataGridViewTextBoxColumn ldgtbColPlanContable1 = new Mantegrid.ewDataGridViewTextBoxColumn())
2155  {
2156  // Plan contable 1
2157  ldgtbColPlanContable1.Name = lcName; // "CuentaNA1";
2158  ldgtbColPlanContable1.DataPropertyName = lcDataPropertyName; // "_CuentaNA1";
2159  ldgtbColPlanContable1.HeaderText = lcHeaderText; // "C.NA1";
2160  ldgtbColPlanContable1.ValueType = typeof(string);
2161  ldgtbColPlanContable1.Width = _nAnchoColumnaAnalitica; // De momento no utilizamos el PreferedSize. Si es necesario afinar más, se puede implementar;
2162  ldgtbColPlanContable1.MinimumWidth = _nAnchoColumnaAnalitica;
2163 
2164  ldgtbColPlanContable1.DisplayIndex = tnDisplayIndex;
2165  ldgtbColPlanContable1.ToolTipText = lcToolTipText; // "Código plan analítico 1";
2166  ldgtbColPlanContable1.SortMode = DataGridViewColumnSortMode.NotSortable;
2167 
2168  if (_lSecManual)
2169  {
2170  mantegridSecundarias._TeclaF4(lcName, _btBrowSecundar); // "PlanContable1";
2171  if (!_lPlanAnaliticoCompleto)
2172  mantegridSecundarias._TeclaF5(lcName, _btManteSecundar);
2173  }
2174 
2175  mantegridSecundarias._Grid.Columns.Add(ldgtbColPlanContable1);
2176  }
2177  }
2178 
2187  private void ConfigurarPropiedadesColumnaAnalitica(ref string tcName, ref string tcDataPropertyName, ref string tcHeaderText, ref string tcToolTipText)
2188  {
2189  tcName = $"CuentaNA1"; // Independientemente de como trabajemos el nombre de la primera columna de analítica se llamará "CuentaNA1". Posteriormente se utiliza el nombre para realizar diferentes acciones
2190 
2191  var prefijoPorcentaje = ModoPlantilla && _lColPorcentajeVisible ? "% " : "";
2192 
2193  if (_lPlanAnaliticoCompleto) // Plan analítico completo
2194  {
2195  tcDataPropertyName = "_CuentaNA1NA2";
2196  tcHeaderText = prefijoPorcentaje + "Código analítico";
2197  tcToolTipText = "Código analítico";
2198  }
2199  else
2200  {
2201  tcDataPropertyName = $"_Secundaria";
2202  tcHeaderText = prefijoPorcentaje + "C.NA1";
2203  tcToolTipText = $"Código nivel analítico 1";
2204  }
2205  }
2206 
2207  //private abstract class ModoFuncionamientoGrid
2208  //{
2209  // public abstract decimal TotalMaximoDeseado();
2210  //}
2211 
2214 
2216 
2219 
2221 
2222  //ModoFuncionamientoGrid _ControladorOperaciones = null;
2223 
2228  private decimal TotalMaximoDeseado()
2229  {
2230  decimal lnTotalDebeHaber = decimal.Zero;
2231 
2232  if (ModoPlantilla)
2233  {
2234  return 100M; //Va por porcentajes. Maximo 100
2235  }
2236  else
2237  {
2238  if (_oNegocio != null)
2239  lnTotalDebeHaber = _oNegocio.TotalLineaPredefinido();
2240  }
2241 
2242  return lnTotalDebeHaber;
2243  }
2244 
2249  private decimal TotalSecundariasN1()
2250  {
2251  decimal importe = decimal.Zero;
2252 
2253  if (_oNegocio != null)
2254  {
2255  if (ModoPlantilla)
2256  {
2257  return _oNegocio.TotalPorcentajeN1(_PlanContable);
2258  }
2259  else
2260  {
2261 
2262  return _oNegocio.TotalN1(_PlanContable);
2263  }
2264  }
2265 
2266  return importe;
2267  }
2268 
2273  private decimal TotalSecundariasN2()
2274  {
2275  decimal importe = decimal.Zero;
2276 
2277  if (_oNegocio != null)
2278  {
2279  if (ModoPlantilla)
2280  {
2281  return _oNegocio.TotalPorcentajeN2(_PlanContable);
2282  }
2283  else
2284  {
2285 
2286  return _oNegocio.TotalN2(_PlanContable);
2287  }
2288  }
2289 
2290  return importe;
2291  }
2292 
2293  # endregion Métodos privados
2294 
2295  # region Métodos públicos
2296 
2302  private bool RepartirImporte(bool accionDeUsuario = false)
2303  {
2304  BindingList<SecundariasPredefinidos.Secundaria> loSecundarias = _Negocio.GetLineasPlan(_PlanContable);
2305  var cantidadSecundarias = loSecundarias.AsEnumerable().Count(lin => lin._Secundaria != null && !string.IsNullOrWhiteSpace(lin._Secundaria));
2306 
2307  string lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
2308 
2309  if (cantidadSecundarias == 0) // Si no hay secundarias ya podemos salir
2310  {
2311  if (accionDeUsuario)
2312  FUNCTIONS._MessageBox($"No hay {lcDefMens} analíticos a recalcular.", lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
2313 
2314  return false;
2315  }
2316 
2317  _Negocio._RepartirImporte(_PlanContable, accionDeUsuario);
2318 
2319  //Binding();
2320 
2321  _RefrescarSecundarias();
2322 
2323  return true;
2324  }
2325 
2331  private bool RepartirPorcentaje(bool accionDeUsuario = false)
2332  {
2333  //BindingList<SecundariasPredefinidos.Secundaria> loSecundarias = _Negocio.CurrentPlan.Lineas;
2334  BindingList<SecundariasPredefinidos.Secundaria> loSecundarias = _Negocio.GetLineasPlan(_PlanContable);
2335  var cantidadSecundarias = loSecundarias.AsEnumerable().Count(lin => lin._Secundaria != null && !string.IsNullOrWhiteSpace(lin._Secundaria));
2336 
2337  string lcDefMens = (_lPlanAnaliticoCompleto ? "códigos" : "niveles");
2338 
2339  if (cantidadSecundarias == 0) // Si no hay secundarias ya podemos salir
2340  {
2341  if (accionDeUsuario)
2342  FUNCTIONS._MessageBox($"No hay {lcDefMens} analíticos a recalcular.", lcDefMens.Substring(0, 1).ToUpper() + lcDefMens.Substring(1).ToLower() + " analíticos", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button2);
2343 
2344  return false;
2345  }
2346 
2347  //_Negocio._RepartirPorcentaje(_PlanContable, accionDeUsuario: true);
2348  _Negocio._RepartirPorcentaje(_PlanContable);
2349 
2350  Binding();
2351 
2352  //_RefrescarSecundarias();
2353 
2354  return true;
2355  }
2356 
2361  {
2362  RefrescarTotalSecundarias(); // Actualizamos el total de las secundarias
2363 
2364  mantegridSecundarias._Grid.Refresh(); // Refrescamos la grid
2365  }
2366 
2370  public void _Focus()
2371  {
2372  if (_Grid.Rows.Count > 0)
2373  {
2374  if (_lSecManual)
2375  _Grid.Rows[0].Cells["CuentaNA1"].Selected = true;
2376  else
2377  {
2378  if (ModoPlantilla && _lColPorcentajeVisible)
2379  {
2380  _Grid.Rows[0].Cells["Porcentaje"].Selected = true;
2381  }
2382  else
2383  {
2384  _Grid.Rows[0].Cells["Importe"].Selected = true;
2385  }
2386  }
2387  }
2388 
2389  _Grid.Focus();
2390  }
2391  #endregion Métodos públicos
2392 
2393  #region Métodos protected override
2394  protected override void OnHandleCreated(EventArgs e)
2399  {
2400  base.OnHandleCreated(e);
2401 
2402  if (_lSecundar && _lPlanAnaliticoCompleto)
2403  {
2404  ewlabelTotalNA1.Visible = false;
2405  ewtextboxTotalSecundarias.Visible = false;
2406  }
2407  }
2408 
2415  protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
2416  {
2417  string lcColumna = string.Empty, lcNameButton = string.Empty;
2418 
2419  if (ActiveControl == mantegridSecundarias)
2420  {
2421  if ((keyData == Keys.Left && ColumnaActual() == "CuentaNA1") && _FocusLineaRelacionada != null && SecundariasRepartidas(true, true)) // Pasar el foco a las secundarias mediante la flecha de la izquiera a la grid de asientos
2422  {
2423  base.ProcessCmdKey(ref msg, keyData);
2424  _FocusLineaRelacionada();
2425  return true;
2426  }
2427 
2428  if (keyData == Keys.Add || keyData == Keys.Subtract)
2429  {
2430  lcColumna = ColumnaActual();
2431 
2432  if (lcColumna == "_Secnivel1" || lcColumna == "_Secnivel2")
2433  {
2434  if (keyData == Keys.Add)
2435  lcNameButton = "btBrowserCol";
2436  else
2437  lcNameButton = "btManteCol";
2438 
2439  ewbutton lobtBrowserCol = ((ewbutton)mantegridSecundarias.Controls[lcNameButton]);
2440 
2441  if (lobtBrowserCol != null)
2442  {
2443  if (lcNameButton == "btManteCol")
2444  {
2445  var linea = ObtenerNegocioDeLaLinea();
2446 
2447  if (linea != null)
2448  {
2449  string lcCuenta = lcColumna == "_Secnivel1" ? linea._Secundaria : linea._Secnivel2;
2450 
2451  ((btMante)lobtBrowserCol)._Codigo = lcCuenta;
2452  }
2453  }
2454 
2455  lobtBrowserCol.PerformClick();
2456  }
2457 
2458  return true;
2459  }
2460  }
2461  else if (keyData == Keys.F5 && !_lSecManual) // Si no tenemos el botón de browser capturamos el F5
2462  {
2463  lcColumna = ColumnaActual();
2464 
2465  if (lcColumna == "_Secnivel1" || lcColumna == "_Secnivel2")
2466  {
2467  NavegarMantenimientoNivelesAnaliticos();
2468  return true;
2469  }
2470  }
2471  else if (keyData == Keys.Escape && SecundariasDescuadradas(true)) // Si pulsa Escape pero tenemos las secundarias descuadradas no dejamos abandonar la grid
2472  return true;
2473  }
2474 
2475  return base.ProcessCmdKey(ref msg, keyData);
2476  }
2477  # endregion Métodos protected override
2478  }
2479 }
2480 
decimal _Rango_Max
Valor máximo según la máscara. Es la máscara de VFP convertida a decimal
Definition: clsEwBase.cs:6245
delegate void _DataSource_Row_Delete_Event_Handler(DataGridViewRow trRowDelete)
Se dispara al borrar un registro cuando el DataSource no es un DataTable
_RefreshImagenPlanAnaliticoHandler _RefreshImagenPlanAnalitico
Declaramos evento nuevo para poder refrescar la imagen relacionada con la linea relacionada ...
String _CondicionAutomatica
Texto para el filtro automático
void _RefrescarSecundarias()
Refrescamos las secundarias desde el formulario de asientos
virtual DataTable _DatatablePersonalizado
Datatable personalizado
_Click_After_Handler _Click_After
_Click_After_Handler
static System.Drawing.Bitmap settings_16
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
decimal TotalN1(string plan)
Obtiene una suma de los importes de N1
bool _AplicarEstilos
Aplicar estilo al control
void _RefreshDatatablePersonalizado(bool lbRefrescar=false)
Refresco del datatable personalizado Necesario al cambiar las propiedades relacionadas con la opción ...
_ReadOnly
_ReadOnly
Definition: clsPerfiles.cs:671
Clase para gestionar la información de planes analíticos asociados a una línea de asiento predefinido...
delegate void _DataSource_Row_New_Event_Handler(int tnInsertLinea)
Se dispara al añadir un nuevo registro cuando el DataSource no es un DataTable
Browser, basat en sage.ew.objetos.ewbutton
Muestra el browser de cuentas secundarias
Mostra el manteniment de comptes secundaries carregant el registre corresponent al _Codigo ...
delegate void _Click_Before_Handler(ref Boolean tlOk)
_Click_Before_Handler
Usercontrol de grid de secundarias de la pantalla de asientos
Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
KeyDiccionarioMascara
Clave para diccionario de máscaras
delegate void _Row_New_Before_Handler(ref bool tlOk, bool tlInsert=false)
Se dispara antes de insertar una nueva fila
string _Tooltip
Tooltip del control para asignar por código
void _Focus()
Pasamos el foco a la grid y activamos la celda
ewbuttonEstilosBase _PropiedadesDeEstilos
Objeto estilo
KeyDiccionarioLenCampos
Clave del diccionario LenCampos
Definition: Diccionarios.cs:11
Clase del objeto grid para Sage50
Definition: grid.cs:31
override bool ProcessCmdKey(ref Message msg, Keys keyData)
Gestión de las teclas rápidas de Contaplus: F4(+) y F5(-)
string _Plan
Plan a presentar con la opción de TRABAJAR SOLO CON NIVELES DEFINIDOS EN CADA PLAN ANALÍTICO ...
int _Num_Decimales
Número de decimales de la máscara
Definition: clsEwBase.cs:6240
delegate void _Row_New_After_Handler(DataGridViewRow tdgvRowLastInsert, bool tlInsert)
Se dispara despues de insertar una nueva fila
ModoPlantilla
Posibles Modos de Plantillas
delegate void _Click_After_Handler(Boolean tlAceptar)
_Click_After_Handler
Custom column type dedicated to the DataGridViewNumericUpDownCell cell type.
Definition: Mantegrid.cs:3451
Boolean _CondicionAutomaticaActiva
Filtrar automáticamente los registros si al acceder a los F4
Muestra el mantenimiento correspondiente a _Form con el registro correspondiente al _Codigo ...
delegate void _BeforeColChange_Handler(DataGridViewColumn tdgvCurrentCol, ref bool tlOk)
Se dispara antes de que se cambie la celda seleccionada en el grid
Proporciona características adicionales de las máscaras de Eurowin
Definition: clsEwBase.cs:6212
string _Codigo
valor del registro seleccionado por parte del usuario (readonly)
_Click_Before_Handler _Click_Before
_Click_Before_Handler
Base para los botones de Eurowin
string _Titulo
Titulo de la ventana
decimal TotalN2(string plan)
Obtiene una suma de los importes de N2
decimal TotalPorcentajeN2(string plan)
Obtiene una suma de los porcentajes de N2
decimal _Rango_Min
Valor mínimo según la máscara. Es la máscara de VFP convertida a decimal y en negativo ...
Definition: clsEwBase.cs:6250
string _Mascara_Net
Máscara convertida en formato .Net
Definition: clsEwBase.cs:6235
decimal TotalPorcentajeN1(string plan)
Obtiene una suma de los porcentajes de N1
Dictionary< string, object > _Codigo_List
Contendra los registros seleccionados si la propiedad _Seleccion_Multiple esta activada ...
static string _DefinicionPlanAnalitico(string tcCodigo)
Definición planes analíticos
decimal TotalLineaPredefinido()
Recupera el importe de la línea de predefinido asociada
int _Nivel
Nivel a presentar con la opción de TRABAJAR SOLO CON NIVELES DEFINIDOS EN CADA PLAN ANALÍTICO ...
string _Condicion
condición que se podrá especificar en el momento de realizar la consulta SQL
Presenta un datagridview con botones añadir y borrar tipo Mantegrid de Eurowin
Definition: Mantegrid.cs:30