MES系统通常都会与SCADA系统集成使用,尤其具备中控管理需求的工厂,集控SCADA需要集成MES系统的计划工单数据实现工单数据、工艺配方数据、SN数据、打码数据等下发,执行状态、关键参数反馈等上传。本文介绍在WinCC画面集成基于C#开发的计划管理界面,以下代码主要是C#开发计划管理组件代码。
项目代码:https://download.csdn.net/download/bjhtgy/89696770
namespace ProUserLib
{
[ProgId("ProUserLib.BatchPlan")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public partial class BatchPlan : UserControl
{
BusinessLogic.CommonLogic logic = null;
BusinessLogic.WebServiceLogic weblogic = null;
BusinessLogic.MqLogic mq = null;
BusinessLogic.HandleMesXmlLogic hxml = null;
public BatchPlan()
{
InitializeComponent();
logic = (BusinessLogic.CommonLogic)(Activator.GetObject(typeof(BusinessLogic.CommonLogic), "tcp://" + ServerIp + ":8505/CommonLogic"));
weblogic = (BusinessLogic.WebServiceLogic)(Activator.GetObject(typeof(BusinessLogic.WebServiceLogic), "tcp://" + ServerIp + ":8505/WebServiceLogic"));
mq = (BusinessLogic.MqLogic)(Activator.GetObject(typeof(BusinessLogic.MqLogic), "tcp://" + ServerIp + ":8601/MqLogic"));
hxml = (BusinessLogic.HandleMesXmlLogic)(Activator.GetObject(typeof(BusinessLogic.HandleMesXmlLogic), "tcp://" + ServerIp + ":8601/HandleMesXmlLogic"));
//mq.queuemanagername = QueueManagerName;
}
private string m_serverIp = "172.17.129.97";
public string ServerIp
{
get { return m_serverIp; }
set { m_serverIp = value; }
}
//private string m_QueueManagerName = "cczs2";
//private string m_QueueName = "channelformes";
//public string QueueManagerName
//{
// get { return m_QueueManagerName; }
// set { m_QueueManagerName = value; }
//}
//public string QueueName
//{
// get { return m_QueueName; }
// set { m_QueueName = value; }
//}
/// <summary>
/// 更新生产单元计划
/// </summary>
/// <param name="m_startorend">开始或者结束 0-开始 1-结束</param>
/// <param name="m_unitno">生产单元编码</param>
/// <param name="m_batch">批次号</param>
/// <param name="m_grade">班次</param>
/// <returns>更新是否成功 0-不成功 1-成功</returns>
public string UpdatePlanUnit(string m_startorend, string m_unitno, string m_batch, string m_grade)
{
string m_time="";
ArrayList field = new ArrayList();
if (m_startorend == "0")
{
field.Add("PlanStartDate");
field.Add("ProductGrade");
}
else
{
field.Add("PlanEndDate");
field.Add("ProductGrade");
}
field.Add("PlanState");
ArrayList value = new ArrayList();
if (m_startorend == "0")
{
m_time=System.DateTime.Now.ToString();
value.Add(System.DateTime.Now.ToString());
value.Add(m_grade);
value.Add(6);
}
else
{
m_time=System.DateTime.Now.ToString();
value.Add(System.DateTime.Now.ToString());
value.Add(m_grade);
value.Add(7);
}
ArrayList type = new ArrayList();
type.Add("string");
type.Add("string");
type.Add("int");
ArrayList confield = new ArrayList();
confield.Add("Batch");
confield.Add("productionUnit");
ArrayList convalue = new ArrayList();
convalue.Add(m_batch);
convalue.Add(int.Parse(m_unitno));
ArrayList contype = new ArrayList();
contype.Add("string");
contype.Add("int");
int flag = logic.UpDateClass("T_BatchPlan", field, value, type, confield, convalue, contype);
FeedBackUnitPlanTime(m_startorend, m_batch, m_unitno, m_time);// m_startorend, string m_unitno, string m_batch, string m_grade)
if (flag == 1)
{
return "1";
}
else
{
return "0";
}
}
/// <summary>
/// 更新生产段计划,需要查询工艺段包含的生产单元
/// </summary>
/// <param name="m_startorend">开始或者结束 0-开始 1-结束</param>
/// <param name="m_unitno">生产段编码</param>
/// <param name="m_batch">批次号</param>
/// /// <param name="m_grade">班次</param>
public void UpdatePlanSeg(string m_startorend, string m_segno, string m_batch, string m_grade)
{
ArrayList field = new ArrayList();
field.Add("PuNo");
ArrayList confield = new ArrayList();
confield.Add("Sno");
ArrayList convalue = new ArrayList();
convalue.Add(int.Parse(m_segno));
ArrayList contype = new ArrayList();
contype.Add("int");
DataSet ds = logic.SearchClass("T_ProductionUnit", field, confield, convalue, contype);
if (ds != null)
{
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
string puno = dr[0].ToString();
UpdatePlanUnit(m_startorend, puno, m_batch, m_grade);
}
}
}
}
}
/// <summary>
/// 记录贮柜信息
/// </summary>
/// <param name="m_unitno">生产单元</param>
/// <param name="m_batch">批次号</param>
/// <param name="m_brand">烟牌</param>
/// <param name="m_grade">班次</param>
/// <param name="m_fromcab">来源柜</param>
/// <param name="m_tocab">去向柜</param>
/// <returns>返回记录状态</returns>
public string BatchCabInfo(string m_unitno, string m_batch, string m_brand, string m_grade, string m_fromcab, string m_tocab)
{
ArrayList array = new ArrayList();
array.Add("Batch");
array.Add("Brand");
array.Add("Punit");
array.Add("ProductGrade");
array.Add("FromCab");
array.Add("ToCab");
array.Add("CurDateTime");
ArrayList value = new ArrayList();
value.Add(m_batch);
value.Add(m_brand);
value.Add(m_unitno);
value.Add(m_grade);
value.Add(m_fromcab);
value.Add(m_tocab);
value.Add(DateTime.Now.ToString());
ArrayList type = new ArrayList();
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
int flag = logic.AddClass("T_BatchCabInfo", array, value, type);
return flag.ToString();
}
public void SaveFlex(string m_batch, string m_brand, string m_grade, string m_puno, string m_flexname, string m_flex)
{
ArrayList array = new ArrayList();
array.Add("Batch");
array.Add("Brand");
array.Add("Punit");
array.Add("ProductGrade");
array.Add("FlexName");
array.Add("FlexWeight");
array.Add("CurDateTime");
ArrayList value = new ArrayList();
value.Add(m_batch);
value.Add(m_brand);
value.Add(m_puno);
value.Add(m_grade);
value.Add(m_flexname);
value.Add(m_flex);
value.Add(DateTime.Now.ToString());
ArrayList type = new ArrayList();
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
type.Add("string");
int flag = logic.AddClass("T_BatchFlex", array, value, type);
}
#region add by ms
/// <summary>
///工段结束后, 向mes反馈投入产出信息。即秤的信息.需要在秤的统计方法执行之后再执行。找出所有这个批次的秤的信息,将所有秤全部反馈
/// </summary>
/// <param name="m_mes_puborgcode">在脚本里写死,由mes提供</param>
/// <param name="m_gbrandno">梗烟牌编码(mes新的需求,写脚本通过柜的信息获取梗烟牌编码)</param>
/// <param name="m_batch">批次</param>
/// <param name="m_class">班别</param>
///<param name=" m_segcode">自己的工段编码,需要对应秤mes的编码</param>
/// <param name="m_remark">备注</param>
/// <param name="silocode">秤的编码,是mes的编码,在脚本里写死</param>
/// <param name="silooutweight">秤的产量,在脚本里传</param></param
public void FeedBackOutWeight(string m_mes_puborgcode, string m_gbrandno, string m_batch, string m_class, string m_segcode, string silocode, string silooutweight, string m_remark)//
{
string m_planno = "";//mes计划中的工单号
// string m_order = "";//mes计划中的序号,当天的计划按开始时间排,当前计划的排序
string m_planstarttime = "";//当前计划开始的时间
string m_mes_segcode = "";//mes中的工段号
string m_segname = "";//mes中的工段名称
string m_brandno = GetMesBrandCode(m_batch);
//从mes_t_mainplan中通过BATCHNO获取PLANNO//错,改成,通过批次号和工段号获取
string sqlstr1 = "select EXESTARTDATE from T_MAINPLAN where batch='" + m_batch + "' and plantype ='" + m_segcode + "'";
DataSet ds0 = logic.ExecSqlStr(sqlstr1);
if (ds0 != null && ds0.Tables[0].Rows.Count > 0)
{
m_planstarttime = ds0.Tables[0].Rows[0][0].ToString();
}
string sqlstr2 = "select PLANNO from MES_T_MAINPLAN where guid=(select mescode from t_mainplan where batch='" + m_batch + "' and plantype ='" + m_segcode + "')";
DataSet ds = logic.ExecSqlStr(sqlstr2);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
m_planno = ds.Tables[0].Rows[0][0].ToString();
}
//从t_segment中通过sno获取sname、mescode
ArrayList searchfileds = new ArrayList();
ArrayList conditionfiles = new ArrayList();
ArrayList conditionvalues = new ArrayList();
ArrayList conditiontypes = new ArrayList();
searchfileds.Add("sname");//
searchfileds.Add("mescode");//
conditionfiles.Add("sno");
conditionvalues.Add(m_segcode);
conditiontypes.Add("int");
DataSet ds1 = logic.SearchClass("t_segment", searchfileds, conditionfiles, conditionvalues, conditiontypes);//mes的表
if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
{
m_segname = ds1.Tables[0].Rows[0][0].ToString();//mes中的工段号
m_mes_segcode = ds1.Tables[0].Rows[0][1].ToString();
}
DataTable dt = new DataTable();
dt.Columns.Add("GUID", System.Type.GetType(" System.String"));// System.Int32 System.Double System.String
dt.Columns.Add("PLANNO", System.Type.GetType(" System.String"));
dt.Columns.Add("PUBORGCODE", System.Type.GetType(" System.String"));
dt.Columns.Add("NO", System.Type.GetType(" System.Int32"));
dt.Columns.Add("MATERIALID", System.Type.GetType(" System.String"));
dt.Columns.Add("BATCHNO", System.Type.GetType(" System.String"));
dt.Columns.Add("PRODUCEDATE", System.Type.GetType(" System.String"));
dt.Columns.Add("SHIFTCLASSCODE", System.Type.GetType(" System.String"));
dt.Columns.Add("CLASSTIMECODE", System.Type.GetType(" System.String"));
dt.Columns.Add("WORKSECTIONCODE", System.Type.GetType(" System.String"));
dt.Columns.Add("WORKSECTIONNAME", System.Type.GetType(" System.String"));
dt.Columns.Add("MATERIALID1", System.Type.GetType(" System.String")); //MATERIALID1
dt.Columns.Add("PUBMATERIALCODE", System.Type.GetType(" System.String"));
dt.Columns.Add("ZSZK", System.Type.GetType(" System.Int32"));
dt.Columns.Add("VALUE", System.Type.GetType(" System.Double"));
dt.Columns.Add("REMARK", System.Type.GetType(" System.String"));
DataRow dr = dt.NewRow();
dr[0] = System.Guid.NewGuid().ToString();
dr[1] = m_planno;//通过批次号获取mes工单号
dr[2] = m_mes_puborgcode;
dr[3] = GetOrderByBath(m_batch, m_segcode);//通过批次号获取计划在当天的序号
dr[4] = m_brandno;
dr[5] = m_batch;
dr[6] = m_planstarttime;//通过批次号获取这个计划的开始时间
dr[7] = GetClassTime();
dr[8] = m_class;
dr[9] = m_mes_segcode;//mes中工段编码
dr[10] = m_segname;//工段名称
dr[11] = m_gbrandno;
dr[12] = m_gbrandno;//新加的混的梗的烟牌编码
dr[13] = silocode;// dr[11] = dr1[0];//投产物料编码
dr[14] = silooutweight;//产量
dr[15] = m_remark;//备注
dt.Rows.Add(dr);
// MesInterface.HandleMesXML hxml = new HandleMesXML();
string TemplateAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/OutWeight/XmlPath", "TemplatePath");//@"F:\项目\长春\长春\计划\ZSZK\投入产出信息集成.xml";//写xml获取这个值
string SaveAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/OutWeight/XmlPath", "SavePath");//@"F:\test";//写xml获取这个值
string QueueManagerName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/OutWeight/Mq", "QueueManagerName");
string QueueName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/OutWeight/Mq", "QueueName");
string xmltext = hxml.GenerateMesXml(TemplateAddress, dt, SaveAddress);
//通过mq发送给mes
// MesInterface.MQ mq = new MQ("cczs2", "channelformes");
mq.SendMQ(xmltext, QueueManagerName, QueueName);
}
/// <summary>
///获取班时
/// </summary>
/// <returns></returns>
private string GetClassTime()
{
string flag = "";//1白班,2夜班
string curdate=System.DateTime.Now.ToString("HH:mm:ss");
if (Convert.ToDateTime(curdate) >Convert.ToDateTime("07:30:00")&&Convert.ToDateTime( curdate) < Convert.ToDateTime( "16:30:00"))
{
flag = "1";
}
else
{
flag = "2";
}
return flag;
}
private string GetMesParaCode(string paracode)
{
string mescode = "";
string sqlstr = "select ATTRVALUE from t_productparauda where PARANO='" + paracode + "'and attrno=10";// //PARANO ATTRVALUE
DataSet ds = logic.ExecSqlStr(sqlstr);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
mescode = ds.Tables[0].Rows[0]["ATTRVALUE"].ToString();
}
return mescode;
}
private int GetOrderByBath(string batchno,string m_segcode)
{
int order = 0;
string sqlstr = "select count(*) from (select STARTTIME from t_mainplan where EXEENDDATE like (select to_char( sysdate ,'yyyy-MM-dd')||'%'from dual))where EXEENDDATE <=(select EXEENDDATE from t_mainplan where batch='" + batchno + "' and plantype='" + m_segcode + "')";//获取当天小于等于这个批次的开始时间的数据条数当作这个批次的顺序号
DataSet ds = logic.ExecSqlStr(sqlstr);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
order = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
}
return order;
}
/// <summary>
///反馈生产单元的开始结束时间
/// </summary>
/// <param name="m_startorend">开始或者结束 0-开始 1-结束</param>
/// <param name="m_batch">批次号</param>
/// <param name="m_unitno">单元编码</param>
/// <param name="m_time">时间</param>
public void FeedBackUnitPlanTime(string m_startorend, string m_batch, string m_unitno, string m_time)
{
string brandno = GetMesBrandCode(m_batch);
// string planid=G
m_unitno = GetMesUnitCode(m_unitno);
DataTable dt = new DataTable();
dt.Columns.Add("GUID", System.Type.GetType(" System.String"));//如何赋值
dt.Columns.Add("PROCESS_ID", System.Type.GetType(" System.String"));
dt.Columns.Add("PROD_DATE", System.Type.GetType(" System.String"));//是这批的开始时间吗
dt.Columns.Add("MATERIAL_ID", System.Type.GetType(" System.String"));
dt.Columns.Add("BATCHNO", System.Type.GetType(" System.String"));
if (m_startorend == "0")
{
dt.Columns.Add("START_TIME", System.Type.GetType(" System.String"));
}
else
{
dt.Columns.Add("END_TIME", System.Type.GetType(" System.String"));
}
dt.Rows.Add(new object[] { "123", m_unitno, DateTime.Now.ToString(), brandno, m_batch, m_time });
dt.TableName = "time";
weblogic.FeedBackUnitTimeMethod(m_startorend, dt); 0开始时间,1结束时间
}
/// <summary>
/// 根据批次,找到自己的烟牌,然后找到对应的mes的烟牌编码
/// </summary>
/// <param name="m_batch">批次号</param>
/// <returns></returns>
private string GetMesBrandCode(string m_batch)//,string m_segno
{
string brandno = "";//需要转换秤mes的烟牌编码
string sqlstr = "select mescode from t_brand where brandno=( select distinct brandno from t_mainplan where batch='" + m_batch + "' )";//and PLANTYPE='" + m_segno + "'
DataSet ds = logic.ExecSqlStr(sqlstr);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
brandno = ds.Tables[0].Rows[0][0].ToString();
}
return brandno;
}
/// <summary>
/// 根据自己的生产单元编码找出mes的编码
/// </summary>
/// <param name="m_unit">自己的生产单元号</param>
/// <returns></returns>
private string GetMesUnitCode( string m_unit)
{
string unitno = "";//需要转换秤mes的生产单元编码
string sqlstr = "select mescode from t_productionunit where puno='" + m_unit + "'";
DataSet ds = logic.ExecSqlStr(sqlstr);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
unitno = ds.Tables[0].Rows[0][0].ToString();
}
return unitno;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private string GetSegnoByUnitno(string unitno)
{
string Segno = "";
string sqlstr = "select sno from t_productionunit where puno='" + unitno + "'";
DataSet ds = logic.ExecSqlStr(sqlstr);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
Segno = ds.Tables[0].Rows[0]["sno"].ToString();
}
return Segno;
}
/// <summary>
/// 反馈工段的开始结束时间,需要找到工段的开始结束生产单元,在脚本里加这个方法
/// </summary>
/// <param name="m_startorend">开始或者结束 0-开始 1-结束</param>
/// <param name="m_batch"></param>
/// <param name="m_time"></param>
/// <param name="actualcabinno">实际入柜编号</param>
/// <param name="actualcaboutno">实际出柜编号</param>
/// <param name="outweight">产量</param>
public void FeedBackSegPlanTime(string m_startorend, string segmentno, string m_batch, string actualcabinno,string actualcaboutno,string outweight)
{
string m_time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
if (UpdateTimeAndStatusOfT_mainplan(m_startorend,segmentno, m_batch, m_time, actualcabinno, actualcaboutno, outweight))
{
string sqlstr = "select * from mes_t_mainplan where guid= (select mescode from t_mainplan where batch='" + m_batch + "' and plantype ='" + segmentno + "')";
DataSet ds0 = logic.ExecSqlStr(sqlstr);
if (ds0 != null && ds0.Tables[0].Rows.Count > 0)
{
if (m_startorend == "0")//开始时间反馈
{
//实际入柜出柜 INCUPBOARD OUTCUPBOARD
ds0.Tables[0].Rows[0]["INCUPBOARD"] = actualcabinno;
ds0.Tables[0].Rows[0]["OUTCUPBOARD"] = actualcaboutno;
ds0.Tables[0].Rows[0]["starttime"] = m_time;
ds0.Tables[0].Rows[0]["planstatus"] = "4";
}
else
{
ds0.Tables[0].Rows[0]["FACT_NUM"] = outweight;
ds0.Tables[0].Rows[0]["endtime"] = m_time;
ds0.Tables[0].Rows[0]["planstatus"] = "5";
}
}
if ((m_startorend == "0"))//开始时间反馈
{
m_startorend = "3";
}
else
{
m_startorend = "4";
}
weblogic.FeedBackMethod(ds0.Tables[0], m_startorend);//1:确认计划,3:计划开始:4:计划结束
}
}
/// <summary>
/// 更新t_mainplan中的状态和开始结束时间和实际入柜、出柜信息
/// </summary>
/// <param name="m_startorend"></param>
/// <param name="m_batch"></param>
/// <param name="m_time"></param>
/// <param name="actualcaboutno">实际入柜信息</param>
/// <param name="actualcaboutno">实际出柜信息</param>
/// <param name="outweight">产量</param>
/// <returns></returns>
public bool UpdateTimeAndStatusOfT_mainplan(string m_startorend, string segmentno, string m_batch, string m_time, string actualcabinno, string actualcaboutno, string outweight)
{
string sqlstr = "";
if (m_startorend == "0")
{
sqlstr = "update T_mainplan set EXESTARTDATE='" + m_time + "',PLANSTATE=4,actualcabinno='" + actualcabinno + "',actualcaboutno='" + actualcaboutno + "' where batch='" + m_batch + "'and PLANTYPE='" + segmentno + "'";
}
else
{
sqlstr = "update T_mainplan set EXEENDDATE='" + m_time + "' ,PLANSTATE=5,ACTUALOUTWEIGHT='" + outweight + "' where batch='" + m_batch + "'and PLANTYPE='" + segmentno + "'";//planstatus starttime endtime
}
return logic.ExecSqlDirict(sqlstr);
}
/// <summary>
/// 反馈设备部位产量,按工序
/// </summary>
/// <param name="m_unitno">生产单元编码</param>
/// <param name="m_equitname">设备名称</param>
/// <param name="m_outweight">产量</param>
/// <returns></returns>
public void FeedBackPartOutWeight(string m_unitno, string m_equitname, string m_outweight)
{
string guid = System.Guid.NewGuid().ToString();
string time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
string unitno = GetMesUnitCode(m_unitno);
string equitname = m_equitname;
string outweight = m_outweight;
DataTable dt = new DataTable();
dt.Columns.Add("GUID", typeof(string));
dt.Columns.Add("PROD_DATE", typeof(string));
dt.Columns.Add("TC_ID", typeof(string));
dt.Columns.Add("EQUITNAME", typeof(string));
dt.Columns.Add("OUTWEIGHT", typeof(string));
DataRow dr = dt.NewRow();
dr.ItemArray = new object[] { guid, time, unitno, equitname, outweight};
dt.Rows.Add(dr);
#region 生成xml字符串通过mq发送并存储xml文件
// MesInterface.HandleMesXML hxml = new HandleMesXML();
string TemplateAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/PartsOutWeight/XmlPath", "TemplatePath");//@"F:\项目\长春\长春\计划\ZSZK\投入产出信息集成.xml";//写xml获取这个值
string SaveAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/PartsOutWeight/XmlPath", "SavePath");//@"F:\test";//写xml获取这个值
string QueueManagerName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/PartsOutWeight/Mq", "QueueManagerName");
string QueueName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/PartsOutWeight/Mq", "QueueName");
string xmltext = hxml.GenerateMesXml(TemplateAddress, dt, SaveAddress);
//通过mq发送给mes
// MesInterface.MQ mq = new MQ("cczs2", "channelformes");
// MesInterface.MQ mq = new MQ(QueueManagerName, QueueName);
mq.SendMQ(xmltext, QueueManagerName, QueueName);
#endregion
}
/// <summary>
/// 向mes反馈修改的工艺参数
/// </summary>
/// <param name="m_unitno">生产单元编码</param>
/// <param name="m_batchno">批次号</param>
/// <param name="m_adresses">所有该生产单元的参数的地址</param>
/// <param name="m_values">所有这些参数的值</param>
public void FeedBackSegRecipeParas(string m_unitno, string m_batchno, string m_adressesstr, string m_valuesstr)
{
ArrayList changedparanos = new ArrayList();
ArrayList changedparavalues = new ArrayList();
ArrayList m_paracodes = new ArrayList();
string[] m_adresses=m_adressesstr.Split(',');
string[] m_values=m_valuesstr.Split(',');
string m_segcode = GetSegnoByUnitno(m_unitno);
string m_brandno = GetMesBrandCode(m_batchno);
if (m_adresses.GetLength(0) == m_values.GetLength(0))
{
for (int i = 0; i < m_adresses.GetLength(0); i++)
{
string sql = "select PARANO from t_productparauda where ATTRVALUE='" + m_adresses.GetValue(i).ToString() + "'";
DataSet ds = logic.ExecSqlStr(sql);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
m_paracodes.Add(ds.Tables[0].Rows[0][0]);
}
}
string sqlstr = "select parano,paradata from t_segrecipechild where datatype=2 and puno='" + m_unitno + "' and srid=(select distinct SEGRECIPEID from T_mainplan where batch='" + m_batchno + "'and plantype ='" + m_segcode + "')";//获取所以此批次的配方号对应的下发参数的设定值
DataSet ds1 = logic.ExecSqlStr(sqlstr);
if (ds1 != null && ds1.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds1.Tables[0].Rows)
{
string abc = dr["parano"].ToString();
string abc1 = dr["paradata"].ToString();
for (int j = 0; j < m_paracodes.Count; j++)//m_paracodes参数的编码数组 m_values参数的值数组
{
if (m_paracodes[j].ToString() == dr["parano"].ToString() && m_values.GetValue(j).ToString() != dr["paradata"].ToString())
{
changedparanos.Add(m_paracodes[j]);
changedparavalues.Add(m_values.GetValue(j).ToString());
}
}
}
}
}
//放到datatable中
if (changedparanos != null && changedparavalues != null)
{
DataTable dt = new DataTable();
dt.Columns.Add("GUID");
dt.Columns.Add("PRODUCT_DATE");
dt.Columns.Add("SETTIME");
dt.Columns.Add("MATERIAL");
dt.Columns.Add("BATCH_NO");
dt.Columns.Add("TC_ITEM");
dt.Columns.Add("EQUIMENT");
dt.Columns.Add("MIDVALUS");
dt.Columns.Add("UPVALUE");
dt.Columns.Add("DOWNVALUE");
dt.Columns.Add("PRECISION");
dt.Columns.Add("TYPE");
string productTime = "";
string sqlstr1 = "select min(EXESTARTDATE) from t_mainplan where batch='" + m_batchno + "'";
DataSet ds0 = logic.ExecSqlStr(sqlstr1);
if (ds0 != null && ds0.Tables[0].Rows.Count > 0)
{
productTime = ds0.Tables[0].Rows[0][0].ToString();
}
//PARANO ATTRVALUE
for (int j = 0; j < changedparanos.Count; j++)
{
DataRow dr = dt.NewRow();
dr.ItemArray = new object[] { GetMesParaCode(changedparanos[j].ToString()), productTime, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), GetMesBrandCode(m_brandno), m_batchno, "", GetMesUnitCode(m_unitno), changedparavalues[j], "", "", "", "0" };//
// dr. new object[]{ changedparanos[j], productTime, DateTime.Now.ToString(), m_brandno, m_batchno, "canshu_test", m_unitno, changedparavalues[j], "", "", "", "0" };//
dt.Rows.Add(dr);
}
#region 生成xml字符串通过mq发送并存储xml文件
// MesInterface.HandleMesXML hxml = new HandleMesXML();
string TemplateAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/SegRecipeParas/XmlPath", "TemplatePath");//@"F:\项目\长春\长春\计划\ZSZK\投入产出信息集成.xml";//写xml获取这个值
string SaveAddress = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/SegRecipeParas/XmlPath", "SavePath");//@"F:\test";//写xml获取这个值
string QueueManagerName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/SegRecipeParas/Mq", "QueueManagerName");
string QueueName = hxml.Read(@"C:\ProFiles\MesWebServiceConfigure.xml", "/app/FeedBack/SegRecipeParas/Mq", "QueueName");
string xmltext = hxml.GenerateMesXml(TemplateAddress, dt, SaveAddress);
//通过mq发送给mes
// MesInterface.MQ mq = new MQ("cczs2", "channelformes");
// MesInterface.MQ mq = new MQ(QueueManagerName, QueueName);
mq.SendMQ(xmltext, QueueManagerName, QueueName);
#endregion
// data
}
}
#endregion
}
}