111 lines
3.4 KiB
C#
111 lines
3.4 KiB
C#
using JY.DAL;
|
|
using JY.Model;
|
|
using MetroFramework.Forms;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace JY.Inspection.Frm
|
|
{
|
|
public partial class FrmAlamQuery : MetroForm
|
|
{
|
|
public delegate void myDelegate(List<AlarmData> dtt);
|
|
public delegate void PDelegate();
|
|
Thread tSo;
|
|
|
|
/// <summary>
|
|
/// 数据库访问接口
|
|
/// </summary>
|
|
private IDbHelper dbHelper = new OpSqlDataBase();
|
|
public FrmAlamQuery()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FrmAlamQuery_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
/// <summary>
|
|
/// 查询报警日志
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void btnSelect_Click(object sender, EventArgs e)
|
|
{
|
|
//string strDate1 = dtStartTime.Value.ToString("yyyy-MM-dd HH:mm") + ":01";
|
|
//string strDate2 = dtEndTime.Value.ToString("yyyy-MM-dd HH:mm") + ":59";
|
|
|
|
//var list = dbHelper.GetAlarmData(strDate1, strDate2);
|
|
|
|
//if (list == null || list.Count == 0)
|
|
//{
|
|
// MessageBox.Show("此时间段无数据或无此条码数据", "系统提示");
|
|
// lblSelectStures.BeginInvoke(new PDelegate(bb));
|
|
// return;
|
|
//}
|
|
//else
|
|
//{
|
|
// dgvData.DataSource = list;
|
|
//}
|
|
//以下线程方法
|
|
try
|
|
{
|
|
tSo = new Thread(new ThreadStart(ThreadWork));
|
|
tSo.IsBackground = true;
|
|
tSo.Start();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message.ToString() + ",数据查询失败", "查询提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
private void ThreadWork()
|
|
{
|
|
lblSelectStures.BeginInvoke(new PDelegate(aa));
|
|
string strDate1 = dtStartTime.Value.ToString("yyyy-MM-dd HH:mm") + ":01";
|
|
string strDate2 = dtEndTime.Value.ToString("yyyy-MM-dd HH:mm") + ":59";
|
|
if (dtEndTime.Value.Year != dtStartTime.Value.Year)
|
|
{
|
|
MessageBox.Show("请选择日期必须在同一年份内!");
|
|
lblSelectStures.BeginInvoke(new PDelegate(bb));
|
|
return;
|
|
}
|
|
|
|
var result = dbHelper.GetAlarmData(strDate1, strDate2);
|
|
if (result == null || result.Count == 0)
|
|
{
|
|
MessageBox.Show("此时间段无数据或无此条码数据", "系统提示");
|
|
lblSelectStures.BeginInvoke(new PDelegate(bb));
|
|
return;
|
|
}
|
|
this.dgvData.BeginInvoke(new myDelegate(FillData), new object[] { result });//异步调用(来填充)
|
|
lblSelectStures.BeginInvoke(new PDelegate(bb));
|
|
}
|
|
|
|
private void FillData(List<AlarmData> dt )
|
|
{
|
|
this.dgvData.DataSource = dt;
|
|
}
|
|
|
|
private void aa()
|
|
{
|
|
this.lblSelectStures.Text = "正在查询数据...";
|
|
}
|
|
private void bb()
|
|
{
|
|
this.lblSelectStures.Text = "查询结束";
|
|
}
|
|
}
|
|
}
|