|
|
@@ -53,7 +53,22 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
try
|
|
|
{
|
|
|
//按当前登录用户在工位表中的当前工号查找工位类型
|
|
|
- workStationType = getWorkStationType(conn, sUserInfo.UserCode);
|
|
|
+ //workStationType = getWorkStationType(conn, sUserInfo.UserCode);
|
|
|
+ DataTable dataTable = GetWorkStationInfo(conn, sUserInfo.UserCode);
|
|
|
+ if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ workStationType = Convert.ToInt32(dataTable.Rows[0]["WORKSTATIONTYPEID"]);
|
|
|
|
|
|
//成检交接3211
|
|
|
if (workStationType == 3211)
|
|
|
@@ -244,6 +259,33 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
new CDAParameter("USERCODE", userCode)
|
|
|
));
|
|
|
}
|
|
|
+ private static DataTable GetWorkStationInfo(IDataAccess conn, string userCode)
|
|
|
+ {
|
|
|
+ DataTable dataTable = conn.ExecuteDatatable(@"
|
|
|
+ SELECT
|
|
|
+t.workstationid,
|
|
|
+t.workstationtypeid,
|
|
|
+t.workstationname,
|
|
|
+t.procedureid,
|
|
|
+t.groutinglineid,
|
|
|
+t.usercode,
|
|
|
+t.pccode,
|
|
|
+t.plcip,
|
|
|
+t.plcport,
|
|
|
+t.plcobject,
|
|
|
+t.valueflag,
|
|
|
+t.plcobjectread,
|
|
|
+t.plc_flag
|
|
|
+ FROM
|
|
|
+ TP_MST_WORKSTATION t
|
|
|
+ WHERE
|
|
|
+ t.USERCODE =@USERCODE@
|
|
|
+ ",
|
|
|
+ //new CDAParameter("WORKSTATIONTYPE", workStationType),
|
|
|
+ new CDAParameter("USERCODE", userCode)
|
|
|
+ );
|
|
|
+ return dataTable;
|
|
|
+ }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 写PLC xuwei add 2020-06-29
|
|
|
@@ -257,13 +299,24 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
{
|
|
|
//读取工位配置信息
|
|
|
DataTable dataTable = conn.ExecuteDatatable(@"
|
|
|
- SELECT
|
|
|
- *
|
|
|
+ SELECT --t.*
|
|
|
+t.workstationtypeid,
|
|
|
+t.workstationname,
|
|
|
+t.procedureid,
|
|
|
+t.groutinglineid,
|
|
|
+t.usercode,
|
|
|
+t.pccode,
|
|
|
+t.plcip,
|
|
|
+t.plcport,
|
|
|
+t.plcobject,
|
|
|
+t.valueflag,
|
|
|
+t.plcobjectread,
|
|
|
+t.plc_flag
|
|
|
FROM
|
|
|
TP_MST_WORKSTATION t
|
|
|
WHERE
|
|
|
t.WORKSTATIONTYPEID = @WORKSTATIONTYPE@
|
|
|
- AND USERCODE =@USERCODE@
|
|
|
+ AND t.USERCODE =@USERCODE@
|
|
|
",
|
|
|
new CDAParameter("WORKSTATIONTYPE", workStationType),
|
|
|
new CDAParameter("USERCODE", userCode)
|
|
|
@@ -272,7 +325,20 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
{
|
|
|
return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
}
|
|
|
+
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
+ if (string.IsNullOrWhiteSpace(ip))
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
|
|
|
JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
|
|
|
|
|
|
@@ -327,13 +393,24 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
{
|
|
|
//读取工位配置信息
|
|
|
DataTable dataTable = conn.ExecuteDatatable(@"
|
|
|
- SELECT
|
|
|
- *
|
|
|
+ SELECT --t.*
|
|
|
+t.workstationtypeid,
|
|
|
+t.workstationname,
|
|
|
+t.procedureid,
|
|
|
+t.groutinglineid,
|
|
|
+t.usercode,
|
|
|
+t.pccode,
|
|
|
+t.plcip,
|
|
|
+t.plcport,
|
|
|
+t.plcobject,
|
|
|
+t.valueflag,
|
|
|
+t.plcobjectread,
|
|
|
+t.plc_flag
|
|
|
FROM
|
|
|
TP_MST_WORKSTATION t
|
|
|
WHERE
|
|
|
t.WORKSTATIONTYPEID = @WORKSTATIONTYPE@
|
|
|
- AND USERCODE =@USERCODE@
|
|
|
+ AND t.USERCODE =@USERCODE@
|
|
|
",
|
|
|
new CDAParameter("WORKSTATIONTYPE", workStationType),
|
|
|
new CDAParameter("USERCODE", userCode)
|
|
|
@@ -344,7 +421,20 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "当前工号无工位信息" };
|
|
|
}
|
|
|
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
+ if (string.IsNullOrWhiteSpace(ip))
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
|
|
|
JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECTREAD"].ToString());
|
|
|
|
|
|
@@ -397,7 +487,19 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
|
|
|
#region 读取工位配置信息
|
|
|
string sql =
|
|
|
- "SELECT *\n" +
|
|
|
+ "SELECT --t.*\n" + @"
|
|
|
+t.workstationtypeid,
|
|
|
+t.workstationname,
|
|
|
+t.procedureid,
|
|
|
+t.groutinglineid,
|
|
|
+t.usercode,
|
|
|
+t.pccode,
|
|
|
+t.plcip,
|
|
|
+t.plcport,
|
|
|
+t.plcobject,
|
|
|
+t.valueflag,
|
|
|
+t.plcobjectread,
|
|
|
+t.plc_flag" +
|
|
|
" FROM tp_mst_workstation t\n" +
|
|
|
" WHERE t.workstationtypeid = @workstationtype@";
|
|
|
|
|
|
@@ -405,7 +507,7 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
|
|
|
if (!string.IsNullOrEmpty(userCode))
|
|
|
{
|
|
|
- sql += " AND usercode = @usercode@";
|
|
|
+ sql += " AND t.usercode = @usercode@";
|
|
|
paras.Add(new CDAParameter("usercode", userCode));
|
|
|
}
|
|
|
|
|
|
@@ -415,9 +517,123 @@ namespace Dongke.IBOSS.PRD.Service.CMNModuleService
|
|
|
{
|
|
|
return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "无当前工位信息" };
|
|
|
}
|
|
|
-#endregion
|
|
|
+
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
|
|
|
string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
+ if (string.IsNullOrWhiteSpace(ip))
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
|
|
|
+ JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
|
|
|
+
|
|
|
+ //写入PLC
|
|
|
+ using (SocketClient<SiemensS7_1200Model> plc = new SocketClient<SiemensS7_1200Model>())
|
|
|
+ {
|
|
|
+ //自动按配置写
|
|
|
+ plc.Connect(ip, port);
|
|
|
+ for (int i = 0; i < plcObj.Count; i++)
|
|
|
+ {
|
|
|
+ if (plcObj[i]["type"].ToString().ToLower() == "string")
|
|
|
+ plc.Write<string>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), plcPara[plcObj[i]["name"].ToString()].ToString());
|
|
|
+ else if (plcObj[i]["type"].ToString().ToLower() == "int")
|
|
|
+ plc.Write<short>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToInt16(plcPara[plcObj[i]["name"].ToString()]));
|
|
|
+ else if (plcObj[i]["type"].ToString().ToLower() == "bool")
|
|
|
+ plc.Write<bool>(plcObj[i]["code"].ToString(), plcObj[i]["number"].ToString(), Convert.ToBoolean(plcPara[plcObj[i]["name"].ToString()]));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+#if DEBUG
|
|
|
+ //写入操作成功日志
|
|
|
+ string plcParaStr = "";
|
|
|
+ foreach (string key in plcPara.Keys)
|
|
|
+ {
|
|
|
+ plcParaStr += " " + key + ":" + plcPara[key].ToString() + " ";
|
|
|
+ }
|
|
|
+ Curtain.Log.Logger.Debug($"PLC写入成功!{plcParaStr} {ip} {userCode} {plcObj.ToString()}");
|
|
|
+#endif
|
|
|
+ //PLC操作成功
|
|
|
+ return new ServiceResultEntity()
|
|
|
+ {
|
|
|
+ Status = Constant.ServiceResultStatus.Success,
|
|
|
+ Message = "" //一定不可以有值,为空时才是提交成功
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 写PLC 成型线放行
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="workStationType"></param>
|
|
|
+ /// <param name="plcPara"></param>
|
|
|
+ /// <param name="userCode"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static ServiceResultEntity PlcWrite_GL(int workStationType, int gl_id,
|
|
|
+ Hashtable plcPara, string userCode = null)
|
|
|
+ {
|
|
|
+ using (IDataAccess conn = DataAccess.Create())
|
|
|
+ {
|
|
|
+ List<CDAParameter> paras = new List<CDAParameter>();
|
|
|
+
|
|
|
+ #region 读取工位配置信息
|
|
|
+ string sql =
|
|
|
+ "SELECT --t.*\n" + @"
|
|
|
+t.workstationtypeid,
|
|
|
+t.workstationname,
|
|
|
+t.procedureid,
|
|
|
+t.groutinglineid,
|
|
|
+t.usercode,
|
|
|
+t.pccode,
|
|
|
+t.plcip,
|
|
|
+t.plcport,
|
|
|
+t.plcobject,
|
|
|
+t.valueflag,
|
|
|
+t.plcobjectread,
|
|
|
+t.plc_flag" +
|
|
|
+ " FROM tp_mst_workstation t\n" +
|
|
|
+ " WHERE t.workstationtypeid = @workstationtype@\n" +
|
|
|
+ " AND t.GROUTINGLINEID = @GROUTINGLINEID@\n"
|
|
|
+ ;
|
|
|
+
|
|
|
+ paras.Add(new CDAParameter("workstationtype", workStationType));
|
|
|
+ paras.Add(new CDAParameter("GROUTINGLINEID", gl_id));
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(userCode))
|
|
|
+ {
|
|
|
+ sql += " AND t.usercode = @usercode@";
|
|
|
+ paras.Add(new CDAParameter("usercode", userCode));
|
|
|
+ }
|
|
|
+
|
|
|
+ DataTable dataTable = conn.ExecuteDatatable(sql, paras.ToArray());
|
|
|
+
|
|
|
+ if (dataTable == null || dataTable.Rows.Count == 0)
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Other, Message = "无当前工位信息" };
|
|
|
+ }
|
|
|
+ if (dataTable.Columns.Contains("PLC_FLAG"))
|
|
|
+ {
|
|
|
+ string plc_flag = dataTable.Rows[0]["PLC_FLAG"] + "";
|
|
|
+ if (plc_flag != "1")
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ string ip = dataTable.Rows[0]["PLCIP"] + "";
|
|
|
+ if (string.IsNullOrWhiteSpace(ip))
|
|
|
+ {
|
|
|
+ return new ServiceResultEntity() { Status = Constant.ServiceResultStatus.Success, Message = "" /*"PLC对接未启用"*/ };
|
|
|
+ }
|
|
|
int port = Convert.ToInt32(dataTable.Rows[0]["PLCPORT"]);
|
|
|
JArray plcObj = JArray.Parse(dataTable.Rows[0]["PLCOBJECT"].ToString());
|
|
|
|