182 lines
7.1 KiB
C#
182 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using OliviaAddInPro.Model;
|
|
using OliviaAddInPro.Helper;
|
|
using System.Windows;
|
|
|
|
namespace OliviaAddInPro.Services
|
|
{
|
|
public class FinProcServ
|
|
{
|
|
public void finEjecuta(Respuesta<TiposEjecucion> res, TratamientoComun inst)
|
|
{
|
|
//REVISAR CUANDO ACABA, SE CAMBIE EL MARCHANDO PARA QUE SE LE DE A FINALIZAR Y TERMINA OK
|
|
|
|
String msg=string.Empty;
|
|
//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<bool> { Value=false};
|
|
if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización
|
|
{
|
|
resp2 = inst.ServCom.ImportSecto(GdbFileName);
|
|
}
|
|
else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación
|
|
{
|
|
GuardaCsv(inst);
|
|
resp2 = inst.ServCom.ImportPlanif(GdbFileName);
|
|
}
|
|
if (!resp2.Value)
|
|
{
|
|
msg = resp2.Error.First();
|
|
}
|
|
else
|
|
{
|
|
msg = Resource1.String_exito;
|
|
//pone modo config2
|
|
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2);
|
|
}
|
|
}
|
|
}
|
|
//borra los archivos que le toca borrar
|
|
BorraFiles();
|
|
HelperGlobal.ponMsg(msg);
|
|
Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); }));
|
|
}
|
|
|
|
public void finEjecuta2()
|
|
{
|
|
OliviaGlob.progrDialog.Hide();
|
|
//muestra la ventana
|
|
OliviaGlob.ShowHidePane(true);
|
|
}
|
|
|
|
/**
|
|
* Borra los archivos exportados para el proceso
|
|
*/
|
|
public static void BorraFiles()
|
|
{
|
|
string[] list = null;
|
|
string capa_principal = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData);
|
|
string capa_principal_nw = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathNW);
|
|
|
|
try
|
|
{
|
|
if (capa_principal != null && HelperGdb.CloseLayer(capa_principal))
|
|
{
|
|
list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal + "*");
|
|
if (list.Length > 0)
|
|
{
|
|
foreach (string f in list)
|
|
{
|
|
if (System.IO.Path.GetExtension(f) == ".lock")
|
|
continue;
|
|
System.IO.File.Delete(f);
|
|
}
|
|
}
|
|
}
|
|
if (capa_principal_nw != null && HelperGdb.CloseLayer(capa_principal_nw))
|
|
{
|
|
list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal_nw + "*");
|
|
if (list.Length > 0)
|
|
{
|
|
foreach (string f in list)
|
|
{
|
|
if (System.IO.Path.GetExtension(f) == ".lock")
|
|
continue;
|
|
System.IO.File.Delete(f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
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.
|
|
*/
|
|
public static void GuardaCsv(TratamientoComun inst)
|
|
{
|
|
string auxi, nombre = null;
|
|
string[] nameDokL;
|
|
string DirData = System.IO.Path.GetDirectoryName(OliviaGlob.Paths.PathData);
|
|
nameDokL = Directory.GetFiles(DirData,
|
|
System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + NAME_CSV + ".*");
|
|
|
|
string Title = "Guardar Secuencia de la Planificación";
|
|
string Filter = "Secuencia en formato CSV (*.csv)|*.csv";
|
|
inst.decode_gdb(System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData),
|
|
out auxi, out nombre);
|
|
string InitialDirectory = System.IO.Path.Combine(DirData, nombre);
|
|
|
|
|
|
string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, EXT_CSV, Filter);
|
|
|
|
if (string.IsNullOrEmpty(FileName) || FileName.Length == 0)
|
|
{
|
|
bool ok = HelperGlobal.ponMsg("Se va a perder el archivo que contiene la secuencia en planificación, ¿está seguro?",
|
|
MessageBoxImage.Question,"OLIVIA",MessageBoxButton.YesNo);
|
|
if (!ok)
|
|
GuardaCsv(inst);
|
|
}
|
|
else
|
|
{
|
|
if (File.Exists(FileName))
|
|
File.Delete(FileName);
|
|
File.Move(nameDokL[0], FileName);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Inicializa la importación
|
|
*/
|
|
public Respuesta<string> IniImport()
|
|
{
|
|
var res = new Respuesta<string>() { Value = string.Empty };
|
|
//Lanza ventana para elegir gdb a la que importar resultados
|
|
bool sal = true;
|
|
string GdbFileName="";
|
|
do
|
|
{
|
|
sal = true;
|
|
//repite por si se ha equivocado hasta que elige la gdb
|
|
GdbFileName = HelperGdb.OpenFileDialog(HelperGdb.TiposOpenFileDlg.OpenGdb,"", "Seleccionar GDB a la que importar los resultados");
|
|
if(string.IsNullOrEmpty(GdbFileName))
|
|
sal= HelperGlobal.ponMsg("¿Desea cancelar el proceso de imporación?",
|
|
MessageBoxImage.Question, "OLIVIA", MessageBoxButton.YesNo);
|
|
} while (!sal);
|
|
|
|
if (string.IsNullOrEmpty(GdbFileName) || !Directory.Exists(GdbFileName))
|
|
{
|
|
res.Error.Add("Se ha cancelado la importación de resultados.");
|
|
return res;
|
|
}
|
|
res.Value = GdbFileName;
|
|
return res;
|
|
}
|
|
}
|
|
}
|