qin
2025-03-17 a4657284bf071582077d84caf9e61b59d80c9796
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
using Yw;
using Yw.WinFrmUI;
 
 
namespace IBox.WinFrmUI
{
    public partial class IBoxFormLog : DocumentPage
    {
 
        private string startCode = "[&start&]";
        private string endCode = "[&end&]";
        private string paramCode = "[&param&]";
        private string getlogCode = "getlog";
        private string clearlogCode = "clearlog";
        public IBoxFormLog()
        {
            this.PageTitle.Caption = "日志管理";
            InitializeComponent();
        }
 
        private void EboxFormLog_Load(object sender, EventArgs e)
        {
            this.dateEditStartDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd");
            this.dateEditEndDate.EditValue = DateTime.Now.ToString("yyyy-MM-dd");
            SetData();
            var m = new GetCalcValueModel()
            {
                StartDate = DateTime.Parse(this.dateEditStartDate.EditValue.ToString()),
                EndDate = DateTime.Parse(this.dateEditEndDate.EditValue.ToString()),
                LogEvent = "",
                LogResult = ""
            };
 
            SendText(startCode + getlogCode + paramCode + JsonHelper.Object2Json(m) + endCode);
        }
 
        public void SetData()
        {
            var dic = GetDic();
            imageComboBoxEdit1.Properties.Items.Add("全部", "", -1);
            foreach (var item in dic)
            {
                imageComboBoxEdit1.Properties.Items.Add(item.Value, item.Key, -1);
            }
 
            imageComboBoxEdit2.Properties.Items.Add("全部", "", -1);
            imageComboBoxEdit2.Properties.Items.Add("成功", "success", -1);
            imageComboBoxEdit2.Properties.Items.Add("提示", "info", -1);
            imageComboBoxEdit2.Properties.Items.Add("失败", "fail", -1);
            imageComboBoxEdit2.Properties.Items.Add("异常", "error", -1);
 
            imageComboBoxEdit1.SelectedIndex = 0;
            imageComboBoxEdit2.SelectedIndex = 0;
 
        }
 
        public event EventHandler<string> SendData;
        private void SendText(string content)
        {
            //BluetoothHelper.GetInstance().SendData(content);
            SendData?.Invoke(null, content);
        }
 
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            //查询
            var m = new GetCalcValueModel()
            {
                StartDate = DateTime.Parse(this.dateEditStartDate.EditValue.ToString()),
                EndDate = DateTime.Parse(this.dateEditEndDate.EditValue.ToString()),
                LogResult = imageComboBoxEdit2.EditValue?.ToString(),
                LogEvent = imageComboBoxEdit1.EditValue?.ToString()
            };
 
            SendText(startCode + getlogCode + paramCode + JsonHelper.Object2Json(m) + endCode);
        }
 
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            //清空
            this.Invoke(new Action(() =>
            {
                eboxLogViewModelBindingSource.DataSource = null;
                this.gridView1.RefreshData();
            }));
            SendText(startCode + clearlogCode + paramCode + endCode);
        }
 
        private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
 
            if (e.Column.FieldName == "LogResult")
            {
                var celValue = e.CellValue.ToString();
                var celNewValue = "成功";
                switch (celValue)
                {
                    case "info":
                        celNewValue = "提示";
                        e.Appearance.ForeColor = Color.Blue;
                        break;
                    case "fail":
                        celNewValue = "失败";
                        e.Appearance.ForeColor = Color.Coral;
                        break;
                    case "error":
                        celNewValue = "异常";
                        e.Appearance.ForeColor = Color.Red;
                        break;
                    default:
                        celNewValue = "成功";
                        e.Appearance.ForeColor = Color.Green;
                        break;
                }
                e.CellValue = celNewValue;
            }
        }
 
        private Dictionary<string, string> GetDic()
        {
 
            return new Dictionary<string, string>
                            {
                                { "controll", "智能控制" },
                                { "postdata", "数据推送" },
                                { "default", "常规" },
                                { "datadocking", "数据采集" },
                            };
        }
        private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.FieldName == "LogEvent")
            {
                var celValue = e.Value.ToString();
                var celNewValue = "";
                // 创建一个字典,键为字符串,值为字符串
 
                var commandDescriptions = GetDic();
                string key = celValue;
                string value;
                if (commandDescriptions.TryGetValue(key, out value))
                {
                    celNewValue = value;
                }
 
                e.DisplayText = celNewValue;
            }
            if (e.Column.FieldName == "LogResult")
            {
                var celValue = e.Value.ToString();
                var celNewValue = "成功";
                switch (celValue)
                {
                    case "info":
                        celNewValue = "提示";
                        break;
                    case "fail":
                        celNewValue = "失败";
                        break;
                    case "error":
                        celNewValue = "异常";
                        break;
                    default:
                        celNewValue = "成功";
                        break;
                }
                e.DisplayText = celNewValue;
            }
 
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="eboxLogs"></param>
        /// <param name="isBlue"></param>
        public void BindData(List<IBoxLogViewModel> eboxLogs, bool isBlue = true)
        {
            if (isBlue)
            {
                this.Invoke(new Action(() =>
                {
                    eboxLogViewModelBindingSource.DataSource = eboxLogs;
                    this.gridView1.RefreshData();
                }));
            }
            else
            {
                eboxLogViewModelBindingSource.DataSource = eboxLogs;
                this.gridView1.RefreshData();
            }
        }
    }
}