|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Net.NetworkInformation;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Controls.Base;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Mesnac.Action.Feeding.BasicInfo;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.Feeding.FeedingPlc
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下传称量物料参数业务处理
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class WeightPara : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
private int getMaterialIndex(string MaterialName)
|
|
|
|
|
{
|
|
|
|
|
int result = -100;
|
|
|
|
|
string ss = MaterialName.Trim();
|
|
|
|
|
if (ss.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
ss = ss.Substring(ss.Length - 1, 1);
|
|
|
|
|
}
|
|
|
|
|
if (!int.TryParse(ss, out result))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
private double getParData(string data, int iMul)
|
|
|
|
|
{
|
|
|
|
|
string ss = data;
|
|
|
|
|
double d = 0;
|
|
|
|
|
double.TryParse(ss, out d);
|
|
|
|
|
return d * iMul;
|
|
|
|
|
}
|
|
|
|
|
private DataTable getTypeDataTable(DbHelper localHelper, string typeName)
|
|
|
|
|
{
|
|
|
|
|
DataTable result = new DataTable();
|
|
|
|
|
string sqlstr = string.Empty;
|
|
|
|
|
// sqlstr = string.Format(@"select ID=IDENTITY(INT,1,1),MaterialName, mcValue, tqValue, tzValue, ddValue, gsclValue, msclValue, parType, parNumber into #SytParlist from SytPar where parType like '%{0}%'
|
|
|
|
|
// select * from #SytParlist ", typeName);
|
|
|
|
|
//把称量物料参数表合并到了日罐物料参数表中修改语句
|
|
|
|
|
sqlstr = string.Format(@"select ID=IDENTITY(INT,1,1),MaterialName, mcValue, tqValue, tzValue, ddValue, gsclValue, msclValue, JarType, JarSerial into #SytParlist from SytJar where JarType like '%{0}%'
|
|
|
|
|
select * from #SytParlist ", typeName);
|
|
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
result = localHelper.ToDataTable();
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
private bool downloadData(PlcData.DataKeyValue dataKey, DataTable dtPar, string valueName, int len, int iMul)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
object[] downloadPar = new object[len];
|
|
|
|
|
for (int i = 0; i < downloadPar.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
downloadPar[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
foreach (DataRow row in dtPar.Rows)
|
|
|
|
|
{
|
|
|
|
|
//int idx = int.Parse(row["id"].ToString());//;getMaterialIndex(row["MaterialName"].ToString());
|
|
|
|
|
int JarSerial = Mesnac.Basic.DataProcessor.RowValue(row, "JarSerial", 0);
|
|
|
|
|
if (JarSerial == 0)
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService.Warn("下传称量物料参数:获取罐号失败!");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
double data = getParData(row[valueName].ToString(), iMul);
|
|
|
|
|
downloadPar[JarSerial - 1] = data; //罐号-1为写入位置
|
|
|
|
|
}
|
|
|
|
|
return PlcData.Instance.PlcWriteByDataKey(dataKey, downloadPar);
|
|
|
|
|
}
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
base.LogDebug("称量物料参数...");
|
|
|
|
|
//您确定要执行此操作吗?
|
|
|
|
|
if (MessageBox.Show(Language(40), Language(1), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
|
|
{
|
|
|
|
|
runtime.IsReturn = true; //终止执行
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (runtime.Sender is Control)
|
|
|
|
|
{
|
|
|
|
|
(runtime.Sender as Control).Enabled = false;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
#region 检验本地数据连接
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("获取本地数据连接失败...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
bool[] results = new bool[] { true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true };
|
|
|
|
|
string msg = "称量物料参数-炭黑-慢称|称量物料参数-炭黑-提前量|称量物料参数-炭黑-调整值|称量物料参数-炭黑-点动值|";
|
|
|
|
|
msg += "称量物料参数-油1-慢称|称量物料参数-油1-提前量|称量物料参数-油1-调整值|称量物料参数-油1-点动值|";
|
|
|
|
|
msg += "称量物料参数-油2-慢称|称量物料参数-油2-提前量|称量物料参数-油2-调整值|称量物料参数-油2-点动值|";
|
|
|
|
|
msg += "称量物料参数-粉料-慢称|称量物料参数-粉料-提前量|称量物料参数-粉料-调整值|称量物料参数-粉料-点动值|";
|
|
|
|
|
string msg2 = "\r\n下传失败!";
|
|
|
|
|
string msg3 = "下传成功!";
|
|
|
|
|
|
|
|
|
|
DataTable dtPar = getTypeDataTable(localHelper, "炭黑");
|
|
|
|
|
results[0] = downloadData(PlcData.Instance.CLWLCS_TanHei_MC, dtPar, "mcValue", PlcData.Instance.CLWLCS_TanHei_MC.EquipData.Len, 100);
|
|
|
|
|
results[1] = downloadData(PlcData.Instance.CLWLCS_TanHei_TQ, dtPar, "tqValue", PlcData.Instance.CLWLCS_TanHei_TQ.EquipData.Len, 100);
|
|
|
|
|
results[2] = downloadData(PlcData.Instance.CLWLCS_TanHei_TZ, dtPar, "tzValue", PlcData.Instance.CLWLCS_TanHei_TZ.EquipData.Len, 1);
|
|
|
|
|
results[3] = downloadData(PlcData.Instance.CLWLCS_TanHei_DD, dtPar, "ddValue", PlcData.Instance.CLWLCS_TanHei_DD.EquipData.Len, 1);
|
|
|
|
|
|
|
|
|
|
dtPar = getTypeDataTable(localHelper, "油1");
|
|
|
|
|
results[4] = downloadData(PlcData.Instance.CLWLCS_You_MC1, dtPar, "mcValue", PlcData.Instance.CLWLCS_You_MC1.EquipData.Len, 100);
|
|
|
|
|
results[5] = downloadData(PlcData.Instance.CLWLCS_You_TQ1, dtPar, "tqValue", PlcData.Instance.CLWLCS_You_TQ1.EquipData.Len, 100);
|
|
|
|
|
results[6] = downloadData(PlcData.Instance.CLWLCS_You_TZ1, dtPar, "tzValue", PlcData.Instance.CLWLCS_You_TZ1.EquipData.Len, 1);
|
|
|
|
|
results[7] = downloadData(PlcData.Instance.CLWLCS_You_DD1, dtPar, "ddValue", PlcData.Instance.CLWLCS_You_DD1.EquipData.Len, 1);
|
|
|
|
|
|
|
|
|
|
dtPar = getTypeDataTable(localHelper, "油2");
|
|
|
|
|
results[8] = downloadData(PlcData.Instance.CLWLCS_You_MC2, dtPar, "mcValue", PlcData.Instance.CLWLCS_You_MC2.EquipData.Len, 100);
|
|
|
|
|
results[9] = downloadData(PlcData.Instance.CLWLCS_You_TQ2, dtPar, "tqValue", PlcData.Instance.CLWLCS_You_TQ2.EquipData.Len, 100);
|
|
|
|
|
results[10] = downloadData(PlcData.Instance.CLWLCS_You_TZ2, dtPar, "tzValue", PlcData.Instance.CLWLCS_You_TZ2.EquipData.Len, 1);
|
|
|
|
|
results[11] = downloadData(PlcData.Instance.CLWLCS_You_DD2, dtPar, "ddValue", PlcData.Instance.CLWLCS_You_DD2.EquipData.Len, 1);
|
|
|
|
|
|
|
|
|
|
if (true) //如果不存在粉料
|
|
|
|
|
{
|
|
|
|
|
dtPar = getTypeDataTable(localHelper, "粉料");
|
|
|
|
|
results[12] = downloadData(PlcData.Instance.CLWLCS_FenLiao_MC, dtPar, "mcValue", PlcData.Instance.CLWLCS_FenLiao_MC.EquipData.Len, 100);
|
|
|
|
|
results[13] = downloadData(PlcData.Instance.CLWLCS_FenLiao_TQ, dtPar, "tqValue", PlcData.Instance.CLWLCS_FenLiao_TQ.EquipData.Len, 100);
|
|
|
|
|
results[14] = downloadData(PlcData.Instance.CLWLCS_FenLiao_TZ, dtPar, "tzValue", PlcData.Instance.CLWLCS_FenLiao_TZ.EquipData.Len, 1);
|
|
|
|
|
results[15] = downloadData(PlcData.Instance.CLWLCS_FenLiao_DD, dtPar, "ddValue", PlcData.Instance.CLWLCS_FenLiao_DD.EquipData.Len, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string[] msgs = msg.Split(new char[] { '|' });
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < results.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (results[i] == false)
|
|
|
|
|
{
|
|
|
|
|
sb.AppendLine(msgs[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!String.IsNullOrEmpty(sb.ToString()))
|
|
|
|
|
{
|
|
|
|
|
ShowMsg(String.Format("{0}{1}", sb.ToString(), msg2), Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ShowMsg(msg3, Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
base.LogError(ex.Message);
|
|
|
|
|
base.LogError(ex.StackTrace);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
if (runtime.Sender is Control)
|
|
|
|
|
{
|
|
|
|
|
(runtime.Sender as Control).Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SelectedType : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
#region IAction 成员
|
|
|
|
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
base.LogDebug("选择类别...");
|
|
|
|
|
#region 检验本地数据连接
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("获取本地数据连接失败...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
DbMCControl jarnoControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarSerial]").FirstOrDefault();
|
|
|
|
|
DbMCControl jartypeControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarType]").FirstOrDefault();
|
|
|
|
|
DbMCControl jartmaterial = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[MaterialName]").FirstOrDefault();
|
|
|
|
|
if (jarnoControl == null || jartypeControl == null || jartmaterial == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("缺少控件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string jartype = jartypeControl.BaseControl.MCValue.ToString();
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
string sqlstr = string.Format("select jarserial from SytJar where jartype='{0}' order by jarserial", jartype.Trim());
|
|
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
|
|
DataTable table = localHelper.ToDataTable();
|
|
|
|
|
jarnoControl.BaseControl.BindDataSource = table;
|
|
|
|
|
|
|
|
|
|
string jarno = jarnoControl.BaseControl.MCValue.ToString();
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
sqlstr = string.Format("select MaterialName from SytJar where jartype='{0}' and jarserial='{1}' order by jartype,jarserial ", jartype.Trim(), jarno.Trim());
|
|
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
|
|
jartmaterial.BaseControl.BindDataSource = localHelper.ToDataTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SelectedType1 : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
#region IAction 成员
|
|
|
|
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
base.LogDebug("选择类别...");
|
|
|
|
|
#region 检验本地数据连接
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("获取本地数据连接失败...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
DbMCControl jartypeControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarType]").FirstOrDefault();
|
|
|
|
|
DbMCControl jartmaterial = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[MaterialName]").FirstOrDefault();
|
|
|
|
|
if (jartypeControl == null || jartmaterial == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("缺少控件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string jartype = jartypeControl.BaseControl.MCValue.ToString();
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
string sqlstr = string.Format("select mater_name as MaterialName from pmt_material where mater_type='{0}' order by mater_code ", jartype.Trim());
|
|
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
|
|
jartmaterial.BaseControl.BindDataSource = localHelper.ToDataTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SelectedJarNo : FeedingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
#region IAction 成员
|
|
|
|
|
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
base.LogDebug("选择罐号...");
|
|
|
|
|
#region 检验本地数据连接
|
|
|
|
|
DbHelper localHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (localHelper == null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("获取本地数据连接失败...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
DbMCControl jartypeControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarType]").FirstOrDefault();
|
|
|
|
|
DbMCControl jarnoControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarSerial]").FirstOrDefault();
|
|
|
|
|
DbMCControl jartmaterial = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[MaterialName]").FirstOrDefault();
|
|
|
|
|
if (jarnoControl == null || jartmaterial == null || jartypeControl==null)
|
|
|
|
|
{
|
|
|
|
|
base.LogError("缺少控件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string jartype = jartypeControl.BaseControl.MCValue.ToString();
|
|
|
|
|
string jarno = jarnoControl.BaseControl.MCValue.ToString();
|
|
|
|
|
localHelper.ClearParameter();
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
|
|
string sqlstr = string.Format("select MaterialName from sytjar where jartype='{0}' and jarserial='{1}' order by jartype,jarserial ", jartype.Trim(), jarno.Trim());
|
|
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
|
|
jartmaterial.BaseControl.BindDataSource = localHelper.ToDataTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|