btSkype.cs
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Drawing;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
10 using sage.ew.global;
11 using sage.ew.objetos;
12 using sage.ew.interficies;
13 using sage.ew.functions;
14 
15 namespace sage.ew.botones.Clases
16 {
20  public enum TipoContacto
21  {
25  User,
29  Telephone
30  }
31 
35  public class btSkype : ewbutton
36  {
40  [Browsable(true)]
41  public dynamic _oEntidad = null;
42 
46  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
47  [Category("Varios EW"),
48  DisplayName("Imagen del boton activo"),
49  DefaultValue(""),
50  Description("Obtiene o establece la imagen del botón cuando esta activo."),
51  Localizable(false),
52  Browsable(true)]
53  public Image _Image_On
54  {
55  get { return _iImage_On; }
56  set { _iImage_On = value; }
57  }
58  private Image _iImage_On = sage.ew.images.Properties.Resources.skype_32;
59 
63  [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
64  [Category("Varios EW"),
65  DisplayName("Imagen del boton inactivo"),
66  DefaultValue(""),
67  Description("Obtiene o establece la imagen del botón cuando esta inactivo."),
68  Localizable(false),
69  Browsable(true)]
70  public Image _Image_Off
71  {
72  get { return _iImage_Off; }
73  set { _iImage_Off = value; }
74  }
75  private Image _iImage_Off = sage.ew.images.Properties.Resources.skype_gray_32;
76 
80  public Dictionary<string, string> _Users = new Dictionary<string, string>() { };
81 
85  public Dictionary<string, string> _Telephones = new Dictionary<string, string>() { };
86 
90  private Dictionary<string, TipoContacto> _ValidContacts
91  {
92  get
93  {
94  string lcKey = "";
95  Dictionary<string, TipoContacto> llTotal = new Dictionary<string, TipoContacto>();
96  if (this._Users != null)
97  {
98  foreach (var item in this._Users)
99  {
100  lcKey = item.Key.Trim() + (string.IsNullOrWhiteSpace(item.Value) ? "" : " (" + item.Value + ")");
101  if (!string.IsNullOrWhiteSpace(item.Key) && !llTotal.ContainsKey(lcKey))
102  llTotal.Add(lcKey, TipoContacto.User);
103  }
104  }
105  if (this._Telephones != null)
106  {
107  foreach (var item in this._Telephones)
108  {
109  lcKey = item.Key.Trim() + (string.IsNullOrWhiteSpace(item.Value) ? "" : " (" + item.Value + ")");
110  if (!string.IsNullOrWhiteSpace(item.Key) && !llTotal.ContainsKey(lcKey))
111  llTotal.Add(lcKey, TipoContacto.Telephone);
112  }
113  }
114  return llTotal;
115  }
116  }
117 
118  private bool _lCleared = false;
119 
120  private string _lcPrefijoTelefonico = "";
124  public string _PrefijoTelefonico
125  {
126  get
127  {
128  if (string.IsNullOrWhiteSpace(_lcPrefijoTelefonico))
129  this._lcPrefijoTelefonico = sage.ew.functions.FUNCTIONS._GetPrefix();
130  return this._lcPrefijoTelefonico;
131  }
132  }
133 
137  public btSkype()
138  {
139  //Centrem l'imatge
140  this.BackgroundImageLayout = ImageLayout.Center;
141 
142  //Context menu
143  ContextMenuStrip loMenu = new ContextMenuStrip();
144  loMenu.Opened += new EventHandler(ContextMenuStrip_Click);
145  loMenu.Click += new EventHandler(ContextMenuStrip_Click);
146  loMenu.ItemClicked += new ToolStripItemClickedEventHandler(ContextMenuStrip_ItemClicked);
147  this.ContextMenuStrip = loMenu;
148 
149  //Click sobre el defecte
150  this.Click += new EventHandler(ewbtSkype_Click);
151 
152  this._Refresh();
153  }
154 
160  void ewbtSkype_Click(object sender, EventArgs e)
161  {
162  //Refresquem dades
163  this._RefreshDatos();
164 
165  //Mirem si hi ha contactes
166  if (this._ValidContacts.Count > 0)
167  {
168  //Montem el menu contextual
169  ToolStripMenuItem menuItem = null;
170  this.ContextMenuStrip.Items.Clear();
171  foreach (var item in this._ValidContacts)
172  {
173  menuItem = new ToolStripMenuItem();
174  menuItem.Text = item.Key;
175  menuItem.Tag = (TipoContacto)item.Value;
176  if ((TipoContacto)item.Value == TipoContacto.User)
177  menuItem.Image = Resources.user32_sage50_black;
178  else
179  menuItem.Image = Resources.telefono_16x16;
180  this.ContextMenuStrip.Items.Add(menuItem);
181  }
182  Button btnSender = (Button)sender;
183  Point ptLowerLeft = new Point(0, btnSender.Height); // - (btnSender.Margin.Vertical + btnSender.Padding.Vertical));
184  ptLowerLeft = btnSender.PointToScreen(ptLowerLeft);
185  this.ContextMenuStrip.Show(ptLowerLeft);
186  }
187  else
188  {
189  FUNCTIONS._MessageBox("Debe haber declarado al menos un número de teléfono válido para realizar la llamada Skype.", "Llamada Skype", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
190  }
191  }
192 
197  private void _ShowSkype(string tcContact = "")
198  {
199  if (!string.IsNullOrWhiteSpace(tcContact))
200  {
201  //Llamamos al usuario
202  skype.SkypePlugin loSkype = skype.SkypePlugin.Instance;
203  loSkype._Call(tcContact);
204 
205  //PE-104237: Guardar Log de la llamada de Skype en C_EMAIL
206  this._GuardarLogLlamadaSkype(tcContact);
207  }
208  }
209 
214  private void _GuardarLogLlamadaSkype(string tcContact)
215  {
216  //Parsear tcContact y quedarnos con el valor de antes del paréntesis
217  string lcValor = string.Empty;
218  string lcCliente = string.Empty;
219  string lcProveedor = string.Empty;
220 
221  lcValor = tcContact.Split('(')[0].Trim();
222 
223  usuario.Usuario loUsuario = usuario.Usuario._This;
224 
225  //Dependiendo de si estamos en cliente o proveedor, rellenamos un campo o otro
226  if (_oEntidad is cliente.Cliente)
227  lcCliente = _oEntidad._Codigo;
228  else if (_oEntidad is docscompra.Proveedor)
229  lcProveedor = _oEntidad._Codigo;
230 
231  functions.FUNCTIONS.GuardarLogEnvioEmail(loUsuario._Codigo, "", lcValor, "", Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa")), lcCliente, lcProveedor, tcTipo: "Llamada por Skype");
232  }
233 
234  void ContextMenuStrip_Click(object sender, EventArgs e)
235  {
236  this.BringToFront();
237  }
238 
244  void ContextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
245  {
246  string lcContact = e.ClickedItem.Text.ToString();
247  TipoContacto loTipo = (TipoContacto)e.ClickedItem.Tag;
248  switch (loTipo)
249  {
250  case TipoContacto.User:
251  //Truquem
252  this._ShowSkype(lcContact);
253  break;
254  case TipoContacto.Telephone:
255  //Afegim prefix
256  if (lcContact.IndexOf('+') != 0)
257  lcContact = this._PrefijoTelefonico + lcContact;
258  //Truquem
259  this._ShowSkype(lcContact);
260  break;
261  }
262  }
263 
267  public void _Clear()
268  {
269  this._Users.Clear();
270  this._Telephones.Clear();
271  this._lCleared = true;
272  }
273 
277  protected void _RefreshDatos()
278  {
279  if (this._oEntidad != null)
280  {
281  //Borramos resultados anteriores
282  this._Clear();
283  //Tratamos entidad
284  string lcTemp = "";
285  if (this._oEntidad is sage.ew.docscompra.Proveedor)
286  {
287  //Recuperem proveedor
288  sage.ew.docscompra.Proveedor tmpProv = (sage.ew.docscompra.Proveedor)this._oEntidad;
289  //Usuarios skype
290  if (!string.IsNullOrWhiteSpace(tmpProv._Skype))
291  {
292  if (!this._Users.ContainsKey(tmpProv._Skype))
293  this._Users.Add(tmpProv._Skype, tmpProv._Nombre);
294  }
295  foreach (var item in tmpProv._TRelContacTelefs._Items.ToList<sage.ew.docscompra.Proveedor.ContacTelefs.ContacTelef>().OrderByDescending(o => o._Predet).ToList())
296  {
297  if (!string.IsNullOrWhiteSpace(item._Skype) && !this._Users.ContainsKey(item._Skype))
298  this._Users.Add(item._Skype, item._Persona.Trim());
299  }
300  //Telefonos del proveedor
301  foreach (var item in tmpProv._TRelContacTelefs._Items.ToList<sage.ew.docscompra.Proveedor.ContacTelefs.ContacTelef>().OrderByDescending(o => o._Predet).ToList())
302  {
303  lcTemp = tmpProv._PrefijoTelefonico + item._Telefono;
304  if (!string.IsNullOrWhiteSpace(item._Telefono) && !this._Telephones.ContainsKey(lcTemp))
305  this._Telephones.Add(tmpProv._PrefijoTelefonico + item._Telefono,
306  !string.IsNullOrWhiteSpace(item._Persona) ? item._Persona.Trim() : tmpProv._Nombre); //item._Predet ? tmpProv._Nombre : "");
307  }
308  }
309  else if (this._oEntidad is sage.ew.cliente.Cliente)
310  {
311  //Recuperem client
312  sage.ew.cliente.Cliente tmpCli = (sage.ew.cliente.Cliente)this._oEntidad;
313  //Usuarios skype
314  if (!string.IsNullOrWhiteSpace(tmpCli._Skype))
315  {
316  if (!this._Users.ContainsKey(tmpCli._Skype))
317  this._Users.Add(tmpCli._Skype, tmpCli._Nombre);
318  }
319  foreach (var item in tmpCli._TRelContacTelefs._Items.ToList<sage.ew.cliente.Cliente.ContacTelefs.ContacTelef>().OrderByDescending(o => o._Predet).ToList())
320  {
321  if (!string.IsNullOrWhiteSpace(item._Skype) && !this._Users.ContainsKey(item._Skype))
322  this._Users.Add(item._Skype, item._Persona.Trim());
323  }
324  //Telefonos del cliente
325  foreach (var item in tmpCli._TRelContacTelefs._Items.ToList<sage.ew.cliente.Cliente.ContacTelefs.ContacTelef>().OrderByDescending(o => o._Predet).ToList())
326  {
327  lcTemp = tmpCli._PrefijoTelefonico + item._Telefono;
328  if (!string.IsNullOrWhiteSpace(item._Telefono) && !this._Telephones.ContainsKey(lcTemp))
329  {
330  this._Telephones.Add(tmpCli._PrefijoTelefonico + item._Telefono,
331  !string.IsNullOrWhiteSpace(item._Persona) ? item._Persona.Trim() : tmpCli._Nombre); //item._Predet ? tmpCli._Nombre : "");
332  }
333  }
334  }
335  else if (this._oEntidad is sage.ew.cliente.FuturoCliente)
336  {
337  // PE-101270. Recuperar teléfonos del cliente potencial
338  sage.ew.cliente.FuturoCliente tmpFutCli = (sage.ew.cliente.FuturoCliente)this._oEntidad;
339 
340  if (!string.IsNullOrWhiteSpace(tmpFutCli._Mobil) && !this._Telephones.ContainsKey(tmpFutCli._Mobil))
341  this._Telephones.Add( tmpFutCli._Mobil, "Móvil");
342 
343  if (!string.IsNullOrWhiteSpace(tmpFutCli._Telefono) && !this._Telephones.ContainsKey(tmpFutCli._Telefono))
344  this._Telephones.Add(tmpFutCli._Telefono, "Teléfono");
345 
346  if (!string.IsNullOrWhiteSpace(tmpFutCli._Fax) && !this._Telephones.ContainsKey(tmpFutCli._Fax))
347  this._Telephones.Add(tmpFutCli._Fax, "Fax");
348 
349  }
350  this._lCleared = false;
351  }
352  }
353 
357  public virtual void _Refresh(dynamic toObject = null)
358  {
359  //Guardem l'entitat de la que recuperarem les dades
360  if (toObject != null && (this._oEntidad != toObject || this._lCleared))
361  {
362  this._oEntidad = toObject;
363  this._RefreshDatos();
364  }
365 
366  if (this._ValidContacts.Count > 0)
367  {
368  this.BackgroundImage = this._Image_On;
369  this.Enabled = true;
370  }
371  else
372  {
373  this.BackgroundImage = this._Image_Off;
374  this.Enabled = false;
375  }
376  }
377  }
378 }
Clase de negocio para Futuros Clientes
Definir la estructura de las líneas de contactos-teléfonos de clientes
Definition: clsCliente.cs:454
static System.Drawing.Bitmap skype_32
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
static System.Drawing.Bitmap telefono_16x16
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
static System.Drawing.Bitmap user32_sage50_black
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
static System.Drawing.Bitmap skype_gray_32
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
Clase de negocio Proveedor
Definition: Proveedor.cs:33
TipoContacto
Tipo de contacto
Definition: btSkype.cs:20
Contactos y teléfonos de proveedores, clase de negocio de la nueva tabla GESTION!CONTLF_PRO resultado...
Definition: Proveedor.cs:41
virtual void _Refresh(dynamic toObject=null)
Refresco del control
Definition: btSkype.cs:357
void _RefreshDatos()
Refrescar Datos
Definition: btSkype.cs:277
Clase para uso de funciones genéricas
Definition: functions.cs:146
string _PrefijoTelefonico
Prefijo telefonico del proveedor (según país).
Definition: Proveedor.cs:7189
Base para los botones de Eurowin
void _Clear()
Borra todos los usuarios y telefonos asociados al botón
Definition: btSkype.cs:267
Definir la estructura de las líneas de contactos-teléfonos de proveedores
Definition: Proveedor.cs:427
string _PrefijoTelefonico
Prefijo telefonico del cliente (según país)
Contactos y teléfonos de clientes, clase de negocio de la nueva tabla GESTION!CONTLF_CLI resultado de...
Definition: clsCliente.cs:53
btSkype()
Constructor vacio
Definition: btSkype.cs:137