OliviaAddInPro/ViewModel/PaneLimpiezaViewModel.cs

159 lines
6.2 KiB
C#
Raw Blame History

using OliviaAddInPro.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using OliviaAddInPro.Helper;
namespace OliviaAddInPro
{
class PaneLimpiezaViewModel : PanelViewModelBase
{
private PaneLimpiezaSub1ViewModel _subPanel1ViewModel;
Limpieza limp;
public PaneLimpiezaViewModel()
{
_subPanel1ViewModel = new PaneLimpiezaSub1ViewModel();
_subPanel2ViewModel = new PaneLimpiezaSub2ViewModel();
_subPanel3ViewModel = new PaneLimpiezaSub3ViewModel();
_subPanel4ViewModel = new PaneLimpiezaSub4ViewModel();
OptionsMenu = new ObservableCollection<OptionsMenuItem>
{
new OptionsMenuItem(new BitmapImage(new Uri("pack://application:,,,/OliviaAddInPro;component/Resources/Dog32.png")), Resource1.String_tto, _subPanel1ViewModel),
new OptionsMenuItem(new BitmapImage(new Uri("pack://application:,,,/OliviaAddInPro;component/Resources/Dino32.png")), Resource1.String_zonif, _subPanel2ViewModel),
new OptionsMenuItem(new BitmapImage(new Uri("pack://application:,,,/OliviaAddInPro;component/Resources/Cat32.png")), Resource1.String_ctrol, _subPanel3ViewModel),
new OptionsMenuItem(new BitmapImage(new Uri("pack://application:,,,/OliviaAddInPro;component/Resources/Panda32.png")), Resource1.String_tiempos, _subPanel4ViewModel)
};
SelectedOption = OptionsMenu[0];
limp = OliviaGlob.Limp;
}
public override string DisplayName
{
get { return Resource1.String_header_limpieza; }
}
private ObservableCollection<OptionsMenuItem> _optionsMenu = new ObservableCollection<OptionsMenuItem>();
public ObservableCollection<OptionsMenuItem> OptionsMenu
{
get { return _optionsMenu; }
set { SetProperty(ref _optionsMenu, value, () => OptionsMenu); }
}
private PanelViewModelBase _currentSubPanelPage;
public PanelViewModelBase CurrentSubPanelPage
{
get { return _currentSubPanelPage; }
set { SetProperty(ref _currentSubPanelPage, value, () => CurrentSubPanelPage); }
}
private OptionsMenuItem _selectionOption;
public OptionsMenuItem SelectedOption
{
get { return _selectionOption; }
set {
SetProperty(ref _selectionOption, value, () => SelectedOption);
CurrentSubPanelPage = value.SubPanelViewModel;
}
}
public bool Lee(out string err_str)
{
err_str = "";
try
{
////////////////////////////////////////////////////////////
///Lee el panel 1
if(!_subPanel1ViewModel.CapaAbierta || string.IsNullOrEmpty(_subPanel1ViewModel.CapaElems))
{
err_str = "No se ha seleccionado ninguna Capa de Limpieza";
return false;
}
limp.CapaElems = _subPanel1ViewModel.CapaElems;
//lee el tipo tto
if (_subPanel1ViewModel.TipoTto == (int)LimpiezaDef.TiposTto.TtoNoDef)
{
err_str = "No se ha seleccionado ning<6E>n Tipo de Tratamiento";
return false;
}
limp.TipoTto = _subPanel1ViewModel.TipoTto;
//lee el/los <20>mbito seleccionado
if (!_subPanel1ViewModel.lee_ambitos())
{
err_str = "No se ha seleccionado ning<6E>n <20>mbito de trabajo";
return false;
}
limp.AmbitosSel = _subPanel1ViewModel.AmbitosSel;
int i = 0;
for (i = 0; i < limp.AmbitosSel.Length; i++)
if (limp.AmbitosSel[i])
break;
if(i>= limp.AmbitosSel.Length)
{
err_str = "No se ha seleccionado ning<6E>n <20>mbito de trabajo";
return false;
}
//lee si respeta circulacion
limp.RespCirc = _subPanel1ViewModel.RespCirc;
//lee velo de desplazamiento
int vv = -1;
if((!HelperGlobal.Str2Int(_subPanel1ViewModel.TextVeloDespl, out vv)) && (_subPanel1ViewModel.TextVeloDespl!=Resource1.String_velo_nodef))
{
err_str = "Error al leer la velocidad de desplazamiento";
return false;
}
if ((vv == 0) || (vv > LimpiezaDef.Parametros.v_despM) || (vv < LimpiezaDef.Parametros.v_despm))
{
err_str = "La velocidad de desplazamiento no est<73> dentro de los l<>mites configurados";
return false;
}
limp.VDespl = vv;
//lee tiempo de tto
if ((_subPanel1ViewModel.TimeTto == 0) ||
(_subPanel1ViewModel.TimeTto > LimpiezaDef.Parametros.t_ttoM) || (_subPanel1ViewModel.TimeTto < LimpiezaDef.Parametros.t_ttom))
{
err_str = "El tiempo de tratamiento no est<73> dentro de los l<>mites configurados";
return false;
}
limp.Ttto = _subPanel1ViewModel.TimeTto;
limp.UdsTTto = _subPanel1ViewModel.UdsTTto;
//lee las propiedades comunes a recogida
if (!LeeComun(limp,out err_str))
{
return false;
}
return true;
}
catch
{
return false;
}
}
/**
* Acciones para comenzar ejecuci<63>n
*/
public void Ejecuta(OliviaAddInPro.Services.ModosEjec modo)
{
string err = "";
if(!Lee(out err))
{
HelperGlobal.ponMsg(err);
return;
}
OliviaGlob.Limp.Ejecuta(modo);
}
}
}