From e50d99802979b953dbe509b148eb21763b7711a6 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Thu, 21 Oct 2021 00:07:13 +0200 Subject: [PATCH] Configuracion: pillar path del registro y tratamiento de propiedades tiempo --- Model/OliviaConf.cs | 361 ++++++++++++++++++++++++++++++++++++++++- Services/ConfigServ.cs | 31 +++- 2 files changed, 381 insertions(+), 11 deletions(-) diff --git a/Model/OliviaConf.cs b/Model/OliviaConf.cs index 4c5e524..b77e636 100644 --- a/Model/OliviaConf.cs +++ b/Model/OliviaConf.cs @@ -1,8 +1,10 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace OliviaAddInPro.Model @@ -10,6 +12,29 @@ namespace OliviaAddInPro.Model [Serializable] class OliviaConf { + private string m2s(int min) + { + var val = min; + int horas = val / 60; + return string.Format("{0}:{1:D2}", horas, val - (horas * 60)); + } + private int s2m(string str, int defec) + { + var match = Regex.Match(str, @"^([0-9]*):([0-9]*)"); + if (match.Success) + { + int res = 0; + var horas = match.Groups[1].Value; + var min = match.Groups[2].Value; + if (!string.IsNullOrEmpty(horas)) + res += Int32.Parse(horas) * 60; + if (!string.IsNullOrEmpty(min)) + res += Int32.Parse(min) * 60; + return res; + } + return defec; + } + #region PropiedadesOcultas #region Paths @@ -331,29 +356,101 @@ namespace OliviaAddInPro.Model #region PARAM_LIMP - [Category("Parametros limpieza")] - [DisplayName("Tiempo jornada")] - [Description("Tiempo de la jornada en minutos")] + [Browsable(false)] public int t_convenio { get; set; } + [Category("Parametros limpieza")] + [DisplayName("Tiempo jornada")] + [Description("Tiempo de la jornada en formato horas:minutos")] + [JsonIgnore] + public string timeConvenio + { + get + { + return m2s(t_convenio); + } + set + { + t_convenio = s2m(value, t_convenio); + } + } + + [Category("Parametros limpieza")] [DisplayName("Tiempo desplazamiento")] - [Description("Tiempo de desplazamiento en minutos")] + [Description("Tiempo de desplazamiento en horas:minutos")] + [JsonIgnore] + public string timeDesplazamiento + { + get + { + return m2s(t_desplaz); + } + set + { + t_desplaz = s2m(value, t_desplaz); + } + } + + [Browsable(false)] public int t_desplaz { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo de descarga")] - [Description("Tiempo de descarga en minutos")] + [Description("Tiempo de descarga en horas:minutos")] + [JsonIgnore] + public string timeDescarga + { + get + { + return m2s(t_carga_desc); + } + set + { + t_carga_desc = s2m(value, t_carga_desc); + } + } + + [Browsable(false)] public int t_carga_desc { get; set; } + [Category("Parametros limpieza")] [DisplayName("Tiempo de Descanso")] [Description("Tiempo de descanso en minutos")] + [JsonIgnore] + public string timeDescanso + { + get + { + return m2s(t_descanso); + } + set + { + t_descanso = s2m(value, t_descanso); + } + } + + [Browsable(false)] public int t_descanso { get; set; } [Category("Parametros limpieza")] [DisplayName("Hora de inicio")] [Description("Hora de inicio")] + [JsonIgnore] + public string horaInicio + { + get + { + return m2s(hora_inicio); + } + set + { + hora_inicio = s2m(value, hora_inicio); + } + } + + [Browsable(false)] public int hora_inicio { get; set; } //ES UNA HORA, SON LOS MINUTOS DESDE LAS 00, PERO TIENE QUE APARECER CON FORMATO DE TIME 07:30, POR EJEMPLO [Category("Parametros limpieza")] @@ -364,91 +461,343 @@ namespace OliviaAddInPro.Model [Category("Parametros limpieza")] [DisplayName("Tiempo barrido manual")] [Description("Tiempo tratamiento barrido manual")] + /*[JsonIgnore] + public string str_t_tratamiento_BarMan + { + get + { + return m2s(t_tratamiento_BarMan); + } + set + { + t_tratamiento_BarMan = s2m(value, t_tratamiento_BarMan); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarMan { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo barrido manual mantenimiento")] [Description("Tiempo tratamiento barrido manual de mantenimiento")] + /*[JsonIgnore] + public string str_t_tratamiento_BarManMant + { + get + { + return m2s(t_tratamiento_BarManMant); + } + set + { + t_tratamiento_BarManMant = s2m(value, t_tratamiento_BarManMant); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarManMant { get; set; } [Category("Parametros limpieza")] [DisplayName("tiempo barrido manual motorizado")] [Description("Tiempo de tratamiento de Barrido manual motorizado")] + /*[JsonIgnore] + public string str_t_tratamiento_BarMMo + { + get + { + return m2s(t_tratamiento_BarMMot); + } + set + { + t_tratamiento_BarMMot = s2m(value, t_tratamiento_BarMMot); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarMMot { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo barrido mecánico calzadas")] [Description("Tiempo de tratamiento de Barrido mecánico de calzadas")] + /*[JsonIgnore] + public string str_t_tratamiento_BarMC + { + get + { + return m2s(t_tratamiento_BarMC); + } + set + { + t_tratamiento_BarMC = s2m(value, t_tratamiento_BarMC); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarMC { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo barrido mecánico aceras peatonales")] [Description("Tiempo de tratamiento de Barrido mecánico de aceras peatonales")] + /*[JsonIgnore] + public string str_t_tratamiento_BarMAP + { + get + { + return m2s(t_tratamiento_BarMAP); + } + set + { + t_tratamiento_BarMAP = s2m(value, t_tratamiento_BarMAP); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarMAP { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo barrido mixto")] [Description("Tiempo de tratamiento de barrido mixto")] + /*[JsonIgnore] + public string str_t_tratamiento_BarMix + { + get + { + return m2s(t_tratamiento_BarMix); + } + set + { + t_tratamiento_BarMix = s2m(value, t_tratamiento_BarMix); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BarMix { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo baldeo manual")] [Description("Tiempo de tratamiento de baldeo manual")] + /*[JsonIgnore] + public string str_t_tratamiento_BalMan + { + get + { + return m2s(t_tratamiento_BalMan); + } + set + { + t_tratamiento_BalMan = s2m(value, t_tratamiento_BalMan); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BalMan { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo baldeo mecánico calzadas")] [Description("Tiempo de tratamiento de Baldeo mecánico calzadas")] + /*[JsonIgnore] + public string str_t_tratamiento_BalMC + { + get + { + return m2s(t_tratamiento_BalMC); + } + set + { + t_tratamiento_BalMC = s2m(value, t_tratamiento_BalMC); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BalMC { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo baldeo mecanico aceras peatonales")] [Description("Tiempo de tratamiento de Baldeo mecánico aceras peatonales")] + /* [JsonIgnore] + public string str_t_tratamiento_BalMAP + { + get + { + return m2s(t_tratamiento_BalMAP); + } + set + { + t_tratamiento_BalMAP = s2m(value, t_tratamiento_BalMAP); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BalMAP { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo baldeo mixto")] [Description("Tiempo de tratamiento de baldeo mixto")] + /*[JsonIgnore] + public string str_t_tratamiento_BalMix + { + get + { + return m2s(t_tratamiento_BalMix); + } + set + { + t_tratamiento_BalMix = s2m(value, t_tratamiento_BalMix); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BalMix { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo brigada limpieza")] [Description("Tiempo de tratamiento de brigada limpieza")] + /*[JsonIgnore] + public string str_t_tratamiento_BL + { + get + { + return m2s(t_tratamiento_BL); + } + set + { + t_tratamiento_BL = s2m(value, t_tratamiento_BL); + } + } + + [Browsable(false)]*/ public int t_tratamiento_BL { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo caída hoja")] [Description("Tiempo de tratamiento de caída de hoja")] + /*[JsonIgnore] + public string str_t_tratamiento_CH + { + get + { + return m2s(t_tratamiento_CH); + } + set + { + t_tratamiento_CH = s2m(value, t_tratamiento_CH); + } + } + + [Browsable(false)]*/ public int t_tratamiento_CH { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo vaciado papeleras")] [Description("Tiempo de tratamiento de vaciado papeleras")] + [JsonIgnore] + public string str_t_tratamiento_VPap + { + get + { + return m2s(t_tratamiento_VPap); + } + set + { + t_tratamiento_VPap = s2m(value, t_tratamiento_VPap); + } + } + + [Browsable(false)] public int t_tratamiento_VPap { get; set; } [Category("Parametros limpieza")] [DisplayName("")] [Description("")] + [JsonIgnore] + public string Tiempo_tratamiento_LPap + { + get + { + return m2s(t_tratamiento_LPap); + } + set + { + t_tratamiento_LPap = s2m(value, t_tratamiento_LPap); + } + } + + [Browsable(false)] public int t_tratamiento_LPap { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo limpieza papeleras")] [Description("Tiempo de tratamiento de limpieza papeleras")] + [JsonIgnore] + public string str_t_tratamiento_LC + { + get + { + return m2s(t_tratamiento_LC); + } + set + { + t_tratamiento_LC = s2m(value, t_tratamiento_LC); + } + } + + [Browsable(false)] public int t_tratamiento_LC { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo limpieza contenedores")] [Description("Tiempo de tratamiento de limpieza contenedores")] + [JsonIgnore] + public string str_t_tratamiento_LZI + { + get + { + return m2s(t_tratamiento_LZI); + } + set + { + t_tratamiento_LZI = s2m(value, t_tratamiento_LZI); + } + } + + [Browsable(false)] public int t_tratamiento_LZI { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo limpieza pipicanes")] [Description("Tiempo de tratamiento de Limpieza pipicanes")] + [JsonIgnore] + public string str_t_tratamiento_LPip + { + get + { + return m2s(t_tratamiento_LPip); + } + set + { + t_tratamiento_LPip = s2m(value, t_tratamiento_LPip); + } + } + + [Browsable(false)] public int t_tratamiento_LPip { get; set; } [Category("Parametros limpieza")] [DisplayName("Tiempo limpieza saneacanes")] [Description("Tiempo de tratamiento de Limpieza sanecanes")] + [JsonIgnore] + public string str_t_tratamiento_LS + { + get + { + return m2s(t_tratamiento_LS); + } + set + { + t_tratamiento_LS = s2m(value, t_tratamiento_LS); + } + } + + [Browsable(false)] public int t_tratamiento_LS { get; set; } [Category("Parametros limpieza")] diff --git a/Services/ConfigServ.cs b/Services/ConfigServ.cs index e097697..09d88ac 100644 --- a/Services/ConfigServ.cs +++ b/Services/ConfigServ.cs @@ -6,15 +6,17 @@ using System.Text; using System.Threading.Tasks; using System.IO; using Newtonsoft.Json; +using Microsoft.Win32; namespace OliviaAddInPro.Services { class ConfigServ { - private static string pathConfig = "F:\\temp\\olv\\olv.conf"; + private static string pathConfigDef = "C:\\Olivia\\olv.conf"; private static ConfigServ configServ=null; - private static string nameDirWork = "%dir_work%"; - + private static string nameDirWork = "%dir_work%"; + public const string OlvRegKey = "SOFTWARE\\Narvaling\\Olivia"; + public static ConfigServ Serv { get { @@ -29,7 +31,7 @@ namespace OliviaAddInPro.Services OliviaConf res = null; try { - res= JsonConvert.DeserializeObject(File.ReadAllText(pathConfig)); + res= JsonConvert.DeserializeObject(File.ReadAllText(GetPathConfig())); }catch(Exception e) { var ee = e; @@ -51,7 +53,7 @@ namespace OliviaAddInPro.Services conf.path_data = pon_path_relativo(conf.path_data, conf.path_work); string jsonString = JsonConvert.SerializeObject(conf); - File.WriteAllText(pathConfig, jsonString); + File.WriteAllText(GetPathConfig(), jsonString); conf.path_exe = pon_path_absoluto(conf.path_exe, conf.path_work); conf.path_temp = pon_path_absoluto(conf.path_temp, conf.path_work); @@ -76,6 +78,25 @@ namespace OliviaAddInPro.Services return path; return path.Replace(DirWork, nameDirWork); } + private string GetPathConfig() + { + RegistryKey rk, rkprg; + string strky, str; + + //el path del archivo de configuración se obtiene del registro + strky = OlvRegKey; + rk = Registry.CurrentUser; + rkprg = rk.CreateSubKey(strky); + str = null; + if (rkprg.ValueCount > 0) + { + str = (String)rkprg.GetValue("path_cfg"); + if (!string.IsNullOrEmpty(str)) + return str; + } + + return pathConfigDef; //por defecto + } private OliviaConf Default() { var c= new OliviaConf();