clsClasificacionArticulos.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using sage.ew.ewbase;
6 using sage.ew.articulo;
7 using System.Data;
8 using sage.ew.db;
9 using System.ComponentModel;
10 using System.Drawing;
11 using sage.ew.functions;
12 
13 namespace sage.ew.tpv
14 {
19  {
20  #region Propiedades
21 
22  //public string _Codigo
26  public override string _Codigo //= string.Empty;
27  {
28  get
29  {
30  return base._Codigo;
31  }
32  set
33  {
34  base._Codigo = value;
35  if (_lisCampos.ContainsKey("CODIGO")) //Actualitzo el camp equivalent
36  {
37  _lisCampos["CODIGO"]._NewVal = value;
38  _Exportar_Null();
39  }
40 
41  }
42  }
43 
47  public Int32 _ColorFondo
48  {
49  get
50  {
51  return _lisCampos.ContainsKey("BACKCOLOR") ? _TranslateColor(_lisCampos["BACKCOLOR"]._NewVal.ToString()) : 0;
52  }
53  set
54  {
55  if (_lisCampos.ContainsKey("BACKCOLOR"))
56  {
57  _lisCampos["BACKCOLOR"]._NewVal = value;
58  _Exportar_Null();
59  }
60  }
61  }
62 
66  public Int32 _ColorFuente
67  {
68  get
69  {
70  return _lisCampos.ContainsKey("FORECOLOR") ? _TranslateColor(_lisCampos["FORECOLOR"]._NewVal.ToString()) : 0;
71  }
72  set
73  {
74  if (_lisCampos.ContainsKey("FORECOLOR"))
75  {
76  _lisCampos["FORECOLOR"]._NewVal = value;
77  _Exportar_Null();
78  }
79  }
80  }
81 
82 
86  public string _Fuente
87  {
88  get
89  {
90  if (_lisCampos.ContainsKey("FONTTPV"))
91  return _lisCampos["FONTTPV"]._NewVal.ToString();
92  else
93  return "";
94  }
95  set
96  {
97  if (_lisCampos.ContainsKey("FONTTPV"))
98  {
99  _lisCampos["FONTTPV"]._NewVal = value;
100  _Exportar_Null();
101  }
102  }
103  }
104 
108  public string _Foto
109  {
110  get
111  {
112  if (_lisCampos.ContainsKey("FOTO"))
113  return _lisCampos["FOTO"]._NewVal.ToString();
114  else
115  return "";
116  }
117  set
118  {
119  if (_lisCampos.ContainsKey("FOTO"))
120  {
121  _lisCampos["FOTO"]._NewVal = value;
122  _Exportar_Null();
123  }
124  }
125  }
126 
130  public BindingList<ArticulosClasifica> _Articulos = new BindingList<ArticulosClasifica>();
131 
132  private string _cDatabaseDetalle = "COMUNES";
133  private string _cTablaDetalle = "ART_CLASIF";
134 
138  private List<string> _ArticulosClasif = new List<string>();
139 
140  #endregion Propiedades
141 
142  #region Constructores
143 
144 
149  {
150  this._Clave = "CODIGO";
151  this._DataBase = "COMUNES";
152  this._Tabla = "CLASIF";
153  this._TituloMantenimiento = "Mantenimiento de clasificaciones"; // PARTE 92701
154  this._Pregunta_Borrar = "¿Desea eliminar el registro?";
155  this._Pantalla = "CLASIFICA"; // PARTE 88499
156  this._FormManteBaseType = typeof(sage.ew.tpv.Forms.frmClasificacionArticulos);
157  }
158 
159  #endregion Constructores
160 
165  public override void _Load()
166  {
167  string lcSql = string.Empty;
168  DataTable loDt;
169 
170  //Invoco al método de la base
171  base._Load();
172 
173  #region Recuperación del detalle
174 
175  //Limpio el detalle de artículos
176  _Articulos.Clear();
177 
178  loDt = new DataTable();
179  if (!string.IsNullOrEmpty(_Codigo))
180  {
181  lcSql = $"SELECT * FROM {DB.SQLDatabase(_cDatabaseDetalle, _cTablaDetalle) } WHERE CLASIF = { DB.SQLString(_Codigo) }";
182  //Si ha ido bien y tengo resultados monto las líneas
183  if (DB.SQLExec(lcSql, ref loDt) && loDt.Rows.Count > 0)
184  {
185  //Construyo una linea de portes por registro
186  foreach (DataRow ldrArticuloClasificado in loDt.Rows)
187  {
188  _Articulos.Add(new ArticulosClasifica(this, ldrArticuloClasificado));
189  }
190  }
191 
192  FUNCTIONS._DisposeDatatable(loDt);
193  }
194 
195  _ArticulosClasif = _Articulos.Select(f => f._Articulo.Trim()).ToList();
196 
197  #endregion Recuperación del detalle
198 
199  }
200 
201 
205  protected override void _DescargarDatos()
206  {
207  base._DescargarDatos();
208 
209  _ArticulosClasif.Clear();
210 
211  return;
212  }
213 
219  private int _TranslateColor(string tcColor)
220  {
221  Int32 lnColor = 0;
222 
223  if (!Int32.TryParse(tcColor, out lnColor) && !String.IsNullOrWhiteSpace(tcColor))
224  {
225  Color loColor = Name_To_Color(tcColor);
226  lnColor = System.Drawing.ColorTranslator.ToWin32(loColor);
227  }
228 
229  return lnColor;
230  }
231 
232 
238  private Color Name_To_Color(string tcNomColor)
239  {
240  Color loColor;
241 
242  // Primer mirem si és un SystemColor
243  if (tcNomColor.Substring(0, 1) == "#")
244  loColor = ColorTranslator.FromHtml(tcNomColor);
245  else
246  loColor = Color.FromName(tcNomColor.Trim());
247 
248  return loColor;
249  }
250 
257  public override bool _Delete()
258  {
259  bool llOk = false;
260 
261  llOk = base._Delete();
262 
263  //Elimino el registro de la tabla principal
264  string lcSql = string.Empty;
265  lcSql = "DELETE FROM " + DB.SQLDatabase(_DataBase, _Tabla) + " " +
266  "WHERE CODIGO = " + DB.SQLString(this._Codigo) + " ";
267  llOk = DB.SQLExec(lcSql);
268 
269  //Elimino el detalle
270  lcSql = "DELETE FROM " + DB.SQLDatabase(_cDatabaseDetalle, _cTablaDetalle ) + " " +
271  "WHERE CLASIF = " + DB.SQLString(this._Codigo) + " ";
272  llOk = llOk && DB.SQLExec(lcSql);
273 
274  return llOk;
275  }
276 
281  public override bool _Save()
282  {
283 
284  ArticulosClasifica loRegBlanco = _Articulos.Where(x => string.IsNullOrWhiteSpace(x._Articulo)).FirstOrDefault();
285  if (loRegBlanco != null)
286  _Articulos.Remove(loRegBlanco);
287 
288  List<ArticulosClasifica> loInvalidos = new List<ArticulosClasifica>();
289 
290  foreach(string lcArticulosClasifica in _ArticulosClasif)
291  {
292  if(!_Articulos.Any(f=>f._Articulo.Trim() == lcArticulosClasifica.Trim()))
293  {
294  if (!new ArticulosClasifica(this, lcArticulosClasifica)._Delete()) return false;
295  }
296  }
297 
298  //Grabo el detalle: Invoco al método de grabación lineal (para aquellos no nulos)
299  foreach (ArticulosClasifica loArticuloClasificado in _Articulos)
300  {
301  if (!string.IsNullOrWhiteSpace(loArticuloClasificado._Articulo))
302  {
303  // Si no está en la lista que cargué al hacer el _Load() es que han creado el registro.
304  // Si ya está en la lista que cargué al hacer el _Load() y sigue estando quiere decir que no lo han borrado, luego no hay
305  // que hacer nada.
306  //
307  if (!_ArticulosClasif.Contains(loArticuloClasificado._Articulo.Trim()))
308  {
309  if (!loArticuloClasificado._Save())
310  return false;
311  }
312  }
313  }
314 
315  //Grabo el registro principal
316  return base._Save();
317  }
318 
322  public class ArticulosClasifica
323  {
324  #region Propiedades públicas
325 
329  public bool IsNew { get; set; } = true;
330 
334  public string _Articulo
335  {
336  get { return _cArticulo; }
337  set
338  {
339  _cArticulo = value;
340  if (!string.IsNullOrWhiteSpace(_cArticulo))
341  {
342  Articulo loArt = new Articulo(_cArticulo);
343  loArt._Load();
344  _cNombre = loArt._Nombre;
345  }
346  else _cNombre = string.Empty;
347  }
348  }
349  private string _cArticulo = string.Empty;
350 
354  public string _Nombre
355  {
356  get { return _cNombre; }
357  //set { _cArticulo = value; }
358  }
359  private string _cNombre = string.Empty;
360 
361  #endregion Propiedades públicas
362 
363  #region Propiedades privadas
364 
368  private ClasificacionArticulos _oClasificacion = null;
369 
370  #endregion Propiedades privadas
371 
372  #region Constructores
373 
378  {
379  }
380 
386  public ArticulosClasifica(ClasificacionArticulos toClasificacion, string tcArticulo)
387  {
388  //Asigno la clase relacionada
389  _oClasificacion = toClasificacion;
390 
391  this._Articulo = tcArticulo;
392  }
393 
399  public ArticulosClasifica(ClasificacionArticulos toClasificacion, DataRow tdrRow = null)
400  {
401  //Asigno la clase relacionada
402  _oClasificacion = toClasificacion;
403 
404  //Recupero el detalle desde el DataRow
405  if (tdrRow != null)
406  {
407  IsNew = false;
408  _Articulo = Convert.ToString(tdrRow["ARTICULO"]);
409  }
410  }
411 
412  #endregion Constructores
413 
414  #region Métodos
415 
420  public bool _Save()
421  {
422  string lcSql = string.Empty;
423 
424  if (IsNew)
425  {
426  // asignar-lo nLinea
427  lcSql = string.Format("INSERT INTO {0} (ARTICULO, CLASIF, CREATED, MODIFIED) Values({1}, {2}, {3}, {3})", DB.SQLDatabase("COMUNES", "ART_CLASIF"), DB.SQLString(_cArticulo), DB.SQLString(this._oClasificacion._Codigo), DB.SQLString(DateTime.Now));
428  }
429  else
430  {
431  lcSql = $"UPDATE { DB.SQLDatabase("COMUNES", "ART_CLASIF") } SET MODIFIED = {DB.SQLString(DateTime.Now)} WHERE ARTICULO = {DB.SQLString(_cArticulo)} AND CLASIF = {DB.SQLString(this._oClasificacion._Codigo)}";
432  }
433 
434  //Ejecuto el Query
435  return DB.SQLExec(lcSql);
436  }
437 
442  public bool _Load()
443  {
444  string lcSql = string.Empty;
445  DataTable ldtResult = new DataTable();
446  bool llOk = false;
447 
448  //Recupero las lineas de la clasificación
449  lcSql = "SELECT ARTICULO, CLASIF " +
450  "FROM " + DB.SQLDatabase("COMUNES", "ART_CLASIF") + " " +
451  "WHERE CLASIF = " + DB.SQLString(this._oClasificacion._Codigo) + " ";
452 
453  //Ejecuto el Query
454  llOk = DB.SQLExec(lcSql, ref ldtResult);
455  if (llOk && ldtResult.Rows.Count > 0)
456  {
457  this._Articulo = Convert.ToString(ldtResult.Rows[0]["ARTICULO"]);
458  }
459 
460  return llOk;
461  }
462 
467  public bool _Delete()
468  {
469  string lcSql = string.Empty;
470 
471  //Creo la instrucción
472  lcSql = "DELETE FROM " + DB.SQLDatabase("COMUNES", "ART_CLASIF") + " " +
473  "WHERE CLASIF = " + DB.SQLString(this._oClasificacion._Codigo) + " " +
474  "AND ARTICULO = " + DB.SQLString(this._Articulo) + " ";
475  //Ejecuto el Query
476  return DB.SQLExec(lcSql);
477  }
478 
479  #endregion Métodos
480  }
481  }
482 }
Clase para administrar el detalle de artículos clasificados
Clase de negocio base para mantenimientos
Definition: clsEwBase.cs:1643
override void _Load()
Override del _Load
Clase Artículo
Definition: articulo.cs:33
Clase de clasificaciones de artículos
override void _DescargarDatos()
Descargar datos
bool _Save()
Método para guardar artículos clasificados
bool _Load()
Método para cargar detalle de clasificaciones
Formulario de mantenimiento de clasificaciones
override bool _Delete()
Elimina una clasificación Registro de la tabla COMUNES.CLASIF Detalle de la tabla COMUNES...
virtual string _Nombre
Campo nombre del mantenimiento. En este hay que basar los demás campos en las clases heredadas ...
Definition: clsEwBase.cs:2655
bool _Delete()
Método para eliminar linealmente artículos clasificados
override string _Codigo
Override del código
override bool _Save()
Guarda los artículos de la clasificación (en la tabla COMUNES.ART_CLASIF)
ArticulosClasifica(ClasificacionArticulos toClasificacion, string tcArticulo)
Constructor a partir de la clase y el código de artículo
override void _Load()
Load
Definition: articulo.cs:3167
ArticulosClasifica(ClasificacionArticulos toClasificacion, DataRow tdrRow=null)
Constructor que nos permite inicializar el objeto ArticulosClasifica a partir de un datarow de la tab...
ClasificacionArticulos()
Constructor con parámetros