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

using DBFactory;
namespace wcfControlMonitorClient
{
    /// <summary>
    /// Creator:Richard.liu
    /// 设备故障查询
    /// </summary>
    public partial class FrmDeviceErrorLog : Form
    {
        private static FrmDeviceErrorLog _formInstance;

        public static FrmDeviceErrorLog FormInstance
        {
            get 

            {
                if (_formInstance == null)
                {
                    _formInstance = new FrmDeviceErrorLog();
                }
                return _formInstance; 
            }
            set { _formInstance = value; }
        }
        DBOperator dbo =CStaticClass.dbo;
        public FrmDeviceErrorLog()
        {
            InitializeComponent();
            _formInstance = this;//20101028
        }

        private void btQuery_Click(object sender, EventArgs e)
        {
            string dfield,sql;
            switch (this.cbField.Text )
            {
                case "设备索引":
                    dfield = "设备索引";
                    break;
                case "设备名称":
                    dfield = "设备名称";
                    break;
                case "设备故障编号":
                    dfield = "设备故障编号";
                    break;
                case "设备种类索引":
                    dfield = "设备种类索引";
                    break;
                case "发生时间":
                    dfield = "发生时间";
                    break;
                default:
                    dfield = "设备索引";
                    break;
            }
            sql = "select * from V_Device_Error_log where " + dfield + " like '%"+this.tbContent.Text+"%'" ;
            DataSet ds = dbo.ExceSQL(sql);
            this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void btNullQuery_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确认要清空数据库内记录的所有历史报警吗?", "操作提示:", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
            {
                return;
            }
            dbo.ExceSQL("delete from T_Base_Device_Error_Log");
        }

        private void cbField_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dfield, sql;
            switch (this.cbField.Text)
            {
                case "设备索引":
                    dfield = "设备索引";
                    break;
                case "设备名称":
                    dfield = "设备名称";
                    break;
                case "设备故障编号":
                    dfield = "设备故障编号";
                    break;
                case "设备种类索引":
                    dfield = "设备种类索引";
                    break;
                case "发生时间":
                    dfield = "发生时间";
                    break;
                default:
                    dfield = "设备索引";
                    break;
            }
            sql = "select distinct "+dfield+" from V_Device_Error_log ";
            DataView  dv = dbo.ExceSQL(sql).Tables[0].DefaultView;
            this.tbContent.DisplayMember = dfield;
            this.tbContent.ValueMember = dfield;
            this.tbContent.DataSource = dv;
        }

        private void FrmDeviceErrorLog_FormClosing(object sender, FormClosingEventArgs e)
        {
            _formInstance = null;
        }
    }
}