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.
287 lines
9.3 KiB
C#
287 lines
9.3 KiB
C#
using DataBlockHelper.DBHelpers;
|
|
|
|
using DevExpress.Utils.Extensions;
|
|
|
|
using Mesnac.Action.Base;
|
|
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;
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.LjReport.DayWhiteEmbryo
|
|
{
|
|
public class GhWuLiaoInitDb : ChemicalWeighingAction, IAction
|
|
{
|
|
private RuntimeParameter _runtime;
|
|
MCButton selectButton;
|
|
MCDateTimePicker startDate;
|
|
MCDateTimePicker startTime;
|
|
MCDateTimePicker endDate;
|
|
MCDateTimePicker endTime;
|
|
|
|
MCDataGridView dataGridView;
|
|
MCDataGridView moreData;
|
|
|
|
DataTable dt;
|
|
DataTable MoreDataTable;
|
|
|
|
List<GhWuLiaoIniEntity> list;
|
|
|
|
|
|
MCButton WhiteWork;
|
|
MCButton NightWork;
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime); //必须调用
|
|
this._runtime = runtime;
|
|
var control = GetAllControls();
|
|
|
|
dataGridView = control.FirstOrDefault(x => x.Name == "MCDataGridView1") as MCDataGridView;
|
|
selectButton = control.FirstOrDefault(x => x.Name == "SelectButton") as MCButton;
|
|
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;
|
|
|
|
|
|
|
|
WhiteWork = control.FirstOrDefault(x => x.Name == "WhiteWork") as MCButton;
|
|
NightWork = control.FirstOrDefault(x => x.Name == "NightWork") as MCButton;
|
|
|
|
WhiteWork.Click += WhiteWork_Click;
|
|
NightWork.Click += WhiteWork_Click;
|
|
|
|
|
|
startDate.Value = DateTime.Now.AddDays(-1);
|
|
|
|
selectButton.Click += SelectButton_Click;
|
|
|
|
|
|
|
|
|
|
SelectButton_Click(new object(),new EventArgs());
|
|
|
|
|
|
|
|
|
|
//MoreDataTable = new DataTable();
|
|
//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 SelectButton_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
dt = GetDefault();
|
|
|
|
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);
|
|
|
|
string statValue = starttime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string endValue = endtime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
FillData(statValue, endValue);
|
|
|
|
}
|
|
|
|
private void WhiteWork_Click(object sender, EventArgs e)
|
|
{
|
|
dt = GetDefault();
|
|
DateTime nowTime = DateTime.Now;
|
|
|
|
DateTime starttime=DateTime.Now;
|
|
DateTime endtime=DateTime.Now;
|
|
|
|
if (((Button)sender).Text.Contains("白"))
|
|
{
|
|
//如果大于当天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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//如果小于当天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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
string statValue = starttime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string endValue = endtime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
startDate.Value = Convert.ToDateTime(starttime.ToString("yyyy-MM-dd"));
|
|
endDate.Value = Convert.ToDateTime(endtime.ToString("yyyy-MM-dd"));
|
|
|
|
startTime.Value = Convert.ToDateTime(starttime.ToString("HH:mm:ss"));
|
|
endTime.Value = Convert.ToDateTime(endtime.ToString("HH:mm:ss"));
|
|
|
|
|
|
FillData(statValue, endValue);
|
|
}
|
|
|
|
|
|
|
|
private void FillData(string statValue, string endValue)
|
|
{
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
list = new List<GhWuLiaoIniEntity>();
|
|
|
|
for (int i = 1; i < 5; i++)
|
|
{
|
|
|
|
|
|
string sql = "select t2.dryNo, eqNo, t1.batch ,t1.matCode,\r\n " +
|
|
" t1.actValue, t1.actToler, t1.recordTime\r\n " +
|
|
" from Report_DryDos_Detail t1\r\n " +
|
|
" left join Report_Dry t2 on t1.reportId= t2.reportId\r\nwhere " +
|
|
$"t2.dryNo='{i}' and t2.recordTime>'{statValue}' and t2.recordTime<='{endValue}'\r\n\r\norder by t1.matCode";
|
|
|
|
dbHelper.CommandText = sql.ToString();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
DataTable table2 = dbHelper.ToDataTable();
|
|
|
|
foreach (DataRow dr in table2.Rows)
|
|
{
|
|
GhWuLiaoIniEntity entity = new GhWuLiaoIniEntity();
|
|
entity.dryNo = i;
|
|
entity.matCode = Convert.ToInt32(dr["matCode"].ToString());
|
|
entity.actValue = Convert.ToSingle(dr["actValue"].ToString());
|
|
list.Add(entity);
|
|
|
|
}
|
|
}
|
|
|
|
dt.Rows.Clear();
|
|
|
|
var drTotal = dt.NewRow();
|
|
drTotal[0] = "总计";
|
|
for (int i = 1; i < 5; i++)
|
|
{
|
|
DataRow dr = dt.NewRow();
|
|
dr[0] = "干混机" + i;
|
|
for (int j = 1; j <= 15; j++)
|
|
{
|
|
var actValue = list.Where(x => x.dryNo == i)
|
|
.Where(x => x.matCode == j).Sum(x => x.actValue);
|
|
|
|
dr[j] = actValue.ToString("#0.00");
|
|
|
|
|
|
}
|
|
|
|
|
|
dt.Rows.Add(dr);
|
|
}
|
|
|
|
for (int j = 1; j <= 15; j++)
|
|
{
|
|
drTotal[j] = list
|
|
.Where(x => x.matCode == j).Sum(x => x.actValue).ToString("#0.00");
|
|
}
|
|
|
|
dt.Rows.Add(drTotal);
|
|
|
|
dt.Columns.Remove("木薯粉总量");
|
|
dt.Columns.Remove("玉米粉总量");
|
|
|
|
|
|
for (int j = 0; j <= 4; j++)
|
|
{
|
|
var dr = dt.Rows[j];
|
|
float total = 0;
|
|
for (int i = 1; i <= 13; i++)
|
|
{
|
|
total += Convert.ToSingle(dr[i]);
|
|
}
|
|
dr[14] = total.ToString("#0.00");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dataGridView.AutoGenerateColumns = true;
|
|
this.dataGridView.DataSource = null;
|
|
|
|
this.dataGridView.DataSource = dt;
|
|
}
|
|
|
|
private DataTable GetDefault()
|
|
{
|
|
dt = new DataTable();
|
|
dt.Columns.Add("机台", typeof(string));
|
|
|
|
dt.Columns.Add("小料1总量", typeof(string));
|
|
dt.Columns.Add("碳酸钙总量", typeof(string));
|
|
dt.Columns.Add("木粉总量", typeof(string));
|
|
dt.Columns.Add("碳粉9总量", typeof(string));
|
|
|
|
dt.Columns.Add("木薯粉总量", typeof(string));
|
|
dt.Columns.Add("玉米粉总量", typeof(string));
|
|
|
|
dt.Columns.Add("炭粉1总量", typeof(string));
|
|
dt.Columns.Add("炭粉2总量", typeof(string));
|
|
dt.Columns.Add("炭粉3总量", typeof(string));
|
|
dt.Columns.Add("炭粉4总量", typeof(string));
|
|
dt.Columns.Add("炭粉5总量", typeof(string));
|
|
dt.Columns.Add("炭粉6总量", typeof(string));
|
|
dt.Columns.Add("炭粉7总量", typeof(string));
|
|
dt.Columns.Add("炭粉8总量", typeof(string));
|
|
dt.Columns.Add("回收总量", typeof(string));
|
|
|
|
dt.Columns.Add("总计", typeof(string));
|
|
|
|
return dt;
|
|
}
|
|
}
|
|
|
|
public class GhWuLiaoIniEntity
|
|
{
|
|
public int dryNo { get; set; }
|
|
|
|
/// <summary>
|
|
/// 物料编码
|
|
/// </summary>
|
|
public int matCode { get; set; }
|
|
|
|
|
|
public float actValue { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|