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.
169 lines
6.5 KiB
C#
169 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Data;
|
|
using Mesnac.Action.Base;
|
|
using Mesnac.Controls.Base;
|
|
using Mesnac.Controls.Default;
|
|
using System.Windows.Forms;
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
|
namespace Mesnac.Action.Feeding.Technology
|
|
{
|
|
public class SelectedRecipe : FeedingAction, IAction
|
|
{
|
|
private DataTable FormatDataTable(DataTable dt)
|
|
{
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
foreach (DataColumn dc in dt.Columns)
|
|
{
|
|
if (dc.DataType == typeof(double?) || dc.DataType == typeof(double) ||
|
|
dc.DataType == typeof(decimal) ||
|
|
dc.DataType == typeof(int))
|
|
{
|
|
if (dt.Rows[i][dc] != null && dt.Rows[i][dc] != DBNull.Value)
|
|
{
|
|
double d = 0.0;
|
|
string ss = dt.Rows[i][dc].ToString();
|
|
if (double.TryParse(ss, out d) && d == 0)
|
|
{
|
|
dt.Rows[i][dc] = DBNull.Value;
|
|
}
|
|
else if (dc.DataType != typeof(int))
|
|
{
|
|
dt.Rows[i][dc] = String.Format("{0:f3}", dt.Rows[i][dc]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return dt;
|
|
}
|
|
/// <summary>
|
|
/// 初始化称量数据
|
|
/// </summary>
|
|
/// <param name="dbHelper"></param>
|
|
/// <param name="recipeid"></param>
|
|
/// <param name="weightType"></param>
|
|
/// <returns></returns>
|
|
private DataTable IniWeightData(DbHelper dbHelper, string recipeid, string weightType)
|
|
{
|
|
string sqlstr = "SELECT weight_id as SeqInx,* FROM pmt_weigh WHERE RecipeObjID=" + recipeid + " AND weigh_type=" + weightType + " ORDER BY weight_id";
|
|
DbMCSource dbsource = base.GetAllDbMCSources().FirstOrDefault();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandText = sqlstr;
|
|
DataTable weight = dbHelper.ToDataTable();
|
|
foreach (DataColumn dc in weight.Columns)
|
|
{
|
|
dc.ReadOnly = false;
|
|
dc.AllowDBNull = true;
|
|
}
|
|
FormatDataTable(weight);
|
|
for (int i = weight.Rows.Count + 1; i <= 10; i++)
|
|
{
|
|
DataRow dr = weight.NewRow();
|
|
dr["ObjID"] = i;
|
|
dr["weight_id"] = i;
|
|
dr["SeqInx"] = i;
|
|
dr["act_code"] = string.Empty;
|
|
dr["child_name"] = string.Empty;
|
|
weight.Rows.Add(dr);
|
|
}
|
|
return weight;
|
|
}
|
|
/// <summary>
|
|
/// 初始化密炼数据
|
|
/// </summary>
|
|
/// <param name="dbHelper"></param>
|
|
/// <param name="recipeid"></param>
|
|
/// <returns></returns>
|
|
private DataTable IniMixingData(DbHelper dbHelper, string recipeid)
|
|
{
|
|
string sqlstr = "SELECT mix_id as SeqInx,* FROM pmt_mix WHERE RecipeObjID=" + recipeid + " ORDER BY mix_id";
|
|
DbMCSource dbsource = base.GetAllDbMCSources().FirstOrDefault();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandText = sqlstr;
|
|
DataTable mixing = dbHelper.ToDataTable();
|
|
foreach (DataColumn dc in mixing.Columns)
|
|
{
|
|
dc.ReadOnly = false;
|
|
dc.AllowDBNull = true;
|
|
}
|
|
FormatDataTable(mixing);
|
|
for (int i = mixing.Rows.Count + 1; i <= 30; i++)
|
|
{
|
|
DataRow dr = mixing.NewRow();
|
|
dr["ObjID"] = i;
|
|
dr["mix_id"] = i;
|
|
dr["SeqInx"] = i;
|
|
dr["act_code"] = string.Empty;
|
|
dr["term_code"] = string.Empty;
|
|
mixing.Rows.Add(dr);
|
|
}
|
|
return mixing;
|
|
}
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime);
|
|
DbMCSource dbsource = base.GetAllDbMCSources().FirstOrDefault();
|
|
DbMCControl ObjIDControl = base.GetDbMCControlByKey("[" + dbsource.DesignSource + "].[pmt_recipe].[ObjID]").FirstOrDefault();
|
|
if (ObjIDControl == null)
|
|
{
|
|
return;
|
|
}
|
|
if (ObjIDControl.BaseControl.MCValue == null)
|
|
{
|
|
return;
|
|
}
|
|
string recipeid = ObjIDControl.BaseControl.MCValue.ToString();
|
|
if (string.IsNullOrWhiteSpace(recipeid))
|
|
{
|
|
return;
|
|
}
|
|
DbHelper dbHelper = NewDbHelper(dbsource.DesignSource);
|
|
if (dbHelper == null)
|
|
{
|
|
return;
|
|
}
|
|
dbHelper.CommandType = CommandType.Text;
|
|
dbHelper.CommandText = "SELECT * FROM dbo.pmt_recipe WHERE ObjID='" + recipeid + "'";
|
|
DataTable dt = dbHelper.ToDataTable();
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
foreach (DbMCControl control in GetAllDbMCControls())
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(control.DataTable)
|
|
&& control.DataTable.Equals("pmt_recipe", StringComparison.CurrentCultureIgnoreCase)
|
|
&& !string.IsNullOrWhiteSpace(control.DataField)
|
|
&& (base.DbOptionTypesIsModify(control.BaseControl)))
|
|
{
|
|
control.BaseControl.MCValue = dt.Rows[0][control.DataField];
|
|
}
|
|
}
|
|
List<MCDataGridView> gridList = GetTControls<MCDataGridView>();
|
|
foreach (MCDataGridView grid in gridList)
|
|
{
|
|
if (grid.MCKey != null && grid.MCKey.ToLower().StartsWith("PmtWeight.".ToLower()))
|
|
{
|
|
int iType = 0;
|
|
if (int.TryParse(grid.MCKey.Substring("PmtWeight.".Length).Trim(), out iType))
|
|
{
|
|
grid.DataSource = IniWeightData(dbHelper, recipeid, iType.ToString());
|
|
}
|
|
}
|
|
if (grid.MCKey != null && grid.MCKey.ToLower() == "PmtMixing".ToLower())
|
|
{
|
|
grid.DataSource = IniMixingData(dbHelper, recipeid);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|