2 using System.Collections.Generic;
21 #region PROPIEDADES PUBLICAS 26 public override string _Nombre
34 if (value != base._Nombre) _Fichero._CambiaNombreImpresora(value);
45 if (_lisCampos.ContainsKey(
"TIPO"))
46 return Convert.ToInt32(_lisCampos[
"TIPO"]._NewVal.ToString());
52 if (_lisCampos.ContainsKey(
"TIPO"))
54 _lisCampos[
"TIPO"]._NewVal = value;
63 public string _Nombre_Puerto
67 if (_lisCampos.ContainsKey(
"NOMPORT"))
68 return _lisCampos[
"NOMPORT"]._NewVal.ToString();
74 if (_lisCampos.ContainsKey(
"NOMPORT"))
76 _lisCampos[
"NOMPORT"]._NewVal = value;
85 public int _Longitud_Papel
89 if (_lisCampos.ContainsKey(
"SALT_LIN"))
90 return Convert.ToInt32(_lisCampos[
"SALT_LIN"]._NewVal.ToString());
96 if (_lisCampos.ContainsKey(
"SALT_LIN"))
98 _lisCampos[
"SALT_LIN"]._NewVal = value;
107 public bool _Compcajon
111 if (_lisCampos.ContainsKey(
"COMPCAJON"))
112 return Convert.ToBoolean(_lisCampos[
"COMPCAJON"]._NewVal);
118 if (_lisCampos.ContainsKey(
"COMPCAJON"))
120 _lisCampos[
"COMPCAJON"]._NewVal = value;
129 public string _Abrir_Caja
133 if (_lisCampos.ContainsKey(
"ABRIR_CAJA"))
134 return _lisCampos[
"ABRIR_CAJA"]._NewVal.ToString();
140 if (_lisCampos.ContainsKey(
"ABRIR_CAJA"))
142 _lisCampos[
"ABRIR_CAJA"]._NewVal = value;
151 public string _Cortar_Papel
155 if (_lisCampos.ContainsKey(
"CORTAR_PAP"))
156 return _lisCampos[
"CORTAR_PAP"]._NewVal.ToString();
162 if (_lisCampos.ContainsKey(
"CORTAR_PAP"))
164 _lisCampos[
"CORTAR_PAP"]._NewVal = value;
174 public string _Nombre_Local
176 get {
return _Fichero._NombreLocal; }
177 set { _Fichero._NombreLocal = value; }
179 private string _cNombreLocal =
string.Empty;
182 private ewPrinterFile _Fichero
186 if(_oFichero == null)
187 _oFichero =
new ewPrinterFile(
this);
190 set { _oFichero = value; }
192 private ewPrinterFile _oFichero = null;
194 #endregion PROPIEDADES PUBLICAS 204 this._Clave =
"Codigo";
205 this._DataBase =
"TPV";
206 this._Tabla =
"IMPRESOR";
207 this._TituloMantenimiento =
"Mantenimiento de impresoras";
208 this._FormManteBaseType = typeof(tpv.Forms.frmImpresoras);
210 this._Pantalla =
"IMPRESOR";
213 #endregion CONSTRUCTORS 215 #region Métodos públicos 226 bool llOk = base._Save();
228 if (llOk && !esperandoCodigo)
229 llOk = _Fichero._WriteFile();
261 List<string> llisListaTablas =
new List<string>();
264 llisListaTablas.Clear();
265 llisListaTablas.Add(
"CAJAS");
268 llOk = llOk && !_Existen_Registros(
"TPV", llisListaTablas,
"IMPRESORA");
269 llOk = llOk && !_Existen_Registros(
"TPV", llisListaTablas,
"IMPRESORA2");
270 llOk = llOk && !_Existen_Registros(
"TPV", llisListaTablas,
"IMP_COCI");
271 llOk = llOk && !_Existen_Registros(
"TPV", llisListaTablas,
"IMP_RESUM");
274 return base._Delete();
276 this._Error_Message =
"Este código de impresora está siendo utilizado en alguna caja de venta. No se puede borrar.";
287 string lcErrorMessage =
string.Empty;
288 string lcImpresora =
string.Empty;
291 lcImpresora = this._Nombre_Local;
292 if (
string.IsNullOrWhiteSpace(lcImpresora)) lcImpresora = this._Nombre;
293 llOk = (!
string.IsNullOrWhiteSpace(lcImpresora));
295 lcImpresora = FUNCTIONS._GetPrinterDriver(lcImpresora);
297 if(
string.IsNullOrWhiteSpace(this._Abrir_Caja))
299 lcErrorMessage =
"No se ha definido el código para abrir el cajón.";
303 if (llOk && FUNCTIONS.SendStringToPrinter(lcImpresora,
this._Abrir_Caja, ref lcErrorMessage))
return true;
306 this._Error_Message = lcErrorMessage;
317 string lcErrorMessage =
string.Empty;
318 string lcImpresora =
string.Empty;
321 lcImpresora = this._Nombre_Local;
322 if (
string.IsNullOrWhiteSpace(lcImpresora)) lcImpresora = this._Nombre;
323 llOk = (!
string.IsNullOrWhiteSpace(lcImpresora));
325 lcImpresora = FUNCTIONS._GetPrinterDriver(lcImpresora);
327 if(llOk &&
string.IsNullOrWhiteSpace(this._Cortar_Papel))
329 lcErrorMessage =
"No se ha definido el código para cortar el papel.";
333 if(llOk && FUNCTIONS.SendStringToPrinter(lcImpresora,
this._Cortar_Papel, ref lcErrorMessage))
return true;
336 this._Error_Message = lcErrorMessage;
341 #endregion Métodos públicos 344 #region Métodos privados 347 private bool _Crear_Reports()
351 _Crear_Report(
"TICKET");
352 _Crear_Report(
"COBRO");
353 _Crear_Report(
"COCINA");
354 _Crear_Report(
"ENTREGA");
355 _Crear_Report(
"IPAGOVAR");
356 _Crear_Report(
"TICKETPV");
357 _Crear_Report(
"IRETIROS");
358 _Crear_Report(
"IREPOSI");
359 _Crear_Report(
"VALE");
360 _Crear_Report(
"COMPROBA");
361 _Crear_Report(
"COMP_EMV");
367 private bool _Crear_Report(
string tcTipoDoc)
371 string lcDefaultReport =
"";
372 string lcReport =
"";
373 string lcRutaReports = Path.Combine(global.EW_GLOBAL._GetVariable(
"wc_iniservidor").ToString(),
@"MODULOS\TPV\REPORTS\DOCS_TPV\");
376 lcReport = lcRutaReports + tcTipoDoc + _Codigo +
".FRX";
378 if (!Directory.Exists(lcRutaReports)) Directory.CreateDirectory(lcRutaReports);
380 if (!File.Exists(lcReport))
382 lcDefaultReport = lcRutaReports + tcTipoDoc +
".FRX";
383 if (File.Exists(lcDefaultReport))
385 File.Copy(lcDefaultReport, lcReport);
387 lcDefaultReport = lcRutaReports + tcTipoDoc +
".FRT";
388 lcReport = lcRutaReports + tcTipoDoc + _Codigo +
".FRT";
389 if (File.Exists(lcDefaultReport))
391 File.Copy(lcDefaultReport, lcReport);
405 String[] lcFiles = Directory.GetFiles(lcRutaReports, tcTipoDoc + _Codigo +
".*");
407 foreach(String lcFile
in lcFiles)
426 #endregion Métodos privados 437 private readonly
Impresora _oImpresora = null;
445 _oImpresora = toImpresora;
451 public string _NombreLocal
453 get {
return _Get_NombreLocal(); }
454 set { _Set_NombreLocal(value); }
456 private string _cNombreLocal =
string.Empty;
463 public string _NombreFichero
465 get {
return (Path.Combine(_cPathFichero, _cSafeFileName)).Trim(); }
476 protected string _cSafeFileName =
"EWPRNSET.INF";
483 private string _cTextoFichero =
string.Empty;
488 private string _cTextoFijo =
string.Empty;
493 private bool _lFicheroCargado =
false;
498 private Dictionary<string, string> _dicEquivalenciasImpresoras =
new Dictionary<string, string>();
503 private string _cEtiqueta =
"[Printers]";
509 private string _Get_NombreLocal()
511 if (!_lFicheroCargado) _ReadFile();
513 if (_dicEquivalenciasImpresoras.ContainsKey(_oImpresora._Nombre.TrimEnd()))
return _dicEquivalenciasImpresoras[_oImpresora._Nombre.TrimEnd()];
525 if (!_lFicheroCargado) _ReadFile();
527 if (
string.IsNullOrWhiteSpace(tcValor) ||
string.IsNullOrWhiteSpace(tcValor))
return;
529 lcClave = _oImpresora._Nombre.TrimEnd();
532 if (_dicEquivalenciasImpresoras.ContainsKey(lcClave))
534 _dicEquivalenciasImpresoras.Add(tcValor, _NombreLocal);
535 _dicEquivalenciasImpresoras.Remove(lcClave);
543 private void _Set_NombreLocal(
string tcValor)
545 if (!_lFicheroCargado) _ReadFile();
547 if (
string.IsNullOrWhiteSpace(_oImpresora._Nombre) ||
string.IsNullOrWhiteSpace(tcValor))
return;
549 string lcClave = _oImpresora._Nombre.TrimEnd();
552 if (_dicEquivalenciasImpresoras.ContainsKey(lcClave))
554 _dicEquivalenciasImpresoras[lcClave] = tcValor;
557 _dicEquivalenciasImpresoras.Add(lcClave, tcValor);
565 _lFicheroCargado =
false;
567 if (!_Existe_Fichero())
return false;
571 StreamWriter loStrmWrtr =
new StreamWriter(_NombreFichero);
574 _cTextoFichero = _cTextoFijo;
577 foreach (KeyValuePair<string,string> loDicItem
in _dicEquivalenciasImpresoras)
580 _cTextoFichero += (loDicItem.Key +
"=" + loDicItem.Value + Environment.NewLine);
583 loStrmWrtr.WriteLine(_cTextoFichero);
587 catch (Exception loEx)
589 functions.FUNCTIONS._MessageBox(loEx.Message,
"Error grabando el fichero",
590 MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
600 _lFicheroCargado =
false;
602 if (!_Existe_Fichero())
return;
610 string lcImpresoras =
string.Empty;
613 if (_cTextoFichero.Contains(_cEtiqueta))
616 _dicEquivalenciasImpresoras =
new Dictionary<string, string>();
619 _cTextoFijo = _cTextoFichero.Substring(0,(_cTextoFichero.IndexOf(_cEtiqueta) + _cEtiqueta.Length)) +Environment.NewLine;
622 lcImpresoras = _cTextoFichero.Substring((_cTextoFichero.IndexOf(_cEtiqueta) + _cEtiqueta.Length));
624 if (!
string.IsNullOrWhiteSpace(lcImpresoras))
626 string[] lcSeparador =
new string[] {
"\r\n" };
627 string[] laLineasImpresoras = lcImpresoras.Split(lcSeparador, StringSplitOptions.RemoveEmptyEntries);
629 if (laLineasImpresoras.Count() > 0)
632 foreach (
string lcImpresora
in laLineasImpresoras)
634 string[] laDetalleImpresora = lcImpresora.Split(
'=');
635 if (laDetalleImpresora.Count() > 1)
637 if (_dicEquivalenciasImpresoras.ContainsKey(laDetalleImpresora[0]))
639 _dicEquivalenciasImpresoras[laDetalleImpresora[0]] = laDetalleImpresora[1];
641 else _dicEquivalenciasImpresoras.Add(laDetalleImpresora[0], laDetalleImpresora[1]);
647 _lFicheroCargado =
true;
653 catch (Exception loEx)
655 functions.FUNCTIONS._MessageBox(loEx.Message,
"Error leyendo el fichero",
656 MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
664 private bool _Existe_Fichero()
671 if (!Directory.Exists(_cPathFichero) && (
string.IsNullOrWhiteSpace(_cPathFichero) ==
false)) Directory.CreateDirectory(_cPathFichero);
674 if (!File.Exists(_NombreFichero))
683 if (!_cTextoFichero.Contains(_cEtiqueta))
691 catch (Exception loEx)
693 functions.FUNCTIONS._MessageBox(loEx.Message,
"Operaciones previas con ficheros",
694 MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
702 private void leerFichero()
705 StreamReader loStrmRdr =
new StreamReader(_NombreFichero);
706 _cTextoFichero = loStrmRdr.ReadToEnd();
710 private void reemplazarFichero()
712 File.Delete(_NombreFichero);
716 private void crearFichero()
719 using (FileStream loFS = File.Create(_NombreFichero))
723 List<Byte[]> llisLineas =
new List<byte[]>();
724 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
";" + Environment.NewLine));
725 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; EWPRNSET.INF -- NO CANVIAR" + Environment.NewLine));
726 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
";" + Environment.NewLine));
727 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; En aquest fitxer es guarden les equivalencies d'impressores de TPV." + Environment.NewLine));
728 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; Des de la pantalla d'impressores de TPV es pot seleccionar la impressora" + Environment.NewLine));
729 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; local que correspondria a la impressora de TPV." + Environment.NewLine));
730 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; Amb això se soluciona el problema de que el terminal que te endollada la" + Environment.NewLine));
731 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; impressora no imprimeixi amb el registre de Impressores de TPV que utilitzen" + Environment.NewLine));
732 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"; els altres terminals." + Environment.NewLine));
733 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
";" + Environment.NewLine));
734 llisLineas.Add(
new UTF8Encoding(
true).GetBytes(
"[Printers]" + Environment.NewLine));
737 foreach (Byte[] loLinea
in llisLineas)
739 loFS.Write(loLinea, 0, loLinea.Length);
756 String lcQuery, lcPrinterName, lcPort =
""; ;
758 lcPrinterName = lcPrinter.Contains(
@"\") ? lcPrinter.Substring(lcPrinter.LastIndexOf(
@"\") + 1) : lcPrinter;
759 lcQuery =
string.Format(
"SELECT * from Win32_Printer WHERE Name LIKE '%{0}'", lcPrinterName);
761 using (ManagementObjectSearcher loSearcher =
new ManagementObjectSearcher(lcQuery))
762 using (ManagementObjectCollection loCol = loSearcher.Get())
766 foreach (ManagementObject printer
in loCol)
768 lcPrinterName = Convert.ToString(printer.GetPropertyValue(
"Name"));
769 if (lcPrinterName == lcPrinter) lcPort = Convert.ToString(printer.GetPropertyValue(
"PortName"));
Clase de negocio base para mantenimientos
bool _Send_Cortar_Papel()
Función que manda a la impresora el código de cortar papel
override bool _Save()
Override del método _Save
bool _Send_Abrir_Cajon()
Función que manda a la impresora el código de abrir el cajón
static string _ObtenerPuerto(String lcPrinter)
Bug 113424 Obtener puerto de impresora
void _CambiaNombreImpresora(string tcValor)
Establece el nombre local para la impresora
bool _WriteFile()
Función que escribe en el fichero
void _ReadFile()
Función que recupara el contenido del fichero
Clase EW_GLOBAL para gestionar las variables públicas de Eurowin, variables de empresa, variables de anchuras de campo, variables de mascaras, etc.
Clase auxiliar para gestionar el fichero EWPRNSET
override bool _Delete()
Método para eliminar impresoras
virtual string _Nombre
Campo nombre del mantenimiento. En este hay que basar los demás campos en las clases heredadas ...
Impresora()
Constructor por fefecto
_EstadosMantenimiento
Declaro un enum para los estados del mantenimiento.
ewPrinterFile(Impresora toImpresora)
Constructor con parámetros
override void _Load()
Override del método _Load