CuentaOffice365.cs
1 using System;
2 using System.Windows.Forms;
3 using sage.ew.functions;
4 using sage.ew.ewbase;
5 using sage.ew.interficies;
6 using sage.ew.global;
7 
8 namespace sage.ew.o365.UserControls
9 {
13  public partial class CuentaOffice365 : UserControl, ICuentaOffice365UC
14  {
15 
16  #region PROPIEDADES
17 
21  //public ewMante _ewMante = null;
22  public GrupoEmpresa _GrupoEmpresa { get; set; } = null;
23 
24  #endregion PROPIEDADES
25 
26  #region PROPIEDADES privadas
27 
28  private bool _bUsingContactsCapture = false;
29 
30  #endregion
31 
32 
33  #region CONSTRUCTORES
34 
38  public CuentaOffice365()
39  {
40  if (!DesignMode)
41  {
42  InitializeComponent();
43  ConstructorPrivado();
44  }
45  }
46 
50  public CuentaOffice365(GrupoEmpresa toGrupo)
51  {
52  if (!DesignMode)
53  {
54  InitializeComponent();
55  _GrupoEmpresa = toGrupo;
56  ConstructorPrivado();
57  }
58  }
59 
63  private void ConstructorPrivado()
64  {
65  lblBusiness.Visible = false;
66  btBusinessCenter.Visible = false;
67 
68  btAsociarCuenta._GoogleAnalytics = true; //Task 103195
69  btLiberarCuenta._GoogleAnalytics = true; //Task 103195
70 
71  CambiosContactCapture();
72  }
73 
74  #endregion CONSTRUCTORES
75 
76 
77  #region EVENTOS
78 
79  //La definición del delegado esta en la interficie
83  //public delegate void _CuentaLiberadaDelegado();
84 
89 
90  #endregion EVENTOS
91 
92 
93  #region METODOS PRIVADOS
94 
95  private void CambiosContactCapture()
96  {
97  if (_GrupoEmpresa != null)
98  _bUsingContactsCapture = _GrupoEmpresa.IsConctactsEnabled();
99  else
100  {
101  GrupoEmpresa loGrupoTemp = new GrupoEmpresa();
102  _bUsingContactsCapture = loGrupoTemp.IsConctactsEnabled();
103  }
104 
105  if (_bUsingContactsCapture)
106  {
107  lblInfo.Text = "Configura desde esta opción una cuenta de Microsoft 365 Business Standard para activar la funcionalidad de copia de seguridad en la nube Cloud Backup y la sincronización con Outlook de los datos mas relevantes de Clientes,proveedores y sus contactos mediante Sage Apps";
108  lblBusiness.Visible = true;
109  btBusinessCenter.Visible = true;
110  }
111  else
112  {
113  lblInfo.Text = "Configura desde esta opción una cuenta de Microsoft 365 Business Standard para activar la funcionalidad de copia de seguridad en la nube Cloud Backup";
114  lblBusiness.Visible = false;
115  btBusinessCenter.Visible = false;
116  }
117  }
118 
124  private void btAsociarCuenta_Click(object sender, EventArgs e)
125  {
126  bool lbOk;
127 
128  //Llamada por reflection al AppAdapter de overdrive para logarse
129  Overdrive loOverdrive = new Overdrive();
130 
131  if (btAsociarCuenta.Text == "Actualizar credenciales")
132  {
133  //Si estamos actualizando credenciales, forzamos un logout para forzar a volver a logar, pero sin borrar datasets ni configuraciones
134  loOverdrive.LogoutOverDrive();
135  }
136 
137  lbOk = loOverdrive.LoginOverdrive();
138  if (lbOk)
139  {
140  btAsociarCuenta.Text = "Actualizar credenciales";
141  if (_bUsingContactsCapture)
142  {
143  btBusinessCenter.Visible = true;
144  lblBusiness.Visible = true;
145  }
146  else
147  {
148  btBusinessCenter.Visible = false;
149  lblBusiness.Visible = false;
150  }
151  btLiberarCuenta.Enabled = true;
152  txtCuentaO365.Text = loOverdrive.ObtenerUsuarioLogueado(); //Task 128909
153  EW_GLOBAL._SaveDbVariable("wl_o365", true);
154 
155  FUNCTIONS._MessageBox("Se ha logado con éxito a Microsoft365/Overdrive", "Login correcto", MessageBoxButtons.OK, MessageBoxIcon.Information);
156  }
157  else
158  {
159  FUNCTIONS._MessageBox("Login incorrecto a Microsoft365/Overdrive", "Login incorrecto", MessageBoxButtons.OK, MessageBoxIcon.Information);
160  }
161  }
162 
168  private void btLiberarCuenta_Click(object sender, EventArgs e)
169  {
170  bool lbOk;
171 
172  // Llamada por reflection al AppAdapter de overdrive para salir del logout
173  // Comprobar si hay que eliminar la configuración
174  DialogResult loResult = FUNCTIONS._MessageBox("Se eliminará la configuración que permite realizar las copias de seguridad Cloud Backup y la sincronización de datos con Outlook con Sage Contact. ¿Desea continuar?", "Liberar cuenta", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
175 
176  if (loResult == DialogResult.Yes)
177  {
178  // Resetear los campos de contacts y cloud para empresas y grupos y eliminar las tareas programadas en overdrive
179  if (!DesignMode)
180  {
181  _GrupoEmpresa._LiberarCuenta();
182  }
183 
184  Overdrive loOverdrive = new Overdrive();
185  lbOk = loOverdrive.LogoutOverDrive();
186  if (lbOk)
187  {
188  btAsociarCuenta.Text = "Asociar Cuenta";
189  lblBusiness.Visible = false;
190  btBusinessCenter.Visible = false;
191  btLiberarCuenta.Enabled = false;
192  txtCuentaO365.Text = ""; //Task 128909
193  EW_GLOBAL._SaveDbVariable("wl_o365", false);
194 
195  //CCR 166167 => Forzamos cierre para garantizar borrado de variables de sesión externas a Sage50c
196  var mensaje = $"Cuenta Office365/Overdrive liberada con éxito." + Environment.NewLine + Environment.NewLine + "Para el correcto funcionamiento es necesario reiniciar la aplicación.";
197  FUNCTIONS._MessageBox(mensaje, "Logout Overdrive", MessageBoxButtons.OK, MessageBoxIcon.Information);
198 
199  // Ejecutar método sobreescribible para poder realizar operaciones extra
200  _CuentaLiberada?.Invoke();
201 
202  //CCR 166167 => Forzamos cierre para garantizar borrado de variables de sesión externas a Sage50c
203  FUNCTIONS._CerrarAplicacion();
204  }
205  }
206  }
207 
213  private void btBusinessCenter_Click(object sender, EventArgs e)
214  {
215  System.Diagnostics.Process.Start("https://ceo365portal.na.sage.com/Home/Landing");
216  }
217 
218  #endregion METODOS PRIVADOS
219 
220 
221  #region METODOS PUBLICOS
222 
227  public bool _Login()
228  {
229  bool llOk = false;
230 
231  // Al Entrar al tab de Office365, comprobamos credenciales
232  // Llamada por reflection al AppAdapter de overdrive para logarse
233 
234  string lcMensajeErrorSO = "";
235  if (!FUNCTIONS._RequisitosVersionSO(out lcMensajeErrorSO)) //Requisitos mínimos de Sistema operativo para Overdrive
236  {
237  AutoClosingMessageBox._Show(lcMensajeErrorSO, "Requisitos de sistema operativo", 120000);
238  }
239 
240  Overdrive loOverdrive = new Overdrive();
241  llOk = loOverdrive.CheckLoginOverDrive();
242  if (llOk)
243  {
244  btAsociarCuenta.Text = "Actualizar credenciales";
245  if (_bUsingContactsCapture)
246  {
247  btBusinessCenter.Visible = true;
248  lblBusiness.Visible = true;
249  }
250  else
251  {
252  btBusinessCenter.Visible = false;
253  lblBusiness.Visible = false;
254  }
255  btLiberarCuenta.Enabled = true;
256  txtCuentaO365.Text = loOverdrive.ObtenerUsuarioLogueado(); //Task 128909
257  }
258  else
259  txtCuentaO365.Text = "";
260 
261  return llOk;
262  }
263 
264  #endregion METODOS PUBLICOS
265  }
266 }
bool LoginOverdrive()
PE-104237: Método para hacer el login o refrescar las credenciales de Overdrive para un determinado g...
Definition: Overdrive.cs:255
delegate void _CuentaLiberadaDelegado()
Definición del delegado para el evento que se disparará al liberar una cuenta de office 365 ...
static void _Show(string tcTexto, string tcTitulo, int tnTimeout)
Método show. Instancia la clase.
Definition: functions.cs:20562
Interficie de operaciones adicionales del UserControl CuentaOffice365
bool LogoutOverDrive()
PE-104237: Método para hacer logout de OverDrive
Definition: Overdrive.cs:284
CuentaOffice365(GrupoEmpresa toGrupo)
Constructor con mante
bool _Login()
Método para lanzar login de credenciales
PE-104237: Clase con métodos estáticos para realizar las llamadas por reflection al conector de AppAd...
Definition: Overdrive.cs:22
string ObtenerUsuarioLogueado()
Task 128909: Obtener Usuario Logueado a O365
Definition: Overdrive.cs:929
bool IsConctactsEnabled()
Task 184846: Obtener si está activada la variable que nos indica que Contacts/Capture han de ser visi...
Definition: GruposEmp.cs:2816
Task 137442. Usercontrol para la cuenta de Microsoft 365
bool CheckLoginOverDrive()
PE-104237: Comprobar la conexión con Overdrive si ya estamos o no logueados
Definition: Overdrive.cs:313
Clase para el control de grupos de empresa (nuevo enfoque en Sage50, desaparece el multiempresa...
Definition: GruposEmp.cs:40
_CuentaLiberadaDelegado _CuentaLiberada
Definición del delegado para el evento _CuentaLiberada
Clase auxiliar para mostrar mensajes de error que se cierren temporizados
Definition: functions.cs:20537