Carpetas.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Data;
6 using sage.ew.db;
7 using sage.ew.interficies;
8 
9 namespace sage.addons.rgpd.Negocio
10 {
14  internal class GestorCarpetas
15  {
16  IRgpdGestdocOperationProvider _oModulo = null;
17 
18  internal List<CarpetaItem> _Carpetas
19  {
20  get { return _lisCarpetas; }
21  set { _lisCarpetas = value; }
22  }
23  List<CarpetaItem> _lisCarpetas = new List<CarpetaItem>();
24 
25  private GestorCarpetas() { }
26 
31  public GestorCarpetas(IRgpdGestdocOperationProvider toModulo)
32  {
33  _oModulo = toModulo;
34  _Load();
35  }
36 
40  private void _Load()
41  {
42  _lisCarpetas.Clear();
43 
44  string lcSql = "SELECT ID, IDGESTDOC, NOMBRE, PARENT, VISIBLE FROM " +
45  DB.SQLDatabase("RGPD", "CARPETAS") +
46  " WHERE VISIBLE = 1 " +
47  " ORDER BY ID ASC ";
48 
49  DataTable ldtCarpetas = new DataTable();
50  if (DB.SQLExec(lcSql, ref ldtCarpetas) && ldtCarpetas.Rows.Count > 0)
51  {
52  ldtCarpetas.AsEnumerable().Cast<DataRow>().ToList()
53  .ForEach(loRow => _lisCarpetas.Add(new CarpetaItem(loRow)));
54  }
55  }
56 
61  public bool _GarantizarCarpetasRgpd()
62  {
63  //Obtengo la carpeta Raiz
64  CarpetaItem loRaiz = _lisCarpetas.Where(loCarpeta => loCarpeta._IsRoot() == true).FirstOrDefault();
65  if (loRaiz != null)
66  {
67  loRaiz._CreateOrUpdateIdGestDoc(_oModulo);
68  var restoCarpetas = _lisCarpetas.Where(loCarpeta => loCarpeta._IsRoot() == false).ToList();
69 
70  //Establezco el Parent que ha de usar en la GESTION DOCUMENTAL
71  restoCarpetas.ForEach(loCarpeta => loCarpeta._ParentGestDoc = loRaiz._IdGestdoc);
72 
73  //Invierto la ordenaciĆ³n para que no me reaproveche un Max de IdGestdoc
74  var carpetasOrdenadas = restoCarpetas.OrderByDescending(loEle => loEle._IdRgpd).ToList();
75 
76  //Trato la carpeta
77  carpetasOrdenadas.ForEach(loCarpeta => loCarpeta._CreateOrUpdateIdGestDoc(_oModulo));
78  return true;
79  }
80  else
81  return false;
82  }
83 
88  public Dictionary<int, int> _ToDictionary()
89  {
90  Dictionary<int, int> dicCarpetas = new Dictionary<int, int>();
91  _Carpetas.ForEach(loCarpeta => dicCarpetas.Add(loCarpeta._IdRgpd, loCarpeta._IdGestdoc));
92  return dicCarpetas;
93  }
94  }
95 
99  internal class CarpetaItem
100  {
101  #region Propiedades
102 
106  public int _IdRgpd
107  {
108  get { return _nIdRgpd; }
109  set { _nIdRgpd = value; }
110  }
111  private int _nIdRgpd = -1;
112 
116  public int _IdGestdoc
117  {
118  get { return _nIdGestdoc; }
119  set { _nIdGestdoc = value; }
120  }
121  private int _nIdGestdoc = -1;
122 
126  public string _Nombre
127  {
128  get { return _cNombre; }
129  set { _cNombre = value; }
130  }
131  private string _cNombre = "";
132 
136  public int _Parent
137  {
138  get { return _nParent; }
139  set { _nParent = value; }
140  }
141  private int _nParent = -1;
142 
146  public int _ParentGestDoc
147  {
148  get { return _nParentGestDoc; }
149  set { _nParentGestDoc = value; }
150  }
151  private int _nParentGestDoc = -1;
152 
156  public bool _Visible
157  {
158  get { return _lVisible; }
159  set { _lVisible = value; }
160  }
161  private bool _lVisible = false;
162 
163  #endregion Propiedades
164 
165  #region Constructores
166 
170  public CarpetaItem() { }
171 
176  public CarpetaItem(DataRow tdRow)
177  {
178  _nIdRgpd = Convert.ToInt32(tdRow["ID"]);
179  _cNombre = Convert.ToString(tdRow["NOMBRE"]).TrimEnd();
180  _nIdGestdoc = Convert.ToInt32(tdRow["IDGESTDOC"]);
181  _nParent = Convert.ToInt32(tdRow["PARENT"]);
182  _lVisible = Convert.ToBoolean(tdRow["VISIBLE"]);
183 
184  if (_IsRoot())
185  _nParentGestDoc = 1; //Esblezco la raiz del rgpd
186  }
187 
188  #endregion Constructores
189 
194  public bool _IsRoot()
195  {
196  return _nParent == 0;
197  }
198 
203  public void _CreateOrUpdateIdGestDoc(IRgpdGestdocOperationProvider toModulo)
204  {
205  string lcNombreOriginal = _cNombre;
206  int lnIdGestDocOriginal = _nIdGestdoc;
207  toModulo.RgpdGarantizarDirectorio(ref _cNombre, ref _nIdGestdoc, _nParentGestDoc);
208  if (lnIdGestDocOriginal != _nIdGestdoc || lcNombreOriginal != _cNombre) //Si ha cambiado de nombre o de ID
209  _Update();
210  }
211 
216  private bool _Update()
217  {
218  return DB.SQLExec("UPDATE " + DB.SQLDatabase("RGPD", "CARPETAS") +
219  " SET NOMBRE = " + DB.SQLString(_cNombre) + ", IDGESTDOC = " + _nIdGestdoc + " " +
220  " WHERE ID = " + _nIdRgpd);
221  }
222  }
223 }
Es como el tipo de entrada asientos pero por negocio, sin formulario, pq quiero que me haga las propu...
void RgpdGarantizarDirectorio(ref string tnNombre, ref int tnIdCarperta, int tnParentId=0)
RgpdGarantizarDirectorio
Interficie de operaciones requeridas por el Addon de RGPD al Addon de GESTDOC