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 FrmDisturbedAdd : Form
    {
        public ModalForm mr = null;
        public FrmDisturbedAdd()
        {
            InitializeComponent();
            Dt_start.Value = DateTime.Now.Date;
            Dt_End.Value = DateTime.Now.AddDays(1).Date.AddSeconds(-1);
            CbbType.SelectedIndex = 0;
            CbbStartWeek.SelectedIndex = 0;
            CbbEndWeek.SelectedIndex = 4;
            PnlWeek.Left = PnlDate.Left;
            PnlWeek.Top = PnlDate.Top;
        }

        private void BtnCancel_Click(object sender, EventArgs e)
        {
            if (mr != null) mr.Form_Result = DialogResult.Cancel;
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
            if (CbbType.SelectedIndex==1) //日期
            {
                if(Dt_End.Value<=Dt_start.Value)
                {
                    MessageBox.Show("请选择正确的时间段。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else if (CbbType.SelectedIndex == 2) //星期
            {
                int start_week = CbbStartWeek.SelectedIndex + 1;
                int end_week = CbbEndWeek.SelectedIndex + 1;
                end_week += 1;
                if (end_week > 7) { end_week = 1; }
                if (start_week==end_week)
                {
                    MessageBox.Show("不能将全部星期包含进去。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            if (mr != null) mr.Form_Result = DialogResult.OK;
        }

        private void CbbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(CbbType.SelectedIndex!=2)
            {
                PnlDate.Visible = true;
                PnlWeek.Visible = false;
            }
            else
            {
                PnlDate.Visible = false;
                PnlWeek.Visible = true;
            }
            Dt_start.ShowUpDown = CbbType.SelectedIndex == 0;
            if (CbbType.SelectedIndex == 1)
            {
                Dt_start.CustomFormat = "yyyy年MM月dd日 HH:mm";
            }
            else
            {
                Dt_start.CustomFormat = "HH:mm";
            }
            Dt_End.CustomFormat = Dt_start.CustomFormat;
            Dt_End.ShowUpDown = Dt_start.ShowUpDown;
        }
    }
}
