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/Report/GelDoser/SelectRowAction.cs

243 lines
10 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Mesnac.Action.Base;
using Mesnac.Codd.Session;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Report.GelDoser
{
/// <summary>
/// 糊化机报表明细查询事件
/// </summary>
public class SelectRowAction : ChemicalWeighingAction, IAction
{
private Control _clientGridControl = null; //多维表控件
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须要调用的
ICSharpCode.Core.LoggingService<SelectAction>.Debug("糊化机报表-明细查询...");
//获取报表数据
DbMCControl _dgvGelDoser = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Report_GelDoser").FirstOrDefault();
if (_dgvGelDoser == null || !(_dgvGelDoser.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<SelectRowAction>.Warn("{生产报表} 缺少糊化机报表DataGridView控件...");
runtime.IsReturn = false;
return;
}
DataGridView _GelDoserGridView = _dgvGelDoser.BaseControl as DataGridView;
this._clientGridControl = GetAllControls().Where(x => x.Name.Contains("MultiColHeaderDgv1")).FirstOrDefault();
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid = (this._clientGridControl as Mesnac.Controls.Default.MultiColHeaderDgv);
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid2 = (GetAllControls().Where(x => x.Name.Contains("MultiColHeaderDgv2")).FirstOrDefault() as Mesnac.Controls.Default.MultiColHeaderDgv);
#region 明细控件格式化
clientGrid.myColHeaderTreeView = null;
clientGrid.DataSource = null;
clientGrid.iNodeLevels = 0;
clientGrid.ColLists.Clear();
clientGrid.ColumnHeadersHeight = 23;
clientGrid.ScrollBars = ScrollBars.Both;
clientGrid.AllowUserToAddRows = false;
clientGrid.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
clientGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
clientGrid.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12);
clientGrid.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 10);
clientGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
clientGrid2.myColHeaderTreeView = null;
clientGrid2.DataSource = null;
clientGrid2.iNodeLevels = 0;
clientGrid2.ColLists.Clear();
clientGrid2.ColumnHeadersHeight = 23;
clientGrid2.ScrollBars = ScrollBars.Both;
clientGrid2.AllowUserToAddRows = false;
clientGrid2.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
clientGrid2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
clientGrid2.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("宋体", 12);
clientGrid2.DefaultCellStyle.Font = new System.Drawing.Font("宋体", 10);
clientGrid2.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
#endregion
//获取选中行的ReportId关联获取明细数据并赋值给明细控件
if (_GelDoserGridView.SelectedRows.Count == 1)
{
string lR_planID = _GelDoserGridView.SelectedRows[0].Cells["reportId"].Value as string;
//获取数据链接
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
if (dbHelper == null)
{
ICSharpCode.Core.LoggingService<ExportAction>.Error("获取本地数据连接失败...");
return;
}
dbHelper.ClearParameter();
var tableNew=new DataTable();
tableNew.Columns.Add("批次号", typeof(string));
tableNew.Columns.Add("物料", typeof(string));
tableNew.Columns.Add("实际重量", typeof(string));
tableNew.Columns.Add("实际公差", typeof(string));
//获取明细数据
StringBuilder sqlStr = new StringBuilder(@"select t1.batch as 批次号,t2.MName as 物料,
t1.actValue as 实际重量,t1.actToler as 实际公差
from Report_GelDoser_Detail t1
left join lj_stock_material t2 on t1.matCode = t2.Code
where t2.MTypeId=1 and t1.kinds=1 and t1.reportId=@reportId
");
dbHelper.CommandText = sqlStr.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.AddParameter("@reportId", lR_planID);
DataTable table = dbHelper.ToDataTable();
foreach (DataRow item in table.Rows)
{
var dr = tableNew.NewRow();
dr["批次号"] = item["批次号"];
dr["物料"] = item["物料"];
dr["实际重量"] = Convert.ToSingle(item["实际重量"]).ToString("#0.00");
dr["实际公差"] = Convert.ToSingle(item["实际公差"]).ToString("#0.00");
tableNew.Rows.Add(dr);
}
//水 这个奇葩的设计
string sql = $"select t1.batch as 批次号,t2.MName as 物料,\r\nt1.actValue as 实际重量" +
$",t1.actToler as 实际公差 , t1.kinds \r\n from Report_GelDoser_Detail t1\r\n " +
$"left join lj_stock_material t2 on t1.matCode = t2.Code\r\n where t1.kinds <> 1 and t1.reportId='{lR_planID}'";
dbHelper.CommandText = sql.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
DataTable table1 = dbHelper.ToDataTable();
foreach (System.Data.DataColumn col in table1.Columns)
{
col.ReadOnly = false;
}
foreach (DataRow row in table1.Rows )
{
var kinds=row["kinds"].ToString();
if (kinds == "2")
{
row["物料"] = "热水";
}
else
{
row["物料"] = "冷水";
}
var dr = tableNew.NewRow();
dr["批次号"] = row["批次号"];
dr["物料"] = row["物料"];
dr["实际重量"] = Convert.ToSingle(row["实际重量"]).ToString("#0.00");
dr["实际公差"] = Convert.ToSingle(row["实际公差"]).ToString("#0.00");
tableNew.Rows.Add(dr);
}
clientGrid.DataSource = tableNew;
sql = $"select t1.actCode, t1. mixBatch as 批次,t1.mixStep as 步号,t2.ActionName as 动作,\r\n\t\t " +
$" t1.mixTime as 时间,t1.mixTemp as 温度,t1.mixSpeed as 速度,t1.recordTime as 记录时间\r\n " +
$" from Report_GelMixing_Detail t1\r\n " +
$" left join ActionCode t2 on t1.actCode =t2.Code\r\n\r\n " +
$" where t2.DeviceUnitId=2 and t1.reportId ='{lR_planID}'\r\n\r\n " +
$"" +
$" order by t1.actCode";
dbHelper.CommandText = sql.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
DataTable table2 = dbHelper.ToDataTable();
var tableNewB=new DataTable();
tableNewB.Columns.Add("批次", typeof(string));
tableNewB.Columns.Add("步号", typeof(string));
tableNewB.Columns.Add("动作", typeof(string));
tableNewB.Columns.Add("时间", typeof(string));
//tableNewB.Columns.Add("温度", typeof(string));
tableNewB.Columns.Add("速度", typeof(string));
tableNewB.Columns.Add("记录时间", typeof(string));
foreach (System.Data.DataRow row in table2.Rows)
{
row["速度"] = Convert.ToSingle(row["速度"]).ToString("#0.00");
row["动作"] = GelStepConvert(Convert.ToInt32(row["actCode"]));
var dr = tableNewB.NewRow();
dr["批次"] = row["批次"];
dr["步号"] = row["步号"];
dr["动作"] = row["动作"];
dr["时间"] = ConverToTime(Convert.ToInt32(row["时间"]));
//dr["温度"] = row["温度"];
dr["速度"] = row["速度"];
dr["记录时间"] = row["记录时间"];
tableNewB.Rows.Add(dr);
}
clientGrid2.DataSource = null;
clientGrid2.DataSource = tableNewB;
}
string ConverToTime(int duration)
{
TimeSpan ts = new TimeSpan(0, 0, Convert.ToInt32(duration));
string str = "";
if (ts.Hours > 0)
{
str = ts.Hours.ToString() + "小时 " + ts.Minutes.ToString() + "分钟 " + ts.Seconds + "秒";
}
if (ts.Hours == 0 && ts.Minutes > 0)
{
str = ts.Minutes.ToString() + "分钟 " + ts.Seconds + "秒";
}
if (ts.Hours == 0 && ts.Minutes == 0)
{
str = ts.Seconds + "秒";
}
return str;
}
string GelStepConvert(int code)
{
switch (code)
{
case 1: return "加冷水";
case 2: return "加玉米粉";
case 3: return "正反搅拌";
case 4: return "加热水";
case 5: return "搅拌";
case 6: return "等待确认";
case 7: return "等待排料";
default: return "无";
}
}
}
}
}