using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using CRVM.CIDExcuter;
using CRVM.Entity;

namespace CRVM
{
    public partial class OnlineRollForm : Form
    {
        string exp_msg = "";
        public OnlineRollForm()
        {
            InitializeComponent();
        }

        private void RollInfo_Load(object sender, EventArgs e)
        {
            label_alarm.Text = "正在读取在线轧辊信息!";
            label_alarm.Visible = true;

            backgroundWorker.DoWork += backgroundWorker_DoWork;
            backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;

            if (!backgroundWorker.IsBusy)
            {
                backgroundWorker.RunWorkerAsync();
            }
        }

        void backgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {
            DataTable data = (DataTable)e.Result;
            string msg = "";
            if (data != null)
            {
                if (data.Rows.Count == 1)
                {
                    for (int i = 0; i < data.Columns.Count; i++)
                    {
                        string controlName = "dia_" + i.ToString();
                        TextBox box = (TextBox)panel2.Controls[controlName];
                        if (box != null)
                        {
                            box.Text = data.Rows[0][i].ToString();
                        }
                    }
                    label_alarm.Visible = false;
                }
            }
            else
            {
                exp_msg = "读取在线轧辊数据失败，请查看数据库连接配置或网络状态！异常信息如下：" + exp_msg;
                MessageShowForm form = new MessageShowForm("警告", exp_msg);
                form.ShowDialog();

                label_alarm.Text = "读取在线轧辊数据失败!";
                label_alarm.Visible = true;
            }
        }

        private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            DataTable data = null;
            try
            {
                data = DbHelper.GetInstance("").GetL2OnlineRollInfo();
            }
            catch (Exception ex)
            {
                exp_msg = ex.ToString();
            }
            e.Result = data;
        }

        private void label12_Click(object sender, EventArgs e)
        {

        }
    }
}
