From d267229f9e87aefaf6432d91fb5408acc3b9b3e5 Mon Sep 17 00:00:00 2001 From: Elena Date: Tue, 24 May 2022 00:26:54 +0200 Subject: [PATCH] =?UTF-8?q?Avances=20en=20importaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Helper/HelperGdb.cs | 222 ++++++++++++++++++- Model/TratamientoComun.cs | 6 + Services/EjecServ.cs | 230 +++++++++++++++++--- Services/FinProcServ.cs | 84 ++++++- Services/ProcesoEjecServ.cs | 19 +- ViewModel/Limpieza/PaneLimpiezaViewModel.cs | 15 +- ViewModel/Recogida/PaneRecogidaViewModel.cs | 6 + 7 files changed, 529 insertions(+), 53 deletions(-) diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 1554bbe..526dff7 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -22,6 +22,7 @@ using System.IO; using System.Diagnostics; using OliviaAddInPro.View; using OliviaAddInPro.Model.contract; +using ArcGIS.Core.Data.DDL; namespace OliviaAddInPro.Helper { @@ -115,13 +116,36 @@ namespace OliviaAddInPro.Helper /** * Devuelve el sistema de coordenadas de una capa */ - public static int GetCoorSys(string ftclasspath) + public static ArcGIS.Core.Geometry.SpatialReference GetSpatRef(FeatureClass fc) { - FeatureClass fc = GetFtClass(ftclasspath); if (fc == null) - return -1; + return null; ArcGIS.Core.Geometry.SpatialReference spatref = fc.GetDefinition().GetSpatialReference(); - return spatref.Wkid; + return spatref; + } + + /** + * Devuelve el sistema de coordenadas de un dataset + */ + public static ArcGIS.Core.Geometry.SpatialReference GetSpatRef(string gdbName, string dataset) + { + if (gdbName == null || string.IsNullOrEmpty(dataset)) + return null; + try + { + Geodatabase gdb = GetGdb(gdbName).Result; + if (gdb == null) + return null; + FeatureClassDefinition fcdef = gdb.GetDefinition(dataset); + ArcGIS.Core.Geometry.SpatialReference spatref = fcdef.GetSpatialReference(); + Free(gdb); + Free(fcdef); + return spatref; + } + catch + { + return null; + } } //Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass @@ -1448,10 +1472,31 @@ namespace OliviaAddInPro.Helper } } + /** + * Cierra todas las capas abiertas + */ + public static bool CloseAllLayers() + { + try + { + var lyrs = MapView.Active.Map.Layers; + foreach (FeatureLayer fl in lyrs) + { + if (fl != null) + MapView.Active.Map.RemoveLayer(fl); + } + return true; + } + catch (Exception ex) + { + return false; + } + } + /** * Saca diálogo para guardar un archivo */ - public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_) + public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_, BrowseProjectFilter brwsFilt=null) { //Display the filter in an Open Item dialog SaveItemDialog dlg = new SaveItemDialog @@ -1465,6 +1510,8 @@ namespace OliviaAddInPro.Helper dlg.Filter = filt_; if (!string.IsNullOrEmpty(ext_)) dlg.DefaultExt = ext_; + if (brwsFilt != null) + dlg.BrowseFilter = brwsFilt; bool? ok = dlg.ShowDialog(); @@ -1473,5 +1520,170 @@ namespace OliviaAddInPro.Helper else return string.Empty; } + + /** + * Comprueva si una GDB contiene un Dataset + */ + public static bool CheckDataset(Geodatabase gdb, string datasetName) + { + try + { + FeatureClass ftclss = gdb.OpenDataset(datasetName); + ftclss.Dispose(); + return true; + } + catch + { + return false; + } + } + + /** + * Crea un FeatureDataset con el nombre dado y la spatialrefernece dada en la gdb dada + * Devuelve 0 si no hay que crear nada o si lo ha creado bien, 2 si existe el dataset pero con otra referencia espacial, 1 si da error + */ + public static Respuesta CreateDataset(string gdbPath, string datasetName, ArcGIS.Core.Geometry.SpatialReference spatref, out string datasetNameOut) + { + Respuesta res = new Respuesta { Value = 1 }; + datasetNameOut = string.Empty; + Geodatabase gdb = null; + FeatureDatasetDefinition featureDatasetDefinition = null; + try + { + gdb = GetGdb(gdbPath).Result; + if(gdb==null) + { + res.Value = 1; + res.Error.Add("Error al abrir la gdb " + gdbPath); + return res; + } + //comprueba si extiste ya el dataset + if(CheckDataset(gdb,datasetName)) + { + //comprueba si tiene la misma referencia espacial + featureDatasetDefinition = gdb.GetDefinition(datasetName); + if (featureDatasetDefinition.GetSpatialReference().Equals(spatref)) + { + res.Value = 0; //no hay nada que crear, existe y coincide la spatial ref + return res; + } + else + { + //crea un nuevo dataset y avisa + datasetName = datasetName + "_1"; + datasetNameOut = datasetName; + } + } + //no existe, lo crea + SchemaBuilder schemaBuilder = new SchemaBuilder(gdb); + // Create a FeatureDataset + FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref); + schemaBuilder.Create(featureDatasetDescription); + + // Build status + bool buildStatus = schemaBuilder.Build(); + if(buildStatus)//ha ido bien + { + if (string.IsNullOrEmpty(datasetNameOut)) + res.Value = 0; + else + res.Value = 2;//avisa + } + else// Build errors + { + res.Value = 1; + res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); + } + return res; + } + catch (Exception ex) + { + res.Value = 1; + res.Error.Add("Errores al crear el Dataset "+datasetName + " " +ex.Message); + return res; + } + finally + { + Free(featureDatasetDefinition); + Free(gdb); + + } + } + + /** + * Importa el shp en la gdb y el dataset, como una featureclass + */ + public static Respuesta ImportShp(string nom_shp, string Gdb_dataset, string namefc) + { + var res = new Respuesta { Value = false }; + string[] args = { nom_shp, Gdb_dataset, namefc}; + // execute the tool + FeatureClass fc = GetFtClassFromShp(nom_shp).Result; + if (fc == null) + return res; + try + { + ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc); + var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: spatref); + IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, + environments, null, null).Result; + if (gpResult.IsCanceled) + { + return res; + } + if (gpResult.IsFailed) + { + string msg; + if (gpResult.ErrorMessages != null) + msg = gpResult.ErrorMessages.First().Text; + else + msg = "Errores en la importación"; + res.Error.Add("Error: " + msg); + return res; + } + res.Value = true; + return res; + } + catch (Exception ex) + { + res.Error.Add("Error: " + ex.Message); + return res; + } + finally + { + Free(fc); + } + } + + /** + * Borrar una feature class de un dataset + */ + public static Respuesta DeleteFeatureClass(string gdbPath, string featureClassPath) + { + var res = new Respuesta { Value = false }; + FeatureClass ftclss = GetFtClass(featureClassPath); + if (ftclss == null) + return res; + Geodatabase gdb = GetGdb(gdbPath).Result; + if (gdb == null) + return res; + // Create a FeatureClassDescription object + FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition()); + // Create a SchemaBuilder object + SchemaBuilder schemaBuilder = new SchemaBuilder(gdb); + // Add the deletion fo the feature class to our list of DDL tasks + schemaBuilder.Delete(featureClassDescription); + // Execute the DDL + bool success = schemaBuilder.Build(); + if (success) + res.Value = true; + else + { + res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); + } + Free(gdb); + Free(ftclss); + return res; + } } } diff --git a/Model/TratamientoComun.cs b/Model/TratamientoComun.cs index 2bd2191..a3649f5 100644 --- a/Model/TratamientoComun.cs +++ b/Model/TratamientoComun.cs @@ -153,6 +153,12 @@ namespace OliviaAddInPro.Model OliviaGlob.ShowHidePane(false); //comienza ejecución Action, TratamientoComun> ac = FinProceSrv.finEjecuta; + //pone los flags + if (modo == ModosEjec.Sectoriza) + OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecSecto); + else if (modo == ModosEjec.Planifica || modo == ModosEjec.SoloPlanifica) + OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecPlanif); + //llama ejecuta EjecutaAsync(modo, ac); } public async void EjecutaAsync(ModosEjec modo, Action, TratamientoComun> ffin) diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index b748004..0a4d1a2 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -24,9 +24,22 @@ namespace OliviaAddInPro.Services public class EjecServ { //Cadenas de nombres internos para la exportación/importación de los archivos - public string prefNameExport = "data_"; - public string extShp = ".shp"; - public string prefNameExportNw = "nw_"; + public string PREF_NAME_EXPORT = "data_"; + public string EXT_SHP = ".shp"; + public string PREF_NAME_EXPORT_NW = "nw_"; + public string NAME_CSV = "_L"; + public string EXT_CSV = ".csv"; + public string NAME_RUTA2 = "_R2"; + public string NAME_RUTA2_OUT = "_Viajes"; + public string NAME_AUX = "_aux"; + public string NAME_SECT = "_Sector"; + public string NAME_CONTROL_OUT = "_Control"; + public string NAME_CONTROL = "_C"; + public string NAME_RUTA_OUT = "_Ruta"; + public string NAME_RUTA = "_R"; + public string NAME_RUTA_AUX = "_Raux"; + public string NAME_INSTAL = "_I"; + public string NAME_INSTAL_OUT = "_Instalacion"; public string ErrStr = ""; SpatialQueryFilter filtroEspacial = null; @@ -87,7 +100,7 @@ namespace OliviaAddInPro.Services //se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles) fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss"); //Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp - com.NombreShpExport = prefNameExport + com.NombreShpExp_PrefTto + "_" + fechaHora + extShp; + com.NombreShpExport = PREF_NAME_EXPORT + com.NombreShpExp_PrefTto + "_" + fechaHora + EXT_SHP; com.ProgrSrc.IncMessage(10, "Exportando ámbitos de trabajo"); @@ -228,7 +241,7 @@ namespace OliviaAddInPro.Services com.ProgrSrc.IncMessage(10, "Exportando red navegable");//60% //Prepara nombre de exportación - com.NombreShpExportNw = prefNameExportNw + fechaHora + extShp; + com.NombreShpExportNw = PREF_NAME_EXPORT_NW + fechaHora + EXT_SHP; //exporta los datos de entrada if (!HelperGdb.ExportShp2(OliviaGlob.Paths.PathGdbNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, com.ProgrSrc._ProgrSrc, spatRefData,100)) { @@ -362,45 +375,206 @@ namespace OliviaAddInPro.Services /** * Realiza las funciones de importación de la sectorización */ - public Respuesta ImportSecto(string GdbFileName) + public Respuesta ImportSecto(string GdbFileName) { - var res = new Respuesta { Value = false }; + /*var res = new Respuesta { Value = string.Empty }; + return res;*/ + return Import(GdbFileName, 0); + } + /** + * Realiza las funciones de importación, modo 0 secto, modo 1 planif + */ + public Respuesta Import(string GdbFileName, int modo) + { + var res = new Respuesta { Value = string.Empty }; + ///////////////////////////////////////// + string path_shape = OliviaGlob.Paths.PathData; + string dir_shp = System.IO.Path.GetDirectoryName(path_shape); + string shapefile = System.IO.Path.GetFileNameWithoutExtension(path_shape); + int ind = shapefile.IndexOf("_", 0); + string prefijo = shapefile.Substring(ind + 1, 1); + + ////////////////////////////////////////////////////////////////////////////////// + //decodifica el nombre del shapefile para asignarle el correspondiente nombre en la GDB a la que se importa el shape + string tratamiento = string.Empty; + string ambitos = string.Empty; + com.decode_gdb(shapefile, out tratamiento, out ambitos); //supsuestamente distingue si es limpieza o recogida /* - try + if (prefijo == "T") { - //temp - string name; - res = import_secto_fin(GdbFileName, out name); - if (!res.Value) - { - res.Error.Add("Error al importar resultados."); - return res; - } - res = pinta_sectores(GdbFileName, name, 4); - if (!res.Value) - { - res.Error.Add("Error al pintar sectores."); - return res; - } + com.decode_gdb(shapefile, out tratamiento, out ambitos); } - catch (Exception) + else if (prefijo == "F") { - res.Error.Add("Se ha cancelado la importación de resultados."); + com.decode_gdb(shapefile, out tratamiento, out ambitos); + }*/ + if(string.IsNullOrEmpty(tratamiento) || string.IsNullOrEmpty(ambitos)) + { + res.Error.Add(string.Format("Nombre del archivo a importar erróneo. No se reconoce el prefijo introducido: {0}", prefijo)); return res; } - res.Value = true; - return res;*/ + bool reco_o_limp_con_instala = (prefijo == "F") || + ((prefijo == "T") && !com.CoordsInstal.Equals(new Coordinate2D(0, 0))); + bool reco_tramos = System.IO.File.Exists(System.IO.Path.Combine(dir_shp, shapefile + NAME_RUTA2 + EXT_SHP)); + + + ///////////////////////////////////////// + //crea el dataset o comprueba si existe + string datasetNameOut = string.Empty; + var resp = HelperGdb.CreateDataset(GdbFileName, tratamiento, spatRefData, out datasetNameOut); + string err_spatref = "Atención, no coincide la proyección de las FeatureClass del Dataset ya creado con la del FeatureClass a importar"; + if (resp.Value == 1) + { + res.Error.Add("Error al crear el Dataset para importar" + tratamiento); + return res; + } + else if (resp.Value == 2) + { + //avisa + HelperGlobal.ponMsg(err_spatref +", se ha creado un nuevo dataset "+ datasetNameOut ); + tratamiento = datasetNameOut; + } + + ///////////////////////////////////////// + //pregunta a ver si se quiere ese nombre u otro + bool replace = false; + string dataset = tratamiento; + + string ambitos_aux = HelperGdb.SaveFileDlg("Guardar Feature Class como...", GdbFileName + "\\" + tratamiento + "\\" + ambitos, null, null, + new ArcGIS.Desktop.Core.BrowseProjectFilter()); + if (!string.IsNullOrEmpty(ambitos_aux)) + { + //sustituye los ámbitos por los elegidos + ambitos = System.IO.Path.GetFileNameWithoutExtension(ambitos_aux); + replace = System.IO.File.Exists(ambitos_aux); + dataset = System.IO.Path.GetDirectoryName(ambitos_aux) ; + } + //comprueba si la proyección es la misma la del dataset que la que llega + if (!dataset.Equals(tratamiento)) + { + //ha cambiado de dataset al elegir + //comprueba las proyecciones + if (!HelperGdb.GetSpatRef(GdbFileName, dataset).Equals(spatRefData)) + { + //avisa + HelperGlobal.ponMsg(err_spatref); + } + } + ///////////////////////////////////////// + //todo ok, se pone a importar + string err_st=string.Empty; + string name = ambitos; + string path_import = GdbFileName + "\\" + dataset + "\\" + ambitos; + int NIMPORT; + string[] noms_shp = null; + string[] noms_gdb = null; + int i; + int ii = 0; + NIMPORT = 0; + if (modo == 0) //sectoriza + { + NIMPORT = 2; + noms_shp = new string[NIMPORT]; + noms_gdb = new string[NIMPORT]; + noms_shp[0] = shapefile; + noms_gdb[0] = ambitos; + noms_shp[1] = shapefile + NAME_AUX; + noms_gdb[1] = ambitos + NAME_SECT; + } + else if (modo == 1) //planifica + { + if (reco_o_limp_con_instala) + NIMPORT = 6; + else + NIMPORT = 5; + if (reco_tramos) + NIMPORT++; + noms_shp = new string[NIMPORT]; + noms_gdb = new string[NIMPORT]; + noms_shp[0] = shapefile; + noms_gdb[0] = ambitos; + noms_shp[1] = shapefile + NAME_AUX; + noms_gdb[1] = ambitos + NAME_SECT; + noms_shp[2] = shapefile + NAME_CONTROL; + noms_gdb[2] = ambitos + NAME_CONTROL_OUT; + noms_shp[3] = shapefile + NAME_RUTA; + noms_gdb[3] = ambitos + NAME_RUTA_OUT; + noms_shp[4] = shapefile + NAME_RUTA_AUX; + noms_gdb[4] = ambitos + NAME_RUTA_OUT + NAME_AUX; + ii = 5; + if (reco_o_limp_con_instala) + { + noms_shp[5] = shapefile + NAME_INSTAL; + noms_gdb[5] = ambitos + NAME_INSTAL_OUT; + ii++; + } + if (reco_tramos) + { + noms_shp[ii] = shapefile + NAME_RUTA2; + noms_gdb[ii] = ambitos + NAME_RUTA2_OUT; + } + } + if (noms_gdb == null || noms_shp==null) + { + res.Error.Add("Errores al crear los nombres de las Feature Class"); + return res; + } + Respuesta resp2; + try + { + ///////////////////////////////////////// + //se embucla para hacer todas las importaciones necesarias + for (i = 0; i < NIMPORT; i++) + { + //mira a ver si hay que borrar para reemplazar + if (replace) + { + resp2 = HelperGdb.DeleteFeatureClass(GdbFileName, noms_gdb[i]); + if (!resp2.Value) + { + err_st = "Error al sobreescribir la capa " + noms_gdb[i]; + if (resp2.HasError) + err_st += " " + resp2.Error.First(); + break; + } + } + resp2 = HelperGdb.ImportShp(noms_shp[i], GdbFileName + "\\" + dataset, noms_gdb[i]); + if (!resp2.Value) + { + err_st = "Error al importar la capa " + noms_gdb[i]; + if (resp2.HasError) + err_st += " " + resp2.Error.First(); + break; + } + + } + if (i < NIMPORT) + { + res.Error.Add("Errores en la importación: "+err_st); + return res; + } + } + catch + { + res.Error.Add("Errores en la importación"); + return res; + } + finally + { + + } + res.Value = path_import; return res; } /** * Realiza las funciones de importación de la planificación */ - public Respuesta ImportPlanif(string GdbFileName) + public Respuesta ImportPlanif(string GdbFileName) { - var res = new Respuesta { Value = false }; + var res = new Respuesta { Value = string.Empty }; return res; } diff --git a/Services/FinProcServ.cs b/Services/FinProcServ.cs index eb7bc6d..5d2c92b 100644 --- a/Services/FinProcServ.cs +++ b/Services/FinProcServ.cs @@ -16,7 +16,7 @@ namespace OliviaAddInPro.Services { //REVISAR CUANDO ACABA, SE CAMBIE EL MARCHANDO PARA QUE SE LE DE A FINALIZAR Y TERMINA OK - String msg=string.Empty; + /*String msg=string.Empty; //gestiona los flags, el estado de finok o finnok va en res.Vale if (res.HasError) { @@ -60,14 +60,82 @@ namespace OliviaAddInPro.Services //borra los archivos que le toca borrar BorraFiles(); HelperGlobal.ponMsg(msg); - Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); })); + //Application.Current.Dispatcher.Invoke(new Action, TratamientoComun>(((p, v)) => { finEjecuta2(p, v); }));*/ + Application.Current.Dispatcher.Invoke(new Action, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst); + + //borra los archivos que le toca borrar + BorraFiles(); } - public void finEjecuta2() + public void finEjecuta2(Respuesta res, TratamientoComun inst) { + String msg = string.Empty; + String msg_err = "Errores en el proceso de importación de resultados"; + try + { + + + //gestiona los flags, el estado de finok o finnok va en res.Vale + if (res.HasError) + { + msg = res.Error.First(); + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecNOk); + } + else + { + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk); + //importa resultados + var resp = IniImport(); + if (resp.HasError) + msg = resp.Error.First(); + else + { + string GdbFileName = resp.Value; + var resp2 = new Respuesta { Value = string.Empty }; + if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización + { + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.EjecSecto); + //acciones de importación + resp2 = inst.ServCom.ImportSecto(GdbFileName); + } + else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación + { + //actualiza los flags + OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.EjecPlanif); + //guarda csv + GuardaCsv(inst); + //acciones de importación + resp2 = inst.ServCom.ImportPlanif(GdbFileName); + + } + if (string.IsNullOrEmpty(resp2.Value)) + { + if (resp2.HasError) + msg = resp2.Error.First(); + else + msg = msg_err; + } + else + { + msg = Resource1.String_exito; + //pone modo config2 + OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2); + } + } + } + } + catch(Exception ex) + { + msg = msg_err + ": "+msg+": "+ex.Message; + } + + HelperGlobal.ponMsg(msg); OliviaGlob.progrDialog.Hide(); - //muestra la ventana - OliviaGlob.ShowHidePane(true); + //muestra la ventana + OliviaGlob.ShowHidePane(true); } /** @@ -113,8 +181,6 @@ namespace OliviaAddInPro.Services MessageBox.Show(ex.Message); } } - public static string NAME_CSV = "_L"; - public static string EXT_CSV = ".csv"; /* * Permite guardar el archivo CSV que contiene la secuencia que se ha llevado a cabo en las rutas en la planificación. */ @@ -124,7 +190,7 @@ namespace OliviaAddInPro.Services string[] nameDokL; string DirData = System.IO.Path.GetDirectoryName(OliviaGlob.Paths.PathData); nameDokL = Directory.GetFiles(DirData, - System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + NAME_CSV + ".*"); + System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + inst.ServCom.NAME_CSV + ".*"); string Title = "Guardar Secuencia de la Planificación"; string Filter = "Secuencia en formato CSV (*.csv)|*.csv"; @@ -133,7 +199,7 @@ namespace OliviaAddInPro.Services string InitialDirectory = System.IO.Path.Combine(DirData, nombre); - string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, EXT_CSV, Filter); + string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, inst.ServCom.EXT_CSV, Filter); if (string.IsNullOrEmpty(FileName) || FileName.Length == 0) { diff --git a/Services/ProcesoEjecServ.cs b/Services/ProcesoEjecServ.cs index 41d933b..f0c4e83 100644 --- a/Services/ProcesoEjecServ.cs +++ b/Services/ProcesoEjecServ.cs @@ -125,7 +125,7 @@ namespace OliviaAddInPro.Services } if (cps.Getcancelled()) //mira a ver si ha cancelado el usuario - { + { //se ha cancelado, lo envía al OliviaTask envia_cancel(); if (!cancela_permu) @@ -134,7 +134,8 @@ namespace OliviaAddInPro.Services { cancela_permu = false; } - res.Error.Add("Proceso Cancelado por el usuario"); + if(!fin) //si no ha finalizado normal, el usuario lo ha cancelado + res.Error.Add("Proceso Cancelado por el usuario"); } else if (!first_send_cfg && ((Math.Abs(Environment.TickCount) - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea { @@ -503,10 +504,22 @@ namespace OliviaAddInPro.Services else if(actu == TiposActu.ActuFinOk) cps.SetProceso("Proceso Finalizado."); - if (actu > TiposActu.ActuFinOk) + //FALTA CAMBIAR EL NOMBRE DEL BOTÓN DE CANCELAR + /*if (actu > TiposActu.ActuFinOk) cps.SetEstado("Calculando..."); if ((actu == TiposActu.ActuPermu) && !cancela) cps.SetEstado("Calculando Permutaciones..."); + + if ((actu == TiposActu.ActuMal) || (actu == TiposActu.ActuFinNOk)) + col = 2; + else + col = 1; + + + if (actu > TiposActu.ActuFinOk) + button_canc.Text = "Finalizar"; + if ((actu == TiposActu.ActuPermu) && !cancela) + button_canc.Text = "Parar permu.";*/ } /* * Para poder actualizar la barra de progreso hay que llamar a invoke diff --git a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs index 090046e..2abaafe 100644 --- a/ViewModel/Limpieza/PaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaViewModel.cs @@ -177,20 +177,19 @@ namespace OliviaAddInPro public void Ejecuta(OliviaAddInPro.Services.ModosEjec modo) { string err = ""; - //marchando - - - OliviaGlob.Limp.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel()); - OliviaGlob.progrDialog.Show(); - - //oculta la ventana - OliviaGlob.ShowHidePane(false); + if (!Lee(out err)) { HelperGlobal.ponMsg(err); return; } + //marchando + OliviaGlob.Limp.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel()); + + //oculta la ventana + OliviaGlob.ShowHidePane(false); + OliviaGlob.limp.ComienzaEjec(modo); } diff --git a/ViewModel/Recogida/PaneRecogidaViewModel.cs b/ViewModel/Recogida/PaneRecogidaViewModel.cs index a4b927f..ccf9e63 100644 --- a/ViewModel/Recogida/PaneRecogidaViewModel.cs +++ b/ViewModel/Recogida/PaneRecogidaViewModel.cs @@ -230,6 +230,12 @@ namespace OliviaAddInPro HelperGlobal.ponMsg(err); return; } + //marchando + OliviaGlob.Reco.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel()); + + //oculta la ventana + OliviaGlob.ShowHidePane(false); + OliviaGlob.Reco.ComienzaEjec(modo); } }