using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;

namespace ThickTcpUiInWindow
{
    /// <summary>
    /// Page_CoatingSegmentProfile.xaml 的交互逻辑
    /// </summary>
    public partial class Page_CoatingSegmentProfile : Page
    {
        ICoatingSegmentService mCoatingSegmentService;
        public Page_CoatingSegmentProfile()
        {
            InitializeComponent();
        }

        public void Init(ICoatingSegmentService coatingSegmentService) 
        {
            mCoatingSegmentService = coatingSegmentService;

        }


        private void button_del_Click(object sender, RoutedEventArgs e)
        {
            if (listview_parts.SelectedItem != null) 
            {
                mCoatingSegmentService.Profile.CoatingPartList.Remove(listview_parts.SelectedItem as CoatingSegmentPart);
            }
        }

        private void button_add_Click(object sender, RoutedEventArgs e)
        {
            if (mCoatingSegmentService.Profile.CoatingPartList.Count > 0)
            {
                mCoatingSegmentService.Profile.CoatingPartList.Add(
                    mCoatingSegmentService.Profile.CoatingPartList.Last().Clone());
            }
            else 
            {
                mCoatingSegmentService.Profile.CoatingPartList.Add(
                    new CoatingSegmentPart() { Total = 300, Distance = 18 });
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = mCoatingSegmentService.Profile;
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {

        }

        private void button_apply_Click(object sender, RoutedEventArgs e)
        {
            mCoatingSegmentService.ProfileApply();
            FLY.ControlLibrary.Window_Tip.Show("应用 & 保存成功",
                null,
                TimeSpan.FromSeconds(2));
        }

    }
}
