UserUsuarioPortal.cs
3 using sage.ew.functions;
4 using System;
5 using System.Collections.Generic;
6 using System.ComponentModel;
7 using System.Data;
8 using System.Drawing;
9 using System.Linq;
10 using System.Reflection.Emit;
11 using System.Text;
12 using System.Windows.Forms;
13 
14 namespace sage.addons.portalcli.Visual.UserControls
15 {
19  public partial class UserUsuarioPortal : UserControl
20  {
21 
22  #region PROPIEDADES PRIVADAS
23 
27  private CfgPortalCli _oPortalCli
28  {
29  get { return (_lModoAsistente ? ((FormAsistentePortal)this.FindForm())._PortalCli : null); }
30  }
31 
32  #endregion PROPIEDADES PRIVADAS
33 
34 
35  #region PROPIEDADES PUBLICAS
36 
40  public bool _ModoRestablecer
41  {
42  get { return _lModoRestablecer; }
43  set { _lModoRestablecer = value; }
44  }
45  private bool _lModoRestablecer = false;
46 
50  public bool _ModoAsistente
51  {
52  get { return _lModoAsistente; }
53  set { _lModoAsistente = value; }
54  }
55  private bool _lModoAsistente = false;
56 
60  public string _LabelUsuario
61  {
62  set
63  {
64  lblUsuarioPortal.Text = value;
65  RevisarVisual();
66  }
67  }
68 
72  public string _LabelPassword
73  {
74  set
75  {
76  lblPasswordUsuarioPortal.Text = value;
77  RevisarVisual();
78  }
79  }
80 
84  public string _UsuarioPortal
85  {
86  get { return txtUsuarioPortal.Text.Trim(); }
87  }
88 
92  public string _PasswordUsuarioPortal
93  {
94  get { return txtPasswordUsuarioPortal.Text.Trim(); }
95  }
96 
97  #endregion PROPIEDADES PUBLICAS
98 
99 
100  #region CONSTRUCTOR
101 
106  {
107  InitializeComponent();
108 
109  if (!DesignMode)
110  Constructor();
111  }
112 
116  private void Constructor()
117  {
118  txtPasswordUsuarioPortal.PasswordChar = '●';
119  SuscripcionEventos();
120  }
121 
122  #endregion CONSTRUCTOR
123 
124 
125  #region METODOS PUBLICOS
126 
131  public void _Load(string tcUsuarioSage50="")
132  {
133  CfgUser loCfgUser = null;
134 
135  if (string.IsNullOrWhiteSpace(tcUsuarioSage50))
136  tcUsuarioSage50 = PORTALCLI._Usuario.Trim();
137 
138  if (_lModoAsistente)
139  _oPortalCli._CfgUser._Load(tcUsuarioSage50);
140  else
141  loCfgUser = new CfgUser(tcUsuarioSage50);
142 
143  // Cargar datos usuario portal del cliente según usuario actual de Sage 50 seleccionado en el asistente
144  txtUsuarioPortal.Text = (_lModoAsistente ? _oPortalCli._CfgUser._UsuarioPortal.Trim() : loCfgUser._UsuarioPortal.Trim());
145  txtPasswordUsuarioPortal.Text = (!string.IsNullOrWhiteSpace(txtUsuarioPortal.Text) && !_lModoRestablecer ? "XXXXXXXX" : "");
146  _ReadOnly(false);
147  }
148 
153  public void _ReadOnly(bool tlReadOnly)
154  {
155  txtUsuarioPortal.ReadOnly = tlReadOnly || _lModoRestablecer;
156  txtPasswordUsuarioPortal.ReadOnly = tlReadOnly;
157  }
158 
163  public bool _Valid()
164  {
165  if (string.IsNullOrWhiteSpace(_UsuarioPortal) || string.IsNullOrWhiteSpace(_PasswordUsuarioPortal))
166  {
167  FUNCTIONS._MessageBox("Para poder seguir con el asistente debe indicar el Usuario del portal del cliente y/o contraseña.", "Asistente de configuración", MessageBoxButtons.OK, MessageBoxIcon.Information);
168  return false;
169  }
170 
171  return true;
172  }
173 
174  #endregion METODOS PUBLICOS
175 
176 
177  #region METODOS PRIVADOS
178 
182  private void SuscripcionEventos()
183  {
184  if (!_lModoRestablecer)
185  {
186  txtUsuarioPortal.GotFocus += TxtUsuarioPortal_GotFocus;
187  txtUsuarioPortal.LostFocus += TxtUsuarioPortal_LostFocus;
188  }
189  }
190 
194  private void CancelarSuscripcionEventos()
195  {
196  if (!_lModoRestablecer)
197  {
198  txtUsuarioPortal.GotFocus -= TxtUsuarioPortal_GotFocus;
199  txtUsuarioPortal.LostFocus -= TxtUsuarioPortal_LostFocus;
200  }
201  }
202 
206  private void RevisarVisual()
207  {
208  int lnWidthMax = Math.Max(lblUsuarioPortal.Width, lblPasswordUsuarioPortal.Width);
209  int lnLeft = lblUsuarioPortal.Left + lnWidthMax + 20;
210 
211  txtUsuarioPortal.Left = lnLeft;
212  txtPasswordUsuarioPortal.Left = lnLeft;
213  }
214 
220  private void TxtUsuarioPortal_GotFocus(object sender, EventArgs e)
221  {
222  txtUsuarioPortal.Tag = txtUsuarioPortal.Text;
223  }
224 
230  private void TxtUsuarioPortal_LostFocus(object sender, EventArgs e)
231  {
232  if (!_lModoAsistente)
233  return;
234 
235  if (txtUsuarioPortal.ReadOnly || (Convert.ToString(txtUsuarioPortal.Tag).Trim() == txtUsuarioPortal.Text.Trim()))
236  return;
237 
238  // Comprobar si el email introducido ya se ha configurado en otro usuario de Sage 50
239  if (!string.IsNullOrWhiteSpace(txtUsuarioPortal.Text) && _oPortalCli._CfgUser._UsuarioPortalUsado(txtUsuarioPortal.Text))
240  {
241  FUNCTIONS._MessageBox("El nombre de usuario del portal del cliente que has introducido ya está asignado a otro usuario de Sage 50, introduce otro nombre de usuario o contacta con tu despacho para que te proporcione unas credenciales nuevas para el usuario de Sage 50.", "Asistente de configuración", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
242  txtUsuarioPortal.Text = "";
243  txtUsuarioPortal.Focus();
244  }
245  }
246 
247  #endregion METODOS PRIVADOS
248 
249  }
250 }
Este es el espacio de nombres de su módulo. Puede encontrar más información y ayuda en el fichero rea...
void _ReadOnly(bool tlReadOnly)
Estado readonly de los objetos
string _UsuarioPortal
Usuario portal
Definition: CfgUser.cs:42
Asistente para la configuración acceso Portal Cliente con Sage Despachos
Clase principal de configuraciones para el Add-on del Portal del Cliente Contendrá instancias a las c...
Definition: CfgPortalCli.cs:14
Usercontrol con el usuario y password para el acceso al Portal del cliente