using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.SubstrateTrackings;
using MECF.Framework.UI.Client.ClientBase;
using OpenSEMI.ClientBase;
using OpenSEMI.Ctrlib.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Forms.VisualStyles;
using System.Windows.Threading;

namespace MECF.Framework.UI.Client.TrayThickness
{
    public class WinTrayThicknessDataViewModel : UiViewModelBase
    {
        TrayDataViewManager trayDataViewManager;

        private ModuleName MoudleName;

        private int Sloat;

        public TrayCoatingThickness TrayData { get; set; }

        public List<string> PmsList { get; set; } = new List<string>() { "PM1", "PM2" };

        private string pmOwned;
        public string PmOwned
        {
            get { return pmOwned; }
            set 
            { 
                pmOwned = value;
                Refresh();
            }
        }

        public WinTrayThicknessDataViewModel(string _trayGuid, ModuleName moudleName, int sloat)
        {
            MoudleName = moudleName;
            Sloat = sloat;
            TrayData = new TrayCoatingThickness(_trayGuid);
            trayDataViewManager = new TrayDataViewManager(TrayData, _trayGuid);
            UpTrayCoatingThickness();
        }
        public void UpTrayCoatingThickness()//打开时，初始化界面数据
        {
            trayDataViewManager.UpTrayCoatingThickness();

            PmOwned = TrayData.Tray.PmOwned;
        }
        public void SET()//设置到数据库
        {
            if (PmOwned is not null && PmOwned.Contains("PM"))
            {
                TrayData.Tray.PmOwned = PmOwned;
                TrayData.TrayInner.PmOwned = PmOwned;
                TrayData.RingInner.PmOwned = PmOwned;
                TrayData.RingOuter.PmOwned = PmOwned; 
            }
            if (trayDataViewManager.SET(out var reason))
            {
                InvokeClient.Instance.Service.DoOperation("UpdatTrayBelongTo", MoudleName, Sloat, TrayData.Tray.PmOwned);
                DialogBox.ShowInfo("MinorCycle Info. created successfully!");
                TryClose();
            }
            else
            {
                DialogBox.ShowError(reason);
            }
        }

        public void LoadCoatingData(string part)//人工输入名称后，查询数据
        {
            trayDataViewManager.LoadCoatingData(part);
            PmOwned = TrayData.Tray.PmOwned;
            Refresh();
        }

        
    }
}
