NotasAsiMem.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.global;
7 using sage.ew.db;
8 using System.Data;
10 
11 namespace sage.ew.contabilidad
12 {
16  public class NotasAsiMem
17  :ewMante
18  {
19 
20  private DataTable _odt;
21  private String _nNumero = "";
22  private String _cFecha = "";
23 
27  public String _Empresa
28  {
29  get
30  {
31  return _lisCampos.ContainsKey("EMPRESA") && !String.IsNullOrEmpty(Convert.ToString(_lisCampos["EMPRESA"]._NewVal)) ? Convert.ToString(_lisCampos["EMPRESA"]._NewVal) : Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa"));
32  }
33  set
34  {
35  if (_lisCampos.ContainsKey("EMPRESA")) _lisCampos["EMPRESA"]._NewVal = value;
36  }
37  }
38 
42  public string _Numero
43  {
44  get
45  {
46  return _nNumero;
47  }
48  set
49  {
50  _nNumero = value;
51  _LoadNumero(value);
52  }
53  }
54 
55 
59  public override string _Nombre
60  {
61  get
62  {
63  return _Codigo;
64  }
65  set
66  {
67 
68  }
69  }
70 
74  public DataTable _Asientos
75  {
76  get
77  {
78  return _odt;
79  }
80  }
81 
85  public String _Tipo
86  {
87  get
88  {
89  return _lisCampos.ContainsKey("NOTA") ? Convert.ToString(_lisCampos["NOTA"]._NewVal) : String.Empty;
90  }
91  set
92  {
93  if (_lisCampos.ContainsKey("NOTA")) _lisCampos["NOTA"]._NewVal = value;
94  }
95  }
96 
100  public String _Observaciones
101  {
102  get
103  {
104  return _lisCampos.ContainsKey("OBSERVA") ? Convert.ToString(_lisCampos["OBSERVA"]._NewVal) : String.Empty;
105  }
106  set
107  {
108  if (_lisCampos.ContainsKey("OBSERVA")) _lisCampos["OBSERVA"]._NewVal = value;
109  }
110  }
111 
115  public String _Fecha
116  {
117  get
118  {
119  return _cFecha;
120  }
121  }
122 
126  public override void _Load()
127  {
128  String lcSql;
129  DataTable lodt = new DataTable();
130 
131  if(!String.IsNullOrEmpty(_Codigo))
132  {
133  lcSql = String.Format("SELECT NUMERO FROM {0} WHERE EMPRESA = '{1}' AND ASI = '{2}' ", DB.SQLDatabase("GESTION", "ASIENTOS"), _Empresa, _Codigo);
134  DB.SQLExec(lcSql, ref lodt);
135 
136  if (lodt.Rows.Count > 0) _Numero = Convert.ToString(lodt.Rows[0]["NUMERO"]);
137  }
138  else
139  {
140  _Numero = String.Empty;
141  }
142 
143  base._Load();
144  }
145 
151  public bool _LoadNumero(String tcNumeroAsi)
152  {
153  String tcCodigo;
154  DateTime loFecha;
155 
156  if (String.IsNullOrEmpty(tcNumeroAsi))
157  {
158  _Codigo = "";
159  _cFecha = "";
160  _odt = new DataTable();
161  }
162  else if (_LoadAsientos(tcNumeroAsi))
163  {
164  tcCodigo = _TrataCodigo();
165 
166  if (_Codigo != tcCodigo)
167  {
168  //CCR 151190 => Si entras desde la 1a linea u otra no hace lo mismo debido a esta gestión manual del estado. Se suprime ya que debe ser de cuando los estados
169  //requerian asignaciones forzadas. Actualemte ya se autogestionan de forma uniforme.
170  //_Estado = _EstadosMantenimiento.EsperandoCodigo;
171  _Codigo = tcCodigo;
172  }
173 
174  loFecha = DateTime.Parse(Convert.ToString(_odt.Rows[0]["FECHA"]));
175  _cFecha = loFecha.ToString(EW_GLOBAL._CustomFormatDate);
176 
177  return true;
178  }
179 
180  return false;
181 
182  }
183 
184  private string _TrataCodigo()
185  {
186  String tcCodigo;
187 
188  tcCodigo = (from loRow in _odt.AsEnumerable()
189  where !loRow.IsNull("ASI_NOTA")
190  select Convert.ToString(loRow["ASI_NOTA"])).FirstOrDefault();
191 
192  if (!String.IsNullOrEmpty(tcCodigo) && Convert.ToString(_odt.Rows[0]["ASI"]) != tcCodigo)
193  {
194  _ChangeAsi(Convert.ToString(_odt.Rows[0]["ASI"]), tcCodigo);
195  }
196 
197  tcCodigo = Convert.ToString(_odt.Rows[0]["ASI"]);
198 
199  return tcCodigo;
200 
201  }
202 
203  private bool _LoadAsientos(String tcNumeroAsi)
204  {
205  ewMascara loMascaraPrecio = new ewMascara(KeyDiccionarioMascara.wc_precioven);
206  String lcMascara = "{0:" + loMascaraPrecio._Mascara_Net + "} ";
207  String lcSql;
208  Decimal ldNum;
209 
210  _odt = new DataTable();
211 
212  if (!String.IsNullOrWhiteSpace(tcNumeroAsi))
213  {
214  lcSql = String.Format("SELECT a.LINEA, a.CUENTA, a.ASI, a.FECHA, a.NUMERO, a.DEFINICION, a.DEBE, a.HABER, '' as DEBE_TEXT, '' as HABER_TEXT, a.FACTURA , b.ASI as ASI_NOTA FROM {0} a OUTER APPLY(SELECT TOP 1 ASI FROM {3} WHERE ASI = a.ASI AND EMPRESA = '{1}' ) as b WHERE a.EMPRESA = '{1}' AND a.NUMERO = '{2}' ORDER BY LINEA ASC ", DB.SQLDatabase("GESTION", "ASIENTOS"), _Empresa, tcNumeroAsi, DB.SQLDatabase("GESTION", "ASIMEM"));
215  DB.SQLExec(lcSql, ref _odt);
216 
217  if (_odt.Rows.Count > 0)
218  {
219  foreach (DataRow loRow in _odt.Rows)
220  {
221 
222  if (Decimal.TryParse(Convert.ToString(loRow["DEBE"]), out ldNum) && ldNum > 0)
223  {
224  loRow["DEBE_TEXT"] = String.Format(lcMascara, Convert.ToDecimal(loRow["DEBE"]));
225  }
226 
227  if (Decimal.TryParse(Convert.ToString(loRow["HABER"]), out ldNum) && ldNum > 0)
228  {
229  loRow["HABER_TEXT"] = String.Format(lcMascara, Convert.ToDecimal(loRow["HABER"]));
230  }
231  }
232  }
233  }
234 
235  return _odt.Rows.Count > 0;
236  }
237 
242  public override bool _Save()
243  {
244  //Si no existen los valores los asignamos
245  if (String.IsNullOrEmpty(Convert.ToString(_lisCampos["EMPRESA"]._NewVal))) _lisCampos["EMPRESA"]._NewVal = Convert.ToString(EW_GLOBAL._GetVariable("wc_empresa"));
246  if (String.IsNullOrEmpty(Convert.ToString(_lisCampos["ASI"]._NewVal))) _lisCampos["ASI"]._NewVal = _Codigo;
247 
248  return base._Save();
249  }
250 
254  public NotasAsiMem()
255  {
256  this._Init();
257  }
258 
263  public NotasAsiMem(string tcCodigo)
264  {
265  this._Init();
266  this._Codigo = tcCodigo;
267  }
268 
269  private void _Init()
270  {
271  // Asignamos las propiedades para Actividad
272  this._lTodos = true;
273  this._Clave = "ASI";
274  this._DataBase = "Gestion";
275  this._Tabla = "ASIMEM";
276  this._TituloMantenimiento = "Mantenimiento de notas";
277 
278  _Browser_Clave = "ASI";
279  _Browser_Campos_No_Visibles = "ASI,LINEA";
280  _Browser_Campos = "NUMERO, DEFINICION";
281  _Browser_Titulos_Campos = "Número, Descripción";
282  _Browser_Datatable_Personalizado = _DataTablePersonalizadoBrownser();
283  _Browser_Campo_Predet = "DEFINICION";
284 
285  this.Navegacion._CampoOrdenPrincipal = "NUMERO";
286  this.Navegacion._Tabla = "ASIENTOS";
287  this.Navegacion._Condicion = String.Format("EMPRESA = '{0}' ", _Empresa);
288 
289  this._TituloMenu = "Nota para la memoria";
290  this._TituloCabecera = "Notas para la memoria";
291 
292  this._FormManteBaseType = typeof(Forms.frmMantenimientoNotas);
293  this._Pantalla = "MNOTAS";
294  }
295 
300  private DataTable _DataTablePersonalizadoBrownser()
301  {
302  String lcSql;
303  DataTable lodt = new DataTable();
304  DataTable lodtResult;
305 
306  lcSql = String.Format("SELECT NUMERO, DEFINICION, LINEA, ASI FROM {0} WHERE EMPRESA = '{1}' ", DB.SQLDatabase("GESTION", "ASIENTOS"), _Empresa);
307  DB.SQLExec(lcSql, ref lodt);
308 
309  //PE-101372
310  lodtResult = (lodt.Rows.Count > 0) ? lodt.AsEnumerable().GroupBy(loField => new { loCol = loField["NUMERO"] }).Select(g => g.OrderBy(loField => loField["LINEA"]).First()).CopyToDataTable() : lodt;
311 
312  return lodtResult;
313  }
314 
320  public void _ChangeAsi(String tcAsi, String tcAsiCodigo = "")
321  {
322  String lcSql;
323 
324  tcAsiCodigo = String.IsNullOrEmpty(tcAsiCodigo) ? _Codigo : tcAsiCodigo;
325 
326  lcSql = String.Format(" UPDATE {0} SET ASI = '{1}' WHERE ASI = '{2}' AND EMPRESA = '{3}' ", DB.SQLDatabase("GESTION", "ASIMEM"), tcAsi, tcAsiCodigo, _Empresa);
327  DB.SQLExec(lcSql);
328  }
329 
330  }
331 }
Clase de negocio base para mantenimientos
Definition: clsEwBase.cs:1643
bool _LoadNumero(String tcNumeroAsi)
Carga el asiento a partir del número
Definition: NotasAsiMem.cs:151
KeyDiccionarioMascara
Clave para diccionario de máscaras
NotasAsiMem(string tcCodigo)
Constructor con código de asi
Definition: NotasAsiMem.cs:263
void _ChangeAsi(String tcAsi, String tcAsiCodigo="")
Actualiza el codigo ASI por si se elimina la primera línea
Definition: NotasAsiMem.cs:320
override bool _Save()
PE-101372 Al insertar un registro nuevo desde el campo número, vacia los campos ya que la navegación ...
Definition: NotasAsiMem.cs:242
Proporciona características adicionales de las máscaras de Eurowin
Definition: clsEwBase.cs:6212
override void _Load()
Load
Definition: NotasAsiMem.cs:126
string _Mascara_Net
Máscara convertida en formato .Net
Definition: clsEwBase.cs:6235