3 using System.Collections.Generic;
10 using Microsoft.Win32;
11 using System.Runtime.InteropServices;
16 using System.ComponentModel;
32 public static partial class FunctionsGestDoc
34 #region Importación de dll 35 [DllImport(
"Shell32", CharSet = CharSet.Auto)]
36 private static extern int ExtractIconEx(
43 [DllImport(
"user32.dll", EntryPoint =
"DestroyIcon", SetLastError =
true)]
44 private static extern int DestroyIcon(IntPtr hIcon);
45 #endregion Importación de dll 56 public static DataTable _Children(eTipoConsultaCarpetasDocumentos teTipoCarpetasDocumentos =
eTipoConsultaCarpetasDocumentos.Nivel,
int tnIdParentCarpeta = 1,
string tcUsuario =
"",
bool tlFiltrarNivelAcceso =
true,
bool tlDelete =
false)
58 DataTable ldtCarpetas =
new DataTable();
59 DataTable ldtDocumentos =
new DataTable();
60 DataTable ldtCarpetasDocs =
new DataTable();
65 if (
string.IsNullOrWhiteSpace(tcUsuario))
66 lcUsuario = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_usuario"));
68 lcUsuario = tcUsuario;
72 llOk = _Carpetas(ref ldtCarpetas, teTipoCarpetasDocumentos, tnIdParentCarpeta, lcUsuario, tlOrphan: llOrphan);
73 llOk = llOk && _Documentos(ref ldtDocumentos, teTipoCarpetasDocumentos, tnIdParentCarpeta, lcUsuario, tlDelete);
77 _AddColumnsIconDocumentos(ldtCarpetas);
78 _AddColumnDatatable(ldtCarpetas,
"useract",
"System.String");
79 _AddColumnDatatable(ldtCarpetas,
"description",
"System.Object");
80 _AddColumnDatatable(ldtCarpetas,
"extension",
"System.Object");
82 ldtCarpetasDocs = ldtCarpetas.Clone();
85 if (ldtCarpetas.Rows.Count > 0)
86 lnNivel = Convert.ToInt32(ldtCarpetas.Rows[0][
"nivel"]);
89 DataTable ldtCarpeta =
new DataTable();
90 _Carpetas(ref ldtCarpeta, teTipoCarpetasDocumentos, tnIdParentCarpeta, lcUsuario, tlOrphan: llOrphan);
92 if (ldtCarpeta.Rows.Count > 0)
93 lnNivel = Convert.ToInt32(ldtCarpeta.Rows[0][
"nivel"]);
98 _ChildrenCarpetasDocumentos(teTipoCarpetasDocumentos, tnIdParentCarpeta, lnNivel, ref ldtCarpetasDocs, ref ldtCarpetas, ref ldtDocumentos, tlOrphan: llOrphan);
100 if (!tlDelete && tlFiltrarNivelAcceso)
101 _NivelAccesoCarpetas(ref ldtCarpetasDocs, teTipoCarpetasDocumentos, tnIdParentCarpeta, lcUsuario);
104 return ldtCarpetasDocs;
112 public static void _AddColumnsIconDocumentos(DataTable tdtGestDoc,
bool tlIconsEdition =
true)
114 _AddColumnDatatable(tdtGestDoc,
"iconSmall",
"System.Object");
115 _AddColumnDatatable(tdtGestDoc,
"iconLarge",
"System.Object");
119 _AddColumnDatatable(tdtGestDoc,
"iconSmallEdition",
"System.Object");
120 _AddColumnDatatable(tdtGestDoc,
"iconLargeEdition",
"System.Object");
121 _AddColumnDatatable(tdtGestDoc,
"iconSmallEditionByOtherUSer",
"System.Object");
122 _AddColumnDatatable(tdtGestDoc,
"iconLargeEditionByOtherUSer",
"System.Object");
135 public static bool _NivelAccesoCarpetas(ref DataTable tdtCarpetasDocs, eTipoConsultaCarpetasDocumentos teTipoCarpetasDocumentos,
int tnIdParentCarpeta,
string tcUsuario)
137 if (tdtCarpetasDocs.Rows.Count == 0)
141 if (tcUsuario ==
"SUPERVISOR")
144 var ldtCarpetas = tdtCarpetasDocs.AsEnumerable().Where(myRow => ((myRow.Field<
int>(
"nivel") == -1)));
146 DataTable ldtCarpetasDocs = tdtCarpetasDocs.Clone();
148 if (tnIdParentCarpeta == 1)
151 ldtCarpetasDocs = tdtCarpetasDocs.AsEnumerable().Where(myRow => (myRow.Field<
bool>(
"carpeta") ==
true && myRow.Field<
int>(
"nivel") >= 1 && (myRow.Field<
int>(
"id_parent") == tnIdParentCarpeta || myRow.Field<
bool>(
"orphan")))).__CopyToDataTable();
153 ldtCarpetasDocs = tdtCarpetasDocs.AsEnumerable().Where(myRow => ((myRow.Field<
int>(
"id_parent") == tnIdParentCarpeta && myRow.Field<
int>(
"nivel") >= 1) || myRow.Field<
bool>(
"orphan"))).__CopyToDataTable();
156 ldtCarpetasDocs = tdtCarpetasDocs.AsEnumerable().Where(myRow => (myRow.Field<
int>(
"id_parent") == tnIdParentCarpeta && myRow.Field<
int>(
"nivel") >= 1)).__CopyToDataTable();
158 tdtCarpetasDocs.Clear();
159 tdtCarpetasDocs.Dispose();
161 tdtCarpetasDocs = ldtCarpetasDocs;
176 public static bool _Carpetas(ref DataTable tdtCarpetas, eTipoConsultaCarpetasDocumentos teTipoCarpetasDocumentos,
int tnIdParentCarpeta,
string tcUsuario,
bool tlFilterId =
false,
bool tlOrphan =
false)
178 string lcSql, lcNivelUsuarioCarpetas, lcLeftNivelCarpetas =
"";
181 if (tcUsuario ==
"SUPERVISOR")
182 lcNivelUsuarioCarpetas =
", 2 AS nivel ";
185 lcNivelUsuarioCarpetas =
"," + DB.SQLNvl(
"cu.nivel",
"0") +
" AS nivel ";
186 lcLeftNivelCarpetas =
"LEFT JOIN " + DB.SQLDatabase(
"GESTDOC",
"CARP_USER") +
" cu ON c.id = cu.idcarpeta AND cu.usuario = " + DB.SQLString(tcUsuario);
189 lcSql =
"SELECT c.id, c.nombre, c.parent AS id_parent, c.modified, c.created, " + DB.SQLTrue() +
" AS carpeta, " + DB.SQLFalse() +
" AS orphan " + lcNivelUsuarioCarpetas +
190 " FROM " + DB.SQLDatabase(
"GESTDOC",
"CARPETAS") +
" c " + lcLeftNivelCarpetas;
195 lcSql +=
" WHERE c.id = " + DB.SQLString(tnIdParentCarpeta);
200 lcSql +=
" WHERE c.parent = " + DB.SQLString(tnIdParentCarpeta);
204 lcSql +=
" ORDER BY c.parent, c.nombre";
206 llOk = DB.SQLExec(lcSql, ref tdtCarpetas);
220 public static bool _Documentos(ref DataTable tdtDocumentos, eTipoConsultaCarpetasDocumentos teTipoCarpetasDocumentos,
int tnIdParent,
string tcUsuario,
bool tlDelete)
222 string lcSql, lcFields, lcLeft =
"";
224 DataTable ldtDocumentos =
new DataTable();
226 if (tcUsuario ==
"SUPERVISOR")
227 lcFields =
", 2 AS nivel ";
230 lcFields =
"," + DB.SQLNvl(
"du.nivel",
"0") +
" AS nivel ";
231 lcLeft =
"LEFT JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOC_USER") +
" du ON c.id = du.iddoc AND du.usuario = " + DB.SQLString(tcUsuario);
234 lcSql =
"SELECT c.id, c.nom_doc AS nombre, c.extension, c.carpeta as id_parent, c.modified, c.created, " + DB.SQLFalse() +
" AS carpeta," + DB.SQLFalse() +
" AS orphan, " +
235 " de.ejercicio, d.useract " + lcFields +
236 " FROM " + DB.SQLDatabase(
"GESTDOC",
"DOCUMENT_C") +
" c" +
237 " LEFT JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOCUMENT_D") +
" d ON c.id = d.iddoc AND c.version = d.version "+
238 " LEFT JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOC_ENLACE") +
" de ON c.id = de.iddoc "+
242 lcSql +=
" WHERE c.carpeta = " + DB.SQLString(tnIdParent);
244 lcSql +=
" ORDER BY c.carpeta, c.nom_doc";
246 llOk = DB.SQLExec(lcSql, ref ldtDocumentos);
250 if (ldtDocumentos.Rows.Count > 0)
252 List<Int16> lstEjercicios =
new List<Int16>() { 0, Convert.ToInt16(Convert.ToString(EW_GLOBAL._GetVariable(
"wc_any"))) };
253 tdtDocumentos = ldtDocumentos.AsEnumerable().Where(row => (row[
"ejercicio"] == DBNull.Value) || lstEjercicios.Contains(Convert.ToInt16(row[
"ejercicio"]))).__CopyToDataTable();
255 if (tdtDocumentos.Rows.Count == 0)
256 tdtDocumentos = ldtDocumentos.Clone();
259 tdtDocumentos = ldtDocumentos.Copy();
261 FUNCTIONS._DisposeDatatable(ldtDocumentos);
277 public static void _ChildrenCarpetasDocumentos(eTipoConsultaCarpetasDocumentos teTipoCarpetasDocumentos,
int tnId_Parent,
int tnNivel, ref DataTable tdtCarpetasDocs, ref DataTable tdtCarpetas, ref DataTable tdtDocumentos,
bool tlOrphan =
false)
279 if ((tlOrphan && tnId_Parent == 1) || (!tlOrphan))
281 _ChildrenDocumentos(tnId_Parent, tnNivel, ref tdtCarpetasDocs, ref tdtDocumentos);
284 DataRow[] ldrCarpetas = tdtCarpetas.Select(
"id_parent = " + Convert.ToString(tnId_Parent).Trim(),
"nombre");
286 if (ldrCarpetas != null && ldrCarpetas.Count() > 0)
289 int lnParent = tnId_Parent;
292 foreach (DataRow ldrCarpeta
in ldrCarpetas)
294 llAcceso = (Convert.ToInt32(ldrCarpeta[
"nivel"]) > 0);
296 if (llAcceso && tnNivel == 0)
297 ldrCarpeta[
"orphan"] =
true;
299 tdtCarpetasDocs.ImportRow(ldrCarpeta);
303 lnParent = Convert.ToInt32(ldrCarpeta[
"id"]);
304 lnNivel = Convert.ToInt32(ldrCarpeta[
"nivel"]);
305 _ChildrenCarpetasDocumentos(teTipoCarpetasDocumentos, lnParent, lnNivel, ref tdtCarpetasDocs, ref tdtCarpetas, ref tdtDocumentos, tlOrphan: tlOrphan);
318 public static void _ChildrenDocumentos(
int tnParentCarpeta,
int tnNivel, ref DataTable tdtCarpetasDocs, ref DataTable tdtDocumentos)
320 DataRow[] ldrDocumentos = tdtDocumentos.Select(
"id_parent = " + Convert.ToString(tnParentCarpeta).Trim(),
"nombre");
322 if (ldrDocumentos != null && ldrDocumentos.Count() > 0)
328 foreach (DataRow ldrDocumento
in ldrDocumentos)
330 llAcceso = (Convert.ToInt32(ldrDocumento[
"nivel"]) > 0);
332 if (llAcceso && tnNivel == 0)
333 ldrDocumento[
"orphan"] =
true;
335 lcExtension = Convert.ToString(ldrDocumento[
"extension"]).Trim();
337 tdtCarpetasDocs.ImportRow(ldrDocumento);
339 FileExensionDocumento loFileExensionDocumento = _FileExtensionDocumento(lcExtension);
341 if (loFileExensionDocumento != null)
343 lnRegDocumento = tdtCarpetasDocs.Rows.Count - 1;
345 tdtCarpetasDocs.Rows[lnRegDocumento][
"description"] =
"";
346 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconSmall"] = loFileExensionDocumento._IconSmall;
347 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconLarge"] = loFileExensionDocumento._IconLarge;
348 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconSmallEdition"] = loFileExensionDocumento._IconSmallEdition;
349 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconLargeEdition"] = loFileExensionDocumento._IconLargeEdition;
350 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconSmallEditionByOtherUser"] = loFileExensionDocumento._IconSmallEditionByOtherUser;
351 tdtCarpetasDocs.Rows[lnRegDocumento][
"IconLargeEditionByOtherUser"] = loFileExensionDocumento._IconLargeEditionByOtherUser;
362 public static FileExensionDocumento _FileExtensionDocumento(
string tcExtension)
364 bool llExist =
false;
366 string lcExtension = tcExtension.ToLower();
368 FileExensionDocumento loFileExensionDocumento = null;
369 Dictionary<string, FileExensionDocumento> dictFileExtension = null;
373 dictFileExtension = (Dictionary<string, FileExensionDocumento>)loObjet;
374 if (dictFileExtension.ContainsKey(lcExtension))
375 llExist = dictFileExtension.TryGetValue(lcExtension, out loFileExensionDocumento);
380 EW_GLOBAL.ValorEnClave_VarGlob(
"wo_FileExensionDocumentoGestdoc",
new Dictionary<string, FileExensionDocumento>());
388 loFileExensionDocumento =
new FileExensionDocumento();
389 loFileExensionDocumento._Extension = lcExtension;
390 loFileExensionDocumento._Description = _DescriptionExtension(lcExtension);
393 loFileExensionDocumento._IconSmall = _IconForExtension(lcExtension,
eIconSize.Small);
394 loFileExensionDocumento._IconLarge = _IconForExtension(lcExtension,
eIconSize.Large);
401 catch (Exception loEx)
403 DB.Registrar_Error(loEx);
407 if (dictFileExtension == null)
408 dictFileExtension = (Dictionary<string, FileExensionDocumento>)loObjet;
410 dictFileExtension.Add(lcExtension, loFileExensionDocumento);
413 return loFileExensionDocumento;
421 public static RegistryKey _RegistryKeyDefaultIcon(RegistryKey keyForClass)
423 RegistryKey keyForCLSID = keyForClass.OpenSubKey(
"CLSID");
424 if (keyForCLSID == null)
return null;
426 string clsid =
"CLSID\\" + Convert.ToString(keyForCLSID.GetValue(null)) +
"\\DefaultIcon";
427 RegistryKey keyForIcon = Registry.ClassesRoot.OpenSubKey(clsid);
428 if (keyForIcon == null)
439 public static RegistryKey _RegistryKeyDefaultOpenWithProdids(RegistryKey keyForExt)
441 RegistryKey keyOpenWithProgids = keyForExt.OpenSubKey(
"OpenWithProgids");
443 if (keyOpenWithProgids != null)
445 RegistryKey keyForIcon = null;
448 string[] valueNames = keyOpenWithProgids.GetValueNames();
449 foreach (
string valueName
in valueNames)
451 RegistryKey keyForExtName = Registry.ClassesRoot.OpenSubKey(valueName);
453 if (keyForExtName != null)
455 keyForIcon = keyForExtName.OpenSubKey(
"DefaultIcon");
456 if (keyForIcon != null)
458 lcTipo = Convert.ToString(keyForExtName.GetValue(null));
459 if (lcTipo != null && !
string.IsNullOrWhiteSpace(lcTipo))
475 public static string Extension_GetExePath(
string strExtension)
478 if (!strExtension.StartsWith(
".")) strExtension =
"." + strExtension;
481 Microsoft.Win32.RegistryKey rkClassName
482 = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strExtension);
484 if (rkClassName == null)
return string.Empty;
485 string strClassName = rkClassName.GetValue(
"").ToString();
491 Microsoft.Win32.RegistryKey rkShellCommandRoot
492 = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strClassName);
493 if (rkShellCommandRoot == null)
return string.Empty;
495 Microsoft.Win32.RegistryKey rkShell
496 = rkShellCommandRoot.OpenSubKey(
"shell");
497 if (rkShell == null)
return string.Empty;
499 Microsoft.Win32.RegistryKey rkOpen
500 = rkShell.OpenSubKey(
"open");
501 if (rkOpen == null)
return string.Empty;
503 Microsoft.Win32.RegistryKey rkCommand
504 = rkOpen.OpenSubKey(
"command");
505 if (rkCommand == null)
return string.Empty;
507 string strShellCommand = rkCommand.GetValue(
"").ToString();
512 if (strShellCommand.StartsWith(
@""""))
514 strExePath = strShellCommand.Split(
'"')[1];
517 strExePath = strShellCommand.Split(
' ')[0];
528 public static Icon _IconForExtension(
string tcExtension, eIconSize toeIconSize =
eIconSize.Large)
530 tcExtension = tcExtension.ToLower().Trim();
532 string lcKeyExtension = tcExtension.Trim();
534 if (
string.IsNullOrWhiteSpace(lcKeyExtension))
535 return _IconForExtension(
"txt", toeIconSize);
537 lcKeyExtension =
"." + lcKeyExtension.ToLower();
539 RegistryKey keyForExt = Registry.ClassesRoot.OpenSubKey(lcKeyExtension);
540 if (keyForExt == null && tcExtension !=
"txt")
541 return _IconForExtension(
"txt", toeIconSize);
543 string className = Convert.ToString(keyForExt.GetValue(null));
544 RegistryKey keyForClass = Registry.ClassesRoot.OpenSubKey(className);
545 if (keyForClass == null && tcExtension !=
"txt")
546 return _IconForExtension(
"txt", toeIconSize);
548 RegistryKey keyForIcon = keyForClass.OpenSubKey(
"DefaultIcon");
550 if (keyForIcon == null)
552 RegistryKey keyForClassDefaultIcon = _RegistryKeyDefaultIcon(keyForClass);
554 if (keyForClassDefaultIcon == null)
556 RegistryKey keyOpenWithProgids = _RegistryKeyDefaultOpenWithProdids(keyForExt);
557 if (keyOpenWithProgids != null)
558 keyForIcon = keyOpenWithProgids;
560 if (keyForIcon == null && tcExtension !=
"txt")
561 return _IconForExtension(
"txt", toeIconSize);
564 keyForIcon = keyForClassDefaultIcon;
567 string[] defaultIcon = null;
571 defaultIcon = Convert.ToString(keyForIcon.GetValue(null)).Split(
',');
577 if (defaultIcon == null)
579 Icon loIcon = IconForExtensionResources(tcExtension, toeIconSize);
581 if (loIcon == null && tcExtension !=
"txt")
582 loIcon = IconForExtensionResources(
"txt", toeIconSize);
587 if (defaultIcon.Count() <= 1)
589 RegistryKey keyForIconDef = _RegistryKeyDefaultIcon(keyForClass);
591 if (keyForIconDef != null)
593 keyForIcon = keyForIconDef;
594 defaultIcon = Convert.ToString(keyForIcon.GetValue(null)).Split(
',');
598 return ExtractIcon(tcExtension, toeIconSize, defaultIcon);
608 private static Icon ExtractIcon(
string tcExtension, eIconSize toeIconSize,
string[] toKeyDefaultIcon)
611 int index = (toKeyDefaultIcon.Length > 1) ?
Int32.Parse(toKeyDefaultIcon[1]) : 0;
613 IntPtr[] hDummy =
new IntPtr[1] { IntPtr.Zero };
614 IntPtr[] hIconEx =
new IntPtr[1] { IntPtr.Zero };
619 lnRead = ExtractIconEx(toKeyDefaultIcon[0], index, hIconEx, hDummy, 1);
621 lnRead = ExtractIconEx(toKeyDefaultIcon[0], index, hDummy, hIconEx, 1);
623 if (lnRead > 0 && hIconEx[0] != IntPtr.Zero)
624 loIcon = (Icon)Icon.FromHandle(hIconEx[0]).Clone();
632 foreach (IntPtr ptr
in hIconEx)
633 if (ptr != IntPtr.Zero)
636 foreach (IntPtr ptr
in hDummy)
637 if (ptr != IntPtr.Zero)
641 if (loIcon == null && tcExtension !=
"txt")
642 loIcon = _IconForExtension(
"txt", toeIconSize);
645 IconForExtensionResources(tcExtension, toeIconSize);
658 private static Icon IconForExtensionResources(
string tcExtension, eIconSize toeIconSize =
eIconSize.Large)
666 loIcon = Properties.Resources.icon_pdf_32;
668 loIcon = Properties.Resources.icon_pdf_16;
674 loIcon = Properties.Resources.icon_docx_32;
676 loIcon = Properties.Resources.icon_docx_16;
682 loIcon = Properties.Resources.icon_xls_32;
684 loIcon = Properties.Resources.icon_xls_16;
689 loIcon = Properties.Resources.icon_txt_32;
691 loIcon = Properties.Resources.icon_txt_16;
704 public static string _ReadDefaultValueSubkey(
string tcRegKey)
706 using (var lcKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(tcRegKey,
false))
709 return lcKey.GetValue(
"") as string;
720 public static Icon _IconOverlay(Icon toIconBackGround, Image toImageOverlay)
722 if (toIconBackGround != null)
724 if (toImageOverlay == null)
725 return toIconBackGround;
727 Image imageOriginal = toIconBackGround.ToBitmap();
728 int lnHeight = toIconBackGround.Height;
729 int lnWidth = toIconBackGround.Size.Width;
733 lnDif = lnHeight / 12;
735 lnDif = lnHeight / 6;
737 imageOriginal = (Image)(
new Bitmap(imageOriginal,
new Size(lnWidth - lnDif, lnHeight - lnDif)));
739 Bitmap bitmap =
new Bitmap(lnWidth, lnWidth);
740 Graphics canvas = Graphics.FromImage(bitmap);
741 canvas.DrawImage(imageOriginal,
new Point(lnDif, lnDif));
742 canvas.DrawImage(toImageOverlay,
new Point(0, 0));
745 return Icon.FromHandle(bitmap.GetHicon());
756 public static string _DescriptionExtension(
string tcExtension)
758 string lcExtension = tcExtension.ToLower().Trim();
760 if (
string.IsNullOrWhiteSpace(lcExtension))
763 if (lcExtension.StartsWith(
".") && lcExtension.Length > 1)
764 lcExtension = lcExtension.Substring(1);
766 string lcDescription = _ReadDefaultValueSubkey(lcExtension +
"file");
767 if (!
String.IsNullOrEmpty(lcDescription))
768 return lcDescription;
770 using (var lcKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(
"." + lcExtension,
false))
777 string lcProgId = lcKey.GetValue(
"").ToString();
779 using (var lcSubkey = lcKey.OpenSubKey(
"OpenWithProgids"))
781 if (lcSubkey == null)
784 var lcNames = lcSubkey.GetValueNames();
785 if (lcNames == null || lcNames.Length == 0)
788 foreach (var lcName
in lcNames)
790 lcDescription = _ReadDefaultValueSubkey(lcName);
791 if (!
String.IsNullOrEmpty(lcDescription))
792 return lcDescription;
811 public static int _EnlaceTabla(
string tcDataBase,
string tcTabla)
813 if (
string.IsNullOrWhiteSpace(tcDataBase) ||
string.IsNullOrWhiteSpace(tcTabla))
819 DataTable ldtEnlaces =
new DataTable();
821 lcSql =
"SELECT ID, LIBRERIA, CLASE " +
822 " FROM " + DB.SQLDatabase(
"GESTDOC",
"ENLACES") +
823 " WHERE DB = " + DB.SQLString(tcDataBase) +
824 " AND TABLA = " + DB.SQLString(tcTabla);
825 llOk = DB.SQLExec(lcSql, ref ldtEnlaces);
827 if (llOk && ldtEnlaces != null && ldtEnlaces.Rows.Count > 0 && (Convert.ToInt32(ldtEnlaces.Rows[0][
"id"]) > 0))
828 lnId = Convert.ToInt32(ldtEnlaces.Rows[0][
"id"]);
842 public static int _Enlace(
IGestionDocumental toEnlace,
string tcLibreria,
string tcClase,
string tcCarpeta)
844 if (
string.IsNullOrWhiteSpace(tcLibreria) ||
string.IsNullOrWhiteSpace(tcClase))
850 DataTable ldtEnlaces =
new DataTable();
852 lcSql =
"SELECT ID, LIBRERIA, CLASE " +
853 " FROM " + DB.SQLDatabase(
"GESTDOC",
"ENLACES") +
854 " WHERE LIBRERIA = " + DB.SQLString(tcLibreria) +
855 " AND CLASE = " + DB.SQLString(tcClase);
856 llOk = DB.SQLExec(lcSql, ref ldtEnlaces);
858 if (llOk && ldtEnlaces != null && ldtEnlaces.Rows.Count > 0 && (Convert.ToInt32(ldtEnlaces.Rows[0][
"id"]) > 0))
859 lnId = Convert.ToInt32(ldtEnlaces.Rows[0][
"id"]);
862 DataTable ldtMaxId =
new DataTable();
863 lcSql =
"SELECT MAX(id) AS maxim FROM " + DB.SQLDatabase(
"GESTDOC",
"ENLACES");
864 DB.SQLExec(lcSql, ref ldtMaxId);
866 if (ldtMaxId != null && ldtMaxId.Rows.Count > 0 && !
string.IsNullOrWhiteSpace(Convert.ToString(ldtMaxId.Rows[0][
"maxim"])))
867 lnId = (Convert.ToInt32(ldtMaxId.Rows[0][
"maxim"]) + 1);
871 lcSql =
"INSERT INTO " + DB.SQLDatabase(
"GESTDOC",
"ENLACES") +
872 " (ID, LIBRERIA, CLASE, CARPETA, DB, TABLA)" +
873 " Values(" + DB.SQLString(lnId) +
", " + DB.SQLString(tcLibreria) +
", " + DB.SQLString(tcClase) +
", " + DB.SQLString(tcCarpeta) +
", " + DB.SQLString(toEnlace.
_DataBase) +
", " + DB.SQLString(toEnlace.
_Tabla) +
")";
874 llOk = DB.SQLExec(lcSql);
889 public static bool _Sage50Assembly(
string tcLibreria)
891 List<string> ltsLibrerias =
new List<string>() {
"sage.ew.empresa",
"sage.es.s50.comunicados",
"sage.es.s50.fabricacion",
"sage.es.S50.fintech",
"sage.es.s50.modelos",
"sage.es.s50.nuevoejercicio,",
"sage.es.s50.s50Update",
"sage.ew.articulo",
"sage.ew.botones",
"sage.ew.cliente",
"sage.ew.contabilidad",
"sage.ew.docscompra",
"sage.ew.docsven",
"sage.ew.docventatpv",
"sage.ew.ewbase",
"sage.ew.formul",
"sage.ew.functions",
"sage.ew.global",
"sage.ew.graficas",
"sage.ew.listados",
"sage.ew.lote",
"sage.ew.o365",
"sage.ew.objetos",
"sage.ew.perfiles",
"sage.ew.sepa",
"sage.ew.serie",
"sage.ew.stocks",
"sage.ew.tpv",
"sage.ew.txtbox",
"sage.ew.usuario" };
893 return ltsLibrerias.Contains(tcLibreria.ToLower());
902 public static void _AddColumnDatatable(DataTable tdtDatatable,
string tcNameDataColumn,
string tcTypeDataColumn)
904 DataColumn ldtNewCol =
new DataColumn(tcNameDataColumn, Type.GetType(tcTypeDataColumn));
905 tdtDatatable.Columns.Add(ldtNewCol);
915 public static DataTable _DocumentosEnlace(
IGestionDocumental toIGestionDocumental,
int tnIdEnlace,
string tcValor)
917 if (tnIdEnlace == 0 ||
string.IsNullOrWhiteSpace(tcValor))
920 DataTable ldtDocumentos =
new DataTable();
921 string lcSql, lcExtension, lcUsuario, lcInnerAcceso =
string.Empty, lcWhere =
string.Empty, lcUseract;
924 lcUsuario = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_usuario"));
926 if (lcUsuario !=
"SUPERVISOR")
928 lcInnerAcceso =
" INNER JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOC_USER") +
" D_U ON D_U.IDDOC = D.IDDOC AND D_U.USUARIO = " + DB.SQLString(lcUsuario) +
" AND D_U.NIVEL >=1 " +
929 " INNER JOIN " + DB.SQLDatabase(
"GESTDOC",
"CARP_USER") +
" C_U ON C_U.IDCARPETA = D_C.CARPETA AND C_U.USUARIO = " + DB.SQLString(lcUsuario) +
" AND C_U.NIVEL >=1 ";
932 lcSql =
"SELECT D.ENLACE, D.IDDOC, D.VALOR, D.EJERCICIO, D_C.TITULO, D_C.NOM_DOC, D_C.EXTENSION, D_D.USERACT " +
933 " FROM " + DB.SQLDatabase(
"GESTDOC",
"DOC_ENLACE") +
" D " +
934 " INNER JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOCUMENT_C") +
" D_C ON D_C.ID = D.IDDOC" +
935 " LEFT JOIN " + DB.SQLDatabase(
"GESTDOC",
"DOCUMENT_D") +
" D_D ON D_D.IDDOC = D.IDDOC AND D_C.VERSION = D_D.VERSION " +
937 " WHERE D.ENLACE = " + DB.SQLString(tnIdEnlace) +
938 " AND D.VALOR = " + DB.SQLString(tcValor);
941 lcSql +=
" AND D.EJERCICIO = " + Convert.ToString(EW_GLOBAL._GetVariable(
"wc_any"));
943 lcSql +=
" ORDER BY D_C.TITULO";
945 llOk = DB.SQLExec(lcSql, ref ldtDocumentos);
947 if (llOk && ldtDocumentos != null && ldtDocumentos.Rows.Count > 0)
949 _AddColumnsIconDocumentos(ldtDocumentos,
false);
951 foreach (DataRow ldrDocumento
in ldtDocumentos.Rows)
953 lcExtension = Convert.ToString(ldrDocumento[
"extension"]);
954 lcUseract = Convert.ToString(ldrDocumento[
"useract"]).Trim();
955 FileExensionDocumento loFileExensionDocumento = _FileExtensionDocumento(lcExtension);
956 if (loFileExensionDocumento != null)
958 if (
string.IsNullOrWhiteSpace(lcUseract))
960 ldrDocumento[
"IconSmall"] = loFileExensionDocumento._IconSmall;
961 ldrDocumento[
"IconLarge"] = loFileExensionDocumento._IconLarge;
965 if (lcUseract == lcUsuario)
967 ldrDocumento[
"IconSmall"] = loFileExensionDocumento._IconSmallEdition;
968 ldrDocumento[
"IconLarge"] = loFileExensionDocumento._IconLargeEdition;
972 ldrDocumento[
"IconSmall"] = loFileExensionDocumento._IconSmallEditionByOtherUser;
973 ldrDocumento[
"IconLarge"] = loFileExensionDocumento._IconLargeEditionByOtherUser;
980 return ldtDocumentos;
990 string lcValor =
string.Empty;
992 if (toEnlace.
_Keys != null)
994 foreach (
string lcPropertyName
in toEnlace.
_Keys.Values)
996 object loPropertyValue = _GetReflectionPropertyValue(toEnlace, lcPropertyName);
998 if (loPropertyValue != null)
1000 string lcPropertyValue;
1002 if (loPropertyValue.GetType() == typeof(DateTime))
1003 lcPropertyValue = ((DateTime)loPropertyValue).ToString(EW_GLOBAL._CustomFormatDate);
1005 lcPropertyValue = loPropertyValue.ToString();
1007 if (!
string.IsNullOrWhiteSpace(lcValor))
1010 lcValor += lcPropertyValue;
1024 public static object _GetReflectionPropertyValue(
object toObjeto,
string tcPropertyName)
1026 if (toObjeto == null)
1029 PropertyInfo loPropertyInfo = null;
1030 object loObjeto = toObjeto;
1031 string lcPropertyName;
1033 if (tcPropertyName.Contains(
"."))
1035 string[] lstPropertyNames = tcPropertyName.Split(
'.');
1037 if (lstPropertyNames.Count() == 2)
1039 string lclcPropertyNameParent = lstPropertyNames[0];
1040 object loPropertyValueParent = _GetReflectionPropertyValue(toObjeto, lclcPropertyNameParent);
1042 if (loPropertyValueParent == null)
1046 loObjeto = loPropertyValueParent;
1047 lcPropertyName = lstPropertyNames[1];
1054 lcPropertyName = tcPropertyName;
1058 loPropertyInfo = loObjeto.GetType().GetProperty(lcPropertyName);
1064 if (loPropertyInfo == null)
1067 return loPropertyInfo.GetValue(loObjeto, null);
1076 public static bool _SetReflectionPropertyValues(
object toObjeto,
string tcValues)
1081 string[] lstValores = tcValues.Split(
'|');
1084 string lcPropertyName;
1087 if (loIGestionDocumental.
_Keys.Count == lstValores.Count())
1089 foreach (KeyValuePair<string, string> kvpGestion
in loIGestionDocumental.
_Keys)
1091 lcPropertyName = kvpGestion.Value;
1092 loValue = lstValores[lnIndice];
1095 ReflectionPropertyValue(loIGestionDocumental, ref lcPropertyName, ref loValue);
1097 llOk = FunctionsGestDoc._SetReflectionPropertyValue(loIGestionDocumental, lcPropertyName, loValue);
1114 private static void ReflectionPropertyValue(
IGestionDocumental toIGestionDocumental, ref
string tcPropertyName, ref
object toValue)
1116 bool llAsientos = (toIGestionDocumental is
IAsientos);
1118 if (llAsientos && tcPropertyName ==
"_Guid")
1120 int lnAsiento = Convert.ToInt32(DB.SQLValor(
"ASIENTOS",
"EMPRESA='" + ((dynamic)toIGestionDocumental)._Empresa +
"' AND GUID", Convert.ToString(toValue),
"NUMERO"));
1124 toValue = Convert.ToString(lnAsiento);
1125 tcPropertyName =
"_Numero";
1137 public static bool _SetReflectionPropertyValue(
object toObjeto,
string tcPropertyName,
object toValue)
1140 string lcPropertyName = tcPropertyName;
1141 dynamic loObjeto = (dynamic)toObjeto;
1142 PropertyInfo propertyInfo = null;
1146 if (tcPropertyName.Contains(
"."))
1148 string[] lstPropertyNames = tcPropertyName.Split(
'.');
1150 if (lstPropertyNames.Count() == 2)
1152 string lclcPropertyNameParent = lstPropertyNames[0];
1153 object loPropertyValueParent = loObjeto.GetType().GetProperty(lclcPropertyNameParent).GetValue(loObjeto);
1155 if (loPropertyValueParent == null)
1159 loObjeto = (dynamic)loPropertyValueParent;
1160 lcPropertyName = lstPropertyNames[1];
1167 propertyInfo = loObjeto.GetType().GetProperty(lcPropertyName);
1169 if (propertyInfo != null)
1171 Type type = propertyInfo.PropertyType;
1172 object loValue = null;
1174 TypeConverter converter = TypeDescriptor.GetConverter(type);
1175 if (converter.CanConvertFrom(typeof(
string)))
1176 loValue = converter.ConvertFrom(toValue);
1178 if (loValue != null)
1179 propertyInfo.SetValue(loObjeto, loValue, null);
1198 public static bool _DeleteDocumentos(dynamic toDocumento,
string tcValueKeys =
"")
1200 bool llOk =
true, llDelete =
false;
1205 int lnIdEnlace = FunctionsGestDoc._EnlaceTabla(loIGestionDocumental.
_DataBase, loIGestionDocumental.
_Tabla);
1208 string lcSql, lcValueKeys, lcWhereEjercicio =
string.Empty;
1209 if (
string.IsNullOrWhiteSpace(tcValueKeys))
1210 lcValueKeys = FunctionsGestDoc._ValueKeys(loIGestionDocumental);
1212 lcValueKeys = tcValueKeys;
1214 if (!
string.IsNullOrWhiteSpace(lcValueKeys))
1216 DataTable ldtDocumentos =
new DataTable();
1219 lcWhereEjercicio =
" AND ejercicio = " + DB.SQLString(Convert.ToString(EW_GLOBAL._GetVariable(
"wc_any")));
1221 lcSql =
"SELECT iddoc FROM " + DB.SQLDatabase(
"GESTDOC",
"DOC_ENLACE") +
1222 " WHERE enlace = " + DB.SQLString(lnIdEnlace) +
" AND valor = " + DB.SQLString(lcValueKeys) +
1224 llOk = DB.SQLExec(lcSql, ref ldtDocumentos);
1226 if (llOk && ldtDocumentos != null && ldtDocumentos.Rows.Count > 0 && (Convert.ToInt32(ldtDocumentos.Rows[0][
"iddoc"]) > 0))
1229 foreach (DataRow ldrDocumento
in ldtDocumentos.Rows)
1231 lnIdDoc = Convert.ToInt32(ldrDocumento[
"iddoc"]);
1233 if (loDocumento.
_Id > 0)
1235 llDelete = loDocumento.
_Delete();
1236 llOk = llOk && llDelete;
1258 else if (toDocumento is
ewMante)
1269 return loeTipoDocumentoGestDoc;
1276 public static int _NumArchivosYCarpetas(
string tcPath)
1278 if (!Directory.Exists(tcPath))
1281 int lnFicheros = Directory.GetFiles(tcPath,
"*.*", SearchOption.AllDirectories).Count();
1283 int lnCarpetas = Directory.GetDirectories(tcPath,
"*", SearchOption.AllDirectories).Count();
1284 int lnNumeroTotal = (lnFicheros + lnCarpetas);
1286 lnNumeroTotal = lnNumeroTotal < 0 ? 0 : lnNumeroTotal;
1288 return lnNumeroTotal;
1296 public static string _TamanyoDocumentoFormateado(decimal tnBytes)
1298 double lnBytesPorKB = 1024;
1299 double lnBytesDocumento = Convert.ToDouble(tnBytes);
1300 string lcCadenaTamanyo =
"";
1303 lcCadenaTamanyo =
String.Format(
"{0:n0}", lnBytesDocumento) +
" bytes";
1306 if (tnBytes >= 1024 && tnBytes < 1048576)
1308 lcCadenaTamanyo =
String.Format(
"{0:n0}", Math.Ceiling(lnBytesDocumento / lnBytesPorKB)) +
" KB";
1312 if (tnBytes >= 1048576 && tnBytes < 1073741824)
1314 lcCadenaTamanyo =
String.Format(
"{0:n1}", lnBytesDocumento / Math.Pow(lnBytesPorKB, 2)) +
" MB";
1318 if (tnBytes >= 1073741824 && tnBytes < 1099511627776)
1320 lcCadenaTamanyo =
String.Format(
"{0:n1}", lnBytesDocumento / Math.Pow(lnBytesPorKB, 3)) +
" GB";
1324 if (tnBytes >= 1099511627776)
1326 lcCadenaTamanyo =
String.Format(
"{0:n2}", lnBytesDocumento / Math.Pow(lnBytesPorKB, 4)) +
" TB";
1334 return lcCadenaTamanyo;
1342 public static string _DirectorioGestDoc(
string tcCarpeta =
"")
1344 string lcPath = Convert.ToString(EW_GLOBAL._GetVariable(
"wc_iniservidor")).ToString().Trim();
1346 if (
string.IsNullOrWhiteSpace(lcPath))
1349 lcPath = Path.Combine(lcPath,
"Modulos");
1350 lcPath = Path.Combine(lcPath,
"GestDoc");
1352 if (!
string.IsNullOrWhiteSpace(tcCarpeta))
1353 lcPath = Path.Combine(lcPath, tcCarpeta);
1363 public static string _DirectorySeparatorChar(
string tcPath)
1365 string lcDirectoryName = tcPath;
1367 if (lcDirectoryName.EndsWith(
"\\") ==
false)
1368 lcDirectoryName += Path.DirectorySeparatorChar;
1370 return lcDirectoryName;
1377 public static string _DirectorioSincro()
1379 return Path.Combine(FunctionsGestDoc._DirectorioGestDoc(
"Sincro"),
"Docs" + FUNCTIONS._Grupo_Actual());
1385 public static void _SincronizarGestDocUnload()
1389 if (loObjet != null)
1391 Sincroniza_GestDoc loSincroniza_GestDoc = (Sincroniza_GestDoc)loObjet;
1392 loSincroniza_GestDoc._Unload();
1401 public static Sincroniza_GestDoc _SincronizarGestDoc(
TipoConexion toTipoConexionServicio)
1407 Sincroniza_GestDoc loSincroniza_GestDoc = null;
1409 if (loObjet == null)
1413 loSincroniza_GestDoc = (Sincroniza_GestDoc)loObjet;
1415 if (loSincroniza_GestDoc._TipoConexionServicio != toTipoConexionServicio || (loSincroniza_GestDoc._Grupo != FUNCTIONS._Grupo_Actual()))
1418 loSincroniza_GestDoc._Unload();
1424 loSincroniza_GestDoc =
new Sincroniza_GestDoc(toTipoConexionServicio);
1425 EW_GLOBAL.ValorEnClave_VarGlob(
"wo_Sincroniza_GestDoc", loSincroniza_GestDoc);
1428 return loSincroniza_GestDoc;
1443 public static void _SincronizarDocumento(eSincronizacionGestDoc teSincronizacionGestDoc,
string tcRutaDocsOneDrive,
TipoConexion toTipoConexionServicio,
int tnId,
string tcGuid,
string tcFileName,
string tcOldName,
string tcFilePathUpload,
string tcPathSincronizacion)
1445 Sincroniza_GestDoc loSincroniza_GestDoc = _SincronizarGestDoc(toTipoConexionServicio);
1447 if (loSincroniza_GestDoc != null)
1448 loSincroniza_GestDoc._SincronizarDocumento(teSincronizacionGestDoc, tcRutaDocsOneDrive, tnId, tcGuid, tcFileName, tcOldName, tcFilePathUpload, tcPathSincronizacion);
1462 public static void _SincronizarCarpeta(eSincronizacionGestDoc teSincronizacionGestDoc,
string tcRutaDocsOneDrive,
TipoConexion toTipoConexionServicio,
int tnId,
string tcGuid,
string tcPath,
string tcPathSincro,
string tcPathSincronizacion =
"")
1464 Sincroniza_GestDoc loSincroniza_GestDoc = _SincronizarGestDoc(toTipoConexionServicio);
1466 if (loSincroniza_GestDoc != null)
1467 loSincroniza_GestDoc._SincronizarCarpeta(teSincronizacionGestDoc, tcRutaDocsOneDrive, tnId, tcGuid, tcPath, tcPathSincro, tcPathSincronizacion);
Clase de negocio base para mantenimientos
static System.Drawing.Bitmap EditionByOtherUser32x32
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
Clase para la gestión de los stocks iniciales (Cabecera)
string _Tabla
Tabla relacionada del enlace del documento
bool _Delete(int tnVersion)
Borrará una versión del documento
Clase documento de DEPOSITO DE COMPRA
Clase documento de venta TPV
Interfaz IGestionDocumental para gestionar el enlace de la gestión documental con los diferentes docu...
Interfaz para el el Objeto Documento
Clase para la gestión de los albaranes de regularización (C_ALBARE)
eTipoConsultaCarpetasDocumentos
Enumeración para gestionar la consulta de la estructura de carpetas y documentos
Clase documento de PRESUPUESTOS
Es como el tipo de entrada asientos pero por negocio, sin formulario, pq quiero que me haga las propu...
Clase para la gestión de los inventarios de stocks -REGULARI- (Cabecera)
Classe documento Factura de venta
Clase de recurso fuertemente tipado, para buscar cadenas traducidas, etc.
Clase documento de PROPUESTAS DE COMPRA
string _DataBase
Base de datos relacionada del enlace del documento
Classe documento Factura de compra
Clase documento de PEDIDOS
Clase EW_GLOBAL para gestionar las variables públicas de Eurowin, variables de empresa, variables de anchuras de campo, variables de mascaras, etc.
Clase para la gestión de los albaranes de traspaso (C_ALBATR)
static System.Drawing.Bitmap EditionByOtherUser16x16
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
static System.Drawing.Bitmap Edition32x32
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
static System.Drawing.Bitmap Edition16x16
Busca un recurso adaptado de tipo System.Drawing.Bitmap.
Clase documento de ALBARANES DE COMPRA
Clase documento de PEDIDOS DE COMPRA
eIconSize
Tamaño de los iconos
eTipoDocumentoGestDoc
Enumeración para gestionar el tipo de documento
bool _GestEjercicio
Indica si el enlace se debe de realizar teniendo en cuenta el ejercicio
TipoConexion
Tipo de conexión
Dictionary< string, string > _Keys
Relación entre los campos y las propiedades de la clase de negocio
Clase de documentos DEPOSITO