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 ControlSystem
{
    public partial class FrmConfigManage : Form
    {
        private FrmConfigManage()
        {
            InitializeComponent();
        }

        private static FrmConfigManage _formInstance;
        public static FrmConfigManage FormInstance
        {
            get
            {
                if (_formInstance == null)
                {
                    _formInstance = new FrmConfigManage();
                }
                return _formInstance;
            }
            set
            {
                _formInstance = value;
            }
        }
        private void FrmConfigManage_Load(object sender, EventArgs e)
        {
            flush();
        }
        private void flush()
        {
            DataView dv = CStaticClass.dbo.ExceSQL("select * from t_base_device_taskcontrol order by index_order").Tables[0].DefaultView;
            if (dv.Count > 0)
            {
                this.comboBox1.DataSource = dv;
                this.comboBox1.DisplayMember = "device_name";
                this.comboBox1.ValueMember = "device_id";
                this.comboBox2.DataSource = dv;
                this.comboBox2.DisplayMember = "manage_max";
            }
            this.textBox1.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i =0;
            if (!int.TryParse(this.comboBox2.Text.Trim(), out i))
            {
                MessageBox.Show("任务数必须为数字");
                this.comboBox2.Focus();
                return;
            }
            if (this.comboBox1.SelectedValue == null)
            {
                MessageBox.Show("终点设备不能为空");
                this.comboBox1.Focus();
                return;
            }
            CStaticClass.dbo.ExceSQL("update t_base_device_taskcontrol set manage_max =" + i + " where device_id =" + Convert.ToInt32(this.comboBox1.SelectedValue));
            MessageBox.Show("修改成功");
            CommonClassLib.CCarryConvert.WriteDarkCasket("Login", "将：" + this.comboBox1.SelectedValue.ToString()+"设备" + "", "任务数改为"+i, "", "");
            flush();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Visible == false)
            {
                this.textBox1.Visible = true;
            }
            else
            {
                int i =0;
                if(!int.TryParse(this.textBox1.Text.Trim(),out i))
                {
                     MessageBox.Show("任务数必须为数字");
                    this.textBox1.Focus();
                    return;
                }
                CStaticClass.dbo.ExceSQL("update t_base_device_taskcontrol set manage_max =" + i);
                MessageBox.Show("修改成功");
                flush();

            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
