using System; using System.Collections.Generic; using System.Text; using System.Data; using DBFactory; namespace Model { public static class CGeneralFunction { static DBOperator dbo = CGetInfo.dbo; static DBOperator dboM = CGetInfo.dboM; public const string DBSend = "DB1"; public const string DBGet = "DB2"; static Model.MDevice devinfo; /// /// 双叉关联任务是否能同步运行 /// /// 设备指令索引 /// public static bool DoubleForkIfSync(int monitorIndex, int devIndex, int devKind) {//查找关联的调度任务(主任务或者辅助任务);输送机与堆垛机区别对待 //如果只能找到关联任务未被拆分,那么认为能同步运行20100323 int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex); int FID = GetManageTaskIndexfromMonitor(monitorIndex); int devOrder = GetDeviceOrderFromMonitor(monitorIndex); int dfx = GetDoubleForkX(mankind, FID,devIndex,devOrder); int mx = GetXCoorFromMonitor(monitorIndex, devIndex, devOrder); int dfy = GetDoubleForkY(mankind,FID,devIndex,devOrder); int my = GetYCoorFromMonitor(monitorIndex, devIndex, devOrder); int dfz = GetDoubleForkZ(mankind, FID, devIndex, devOrder); int mz = GetZCoorFromMonitor(monitorIndex, devIndex, devOrder); if (GetDoubleForkUnIntoStep(monitorIndex) == true) return true; switch (devKind) { case 1: //如果主任务和副任务的列数都是1列,则是1121、1122顶升机构,可以同步 if (1 == GetDoubleForkX(mankind, FID, devIndex, devOrder) && (GetXCoorFromMonitor(monitorIndex, devIndex, devOrder) == 1)) { return true; } //堆垛机的同排,同层,临列可以同步并且ST_CELL的FDoubleFork值匹配 if ((Math.Abs(dfx - mx) == 1)&& (dfy ==my)&&(mz==dfz)) { if (EqualMonitorDoubleFork(mankind, FID, devIndex,devOrder) == true) { return true; } else { return false; } } else { return false; } case 2: //输送机同步 return true; case 6: //AGV临列可以同步并且ST_CELL的F_UseAwayFork值匹配 if (Math.Abs(dfx - mx) == 1) { if (EqualAGVGateDoubleFork(mankind, FID, devIndex, devOrder) == true) { return true; } else { return false; } } else { return false; } default: return false; } } /// /// 20110216根据S7Connection标识反馈所有DB1数据的虚拟设备 /// /// S7Connection标识 /// public static Model.MDevice GetDevice28AllDB1Data(StringBuilder sb) { DataView dv = dbo.ExceSQL("SELECT F_DeviceIndex FROM T_Base_Device WHERE (F_DeviceKindIndex = 28 and F_S7Connection='" + sb.ToString() + "')").Tables[0].DefaultView; if (dv.Count > 0) { return Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(dv[0]["F_DeviceIndex"])); } else { return null; } } /// /// 获得双叉控制的堆垛机的送货任务(已经分配远货叉或者近货叉的任务)的值 /// /// 设备指令索引 /// public static string GetUseAwayFork(int monitorIndex) { DataView dv = dbo.ExceSQL("SELECT F_UseAwayFork FROM T_Monitor_Task WHERE (F_MonitorIndex = "+monitorIndex +")").Tables[0].DefaultView; if (dv.Count > 0) { return dv[0][0].ToString(); } else { return "-"; } } /// /// 获取双叉控制的堆垛机的取货任务(尚未指定应该使用哪个货叉)是否使用远货叉(主货叉):0,近货叉;1远货叉 /// /// 排 /// 列 /// 层 /// 库房索引 /// 任务类型 /// 调度任务索引 /// 设备索引 /// 指令 /// public static int GetUseAwayFork(int monitorIndex,int devIndex, int devOrder) { int z = GetZCoorFromMonitor(monitorIndex, devIndex, devOrder); int x = GetXCoorFromMonitor(monitorIndex, devIndex, devOrder); int y = GetYCoorFromMonitor(monitorIndex, devIndex, devOrder); string FWAREHOUSE=GetWAREHOUSEFromSTCELL(devIndex); int Mankind=GetManageTaskKindIndexFromMonitor(monitorIndex); int ManFID=GetManageTaskIndexfromMonitor(monitorIndex); DataView dv; int UseAwayFork = 1; try { dv = dbo.ExceSQL("SELECT FDoubleFork FROM ST_CELL WHERE (FWAREHOUSE='" + FWAREHOUSE + "') and (F_Z = " + z + ") AND (F_X = " + x + ") AND (F_Y = " + y + ")").Tables[0].DefaultView; if (dv.Count > 0) { UseAwayFork = Convert.ToInt32(dv[0][0]); } else { UseAwayFork = 0; } switch (UseAwayFork) { case 0://可用任何一个货叉: int xcoor = GetDoubleForkX(Mankind, ManFID, devIndex, devOrder); if (xcoor != -1) { //根据关联任务的货位判断使用近货叉(列坐标小)或者远货叉(列坐标大) if (xcoor != x) { if (xcoor < x) { UseAwayFork = 1; } else { UseAwayFork = 0; } } else { //列坐标相同的,判断层坐标,近货叉(层坐标小)或者远货叉(层坐标大) int ycoor = GetDoubleForkY(Mankind, ManFID, devIndex, devOrder); if (ycoor != -1) { if (ycoor != y) { if (ycoor < y) { UseAwayFork = 1; } else { UseAwayFork = 0; } } else { //列和层都相同的,判断排坐标,近货叉(排坐标小)或者远货叉(排坐标大) int zcoor = GetDoubleForkZ(Mankind, ManFID, devIndex, devOrder); if (zcoor != -1) { if (zcoor != z) { if (zcoor < z) { UseAwayFork = 1; } else { UseAwayFork = 0; } } } } } } } else { UseAwayFork = 1; } break; case 1://只能用近叉 UseAwayFork = 0; break; case 2://只能用远叉 UseAwayFork = 1; break; } return UseAwayFork; } catch (Exception ex) { throw ex; } finally { dv = null; } } public static int GetDoubleForkFromST_CELL(int z, int x, int y, string FWAREHOUSE) { DataView dv; int UseAwayFork = 1; try { dv = dbo.ExceSQL("SELECT FDoubleFork FROM ST_CELL WHERE (FWAREHOUSE='" + FWAREHOUSE + "') and (F_Z = " + z + ") AND (F_X = " + x + ") AND (F_Y = " + y + ")").Tables[0].DefaultView; if (dv.Count > 0) { UseAwayFork = Convert.ToInt32(dv[0][0]); } else { UseAwayFork = 0; } return UseAwayFork; } catch (Exception ex) { throw ex; } finally { dv = null; } } public static string GetWAREHOUSEFromSTCELL(int stackIndex) { DataView dv; try { dv = dbo.ExceSQL("SELECT FWAREHOUSE FROM ST_CELL WHERE (FStack = " + stackIndex + ")").Tables[0].DefaultView; if (dv.Count > 0) { return dv[0][0].ToString(); } else { return ""; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 查找双叉关联任务的列坐标 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令 /// public static int GetDoubleForkX(int mankind, int fid, int devIdx, int devOrder) { DataView dv; string xc = "F_NumParam2"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 4) { xc = "F_NumParam2"; } else if (devOrder == 5) { xc = "F_NumParam5"; } } try { //查找被关联辅助设备指令索引的列坐标 DataView dv0 = dbo.ExceSQL("select F_RELATIVECONTORLID from T_Manage_Task where (FID = " + fid + ") AND (F_ManageTaskKindIndex = " + mankind + ")").Tables[0].DefaultView; if (dv0.Count == 0) return -1; string sql = "SELECT " + xc + " FROM T_Monitor_Task Where ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ") AND (T_Monitor_Task.F_ManageTaskIndex=" + dv0[0]["F_RELATIVECONTORLID"] + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][xc]); } dv0 = dbo.ExceSQL("select T_Manage_Task.FID from T_Manage_Task where (T_Manage_Task.F_ManageTaskKindIndex = "+mankind+") AND (F_RELATIVECONTORLID = " + fid + ")").Tables[0].DefaultView; if (dv0.Count == 0) return -1; //查找关联自己的主设备指令索引的列坐标 sql = "SELECT "+xc+" FROM T_Monitor_Task Where ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ") and (T_Monitor_Task.F_ManageTaskIndex= " + dv0[0]["FID"] + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][xc]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 查找双叉关联任务的层坐标 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令 /// public static int GetDoubleForkY(int mankind, int fid, int devIdx, int devOrder) { DataView dv; string yc = "F_NumParam3"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 4) { yc = "F_NumParam3"; } else if (devOrder == 5) { yc = "F_NumParam6"; } } try { //string aa22 = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString(); DataView dv0 = dbo.ExceSQL("select F_RELATIVECONTORLID from T_Manage_Task where FID = " + fid + " and F_ManageTaskKindIndex="+mankind +"").Tables[0].DefaultView; if (dv0.Count == 0) return -1; //查找被关联辅助设备指令索引的层坐标 string sql = "SELECT " + yc + " FROM T_Monitor_Task Where (T_Monitor_Task.F_ManageTaskIndex=" + dv0[0]["F_RELATIVECONTORLID"] + " " + " ) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][yc]); } dv0 = dbo.ExceSQL("select FID from T_Manage_Task where F_RELATIVECONTORLID = " + fid + " and F_ManageTaskKindIndex=" + mankind + "").Tables[0].DefaultView; if (dv0.Count == 0) return -1; //string aa212 = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString(); //查找关联自己的主设备指令索引的层坐标 sql = "SELECT " + yc + " FROM T_Monitor_Task Where (T_Monitor_Task.F_ManageTaskIndex=" + dv0[0]["FID"] + " " + ") and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; //string aa2qq2 = DateTime.Now.Second.ToString() + "-" + DateTime.Now.Millisecond.ToString(); if (dv.Count > 0) { return Convert.ToInt32(dv[0][yc]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 查找双叉关联任务的排坐标 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令 /// public static int GetDoubleForkZ(int mankind, int fid, int devIdx, int devOrder) { DataView dv; string zc = "F_NumParam1"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 4) { zc = "F_NumParam1"; } else if (devOrder == 5) { zc = "F_NumParam4"; } } try { //查找被关联辅助设备指令索引的排坐标 string sql = "SELECT "+zc+" FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][zc]); } //查找关联自己的主设备指令索引的排坐标 sql = "SELECT "+zc+" FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][zc]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 查找双叉关联任务的ST_CELL表的使用哪个货叉属性是否相同 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令 /// public static bool EqualMonitorDoubleFork(int mankind, int fid, int devIdx, int devOrder) { DataView dv; char DoubleFork = '0', DoubleFork1 = '0'; string xc = "F_NumParam2";string yc = "F_NumParam3";string zc = "F_NumParam1"; if (GetDeviceKindIdx(devIdx) == 1) { if ((devOrder == 4)||(devOrder == 2)) { xc = "F_NumParam2"; yc = "F_NumParam3"; zc = "F_NumParam1"; } else if ((devOrder == 5)||(devOrder == 3)) { xc = "F_NumParam5"; yc = "F_NumParam6"; zc = "F_NumParam4"; } } try { int z = 0, x = 0, y = 0, z1 = 0, x1 = 0, y1 = 0; //查找被关联辅助设备指令索引的列坐标 string sql = "SELECT " + zc + "," + xc + "," + yc + ",F_UseAwayFork FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { z = Convert.ToInt32(dv[0][zc]); x = Convert.ToInt32(dv[0][xc]); y = Convert.ToInt32(dv[0][yc]); DoubleFork = Convert.ToChar(dv[0]["F_UseAwayFork"]); } else { //查找关联自己的主设备指令索引的列坐标 sql = "SELECT " + zc + "," + xc + "," + yc + ",F_UseAwayFork FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { z = Convert.ToInt32(dv[0][zc]); x = Convert.ToInt32(dv[0][xc]); y = Convert.ToInt32(dv[0][yc]); DoubleFork = Convert.ToChar(dv[0]["F_UseAwayFork"]); } } if ((z == 0) && (x == 0) && (y == 0)) { return false; } else { sql = "SELECT " + zc + "," + xc + "," + yc + ",F_UseAwayFork FROM T_Monitor_Task Where ( F_ManageTASKKINDINDEX = " + mankind + ") AND (F_ManageTaskIndex = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { z1 = Convert.ToInt32(dv[0][zc]); x1 = Convert.ToInt32(dv[0][xc]); y1 = Convert.ToInt32(dv[0][yc]); DoubleFork1 = Convert.ToChar(dv[0]["F_UseAwayFork"]); if (((x1 > x) && (DoubleFork1 > DoubleFork)) || ((x > x1) && (DoubleFork > DoubleFork1))) { return true; } else { return false; } } else { return false; } } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 查找双叉关联任务的T_Base_AGV_Gate表的货叉属性是否匹配 /// /// 任务类型 /// 调度任务索引 /// 设备索引 /// 设备指令 /// public static bool EqualAGVGateDoubleFork(int mankind, int fid, int devIdx, int devOrder) { DataView dv; string xc = "F_NumParam2"; if (GetDeviceKindIdx(devIdx) == 6) { if (devOrder == 1) { xc = "F_NumParam2"; } else if (devOrder == 2) { xc = "F_NumParam5"; } else if (devOrder == 4) { xc = "F_NumParam5"; } } try { int x = 0, x1 = 0; int channelleft = 0, channelleft1 = 0, xd = 0, xd1 = 0; //查找被关联辅助设备指令索引的列坐标 string sql = "SELECT " + xc + " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { xd = Convert.ToInt32(dv[0][xc]); dv = dbo.ExceSQL("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = "+xd+")").Tables[0].DefaultView; if (dv.Count > 0) { x = Convert.ToInt32(dv[0]["F_Sequence"]); } else { x = 0; } } else { //查找关联自己的主设备指令索引的列坐标 sql = "SELECT " + xc + " FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { xd = Convert.ToInt32(dv[0][xc]); dv = dbo.ExceSQL("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = " + xd + ")").Tables[0].DefaultView; if (dv.Count > 0) { x = Convert.ToInt32(dv[0]["F_Sequence"]); } else { x = 0; } } } if (x == 0) { return false; } else { sql = "SELECT " + xc + " FROM T_Monitor_Task Where ( F_ManageTASKKINDINDEX = " + mankind + ") AND (F_ManageTaskIndex = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { xd1 = Convert.ToInt32(dv[0][xc]); dv = dbo.ExceSQL("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = " + xd1 + ")").Tables[0].DefaultView; if (dv.Count > 0) { x1 = Convert.ToInt32(dv[0]["F_Sequence"]); } else { x1 = 0; } int DoubleFork = 0, DoubleFork1 = 0; dv = dbo.ExceSQL("SELECT F_UseAwayFork,F_IfChannelLeft FROM T_Base_AGV_Gate WHERE F_AGVGateDeviceIndex =" + xd).Tables[0].DefaultView; if (dv.Count > 0) { DoubleFork = Convert.ToInt32(dv[0]["F_UseAwayFork"]); channelleft = Convert.ToInt32(dv[0]["F_IfChannelLeft"]); } else { return false; } dv = dbo.ExceSQL("SELECT F_UseAwayFork,F_IfChannelLeft FROM T_Base_AGV_Gate WHERE F_AGVGateDeviceIndex =" + xd1).Tables[0].DefaultView; if (dv.Count > 0) { DoubleFork1 = Convert.ToInt32(dv[0]["F_UseAwayFork"]); channelleft1 = Convert.ToInt32(dv[0]["F_IfChannelLeft"]); } else { return false; } if ((((x1 > x) && (DoubleFork1 > DoubleFork)) || ((x > x1) && (DoubleFork > DoubleFork1))) && (channelleft == channelleft1)) { return true; } else { return false; } } else { return false; } } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 在设备指令队列表获取Z 排坐标 /// /// 设备指令索引 /// public static int GetZCoorFromMonitor(int monitorIndex, int devIdx, int devOrder) { DataView dv; string zc = "F_NumParam1"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 2 || devOrder == 4) { zc = "F_NumParam1"; } else if (devOrder == 3 || devOrder == 5) { zc = "F_NumParam4"; } } try { dv = dbo.ExceSQL("SELECT "+zc+" FROM T_Monitor_Task WHERE (F_MonitorIndex = " + monitorIndex + ")").Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 在设备指令队列表获取X 列坐标 /// /// 设备指令索引 /// public static int GetXCoorFromMonitor(int monitorIndex, int devIdx, int devOrder) { DataView dv; string xc = "F_NumParam2"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 4) { xc = "F_NumParam2"; } else if (devOrder == 5) { xc = "F_NumParam5"; } } try { dv = dbo.ExceSQL("SELECT "+xc+" FROM T_Monitor_Task WHERE (F_MonitorIndex = " + monitorIndex + ")").Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 在设备指令队列表获取Y 层坐标 /// /// 设备指令索引 /// public static int GetYCoorFromMonitor(int monitorIndex, int devIdx, int devOrder) { DataView dv; string yc = "F_NumParam3"; if (GetDeviceKindIdx(devIdx) == 1) { if (devOrder == 4) { yc = "F_NumParam3"; } else if (devOrder == 5) { yc = "F_NumParam6"; } } try { dv = dbo.ExceSQL("SELECT "+yc+" FROM T_Monitor_Task WHERE (F_MonitorIndex = " + monitorIndex + ")").Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0][0]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 返回双叉关联设备指令信息:【0】设备指令索引【1】提前检测【2】设备索引【3】路径 /// /// 设备指令索引 /// 设备索引 /// public static string[] GetDoubleForkMonitorInfo(int monitorIndex, int devIdx) { DataView dv; string[] rr = null; try { int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex); int fid = GetManageTaskIndexfromMonitor(monitorIndex); int devOrder = GetDeviceOrderFromMonitor(monitorIndex); //查找被关联辅助设备指令索引的列坐标 string sql = "SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { rr = new string[4]; rr[0] = dv[0]["F_MonitorIndex"].ToString(); rr[1] = dv[0]["F_AheadDetect"].ToString(); rr[2] = dv[0]["F_DeviceIndex"].ToString(); rr[3] = dv[0]["F_RouteID"].ToString(); } else { //查找关联自己的主设备指令索引的列坐标 sql = "SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and F_DeviceCommandIndex=" + devOrder + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { rr = new string[4]; rr[0] = dv[0]["F_MonitorIndex"].ToString(); rr[1] = dv[0]["F_AheadDetect"].ToString(); rr[2] = dv[0]["F_DeviceIndex"].ToString(); rr[3] = dv[0]["F_RouteID"].ToString(); } else { return null; } } return rr; } catch (Exception ex) { throw ex; } finally { dv = null; rr = null; } } /// /// 是否有任务状态大于0的双叉关联任务的存在 /// /// /// /// public static bool GetDoubleForkMonitorInfo(int monitorIndex, int devIdx,int status) { DataView dv; try { int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex); int fid = GetManageTaskIndexfromMonitor(monitorIndex); //查找被关联辅助设备指令索引的列坐标 string sql = "SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.F_RELATIVECONTORLID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and f_status>"+status+")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { //查找关联自己的主设备指令索引的列坐标 sql = "SELECT F_MonitorIndex,F_AheadDetect,F_DeviceIndex,F_RouteID FROM T_Manage_Task,T_Monitor_Task Where (T_Manage_Task.FID = T_Monitor_Task.F_ManageTaskIndex " + " AND T_Manage_Task.F_ManageTaskKindIndex = T_Monitor_Task.F_ManageTASKKINDINDEX) and ( T_Monitor_Task.F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ") and (F_DeviceIndex=" + devIdx + " and f_status>" + status + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return true; } else { return false; } } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 返回未拆分的双叉关联设备指令,true 代表有未拆分的双叉关联设备指令 /// /// 设备指令索引 /// public static bool GetDoubleForkUnIntoStep(int monitorIndex) { DataView dv; try { int mankind = GetManageTaskKindIndexFromMonitor(monitorIndex); int fid = GetManageTaskIndexfromMonitor(monitorIndex); //查找被关联辅助设备指令索引的列坐标 string sql = "SELECT F_RELATIVECONTORLID FROM T_Manage_Task Where (T_Manage_Task.F_RELATIVECONTORLID <>-1 ) and ( F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + fid + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { sql = "SELECT FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + dv[0][0] + " and FIntoStepOK<>'1')"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return true; } } else { //查找关联自己的主设备指令索引的列坐标 sql = "SELECT FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " + mankind + ") AND (F_RELATIVECONTORLID = " + fid + ")"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { sql = "SELECT FID FROM T_Manage_Task Where ( F_ManageTaskKindIndex = " + mankind + ") AND (FID = " + dv[0][0] + " and FIntoStepOK<>'1')"; dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return true; } } } return false; } catch (Exception ex) { throw ex; } finally { dv = null; } } public static int GetManageTaskIndexfromMonitor(int monitorIdx) { //20100108 DataView dv; try { //20100108 dv = dbo.ExceSQL("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " + monitorIdx + ")").Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_ManageTaskIndex"]); } else { return -1; } } catch (Exception ex) {//20100108 throw ex; } finally {//20100108 dv = null; } } public static int GetManageTaskKindIndexFromMonitor(int monitorIdx) {//20100108 DataView dv; try { //20100108 dv = dbo.ExceSQL("SELECT F_ManageTaskKindIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " + monitorIdx + ")").Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_ManageTaskKindIndex"]); } else { return -1; } } catch (Exception ex) {//20100108 throw ex; } finally {//20100108 dv = null; } } /// /// 在调度队列中找到设备命令 /// /// 调度所引 /// public static int GetDeviceOrderFromMonitor(int MonitorIndex) { //20100108 DataView dv; try { string sql = "select F_DeviceCommandIndex from T_Monitor_Task where (F_DeviceCommandIndex IS NOT NULL) and F_MonitorIndex=" + MonitorIndex; //20100108 dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } public static int GetDeviceKindIdx(int devIdx) { try { devinfo = Model.CGetInfo.GetDeviceInfo(devIdx); return devinfo.DeviceKind; } catch (Exception ex) { throw ex; } } public static int GetDeviceIndexFromMonitor(int MonitorIndex) { //20100108 DataView dv; try { string sql = "select F_DeviceIndex from T_Monitor_Task where (F_DeviceIndex IS NOT NULL) and F_MonitorIndex=" + MonitorIndex; //20100108 dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv.Count > 0) { return Convert.ToInt32(dv[0]["F_DeviceIndex"]); } else { return -1; } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 获得表型层数 /// /// /// public static void GetBoxTypeAndQUANTITYFromMonitor(int MonitorIndex, out int boxtype, out int QUANTITY) { //20100108 DataView dv; //NUMParam5 表示表箱层数 boxtype = 0; QUANTITY = 0; try { string sql = "select F_NumParam5 ,F_NumParam6 from T_Monitor_Task where (F_NumParam5 IS NOT NULL) and (F_NumParam6 IS NOT NULL)and F_MonitorIndex=" + MonitorIndex; //20100108 dv = dbo.ExceSQL(sql).Tables[0].DefaultView; if (dv[0]["F_NumParam5"] != DBNull.Value) { boxtype = Convert.ToInt32(dv[0]["F_NumParam5"]); } if (dv[0]["F_NumParam6"] != DBNull.Value) { QUANTITY = Convert.ToInt32(dv[0]["F_NumParam6"]); } } catch (Exception ex) { throw ex; } finally { dv = null; } } /// /// 双叉堆垛机在一个输送机取送盘时需要额外检测的探物开关(隔壁输送机是否有探物) /// /// /// public static int GetDoubleForkDetect(int devinx) { try { devinfo = Model.CGetInfo.GetDeviceInfo(devinx); return Convert.ToInt32(devinfo.DoubleForkDetect); } catch (Exception ex) { throw ex ; } finally { devinfo = null; } } public static void ActionComplete(int DeviceIdx, int TaskIdx, int ClearZero) { int devKind = GetDeviceKindIdx(DeviceIdx); int order = GetDeviceOrderFromMonitor(TaskIdx); int fid = GetManageTaskIndexfromMonitor(TaskIdx); int mti = GetManageTaskKindIndexFromMonitor(TaskIdx); string cap; int errrcode = GetExceptionNOFromManageTask(fid, mti); DataView dv;//20100127 //dbo.TransBegin(); try { //20100127 dv = dbo.ExceSQL("select count(F_MonitorIndex) as counts from T_Monitor_Task " + " where F_ManageTaskIndex =" + fid + " and F_ManageTaskKindIndex= " + mti).Tables[0].DefaultView; if (dv.Count > 0) { if ((Convert.ToInt32(dv[0]["counts"]) == 1) ) { //固定路径模式 //调度任务的fid的最后一个监控分解任务完成 if (mti == 1) { cap = "调度任务"; //完成FSTATUS=999;970堆垛机送货重故障异常完成;980堆垛机取空故障异常完成;990条码扫描异常完成;调度撤销删除调度任务900 if (errrcode > 900)//异常完成 { dboM.ExceSQL("update IO_Control set Control_STATUS=" + errrcode + " where Control_ID=" + fid); } else { if (ClearZero == Model.CGeneralFunction.TASKDELETE)//调度撤销删除调度任务900 { dboM.ExceSQL("update IO_Control set Control_STATUS=" + Model.CGeneralFunction.TASKDELETE + " where Control_ID=" + fid); } else//完成FSTATUS=999 { dboM.ExceSQL("update IO_Control set Control_STATUS=" + Model.CGeneralFunction.TASKFINISH + " where Control_ID=" + fid); } } } else if (mti == 4) { cap = "手工任务"; } else { cap = "临时任务"; } //回写管理表 if (ClearZero == Model.CGeneralFunction.TASKDELETE)//调度撤销删除调度任务900 { ReturnManageInfo(fid, mti, cap, false); } else { ReturnManageInfo(fid, mti, cap, true); } } } //被这个任务号锁定的设备全部解锁 dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_LockedState=" + TaskIdx); //dbo.ExceSQL("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=" + DeviceIdx); dbo.ExceSQL("update T_Base_Device set F_CreateLock='0' where F_DeviceIndex=" + DeviceIdx); if (ClearZero == 1) { if (mti == 1) { dboM.ExceSQL("UPDATE IO_CONTROL SET ERROR_TEXT ='' WHERE Control_ID=" + fid + " and Control_STATUS<900"); } } dbo.ExceSQL("delete from T_Monitor_Task where F_MonitorIndex=" + TaskIdx); } catch (Exception ex) { throw ex; } finally {//20100127 dv = null; } } public static int GetExceptionNOFromManageTask(int FID, int ManTaskKind) { //20100127 DataTable dt; try { string sql = "SELECT FID, F_ManageTaskKindIndex, FExceptionNO FROM T_Manage_Task WHERE (FID = " + FID + ") AND (F_ManageTaskKindIndex = " + ManTaskKind + ") "; //20100127 dt = dbo.ExceSQL(sql).Tables[0]; if (dt.Rows.Count > 0) { if (dt.Rows[0]["FExceptionNO"] == DBNull.Value) { return -1; } else { return Convert.ToInt32(dt.Rows[0]["FExceptionNO"]); } } else { return -1; } } catch (Exception ex) {//20100127 throw ex; } finally {//20100127 dt = null; } } static void ReturnManageInfo(int fid, int mti, string cap, bool IFOK) { //20100127 DataView dv; try { //200906240111增加货位记录:入库1-结束位置有货;出库2-起始位置无货;倒库3-起始位置无货,结束位置有货 //20100127 dv = dbo.ExceSQL("SELECT FID, F_ManageTaskKindIndex,FCONTROLTASKTYPE, FSTARTDEVICE,FSTARTCELL, FENDDEVICE,FENDCELL FROM T_Manage_Task where F_ManageTaskKindIndex=" + mti + " and FID=" + fid + "").Tables[0].DefaultView; if (dv.Count > 0) { switch (dv[0]["FCONTROLTASKTYPE"].ToString()) { case "1": dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS = 1 WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and FCELLCODE = '" + dv[0]["FENDCELL"] + "')"); break; case "2": dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS =0 WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and FCELLCODE = '" + dv[0]["FSTARTCELL"] + "')"); break; case "3": dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS = 1 WHERE (FLaneWay=" + dv[0]["FENDDEVICE"] + " and FCELLCODE = '" + dv[0]["FENDCELL"] + "')"); dbo.ExceSQL("UPDATE ST_CELL SET FCELLSTATUS =0 WHERE (FLaneWay=" + dv[0]["FSTARTDEVICE"] + " and FCELLCODE = '" + dv[0]["FSTARTCELL"] + "')"); break; default: break; } } //////////////////// //dbo.ExceSQL("update T_Manage_Task set FSTATUS='2' where FID=" + fid + " and F_ManageTaskKindIndex= " + mti); dbo.ExceSQL("delete from T_Manage_Task where FID=" + fid + " and F_ManageTaskKindIndex= " + mti); } catch (Exception ex) {//20100127 throw ex; } finally {//20100127 dv = null; } } #region 与管理任务交互的调度任务状态 /// /// 任务等待,默认0 /// public static readonly int TASKWAIT = CGetInfo.GetIOControlStatus("TASKWAIT").StatusID; /// /// 任务开始运行,默认10 /// public static readonly int TASKRUN = CGetInfo.GetIOControlStatus("TASKRUN").StatusID; /// /// 调度申请改道,默认30 /// public static readonly int TASKALTERROUTEAPPLY = CGetInfo.GetIOControlStatus("TASKALTERROUTEAPPLY").StatusID; /// /// 管理答复改道申请,默认40 /// public static readonly int TASKALTERROUTEREPLY = CGetInfo.GetIOControlStatus("TASKALTERROUTEREPLY").StatusID; /// /// 管理任务被调度删除,默认900 /// public static readonly int TASKDELETE = CGetInfo.GetIOControlStatus("TASKDELETE").StatusID; /// /// 人工暂停出库,默认940 /// public static readonly int TASKSTOPOUTPUT = CGetInfo.GetIOControlStatus("TASKSTOPOUTPUT").StatusID; /// /// 三层拆盘任务完成,默认950 /// public static readonly int TASKUNPACKFINISH = CGetInfo.GetIOControlStatus("TASKUNPACKFINISH").StatusID; /// /// 任务类型错,送到拆盘机的不是空托盘组,默认955 /// public static readonly int TASKTYPEERROR = CGetInfo.GetIOControlStatus("TASKTYPEERROR").StatusID; /// /// 配送出库到叠盘输送机,默认960 /// public static readonly int TASKPACKFINISH = CGetInfo.GetIOControlStatus("TASKPACKFINISH").StatusID; /// /// 任务被取消,搬运到异常出库站台,默认966 /// public static readonly int TASKCANCEL = CGetInfo.GetIOControlStatus("TASKCANCEL").StatusID; /// /// 堆垛机的送货重需要改路径处理,默认970 /// public static readonly int TASKREPEATINPUT = CGetInfo.GetIOControlStatus("TASKREPEATINPUT").StatusID; /// /// 堆垛机的取空处理,调度取消执行管理任务,默认980 /// public static readonly int TASKEMPTYOUTPUT = CGetInfo.GetIOControlStatus("TASKEMPTYOUTPUT").StatusID; /// /// 任务异常完成,默认990 /// public static readonly int TASKABEND = CGetInfo.GetIOControlStatus("TASKABEND").StatusID; /// /// 任务搬运完成,默认999 /// public static readonly int TASKFINISH = CGetInfo.GetIOControlStatus("TASKFINISH").StatusID; /// /// 入库任务RFID比对错误,默认值930 /// public static readonly int TASKINPUTRFIDERROR = CGetInfo.GetIOControlStatus("TASKINPUTRFIDERROR").StatusID; /// /// 20100617管理任务对出库托盘确认接收,默认值50 /// public static readonly int TASKOUTCONFIRM = CGetInfo.GetIOControlStatus("TASKOUTCONFIRM").StatusID; /// /// 20101011双叉极限货位需要更换货叉,默认值800 /// public static readonly int TASKCHANGEFORK = CGetInfo.GetIOControlStatus("TASKCHANGEFORK").StatusID; /// /// 20101011调度已经获取任务,默认值7 /// public static readonly int TASKCONTROLREADED = CGetInfo.GetIOControlStatus("TASKCONTROLREADED").StatusID; /// /// 20101028堆垛机单叉入库任务立即执行:默认值,25 /// public static readonly int TASKSINGLEFORKRUN = CGetInfo.GetIOControlStatus("TASKSINGLEFORKRUN").StatusID; #endregion #region 堆垛机取空和送重的故障码 /// /// 堆垛机的送重故障码,默认48(双叉中的近叉) /// public static readonly int STACKREPEATINPUT =CGetInfo.GetIOControlStatus("STACKREPEATINPUT").StatusID; /// /// 堆垛机的取空故障码,默认49(双叉中的近叉) /// public static readonly int STACKEMPTYOUTPUT =CGetInfo.GetIOControlStatus("STACKEMPTYOUTPUT").StatusID; /// /// 堆垛机的送重故障码,默认60(双叉中的远叉) /// public static readonly int STACKREPEATINPUTAWAY = CGetInfo.GetIOControlStatus("STACKREPEATINPUTAWAY").StatusID; /// /// 堆垛机的取空故障码,默认62(双叉中的远叉) /// public static readonly int STACKEMPTYOUTPUTAWAY = CGetInfo.GetIOControlStatus("STACKEMPTYOUTPUTAWAY").StatusID; /// /// 堆垛机的送重故障码,默认61(双叉) /// public static readonly int STACKREPEATINPUTDOUBLE = CGetInfo.GetIOControlStatus("STACKREPEATINPUTDOUBLE").StatusID; /// /// 堆垛机的取空故障码,默认63(双叉) /// public static readonly int STACKEMPTYOUTPUTDOUBLE = CGetInfo.GetIOControlStatus("STACKEMPTYOUTPUTDOUBLE").StatusID; #endregion } }