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

namespace Project.Dialog
{
    public partial class fJobSelect : Form
    {
        private Boolean fMove = false;
        private Point MDownPos;
        private string _msg = string.Empty;

        public fJobSelect()
        {
            InitializeComponent();
        }

        public fJobSelect(string msg)
        {
            InitializeComponent();
            this.FormClosing += fMsgWindow_FormClosing;
            this.KeyDown += FJobSelect_KeyDown;
            this._msg = msg;
            setMessage(msg);
            this.lbTitle.MouseMove += label1_MouseMove;
            lbTitle.MouseUp += label1_MouseUp;
            lbTitle.MouseDown += label1_MouseDown;
            lbTitle.MouseDoubleClick += label1_MouseDoubleClick;
        }

        void fMsgWindow_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void fMsg_Load(object sender, EventArgs e)
        {

        }
        private void FJobSelect_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                e.Handled = true;
                e.SuppressKeyPress = false;
                DialogResult = DialogResult.Cancel;
                this.Close();
            }
            else if (e.KeyCode == Keys.F5)
                btYes.PerformClick();
        }

        public void setMessage(string msg)
        {
            //msg를 분리해서 표시를 한다.
            var lbs = new arCtl.arLabel[] { lbTitle, lb1, lb2, lb3, lb4, lb5 };
            var lineBuf = msg.Replace("\r", "").Split('\n');
            int maxLine = Math.Min(lbs.Length, lineBuf.Length);

            for (int i = 0; i < lbs.Length; i++)   //최대줄을 넘어가는건 표시불가
            {
                if (i >= lineBuf.Length)
                {
                    lbs[i].Text = string.Empty;
                }
                else
                {
                    if (i > 0) lbs[i].Text = string.Format("{0}. {1}", i, lineBuf[i]);
                    else lbs[i].Text = lineBuf[i];
                }

            }
        }



        private void label1_MouseMove(object sender, MouseEventArgs e)
        {
            if (fMove)
            {
                Point offset = new Point(e.X - MDownPos.X, e.Y - MDownPos.Y);
                this.Left += offset.X;
                this.Top += offset.Y;
                offset = new Point(0, 0);
            }
        }

        private void label1_MouseUp(object sender, MouseEventArgs e)
        {
            fMove = false;
        }

        private void label1_MouseDown(object sender, MouseEventArgs e)
        {
            MDownPos = new Point(e.X, e.Y);
            fMove = true;
        }

        private void label1_MouseDoubleClick(object sender, MouseEventArgs e)
        {


        }
        public enum EWinColor
        {
            Attention = 0,
            Error,
            Information
        }

        public void SetWindowColor(EWinColor wincolor)
        {
            switch (wincolor)
            {
                case EWinColor.Attention:
                    lbTitle.BackColor = Color.Gold;
                    lbTitle.BackColor2 = Color.Orange;
                    lbTitle.ShadowColor = Color.FromArgb(150, 150, 150);
                    lbTitle.ForeColor = Color.FromArgb(50, 50, 50);
                    break;
                case EWinColor.Error:
                    lbTitle.BackColor = Color.Brown;
                    lbTitle.BackColor2 = Color.Tomato;
                    lbTitle.ShadowColor = Color.FromArgb(50, 50, 50);
                    lbTitle.ForeColor = Color.WhiteSmoke;
                    break;
                default:
                    lbTitle.BackColor = Color.DarkTurquoise;
                    lbTitle.BackColor2 = Color.LightSkyBlue;
                    lbTitle.ShadowColor = Color.FromArgb(50, 50, 50);
                    lbTitle.ForeColor = Color.WhiteSmoke;
                    break;
            }
        }

        private void lbTitle_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void tmBlink_Tick(object sender, EventArgs e)
        {
            var bg1 = lbTitle.BackColor;
            var bg2 = lbTitle.BackColor2;
            if (bg1 != null) lbTitle.BackColor2 = (Color)bg1;
            if (bg2 != null) lbTitle.BackColor = (Color)bg2;

        }

        private void btYes_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void btNo_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();

        }
    }
}
