aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Modules/Tango.PPC.JobsV2/Dialogs/JobCreationViewVM.cs
blob: 5387bb9c9d09eb5608edcd6aa4dd23a3c9a97409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29<
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

[assembly: AssemblyTitle("Tango - Machine Studio Stubs Module")]
[assembly: AssemblyVersion("2.0.10.1737")]

[assembly: ComVisible(false)]

[assembly:ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
                             //(used if a resource is not found in the page,
                             // or application resource dictionaries)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.Core.Commands;
using Tango.PPC.Common;
using Tango.PPC.Common.Lubrication;
using Tango.Settings;
using Tango.SharedUI;

namespace Tango.PPC.Jobs.Dialogs
{
    /// <summary>
    /// Represents the a job type picker view model
    /// </summary>
    /// <seealso cref="Tango.SharedUI.DialogViewVM" />
    public class JobCreationViewVM : DialogViewVM
    {
        private String _jobName;

        public String JobName
        {
            get { return _jobName; }
            set { _jobName = value;
                RaisePropertyChangedAuto();
                OKCommand.RaiseCanExecuteChanged();
            }
        }

        private List<Rml> _rmls;
        /// <summary>
        /// Gets or sets the available RMLS.
        /// </summary>
        public List<Rml> Rmls
        {
            get { return _rmls; }
            set { _rmls = value;
                RaisePropertyChangedAuto(); }
        }

        private Rml _selectedRML;
        /// <summary>
        /// Gets or sets the selected RML.
        /// </summary>
        public Rml SelectedRML
        {
            get { return _selectedRML; }
            set {
                if(_selectedRML != value)
                {
                    _selectedRML = value;
                    OnRmlSelectionChanged();
                    RaisePropertyChangedAuto();
                    OKCommand.RaiseCanExecuteChanged();
                }
            }
        }

        private List<SpoolType> _spoolTypes;
        /// <summary>
        /// Gets or sets the available spool types.
        /// </summary>
        public List<SpoolType> SpoolTypes
        {
            get { return _spoolTypes; }
            set { _spoolTypes = value;
                RaisePropertyChangedAuto();
                OKCommand.RaiseCanExecuteChanged();
            }
        }

        private SpoolType _selectedSpoolType;
        /// <summary>
        /// Gets or sets the type of the selected spool.
        /// </summary>
        public SpoolType SelectedSpoolType
        {
            get { return _selectedSpoolType; }
            set {
                if(_selectedSpoolType != value)
                {
                    _selectedSpoolType = value;
                    OnSelectedSpoolTypeChanged();
                    RaisePropertyChangedAuto();
                }
            }
        }

        private RmlLubricationLevel _lubricationLevel;
        public RmlLubricationLevel LubricationLevel
        {
            get { return _lubricationLevel; }
            set { _lubricationLevel = value; RaisePropertyChangedAuto(); }
        }

        private int _btsrSpoolTension;
        public int BtsrSpoolTension
        {
            get { return _btsrSpoolTension; }
            set { _btsrSpoolTension = value; RaisePropertyChangedAuto(); }
        }

        private PPCSettings _settings;
        /// <summary>
        /// Gets the main PPC settings.
        /// </summary>
        public PPCSettings Settings
        {
            get
            {
                if (_settings == null)
                {
                    _settings = SettingsManager.Default.GetOrCreate<PPCSettings>();
                }

                return _settings;
            }
            private set { _settings = value; }
        }
        private double _whiteGap;

        public double WhiteGap
        {
            get { return _whiteGap; }
            set { _whiteGap = value;
                RaisePropertyChangedAuto();
            }
        }


        private bool  _showDuplicate;

        public bool  ShowDuplicate
        {
            get { return _showDuplicate; }
            set { _showDuplicate = value;
                RaisePropertyChangedAuto();

            }
        }

        public bool IsDuplicate { get; set; }
        public RelayCommand DuplicateCommand { get; set; }
        /// <summary>
        /// Initializes a new instance of the <see cref="JobCreationViewVM"/> class.
        /// </summary>
        /// <param name="supportedJobTypes">The supported job types.</param>
        /// <param name="supportedColorSpaces">The supported color spaces</param>
        public JobCreationViewVM(List<SpoolType> spoolTypes, List<Rml> rmls, double whitegap, bool showDuplicate) : base()
        {
            JobName = "Unnamed";
            SpoolTypes = spoolTypes;
            Rmls = rmls.OrderBy(x => x.Name).ToList();
            DuplicateCommand = new RelayCommand(Duplicate);
            IsDuplicate = false;
            ShowDuplicate = showDuplicate;
            WhiteGap = whitegap;
        }

        #region Commands

        private void Duplicate(object obj)
        {
            IsDuplicate = true;
            Accept();
        }
        
        protected override bool CanOK()
        {
            //var ret = (false == String.IsNullOrEmpty(JobName) && SelectedRML != null && SelectedSpoolType != null);
            return (false == String.IsNullOrEmpty(JobName) && SelectedRML!=null && SelectedSpoolType!=null);
        }

        #endregion

        #region update on change value

        private void OnRmlSelectionChanged()
        {
            GetLubricationLevel();
            SetSpoolTension();
        }

        private void OnSelectedSpoolTypeChanged()
        {
            SetSpoolTension();
        }

        #endregion


        #region Lubrication Level

        private void GetLubricationLevel()
        {
            if (SelectedRML != null)
            {
                LubricationLevel = Settings.LubricationLevels.FirstOrDefault(x => x.RmlGuid == SelectedRML.Guid);
            }
            else
            {
                LubricationLevel = null;
            }
        }

        #endregion

        #region Spool Tension

        private async void SetSpoolTension()
        {
            if (SelectedRML != null && SelectedSpoolType != null)
            {
                using (ObservablesContext db = ObservablesContext.CreateDefault())
                {
                    BtsrSpoolTension = await SelectedRML.GetRequiredBtsrSpoolTension(db, SelectedSpoolType);
                }
            }
        }

        #endregion
    }
}