using GcDevicePc.Common;
using GcDevicePc.ConfigMethod;
using GcDevicePc.Controls;
using GcDevicePc.GCBuffer;
using GcDevicePc.ProThread;
using Ini.Net;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GcDevicePc
{
    public partial class TestForm : Form
    {
        private Button MyButton;//创建Button
        public TestForm()
        {
            InitializeComponent();
            //bgWorker.DoWork += BgWorker_DoWork;
            //title.Show();

            //bgWorker.RunWorkerCompleted += BgWorker_RunWorkerCompleted;
            this.FormClosed += CloseDialog;
            MyButton = new Button();//实例化Button
            MyButton.Left = 30;//设置控件离form左边的距离
            MyButton.Top = 130;//设置控件离form上边的距离
            MyButton.Width = 200;//设置控件的宽度
            MyButton.Text = "弹出对话框";//按钮显示名称
            MyButton.Click += ShowMessage;//按钮单机事件
            this.Controls.Add(MyButton);//将控件加入到form中
        }
        //GCTitle title = new GCTitle();

        /// <summary>
        /// 弹出对话框
        /// </summary>
        /// <param name="sender">出发事件的对象</param>
        /// <param name="e">事件信息</param>
        private void ShowMessage(object sender, EventArgs e)
        {
            MessageBox.Show("这是最简单的弹出框", "弹出对话框");
        }
        /// <summary>
        /// 关闭提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseDialog(object sender, EventArgs e)
        {
            //创建我的提示框
            LMessageBox dialog = new LMessageBox(this.Location,this.Size, true, "123456", "11111111111111111111", LMessageBox.MessageBoxPosition.MBP_BottomRight);
            //注意提示框的返回值，是DialogResult这个枚举
            if (dialog.ShowDialog() == DialogResult.No)
            {
                ((System.ComponentModel.CancelEventArgs)e).Cancel = true;
            }
        }



        BackgroundWorker bgWorker = new BackgroundWorker();
        PrompBox loadingCtl = new PrompBox(162, true);//定义加载控件
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {

            System.Threading.Thread.Sleep(3000);

        }

        private void BgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            loadingCtl.Hide();

        }
        //Form1 form1;

        private void btnShow_Click(object sender, EventArgs e)
        {
            //loadingCtl.TipsInfo = "提示信息";
            ////显示加载动画
            //loadingCtl.ShowLoading(this);
            //Application.DoEvents();
            //bgWorker.RunWorkerAsync();

            //this.pictureMenu1.PMOptbtnstatus = 3;
            //(this.title.Controls.Find("pictureMenu1", true)[0] as PictureMenu).PMOptbtnstatus = 4;
            //kailiang

            //if (form1 == null)
            //{
            //    form1 = new Form1("asdasdasdsa");
            //    form1.Show();

            //}
            //else if(form1.IsDisposed)
            //{
            //    form1 = new Form1("asdasdasdsa");
            //    form1.Show();
            //}
            //else
            //{
            //    form1.Activate();
            //}

            //string savefilename = "C:\\Users\\24042\\Pictures\\新建文件夹\\test11.hw";
            //TWFile twfile = new TWFile(savefilename);
            //twfile.TW_Open();

            //twfile.TW_Close(0);

            //int i = 100 % 1;
            //timer1.Enabled = true;


        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataToZB.testzba();

        }
        int i = 0;
        private void Timer1_Tick(object sender, EventArgs e)
        {
            i++;

        }

        private void Button7_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb();
        }

        SendDataToZB dataToZB = new SendDataToZB();
        private void Button8_Click(object sender, EventArgs e)
        {
            //dataToZB.InitsendData();
            dataToZB.StartSendDataToZB();

            starttr();
        }

        Thread tr;
        private void starttr()
        {
            tr = new Thread(ths);
            tr.Start();
        }

        private void ths()
        {
            while (true)
            {
                dataToZB.testzb(2,10);
                Thread.Sleep(50);
            }
        }

        private void Button9_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(1, 0, 1);
        }

        private void Button10_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(1, 0, 2);
        }

        private void Button11_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(0, 1, 1);
        }

        private void Button12_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(0, 1, 2);
        }

        private void Button13_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(1, 0, 3);
        }

        private void Button14_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(1, 0, 4);
        }

        private void Button15_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(0, 1, 3);
        }

        private void Button16_Click(object sender, EventArgs e)
        {
            dataToZB.testzbb(0, 1, 4);
        }
    }
}
