patrick.xu
2021-03-10 990445751e7e7f65521d0413b7de4dc607e76e14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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 M423project
{
    public partial class FormWarning : Form
    {
        private List<WarningConfigure> _listAll = new List<WarningConfigure>();
        private List<WarningConfigure> _listTemp;
 
        public FormWarning()
        {
            InitializeComponent();
            grid.AutoGenerateColumns = false;
 
            BindCombobox();
        }
 
        private void BindCombobox()
        {
            WarningData warningData = new WarningData();
            _listAll.Add(new WarningConfigure { Val = 0, Content = "全部" });
            _listAll.AddRange(warningData.GetWarningType(null));
            cboType.DisplayMember = "Content";
            cboType.ValueMember = "Val";
            cboType.Items.AddRange(_listAll.ToArray());
            cboType.SelectedItem = _listAll[0];
        }
 
        private void btnQuery_Click(object sender, EventArgs e)
        {
            if ((dtBegin.Value.Date - dtEnd.Value.Date).Days > 0)
            {
                MessageBox.Show("开始时间不得大于结束时间");
                return;
            }
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(@"SELECT warnConfigure.Content Type,warn.Time,warn.ClearTime FROM Warning warn LEFT JOIN WarningConfigure 
                            warnConfigure ON warn.Type=warnConfigure.Val 
                            WHERE warn.Time BETWEEN '{0}' AND '{1}'", dtBegin.Value.ToString("yyyy-MM-dd 00:00:00"), dtEnd.Value.ToString("yyyy-MM-dd 23:59:59"));
            WarningConfigure selected = cboType.SelectedItem as WarningConfigure;
            if (selected != null && selected.Val != 0)
            {
                sb.AppendFormat(@" AND Type={0}", selected.Val);
            }
            sb.AppendFormat(" order by warn.Time");
            DataTable dt = CommonUtil.mainForm.DetectData.Query(sb.ToString());
            grid.DataSource = dt;
            grid.Columns["Time"].DefaultCellStyle.Format = "yyyy-MM-dd  HH:mm:ss";
            grid.Columns["ClearTime"].DefaultCellStyle.Format = "yyyy-MM-dd  HH:mm:ss";
        }
 
        private void cboType_TextUpdate(object sender, EventArgs e)
        {
            cboType.Items.Clear();
            _listTemp = new List<WarningConfigure>();
            if (cboType.Text == "")
            {
                cboType.Items.AddRange(_listAll.ToArray());
                return;
            }
            foreach (var item in _listAll)
            {
                if (item.Content.Contains(cboType.Text))
                {
                    _listTemp.Add(item);
                }
            }
            cboType.Items.AddRange(_listTemp.ToArray());
            cboType.SelectionStart = cboType.Text.Length;
            Cursor = Cursors.Default;
            cboType.DroppedDown = true;
        }
    }
}