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.
3516 lines
145 KiB
3516 lines
145 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using DBFactory;
|
|
using CommLayerFactory;
|
|
using ICommLayer;
|
|
using CommonLib;
|
|
using System.Text.RegularExpressions;
|
|
namespace WcfControlMonitorLib
|
|
{
|
|
/// <summary>
|
|
/// Creator:Richard.liu
|
|
/// 通用函数类库
|
|
/// </summary>
|
|
public class CCommonFunction
|
|
{
|
|
//object lockob = new object();
|
|
string _DisassembleTaskError;
|
|
public string DisassembleTaskError
|
|
{
|
|
get { return _DisassembleTaskError; }
|
|
set { _DisassembleTaskError = value; }
|
|
}
|
|
DBOperator dboM = CStaticClass.dboM;
|
|
DBOperator dbo = CStaticClass.dbo;
|
|
Model.MDevice devinfo;
|
|
StringBuilder sql = new StringBuilder();
|
|
public static event CDataSourceChangeEventHandler DataChange;
|
|
public static void OnDataChange(object sender,CDataChangeEventArgs e)
|
|
{
|
|
if (DataChange != null)
|
|
{
|
|
DataChange(sender, e);
|
|
}
|
|
}
|
|
public static event RefreshMonitorEventHandler RefreshMonitor;
|
|
public static void OnRefreshMonitor(object sender, RefreshMonitorEventArgs e)
|
|
{
|
|
if (RefreshMonitor != null)
|
|
{
|
|
RefreshMonitor(e);
|
|
}
|
|
}
|
|
public CCommonFunction()
|
|
{
|
|
|
|
}
|
|
#region 拆分设备指令
|
|
|
|
/// <summary>
|
|
/// 获得绑定在主设备的探物光电设备索引
|
|
/// </summary>
|
|
/// <param name="devinx">主设备索引</param>
|
|
/// <returns></returns>
|
|
public string GetBindingDeviceIndex(int devinx)
|
|
{
|
|
//20101118
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(devinx);
|
|
if (devinfo.BindingDevice == null) return "";
|
|
return devinfo.BindingDevice;
|
|
}
|
|
/// <summary>
|
|
/// 获得输送机设备的出库口探物光电的设备索引值
|
|
/// </summary>
|
|
/// <param name="devinx">设备索引</param>
|
|
/// <returns></returns>
|
|
public string GetBindingDeviceIndexOut(int devinx)
|
|
{
|
|
//20101118
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(devinx);
|
|
if (devinfo.BindingDeviceOut == null) return "";
|
|
return devinfo.BindingDeviceOut;
|
|
}
|
|
/// <summary>
|
|
/// 发送设备的送出指令时,需要检测的光电开关设备索引
|
|
/// </summary>
|
|
/// <param name="devinx">输送设备索引</param>
|
|
/// <returns></returns>
|
|
public string GetSendOutDetect(int devinx)
|
|
{
|
|
//20101118
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(devinx);
|
|
if (devinfo.SendOutDetect==null) return "";
|
|
return devinfo.SendOutDetect;
|
|
|
|
}
|
|
public string GetBeDetectedDevices(int devinx)
|
|
{
|
|
devinfo= Model.CGetInfo.GetDeviceInfo(devinx);
|
|
return devinfo.BeDetected;
|
|
//string sql = "SELECT F_BeDetected FROM T_Base_Device WHERE (F_DeviceIndex = " + devinx + ") and F_BeDetected is not null";
|
|
//DataView db = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
|
//if (db.Count > 0)
|
|
//{
|
|
// return db[0]["F_BeDetected"].ToString();
|
|
//}
|
|
//else
|
|
// return "";
|
|
}
|
|
/// <summary>
|
|
/// //获得指定调度任务的设备指令索引
|
|
/// </summary>
|
|
/// <param name="managerTaskIndex"></param>
|
|
/// <param name="managerTaskKindIndex"></param>
|
|
/// <returns>设备指令索引值1--10000</returns>
|
|
public int GetMonitorIndex(int managerTaskIndex, int managerTaskKindIndex)
|
|
{//20110104
|
|
|
|
DataView dvMt = new DataView();
|
|
try
|
|
{
|
|
int maxIdx = 0;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Base_Monitor_Task_Index");
|
|
//20100108
|
|
dvMt = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
|
|
if (dvMt.Count > 0 && dvMt[0]["F_MonitorIndex"] != DBNull.Value)
|
|
{
|
|
|
|
maxIdx = (Convert.ToInt32(dvMt[0]["F_MonitorIndex"]) + 1);
|
|
|
|
if (maxIdx >= 29999)//预留999个给接近上限的拆分任务(29000)//20120328
|
|
{
|
|
//maxIdx = 1;
|
|
maxIdx = 1000;//LHDF
|
|
|
|
}
|
|
|
|
}
|
|
else//现在没有该管理的设备指令记录
|
|
{
|
|
//maxIdx = 1;
|
|
maxIdx = 1000;//LHDF
|
|
}
|
|
|
|
//判断调度任务表是否有重复值
|
|
if (IFExitMonitorIndex(maxIdx) == true)
|
|
{
|
|
UpdateMonitorIndex(maxIdx);
|
|
maxIdx = GetMonitorIndex(managerTaskIndex, managerTaskKindIndex);
|
|
|
|
}
|
|
|
|
UpdateMonitorIndex(maxIdx);
|
|
return maxIdx;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_DisassembleTaskError = "获得指定调度任务的设备指令索引失败!" + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dvMt.Dispose();
|
|
}
|
|
|
|
}
|
|
public void UpdateMonitorIndex(int MonitorIndex)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_Monitor_Task_Index set F_MonitorIndex=").Append( MonitorIndex);
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
|
|
|
|
public string GetStackCoordinateFromLaneGate(int Laneway, int device)
|
|
{
|
|
DataView dv =new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ZXY FROM T_Base_Lane_Gate WHERE (F_LaneGateDeviceIndex = ").Append(device).Append(") AND (F_LaneIndex = ").Append(Laneway).Append(")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0][0].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 20110510判断设备是否是路径起始设备
|
|
/// </summary>
|
|
/// <param name="deviceidx"></param>
|
|
/// <returns></returns>
|
|
public bool IfRouteStartDevice(int deviceidx)
|
|
{
|
|
object ob = dbo.GetSingle(string.Format("SELECT F_RouteID FROM T_Base_Route WHERE (F_StartDevice = {0})",deviceidx));
|
|
if (ob != null)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 使用正则表达式验证字符串
|
|
/// </summary>
|
|
/// <param name="strCode">待验证字符串</param>
|
|
/// <returns>合法返回true,否则返回false</returns>
|
|
public bool GetCodeCheck(string strCode)
|
|
{
|
|
Match mCode = Regex.Match(strCode, CStaticClass.StockCodeCheck);
|
|
if (mCode.Success)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获得搬运路径类型
|
|
/// </summary>
|
|
/// <param name="FCONTROLTASKTYPE">调度任务下发的搬运任务类型</param>
|
|
/// <returns></returns>
|
|
public string GetIOType(string FCONTROLTASKTYPE)
|
|
{
|
|
//20100108
|
|
DataSet ds = new DataSet();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FCODE, FINTERCODE FROM T_ITEMTASKTYPE where FCODE='" ).Append( FCONTROLTASKTYPE ).Append( "'");
|
|
ds = dbo.ExceSQL(sql.ToString());
|
|
if (ds.Tables[0].DefaultView.Count > 0)
|
|
{
|
|
return ds.Tables[0].DefaultView[0]["FINTERCODE"].ToString();
|
|
}
|
|
else
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
ds.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查看用户指定的任务优先级原则:0,按照调度任务优先级;1,入库优先,携带符合执行条件的出库任务;
|
|
/// 2,出库优先,携带符合执行条件的入库任务;3,单纯入库优先,执行完所有入库任务后再执行出库任务;
|
|
/// 4,单纯出库优先,执行完所有出库任务后再执行入库任务。
|
|
/// </summary>
|
|
/// <returns>优先级索引值0--4</returns>
|
|
public int SelectTaskPriPrecept()
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_PRINo , F_PRIName , F_IfChecked FROM T_Base_PRI WHERE (F_IfChecked = '1')");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_PRINo"]);
|
|
}
|
|
else
|
|
{
|
|
return 0;//默认值0:按照调度任务优先级
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
|
|
public int GetLaneWayFromLaneInfo(int stackIndex)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(stackIndex);
|
|
if (devinfo.VirtualStack > 0) stackIndex = devinfo.VirtualStack;
|
|
|
|
sql.Append("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = ").Append(stackIndex).Append(")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 判断调度任务号在队列中是否存在,true已经存在;false不存在
|
|
/// </summary>
|
|
/// <param name="Monitorindex"></param>
|
|
/// <returns></returns>
|
|
public bool IFExitMonitorIndex(int Monitorindex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( Monitorindex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public bool IFExitTempManageIndex(int fid)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT fid FROM T_Manage_Task WHERE ( fid = ").Append(fid).Append(")"); //F_ManageTaskKindIndex=2 and //LHDF
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
#region 控制设备(发送命令)
|
|
|
|
/// <summary>
|
|
/// 根据前面得到的F_MonitorIndex值获得被锁定的设备索引
|
|
/// </summary>
|
|
/// <returns>以“;”隔开的设备索引组字符串</returns>
|
|
public string GetLockedDeviceIndex(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataSet ds = new DataSet();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_RunningLock from T_Monitor_Task where F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
ds = dbo.ExceSQL(sql.ToString());
|
|
if (ds.Tables[0].DefaultView.Count > 0)
|
|
{
|
|
return ds.Tables[0].DefaultView[0]["F_RunningLock"].ToString();
|
|
}
|
|
else
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
ds.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据前面得到的MonitorIndex值取得"关联设备索引-命令"
|
|
/// </summary>
|
|
/// <returns>关联设备索引-命令,null表示没有</returns>
|
|
public string GetAssociateDevice(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
DataView dvv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_Associate from T_Monitor_Task where (F_Associate IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceIndex,F_DeviceCommandIndex from T_Monitor_Task where F_MonitorIndex=").Append( dv[0]["F_Associate"]);
|
|
|
|
dvv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvv.Count > 0)
|
|
{
|
|
return dvv[0]["F_DeviceIndex"].ToString() + "-" + dvv[0]["F_DeviceCommandIndex"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
dvv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据前面得到的MonitorIndex值取得"关联调度任务"
|
|
/// </summary>
|
|
/// <returns>关联调度任务索引,0表示没有</returns>
|
|
public int GetAssociateMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
DataView dvv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_Associate from T_Monitor_Task where (F_Associate IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
//20100108
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_MonitorIndex from T_Monitor_Task where F_MonitorIndex=" ).Append( dv[0]["F_Associate"]);
|
|
|
|
|
|
//20100108
|
|
dvv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dvv[0]["F_MonitorIndex"].ToString());
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
//20100108
|
|
dv.Dispose();
|
|
dvv.Dispose();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据前面得到的关联调度任务值取得"调度任务索引"
|
|
/// </summary>
|
|
/// <returns>调度任务索引,0表示没有</returns>
|
|
public int GetMonitorFromAssociate(int AssociateMonitor)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_MonitorIndex from T_Monitor_Task where F_Associate=" ).Append( AssociateMonitor);
|
|
|
|
//20100108
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
|
|
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 在设备指令信息中获得堆垛机的
|
|
/// 取货点Z坐标(站在堆垛机上,面向操作面板:左侧-1,右侧-2)
|
|
/// 取货点X坐标(沿轨道方向)
|
|
/// 取货点Y坐标(沿高度方向)
|
|
/// 送货点Z坐标(站在堆垛机上,面向操作面板:左侧-1,右侧-2)
|
|
/// 送货点X坐标(沿轨道方向)
|
|
/// 送货点Y坐标(沿高度方向)
|
|
/// </summary>
|
|
/// <param name="TaskIdx">设备指令索引</param>
|
|
/// <returns>0--5六个数组分别依次代表6个坐标</returns>
|
|
public int[] GetCoordinatesFromMonitorTask(int TaskIdx)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
int[] gc;
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 from T_Monitor_Task where F_MonitorIndex=" ).Append( TaskIdx);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
gc = new int[6];
|
|
|
|
|
|
//F_NumParam1--z,x--2,y--3;F_NumParam4--z,5--x,6--y
|
|
if (dv.Count > 0)
|
|
{
|
|
gc[0] = Convert.ToInt32(dv[0]["F_NumParam1"]);
|
|
gc[1] = Convert.ToInt32(dv[0]["F_NumParam2"]);
|
|
gc[2] = Convert.ToInt32(dv[0]["F_NumParam3"]);
|
|
gc[3] = Convert.ToInt32(dv[0]["F_NumParam4"]);
|
|
gc[4] = Convert.ToInt32(dv[0]["F_NumParam5"]);
|
|
gc[5] = Convert.ToInt32(dv[0]["F_NumParam6"]);
|
|
return gc;
|
|
}
|
|
return null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
gc = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获得设备类型索引
|
|
/// </summary>
|
|
/// <param name="devIdx">设备索引</param>
|
|
/// <returns>设备类型索引</returns>
|
|
public int GetDeviceKindIdx(int devIdx)
|
|
{
|
|
try
|
|
{
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(devIdx);
|
|
if (devinfo == null) return -1;
|
|
return devinfo.DeviceKind;
|
|
//string strSql = "SELECT F_DeviceIndex, F_DeviceKindIndex FROM T_Base_Device WHERE F_DeviceIndex=" + devIdx;
|
|
//DataSet ds = dbo.ExceSQL(strSql);
|
|
//DataView dv = ds.Tables[0].DefaultView;
|
|
//if (dv.Count > 0)
|
|
//{
|
|
// return Convert.ToInt32(dv[0]["F_DeviceKindIndex"]);
|
|
//}
|
|
//else
|
|
// return 0;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在调度队列中找到设备命令
|
|
/// </summary>
|
|
/// <param name="MonitorIndex">调度所引</param>
|
|
/// <returns></returns>
|
|
public int GetDeviceOrderFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceCommandIndex from T_Monitor_Task where (F_DeviceCommandIndex IS NOT NULL) and F_MonitorIndex=" ).Append( MonitorIndex);
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetDeviceindexFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_DeviceIndex from T_Monitor_Task where (F_DeviceIndex IS NOT NULL) and F_MonitorIndex=").Append(MonitorIndex);
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_DeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetDeviceArrowFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_NumParam4 from T_Monitor_Task where (F_NumParam4 IS NOT NULL) and F_MonitorIndex=").Append(MonitorIndex);
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_NumParam4"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetDeviceStartFromMonitor(int MonitorIndex)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select F_NumParam1 from T_Monitor_Task where (F_NumParam1 IS NOT NULL) and F_MonitorIndex=").Append(MonitorIndex);
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_NumParam1"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 成功发送命令后的处理信息
|
|
/// </summary>
|
|
/// <param name="taskKindIndex">调度任务类型</param>
|
|
/// <param name="Managefid">调度任务索引</param>
|
|
/// <param name="MonirotIdx">设备指令索引</param>
|
|
/// <param name="deviceidx">设备索引</param>
|
|
/// <param name="detailidx">详细路径步骤索引</param>
|
|
public void SendOrderSuccess(int taskKindIndex, int Managefid, int MonirotIdx, int deviceidx, int detailidx)
|
|
{
|
|
string AssociateDevice = "";//关联设备
|
|
string LockedDeviceIndex = "";//被锁定的设备索引组,以“;”分隔
|
|
char[] sep = new char[1];
|
|
string[] split;
|
|
DataView dvs = new DataView();
|
|
try
|
|
{
|
|
int devKind = GetDeviceKindIdx(deviceidx);
|
|
int order = GetDeviceOrderFromMonitor(MonirotIdx);
|
|
if (order < 0) return;
|
|
|
|
//8:更改作业记录的状态F_Status为1,更改设备为占用状态(T_Base_device的F_LockedState=设备指令单)
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_ErrorCode='',F_StartTime='").Append(DateTime.Now.ToString("u")).Append("',F_Status=1,F_SendCount=F_SendCount+1 where F_Status=0 and F_MonitorIndex=").Append(MonirotIdx);
|
|
dbo.ExceSQL(sql.ToString());
|
|
if (taskKindIndex != 4)//20100610
|
|
{
|
|
//AGV,积放或者长输送机链组,条码扫描不需要锁定设备//20111226
|
|
if (devKind == 1 || devKind == 4 )
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_device set F_LockedState=").Append(MonirotIdx).Append(
|
|
" where F_DeviceIndex=").Append(deviceidx);
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
else
|
|
{
|
|
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_AgvNo FROM T_Monitor_Task WHERE (F_AgvNo IS NOT NULL) AND (F_MonitorIndex = " ).Append( MonirotIdx ).Append( ")");
|
|
dvs = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if ((dvs.Count > 0) && (devKind == 6))
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_device set F_LockedState=" ).Append( MonirotIdx).Append(
|
|
" where F_DeviceIndex=" ).Append( dvs[0][0]);
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
if (devKind == 1)
|
|
{
|
|
//修改T_Manage_Task的FLANEWAY,FSTACK
|
|
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneDeviceIndex,F_StackIndex FROM T_Base_LaneInfo where F_StackIndex=").Append( deviceidx);
|
|
dvs = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
int laneway = 0;
|
|
if (dvs.Count > 0)
|
|
{
|
|
laneway = Convert.ToInt32(dvs[0]["F_LaneDeviceIndex"]);
|
|
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Manage_Task set FLANEWAY=" ).Append( laneway).Append( ",FSTACK=" ).Append( deviceidx ).Append( " where F_ManageTaskKindIndex=" ).Append( taskKindIndex ).Append( " and FID=" ).Append( Managefid);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
}
|
|
if (taskKindIndex != 4)
|
|
{
|
|
//如果是RGV、堆垛机的将取(运行)命令需要增加调度任务预约锁F_ManTaskReserve && (order == 7)) && ((order == 2) || (order == 4))
|
|
if ((devKind == 4) || (devKind == 1))//20120110
|
|
{////RGV运到到输送机//堆垛机将取
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Base_Device SET F_ManTaskReserve = (" ).Append( taskKindIndex.ToString()).Append(Managefid.ToString() ).Append( ") WHERE (F_DeviceIndex = " ).Append( deviceidx ).Append( ")");
|
|
dbo.ExceSQL(sql.ToString());
|
|
SetStackSendConveyorManReserve(MonirotIdx, deviceidx);
|
|
|
|
}
|
|
}
|
|
//9:给调度任务表回写调度任务IO_Control的正在执行状态FSTATUS=1;T_Manage_Task的正在执行状态FSTATUS=1
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Manage_Task set FSTATUS='1' where F_ManageTaskKindIndex=" ).Append( taskKindIndex ).Append( " and FID=" ).Append( Managefid);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
//10:调度任务表里的F_RunningLock所有对应设备索引加锁,但是F_AssociateDeviceIndex关联设备不加锁
|
|
AssociateDevice = GetAssociateDevice(MonirotIdx);
|
|
if (AssociateDevice == "") AssociateDevice = null;
|
|
if (AssociateDevice != null)
|
|
{
|
|
sep[0] = '-';
|
|
split = AssociateDevice.Split(sep);
|
|
AssociateDevice = split[0];
|
|
}
|
|
|
|
sep[0] = ';';
|
|
LockedDeviceIndex = GetLockedDeviceIndex(MonirotIdx);
|
|
if (LockedDeviceIndex != "")
|
|
{
|
|
split = LockedDeviceIndex.Split(sep);
|
|
for (int m = split.GetLowerBound(0); m <= split.GetUpperBound(0); m++)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_device set F_LockedState=" ).Append( MonirotIdx ).Append(
|
|
" where F_LockedState<>-1 and F_DeviceIndex=").Append(Convert.ToInt32(split[m])).Append("and F_DeviceIndex<>").Append(Convert.ToInt32(AssociateDevice));
|
|
dbo.ExceSQL(sql.ToString());//20141201 增加条件F_LockedState<>-1 张磊发现接货输送机设备被停用时,可能会被堆垛机放货完成把F_LockedState改为0
|
|
}
|
|
}
|
|
CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null);
|
|
OnDataChange("CcommonFuntion.SendOrderSuccess", cea);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", "CcommonFuntion.SendOrderSuccess是发生错误:" + ex.Message);
|
|
OnRefreshMonitor("CcommonFuntion.SendOrderSuccess", rme);
|
|
}
|
|
finally
|
|
{
|
|
sep =null;
|
|
split=null;
|
|
dvs.Dispose() ;
|
|
}
|
|
|
|
|
|
}
|
|
public int GetManageTaskIndexfromMonitor(int monitorIdx)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20100108
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).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.Dispose();
|
|
}
|
|
}
|
|
public int GetManageTaskKindIndexFromMonitor(int monitorIdx)
|
|
{//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_ManageTaskKindIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = " ).Append( monitorIdx ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).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.Dispose();
|
|
|
|
}
|
|
|
|
|
|
}
|
|
public int GetManageIDFromManageTask(int taskKindIndex, int Managefid)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FMANAGEID FROM T_Manage_Task WHERE (FID = " ).Append( Managefid ).Append( ") AND (F_ManageTaskKindIndex = " ).Append( taskKindIndex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["FMANAGEID"] == DBNull.Value) return -1;
|
|
return Convert.ToInt32(dv[0]["FMANAGEID"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
public int GetFCONTROLTASKTYPEFromManageTask(int taskKindIndex, int Managefid)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FCONTROLTASKTYPE FROM T_Manage_Task WHERE (FID = ").Append( Managefid ).Append( ") AND (F_ManageTaskKindIndex = " ).Append( taskKindIndex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["FCONTROLTASKTYPE"] == DBNull.Value) return -1;
|
|
return Convert.ToInt32(dv[0]["FCONTROLTASKTYPE"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
public string GetControlBatchFromManageTask(int taskKindIndex, int Managefid)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FCONTORL_BATCH FROM T_Manage_Task WHERE (FID = ").Append(Managefid).Append(") AND (F_ManageTaskKindIndex = ").Append(taskKindIndex).Append(")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["FCONTORL_BATCH"] == DBNull.Value) return "";
|
|
return dv[0]["FCONTORL_BATCH"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
public int GetRELATIVECONTORLIDFromManageTask(int taskKindIndex, int Managefid)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_RELATIVECONTORLID FROM T_Manage_Task WHERE (FID = ").Append(Managefid).Append(") AND (F_ManageTaskKindIndex = ").Append(taskKindIndex).Append(")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
if (dv[0]["F_RELATIVECONTORLID"] == DBNull.Value) return -1;
|
|
return Convert.ToInt32(dv[0]["F_RELATIVECONTORLID"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否需要优化调度
|
|
/// </summary>
|
|
/// <param name="DeviceIdx"></param>
|
|
/// <returns></returns>
|
|
public bool NeedOptimize(int DeviceIdx)
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_DeviceIndex, F_NeedOptimize FROM T_Base_Device where F_DeviceIndex=" ).Append( DeviceIdx ).Append( " and F_NeedOptimize='1'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据设备指令索引MonitorIndex检索出需要向T_Monitor_Task_Child插入的纪录,并且完成插入工作
|
|
/// </summary>
|
|
/// <param name="MonitorIndex"></param>
|
|
public void InsertMonitorOptimizeChildTask(int MonitorIndex)
|
|
{
|
|
try
|
|
{//20100108
|
|
//起始x坐标,列-沿轨道方向
|
|
// 起始y坐标,层-高度方向
|
|
// 起始z坐标,排-面向堆垛机操作面板,1-左侧,2-右侧
|
|
//F_NumParam1--z,x--2,y--3;F_NumParam4--z,5--x,6--y
|
|
|
|
int[] childInfo = GetMonitorChildIndex(MonitorIndex);
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("INSERT INTO T_Monitor_Task_Child(F_Child_Index, F_TargetX, F_TargetY, F_TargetZ, F_OriginX, F_OriginY, F_OriginZ, F_Order,F_DeviceKindIndex,F_DummyDeviceIndex,F_MonitorIndex, F_Status)" );
|
|
sql.Append("VALUES (" ).Append( childInfo[0] ).Append( "," ).Append( childInfo[2] ).Append( "," ).Append( childInfo[3] ).Append( "," ).Append(childInfo[1] ).Append( "," ).Append( childInfo[5] ).Append( "," ).Append( childInfo[6] ).Append( "," ).Append( childInfo[4] ).Append( "," ).Append( childInfo[7] ).Append( "," ).Append( childInfo[8] ).Append( "," ).Append( childInfo[9] ).Append( "," ).Append( MonitorIndex ).Append(",0,)");
|
|
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// //获得需要优化调度设备指令的子任务索引
|
|
///conInfo[9]=设备索引 ;
|
|
///conInfo[8]=设备种类索引 ;
|
|
///conInfo[7]=命令 ;
|
|
///conInfo[1] = ["F_NumParam1"];
|
|
///conInfo[2] = ["F_NumParam2"];
|
|
///conInfo[3] = ["F_NumParam3"];
|
|
///conInfo[4] = ["F_NumParam4"];
|
|
///conInfo[5] = ["F_NumParam5"];
|
|
///conInfo[6] = ["F_NumParam6"];
|
|
/// </summary>
|
|
/// <param name="monitorTaskIndex"></param>
|
|
/// <returns>子任务索引值1--65535</returns>
|
|
public int[] GetMonitorChildIndex(int monitorTaskIndex)
|
|
{
|
|
//20100108
|
|
DataView dvMt = new DataView();
|
|
int[] conInfo = new int[10];
|
|
DataView dv = new DataView();
|
|
|
|
try
|
|
{
|
|
int devKindIndex;
|
|
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT T_Base_Device.F_DeviceIndex,T_Base_Device.F_DeviceKindIndex,T_Monitor_Task.F_DeviceCommandIndex," ).Append(
|
|
"F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task" ).Append(
|
|
" WHERE (T_Monitor_Task.F_MonitorIndex = " ).Append( monitorTaskIndex ).Append( ") and " ).Append(
|
|
" (T_Monitor_Task.F_DeviceIndex = T_Base_Device.F_DeviceIndex)");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
devKindIndex = Convert.ToInt32(dv[0]["F_DeviceKindIndex"]);
|
|
conInfo[9] = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
|
|
conInfo[8] = devKindIndex;
|
|
conInfo[7] = Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
|
|
conInfo[1] = Convert.ToInt32(dv[0]["F_NumParam1"]);
|
|
conInfo[2] = Convert.ToInt32(dv[0]["F_NumParam2"]);
|
|
conInfo[3] = Convert.ToInt32(dv[0]["F_NumParam3"]);
|
|
conInfo[4] = Convert.ToInt32(dv[0]["F_NumParam4"]);
|
|
conInfo[5] = Convert.ToInt32(dv[0]["F_NumParam5"]);
|
|
conInfo[6] = Convert.ToInt32(dv[0]["F_NumParam6"]);
|
|
}
|
|
else
|
|
{
|
|
|
|
return null;
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_Child_Index FROM T_Monitor_Task_Child_Index");
|
|
|
|
dvMt = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvMt.Count > 0 && dvMt[0]["F_Child_Index"] != DBNull.Value)
|
|
{
|
|
int maxIdx;
|
|
maxIdx = (Convert.ToInt32(dvMt[0]["F_Child_Index"]) + 1);
|
|
if (maxIdx >= 64000)
|
|
{
|
|
UpdateMonitorChildIndex(Convert.ToInt32(devKindIndex.ToString() + "0" + "1"));
|
|
conInfo[0] = Convert.ToInt32(devKindIndex.ToString() + "0" + "1");
|
|
return conInfo;
|
|
}
|
|
else
|
|
{
|
|
UpdateMonitorChildIndex(maxIdx);
|
|
conInfo[0] = maxIdx;
|
|
return conInfo;
|
|
}
|
|
}
|
|
else//现在没有该设备指令子任务记录
|
|
{
|
|
UpdateMonitorIndex(Convert.ToInt32(devKindIndex.ToString() + "0" + "1"));
|
|
conInfo[0] = Convert.ToInt32(devKindIndex.ToString() + "0" + "1");
|
|
return conInfo;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_DisassembleTaskError = "获得指定调度任务的设备指令索引失败!" + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
dvMt.Dispose();
|
|
conInfo = null;
|
|
}
|
|
|
|
}
|
|
public void UpdateMonitorChildIndex(int MonitorChildIndex)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task_Child_Index set F_Child_Index=" ).Append( MonitorChildIndex);
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
/// <summary>
|
|
/// 增加对表T_Monitor_Task_Child的监控,产生不同设备优选算法,完成优化调度
|
|
/// 优化原则:调度路径和最小者(空闲设备的当前位置与起始位置的“路径模差”的绝对值
|
|
/// 加上 起始位置与终点位置的“路径模差”的绝对值
|
|
/// 路径模差:此路径上总共有n个站点,如果(n1-n2)的绝对值大于或等于(n/2),则
|
|
/// 路径模差=Math.Abs(n1-n2)-n;否则,路径模差=Math.Abs(n1-n2)
|
|
/// </summary>
|
|
public void OptimizeControlDevice()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获得设备指令任务的关联对等设备索引:堆垛机的取货指令任务的取货站台的双叉对等关联站台
|
|
/// 返回值“”表示无关联站台;“0”表示自关联站台;其它值表示关联站台设备索引
|
|
/// </summary>
|
|
/// <param name="MonitorTask">设备指令索引</param>
|
|
/// <param name="DeviceIndex">设备索引</param>
|
|
/// <returns></returns>
|
|
public string GetCorrel_DeviceIndex(int MonitorTask)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
int[] zxy = GetCoordinatesFromMonitorTask(MonitorTask);
|
|
string zxystr = string.Empty;
|
|
if (zxy != null)
|
|
{
|
|
zxystr = (zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString()) + "-" +
|
|
((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString())) + "-" +
|
|
((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString()));
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneGateDeviceIndex,F_CorrelDeviceIndex FROM T_Base_Lane_Gate where (T_Base_Lane_Gate.F_ZXY = '").Append(zxystr).Append("')");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
|
|
if (dv[0]["F_LaneGateDeviceIndex"].ToString() == dv[0]["F_CorrelDeviceIndex"].ToString())
|
|
{
|
|
return "0";
|
|
}
|
|
else
|
|
{
|
|
return dv[0]["F_CorrelDeviceIndex"].ToString();
|
|
}
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据设备指令索引获得设备巷道出入口信息:【0】设备索引【1】顶升高位检测【2】顶升低位检测
|
|
/// 【3】有物检测【4】运行监测【5】近巷道有物检测【6】远巷道有物检测【7】是否使用远货叉【8】关联设备索引【9】货位编码
|
|
/// </summary>
|
|
/// <param name="MonitorTask"></param>
|
|
/// <returns></returns>
|
|
public string[] GetDeviceLaneGateInfoFromStackCoor(int stackdeviceindex,int MonitorTask)
|
|
{
|
|
DataView dvl = new DataView();
|
|
try
|
|
{
|
|
int laneway = 0;
|
|
dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", stackdeviceindex)).Tables[0].DefaultView;
|
|
if (dvl.Count > 0)
|
|
{
|
|
laneway = Convert.ToInt32(dvl[0][0]);
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
string[] rr = new string[10];
|
|
|
|
int[] zxy = GetCoordinatesFromMonitorTask(MonitorTask);
|
|
string zxystr = "";
|
|
if (zxy != null)
|
|
{
|
|
zxystr = (zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString()) + "-" +
|
|
((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString())) + "-" +
|
|
((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString()));
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Base_Lane_Gate where (F_LaneIndex=").Append(laneway).Append(" and T_Base_Lane_Gate.F_ZXY = '").Append(zxystr).Append("')");
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
rr[0] = dv[0]["F_LaneGateDeviceIndex"].ToString();
|
|
rr[1] = dv[0]["F_HighDetect"].ToString();
|
|
rr[2] = dv[0]["F_LowDetect"].ToString();
|
|
rr[3] = dv[0]["F_HavingDetect"].ToString();
|
|
rr[4] = dv[0]["F_RunDetect"].ToString();
|
|
rr[5] = dv[0]["F_NearDetect"].ToString();
|
|
rr[6] = dv[0]["F_FarDetect"].ToString();
|
|
rr[7] = dv[0]["F_UseAwayFork"].ToString();
|
|
rr[8] = dv[0]["F_CorrelDeviceIndex"].ToString();
|
|
rr[9] = dv[0]["F_ZXY"].ToString();
|
|
return rr;
|
|
}
|
|
|
|
}
|
|
return null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dvl.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据堆垛机和设备索引获得设备巷道出入口信息:【0】设备索引【1】顶升高位检测【2】顶升低位检测
|
|
/// 【3】有物检测【4】运行监测【5】近巷道有物检测【6】远巷道有物检测【7】是否使用远货叉【8】关联设备索引【9】货位编码【10】其他额外设备检测
|
|
/// </summary>
|
|
/// <param name="stack"></param>
|
|
/// <param name="device"></param>
|
|
/// <returns></returns>
|
|
public string[] GetLanewayDeviceInfoFromStackDev(int stack, int device)
|
|
{
|
|
DataView dvl = new DataView(); DataView dv = new DataView();
|
|
try
|
|
{
|
|
int laneway = 0;
|
|
dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", stack)).Tables[0].DefaultView;
|
|
if (dvl.Count > 0)
|
|
{
|
|
laneway = Convert.ToInt32(dvl[0][0]);
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
string[] rr = new string[11];
|
|
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Base_Lane_Gate where F_CorrelDeviceIndex<>'' and (F_LaneIndex=").Append(laneway).Append(" and T_Base_Lane_Gate.F_LaneGateDeviceIndex = ").Append(device).Append(")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
rr[0] = dv[0]["F_LaneGateDeviceIndex"].ToString();
|
|
rr[1] = dv[0]["F_HighDetect"].ToString();
|
|
rr[2] = dv[0]["F_LowDetect"].ToString();
|
|
rr[3] = dv[0]["F_HavingDetect"].ToString();
|
|
rr[4] = dv[0]["F_RunDetect"].ToString();
|
|
rr[5] = dv[0]["F_NearDetect"].ToString();
|
|
rr[6] = dv[0]["F_FarDetect"].ToString();
|
|
rr[7] = dv[0]["F_UseAwayFork"].ToString();
|
|
rr[8] = dv[0]["F_CorrelDeviceIndex"].ToString();
|
|
rr[9] = dv[0]["F_zxy"].ToString();
|
|
rr[10] = dv[0]["F_DeviceDetect"].ToString();
|
|
return rr;
|
|
}
|
|
else
|
|
|
|
return null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
dvl.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获得设备索引的关联对等设备索引:堆垛机的取货指令任务的取货站台的双叉对等关联站台或者顶升
|
|
/// 返回值“”表示无关联站台;“0”表示自关联站台;其它值表示关联站台设备索引
|
|
/// </summary>
|
|
/// <param name="DeviceIndex"></param>
|
|
/// <returns></returns>
|
|
public string GetCorrel_DeviceIndex(int DeviceIndex, bool ownCorrel)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneGateDeviceIndex,F_CorrelDeviceIndex FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex = ").Append(DeviceIndex);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
|
|
if (dv[0]["F_LaneGateDeviceIndex"].ToString() == dv[0]["F_CorrelDeviceIndex"].ToString())
|
|
{
|
|
return "0";
|
|
}
|
|
else
|
|
{
|
|
return dv[0]["F_CorrelDeviceIndex"].ToString();
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据设备索引获得关联设备信息集合《关联设备索引,信息数组》,信息数组:【0】设备索引【1】顶升高位检测【2】顶升低位检测
|
|
/// 【3】有物检测【4】运行监测【5】近巷道有物检测【6】远巷道有物检测【7】是否使用远货叉【8】关联设备索引
|
|
/// </summary>
|
|
/// <param name="DeviceIndex">设备索引</param>
|
|
/// <param name="ownCorrel">是否自关联</param>
|
|
/// <returns></returns>
|
|
public Dictionary<int, string[]> GetCorrel_DeviceInfo(int DeviceIndex, bool ownCorrel)
|
|
{
|
|
Dictionary<int, string[]> Dicrr = new Dictionary<int,string[]>();
|
|
string[] rr = new string[9];
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Base_Lane_Gate where F_CorrelDeviceIndex like '%").Append(DeviceIndex).Append("%'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
for (int i = 0; i < dv.Count;i++ )
|
|
{
|
|
rr[0] = dv[i]["F_LaneGateDeviceIndex"].ToString();
|
|
rr[1] = dv[i]["F_HighDetect"].ToString();
|
|
rr[2] = dv[i]["F_LowDetect"].ToString();
|
|
rr[3] = dv[i]["F_HavingDetect"].ToString();
|
|
rr[4] = dv[i]["F_RunDetect"].ToString();
|
|
rr[5] = dv[i]["F_NearDetect"].ToString();
|
|
rr[6] = dv[i]["F_FarDetect"].ToString();
|
|
rr[7] = dv[i]["F_UseAwayFork"].ToString();
|
|
rr[8] = dv[i]["F_CorrelDeviceIndex"].ToString();
|
|
if (ownCorrel == true)
|
|
{
|
|
if (dv[i]["F_LaneGateDeviceIndex"].ToString() == DeviceIndex.ToString())
|
|
{
|
|
Dicrr.Add(Convert.ToInt32(dv[i]["F_LaneGateDeviceIndex"]), rr);
|
|
return Dicrr;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Dicrr.Add(Convert.ToInt32(dv[i]["F_LaneGateDeviceIndex"]), rr);
|
|
|
|
}
|
|
}
|
|
return Dicrr;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据设备索引获得自关联设备信息:【0】设备索引【1】顶升高位检测【2】顶升低位检测
|
|
/// 【3】有物检测【4】运行监测【5】近巷道有物检测【6】远巷道有物检测【7】是否使用远货叉【8】关联设备索引
|
|
/// </summary>
|
|
/// <param name="DeviceIndex">设备索引</param>
|
|
|
|
/// <returns></returns>
|
|
public string[] GetOwnCorrel_DeviceInfo(int DeviceIndex)
|
|
{
|
|
|
|
string[] rr = new string[9];
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex=").Append(DeviceIndex).Append(" and F_CorrelDeviceIndex = '").Append(DeviceIndex).Append("'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if(dv.Count>0){
|
|
rr[0] = dv[0]["F_LaneGateDeviceIndex"].ToString();
|
|
rr[1] = dv[0]["F_HighDetect"].ToString();
|
|
rr[2] = dv[0]["F_LowDetect"].ToString();
|
|
rr[3] = dv[0]["F_HavingDetect"].ToString();
|
|
rr[4] = dv[0]["F_RunDetect"].ToString();
|
|
rr[5] = dv[0]["F_NearDetect"].ToString();
|
|
rr[6] = dv[0]["F_FarDetect"].ToString();
|
|
rr[7] = dv[0]["F_UseAwayFork"].ToString();
|
|
rr[8] = dv[0]["F_CorrelDeviceIndex"].ToString();
|
|
|
|
return rr;
|
|
|
|
}
|
|
return null;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetOldDevcieFromStackCorr(int mankind, int fid, int taskindex)
|
|
{
|
|
if (CStaticClass.DBFactory == "OracleDBFactory")
|
|
{//20151120调度系统oracle的特殊语句
|
|
sql = new StringBuilder(string.Format("SELECT F_ManageTASKKINDINDEX,F_ManageTaskIndex,F_MonitorIndex, F_DeviceIndex,F_NumParam1,F_NumParam2,F_NumParam3 FROM T_Monitor_Task WHERE rownum=1 and F_ManageTASKKINDINDEX={0} and F_ManageTaskIndex={1} and (F_MonitorIndex > {2}) ORDER BY F_MonitorIndex", mankind, fid, taskindex));
|
|
}
|
|
else
|
|
{
|
|
sql = new StringBuilder(string.Format("SELECT TOP 1 F_ManageTASKKINDINDEX,F_ManageTaskIndex,F_MonitorIndex, F_DeviceIndex,F_NumParam1,F_NumParam2,F_NumParam3 FROM T_Monitor_Task WHERE F_ManageTASKKINDINDEX={0} and F_ManageTaskIndex={1} and (F_MonitorIndex > {2}) ORDER BY F_MonitorIndex", mankind, fid, taskindex));
|
|
}
|
|
DataView dvr = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;//20151120调度系统oracle的特殊语句
|
|
if (dvr.Count > 0)
|
|
{
|
|
int laneway =GetLaneWayNoFromStack( Convert.ToInt32(dvr[0]["F_DeviceIndex"]));
|
|
|
|
int[] zxy = GetCoordinatesFromMonitorTask(taskindex);
|
|
StringBuilder zxystr = new StringBuilder();
|
|
if (zxy != null)
|
|
{
|
|
zxystr.Append((zxy[0].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[0].ToString())).Append("-").Append(
|
|
((zxy[1].ToString().Length == 1) ? ("0" + zxy[1].ToString()) : (zxy[1].ToString()))).Append("-").Append(
|
|
((zxy[2].ToString().Length == 1) ? ("0" + zxy[2].ToString()) : (zxy[2].ToString())));
|
|
}
|
|
DataView dv = dbo.ExceSQL(string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_LaneIndex = {0}) AND (F_ZXY = '{1}')",laneway,zxystr.ToString())).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
public int GetLaneWayNoFromStack(int stackNo)
|
|
{
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(stackNo);
|
|
if (devinfo.VirtualStack >0)
|
|
{
|
|
stackNo = devinfo.VirtualStack;
|
|
}
|
|
sql.Clear();
|
|
sql.Append("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo where f_stackindex=").Append(stackNo);
|
|
DataView dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_LaneDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 是否为多叉堆垛机的取货站台
|
|
/// </summary>
|
|
/// <param name="device"></param>
|
|
/// <returns></returns>
|
|
public bool IfMutiForkStackGetDevice(int device)
|
|
{
|
|
DataView dv = dbo.ExceSQL(string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_CorrelDeviceIndex LIKE '%{0}%') AND (F_UseAwayFork > '0')",device)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 根据设备指令索引反馈堆垛机的送货坐标是否为极限货位
|
|
/// </summary>
|
|
/// <param name="TaskIdx"></param>
|
|
/// <returns></returns>
|
|
public bool IfLimitCellCode(int TaskIdx)
|
|
{
|
|
int[] zxy = GetCoordinatesFromMonitorTask(TaskIdx);
|
|
if (zxy != null)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_ForwardLimitX = " ).Append( zxy[4] ).Append( ") OR (F_BackLimitX = " ).Append( zxy[4] ).Append( ")");
|
|
object ob = dbo.GetSingle(sql.ToString());
|
|
if (ob != null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
}
|
|
return false;
|
|
}
|
|
#endregion
|
|
#region 读取设备状态
|
|
/// <summary>
|
|
/// 20110608获取超时运行的调度设备指令
|
|
/// </summary>
|
|
/// <param name="monitorIndex"></param>
|
|
/// <returns></returns>
|
|
public int GetMonitorTaskIndexFromRunTimeoutDevice(int deviceindex)
|
|
{
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE DATEDIFF(minute,CONVERT(datetime,SUBSTRING(F_StartTime, 1, 19)),getdate())>").Append(int.Parse(CStaticClass.TransportTimeout)).Append(" and F_StartTime<>'-' and F_Status>0 and F_DeviceIndex = ").Append(deviceindex);
|
|
object ob = dbo.GetSingle(sql.ToString());
|
|
if (ob != null)
|
|
{
|
|
return int.Parse(ob.ToString());
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
public int GetMonitorTaskIndexFromSendedDevice(int deviceindex)
|
|
{
|
|
try
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_Status=1 and F_DeviceIndex = ").Append(deviceindex);
|
|
object ob = dbo.GetSingle(sql.ToString());
|
|
if (ob != null)
|
|
{
|
|
return int.Parse(ob.ToString());
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 20110309获得调度任务的条码
|
|
/// </summary>
|
|
/// <param name="taskindex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public string GetBarCodeFromMonitor(int taskindex)
|
|
{
|
|
object ob = dbo.GetSingle(string.Format( "SELECT F_TxtParam FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})",taskindex));
|
|
if (ob != null)
|
|
{
|
|
return ob.ToString();
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
public int GetMobileRunTimeSpan(int TaskIdx)
|
|
{
|
|
DateTime dt, dt0 = DateTime.Now;
|
|
int dat = 0;
|
|
if (DateTime.TryParse(GetStartTimeFromMonitor(TaskIdx), out dt) == true)
|
|
{
|
|
TimeSpan ts1 = new TimeSpan(dt0.Ticks);
|
|
TimeSpan ts2 = new TimeSpan(dt.Ticks);
|
|
dat = (int)ts1.Subtract(ts2).Duration().TotalSeconds;
|
|
|
|
}
|
|
return dat;
|
|
|
|
}
|
|
public int GetErrorTimeSpan(int deviceindex)
|
|
{
|
|
DateTime dt, dt0 = DateTime.Now;
|
|
int dat = 0;
|
|
if (DateTime.TryParse(GetTimeFromDevice(deviceindex, "F_ErrorStartTime"), out dt) == true)
|
|
{
|
|
TimeSpan ts1 = new TimeSpan(dt0.Ticks);
|
|
TimeSpan ts2 = new TimeSpan(dt.Ticks);
|
|
dat = (int)ts1.Subtract(ts2).Duration().TotalSeconds;
|
|
|
|
}
|
|
return dat;
|
|
|
|
}
|
|
public int GetAlarmTimeSpan(int deviceindex)
|
|
{
|
|
DateTime dt, dt0 = DateTime.Now;
|
|
int dat = 0;
|
|
if (DateTime.TryParse(GetTimeFromDevice(deviceindex, "F_AlarmStartTime"), out dt) == true)
|
|
{
|
|
TimeSpan ts1 = new TimeSpan(dt0.Ticks);
|
|
TimeSpan ts2 = new TimeSpan(dt.Ticks);
|
|
dat = (int)ts1.Subtract(ts2).Duration().TotalSeconds;
|
|
|
|
}
|
|
return dat;
|
|
|
|
}
|
|
public int GetConveyorRunTimeSpan(int deviceindex)
|
|
{
|
|
DateTime dt, dt0 = DateTime.Now;
|
|
int dat = 0;
|
|
if (DateTime.TryParse(GetTimeFromDevice(deviceindex, "F_ConveyorRunStartTime"), out dt) == true)
|
|
{
|
|
TimeSpan ts1 = new TimeSpan(dt0.Ticks);
|
|
TimeSpan ts2 = new TimeSpan(dt.Ticks);
|
|
dat = (int)ts1.Subtract(ts2).Duration().TotalSeconds;
|
|
|
|
}
|
|
return dat;
|
|
|
|
}
|
|
public int GetScheduledRepairTimeSpan(int deviceindex)
|
|
{
|
|
DateTime dt, dt0 = DateTime.Now;
|
|
int dat = 0;
|
|
if (DateTime.TryParse(GetTimeFromDevice(deviceindex, "F_ScheduledRepairStartTime"), out dt) == true)
|
|
{
|
|
TimeSpan ts1 = new TimeSpan(dt0.Ticks);
|
|
TimeSpan ts2 = new TimeSpan(dt.Ticks);
|
|
dat = (int)ts1.Subtract(ts2).Duration().TotalSeconds;
|
|
|
|
}
|
|
return dat;
|
|
|
|
}
|
|
public string GetTimeFromDevice(int deviceIndex, string timeKind)
|
|
{
|
|
DataView dv = dbo.ExceSQL(string.Format("SELECT {1} FROM T_Base_Device where F_DeviceIndex ={0} and {1} <>'-'", deviceIndex, timeKind)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0][0].ToString().Substring(0,19);
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取设备指令队列的开始执行时间
|
|
/// </summary>
|
|
/// <param name="taskindex">设备指令索引</param>
|
|
/// <returns></returns>
|
|
public string GetStartTimeFromMonitor(int taskindex)
|
|
{
|
|
object ob = dbo.GetSingle(string.Format("SELECT F_StartTime FROM T_Monitor_Task WHERE (F_MonitorIndex = {0})", taskindex));
|
|
if (ob != null)
|
|
{
|
|
if (ob.ToString() != "-")
|
|
{
|
|
return ob.ToString().Substring(0,19);
|
|
}
|
|
else
|
|
{
|
|
return ob.ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
public int GetExceptionNOFromManageTask(int FID,int ManTaskKind)
|
|
{
|
|
//20100108
|
|
DataTable dt = new DataTable();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FID, F_ManageTaskKindIndex, FExceptionNO FROM T_Manage_Task WHERE (FID = " ).Append( FID ).Append( ") AND (F_ManageTaskKindIndex = " ).Append( ManTaskKind ).Append( ") ");
|
|
//20100108
|
|
dt = dbo.ExceSQL(sql.ToString()).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)
|
|
{
|
|
_DisassembleTaskError = "获得指定调度任务的异常代码:" + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dt.Dispose();
|
|
|
|
}
|
|
}
|
|
public string GetBarCodeFromManageTask(int FID, int ManTaskKind)
|
|
{
|
|
//20100108
|
|
DataTable dt = new DataTable();
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FPALLETBARCODE FROM T_Manage_Task WHERE (FID = ").Append(FID).Append(") AND (F_ManageTaskKindIndex = ").Append(ManTaskKind).Append(") ");
|
|
//20100108
|
|
dt = dbo.ExceSQL(sql.ToString()).Tables[0];
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Rows[0]["FPALLETBARCODE"] == DBNull.Value)
|
|
{
|
|
return "-";
|
|
}
|
|
else
|
|
{
|
|
|
|
return dt.Rows[0]["FPALLETBARCODE"].ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_DisassembleTaskError = "获得指定调度任务的条码:" + ex.Message;
|
|
throw ex;
|
|
|
|
}
|
|
finally
|
|
{//20100108
|
|
dt.Dispose();
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 得到出库任务的托盘重量信息
|
|
/// </summary>
|
|
/// <param name="FID"></param>
|
|
/// <returns></returns>
|
|
public string GetMWSWeightFromFID(int FID)
|
|
{
|
|
//20220707
|
|
DataTable dt = new DataTable();
|
|
try
|
|
{
|
|
//20220707
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT STACK_TYPE FROM T_Manage_Task WHERE (FID = ").Append(FID).Append(")");
|
|
//20220707
|
|
dt = dbo.ExceSQL(sql.ToString()).Tables[0];
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
if (dt.Rows[0]["STACK_TYPE"] == DBNull.Value)
|
|
{
|
|
return "0";
|
|
}
|
|
else
|
|
{
|
|
|
|
return dt.Rows[0]["STACK_TYPE"].ToString();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "0";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_DisassembleTaskError = "获得指定调度任务的条码:" + ex.Message;
|
|
throw ex;
|
|
|
|
}
|
|
finally
|
|
{//20100108
|
|
dt.Dispose();
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
#region 获得调度任务
|
|
/// <summary>
|
|
/// 获取调度生成的调度任务的索引
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public int GetTempManageIdx()
|
|
{
|
|
//20100108
|
|
DataSet ds = new DataSet();
|
|
try
|
|
{
|
|
int maxIdx = 10001;
|
|
|
|
ds = dbo.ExceSQL("SELECT F_ManageTaskIndex FROM T_Base_Manage_Task_Index_Temp_Task");
|
|
if (ds.Tables[0].DefaultView.Count > 0)
|
|
{
|
|
if ((Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1) >= 19998)
|
|
{
|
|
maxIdx = 10001;
|
|
}
|
|
else
|
|
{
|
|
maxIdx = (Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
maxIdx = 10001;
|
|
}
|
|
//判断临时调度任务表是否有重复值
|
|
if (IFExitTempManageIndex(maxIdx) == true)
|
|
{
|
|
RecordMaxTempManageTaskFID(maxIdx);
|
|
maxIdx = GetTempManageIdx();
|
|
return maxIdx;
|
|
}
|
|
|
|
RecordMaxTempManageTaskFID(maxIdx);
|
|
return maxIdx;
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
_DisassembleTaskError = "获得指定调度任务的临时任务索引失败," + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
ds.Dispose();
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获得库房索引
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetWarehouseIndex()
|
|
{
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20100108
|
|
dv = dbo.ExceSQL("select F_WarehouseIndex from T_Warehouse").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
|
|
return dv[0]["F_WarehouseIndex"].ToString();
|
|
|
|
}
|
|
else
|
|
{
|
|
return "1";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
_DisassembleTaskError = "获得指定库房索引失败," + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
public string GetWarehouseIndex(int laneway, string cellcode)
|
|
{
|
|
object ob = dbo.GetSingle(string.Format("SELECT FWAREHOUSE FROM ST_CELL WHERE (FLaneWay = {0}) AND (FCELLCODE = '{1}')",laneway,cellcode));
|
|
if (ob != null)
|
|
{
|
|
return ob.ToString();
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 记录调度生成的调度任务的索引的最大值
|
|
/// </summary>
|
|
/// <param name="fid">调度生成的调度任务的索引</param>
|
|
public void RecordMaxTempManageTaskFID(int fid)
|
|
{//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{//20100108
|
|
dv = dbo.ExceSQL("select F_ManageTaskIndex from T_Base_Manage_Task_Index_Temp_Task").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
//if (fid == 19998)
|
|
//{
|
|
// dbo.ExceSQL("UPDATE T_Base_Manage_Task_Index_Temp_Task SET F_ManageTaskIndex =10001");
|
|
// return;
|
|
//}
|
|
//if (fid > Convert.ToInt32(dv[0]["F_ManageTaskIndex"]))
|
|
//{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Base_Manage_Task_Index_Temp_Task SET F_ManageTaskIndex =" ).Append( fid);
|
|
dbo.ExceSQL(sql.ToString());
|
|
return;
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("INSERT INTO T_Base_Manage_Task_Index_Temp_Task (F_ManageTaskIndex)VALUES (" ).Append( fid ).Append( ")");
|
|
dbo.ExceSQL(sql.ToString());
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
_DisassembleTaskError = "获得记录调度任务最大任务索引失败," + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 判断这个货位在ST_CELL是否存在
|
|
/// </summary>
|
|
/// <param name="FWAREHOUSE"></param>
|
|
/// <param name="FLaneWay"></param>
|
|
/// <param name="FCELLCODE"></param>
|
|
/// <returns></returns>
|
|
public bool QueryCellIfExit(string FWAREHOUSE, int FLaneWay, string FCELLCODE)
|
|
{
|
|
|
|
|
|
char[] cc = new char[1] { '-' };
|
|
string[] fcc = FCELLCODE.Split(cc);
|
|
if (fcc.GetUpperBound(0) < 2) return false;
|
|
int[] fcci = new int[fcc.GetUpperBound(0) + 1];
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
for (int i = fcc.GetLowerBound(0); i <= fcc.GetUpperBound(0); i++)
|
|
{
|
|
fcci[i] = Convert.ToInt32(fcc[i]);
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FWAREHOUSE, FCELLCODE, FCELLSTATUS ").Append(
|
|
" FROM ST_CELL Where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay ).Append( " and F_Z=" ).Append(
|
|
fcci[0] ).Append( " and F_X=" ).Append( fcci[1]).Append( " and F_Y=" ).Append( fcci[2] );
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
_DisassembleTaskError = "查询货位是否存在失败," + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
cc =null ;
|
|
fcc =null ;
|
|
fcci = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询货位状态是否满足入库或者出库条件
|
|
/// </summary>
|
|
/// <param name="FWAREHOUSE">库房编号</param>
|
|
/// <param name="FCELLCODE">货位编号</param>
|
|
/// <param name="IOType">"1":入库(放货);"2":出库(取货)</param>
|
|
/// <returns></returns>
|
|
public bool QueryCellStatusIfAccord(string FWAREHOUSE,int FLaneWay, string FCELLCODE, string IOType)
|
|
{
|
|
|
|
char[] cc = new char[1] { '-' };
|
|
string[] fcc = FCELLCODE.Split(cc);
|
|
if (fcc.GetUpperBound(0) < 2) return false;
|
|
int[] fcci = new int[fcc.GetUpperBound(0) + 1];
|
|
//20100108
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
for (int i = fcc.GetLowerBound(0); i <= fcc.GetUpperBound(0); i++)
|
|
{
|
|
fcci[i] = Convert.ToInt32(fcc[i]);
|
|
}
|
|
if (IOType == "1")//入库(放货)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FWAREHOUSE, FCELLCODE, FCELLSTATUS " +
|
|
" FROM ST_CELL Where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay ).Append( " and F_Z=" ).Append(
|
|
fcci[0] ).Append( " and F_X=").Append( fcci[1] ).Append( " and F_Y=" ).Append( fcci[2] ).Append( " and FCELLSTATUS='0'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
else//if (IOType == "2")//出库(取货)
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FWAREHOUSE, FCELLCODE, FCELLSTATUS " ).Append(
|
|
" FROM ST_CELL Where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay ).Append( " and F_Z='" ).Append(
|
|
fcci[0] ).Append( "' and F_X='" ).Append( fcci[1] ).Append( "' and F_Y='" ).Append( fcci[2] ).Append( "' and FCELLSTATUS='1'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
_DisassembleTaskError = "查询货位状态失败," + ex.Message;
|
|
throw ex;
|
|
//return 0;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
cc = null;
|
|
fcc = null;
|
|
fcci = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置货位状态
|
|
/// </summary>
|
|
/// <param name="FWAREHOUSE"></param>
|
|
/// <param name="FCELLCODE"></param>
|
|
/// <param name="FCELLSTATUS"></param>
|
|
public void SetCellStatus(string FWAREHOUSE, int FLaneWay, string FCELLCODE, string FCELLSTATUS)
|
|
{
|
|
char[] cc = new char[1] { '-' };
|
|
string[] fcc = FCELLCODE.Split(cc);
|
|
int[] fcci = new int[fcc.GetUpperBound(0) + 1];
|
|
try
|
|
{//20100108
|
|
for (int i = fcc.GetLowerBound(0); i <= fcc.GetUpperBound(0); i++)
|
|
{
|
|
fcci[i] = Convert.ToInt32(fcc[i]);
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FCELLSTATUS ='" ).Append( FCELLSTATUS ).Append( "' where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay ).Append( " and F_Z='" ).Append(
|
|
fcci[0] ).Append( "' and F_X='" ).Append( fcci[1] ).Append( "' and F_Y='" ).Append( fcci[2] ).Append( "' ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
cc = null;
|
|
fcc = null;
|
|
fcci = null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 查询运行状态是否符合条件
|
|
/// </summary>
|
|
/// <param name="FWAREHOUSE"></param>
|
|
/// <param name="FCELLCODE"></param>
|
|
/// <returns></returns>
|
|
public bool QueryRunStatusIfAccord(string FWAREHOUSE, int FLaneWay, string FCELLCODE)
|
|
{
|
|
char[] cc = new char[1] { '-' };
|
|
string[] fcc = FCELLCODE.Split(cc);
|
|
int[] fcci = new int[fcc.GetUpperBound(0) + 1];
|
|
DataView dv = new DataView(); ;//20100108
|
|
try
|
|
{//20100108
|
|
for (int i = fcc.GetLowerBound(0); i <= fcc.GetUpperBound(0); i++)
|
|
{
|
|
fcci[i] = Convert.ToInt32(fcc[i]);
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FWAREHOUSE, FCELLCODE, FCELLSTATUS ").Append(
|
|
" FROM ST_CELL Where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay ).Append( " and F_Z='" ).Append(
|
|
fcci[0]).Append( "' and F_X='" ).Append( fcci[1] ).Append( "' and F_Y='" ).Append( fcci[2] ).Append( "' and FRUNSTATUS='0'");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
cc = null;
|
|
fcc = null;
|
|
fcci = null;
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 设置货位运行状态
|
|
/// </summary>
|
|
/// <param name="FWAREHOUSE"></param>
|
|
/// <param name="FCELLCODE"></param>
|
|
/// <param name="FRUNSTATUS"></param>
|
|
public void SetRunStatus(string FWAREHOUSE, int FLaneWay, string FCELLCODE, string FRUNSTATUS)
|
|
{
|
|
char[] cc = new char[1] { '-' };
|
|
string[] fcc = FCELLCODE.Split(cc);
|
|
int[] fcci = new int[fcc.GetUpperBound(0) + 1];
|
|
try
|
|
{//20100108
|
|
for (int i = fcc.GetLowerBound(0); i <= fcc.GetUpperBound(0); i++)
|
|
{
|
|
fcci[i] = Convert.ToInt32(fcc[i]);
|
|
}
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE ST_CELL SET FRUNSTATUS ='" ).Append( FRUNSTATUS ).Append( "' where FWAREHOUSE='" ).Append( FWAREHOUSE ).Append( "' and FLaneWay=" ).Append( FLaneWay).Append( " and F_Z='" ).Append(
|
|
fcci[0] ).Append( "' and F_X='" ).Append( fcci[1] ).Append( "' and F_Y='" ).Append( fcci[2] ).Append( "'");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
cc = null;
|
|
fcc = null;
|
|
fcci = null;
|
|
}
|
|
}
|
|
|
|
public int GetSerialNumberFromRouteDevice(int RouteIDSub, int DeviceIndex)
|
|
{
|
|
DataView dv = new DataView();//20100108
|
|
try
|
|
{
|
|
//20101124
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_SerialNumber FROM T_Base_Route_Device WHERE (F_RouteIDSub = " ).Append( RouteIDSub ).Append( ") AND (F_DeviceIndex = " ).Append( DeviceIndex ).Append( ")");
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return (int)dv[0]["F_SerialNumber"];
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{//20100108
|
|
throw ex;
|
|
}
|
|
finally
|
|
{//20100108
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public int GetManTaskReserve(int deviceIndex)
|
|
{//20111020
|
|
object ob = dbo.GetSingle(string.Format("SELECT F_ManTaskReserve FROM T_Base_Device WHERE (F_DeviceIndex = {0})",deviceIndex));
|
|
if (ob != null)
|
|
{
|
|
return Convert.ToInt32(ob);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
public int GetDeviceLockedState(int deviceIndex)
|
|
{//20111020
|
|
object ob = dbo.GetSingle(string.Format("SELECT F_LockedState FROM T_Base_Device WHERE (F_DeviceIndex = {0})", deviceIndex));
|
|
if (ob != null)
|
|
{
|
|
return Convert.ToInt32(ob);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
public int GetStackMutexDevice(int deviceIndex)
|
|
{//20111020
|
|
object ob = dbo.GetSingle(string.Format("SELECT F_Mutex FROM T_Base_StackInfo WHERE (F_StackIndex = {0})",deviceIndex));
|
|
if (ob != null)
|
|
{
|
|
return Convert.ToInt32(ob);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
public int GetRouteIDsub(int device)
|
|
{//20111020
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL("SELECT F_RouteIDSub, F_DeviceIndex, F_RouteID FROM T_Base_Route_Device where F_DeviceIndex=" + device + "").Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_RouteIDSub"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public void GetS7ConnectionRelativeAddressDataLenth(int deviceIndex,out string s7conn,out int relAddr,out int datalength)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
|
|
//lock (lockob)
|
|
{
|
|
relAddr = 0; datalength = 0; s7conn = string.Empty;
|
|
s7conn = dbo.GetSingle(string.Format("select F_S7Connection FROM T_Base_Device WHERE F_DeviceIndex={0}", deviceIndex)).ToString();
|
|
int db228 = Convert.ToInt32(dbo.GetSingle(string.Format("SELECT DISTINCT F_DBW2Address FROM T_Base_Device WHERE (F_DeviceKindIndex = 28 AND F_S7Connection = '{0}')", s7conn)));
|
|
dv = dbo.ExceSQL(string.Format("SELECT (F_DBW2Address -{0}) AS relAddr, F_DBWGetLength FROM T_Base_Device WHERE F_DeviceIndex={1}", db228, deviceIndex)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
relAddr = Convert.ToInt32(dv[0]["relAddr"]);
|
|
datalength = Convert.ToInt32(dv[0]["F_DBWGetLength"]);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
public void GetSplitByteRelativeAddress(int deviceIndex,string s7conn, out int relAddr)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
//lock (lockob)
|
|
{
|
|
relAddr = -1;
|
|
object ob = dbo.GetSingle(string.Format("(SELECT DISTINCT F_DBW2Address FROM T_Base_Device WHERE (F_DeviceKindIndex = 28 AND F_S7Connection = '{0}'))", s7conn));
|
|
dv = dbo.ExceSQL(string.Format("SELECT (F_SplitByte -{0}) AS relAddr FROM T_Base_Device WHERE F_SplitByte is not NULL and F_DeviceIndex={1}", Convert.ToInt32(ob), deviceIndex)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
relAddr = Convert.ToInt32(dv[0]["relAddr"]);
|
|
|
|
}
|
|
else
|
|
{
|
|
relAddr = -1;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 201112105判断是否可以获得可用的路径子路经,并且实现改道
|
|
/// </summary>
|
|
/// <param name="manageTaskIdx">调度任务索引</param>
|
|
/// <param name="manageKindIdx">任务类型索引</param>
|
|
/// <param name="curLocation">当前设备索引</param>
|
|
/// <returns></returns>
|
|
public bool GetUseableRouteIDSubAndModifyRoute(int manageTaskIdx, int manageKindIdx, int curLocation)
|
|
{
|
|
DataView dvmi = new DataView();
|
|
DataView DMAN = new DataView();
|
|
DataView dvnew = new DataView();
|
|
DataView dvc = new DataView();
|
|
try
|
|
{
|
|
|
|
//20091005
|
|
|
|
#region 调度任务存在
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT * FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(1).Append(") order by F_MonitorIndex asc");
|
|
dvmi = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvmi.Count > 0)
|
|
{//已经开始执行的需要更改调度任务
|
|
//判断申请修改路径的第一个调度任务:
|
|
int monitorIndex = (int)dvmi[0]["F_MonitorIndex"];
|
|
int associateMonitor = -1;
|
|
if (dvmi[0]["F_Associate"] != DBNull.Value)
|
|
{
|
|
associateMonitor = Convert.ToInt32(dvmi[0]["F_Associate"]);
|
|
}
|
|
int devindex = Convert.ToInt32(dvmi[0]["F_DeviceIndex"]);
|
|
int devKind = GetDeviceKindIdx(Convert.ToInt32(dvmi[0]["F_DeviceIndex"]));
|
|
int devCommand = Convert.ToInt32(dvmi[0]["F_DeviceCommandIndex"]);
|
|
int routeID = Convert.ToInt32(dvmi[0]["F_RouteID"]);
|
|
int NumParam1 = Convert.ToInt32(dvmi[0]["F_NumParam1"]);
|
|
int NumParam4 = Convert.ToInt32(dvmi[0]["F_NumParam4"]);
|
|
string AheadDetect = dvmi[0]["F_AheadDetect"].ToString();
|
|
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("select * from T_Manage_Task WHERE (FID = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")");
|
|
DMAN = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (DMAN.Count > 0)
|
|
{
|
|
|
|
|
|
//20091005
|
|
int routeidNew = CDisassembleTask.MinRouteID(Convert.ToInt32(DMAN[0]["FSTARTDEVICE"]), Convert.ToInt32(DMAN[0]["FENDDEVICE"]), curLocation);
|
|
|
|
if (routeidNew == -1)
|
|
{
|
|
//20091005
|
|
return false;
|
|
}
|
|
//20091005
|
|
//删除原来的申请修改路径任务,拆分新的任务并且只保留现有设备开始的任务
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("DELETE FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")");
|
|
dbo.ExceSQL(sql.ToString());
|
|
//20090910
|
|
if (CDisassembleTask.CreateMonitor(manageKindIdx, manageTaskIdx, routeidNew, DMAN[0], 3) <= 0)
|
|
{
|
|
//重新生成申请修改路径的申请任务
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("INSERT INTO T_Monitor_Task ").Append(
|
|
"(F_ManageTaskIndex, F_ManageTASKKINDINDEX, F_MonitorIndex,F_MonitorTaskLevel,").Append(
|
|
" F_DeviceIndex, F_DeviceCommandIndex, F_RouteID, F_Status,F_NumParam1, F_NumParam4,").Append(
|
|
" F_AheadDetect,F_TxtParam)").Append(
|
|
"VALUES (").Append(manageTaskIdx).Append(",").Append(manageKindIdx).Append(",").Append(monitorIndex).Append(",1,").Append(devindex).Append(",").Append(devCommand).Append(",").Append(routeID).Append(",3,").Append(NumParam1).Append(",").Append(NumParam4
|
|
).Append(",'").Append(AheadDetect).Append("','").Append(DMAN[0]["FPALLETBARCODE"]).Append("')");
|
|
dbo.ExceSQL(sql.ToString());
|
|
return false;
|
|
}
|
|
|
|
if (devKind == 4)
|
|
{
|
|
if (devCommand == 7)
|
|
{
|
|
int RGVsn = GetSerialNumberFromRouteDevice(routeID, devindex);
|
|
int Consn = GetSerialNumberFromRouteDevice(routeID, NumParam1);
|
|
|
|
#region RGV运动到接货点
|
|
if (RGVsn > Consn)
|
|
{
|
|
//删除RGV运动到接货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(NumParam1).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region RGV运动到送货点
|
|
if (RGVsn < Consn)
|
|
{
|
|
//删除RGV运动到送货点之前的任务
|
|
//DataView dvnew = dbo.ExceSQL("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = " +
|
|
// manageTaskIdx + ") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = " +
|
|
// devindex + ") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = " + routeidNew +
|
|
// ") AND (F_Status = 3) AND (F_NumParam1 <> " + NumParam1 + ")").Tables[0].DefaultView;
|
|
int RGVsn1 = GetSerialNumberFromRouteDevice(routeidNew, devindex);
|
|
//找到接货输送机设备索引
|
|
List<int> nextcon = CDisassembleTask.GetNextDevice(routeidNew, RGVsn1);
|
|
int condev = nextcon[0];
|
|
//删除RGV运动到送货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(condev).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#region RGV送货
|
|
|
|
if ((devCommand == 3) || (devCommand == 5))
|
|
{
|
|
int RGVsn = GetSerialNumberFromRouteDevice(routeidNew, devindex);
|
|
//找到接货输送机设备索引
|
|
List<int> nextcon = CDisassembleTask.GetNextDevice(routeidNew, RGVsn);
|
|
int condev = nextcon[0];
|
|
//删除RGV运动到送货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(condev).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region RGV接货
|
|
if ((devCommand == 2) || (devCommand == 4))
|
|
{
|
|
int RGVsn = GetSerialNumberFromRouteDevice(routeidNew, devindex);
|
|
//找到送货输送机设备索引
|
|
List<int> priorcon = CDisassembleTask.GetPriorDevice(routeidNew, RGVsn);
|
|
int condev = priorcon[0];
|
|
//删除RGV运动到接货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(condev).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
}
|
|
if (devKind == 2)
|
|
{
|
|
#region 输送机送货
|
|
if (devCommand == 3)
|
|
{
|
|
int consn = GetSerialNumberFromRouteDevice(routeidNew, devindex);
|
|
//找到接货RGV设备索引
|
|
List<int> nextrgv = CDisassembleTask.GetNextDevice(routeidNew, consn);
|
|
int rgvdev = nextrgv[0];
|
|
|
|
//删除RGV运动到接货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
rgvdev).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(devindex).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 输送机的接货
|
|
|
|
if (devCommand == 4)
|
|
{
|
|
int consn = GetSerialNumberFromRouteDevice(routeID, devindex);
|
|
//找到送货RGV设备索引
|
|
List<int> priorrgv = CDisassembleTask.GetPriorDevice(routeID, consn);
|
|
int rgvdev = priorrgv[0];
|
|
int rgvsn = GetSerialNumberFromRouteDevice(routeidNew, rgvdev);
|
|
List<int> nextdev = CDisassembleTask.GetNextDevice(routeidNew, rgvdev);
|
|
int condev = nextdev[0];
|
|
//删除RGV运动到送货点之前的任务
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
rgvdev).Append(") AND (F_DeviceCommandIndex = 7) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
") AND (F_NumParam1 = ").Append(condev).Append(")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 输送机的送出
|
|
if (devCommand == 6)
|
|
{
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = 6) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
int CurrentLocation = 0;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT FCurrentLocation FROM T_Manage_Task where FID=").Append(manageTaskIdx).Append(" and F_ManageTaskKindIndex=1");
|
|
dvc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvc.Count > 0)
|
|
{
|
|
CurrentLocation = Convert.ToInt32(dvc[0]["FCurrentLocation"]);
|
|
}
|
|
//20091128
|
|
|
|
if (CurrentLocation == 0) return false;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_DeviceIndex=").Append(CurrentLocation).Append(" where F_MonitorIndex=").Append(dvnew[0]["F_MonitorIndex"]);
|
|
dbo.ExceSQL(sql.ToString());
|
|
//20090910已经搬运到CurrentLocation(F_NumParam4=CurrentLocation) 删除送出任务
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_DeviceIndex=").Append(CurrentLocation).Append(" and F_NumParam4=").Append(CurrentLocation);
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
#region 堆垛机的送货重
|
|
if (devKind == 1)
|
|
{//堆垛机的送货重,只保留堆垛机的送货任务
|
|
|
|
//20091128
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
devindex).Append(") AND (F_DeviceCommandIndex = ").Append(devCommand).Append(") AND (F_RouteID = ").Append(routeidNew).Append(
|
|
")");
|
|
dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dvnew.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("delete from T_Monitor_Task where F_MonitorIndex<").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Base_Device set F_LockedState=0 where F_DeviceIndex=").Append(devindex);
|
|
dbo.ExceSQL(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 条码扫描改道
|
|
if (devKind == 7)
|
|
{
|
|
//sql.Remove(0, sql.Length);
|
|
//sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
|
|
// manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) AND (F_DeviceIndex = ").Append(
|
|
// devindex).Append(") AND (F_DeviceCommandIndex = 1) AND (F_RouteID = ").Append(routeidNew).Append(
|
|
// ")");
|
|
//dvnew = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
//if (dvnew.Count > 0)
|
|
//{
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("delete from T_Monitor_Task where F_MonitorIndex<=").Append(dvnew[0]["F_MonitorIndex"]).Append(" and (F_ManageTaskIndex = ").Append(
|
|
// manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1) ");
|
|
// dbo.ExceSQL(sql.ToString());
|
|
|
|
// sql.Remove(0, sql.Length);
|
|
// sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
// manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
// dbo.ExceSQL(sql.ToString());
|
|
//}
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
#region 高端
|
|
|
|
if (devKind == 13)
|
|
{
|
|
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
|
|
manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
|
|
dbo.ExceSQL(sql.ToString());
|
|
}
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
}//20090910
|
|
CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null);
|
|
OnDataChange("CControl.GetUseableRouteIDSubAndModifyRoute", cea);
|
|
return true;
|
|
}//20091005
|
|
#endregion
|
|
else
|
|
{//调度任务不存在
|
|
return false;
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dvc.Dispose();
|
|
dvmi.Dispose();
|
|
dvnew.Dispose();
|
|
DMAN.Dispose();
|
|
}
|
|
}
|
|
|
|
public int GetUCodeFromDeviceGD(int GdDevice)
|
|
{
|
|
DataView dv =new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("select F_UCODE from T_Base_UArea where F_InputBarcodeConfirm={0}", GdDevice)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("select F_UCODE from T_Base_UArea where F_OutputUDevice={0}", GdDevice)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
public bool IfHaveEarlyTask(int taskindex,int device)
|
|
{
|
|
sql.Clear();
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_DeviceIndex=").Append(device).Append(" and (F_StartTime < (SELECT F_StartTime FROM T_Monitor_Task WHERE F_MonitorIndex = ").Append(taskindex).Append("))");
|
|
if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
void SetStackSendConveyorManReserve(int taskindex, int StackIndex)
|
|
{//20120110
|
|
DataView dvl = new DataView(); DataView dv = new DataView();
|
|
try
|
|
{
|
|
//20120820
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(StackIndex);
|
|
if (devinfo.VirtualStack > 0) StackIndex = devinfo.VirtualStack;
|
|
|
|
int fid = GetManageTaskIndexfromMonitor(taskindex);
|
|
int Mankind = GetManageTaskKindIndexFromMonitor(taskindex);
|
|
int[] zxy = GetCoordinatesFromMonitorTask(taskindex);
|
|
StringBuilder zxystr = new StringBuilder();
|
|
if (zxy != null)
|
|
{
|
|
zxystr.Append((zxy[3].ToString().Length == 1 ? "0" + zxy[3].ToString() : zxy[3].ToString())).Append("-").Append(
|
|
((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString()))).Append("-").Append(
|
|
((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString())));
|
|
}
|
|
int laneway = 0;
|
|
dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", StackIndex)).Tables[0].DefaultView;
|
|
if (dvl.Count > 0)
|
|
{
|
|
laneway = Convert.ToInt32(dvl[0]["F_LaneDeviceIndex"]);
|
|
}
|
|
else
|
|
return;
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate,T_Base_Device WHERE (T_Base_Lane_Gate.F_LaneGateDeviceIndex = T_Base_Device.F_DeviceIndex) and (F_ZXY = '").Append(zxystr).Append("') and F_LaneIndex=").Append(laneway);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
|
|
if ((dv.Count > 0))// && (StackIndex == devinfo.VirtualStack)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("UPDATE T_Base_Device SET F_ManTaskReserve = (").Append(Mankind.ToString()).Append(fid.ToString()).Append(") WHERE (F_DeviceIndex = ").Append(dv[0][0].ToString()).Append(")");
|
|
dbo.ExceSQL(sql.ToString());
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
dvl.Dispose();
|
|
|
|
}
|
|
}
|
|
|
|
public int GetEndDeviceFromManage(int mti, int fid)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("SELECT FENDDEVICE FROM T_Manage_Task where FID={0} and F_ManageTaskKindIndex={1}", fid, mti)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0][0]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetNextMonitorTaskIndex(int taskindex)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
int mti = GetManageTaskKindIndexFromMonitor(taskindex);
|
|
int fid = GetManageTaskIndexfromMonitor(taskindex);
|
|
sql.Clear();
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_MonitorIndex>").Append(taskindex).Append(" order by F_MonitorIndex asc");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public int GetPriorMonitorTaskIndex(int taskindex)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
int mti = GetManageTaskKindIndexFromMonitor(taskindex);
|
|
int fid = GetManageTaskIndexfromMonitor(taskindex);
|
|
sql.Clear();
|
|
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_MonitorIndex<").Append(taskindex).Append(" order by F_MonitorIndex asc");
|
|
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32(dv[0]["F_MonitorIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public bool IfChangeForkCell(int stackno, string cell)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo where F_StackIndex={0} and F_ChangeForkCell='{1}'", stackno, cell)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 返回需要倒库更换货叉的倒库货位,“-”代表不需要更换货叉,T_Base_Lane_Gate里的倒库货位的虚拟设备是为了置【逻辑有物】
|
|
/// </summary>
|
|
/// <param name="task"></param>
|
|
/// <returns></returns>
|
|
public string IfLimitCellChangeFork(int task, int stackindex)
|
|
{//20110412
|
|
bool Ifchange = false;
|
|
int[] zxy = GetCoordinatesFromMonitorTask(task);
|
|
int xCoor = zxy[4];
|
|
StringBuilder zxystr = new StringBuilder();
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(stackindex);
|
|
int DeviceIndex = 0;
|
|
if (devinfo.VirtualStack > 0)
|
|
{
|
|
DeviceIndex = devinfo.VirtualStack;
|
|
}
|
|
else
|
|
{
|
|
DeviceIndex = stackindex;
|
|
}
|
|
zxystr.Append((zxy[3].ToString().Length == 1 ? "0" + zxy[3].ToString() : zxy[3].ToString())).Append("-").Append(
|
|
((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString()))).Append("-").Append(
|
|
((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString())));
|
|
object ob = dbo.GetSingle(string.Format("SELECT FLaneWay FROM ST_CELL WHERE fstack={1} and (FCELLCODE = '{0}')", zxystr.ToString(), stackindex));
|
|
int laneway = -1;
|
|
if (ob != null)
|
|
{
|
|
laneway = Convert.ToInt32(ob);
|
|
}
|
|
|
|
string TaskUseAwayFork = Model.CGeneralFunction.GetUseAwayFork(task);//1,2,3;0没分配货叉
|
|
|
|
int tempStartX = Model.CGeneralFunction.GetXCoorFromMonitor(task, DeviceIndex, 4);
|
|
int tempEndX = Model.CGeneralFunction.GetXCoorFromMonitor(task, DeviceIndex, 5);
|
|
int zeroXcoor = 0, UseAwayFork = 0;
|
|
sql.Clear();
|
|
sql.Append("SELECT F_ForwardLimitX,F_BackLimitX FROM T_Base_LaneInfo WHERE F_StackIndex = ").Append(DeviceIndex).Append(" and F_ForwardLimitX>0 and F_BackLimitX>0");
|
|
DataView dvl = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if ((devinfo.IfCorrelDoubleFork == "1") && (dvl.Count > 0))
|
|
{
|
|
|
|
//堆垛机的原点属性
|
|
char[] sp = new char[1] { ',' };
|
|
string[] yd = devinfo.StackZeroColLayer.Split(sp);
|
|
if (yd.GetLength(0) > 0)
|
|
{
|
|
zeroXcoor = Convert.ToInt32(yd[0]);
|
|
}
|
|
else
|
|
{
|
|
_DisassembleTaskError = "IfLimitCellChangeFork发生错误:堆垛机的原点坐标没有填写!";
|
|
return "-";
|
|
}
|
|
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
|
|
{//如果原点列坐标小于ForwardLimitX,检查ForwardLimitX至ForwardLimitX+(n-2);
|
|
if (((tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"])) >= 0) && (((tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"])) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (tempStartX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
|
|
}
|
|
else if (((tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"])) >= 0) && (((tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"])) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (tempEndX - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1);
|
|
}
|
|
if ((Convert.ToInt32(TaskUseAwayFork) > UseAwayFork) && (UseAwayFork!=0))
|
|
{
|
|
Ifchange = true ;
|
|
}
|
|
|
|
}
|
|
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
|
|
{//如果原点列坐标大于ForwardLimitX,检查ForwardLimitX至ForwardLimitX-(n-2).
|
|
if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempStartX + 1);
|
|
}
|
|
else if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - tempEndX + 1);
|
|
}
|
|
if ((Convert.ToInt32(TaskUseAwayFork) < UseAwayFork) && (UseAwayFork != 0))
|
|
{
|
|
Ifchange = true;
|
|
}
|
|
}
|
|
UseAwayFork = 0;
|
|
if (zeroXcoor < Convert.ToInt32(dvl[0]["F_BackLimitX"]))
|
|
{//如果原点列坐标小于F_BackLimitX,检查F_BackLimitX至F_BackLimitX-(n-2);
|
|
if (((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX) >= 0) && (((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempStartX));
|
|
}
|
|
else if (((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX) >= 0) && (((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - tempEndX));
|
|
}
|
|
if ((Convert.ToInt32(TaskUseAwayFork) < UseAwayFork) && (UseAwayFork != 0))
|
|
{
|
|
Ifchange = true;
|
|
}
|
|
}
|
|
else if (zeroXcoor > Convert.ToInt32(dvl[0]["F_BackLimitX"]))
|
|
{//如果原点列坐标大于F_BackLimitX,检查F_BackLimitX至F_BackLimitX+(n-2).
|
|
if (((tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"])) >= 0) && (((tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"])) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (tempStartX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
|
|
}
|
|
else if (((tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"])) >= 0) && (((tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"])) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (tempEndX - Convert.ToInt32(dvl[0]["F_BackLimitX"])));
|
|
}
|
|
if ((Convert.ToInt32(TaskUseAwayFork) >UseAwayFork) && (UseAwayFork != 0))
|
|
{
|
|
Ifchange = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (Ifchange == true)
|
|
{
|
|
string changeforkcell = GetChangeForkCell(laneway);
|
|
if (changeforkcell == "")
|
|
{
|
|
return "-";
|
|
|
|
}
|
|
else
|
|
{
|
|
return changeforkcell;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return "-";
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 多叉堆垛机换叉货位组,找到空闲的货位
|
|
/// </summary>
|
|
/// <param name="laneway"></param>
|
|
/// <returns></returns>
|
|
public string GetChangeForkCell(int laneway)
|
|
{
|
|
int fids = 0; string cell = ""; int minfids = int.MaxValue;
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex, F_ChangeForkCell FROM T_Base_LaneInfo where F_LaneDeviceIndex={0}", laneway)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
char[] cc = new char[1] { ';' };
|
|
string[] sp = dv[0]["F_ChangeForkCell"].ToString().Split(cc);
|
|
string ChangeForkCell = string.Empty;
|
|
int lanedev = 0;
|
|
for (int i = 0; i < sp.GetLength(0); i++)
|
|
{//T_Monitor_Task表新增 F_ChangeStackCell (和F_ChangeForkCell公用一个字段) "18001,01-30-02"
|
|
int.TryParse(sp[i], out lanedev);
|
|
if (lanedev > 0)
|
|
{//T_Base_LaneInfo表的 F_ChangeStackCell 和F_ChangeForkCell字段可以填写倒叉货位对应虚拟站台的设备索引
|
|
sp[i] = GetChangeCellFromLaneGate(laneway, lanedev);
|
|
}
|
|
ChangeForkCell = dv[0]["F_LaneDeviceIndex"].ToString() + "," + sp[i];
|
|
fids=Convert.ToInt32( dbo.GetSingle(string.Format("SELECT count(distinct F_ManageTaskIndex) as fids FROM T_Monitor_Task where F_ChangeStackCell='{0}'", ChangeForkCell)));
|
|
if (fids < minfids)
|
|
{
|
|
minfids = fids;
|
|
cell = sp[i];
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return cell;
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
}
|
|
public string GetChangeCellFromLaneGate(int laneway, int dev)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_ZXY FROM T_Base_Lane_Gate where F_LaneGateDeviceIndex={0} and F_LaneIndex={1}",dev,laneway)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0]["F_ZXY"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
public int GetChangeCellStationFromLaneGate(int laneway, string changecell)
|
|
{
|
|
DataView dv = new DataView();
|
|
try
|
|
{
|
|
dv = dbo.ExceSQL(string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate where F_ZXY='{0}' and F_LaneIndex={1}", changecell , laneway)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return Convert.ToInt32( dv[0]["F_LaneGateDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 以极限列为准分配货叉1,2,3.....
|
|
/// </summary>
|
|
/// <param name="limitx"></param>
|
|
/// <param name="laneway"></param>
|
|
/// <returns></returns>
|
|
public string GetLimitXForkNo(int limitx,int laneway)
|
|
{
|
|
char[] cc = new char[1]; string[] lc;
|
|
string UseAwayFork = "0";
|
|
DataView dvl = new DataView();
|
|
StringBuilder sbs = new StringBuilder();
|
|
object obj = new object();
|
|
try
|
|
{
|
|
#region 以极限列为准分配货叉
|
|
sbs.Clear();
|
|
sbs.Append("SELECT F_StackIndex FROM T_Base_StackInfo WHERE (F_LaneNo LIKE '%").Append(laneway).Append("%')");
|
|
obj = dbo.GetSingle(sbs.ToString());
|
|
if (obj != null)
|
|
{
|
|
devinfo = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(obj));
|
|
if (devinfo != null)
|
|
{
|
|
sbs.Remove(0, sbs.Length);
|
|
sbs.Append("SELECT F_ForwardLimitX,F_BackLimitX FROM T_Base_LaneInfo WHERE F_LaneDeviceIndex = ").Append(laneway).Append(" and F_ForwardLimitX>0 and F_BackLimitX>0");
|
|
dvl = dbo.ExceSQL(sbs.ToString()).Tables[0].DefaultView;
|
|
if ((devinfo.IfCorrelDoubleFork == "1") && (dvl.Count > 0))
|
|
{
|
|
//堆垛机的原点属性
|
|
cc = new char[1] { ',' };
|
|
lc = devinfo.StackZeroColLayer.Split(cc);
|
|
if (Convert.ToInt32(lc[0]) < Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
|
|
{//如果原点列坐标小于ForwardLimitX,检查ForwardLimitX至ForwardLimitX+(n-2);
|
|
if ((limitx - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) >= 0) && ((limitx - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (limitx - Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) + 1).ToString();
|
|
}
|
|
}
|
|
else if (Convert.ToInt32(lc[0]) > Convert.ToInt32(dvl[0]["F_ForwardLimitX"]))
|
|
{//如果原点列坐标大于ForwardLimitX,检查ForwardLimitX至ForwardLimitX-(n-2).
|
|
if ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - limitx >= 0) && ((Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - limitx <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (Convert.ToInt32(dvl[0]["F_ForwardLimitX"]) - limitx + 1).ToString();
|
|
}
|
|
}
|
|
|
|
if (Convert.ToInt32(lc[0]) < Convert.ToInt32(dvl[0]["F_BackLimitX"]))
|
|
{//如果原点列坐标小于F_BackLimitX,检查F_BackLimitX至F_BackLimitX-(n-2);
|
|
if ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - limitx >= 0) && ((Convert.ToInt32(dvl[0]["F_BackLimitX"]) - limitx <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (Convert.ToInt32(dvl[0]["F_BackLimitX"]) - limitx)).ToString();
|
|
}
|
|
}
|
|
else if (Convert.ToInt32(lc[0]) > Convert.ToInt32(dvl[0]["F_BackLimitX"]))
|
|
{//如果原点列坐标大于F_BackLimitX,检查F_BackLimitX至F_BackLimitX+(n-2).
|
|
if ((limitx - Convert.ToInt32(dvl[0]["F_BackLimitX"]) >= 0) && ((limitx - Convert.ToInt32(dvl[0]["F_BackLimitX"]) <= (devinfo.ForkAmount - 2))))
|
|
{
|
|
UseAwayFork = (devinfo.ForkAmount - (limitx - Convert.ToInt32(dvl[0]["F_BackLimitX"]))).ToString();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
return UseAwayFork;
|
|
#endregion
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
finally
|
|
{
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 需要换叉的极限货位,把终点坐标改为倒库货位坐标,T_Base_Lane_Gate里的倒库货位的虚拟设备是为了置【逻辑有物】
|
|
/// </summary>
|
|
/// <param name="taskindex">设备任务索引</param>
|
|
/// <param name="ChangeForkCell">可更改货叉的倒库货位编码</param>
|
|
public void ChangeEndCellCode(int taskindex, string ChangeForkCell, int StackIndex)
|
|
{//20120110
|
|
int laneway = 0;
|
|
DataView dvl = new DataView();
|
|
DataView dv = new DataView();
|
|
char[] cc = new char[1] { '-' };
|
|
string[] endCell = ChangeForkCell.Split(cc);
|
|
int fid = GetManageTaskIndexfromMonitor(taskindex);
|
|
int Mankind =GetManageTaskKindIndexFromMonitor(taskindex);
|
|
//dbo.TransBegin();
|
|
try
|
|
{
|
|
dvl = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex FROM T_Base_LaneInfo WHERE (F_StackIndex = {0})", StackIndex)).Tables[0].DefaultView;
|
|
if (dvl.Count > 0)
|
|
{
|
|
laneway = Convert.ToInt32(dvl[0]["F_LaneDeviceIndex"]);
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate,T_Base_Device WHERE (T_Base_Lane_Gate.F_LaneGateDeviceIndex = T_Base_Device.F_DeviceIndex) and (F_ZXY = '").Append(ChangeForkCell).Append("') and F_LaneIndex=").Append(laneway);
|
|
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Monitor_Task set F_AheadDetect=F_AheadDetect+'").Append(";N").Append(dv[0]["F_LaneGateDeviceIndex"].ToString()).Append(";R").Append(dv[0]["F_LaneGateDeviceIndex"].ToString())
|
|
.Append("', F_NumParam4=").Append(endCell[0]).Append(",F_NumParam5=").Append(endCell[1]).Append(",F_ChangeStackCell='").Append(laneway.ToString() + "," + ChangeForkCell
|
|
).Append("',F_NumParam6=").Append(endCell[2]).Append(" where F_ManageTaskIndex=").Append(fid).Append(" and F_ManageTASKKINDINDEX=").Append(Mankind).Append(" and F_DeviceIndex=").Append(StackIndex);
|
|
dbo.ExecuteSql(sql.ToString());
|
|
sql.Remove(0, sql.Length);
|
|
sql.Append("update T_Manage_Task set FExceptionNO=").Append(Model.CGeneralFunction.TASKCHANGEFORK).Append(" where FID=").Append(fid).Append(" and F_ManageTaskKindIndex=").Append(Mankind);
|
|
dbo.ExecuteSql(sql.ToString());
|
|
//解除关联
|
|
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET F_RELATIVECONTORLID = - 1 WHERE (F_ManageTaskKindIndex = {0}) AND (FID = {1})", Mankind, fid));
|
|
}
|
|
//dbo.TransCommit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
//dbo.TransRollback();
|
|
}
|
|
finally
|
|
{
|
|
dv.Dispose();
|
|
dvl.Dispose();
|
|
}
|
|
}
|
|
public string GetManageTaskStackFork(int manKind,int fid)
|
|
{
|
|
DataView dv = dbo.ExceSQL(string.Format("SELECT FUseAwayFork FROM T_Manage_Task WHERE (FID = {0}) AND (F_ManageTaskKindIndex = {1})",fid,manKind)).Tables[0].DefaultView;
|
|
if (dv.Count > 0)
|
|
{
|
|
return dv[0]["FUseAwayFork"].ToString();
|
|
}
|
|
else
|
|
{
|
|
return "0";
|
|
}
|
|
}
|
|
}
|
|
}
|