using ryCommon;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TimeClock.DbOp
{
    public partial class FrmQuickAdd : Form
    {
        public ModalForm mr = null;
        public FrmQuickAdd()
        {
            InitializeComponent();
        }
        private void AddTip(DateTime dt)
        {
            if(txtName.Text=="")
            {
                MessageBox.Show("提醒标题不能为空。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Itrycn_Db.AddTip(txtName.Text, TxtContent.Text,dt);
            if (mr != null) mr.Form_Result = DialogResult.OK;
        }
        private void ButtonEx1_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(5));
        }

        private void ButtonEx2_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(10));
        }

        private void ButtonEx3_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(30));
        }

        private void ButtonEx4_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(60));
        }

        private void ButtonEx5_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddDays(1).Date.AddHours(8).AddMinutes(40));
        }

        private void ButtonEx6_Click(object sender, EventArgs e)
        {
            if (DateTime.Now.Hour == 11 && DateTime.Now.Minute > 20)
            {
                MessageBox.Show("已经过了提醒时间,不能再添加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (DateTime.Now.Hour>11)
            {
                MessageBox.Show("已经过了提醒时间,不能再添加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            AddTip(DateTime.Now.Date.AddHours(11).AddMinutes(25));
        }
        /// <summary>
        /// 获取下午下班时间
        /// </summary>
        /// <returns></returns>
        private DateTime GetAfterNoon_ClosingTime()
        {
            DateTime nowTime = DateTime.Now;
            #region 下班时间
            if (nowTime.Month >= 5 && nowTime.Month <= 9) //夏天上班时间
            {
                if (nowTime.Month == 5 && nowTime.Day < 1) //夏天上班时间
                {
                    return Convert.ToDateTime(nowTime.ToString("yyyy-MM-dd") + " 17:00:00");
                }
                else
                {
                    return Convert.ToDateTime(nowTime.ToString("yyyy-MM-dd") + " 17:30:00");
                }
            }
            else
            {
                return Convert.ToDateTime(nowTime.ToString("yyyy-MM-dd") + " 17:00:00");
            }
            #endregion
        }
        private void ButtonEx7_Click(object sender, EventArgs e)
        {
            if (DateTime.Now> GetAfterNoon_ClosingTime().AddMinutes(-10))
            {
                MessageBox.Show("已经过了提醒时间,不能再添加。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            AddTip(GetAfterNoon_ClosingTime().AddMinutes(-5));
        }

        private void FrmQuickAdd_Load(object sender, EventArgs e)
        {
            if(!DbOp.Custom.WorkQuickTip)
            {
                buttonEx5.Visible = false;
                buttonEx6.Visible = false;
                buttonEx7.Visible = false;
            }
            if (DateTime.Now > GetAfterNoon_ClosingTime().AddMinutes(-10))
            {
                buttonEx7.Enabled = false;
            }
            if (DateTime.Now.Hour >= 11)
            {
                if ((DateTime.Now.Hour == 11 && DateTime.Now.Minute > 20) || DateTime.Now.Hour>11)
                {
                    buttonEx6.Enabled = false;
                }
            }
        }

        private void ButtonEx8_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(120));
        }

        private void ButtonEx9_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(15));
        }

        private void ButtonEx10_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(20));
        }

        private void BtnMinuteOK_Click(object sender, EventArgs e)
        {
            AddTip(DateTime.Now.AddMinutes(NumMinute.Value.ToInt()));
        }

        private void NumericUpDown1_Enter(object sender, EventArgs e)
        {
            NumMinute.Select(0, NumMinute.Value.ToString().Length);
        }

        private void NumMinute_MouseClick(object sender, MouseEventArgs e)
        {
            NumMinute.Select(0, NumMinute.Value.ToString().Length);
        }

        private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(tabControl1.SelectedTab==tabPage2)
            {
                NumMinute.Focus();
            }
        }

        private void BtnTimeOK_Click(object sender, EventArgs e)
        {
            if (dateTimePicker1.Value <= DateTime.Now)
            {
                AddTip(dateTimePicker1.Value.AddDays(1));
            }
            else
            {
                AddTip(dateTimePicker1.Value);
            }
        }
    }
}
