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

namespace ryControls
{
    /// <summary>
    /// 日控件
    /// </summary>
    internal partial class LunarDay : UserControl
    {
        /// <summary>
        /// 日控件
        /// </summary>
        public LunarDay()
        {
            InitializeComponent();
            LblDay.Left = border_width;
            LblDay.Width = Width - border_width - border_width;
            LblLunarDay.Left = border_width;
            LblLunarDay.Width = Width - border_width - border_width;
            LblDay.Click += LblDay_Click;
            LblLunarDay.Click += LblDay_Click;
            LblState.Location = new Point(border_width, border_width);
            LblState.Visible = false;
        }
        int border_width = 4;
        /// <summary>
        /// 当前日期
        /// </summary>
        public DateTime Date { get; set; } = DateTime.Now;
        private void LblDay_Click(object sender, EventArgs e)
        {
            base.OnClick(e); ;
        }
        public delegate void ProcessCmdKeyHandler(object sender, ref Message msg, Keys keyData);
        /// <summary>
        /// 在发生页码变化前激发
        /// </summary>
        [Description("在发生页码变化前激发")]
        public event ProcessCmdKeyHandler OnProcessCmdKey;
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            OnProcessCmdKey?.Invoke(this,ref msg,keyData);
            //return false;//如果要调用KeyDown,这里一定要返回false才行,否则只响应重写方法里的按键.
            //这里调用一下父类方向,相当于调用普通的KeyDown事件.//所以按空格会弹出两个对话框
            return base.ProcessCmdKey(ref msg, keyData);
        }
        /// <summary>
        /// 设置休息状态,1为休息,-1为上班，其它为不显示
        /// </summary>
        /// <param name="i"></param>
        public void SetRestState(int i)
        {
            if (i == -1) { LblState.Text = "班"; LblState.BackColor = Color.FromArgb(234, 131, 117); LblState.Visible = true; }
            else if (i == 1) { LblState.Text = "休"; LblState.BackColor = Color.FromArgb(0, 192, 0); LblState.Visible = true; }
            else { LblState.Visible = false; }
        }
        private int _day = 1;
        /// <summary>
        /// 日期
        /// </summary>
        public int Day
        {
            get { return _day; }
            set { _day = value;LblDay.Text = _day.ToString(); }
        }
        /// <summary>
        /// 农历
        /// </summary>
        public string Lunar_Day
        {
            get { return LblLunarDay.Text; }
            set { LblLunarDay.Text = value; toolTip1.SetToolTip(LblLunarDay, value); }
        }
        /// <summary>
        /// 阳历日期字体颜色
        /// </summary>
        public Color Day_ForeColor
        {
            get { return LblDay.ForeColor; }
            set { LblDay.ForeColor = value; }
        }
        /// <summary>
        /// 阳历日期字体
        /// </summary>
        public Font Day_Font
        {
            get { return LblDay.Font; }
            set { LblDay.Font = value; }
        }
        /// <summary>
        /// 农历日期字体
        /// </summary>
        public Font Lunar_Day_Font
        {
            get { return LblLunarDay.Font; }
            set { LblLunarDay.Font = value; }
        }
        /// <summary>
        /// 农历部分字体颜色
        /// </summary>
        public Color Lunar_Day_ForeColor
        {
            get { return LblLunarDay.ForeColor; }
            set { LblLunarDay.ForeColor = value; }
        }
        private bool _Selected = false;
        /// <summary>
        /// 是否选中
        /// </summary>
        public bool Selected
        {
            get { return _Selected; }
            set
            {
                if (_Selected != value)
                {
                    _Selected = value;
                    Refresh();
                }
            }
        }
        private void LunarDay_Paint(object sender, PaintEventArgs e)
        {
            if(Selected)
            e.Graphics.DrawRectangle(new Pen(Color.DeepSkyBlue,border_width), new Rectangle(0, 0, this.Width, this.Height));
        }
        private void DrawBorder(Graphics g, Rectangle rect, RoundStyle roundStyle, int radius)
        {
            rect.Width -= 1;
            rect.Height -= 1;
            using (GraphicsPath path =ryControls.Drawing.CreatePath(rect, radius, roundStyle, false))
            {
                SolidBrush myBrush = new SolidBrush(Color.White);
                using (Pen pen = new Pen(Color.Black))
                {
                    
                    g.FillPath(myBrush, path);
                    g.DrawPath(pen, path);
                }
            }
        }
    }
}
