You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
655 lines
31 KiB
655 lines
31 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using DBFactory;
|
|
using CommonLib;
|
|
using System.Threading;
|
|
using System.Linq;
|
|
namespace WcfControlMonitorLib
|
|
{
|
|
/// <summary>
|
|
/// Creator:Richard.liu
|
|
/// ¶¯Ì¬¼ÆËã·¾¶¿ÉÓÃ״̬
|
|
/// </summary>
|
|
public static class CParsePLCData
|
|
{
|
|
public static event RefreshMonitorEventHandler RefreshMonitor;
|
|
public static void OnRefreshMonitor(RefreshMonitorEventArgs e)
|
|
{
|
|
if (RefreshMonitor != null)
|
|
{
|
|
RefreshMonitor(e);
|
|
}
|
|
}
|
|
public static event CDeviceStateChangeEventHandler DeviceStateChange;
|
|
public static void OnDeviceStateChange(object sender,CDeviceStateChangeEventArgs e)
|
|
{
|
|
if (DeviceStateChange != null)
|
|
{
|
|
DeviceStateChange(sender, e);
|
|
}
|
|
}
|
|
|
|
static StringBuilder sql = new StringBuilder();
|
|
|
|
static string _CParsePLCError = "";//¼à¿Øµ÷¶ÈÀà´íÎó˵Ã÷
|
|
|
|
public static string CParsePLCError
|
|
{
|
|
get { return _CParsePLCError; }
|
|
set { _CParsePLCError = value; }
|
|
}
|
|
public class AltDeviceInfos
|
|
{
|
|
public int DeviceIndex;
|
|
public int DeviceKind;
|
|
public int RunState;
|
|
public int TaskNo;
|
|
public int ErrorCode;
|
|
}
|
|
static DBOperator dbo =new DBOperator();//20130926
|
|
static DBOperator dboMan = CStaticClass.dboM;//20130926
|
|
static Dictionary<int,AltDeviceInfos> _modifyPathDeviceInfo;
|
|
|
|
static object lockThis = new object();
|
|
/// <summary>
|
|
/// Ìí¼Ó¿ÉÒԸĵÀÉ豸ÐÅÏ¢
|
|
/// </summary>
|
|
public static void AddModifyPathDeviceInfo()
|
|
{
|
|
|
|
lock (lockThis)
|
|
{
|
|
DataView dv1 = new DataView();
|
|
_modifyPathDeviceInfo = new Dictionary<int,AltDeviceInfos>();
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select * from T_Base_Device where (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null order by F_DeviceIndex asc");//20130226richard.liu
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
AltDeviceInfos devinfo = new AltDeviceInfos();
|
|
devinfo.DeviceIndex = Convert.ToInt32(dv[i]["F_DeviceIndex"]);
|
|
devinfo.DeviceKind = Convert.ToInt32(dv[i]["F_DeviceKindIndex"]);
|
|
|
|
if (_modifyPathDeviceInfo.ContainsKey(Convert.ToInt32(dv[i]["F_DeviceIndex"])) == false)
|
|
{
|
|
_modifyPathDeviceInfo.Add(Convert.ToInt32(dv[i]["F_DeviceIndex"]), devinfo);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
public static void SetModifyPathDeviceInfo(int devindex,AltDeviceInfos altdev)
|
|
{
|
|
lock (lockThis)
|
|
{
|
|
_modifyPathDeviceInfo[devindex].ErrorCode = altdev.ErrorCode;
|
|
_modifyPathDeviceInfo[devindex].RunState = altdev.RunState;
|
|
_modifyPathDeviceInfo[devindex].TaskNo = altdev.TaskNo;
|
|
}
|
|
}
|
|
|
|
//static Thread mythreadRoute;
|
|
static Thread mythread;
|
|
static bool exitThread = false;//20091107
|
|
private static void BeginListen()
|
|
{//20091107
|
|
while (!exitThread )
|
|
{
|
|
try
|
|
{
|
|
lock (lockThis)
|
|
{//20130226richard.liu
|
|
SetDeviceState();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_CParsePLCError =ex.StackTrace+ ex.Message;
|
|
}
|
|
finally
|
|
{
|
|
//add for CATL YB2 5000
|
|
Thread.Sleep(5000);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void EndListen()
|
|
{//20091107
|
|
exitThread = true;
|
|
// add for CATL YB2 Ïß³ÌÍ£Ó÷½·¨ÓÐÎÊÌâ
|
|
if (mythread != null)
|
|
{
|
|
//add for CATL ×èÈûµ÷¶ÈÓõÄËùÓÐỊ̈߳¬Ê¹µ±Ç°Ïß³ÌÖÕÖ¹
|
|
mythread.Join();
|
|
// stopped µ±Ç°Ïß³Ì
|
|
mythread.Interrupt();
|
|
if (mythread.ThreadState == ThreadState.Stopped)
|
|
{
|
|
// mythread.Abort();
|
|
mythread = null;
|
|
}
|
|
}
|
|
}
|
|
public static void StartListen()
|
|
{
|
|
AddModifyPathDeviceInfo();
|
|
//20091107
|
|
exitThread = false;
|
|
mythread = new Thread(new ThreadStart(BeginListen));
|
|
mythread.IsBackground = true;
|
|
mythread.Start();
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// È¡µÃÖ¸¶¨É豸Ë÷ÒýµÄÉ豸״̬:[0]¶Áд±êÖ¾;[1]״̬;[2]ÈÎÎñºÅ£»[3]X×ø±ê;[4]Y×ø±ê;[5]É豸Ë÷Òý
|
|
/// </summary>
|
|
/// <param name="deviceIdx">É豸Ë÷Òý</param>
|
|
/// <returns></returns>
|
|
|
|
public static int[] GetModifyPathDeviceState(int deviceIdx)
|
|
{
|
|
int[] states = new int[6] { 1, 0, 0, 0, 0, deviceIdx };
|
|
Model.MDevice mdevinfo = Model.CGetInfo.GetModifyPathDeviceInfo(deviceIdx);
|
|
if (mdevinfo != null)
|
|
{
|
|
states[1] = mdevinfo.ErrorCode;
|
|
states[2] = mdevinfo.TaskNo;
|
|
|
|
return states;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// ÉèÖÃËùÓÐÉ豸µÄµ±Ç°¶¯Ì¬ÊôÐÔ
|
|
/// </summary>
|
|
public static void SetDeviceState()
|
|
{
|
|
DataView dvv = new DataView();
|
|
DataView dv = new DataView();//20130306richard.liu
|
|
try
|
|
{
|
|
//Èç¹ûÔËÐгÌÐòºó£¬ÔÚ10ÃëÖÓÒÔÄÚ´ò¿ªÃüÁ¹Øupdateroute = false,Èç¹ûÔÚ10ÃëÖÓÖ®ºó´ò¿ªÃüÁ¹Øupdateroute = true;£¬¿ÉÒÔÔÚ´ò¿ªÃüÁ¹ØÊ±CStaticClass.routetime = DateTime.Now;
|
|
bool updateroute = false;
|
|
//if (CStaticClass.routetime.AddSeconds(10) <= DateTime.Now)
|
|
if (CStaticClass.routetime.AddSeconds(5) <= DateTime.Now)//¿ÉÄÜÔÚ10ÃëÖÓÄÚÉêÇëÈÎÎñ£¬µ¼Ö·¾¶²»¿ÉÓÃC
|
|
{
|
|
updateroute = true;
|
|
CStaticClass.routetime = DateTime.Now;
|
|
}
|
|
sql.Remove(0, sql.Length);//20130306richard.liu
|
|
sql.Append("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_LockedState = - 1) and (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null");//20130306richard.liu// and F_DeviceIndex !=13007 and F_DeviceIndex != 13008 and F_DeviceIndex != 13023 and F_DeviceIndex !=13024
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20130306richard.liu
|
|
dv.Sort = "F_DeviceIndex";//20130306richard.liu
|
|
int[] States;
|
|
foreach (int devindex in _modifyPathDeviceInfo.Keys)
|
|
{
|
|
|
|
|
|
AltDeviceInfos devinfo1 = _modifyPathDeviceInfo[devindex];
|
|
#region Ôö¼ÓÉ豸ͣÓÃ״̬´úÂë add for catl YB3 µ÷ÊÔ½ûÓÃʱµçÆø¸üÐÂ״̬ µ÷¶È״̬±ä»¯
|
|
//É豸ͣÓÃʱºòµçÆøÉϱ¨×´Ì¬ ÔÀ´·½·¨»á½«×´Ì¬¸üР½ûÓÃʧЧ ËùÒÔÔö¼ÓÕâ¸ö
|
|
DataView errorCode = dbo.ExceSQL(string.Format("SELECT f_errorcode FROM T_BASE_DEVICE WHERE f_errorcode = '998' and f_deviceindex = {0}", devinfo1.DeviceIndex)).Tables[0].DefaultView;
|
|
if (errorCode.Count > 0)
|
|
{
|
|
devinfo1.RunState = 4;
|
|
}
|
|
#endregion
|
|
//if (devinfo1.DeviceKind >= 6 && devinfo1.DeviceKind <= 30) continue;//20130226richard.liu
|
|
|
|
#region É豸±»Í£ÓÃ
|
|
//20130306richard.liu
|
|
if (dv.Find(devindex) >= 0)//20130306richard.liu
|
|
{
|
|
// Õâ¸öϹÌîµÄ¼¸¸öÊý ÅäÖà ²»Ð޸ķ¾¶×´Ì¬µÄ kkk
|
|
//string NOCheck = "13250;13456;13123;13024";
|
|
//if (updateroute == true)
|
|
//{//20100131
|
|
// UpdateErrorCode(devinfo1.DeviceIndex, 998);
|
|
// if (!NOCheck.Contains(devindex.ToString()))
|
|
// {
|
|
// AlterRoute(devinfo1.DeviceIndex, 998);
|
|
// }
|
|
//}
|
|
//20090926
|
|
if (devinfo1.ErrorCode != 998)
|
|
{
|
|
UpdateErrorCode(devinfo1.DeviceIndex, 998);
|
|
//if (!NOCheck.Contains(devindex.ToString()))
|
|
//{
|
|
AlterRoute(devinfo1.DeviceIndex, 998);
|
|
//}
|
|
devinfo1.RunState = 4;
|
|
|
|
}
|
|
devinfo1.ErrorCode = 998;
|
|
}
|
|
|
|
#endregion
|
|
|
|
else
|
|
{
|
|
#region ÊäËÍ»úÀà
|
|
|
|
if (devinfo1.DeviceKind == 2)//20130226richard.liu
|
|
{
|
|
{
|
|
States = GetModifyPathDeviceState(devinfo1.DeviceIndex);
|
|
if (States == null) continue;
|
|
|
|
if (States[1] >= 30)
|
|
{
|
|
if (updateroute == true)
|
|
{//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//20100131
|
|
|
|
//Ð޸ķ¾¶±í
|
|
if (States[1] != devinfo1.ErrorCode)
|
|
{
|
|
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
|
|
devinfo1.ErrorCode = States[1];
|
|
devinfo1.RunState = 2;
|
|
}
|
|
|
|
else if ((States[1] == 0) || (States[1] == 1) || (States[1] == 2))
|
|
{
|
|
if (updateroute == true)
|
|
{//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, 0);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//20100131
|
|
|
|
//Ð޸ķ¾¶±í
|
|
if (States[1] != devinfo1.ErrorCode)
|
|
{
|
|
UpdateErrorCode(devinfo1.DeviceIndex, 0);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//20090926
|
|
|
|
if (States[1] == 2)
|
|
{
|
|
//20090920
|
|
devinfo1.RunState = 5;
|
|
}
|
|
else
|
|
{
|
|
devinfo1.RunState = States[1];
|
|
}
|
|
//20100131
|
|
|
|
|
|
//20091006
|
|
devinfo1.ErrorCode = States[1];
|
|
//20090926
|
|
}
|
|
devinfo1.TaskNo = States[2];
|
|
//20101118
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ÒÆ¶¯É豸Àà
|
|
|
|
if ((devinfo1.DeviceKind == 1) || (devinfo1.DeviceKind == 4))
|
|
{
|
|
States = GetModifyPathDeviceState(devinfo1.DeviceIndex);
|
|
|
|
if (States == null) continue;
|
|
|
|
|
|
if (States[1] >= 30)
|
|
{
|
|
if (updateroute == true)
|
|
{//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//Ð޸ķ¾¶±í
|
|
if (States[1] != devinfo1.ErrorCode)
|
|
{
|
|
//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, States[1]);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
devinfo1.ErrorCode = States[1];
|
|
devinfo1.RunState = 2;
|
|
}
|
|
else if ((States[1] == 0) || (States[1] == 1) || (States[1] == 2))
|
|
{
|
|
if (updateroute == true)
|
|
{//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, 0);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//Ð޸ķ¾¶±í
|
|
if (States[1] != devinfo1.ErrorCode)
|
|
{
|
|
//20100131
|
|
UpdateErrorCode(devinfo1.DeviceIndex, 0);
|
|
AlterRoute(devinfo1.DeviceIndex, States[1]);
|
|
}
|
|
//20090926
|
|
|
|
if (States[1] == 2)
|
|
{
|
|
//20090920
|
|
devinfo1.RunState = 5;
|
|
}
|
|
else
|
|
{
|
|
devinfo1.RunState = States[1];
|
|
}
|
|
//20100131
|
|
devinfo1.ErrorCode = States[1];
|
|
|
|
}
|
|
devinfo1.TaskNo = States[2];
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
SetModifyPathDeviceInfo(devindex, devinfo1);
|
|
}
|
|
}
|
|
|
|
catch (Exception exa)
|
|
{
|
|
|
|
_CParsePLCError = string.Format("½âÎöPLC·´À¡Êý¾ÝµÄ¼Ç¼É豸״̬ʱ·¢Éú´íÎó£º{0}", exa.StackTrace+exa.Message );
|
|
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", _CParsePLCError);
|
|
OnRefreshMonitor(rmea);
|
|
}
|
|
finally
|
|
{
|
|
dvv.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ð޸ı¾µØÂ·¾¶±í¡¢·´À¡¸ø¹ÜÀíµÄ·¾¶±í
|
|
/// </summary>
|
|
/// <param name="devInx">·¢Éú¹ÊÕϵÄÉ豸Ë÷Òý</param>
|
|
/// <returns></returns>
|
|
public static bool AlterRoute(int devInx, int state)
|
|
{
|
|
|
|
DataView dvr = new DataView(); DataView dv1 = new DataView(); DataView dv = new DataView();
|
|
try
|
|
{
|
|
#region ¸ù¾Ý¶Ñ¶â»úÐ޸ĹÜÀíÏïµÀÊÇ·ñ¿ÉÓÃ
|
|
//if ((devInx >= 11001) && (devInx <= 11003))
|
|
//{//20110405±íÃû£ºWH_LANEWAY ×ֶΣºWAREHOUSE_CODE£º²Ö¿â±àÂë-01¡¢03¡¢04 LANEWAY_CODE:ÏïµÀ±àÂë-1¡¢2¡¢3
|
|
// //DEVICE_FLAG£ºÉ豸״̬-0=²»¿ÉÓã»1=¿ÉÓÃ
|
|
// string LANEWAY_CODE = devInx.ToString().Substring(4,1);
|
|
// int DEVICE_FLAG=-1;
|
|
// if (state >= 30)
|
|
// {
|
|
// DEVICE_FLAG =0;
|
|
// }
|
|
// else
|
|
// {
|
|
// DEVICE_FLAG =1;
|
|
// }
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update WH_LANEWAY set DEVICE_FLAG=").Append(DEVICE_FLAG).Append(" where WAREHOUSE_CODE='01' and LANEWAY_CODE='").Append(LANEWAY_CODE).Append("' and DEVICE_FLAG<>").Append(DEVICE_FLAG);
|
|
// dboMan.ExceSQL(sql.ToString());
|
|
|
|
//}
|
|
#endregion
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select distinct F_RouteID from T_Base_Route_Device where F_DeviceOrder!=-1 and F_DeviceIndex=").Append(devInx);//F_DeviceOrder>0 and 20170927
|
|
//sql.Append("select distinct F_RouteID from T_Base_Route_Device where F_DeviceOrder>0 and F_DeviceIndex=").Append(devInx);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count; i++)
|
|
{
|
|
if (state >= 30)
|
|
{
|
|
//ËùÓÐ×Ó·¾¶¶¼²»¿ÉÓÃʱ£¬·½²ÅÉ趨´Ë·¾¶ÕæµÄ²»¿ÉÓÃ
|
|
sql.Remove(0, sql.Length);
|
|
// " FROM T_Base_Route_Device,T_Base_Device where (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null and F_DeviceOrder >0 and T_Base_Route_Device.F_DeviceIndex = T_Base_Device.F_DeviceIndex").Append(
|
|
|
|
sql.Append(" SELECT T_Base_Route_Device.F_RouteIDSub, SUM(T_Base_Device.F_ErrorCode) AS ErrorCodes ").Append(
|
|
" FROM T_Base_Route_Device,T_Base_Device where ( F_DeviceOrder!=-1 ) and (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null and T_Base_Route_Device.F_DeviceIndex = T_Base_Device.F_DeviceIndex").Append( //20170927
|
|
" and T_Base_Route_Device.F_RouteID=").Append(dv[i]["F_RouteID"]).Append(" GROUP BY T_Base_Route_Device.F_RouteIDSub ");//20130226richard.liu
|
|
dvr = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
bool ifUsable = false;
|
|
for (int kk = 0; kk < dvr.Count; kk++)
|
|
{
|
|
if (Convert.ToInt32(dvr[kk]["ErrorCodes"]) <= 0)
|
|
{
|
|
ifUsable = true;
|
|
break;
|
|
}
|
|
}
|
|
if (ifUsable == false)
|
|
{
|
|
|
|
//20101011
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update t_base_route set F_Status=0 where f_routeid=").Append(dv[i]["F_RouteID"]).Append(" and F_Status=1 and F_AutoUpdate=1 ");
|
|
int ups = dbo.ExecuteSql(sql.ToString());
|
|
//add for catl FD3 ¸ø¹ÜÀí¸üз¾¶ÓÀÔ¶¿ÉÓÃ ÍÆÍÁ»úÉ豸Õý³£ ¾Í·¾¶¿ÉÓÃ
|
|
string[] NoRouteID1 = { "175", "176", "177", "178","179", "180", "181", "182","183","184","185","186"};//18001
|
|
string[] NoRouteID2= { "187", "188", "189", "190","191", "192", "193", "194","195","196","197","198"};//18002
|
|
string[] NoRouteID3 = { "233", "234", "235", "236","237", "238", "239", "240","241","242","243","244"};//18003
|
|
string[] NoRouteID4 = { "245", "246", "247", "248","249", "250", "251", "252","253","254","255","256"};//18004
|
|
if (NoRouteID1.Contains(dv[i]["F_RouteID"].ToString()) || NoRouteID2.Contains(dv[i]["F_RouteID"].ToString())
|
|
|| NoRouteID3.Contains(dv[i]["F_RouteID"].ToString()) || NoRouteID4.Contains(dv[i]["F_RouteID"].ToString()))
|
|
{
|
|
int intRDevice = 0;
|
|
if (NoRouteID1.Contains(dv[i]["F_RouteID"].ToString()))
|
|
{
|
|
intRDevice = 10001;
|
|
}
|
|
else if (NoRouteID2.Contains(dv[i]["F_RouteID"].ToString()))
|
|
{
|
|
intRDevice = 10002;
|
|
}
|
|
else if (NoRouteID3.Contains(dv[i]["F_RouteID"].ToString()))
|
|
{
|
|
intRDevice = 10003;
|
|
}
|
|
else if (NoRouteID4.Contains(dv[i]["F_RouteID"].ToString()))
|
|
{
|
|
intRDevice = 10004;
|
|
}
|
|
//sql.Remove(0, sql.Length);
|
|
//sql.Append("select f_deviceindex from T_BASE_DEVICE where f_devicekindindex = 1 and f_deviceindex= ").Append(devInx);
|
|
//DataView Route = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (intRDevice == 0) { return true; }
|
|
//Åж϶Ѷâ»ú״̬ ¶Ñ¶â»ú¿ÉÓ÷¾¶¾ÍÊÇ¿ÉÓÃ
|
|
Model.MDevice devinforoute;
|
|
devinforoute = Model.CGetInfo.GetDeviceInfo(intRDevice);
|
|
if (devinforoute.RunState <= 1 && devinforoute.RunState !=5)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where CONTROL_ROUTE_ID='").Append(dv[i]["F_RouteID"]).Append("' and CONTROL_ROUTE_STATUS=0");
|
|
}
|
|
else
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where CONTROL_ROUTE_ID='").Append(dv[i]["F_RouteID"]).Append("' and CONTROL_ROUTE_STATUS=1");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where CONTROL_ROUTE_ID='").Append(dv[i]["F_RouteID"]).Append("' and CONTROL_ROUTE_STATUS=1");
|
|
}
|
|
|
|
|
|
dboMan.ExceSQL(sql.ToString());
|
|
}
|
|
else
|
|
{
|
|
//20120328ÓÐÒ»Ìõ×Ó·¾¶¿ÉÓã¬Â·¾¶¾Í¿ÉÓÃ
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update t_base_route set F_Status=1 where f_routeid=").Append(dv[i]["F_RouteID"]).Append(" and F_Status=0 and F_AutoUpdate=1 ");
|
|
int ups = dbo.ExecuteSql(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where CONTROL_ROUTE_ID='").Append(dv[i]["F_RouteID"]).Append("' and CONTROL_ROUTE_STATUS=0");
|
|
if (ups > 0) dboMan.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT SUM(T_Base_Device.F_ErrorCode) as errcode FROM T_Base_Device ,T_Base_Route_Device").Append(
|
|
" where ( F_DeviceOrder!=-1 ) and (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null and T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and T_Base_Route_Device.F_RouteID=").Append(dv[i]["F_RouteID"]);//20170927
|
|
//" where (F_DeviceKindIndex=1 or F_DeviceKindIndex=2 or F_DeviceKindIndex=4) and F_DBW2Address is not null and F_DeviceOrder>0 and T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and T_Base_Route_Device.F_RouteID=").Append(dv[i]["F_RouteID"]);//20130226richard.liu
|
|
dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv1.Count > 0)
|
|
{
|
|
int errcode = 0; int a = 0;
|
|
if (int.TryParse(dv1[0]["errcode"].ToString(), out a) == true)
|
|
{
|
|
errcode = Convert.ToInt32(dv1[0]["errcode"]);
|
|
}
|
|
|
|
if (errcode <= 0)
|
|
{
|
|
//20101011
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update t_base_route set F_Status=1 where f_routeid=").Append(dv[i]["F_RouteID"]).Append(" and F_Status=0 and F_AutoUpdate=1 ");
|
|
int ups = dbo.ExecuteSql(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where CONTROL_ROUTE_ID='").Append(dv[i]["F_RouteID"]).Append("' and CONTROL_ROUTE_STATUS=0");
|
|
if (ups > 0) dboMan.ExceSQL(sql.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_CParsePLCError = string.Format("½âÎöPLC·´À¡Êý¾ÝµÄÐ޸ķ¾¶Ê±·¢Éú´íÎó,É豸:{0},״̬:{1},Òì³£:{2}", devInx,state, ex.StackTrace+ex.Message );
|
|
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", _CParsePLCError);
|
|
OnRefreshMonitor(rmea);
|
|
return false;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
dvr.Dispose();
|
|
dv1.Dispose();
|
|
}
|
|
}
|
|
static void UpdateErrorCode(int devInx, int errorCode)
|
|
{
|
|
#region ÔÀ´µÄ³ÌÐò
|
|
////20130226richard.liu
|
|
//sql.Clear();
|
|
//sql.Append("SELECT F_DeviceErrorIndex FROM T_Base_Device_State where F_DeviceKindIndex=").Append(_modifyPathDeviceInfo[devInx].DeviceKind).Append(" and F_DeviceErrorIndex=").Append(errorCode);
|
|
//DataView dv = dbo.³ÌÐòExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
//if (dv.Count > 0)
|
|
//{
|
|
// sql.Clear();
|
|
// sql.Append("UPDATE T_Base_Device SET F_ErrorCode = ").Append(errorCode).Append(" WHERE (F_DeviceIndex = ").Append(devInx).Append(")and (F_ErrorCode <> ").Append(errorCode).Append(")");
|
|
// CStaticClass.dbo.ExecuteSql(sql.ToString());//20130306richard.liuʹÓÃÖ÷Ïß³ÌÊý¾ÝÁ¬½ÓÐ޸ģ¬ÒÔÃâÔì³ÉUPDATE²¢·¢
|
|
//}
|
|
//dv.Dispose();
|
|
#endregion
|
|
DataView dv = new DataView();
|
|
int errorindex = 0;
|
|
try
|
|
{
|
|
|
|
string sqlstr = string.Format("SELECT F_DeviceIndex,F_ErrorTaskNo,F_ErrorCode FROM T_Base_Device where F_DeviceIndex={0} and F_ErrorCode!={1}", devInx, errorCode);//²éÕÒ¹ÊÕÏÉ豸
|
|
dv = dbo.ExceSQL(sqlstr).Tables[0].DefaultView;
|
|
//sql.Append("SELECT F_DeviceErrorIndex FROM T_Base_Device_State where F_DeviceKindIndex=").Append(_modifyPathDeviceInfo[devInx].DeviceKind).Append(" and F_DeviceErrorIndex=").Append(errorCode);
|
|
|
|
if (dv.Count > 0)//״̬·¢Éú±ä»¯Ö®ºó²Å¸üÐÂ״̬
|
|
{
|
|
|
|
if (errorCode > 0)
|
|
{
|
|
Model.MError errs = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(_modifyPathDeviceInfo[devInx].DeviceKind + errorCode.ToString()));
|
|
if (errs == null)
|
|
{
|
|
return;
|
|
}
|
|
errorindex = errs.ErrorIndex;
|
|
}
|
|
|
|
|
|
string str = string.Empty;
|
|
if (errorCode == 0)
|
|
{
|
|
str = string.Format(",F_ErrorTaskNo=0 ");
|
|
}
|
|
sqlstr = string.Format("UPDATE T_Base_Device SET F_ErrorCode = {0}{1} WHERE (F_DeviceIndex = {2})and (F_ErrorCode <> {3})", errorCode, str, devInx, errorCode);
|
|
|
|
//sql.Clear();
|
|
//sql.Append("UPDATE T_Base_Device SET F_ErrorCode = ").Append(errorCode).Append(" WHERE (F_DeviceIndex = ").Append(devInx).Append(")and (F_ErrorCode <> ").Append(errorCode).Append(")");
|
|
int count = CStaticClass.dbo.ExecuteSql(sqlstr);//20130306richard.liuʹÓÃÖ÷Ïß³ÌÊý¾ÝÁ¬½ÓÐ޸ģ¬ÒÔÃâÔì³ÉUPDATE²¢·¢
|
|
//È«²¿×¢ÊÍ
|
|
//if (count > 0) //¹ÊÕϽâ³ýʱ¼Ç¼¹ÊÕϽáÊøÊ±¼ä
|
|
//{
|
|
// ×¢Ê͵ô
|
|
//string dtime = DateTime.Now.ToString("u");//20110603
|
|
|
|
//dtime = dtime.Substring(0, dtime.Length - 1);
|
|
|
|
////еĹÊÕÏ·¢Éúʱ£¬Ïȸü¸ÄÉÏÒ»¸ö¹ÊÕϵĽáÊøÊ±¼ä
|
|
//sqlstr = string.Format("UPDATE T_Base_Device_Error_Log SET F_End_DateTime ='{0}' Where F_End_DateTime is null and F_DeviceIndex={1} ", dtime, devInx);
|
|
|
|
//CStaticClass.dbo.ExecuteSql(sqlstr);//20130306richard.liuʹÓÃÖ÷Ïß³ÌÊý¾ÝÁ¬½ÓÐ޸ģ¬ÒÔÃâÔì³ÉUPDATE²¢·¢
|
|
|
|
////еĹÊÕÏ·¢Éú,¼Ç¼
|
|
//if (errorCode != 0 && errorCode != 998)//É豸±»½ûÓÃÒÔºó£¬Ò²ÈÏΪÊÇÎÞ¹ÊÕÏ
|
|
//{
|
|
// int taskno = _modifyPathDeviceInfo[devInx].TaskNo;
|
|
// sqlstr = string.Format("INSERT INTO T_Base_Device_Error_Log (F_TaskNo,F_DeviceIndex, F_ErrorIndex, F_DateTime) VALUES ({0},{1},{2},'{3}')", taskno, devInx, errorindex, dtime);
|
|
|
|
// CStaticClass.dbo.ExecuteSql(sqlstr);//20130306richard.liuʹÓÃÖ÷Ïß³ÌÊý¾ÝÁ¬½ÓÐ޸ģ¬ÒÔÃâÔì³ÉUPDATE²¢·¢
|
|
|
|
|
|
//}
|
|
|
|
|
|
//}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|