You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/DayWhiteEmbryo/GelBlackPowderCount.cs

218 lines
8.0 KiB
C#

using DevExpress.Xpo.Helpers;
using DevExpress.XtraRichEdit.Model;
using FastReport.Dialog;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.FreeDb;
using Mesnac.Action.ChemicalWeighing.ManualControl;
using Mesnac.Codd.Session;
using Mesnac.Controls.Default;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace Mesnac.Action.ChemicalWeighing.LjReport.DayWhiteEmbryo
{
public class GelBlackPowderCount : ChemicalWeighingAction, IAction
{
//BtnOk MCDateTimePicker1 MCDataGridView1
private RuntimeParameter _runtime;
MCButton btnOk;
MCButton selectButton;
MCButton WhiteWork;
MCButton NightWork;
MCDateTimePicker mCDateTimePicker;
MCDateTimePicker startDate;
MCDateTimePicker startTime;
MCDateTimePicker endDate;
MCDateTimePicker endTime;
MCDataGridView dataGridView;
MCDataGridView moreData;
DataTable dt;
DataTable MoreDataTable;
List<ManualLogEntity> list;
List<ManualLogEntity> listMore;
List<ManualLogEntity> listSet;
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
var control = GetAllControls();
mCDateTimePicker = control.FirstOrDefault(x => x.Name == "MCDateTimePicker1") as MCDateTimePicker;
btnOk = control.FirstOrDefault(x => x.Name == "MCButton1") as MCButton;
dataGridView = control.FirstOrDefault(x => x.Name == "MCDataGridView1") as MCDataGridView;
selectButton = control.FirstOrDefault(x => x.Name == "SelectButton") as MCButton;
WhiteWork = control.FirstOrDefault(x => x.Name == "WhiteWork") as MCButton;
NightWork = control.FirstOrDefault(x => x.Name == "NightWork") as MCButton;
moreData = control.FirstOrDefault(x => x.Name == "MoreData") as MCDataGridView;
startDate = control.FirstOrDefault(x => x.Name == "startDate") as MCDateTimePicker;
startTime = control.FirstOrDefault(x => x.Name == "startTime") as MCDateTimePicker;
endDate = control.FirstOrDefault(x => x.Name == "endDate") as MCDateTimePicker;
endTime = control.FirstOrDefault(x => x.Name == "endTime") as MCDateTimePicker;
dataGridView.AutoGenerateColumns = true;
mCDateTimePicker.Value = DateTime.Now.AddDays(0);
startDate.Value = DateTime.Now.AddDays(-1);
//startTime.Value = Convert.ToDateTime(DateTime.Now.ToString("08:00:00"));
//endTime.Value = Convert.ToDateTime(DateTime.Now.ToString("20:00:00"));
dt = new DataTable();
dt.Columns.Add("机台", typeof(string));
dt.Columns.Add("总量", typeof(string));
MoreDataTable = new DataTable();
MoreDataTable.Columns.Add("设定重量", typeof(string));
MoreDataTable.Columns.Add("实际重量", typeof(string));
MoreDataTable.Columns.Add("时间", typeof(string));
btnOk.Click += BtnOk_Click;
selectButton.Click += SelectButton_Click;
dataGridView.CellClick += MoreData_Click;
dataGridView.CellValueChanged += MoreData_Click;
WhiteWork.Click += WhiteWork_Click;
NightWork.Click += NightWork_Click;
}
private void BtnOk_Click(object sender, EventArgs e)
{
dt.Rows.Clear();
string time = mCDateTimePicker.Value.ToString("yyyyMMdd");
list = FreeSqlUnit.Instance.Select<ManualLogEntity>().Where(x => x.createdate == time && x.valuekind == 4 && x.devicekind == 2).ToList();
DataTableSum();
}
private void SelectButton_Click(object sender, EventArgs e)
{
dt.Rows.Clear();
DateTime starttime = startDate.Value.Date.AddHours(startTime.Value.Hour).AddMinutes(startTime.Value.Minute).AddSeconds(startTime.Value.Second);
DateTime endtime = endDate.Value.Date.AddHours(endTime.Value.Hour).AddMinutes(endTime.Value.Minute).AddSeconds(endTime.Value.Second);
list = FreeSqlUnit.Instance.Select<ManualLogEntity>().Where(x => (x.logtime >= starttime && x.logtime <= endtime) && x.valuekind == 4 && x.devicekind == 2).ToList();
DataTableSum();
}
private void MoreData_Click(object sender, EventArgs e)
{
MoreDataTable.Rows.Clear();
string dID = dataGridView.SelectedRows[0].Cells["机台"].Value as string;
char[] a = dID.ToCharArray();
char chr = a[3];
if (chr == '和')
{
return;
}
int num = int.Parse(chr.ToString());
listMore = list.Where(x => x.deviceno == num).ToList();
listSet = FreeSqlUnit.Instance.Select<ManualLogEntity>().Where(x => x.valuekind == 3 && x.devicekind == 2 && x.deviceno == num).ToList();
for (int i = 0; i < listMore.Count; i++)
{
var dr = MoreDataTable.NewRow();
var val = listSet.Where(x => x.logtime <= listMore[i].logtime);
if (val.Count() != 0)
{
dr[0] = val.LastOrDefault().value;
}
dr[1] = listMore[i].value;
dr[2] = listMore[i].logtime;
MoreDataTable.Rows.Add(dr);
}
moreData.DataSource = null;
moreData.DataSource = MoreDataTable;
}
private void WhiteWork_Click(object sender, EventArgs e)
{
dt.Rows.Clear();
DateTime nowTime = DateTime.Now;
DateTime starttime;
DateTime endtime;
//如果大于当天8点 就展示当天的白班 否则展示上一个白班
if (nowTime >= DateTime.Now.Date.AddHours(8))
{
starttime = DateTime.Now.Date.AddHours(7).AddMinutes(30);
endtime = DateTime.Now.Date.AddHours(19).AddMinutes(30);
}
else
{
starttime = DateTime.Now.Date.AddHours(-17).AddMinutes(30);
endtime = DateTime.Now.Date.AddHours(-5).AddMinutes(30);
}
list = FreeSqlUnit.Instance.Select<ManualLogEntity>().Where(x => (x.logtime >= starttime && x.logtime <= endtime) && x.valuekind == 4 && x.devicekind == 2).ToList();
DataTableSum();
}
private void NightWork_Click(Object sender, EventArgs e)
{
dt.Rows.Clear();
DateTime nowTime = DateTime.Now;
DateTime starttime;
DateTime endtime;
//如果小于当天20点 就展示当天的前一个晚班
if (nowTime <= DateTime.Now.Date.AddHours(20))
{
starttime = DateTime.Now.Date.AddHours(-5).AddMinutes(30);
endtime = DateTime.Now.Date.AddHours(7).AddMinutes(30);
}
else
{
starttime = DateTime.Now.Date.AddHours(19).AddMinutes(30);
endtime = DateTime.Now.Date.AddHours(31).AddMinutes(30);
}
list = FreeSqlUnit.Instance.Select<ManualLogEntity>().Where(x => (x.logtime >= starttime && x.logtime <= endtime) && x.valuekind == 4 && x.devicekind == 2).ToList();
DataTableSum();
}
private void DataTableSum()
{
for (int i = 1; i <= 8; i++)
{
var dr = dt.NewRow();
dr[0] = "湿混机" + i;
var totalWeight = list.Where(x => x.deviceno == i).Sum(x => x.value);
dr[1] = totalWeight.ToString();
dt.Rows.Add(dr);
}
var edr = dt.NewRow();
edr[0] = "生产总和";
edr[1] = list.Sum(x => x.value).ToString();
dt.Rows.Add(edr);
dataGridView.DataSource = null;
dataGridView.DataSource = dt;
}
}
}