using FLY.OBJComponents.Client;
using FLY.Weight.Client;
using FLY.Weight.IService;
using MultiLayout.UiModule;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Unity;

namespace FLY.Weight.UI.Client.UiModule
{
    /// <summary>
    /// UcWeighterItem.xaml 的交互逻辑
    /// </summary>
    public partial class UcWeighterItemV6_2 : UserControl
    {


        #region DependencyProperty
        // Using a DependencyProperty as the backing store for WeightSystemService.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WeightSystemServiceProperty =
            DependencyProperty.Register(nameof(WeightSystemService), typeof(IWeightSystemService), typeof(UcWeighterItemV6_2), new PropertyMetadata(null));


        public IWeightSystemService WeightSystemService
        {
            get { return (IWeightSystemService)GetValue(WeightSystemServiceProperty); }
            set { SetValue(WeightSystemServiceProperty, value); }
        }

        public static readonly DependencyProperty ContainerProperty =
            DependencyProperty.Register(nameof(Container), typeof(IUnityContainer), typeof(UcWeighterItemV6_2), new PropertyMetadata(null));

        public IUnityContainer Container
        {
            get { return (IUnityContainer)GetValue(ContainerProperty); }
            set { SetValue(ContainerProperty, value); }
        }

        #endregion

        SetPLCUpdatePlan plan;
        int Index = 0;

        public UcWeighterItemV6_2()
        {
            InitializeComponent();
        }

        private async void button_frequency_Click(object sender, RoutedEventArgs e)
        {
            WdFrequency w = new WdFrequency();
            var weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;
            w.FrequencySet = weight.ScrewManualFreq;
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            if (w.ShowDialog() == true)
            {
                //TODO
                weight.ScrewManualFreq = (float)w.FrequencySet;
                weight.ScrewManualFreqIsSet = true;
                //不用写下降沿!!!!!
            }
        }

        private void button_ratio_Click(object sender, RoutedEventArgs e)
        {
            WdRatioSet w = new WdRatioSet();
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.Init(WeightSystemService);
            w.ShowDialog();
        }

        private void button_ingredient_Click(object sender, RoutedEventArgs e)
        {
            FLY.Weight.Common.WeighterC weight = ((Button)sender).Tag as FLY.Weight.Common.WeighterC;

            if (weight.IsSingle)
            {
                //单组份,没有配料
                return;
            }
            WdIngredientV6 w = new WdIngredientV6();

            w.Init(Container, weight, WeightSystemService);

            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.ShowDialog();
        }
        private void button_density_Click(object sender, RoutedEventArgs e)
        {
            WdDensitySet w = new WdDensitySet();
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.Init(WeightSystemService);
            w.ShowDialog();
        }
    }


}