using MWS.Data.InterFace;
using MWS.Data.Manager;
using MWS.Model;
using MWSDomain.Common.CoreLib;
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.Shapes;

namespace MWS.Domain.View.SystemManage
{
    /// <summary>
    /// TeamEditWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TeamEditWindow : Window
    {
        private ITeam team;
        private Team t_Team;
        public DateTime BeginTime { get; internal set; }
        public DateTime EndTime { get; internal set; }

        public TeamEditWindow(Team t_Team)
        {
            InitializeComponent();
            team = new TeamManager();
            this.t_Team = t_Team;
            BeginTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/HH") + " " + t_Team.StartTime);
            EndTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy/MM/HH") + " " + t_Team.EndTime);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            tbTeamName.Text = t_Team.Name;
            tpcBeginTime.DateTime = BeginTime;
            tpcBeginTime.BindData();
            tpcEndTime.DateTime = EndTime;
            tpcEndTime.BindData();
        }
        private void tbsave_Click(object sender, RoutedEventArgs e)
        {
            t_Team.Name = tbTeamName.Text;
            t_Team.StartTime = tpcBeginTime.tbHour.Text + ":" + tpcBeginTime.tbMinute.Text + ":" + tpcBeginTime.tbSecond.Text;
            t_Team.EndTime = tpcEndTime.tbHour.Text + ":" + tpcEndTime.tbMinute.Text + ":" + tpcEndTime.tbSecond.Text;
            t_Team.Time = DateTime.Now;
            if (string.IsNullOrEmpty(t_Team.Name))
            {
                Msg.Error("班组不能为空！");
                return;
            }
            if (team.Update(t_Team))
            {
                Msg.Info("添加成功！");
                this.Close();
            }
            else
            {
                Msg.Info("添加失败！");
            }
        }

        private void close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

       
    }
}
