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 FrmBeforeRestTip : Form
    {
        bool canDelay = true;
        public FrmBeforeRestTip()
        {
            InitializeComponent();
            Itrycn_Info.StickyList.Add(this);
            contextMenuStrip1.Items.Add("推迟2分钟提醒").Tag = 2;
            contextMenuStrip1.Items.Add("推迟3分钟提醒").Tag = 2;
            contextMenuStrip1.Items.Add("推迟5分钟提醒").Tag = 5;
            contextMenuStrip1.Items.Add("推迟8分钟提醒").Tag =8;
            for (int i = 0; i < contextMenuStrip1.Items.Count; i++)
            {
                contextMenuStrip1.Items[i].Click += Menu_Click;
            }
            canDelay = Itrycn_Info.DelayRestOn;
            if (Itrycn_Info.DelayRestOn)
            {
                canDelay = (Itrycn_Info.DelayRestIndex < Itrycn_Info.DelayRestCount);
            }
            if (canDelay) { LblDelay.Text = "延迟休息"; } else { LblDelay.LinkColor = Color.Red;  LblDelay.Text = "立即休息"; }
        }
        /// <summary>
        /// 大于0表示延迟休息分钟数,-1表示立即休息,0表示不延迟
        /// </summary>
        public int IsDelay = 0;
        private void Menu_Click(object sender, EventArgs e)
        {
            //if (isProcUse) { return; }
            ToolStripItem item = (ToolStripItem)sender;
            switch (item.Tag)
            {
                case int n when n > 0:
                    Itrycn_Info.Timer_index += n * 60;
                    Itrycn_Info.DelayRestIndex++;
                    IsDelay = n;
                    this.Close();
                    break;
            }
        }
        private void Timer1_Tick(object sender, EventArgs e)
        {
            Int64 second=Itrycn_Info.Timer_index;
            if(second>=0)
            {
                if (Itrycn_Info.IsStopCalcRestNowing)
                {
                    if (!panel1.Visible) {  panel1.Visible = true; }
                    LblMode.Text = Itrycn_Info.IsStopCalcRestReason;
                }
                else
                {
                    if (panel1.Visible) { panel1.Visible = false; }
                    LblSecond.Text = second.ToInt().ToString();
                }
                if (second > 60) { this.Close(); }
                else if (Itrycn_Info.IsRestNowing) { this.Close(); }
            }
            else
            {
                this.Close();
            }
        }
        public void StartLoad()
        {
            timer1.Start();
        }
        private void LblDelay_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (canDelay)
            {
                LinkLabel btn = (LinkLabel)sender;
                Point p = new Point(0, btn.Height);
                contextMenuStrip1.Show(btn, p);
            }
            else
            {
                Itrycn_Info.DelayRestIndex = 0;
                Itrycn_Info.Timer_index = 0;
                this.Close();
            }
        }

        private void 立即休息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Itrycn_Info.DelayRestIndex=0;
            Itrycn_Info.Timer_index = 1;
            IsDelay = -1;
            this.Close();
        }

        private void FrmBeforeRestTip_FormClosed(object sender, FormClosedEventArgs e)
        {
            Itrycn_Info.StickyList.Remove(this);
        }
    }
}
