FrmAnalyze.cs
7.1 KB
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
using OnlineStore.Common;
using OnlineStore.DeviceLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.AutoCountClient
{
partial class FrmAnalyze : FrmBase
{
public FrmAnalyze()
{
InitializeComponent();
}
public static DateTime PreStartTime = new DateTime(0);
public static DateTime PreEndTime = new DateTime(0);
private void FrmAnalyze_Load(object sender, EventArgs e)
{
if (PreStartTime.Ticks > 0 && PreEndTime.Ticks > 0)
{
dtpStartTime.Value = PreStartTime;
dtpEndTime.Value = PreEndTime;
}
else
{
DateTime time1 = DateTime.Now.AddHours(-6);
//dtpStartTime.Value = new DateTime(time1.Year, time1.Month, time1.Day, 0, 0, 0);
dtpStartTime.Value = time1;
DateTime time = DateTime.Now.AddDays(-1);
dtpEndTime.Value = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59);
dtpEndTime.Value = DateTime.Now;
}
}
private void btnSearch_Click(object sender, EventArgs e)
{
if (RobotManager.robot.sQLite == null)
{
MessageBox.Show("数据未初始化完成,请稍后!");
return;
}
//RobotManager.robot.sQLite.Insert("", 0, 0, 0, "123");
DateTime startTime = dtpStartTime.Value;
DateTime endTime = dtpEndTime.Value;
if (startTime < DateTime.Now.AddDays(-30))
{
MessageBox.Show("请输入正确的时间(只能查询近30天的日志)");
dtpStartTime.Focus();
return;
}
if (startTime> endTime)
{
MessageBox.Show("请输入正确的时间(开始时间必须小于结束时间)");
dtpEndTime.Focus();
return;
}
PreStartTime = startTime;
PreEndTime = endTime;
string code = txtCode.Text.Trim();
try
{
lastList = new List<XRayHistory>();
string[][] array = null;
string str = "yyyy-MM-dd HH:mm:ss";
string startStr = startTime.ToString(str);
string endStr = endTime.ToString(str);
bool result = RobotManager.robot.sQLite.Select(code, startStr,endStr, out array);
LogUtil.error("查数据【" + code + "】【" + startStr + "】【" + endStr + "】结果:" + result + "," + RobotManager.robot.sQLite.ErrInfo);
if (array != null && array.Length > 0)
{
LogUtil.info("共查询到【" + array.Length + "】行数据");
label4.Text = "开始时间["+ startStr + "] 结束时间["+ endStr + "] 条码["+ code + "] 共查询到"+ array.Length + "条记录";
this.dataGridView1.Rows.Clear();
int index = 1;
foreach (string[] a in array)
{
DataGridViewRow view = new DataGridViewRow();
view.CreateCells(dataGridView1);
view.Cells[0].Value = index;
if (a.Length >= 6)
{
XRayHistory his = new XRayHistory(index, a[0], a[1], a[2], a[3], a[4], a[5]);
lastList.Add(his);
view.Cells[Column_Code.Index] .Value= his.Code;
view.Cells[Column_Count.Index].Value = his.Count;
view.Cells[Column_Data.Index].Value = his.DataStr;
view.Cells[Column_Height.Index].Value = his.Height;
view.Cells[Column_Width.Index].Value = his.Width;
view.Cells[Column_ImageName.Index].Value = his.FileName;
}
dataGridView1.Rows.Add(view);
index++;
}
}
else
{
this.dataGridView1.Rows.Clear();
MessageBox.Show("未查询到点料记录");
}
}catch(Exception ex)
{
LogUtil.error("查询数据出错:" + ex.ToString());
}
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Close();
}
private List<XRayHistory> lastList = new List<XRayHistory>();
private void btnExport_Click(object sender, EventArgs e)
{
if (lastList.Count > 0)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = "";
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
sfd.FileName = "点料记录" + "-" + DateTime.Now.ToString("yyyy:MM:dd:HH:mm").Replace(":", "");
sfd.Filter = @"csv|*.csv";
DialogResult result = sfd.ShowDialog();
if (result.Equals(DialogResult.OK))
{
string filePath = sfd.FileName;
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
List<string> list = new List<string>();
list.Add("编号,条码,时间,数量,高度,宽度,图片文件名");
foreach(XRayHistory obj in lastList)
{
list.Add(obj.ToCSVStr());
}
File.WriteAllLines(filePath, list.ToArray<string>(), Encoding.UTF8);
MessageBox.Show("成功导出程序到文件:" + "\r\n" + filePath);
}
}
}
else
{
MessageBox.Show("暂无数据可导出");
}
}
}
public class XRayHistory
{
public XRayHistory(int num,string code, string h, string w, string c, string fname,string dataStr)
{
this.Code = code;
this.Height = h;
this.Width = w;
this.Count = c;
this.FileName = fname;
this.DataStr = dataStr;
}
public int Num = 0;
public string Code = "";
public string Height = "";
public string Width = "";
public string Count = "";
public string FileName = "";
public string DataStr = "";
public string ToCSVStr()
{
return Num+","+ Code + "," + DataStr + "," + Count + "," + Height + "," + Width + "," + FileName ;
}
}
}