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;
using SixGroup_Knowledge.Class;
using SixGroup_Knowledge.OtherView;

namespace SixGroup_Knowledge.Model
{

    public partial class Model : Form
    {

        public const int PICMINBUT = 0;
        public const int PICMAXBUT = 1;
        public const int PICCLOSEBUT = 2;

        //获得屏幕的宽和高
        protected int winWidth = Screen.PrimaryScreen.Bounds.Width;
        protected int winHeight = Screen.PrimaryScreen.Bounds.Height;
        //窗体是否可被移动
        private Boolean isMove = false;
        //窗体移动标记位置
        private Point mouseOffset;

        protected SQLHelper db = null;

        public Model()
        {
            InitializeComponent();
            db = new SQLHelper();
        }

        private void Model_Load(object sender, EventArgs e)
        {
            this.Size = new Size(1200,680);
        }


        private void moveTitle_MouseDown(object sender, MouseEventArgs e)
        {
            this.isMove = true;//鼠标按下时设置窗口为可拖动
            mouseOffset = new Point(-e.X, -e.Y);
        }
        private void moveTitle_MouseUp(object sender, MouseEventArgs e)
        {
            this.isMove = false;//鼠标抬起时设置窗口为不可拖动
        }

        //窗体移动
        private void moveTitle_MouseMove(object sender, MouseEventArgs e)
        {
            //如果为不可移动状态则直接返回
            if (!this.isMove)
                return;
            //获得鼠标在屏幕中的位置
            Point mouseSet = Control.MousePosition;
            //减去鼠标在窗体中的位置
            mouseSet.Offset(mouseOffset.X, mouseOffset.Y);

            //防止窗体被拖出屏幕
            if (mouseSet.X < 0)
                mouseSet.X = 0;
            if (mouseSet.X > this.winWidth - this.Width)
                mouseSet.X = this.winWidth - this.Width;
            if (mouseSet.Y < 0)
                mouseSet.Y = 0;
            if (mouseSet.Y > this.winHeight - this.Height)
                mouseSet.Y = this.winHeight - this.Height;
            //设置窗体位置
            Location = mouseSet;
        }

        private void titleMouserHover(object sender, EventArgs e)
        {
            PictureBox picBut = sender as PictureBox;
            switch (getButNameId(picBut.Name))
            {
                case PICMINBUT:
                    picBut.Image = Properties.Resources.min_but_hover;
                    break;
                case PICMAXBUT:
                    picBut.Image = Properties.Resources.max_but_hover;
                    break;
                case PICCLOSEBUT:
                    picBut.Image = Properties.Resources.close_but_hover;
                    break;
            }
        }

        private void titleMouserLeave(object sender, EventArgs e)
        {
            PictureBox picBut = sender as PictureBox;
            switch (getButNameId(picBut.Name))
            {
                case PICMINBUT:
                    picBut.Image = Properties.Resources.min_but_def;
                    break;
                case PICMAXBUT:
                    picBut.Image = Properties.Resources.max_but_def;
                    break;
                case PICCLOSEBUT:
                    picBut.Image = Properties.Resources.close_but_def;
                    break;
            }
        }

        private void titleMouserClick(object sender, EventArgs e)
        {
            PictureBox picBut = sender as PictureBox;
            switch (getButNameId(picBut.Name))
            {
                case PICMINBUT:
                    this.WindowState = FormWindowState.Minimized;
                    break;
                case PICMAXBUT:
                    MaskForm maskForm = new MaskForm();
                    maskForm.Show();
                    break;
                case PICCLOSEBUT:
                    this.Close();
                    break;
            }
        }
        public int getButNameId(String name){
            switch (name)
            {
                case "pic_min_but":
                    return PICMINBUT;
                case "pic_max_but":
                    return PICMAXBUT;
                case "pic_close_but":
                    return PICCLOSEBUT;
            }
            return -1;
        }


    }
}
