GetListadosModulosCommand.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Data;
4 using System.Linq;
5 using System.Text;
6 using sage.ew.db;
7 using sage.ew.global;
8 using sage.ew.interficies;
9 
10 namespace Sage.ES.S50.Addons
11 {
12  internal class GetListadosModulosCommand : Command
13  {
14  string lcWhere = string.Empty;
15  int lnAsesorContable = Convert.ToInt32(EW_GLOBAL._GetVariable("wn_AsesorContable"));
16 
17  public GetListadosModulosCommand(IAddonsManager addons) : base(addons)
18  {
19  Name = "GetListadosModulos";
20  }
21  protected override bool Condition(params object[] parameters)
22  {
23  Func<string> Where_Mantes = parameters[1] as Func<string>;
24  lcWhere = Where_Mantes();
25  return base.Condition(parameters);
26  }
27 
28  protected override void CommandModulo(IModulo modulo, params object[] parameters)
29  {
30  string lcConexion = modulo._NombreConexion;
31  string lcNombre = modulo._Nombre;
32  DataTable tdtResultados = parameters[0] as DataTable;
33  Func<string, string> RevisarDescripcion = parameters[2] as Func<string, string>;
34 
35  string tcTipo = parameters[3].ToString();
36 
37  //Task 194374 - Controlar que existe la base de dades en el diccionario
38  if (DB._SQLExisteTablaBBDD(lcConexion, "LISTADOS") && DB._oAliasDB.ContainsKey(lcNombre))
39  {
40  // Task 175987
41  string lcCampoUpdate = DB.SQLExisteCampo(lcNombre, "LISTADOS", "UPDATE") ? " , [update] " : " , '' as [update] ";
42  string lcCampoPers = DB.SQLExisteCampo(lcNombre, "LISTADOS", "PERS") ? " , [pers] " : " , "+DB.SQLFalse()+" as [pers] ";
43 
44  string lcSql = $@"select id,pantalla,nombre, FORM, clase, tipo {lcCampoPers} {lcCampoUpdate}
45  from {DB.SQLDatabase(lcNombre, "listados")}
46  where {lcWhere}";
47 
48  //si la tabla existe en el módulo, obtenemos los registros de listados
49  //string lcSql = "select id,pantalla,nombre, FORM, clase, tipo " +
50  // " from " + DB.SQLDatabase(lcNombre, "listados") +
51  // " where " + lcWhere;
52 
53  if (!string.IsNullOrWhiteSpace(tcTipo))
54  lcSql += " AND tipo=" + DB.SQLString(tcTipo);
55 
56  // Task 142633
57  //
58  if (lnAsesorContable > 0)
59  {
60  // Task 142633; Si estoy en un Sage50 Asesor Contable no miramos el campo SOLUCION sino el campo SMALLPROF y exigiremos que
61  // el campo SMALLPROF sea menor o igual al nivel de Asesor Contable (wn_AsesorContable)
62  //
63  if (DB.SQLExisteCampo(lcNombre, "LISTADOS", "SMALLPROF"))
64  lcSql += " AND smallprof <= " + lnAsesorContable.ToString().Trim() + " ";
65  }
66  else
67  {
68  // Estoy en un Sage50 normal con gestión comercial y contabilidad, o en un Sage50 SoloConta, o cualquier otro.
69  if (DB.SQLExisteCampo(lcNombre, "LISTADOS", "SOLUCION"))
70  lcSql += " AND solucion <= " + DB.SQLString(EW_GLOBAL._Solucion) + " "; // Task 134340
71  }
72 
73  lcSql += " order by nombre";
74 
75  DataTable ldtTemp = new DataTable();
76  DB.SQLExec(lcSql, ref ldtTemp);
77 
78 
79  if (ldtTemp != null && ldtTemp.Rows.Count > 0)
80  {
81  foreach (DataRow row in ldtTemp.Rows)
82  {
83  //añadimos al nombre del listado, entre parentesis el nombre del módulo al que pertenece
84  row["nombre"] = RevisarDescripcion(row["nombre"].ToString());
85  row["nombre"] = row["nombre"].ToString().Trim() + " (" + lcNombre + ")";
86 
87 
88  DataRow[] foundListado = tdtResultados.Select("pantalla = '" + row["pantalla"].ToString().Trim() + "'");
89  if (foundListado.Length != 0)
90  {
91  //eliminar la fila del datatable tdtResultados puesto que a mismo nombre de pantalla tendrá preferencia la del módulo
92  foundListado[0].Delete();
93  tdtResultados.AcceptChanges();
94  }
95  }
96  tdtResultados.Merge(ldtTemp); //añadimos los registros al DataTable de resultados
97  }
98  }
99  }
100 
101  protected override object Return(params object[] parameters)
102  {
103  ((DataTable)parameters[0]).DefaultView.Sort = "nombre asc";
104  ((DataTable)parameters[0]).DefaultView.ToTable();
105  return base.Return(parameters);
106  }
107  protected override ExpectedParameters GetExpectedParameters()
108  {
109  return new ExpectedParameters(new Type[] { typeof(DataTable), typeof(Func<string>), typeof(Func<string, string>), typeof(string) });
110  }
111  }
112 }
PE-93426 Interficie para los módulos de la aplicación
Definition: IModulo.cs:22
string _NombreConexion
Nombre real de la base de datos
Definition: IModulo.cs:59
string _Nombre
Nombre interno del módulo y nombre del directorio de instación
Definition: IModulo.cs:49