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 ControlSystem
{
    /// <summary>
    /// Creator:Richard.liu
    /// 设备故障查询
    /// </summary>
    public partial class FrmBrowseAotoTaskLog : Form
    {
        private static FrmBrowseAotoTaskLog _formInstance;

        public static FrmBrowseAotoTaskLog FormInstance
        {
            get 

            {
                if (_formInstance == null)
                {
                    _formInstance = new FrmBrowseAotoTaskLog();
                }
                return _formInstance; 
            }
            set { _formInstance = value; }
        }
        DBOperator dbo =CStaticClass.dbo;
        public FrmBrowseAotoTaskLog()
        {
            InitializeComponent();
            this.dateTimePicker1.Value = DateTime.Today;
            this.dateTimePicker2.Value = DateTime.Today;
            _formInstance = this;
        }

        private void btQuery_Click(object sender, EventArgs e)
        {
            string searchstr=string.Empty;

            if (this.comboBox_SearchKind.Text.Trim().Length != 0 && this.textBox_SearchKeyWord.Text.Trim().Length != 0)
            {
                searchstr = string.Format(" And {0} like '%{1}%'", comboBox_SearchKind.Text.Trim(), textBox_SearchKeyWord.Text.Trim());
            }

            //string sql = "SELECT * FROM V_manage_task_bak WHERE (开始时间 >= '" + dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") + "') AND (开始时间 <= '" + dateTimePicker2.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss") + "')";
            string sql = string.Format("SELECT * FROM V_manage_task_bak WHERE (开始时间 >= '{0}') AND (开始时间 <= '{1}' {2})",dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss"),dateTimePicker2.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"),searchstr); 

            DataView dv = dbo.ExceSQL(sql).Tables[0].DefaultView;

            this.dataGridView1.DataSource = dv;
   

        }

        private void btNullQuery_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确认要清空所有任务历史记录吗？", "操作提示：", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
            {
                return;
            }
        //    dbo.ExceSQL("delete from T_Manage_Task_BAK");
        }

        private void FrmBrowseAotoTaskLog_Load(object sender, EventArgs e)
        {
            DataView dvs = dbo.ExceSQL("Select name from syscolumns Where ID=OBJECT_ID('V_manage_task_bak') ORDER BY colorder").Tables[0].DefaultView;
            //cbstartposition
            comboBox_SearchKind.ValueMember = "name";
            comboBox_SearchKind.DisplayMember = "name";
            comboBox_SearchKind.DataSource = dvs;
            comboBox_SearchKind.SelectedIndex = -1;
        }

       
    }
}