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>
    /// TeamAddWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TeamAddWindow : Window
    {
        private ITeam team;
        private Team t_Team;
        public DateTime BeginTime { get; internal set; }
        public DateTime EndTime { get; internal set; }

        public TeamAddWindow()
        {
            InitializeComponent();
            team = new TeamManager();
            t_Team = new Team();
            
            this.Topmost = true;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DateTime now = DateTime.Now;
            tpcBeginTime.DateTime = now;
            tpcBeginTime.BindData();
            tpcEndTime.DateTime = now;
            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.Insert(t_Team) > 0)
            {
                Msg.Info("添加成功！");
                this.Close();
            }
            else
            {
                Msg.Info("添加失败！");
            }

        }

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