山东时代原料后WCS代码

6684 lines
331 KiB

using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System;
using System.Linq;
using CommLayerFactory;
using ICommLayer;
using DBFactory;
using CommonLib;
namespace WcfControlMonitorLib
{
/// <summary>
/// Creator:Richard.liu
/// ���ص�����
/// </summary>
public class CControl
{
int StackMutexXCoor = 4800;
int minStackMutexXCoor = 2400;
int StackZeroXCoor = 1950;
StringBuilder AheadDetectUnallow = new StringBuilder();//20110505
StringBuilder sql = new StringBuilder();
char[] dd = new char[1] { '.' };//20101124
string[] DS;//20101124
private Object thisLock = new Object();
DBOperator dbo = CStaticClass.dbo;
DBOperator dboM = CStaticClass.dboM;
Model.MDevice devinfo;
Model.MDevice devinfo11;//add by lyj 20180223
Model.MDevice devinfodaocha;//add by lyj 20171124
ISendDeviceOrder sdo;
CCommonFunction ccf = new CCommonFunction();
int _DeviceIdx = 0;//�豸����
int _routeID = 0;//·��Ψһ����
int _serialNumber = 0;//·���ϵ��豸����������������
int _ManageTaskIdx = 0;//������������
int _ManageKindIdx = 0;//������������
int _DeviceOrder = 0;//�豸����
int _LockedState = 0;
int _Associate = 0;
int _ManTaskReserve = 0;
string _AheadDetect = "";
int _NumParam1 = 0;
int _NumParam2 = 0;
int _NumParam3 = 0;
int _NumParam4 = 0;
int _NumParam5 = 0;
int _NumParam6 = 0;
string _TxtParam = "-";
int _DeviceKind = 0;
int _OutsideAltDevice = 0;
int _InsideAltDevice = 0;
int _StartDevice = 0;
int _EndDevice = 0;
int _RouteKind = 0;
//int _UseAwayFork = 1;
int _AgvNo = 65535;
string _CControlError = "";//���ص���������˵��
public string CControlError
{
get { return _CControlError; }
set
{
_CControlError = value;
RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", _CControlError);
OnRefreshMonitor(rme);
}
}
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(RefreshMonitorEventArgs e)
{
if (RefreshMonitor != null)
{
RefreshMonitor(e);
}
}
public CControl()
{
//dbo.Open();
}
//~CControl()
//{
// dbo.Close();
//}
public void StartOrder()
{
//���ȼ�����һ���������񵥵ġ���һ����������ʣ���еĵ�һ�����豸�Ƿ���ռ�ã���ռ����ִ����һ���������񵥣�
//Ȼ��������һ���豸��F_AheadDetect���Ƿ����������������㣬��ִ����һ���������񵥣�
//������ʼִ��ʱ����ͬ�����еĹ����豸F_AssociateDeviceIndex,׼�������豸��ָ�
//������ҵ��¼��״̬F_StatusΪ1,�����豸Ϊռ��״̬��T_Base_device��F_LockedState=�豸ָ���
//��������������д��������IO_Control������ִ��״̬FSTATUS=1;T_Manage_Task������ִ��״̬FSTATUS=1
//·����ϸ��F_LockedDeviceIndex�������ж�Ӧ�豸�������������ǹ����豸������
StringBuilder taskkind = new StringBuilder();
DataView dv = new DataView(); DataView dvM = new DataView();
try
{
#region//20140604 ɽ����������������֮ǰ�ȼ����� T_Base_Lane_Gate ����F_Top �ֶ�����1�� �У������½��ź�
//sql.Remove(0, sql.Length);
//sql.Append(string.Format("select * from T_Base_Lane_Gate where F_Top = 1"));
//dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
//if (dv.Count > 0) // ��û�����½��źŵ�վ̨
//{
// string bb = dv[0]["F_LaneGateDeviceIndex"].ToString();
// string cc = "";
// int devicebyte = 0;
// if (bb.Length == 6)
// {
// cc = bb.Substring(0, 5);
// }
// else
// {
// cc = bb;
// }
// int.TryParse(cc, out devicebyte);
// if (CStaticClass.GetDevicePhotoelectric(devicebyte, 1) != 1) // ���������л��ź�
// {
// sdo = CommModeCreate.CreateSendDeviceOrder(Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]));
// sdo.SendDeviceOrder(4, 0, 0, Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]), 0); // �����ͻ����ͱ�־λ4����λ������������ţ�
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("update T_Base_Lane_Gate set F_Top = 0 where F_LaneGateDeviceIndex = '{0}'", dv[0]["F_LaneGateDeviceIndex"].ToString()));
// dbo.ExceSQL(sql.ToString());
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "������վ̨�����½���������:", dv[0]["F_LaneGateDeviceIndex"].ToString().Substring(0, 5), dv[0]["F_LaneGateDeviceIndex"].ToString() + ",F_Top����λ0��");
// }
//}
#endregion//20140604
if (CStaticClass.Order == true )
{
taskkind.Append(" (F_ManageTaskKindIndex = 1 or F_ManageTaskKindIndex = 2 or F_ManageTaskKindIndex = 4) "); //�����������������ɵ��Զ�����
}
else
{
return;
}
dvM = new DataView();
char[] sep = new char[1] { '-' };
//���ù�������
sql.Remove(0, sql.Length);
//20120820
sql.Append("SELECT DISTINCT F_ManageTaskIndex AS MIndex,F_MonitorTaskLevel,F_ManageTaskKindIndex,F_SplitTime FROM T_Monitor_Task where ").Append(
taskkind.ToString()).Append(" order by F_ManageTaskKindIndex desc, F_MonitorTaskLevel desc,F_SplitTime asc, F_ManageTaskIndex asc");//20120616
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
try
{
//1����ȡÿ���������ݵĵ�һ���豸ָ��
sql.Remove(0, sql.Length);
sql.Append("select top 1 min(F_MonitorIndex) as minMidx,f_status from T_Monitor_Task where ").Append(taskkind.ToString()).Append(" and F_ManageTaskIndex = ").Append(dv[i]["MIndex"]).Append(" GROUP BY F_MonitorIndex, F_Status");
dvM = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvM.Count > 0)
{//20110412
if (dvM[0]["F_Status"].ToString() == "0" && dvM[0]["minMidx"] != DBNull.Value)
{
SendMonitorTask(Convert.ToInt32(dvM[0]["minMidx"]));
}
else
{
continue;
}
}
else
{
continue;
}
}
catch (Exception ex)
{
CControlError = string.Format("������������StartOrderʱ��{0}", ex.StackTrace + ex.Message);
}
}//for��������
//20091107
return;
}// dv.Count > 0
else
{
return;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dvM.Dispose();
}
}
/// <summary>
/// ��ȡÿ���������ݵĵ�һ���豸�Ƿ�������,true��ʾ��������false��ʾ����
/// </summary>
/// <param name="minMidx">����������</param>
/// <returns>true��ʾ��������false��ʾ����</returns>
public bool GetFirstDeviceIFLocked(int minMidx, bool checkLockedstate)
{
char[] sep = new char[1] { '-' };
int msgIdx = 0;//��Ϣ����
int adidx = 0;//�����豸���豸ָ������
DataView dv = new DataView();
try
{
//����Ҫ���͵���Ϣ
if (GetSendInfo(minMidx) == false)
{//20120420
return true;
}
int DeviceIdx = _DeviceIdx;//�豸����
int routeID = _routeID;//·��Ψһ����
int serialNumber = _serialNumber;//·���ϵ��豸����������������
int ManageTaskIdx = _ManageTaskIdx;//������������
int ManageKindIdx = _ManageKindIdx;//������������
int DeviceOrder = _DeviceOrder;//�豸����
int LockedState = _LockedState;
int Associate = _Associate;
int ManTaskReserve = _ManTaskReserve;
string AheadDetect = _AheadDetect;
int NumParam1 = _NumParam1;
int NumParam2 = _NumParam2;
int NumParam3 = _NumParam3;
int NumParam4 = _NumParam4;
int NumParam5 = _NumParam5;
int NumParam6 = _NumParam6;
string TxtParam = _TxtParam;
int DeviceKind = _DeviceKind;
int OutsideAltDevice = _OutsideAltDevice;
int InsideAltDevice = _InsideAltDevice;
int StartDevice = _StartDevice;
int EndDevice = _EndDevice;
int RouteKind = _RouteKind;
int AgvNo = _AgvNo;
#region �豸����ʱ�Ƿ��Զ��ĵ�
if (CStaticClass.DeviceErrorAutoModifyRoutePath == "1")
{//20100108
#region ֻ������RGV�йص����������жϸ�·��
//20100108 ���ͻ��Ľӻ��Խ�ָ������ĵ�
if ((_DeviceKind == 4) || ((_DeviceKind == 2) && ((_DeviceOrder == 3))) && (RouteKind != 3))
{
bool IfModify = false, IfUseNegativeDevice = false;//20100610
//20091102 RGV�ĵ�һ������ǰ�������˶�ָ���Ҫ����·��
if ((_DeviceKind == 4) && (_DeviceOrder == 7) &&
(ccf.GetSerialNumberFromRouteDevice(_routeID, _DeviceIdx) >
ccf.GetSerialNumberFromRouteDevice(_routeID, _NumParam1)))
{
sql.Remove(0, sql.Length);
sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX = 1)");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
//20091218
if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() == minMidx.ToString()))
{
IfModify = true;
IfUseNegativeDevice = true;//20100610
}
}
}
else if ((_DeviceKind == 4) && ((_DeviceOrder == 3) || (_DeviceOrder == 5)))
{//20100108�Դ������ͻ��Խ�Ӧ�ü������ƣ��ػ�������
devinfo = Model.CGetInfo.DeviceInfo[DeviceIdx];
if ((devinfo.RunState == 0) && (devinfo.HaveGoods == true))
{
IfModify = true;
IfUseNegativeDevice = false;//20100610
}
devinfo = null;
}
else
{
IfModify = true;
IfUseNegativeDevice = true;//20100610
}
if (IfModify == true)
{
int altsn = ccf.GetSerialNumberFromRouteDevice(_routeID, _OutsideAltDevice);
sql.Remove(0, sql.Length);
sql.Append("SELECT F_SerialNumber FROM T_Base_Device,T_Base_Route_Device,T_Base_Device_State where ").Append(
" T_Base_Device.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and F_ErrorCode =F_DeviceErrorIndex and ").Append(
" T_Base_Device_State.F_DeviceKindIndex = T_Base_Device.F_DeviceKindIndex AND T_Base_Device.F_ErrorCode > 0 AND ").Append(
" T_Base_Route_Device.F_SerialNumber > ").Append(_serialNumber).Append(" AND T_Base_Route_Device.F_SerialNumber > ").Append(
altsn).Append(" AND T_Base_Route_Device.F_RouteIDSub = ").Append(_routeID).Append(" and F_ErrorLevel=2 ");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
//�ж��ܷ��ĵ�;�����������ĵ�;��ManageTaskIdx��ManageKindIdx �ĵ�������ȫ�������ĵ�
if (GetUsableDestination(_ManageTaskIdx, _ManageKindIdx) == true)
{
return true;
}
}
#region RGVĿ��λ�ñ�ռ����Ҫ�����ĵ�
//20100610
devinfo = null;
if (_DeviceKind == 4)
{//RGV
devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, _serialNumber)[0]);
}
else
{//���ͻ��ͻ�
devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, _serialNumber)[0]);//RGV
int sn = 0;
if (devinfo != null)
{
sn = ccf.GetSerialNumberFromRouteDevice(_routeID, devinfo.DeviceIndex);
}
devinfo = Model.CGetInfo.GetDeviceInfo(CDisassembleTask.GetNextDevice(_routeID, sn)[0]);//�ӻ����ͻ�
}
if (devinfo != null)
{
if (devinfo.HaveGoods == true)
{//Ŀ��λ�ñ�ռ�ã������ĵ�
if (GetRGVIdleDestination(_ManageTaskIdx, _ManageKindIdx, devinfo.DeviceIndex, IfUseNegativeDevice) == true)
{
return true;
}
}
}
#endregion
}
}
#endregion
}
#endregion
if (DeviceKind == 6)
{//20100512 AGV
#region AGV
if (AgvNo != 65535)//�������Ѿ����䳵�ŵ�AGV��������������Ŷ�Ӧ���豸�����Ƿ�������
{
LockedState = Convert.ToInt32(dbo.GetSingle("SELECT F_LockedState FROM T_Base_Device where F_DeviceIndex=" + (DeviceIdx + AgvNo) + ""));
if (LockedState > 0) return true;
}
if (AheadDetectOK(minMidx, _AheadDetect) == true)//��ǰ����ͨ��
{
#region ˫��AGV���⣬��ͬ���Ĺ��������Ƿ�AheadDetectOK
//20100323
devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx);
if (devinfo.IfCorrelDoubleFork == "1")
{
int[] synctask = Model.CGeneralFunction.MutiForkIfSync(minMidx, _DeviceIdx, _DeviceKind);
if (synctask != null)//20120616
{
if ((synctask.GetLength(0) == 1) && (synctask[0] == minMidx)) return true;//20120616�ȴ�δ���ֵĿ�ͬ��ִ�е�����
string[] df = null;
Dictionary<int, string[]> mforkmonitorinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx);
foreach (int i in mforkmonitorinfo.Keys)
{
df = mforkmonitorinfo[i];
if (df != null)
{
if (AheadDetectOK(Convert.ToInt32(df[0]), df[1]) == false)//����������ǰ����ʧ��
{
return true;
}
#region ����ָ��ǵ�һ��ָ��ܷ���
int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
sql.Remove(0, sql.Length);
sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != df[0]))
{
return true;
}
}
#endregion
}
}
}
}
#endregion
return false;
}
else
{
return true;
}
#endregion
}
else
{//��AGV�豸�����ͻ����Ѷ�����RGV��
#region ��AGV�豸�����ͻ����Ѷ�����RGV��
//��һ���豸�Ƿ���ռ�ã�RGV�ͶѶ���Ҫ���Ƿֲ�����ʱ��ûִ������������ʱ�������µĵ�������
if (((_LockedState == 0) && (checkLockedstate == true)) || (checkLockedstate == false))
{
#region ����RGV���Ѷ������Ƿ񱻵�������ԤԼF_ManTaskReserve
if (_ManTaskReserve > 0)
{
devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx);
if (devinfo.IfCorrelDoubleFork == "1")
{
#region ��������
Dictionary<int, string[]> mforkmonInfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx);
bool iftrue = true;
int relfid = ccf.GetRELATIVECONTORLIDFromManageTask(_ManageKindIdx, _ManageTaskIdx);
if (_ManTaskReserve.ToString() == _ManageKindIdx.ToString() + _ManageTaskIdx.ToString())
{
iftrue = false;
}
else
{
if (relfid > 0)
{//20130704
dv = dbo.ExceSQL(string.Format("SELECT FID FROM T_Manage_Task where F_RELATIVECONTORLID={0} and F_ManageTaskKindIndex={1}", relfid, _ManageKindIdx)).Tables[0].DefaultView;
for (int mt = 0; mt < dv.Count; mt++)
{
if (_ManTaskReserve.ToString() == _ManageKindIdx.ToString() + dv[mt]["FID"].ToString())
{
iftrue = false;
}
}
}
}
if (iftrue == true)
{
UpdateAheadDetectUnallow(new StringBuilder(_DeviceIdx.ToString() + "������ԤԼ" + _ManTaskReserve.ToString().Substring(1)), minMidx);
return true;
}
#endregion
}
else
{
if (devinfo.DeviceKind == 1 || devinfo.DeviceKind == 4)//�Ϻ��ɵ��˴���ʱ���жϴ������ʹ�����
{
if (_ManTaskReserve.ToString() != _ManageKindIdx.ToString() + _ManageTaskIdx.ToString())
{
UpdateAheadDetectUnallow(new StringBuilder(_DeviceIdx.ToString() + "������ԤԼ" + _ManTaskReserve.ToString().Substring(1)), minMidx);
return true;
}
}
}
}
#endregion
//3��F_AheadDetect����(���⿪�ر����顰;��)
if (AheadDetectOK(minMidx, _AheadDetect) == true)//��ǰ����ͨ��
// if(true)
{
devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx);
if (_DeviceIdx == devinfo.VirtualStack)
{//20111020
AssignStackNo(_DeviceIdx, minMidx, ManageKindIdx, ManageTaskIdx);
return true;//20120906
}
#region �����Ѷ������⣬��ͬ����DoubleFork�Ƿ�AheadDetectOK
//20100323
devinfo = Model.CGetInfo.GetDeviceInfo(_DeviceIdx);
if (devinfo.IfCorrelDoubleFork == "1" && devinfo.DeviceKind == 1)
{
int[] synctask = Model.CGeneralFunction.MutiForkIfSync(minMidx, _DeviceIdx, _DeviceKind);
if (synctask != null)//20120616
{
if ((synctask.GetLength(0) == 1) && (synctask[0] == minMidx)) return true;//20120616�ȴ�δ���ֵĿ�ͬ��ִ�е�����
string[] df = null;
Dictionary<int, string[]> mforkmonitorinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, _DeviceIdx);
foreach (int i in mforkmonitorinfo.Keys)
{
if (Array.IndexOf<int>(synctask, i) >= 0)
{//20120906
df = mforkmonitorinfo[i];
if (df != null)
{
if (AheadDetectOK(Convert.ToInt32(df[0]), df[1]) == false)//����������ǰ����ʧ��
{
return true;
}
#region ����ָ��ǵ�һ��ָ��ܷ���
int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(Convert.ToInt32(df[0]));
int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(Convert.ToInt32(df[0]));
sql.Remove(0, sql.Length);
sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != df[0]))
{
return true;
}
}
#endregion
}
}
}
}
}
#endregion
//����ͬ�����еĹ����豸F_AssociateDeviceIndex
//4���Ƿ��й����豸���
#region �Ƿ��й����豸����
//AssociateDevice = ccf.GetAssociateDevice(minMidx);
if (_Associate != 0)
{
//5�������У��ҵ��������еĹ����豸���豸ָ��,�ܷ����У�
//�ظ��ݹ鵽2
//split = AssociateDevice.Split(sep);
adidx = _Associate;
if (adidx != 0)
{
#region �������
if (ccf.GetAssociateMonitor(minMidx) == 0)
{
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "�豸ָ�" + minMidx.ToString() + "�޷����ù�������" + adidx.ToString() + "�����ܷ��ʹ������");
OnRefreshMonitor(rmea);
return true;
}
if (GetFirstDeviceIFLocked(adidx, false) == false)
{
//6�����͹����豸����
//CStaticClass.MessageIndex++;
CStaticClass.MessageIndex = 1;
msgIdx = (CStaticClass.MessageIndex);
sdo = CommModeCreate.CreateSendDeviceOrder(_DeviceIdx);
//�ж��Ƿ�Ϊ�Ѷ����豸
bool sendok;
int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 }; //ccf.GetCoordinatesFromMonitorTask(adidx);//��������
if ((_DeviceKind == 1) || (_DeviceKind == 6))
{
//1���Ѷ�����4��RGV��6��AGV������Ҫ�Ż����ȣ��豸����F_NeedOptimize='1'��
//ֱ��д������T_Monitor_Task_Child������������
if (ccf.NeedOptimize(_DeviceIdx) == true)
{
ccf.InsertMonitorOptimizeChildTask(adidx);
sendok = true;
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder,
_DeviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]);
}
}
else if (_DeviceKind == 4)
{
if (ccf.NeedOptimize(_DeviceIdx) == true)
{
ccf.InsertMonitorOptimizeChildTask(adidx);
sendok = true;
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder, _DeviceIdx, gc[2]);
}
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, adidx, _DeviceOrder, _DeviceIdx, gc[5]);
}
if (sendok == false)
{
return true;
}
else
{
//8��������ҵ��¼��״̬F_StatusΪ1,�����豸Ϊռ��״̬��T_Base_device��F_LockedState=�豸ָ���
sql.Remove(0, sql.Length);
sql.Append("update T_Monitor_Task set F_StartTime='").Append(DateTime.Now.ToString("u")).Append("',F_Status='1' where F_MonitorIndex=").Append(adidx);
dbo.ExceSQL(sql.ToString());
//���ص�ԭ���豸ֵ
_DeviceIdx = DeviceIdx;//�豸����
_routeID = routeID;//·��Ψһ����
_serialNumber = serialNumber;//·���ϵ��豸����������������
_ManageTaskIdx = ManageTaskIdx;//������������
_ManageKindIdx = ManageKindIdx;//������������
_DeviceOrder = DeviceOrder;//�豸����
_LockedState = LockedState;
_Associate = Associate;
_ManTaskReserve = ManTaskReserve;
_AheadDetect = AheadDetect;
_NumParam1 = NumParam1;
_NumParam2 = NumParam2;
_NumParam3 = NumParam3;
_NumParam4 = NumParam4;
_NumParam5 = NumParam5;
_NumParam6 = NumParam6;
_TxtParam = TxtParam;
_DeviceKind = DeviceKind;
_OutsideAltDevice = OutsideAltDevice;
_InsideAltDevice = InsideAltDevice;
_StartDevice = StartDevice;
_EndDevice = EndDevice;
_RouteKind = RouteKind;
_AgvNo = AgvNo;
return false;
}
}
else
{
return true;
}
#endregion
}
else//
{
#region MyRegion
//���ص�ԭ���豸ֵ
_DeviceIdx = DeviceIdx;//�豸����
_routeID = routeID;//·��Ψһ����
_serialNumber = serialNumber;//·���ϵ��豸����������������
_ManageTaskIdx = ManageTaskIdx;//������������
_ManageKindIdx = ManageKindIdx;//������������
_DeviceOrder = DeviceOrder;//�豸����
_LockedState = LockedState;
_Associate = Associate;
_ManTaskReserve = ManTaskReserve;
_AheadDetect = AheadDetect;
_NumParam1 = NumParam1;
_NumParam2 = NumParam2;
_NumParam3 = NumParam3;
_NumParam4 = NumParam4;
_NumParam5 = NumParam5;
_NumParam6 = NumParam6;
_TxtParam = TxtParam;
_DeviceKind = DeviceKind;
_OutsideAltDevice = OutsideAltDevice;
_InsideAltDevice = InsideAltDevice;
_StartDevice = StartDevice;
_EndDevice = EndDevice;
_RouteKind = RouteKind;
#endregion
CControlError = string.Format("���ֵ��������õ����豸ָ������ϸ·���ļ������Ĺ����豸ָ�ƥ�䣬ϵͳ��Ϊû�й����豸ָ�����");
return false;
}
}
else
{
#region ���ص�ԭ���豸ֵ
//���ص�ԭ���豸ֵ
_DeviceIdx = DeviceIdx;//�豸����
_routeID = routeID;//·��Ψһ����
_serialNumber = serialNumber;//·���ϵ��豸����������������
_ManageTaskIdx = ManageTaskIdx;//������������
_ManageKindIdx = ManageKindIdx;//������������
_DeviceOrder = DeviceOrder;//�豸����
_LockedState = LockedState;
_Associate = Associate;
_ManTaskReserve = ManTaskReserve;
_AheadDetect = AheadDetect;
_NumParam1 = NumParam1;
_NumParam2 = NumParam2;
_NumParam3 = NumParam3;
_NumParam4 = NumParam4;
_NumParam5 = NumParam5;
_NumParam6 = NumParam6;
_TxtParam = TxtParam;
_DeviceKind = DeviceKind;
_OutsideAltDevice = OutsideAltDevice;
_InsideAltDevice = InsideAltDevice;
_StartDevice = StartDevice;
_EndDevice = EndDevice;
_RouteKind = RouteKind;
#endregion
return false;
}
#endregion
}
else
{
#region �Ϻ��ɵ���19003������ȡ��ʱ �ж� ͬ���Ƿ��Ѿ���2�����ϵȴ��ֳ�����������Ҫȥ�ò��޳� �����������ĵ�
if (DeviceIdx == 19003 && DeviceOrder == 2)
{
int fid = ccf.GetManageTaskIndexfromMonitor(minMidx);
int mti = ccf.GetManageTaskKindIndexFromMonitor(minMidx);
int endlayer = ccf.GetFEndLayerFromManageTask(mti, fid);
string barcode = ccf.GetBarCodeFromMonitor(minMidx);
sql.Remove(0, sql.Length);
sql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_LaneOut=0 and F_Postion = ").Append(endlayer); //F_LaneOut=0 ��ʾ���������� �������Ƴ�ȥF_LaneOut=1
if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count == 0)
{
//�ж�û�е��˲��Ļ������� ���Ӵ˲������Ļ�������
sql.Remove(0, sql.Length);
sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 AND ((FEndLayer = ").Append(endlayer).Append(") or (FStartLayer = ").Append(endlayer).Append("))");
if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count == 0)
{
//������������������ �ҳ�Ϊ10000 ��ֹ��Ϊendlayer
int stack = 10000;
sql.Remove(0, sql.Length);
sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 1 AND (FEndLayer = ").Append(endlayer).Append(") and (FSTACK = ").Append(stack).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 1)
{
dbo.TransBegin(IsolationLevel.ReadCommitted);
sql.Remove(0, sql.Length);
sql.Append("delete from T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(fid).Append(") and (F_ManageTASKKINDINDEX = ").Append(mti).Append(")");
dbo.ExceSQL(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("delete from T_Manage_Task WHERE FCONTROLTASKTYPE = 1 AND (FID = ").Append(fid).Append(") and (F_ManageTaskKindIndex = ").Append(mti).Append(")");
dbo.ExceSQL(sql.ToString());
if (mti == 1)
{
sql.Remove(0, sql.Length);
sql.Append("update IO_CONTROL set CONTROL_STATUS=100 WHERE (CONTROL_ID = ").Append(fid).Append(")");
dboM.ExceSQL(sql.ToString()); //���߹���Ҫ�ĵ�100
}
CommonClassLib.CCarryConvert.WriteDarkCasket("��ǰ����ʱ����"+barcode,
"�Զ�ɾ�������������ĵ�control_id:",
fid.ToString(),
"�жϵ�Ҫȥ���޳�����2������δ�ֳ�����" );
dbo.TransCommit();
}
}
}
}
#endregion
return true;
}
}
else
{
return true;
}
#endregion
}
}
catch (Exception ex)
{
dbo.TransRollback();
CControlError = string.Format("������������GetFirstDeviceIFLockedʱ��{0}", ex.StackTrace + ex.Message);
return true;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// ����ָ���豸������ִ���Ⱦ������Ƿ�����
/// </summary>
/// <param name="minMidx">����Ψһ����</param>
/// <returns>�Ƿ�����ͨ����true��ʾ�豸ִ���������Ⱦ���������</returns>
public bool AheadDetectOK(int minMidx, string _AheadDetect)
{
AheadDetectUnallow.Remove(0, AheadDetectUnallow.Length);//20110505
int[] States;
string dtime = DateTime.Now.ToString("u");
dtime = dtime.Substring(0, dtime.Length - 1);
int DeviceIdx = _DeviceIdx;
int TaskIdx = minMidx;
int fid = ccf.GetManageTaskIndexfromMonitor(TaskIdx);
int mti = ccf.GetManageTaskKindIndexFromMonitor(TaskIdx);
int DeviceKind = ccf.GetDeviceKindIdx(DeviceIdx);//20100617
int order = ccf.GetDeviceOrderFromMonitor(TaskIdx);
int StartDevice = _StartDevice;//��ǰ������������
int EndDevice = _EndDevice;//��ǰ���������յ�
#region ���䶥�������ڸ�λ�Ķ�������
//if ((DeviceIdx >= 35000) && (DeviceIdx <= 35003)&&(order ==4))
//{//20120110���䶥�������ڸ�λ�Ķ�������
// if (_AheadDetect.IndexOf("D-32036.6") >= 0)
// {
// if(CStaticClass.GetDevicePhotoelectric(32036,7)==1)
// {
// InsertUpDeviceUP(32036, mti, fid,minMidx);
// }
// }
// else if (_AheadDetect.IndexOf("D-32049.6") >= 0)
// {
// if (CStaticClass.GetDevicePhotoelectric(32049, 7) == 1)
// {
// InsertUpDeviceUP(32049, mti, fid, minMidx);
// }
// }
//}
#endregion
//20100706
devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx);
if (ccf.GetBarCodeFromMonitor(minMidx) == "brbrbr")//����ָ����������20120110
{
int zc = 1, xc = 0;
GetStackRunX_Zcoor(DeviceIdx, out xc, out zc);
if (devinfo.RunState == 0 && xc == 0)
{
return true;
}
else
{
return false;
}
}
if (DeviceKind == 1 && order == 1)//��ԭ����������20120110
{
if (devinfo.RunState == 0)
{
return true;
}
else
{
return false;
}
}
//����(���⿪�ر����顰;��)
DataView dv = new DataView();
DataView dvdv = new DataView();
DataView barcodeDV = new DataView();
try
{
if (devinfo.CommType == "OPCClient")//20100706 ֻ��OPCClientͨѶ���͵ļ����豸״̬
{
#region OPCͨѶ�豸�����豸�Ƿ�����
// //gds = CommModeCreate.CreateGetDeviceState(DeviceIdx);
// try
// {
// //States = gds.GetDeviceState(DeviceIdx, TaskIdx);//1����,2������,5�豸��
// if (DeviceKind == 13)
// {
// DeviceIdx = GetNowDevice(minMidx);
// }
// States = CStaticClass.GetDeviceState(DeviceIdx);
// }
// catch (Exception ex)
// {//20110505
// RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "��ǰ����ʱ��" + ex.Message);
// OnRefreshMonitor(rmea);
// return false;
// }
// if (States == null)//û���յ��κη���ֵ
// {
// RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "��������ʱ����ǰ����û�յ�PLC���ݣ�");
// OnRefreshMonitor(rmea);
// return false;
// }
// if (((States[1] == 1) || (States[1] >= 30)) && ((DeviceKind != 13) && (DeviceKind != 31)))//���л��߹���
// {
// if (States[1] >= 30)
// {
// devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIdx);
// int ErrId = States[1];
// //20110505
// errs = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(_DeviceKind.ToString() + States[1].ToString()));
// AheadDetectUnallow.Append(DeviceIdx + "�й��ϣ�" + errs.ErrorName);
// //20090910
// //�й���¼�Ĺ����豸�������ţ������ظ�����
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_DeviceIndex FROM T_Base_Device where F_DeviceIndex=" ).Append( DeviceIdx ).Append( " and F_ErrorTaskNo=" ).Append( TaskIdx );
// ;
// dt = dbo.ExceSQL(sql.ToString()).Tables[0];
// if (dt.Rows.Count >= 1)
// {
// //20110505
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// //��¼�������ϵ��豸����ִ�е�������
// sql.Remove(0, sql.Length);
// sql.Append("update T_Base_Device set F_ErrorTaskNo= " ).Append( TaskIdx ).Append( " where F_DeviceIndex= " ).Append( DeviceIdx);
// dbo.ExceSQL(sql.ToString());
// if (CStaticClass.IsEquals(devinfo.ReturnMessage, States, 2) == true) return false;
// //if ((_DeviceKind == 2) || (_DeviceKind == 4))
// //{//���ͻ���������
// // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx);
// // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0);
// //}
// //if (_DeviceKind == 1) //�Ѷ�����RGV
// //{
// // sdo = CommModeCreate.CreateSendDeviceOrder(DeviceIdx);
// // sdo.SendDeviceOrder(2, 0, 0, DeviceIdx, 0, 0, 0, 0, 0, 0);
// //}
// //20110505
// RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", "�豸����" + DeviceIdx + "�й��ϣ�" + errs.ErrorName);
// OnRefreshMonitor(rmea);
// rmea = new RefreshMonitorEventArgs("notifyIcon1", "����:" + devinfo.DeviceName + "," + DeviceIdx + "�������ϣ�" + errs.ErrorName);
// OnRefreshMonitor(rmea);
// if (mti == 1)
// {
// sql.Remove(0, sql.Length);
// sql.Append("update IO_Control set ERROR_TEXT='" ).Append( "׼��ִ�й�������ʱ��" ).Append( devinfo.DeviceName ).Append( "," ).Append( DeviceIdx ).Append( errs.ErrorName ).Append( "' where Control_ID=" ).Append( fid);
// dboM.ExceSQL(sql.ToString());
// }
// sql.Remove(0, sql.Length);
// sql.Append("update T_Manage_Task set FERRORCODE='" ).Append( "׼��ִ�й�������ʱ��" ).Append( devinfo.DeviceName ).Append( "," ).Append( DeviceIdx ).Append( errs.ErrorName ).Append( "' where F_ManageTaskKindIndex=" ).Append( mti ).Append( " and FID=" ).Append( fid);
// dbo.ExceSQL(sql.ToString());
// CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null);
// OnDataChange("����ָ����ǰ����ʱ��",cea);
// }
// return false;
// }
// #endregion
//}
//else
//{
// #region �Ӽ���20100319 AGV��ָ��67������AGV�Ų���ʱ��������1219���ͳ�ָ�1220��ָ������ִ�л����ѷ��ͣ���ǰ����ʧ�ܣ���Ҫ�ȴ�
// //
// //if (ccf.GetDeviceOrderFromMonitor(minMidx) == 67)
// //{
// // dv = dbo.ExceSQL("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = 1219) AND (F_DeviceCommandIndex = 6) AND (F_Status > 0)").Tables[0].DefaultView;
// // if (dv.Count > 0)
// // {
// // return false;
// // }
// // dv = dbo.ExceSQL("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = 1220) AND (F_Status > 0)").Tables[0].DefaultView;
// // if (dv.Count > 0)
// // {
// // return false;
// // }
// //}
#endregion
}
#region �߶��豸U������������������
//if ((DeviceKind == 13) && (order==6))
//{//20120328
// int arrdevice = ccf.GetDeviceArrowFromMonitor(minMidx);
// int startdevice = ccf.GetDeviceStartFromMonitor(minMidx);
// object ob0 = dbo.GetSingle(string.Format("SELECT count(F_MonitorIndex) as UTaskCount FROM T_Monitor_Task where F_DeviceIndex={0} and F_DeviceCommandIndex={1} and F_Status>0", DeviceIdx, order));
// DataView dvu = dbo.ExceSQL(string.Format("SELECT F_MaxRunTask,F_OutputUDevice,F_InputUDevice FROM T_Base_UArea WHERE (F_UCODE = {0})", DeviceIdx)).Tables[0].DefaultView;
// if ((dvu.Count>0) && (ob0 != null))
// {
// if (arrdevice == Convert.ToInt32(dvu[0]["F_OutputUDevice"]))
// {
// //if (Convert.ToInt32(ob0) >= Convert.ToInt32(dvu[0]["F_MaxRunTask"]))
// //{
// // AheadDetectUnallow.Append("U�ߣ�" + DeviceIdx.ToString() + "�������������Ѿ����ޣ�");
// // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// // return false;
// //}
// }
// else
// {
// if ((Convert.ToInt32(ob0) >= (Convert.ToInt32(dvu[0]["F_MaxRunTask"]) - 2)) && (startdevice == Convert.ToInt32(dvu[0]["F_InputUDevice"])))
// {
// AheadDetectUnallow.Append("U�ߣ�" + DeviceIdx.ToString() + "�������������Ѿ����ޣ�");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// if ((Convert.ToInt32(ob0) >= (Convert.ToInt32(dvu[0]["F_MaxRunTask"]) - 1)) && (startdevice != Convert.ToInt32(dvu[0]["F_InputUDevice"])))
// {
// //AheadDetectUnallow.Append("U�ߣ�" + DeviceIdx.ToString() + "�������������Ѿ����ޣ�");
// //UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// //return false;
// }
// }
// }
//}
#endregion
#region ��ǰ������Ϣ����
if ((_AheadDetect != "") && (_AheadDetect != null))
{
char[] cc = new char[1];
cc[0] = ';';
string[] AheadDetect = _AheadDetect.Split(cc);
string[] sp;
//ͨ�������๤������IGetDeviceState��������
//IGetDeviceState GDS;
int s = 0;
//int[] sss;
int fs = 1;
//int[] fsss;
//��ȡ���翪������ֵ
int devk = 0;
if (CStaticClass.TestSendOrder == false) //�����Է���ʱ��������ǰ�������ж�
{
for (int i = AheadDetect.GetLowerBound(0); i <= AheadDetect.GetUpperBound(0); i++)
{
if (AheadDetect[i].Trim().Length <= 0) continue;
#region �����߼���̽��
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "H")//�����߼���̽��
{
devk = ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)));
if (devk == 9)
{//��̨��Ҫ�ӹ����豸����ȡ
//sql.Remove(0, sql.Length);
//sql.Append("SELECT FID FROM T_ITEMDEVICESTATION WHERE (FCODE = '" ).Append( AheadDetect[i].Trim().Substring(1) ).Append( "') AND (FSTATUS = '1002')");
//if (dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0)
//{
// fs = fs & 1;
//}
//else
//{
// fs = fs & 0;
//}
}
else
{
//�����豸����ȡ
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex, F_HaveGoods FROM T_Base_Device where F_DeviceIndex=").Append(
Convert.ToInt32(AheadDetect[i].Trim().Substring(1)));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
int havegoods = -1;
if (Convert.ToInt32(dvdv[0]["F_HaveGoods"]) == 0)//20110505
{
havegoods = 0;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "�豸�߼����");
}
else
{
havegoods = 1;
}
fs = fs & havegoods;
}
}
continue;
}
#endregion
#region �����߼���̽��
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "N")//�����߼���̽��
{
devk = ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)));
if (devk == 9)
{//��̨��Ҫ�ӹ����豸����ȡ;20101028���������������ƻ�̨��վ̨�Ƿ�����
//if (dboM.ExceSQL("SELECT FID FROM T_ITEMDEVICESTATION WHERE (FCODE = '" + AheadDetect[i].Trim().Substring(1) + "') AND (FSTATUS = '1002')").Tables[0].DefaultView.Count > 0)
//{
// fs = fs & 1;
//}
//else
//{
// fs = fs & 0;
//}
}
else
{
//�����豸����ȡ
// 20140311 ���ж�AheadDetect[i].Trim().Substring(1)���ȣ�������6λ����ȡǰ5λ ɽ��
string idev = string.Empty;
if (AheadDetect[i].Trim().Substring(1).Length == 6)
{
idev = AheadDetect[i].Trim().Substring(1).Substring(0, 5);
}
else
{
idev = AheadDetect[i].Trim().Substring(1);
}
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceIndex, F_HaveGoods FROM T_Base_Device where F_DeviceIndex=").Append(
Convert.ToInt32(idev));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
if (Convert.ToInt32(dvdv[0]["F_HaveGoods"]) > 0)//20110505
{
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "�豸�߼����");
}
s = s + Convert.ToInt32(dvdv[0]["F_HaveGoods"]);
}
}
continue;
}
#endregion
#region �����豸�Ƿ�����
//20090803�����豸�Ƿ�����idle
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "I")//�����豸�Ƿ�����idle
{
int idev = Convert.ToInt32(AheadDetect[i].Trim().Substring(1));
if (idev.ToString().Length == 6)
{
idev = Convert.ToInt32(idev.ToString().Substring(0, 5));
}
States = CStaticClass.GetDeviceState(idev);
#region 20210326_�Ϻ��ɵ����������������dz�������������19003��19004��ͬʱ�����Ƿ�������ִ�еĻ��������������У���ִ��
//if ((idev == 19003 || idev == 19004) && DeviceIdx != 19005)
//{
// sql.Remove(0, sql.Length);
// sql.Append(
// "SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 AND FSTATUS <> 0");
// if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0)
// {
// AheadDetectUnallow.Append("19005����ִ�л�������");
// States[1] = 1;
// }
//}
#endregion
if (States != null)
{
if ((States[1] == 5) && (ccf.GetDeviceKindIdx(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == 2))
{//20120409ֻ�����ͻ������ɿ���Ϊ����
States[1] = 0;
}
if (DeviceHandTaskIfRun(Convert.ToInt32(AheadDetect[i].Trim().Substring(1))) == true)
{//20120207
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "�ֹ��������߱��������������У�");
States[1] = 1;
}
if (States[1] != 0)//20110505
{
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "�豸�����У�");
}
s = s + States[1];
}
continue;
}
#endregion
#region ����F_NumParam1��F_NumParam4�豸���������е�����
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "U")//����F_NumParam1��F_NumParam4�豸���������е�����
{
sql.Clear();
sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_NumParam1 = {0} or F_NumParam4 = {0}) AND (F_Status > 0)", Convert.ToInt32(AheadDetect[i].Trim().Substring(1))));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "����������ִ�У�");
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region ��������������ִ����������
//if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "J")//��������������ִ������������J12008,2��
//{
// cc[0] = ',';
// sp = AheadDetect[i].Trim().Substring(1).Split(cc);
// if (sp.GetLength(0) == 2)
// {
// sql.Clear();
// sql.Append(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex={0}) AND (F_Status > 0)", Convert.ToInt32(sp[0])));
// dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvdv.Count >= Convert.ToInt32(sp[1]))
// {
// s = s + 1;
// AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "�����������ޣ�");
// }
// else
// {
// s = s + 0;
// }
// }
// continue;
//}
#endregion
//�Ϻ��ɵ�����˫���������� ������ִ�к�����Զ����
#region �ɵ�����˫����λ����������λʱ��ϵͳ��δ���ɵĶ�Ӧ��������λ��������
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "J")
{
int Index = ccf.GetManageTaskIndexfromMonitor(minMidx);
int Mk = ccf.GetManageTaskKindIndexFromMonitor(minMidx);
sql.Clear();
sql.Append(string.Format("SELECT FLANEWAY,FENDCELL,F_RELATIVECONTORLID FROM T_Manage_Task WHERE (FID = {0} and F_ManageTaskKindIndex={1} )", Index, Mk));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
if ((Convert.ToInt32(dvdv[0]["FENDCELL"].ToString().Substring(0, 2)) % 4 == 1) || (Convert.ToInt32(dvdv[0]["FENDCELL"].ToString().Substring(0, 2)) % 4 == 0))
{
s = s + 0;//Զ�Ѷ��� ֱ����
}
else//��ǰ���е��� ����ȡ������
{
string ZZ = "";
int ZZZ = 0;
ZZZ = Convert.ToInt32(Convert.ToInt32(dvdv[0]["FENDCELL"].ToString().Substring(0, 2)));
//if (Convert.ToInt32(dvdv[0]["FENDCELL"].ToString().Substring(0, 2)) % 4 == 2)
//{
// ZZ = string.Format("{0:D2}", ZZZ - 1);
//}
//else
if (Convert.ToInt32(dvdv[0]["FENDCELL"].ToString().Substring(0, 2)) % 4 == 3)
{
ZZ = string.Format("{0:D2}", ZZZ + 1);
}
string cell = ZZ + dvdv[0]["FENDCELL"].ToString().Substring(2, (dvdv[0]["FENDCELL"].ToString().Length - 2));
sql.Clear();
sql.Append(string.Format("SELECT * FROM IO_CONTROL WHERE (END_DEVICE_CODE = '{0}' and CONTROL_STATUS='0' )", cell));
DataView dvdd = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdd.Count > 0)
{
//����ϵͳ����δ��ȡ��
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "��������/�ƿ�ȡ��ʱ������Զ��������δ��ȡ��Զ����������ȡִ�к�����ȡ��������");
}
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE (FENDCELL = '{0}' and ((FCONTROLTASKTYPE =1)or (FCONTROLTASKTYPE =3)) )", cell));
DataView dvda = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvda.Count == 1)//
{
//�жϸ��������޲���
if ((Convert.ToInt32(dvda[0]["FIntoStepOK"]) == 0))//���
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "��������/�ƿ�����ȡ���ж�ӦԶ����δ���֣�");
}
else//�Ѿ�����������Ӧ�ĶѶ���ȡ��ָ������˾Ϳ���ͨ��
{
// ���������ж� �����ǹ������� ��������ͨ��
//if ((Convert.ToInt32(dvdv[0]["F_RELATIVECONTORLID"]) == Convert.ToInt32(dvda[0]["F_RELATIVECONTORLID"])) && (-1 != Convert.ToInt32(dvda[0]["F_RELATIVECONTORLID"])))
//{
// s = s + 0;//�����������У���������ʱ�ȷ�Զ�����༴��
//}
//else
//{
string[] split = new string[3];
split = cell.Split('-');
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE (F_NumParam4 = {0} and F_NumParam5 = {1} and F_NumParam6 = {2} )", Convert.ToInt32(split[0]), Convert.ToInt32(split[1]), Convert.ToInt32(split[2])));
DataView dvdb = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdb.Count > 0)//Զ����ȡ��������δ���� ���ⲻ��ͨ��
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "��������/�ƿ�����ȡ���ж�ӦԶ�����������ƿ�δ���ɣ�");
}
else
{
s = s + 0;//Զ����ȡ�������Ѿ�����
}
//}
}
}
else if (dvda.Count > 1)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "��������/�ƿ�����ȡ���ж�Ӧ����������Զ�����������ƿ�δ���ɣ�");
}
else
{
s = s + 0;//��û�ж�Ӧ����������������
}
}
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region �ɵ�����˫����λ���������ƿ��ڲ���λʱ��ϵͳ����δ���ɵĶ�Ӧ��������λ��������
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "M")//
{
int Index = ccf.GetManageTaskIndexfromMonitor(minMidx);
int Mk = ccf.GetManageTaskKindIndexFromMonitor(minMidx);
sql.Clear();
sql.Append(string.Format("SELECT FLANEWAY,FSTARTCELL,F_RELATIVECONTORLID FROM T_Manage_Task WHERE (FID = {0} and F_ManageTaskKindIndex={1} )", Index, Mk));
dvdv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdv.Count > 0)
{
if ((Convert.ToInt32(dvdv[0]["FSTARTCELL"].ToString().Substring(0, 2)) % 4 == 2) || (Convert.ToInt32(dvdv[0]["FSTARTCELL"].ToString().Substring(0, 2)) % 4 == 3))
{
s = s + 0;//���Ѷ��� ֱ�ӳ�
}
else //
{
string ZZ = "";
int ZZZ = 0;
ZZZ = Convert.ToInt32(Convert.ToInt32(dvdv[0]["FSTARTCELL"].ToString().Substring(0, 2)));
//if (Convert.ToInt32(dvdv[0]["FSTARTCELL"].ToString().Substring(0, 2)) % 4 == 1)
//{
// ZZ = string.Format("{0:D2}", ZZZ + 1);
//}
//else
if (Convert.ToInt32(dvdv[0]["FSTARTCELL"].ToString().Substring(0, 2)) % 4 == 0)
{
ZZ = string.Format("{0:D2}", ZZZ - 1);
}
string cell = ZZ + dvdv[0]["FSTARTCELL"].ToString().Substring(2, (dvdv[0]["FSTARTCELL"].ToString().Length - 2));
sql.Clear();
sql.Append(string.Format("SELECT * FROM IO_CONTROL WHERE (START_DEVICE_CODE = '{0}' and CONTROL_STATUS='0' )", cell));
DataView dvdd = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdd.Count > 0)
{
//����ϵͳ����δ��ȡ��
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "Զ������/�ƿ�ȡ��ʱ�����н���������δ��ȡ��������������ȡִ�к�����ȡԶ������");
}
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE (FSTARTCELL = '{0}' and (FCONTROLTASKTYPE =2 or FCONTROLTASKTYPE =3) )", cell));
DataView dvda = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvda.Count == 1)//�ж�Ӧ�Ľ������������ƿ�����
{
//�жϸ��������޲���
if ((Convert.ToInt32(dvda[0]["FIntoStepOK"]) == 0))//ͬ�յ�δ����
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "Զ������/�ƿ�����ȡ���ж�Ӧ����������δ���֣�");
}
else//��ͬ�յ��Ѿ�����������Ӧ�ĶѶ���ȡ��ָ������˾Ϳ���ͨ��
{
//// ���������ж� �����ǹ������� ��������ͨ��
//if ((Convert.ToInt32(dvdv[0]["F_RELATIVECONTORLID"]) == Convert.ToInt32(dvda[0]["F_RELATIVECONTORLID"])) && (-1 != Convert.ToInt32(dvda[0]["F_RELATIVECONTORLID"])))
//{
// s = s + 0;//�����������У���������ʱ�ȷ����Ѷ����༴��
//}
//else
//{
// ���������ж� ���ǹ�����������ͨ��
string[] split = new string[3];
split = cell.Split('-');
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE (F_NumParam1 = {0} and F_NumParam2 = {1} and F_NumParam3 = {2} )", Convert.ToInt32(split[0]), Convert.ToInt32(split[1]), Convert.ToInt32(split[2])));
DataView dvdb = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvdb.Count > 0)//������ȡ��������δ���� ���ⲻ��ͨ��
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "Զ������/�ƿ�����ȡ���ж�Ӧ����������δ���ɣ�");
}
else
{
s = s + 0;//������ȡ�������Ѿ�����
}
//}
}
}
else if (dvda.Count > 1)
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "Զ������/�ƿ�����ȡ�����������϶�Ӧ���������������˹����飡");
}
else
{
s = s + 0;//��û������Ӧ�� ��������δ���ɵ�����
}
}
}
else
{
s = s + 0;
}
continue;
}
#endregion
#region �����豸�Ƿ񱻶Ѷ���ԤԼ
//20120409
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "R")//�����豸�Ƿ񱻶Ѷ���ԤԼ
{
sql.Remove(0, sql.Length);
sql.Append("select F_ManTaskReserve from T_Base_Device where F_ManTaskReserve>0 and F_DeviceIndex=").Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)));
object obr = dbo.GetSingle(sql.ToString());
if (obr != null)
{
if (obr.ToString() != (mti.ToString() + fid.ToString()))
{
s = s + 1;
AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "����������:").Append(obr.ToString()).Append("ԤԼ��");
}
else
{
s = s + 0;
}
}
continue;
}
#endregion
#region �����豸�����ź�
//�����豸�Ĺ����źţ�D-12001.0��ʾ���ͻ�12001�����ڿ������D12001.1��ʾ���ͻ�12001�����ڿ�������
//D-12001.2��ʾ���ͻ�12001�Ķ�����λ���ߵ�λ����D12001.3��ʾ���ͻ�12001�Ķ������ڵ�λ�����ǵ͵�λ��
if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "D")
{
int devicebyte = 0, devbit = 0;
DS = AheadDetect[i].Trim().Substring(1).Split(dd);
int.TryParse(DS[0], out devicebyte);
int.TryParse(DS[1], out devbit);
//�ж��Ƿ����⸺������ֵ�����������Ƿ����㿪����������ִ��ǰ�ᣩ
if (devicebyte < 0)
{
#region ��������ֵΪ���Ŀ���������
int fsn = CStaticClass.GetDevicePhotoelectric(-devicebyte, devbit);//20101124
if (fsn != 1)//20110505
{
StringBuilder kg = new StringBuilder();
switch (devbit)
{
case 0:
kg.Append(".0����");
break;
case 1:
kg.Append(".1����/��δ�յ�λ");
break;
case 2:
if (ccf.GetDeviceKindIdx(-devicebyte) == 31)
{
kg.Append("��λ");
}
else
{
kg.Append(".2����/��δ�쵽λ");
}
break;
case 3:
kg.Append(".3��λ");
break;
case 4:
kg.Append(".4��λ");
break;
case 5:
kg.Append("����");
break;
case 6:
kg.Append("��λ");
break;
case 7:
kg.Append("��λ");
break;
default:
break;
}
AheadDetectUnallow.Append(Convert.ToInt32((-devicebyte)).ToString() + kg.ToString() + "���翪�ز��ڵ���");
}
fs = fs & fsn;
#endregion
}
else
{//
#region ����ֵ����Ϊ���Ŀ���������
int sssn = CStaticClass.GetDevicePhotoelectric(devicebyte, devbit);
if (sssn != 0)//20110505
{
StringBuilder kg = new StringBuilder();
switch (devbit)
{
case 0:
kg.Append(".0����");
break;
case 1:
kg.Append(".1����");
break;
case 2:
if (ccf.GetDeviceKindIdx(devicebyte) == 31)
{
kg.Append("��λ");
}
else
{
kg.Append(".2����");
}
break;
case 3:
kg.Append(".3��λ");
break;
case 4:
kg.Append(".4��λ");
break;
case 5:
kg.Append("����");
break;
case 6:
kg.Append("��λ");
break;
case 7:
kg.Append("��λ");
break;
default:
break;
}
AheadDetectUnallow.Append(devicebyte.ToString() + kg.ToString() + "���翪���ڵ���");
}
s = s + sssn;
#endregion
}
}
#endregion
#region �Ϻ��ɵ��������Ƿ��г�����
//if (AheadDetect[i].Trim().Substring(0, 1).ToUpper() == "C")
//{
// sql.Remove(0, sql.Length);
// sql.Append(
// "select F_SwitchLock from T_Base_Device where F_SwitchLock>0 and F_DeviceIndex=")
// .Append(Convert.ToInt32(AheadDetect[i].Trim().Substring(1)));
// object obr = dbo.GetSingle(sql.ToString());
// if (obr != null)
// {
// if (obr.ToString() != (mti.ToString() + fid.ToString()))
// {
// //�Ƿ������ڴ˴�ǿ���ж�һ�µ����Ѿ�����50 ǿ�ƽ����ѳ����ߣ����ͻ������о��Զ�����dzf
// s = s + 1;
// AheadDetectUnallow.Append(AheadDetect[i].Trim().Substring(1) + "����������:").Append(obr.ToString()).Append("ԤԼ��");
// }
// else
// {
// s = s + 0;
// }
// }
//}
#endregion
}
}
#region ���ֹ��������������ֹ������ȴ�ִ����ִ���ֹ�����
if (mti != 4)
{//20120405
if (DeviceHandTaskIfWaitRun(devinfo.DeviceIndex) == true)
{
AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "�ֹ��������߱��������ȴ����У�");
s += 1;
}
}
#endregion
#region ����������������������������PLCASK��¼�Ƿ�ƥ�� �ɵ�
//��������վ̨�����������������񣬻��������ȶԵ�������ɨ�����˹������������ӵı�������������������PLCAsk��¼�IJ���ͬ����ִ������
sql.Remove(0, sql.Length);
sql.Append("SELECT T_Base_Device.F_DeviceIndex FROM T_Base_Device,T_Base_PLC_Ask WHERE ( T_Base_Device.F_DeviceIndex = T_Base_PLC_Ask.F_DeviceIndex) and (T_Base_Device.F_DeviceKindIndex = 7) AND T_Base_PLC_Ask.F_BindingDevice = ").Append(devinfo.DeviceIndex);
object obr1 = dbo.GetSingle(sql.ToString());
if (obr1 != null)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_BarCode FROM T_Base_PLC_Ask where F_BindingDevice=").Append(devinfo.DeviceIndex);
object obr = dbo.GetSingle(sql.ToString());
if (obr != null)
{
if ((obr.ToString().IndexOf(ccf.GetBarCodeFromMonitor(minMidx)) < 0) && (ccf.GetBarCodeFromMonitor(minMidx).IndexOf(obr.ToString()) < 0))
{
s = s + 1;
AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "��¼������:").Append(obr.ToString()).Append("������������").Append(ccf.GetBarCodeFromMonitor(minMidx)).Append("��ƥ�䣡");
}
}
}
#endregion
if ((s != 0) || (fs != 1))
{
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
#endregion
#region �л����豸�ĶѶ���20111020
if (DeviceKind == 1 && devinfo.VirtualStack > 0)
{
int mutex = ccf.GetStackMutexDevice(DeviceIdx);
if (mutex > 0)
{//���黥���豸����ʱ��λ�ú����е�Ŀ��λ��
Model.MDevice mutexdev = Model.CGetInfo.GetDeviceInfo(mutex);
int mutexDeviceLockedState = ccf.GetDeviceLockedState(mutex);
if (mutexDeviceLockedState == -1) return true;//20120110
int mutexManTaskReserve = ccf.GetManTaskReserve(mutex);
if ((mutexdev.RunState == 0) && (mutexManTaskReserve <= 0) && (mutexDeviceLockedState == 0))
{//
#region mutex���С����������޹�������ԤԼ��
int xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx));
int zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx));
int BCcoor = GetBarcodeCoor(xcoor, zcoor);
if (mutex > DeviceIdx)
{//mutex=35002
if ((BCcoor + StackMutexXCoor) >= mutexdev.XCoor)//mdev.XCoor������������ֵ��Ҫת��Ϊ��ֵ
{
InsertStackMutexOrder(mutex, 2, (BCcoor + StackMutexXCoor), 5);
if (mutexdev.XCoor > 52000)//20120110
{
return true;
}
else
{
if (devinfo.XCoor <= mutexdev.XCoor - minStackMutexXCoor)
{
return true;
}
else
{
return false;
}
}
}
}
else
{//mutex35001
if (BCcoor >= (StackMutexXCoor + StackZeroXCoor))
{
BCcoor = (BCcoor - StackMutexXCoor);
}
else
{
return true;//�Կ������ɣ��������������ˣ����߷����Ѷ����豸����
}
if (BCcoor <= mutexdev.XCoor)//mdev.XCoor������������ֵ��Ҫת��Ϊ��ֵ
{
InsertStackMutexOrder(mutex, 2, BCcoor, 5);
if (mutexdev.XCoor < 4481)//20120110
{
return true;
}
else
{
if (devinfo.XCoor > mutexdev.XCoor + minStackMutexXCoor)
{
return true;
}
else
{
return false;
}
}
}
}
#endregion
}
else
{//mutex����������
int xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx));
int zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(TaskIdx, DeviceIdx, ccf.GetDeviceOrderFromMonitor(TaskIdx));
int bccoor = GetBarcodeCoor(xcoor, zcoor);
int mutXcoor; int mutZcoor;
GetStackRunX_Zcoor(mutex, out mutXcoor, out mutZcoor);
if (mutXcoor > 0)
{
#region ������������������
int mutbccoor = GetBarcodeCoor(mutXcoor, mutZcoor);
if (mutex > DeviceIdx)
{
if (mutbccoor <= (bccoor + StackMutexXCoor))
{
if (mutbccoor > 52000)
{//20120110
return true;
}
else
{
return false;
}
}
}
else
{//mutexС
if (bccoor >= (StackMutexXCoor + StackZeroXCoor))
{
if (mutbccoor >= (bccoor - StackMutexXCoor))
{
if (mutbccoor < 4481)//20120110
{//20120110
return true;
}
else
{
return false;
}
}
}
else
{
if (bccoor >= 52000)
{
return true;
}
else
{
return false;
}
}
}
#endregion
}
else
{//�����񣬱�ԤԼ����û��������,���ܱ������ߴ���������
if ((mutexdev.RunState > 0) || (mutexDeviceLockedState != 0))
{// �������߱���������
#region �����豸������
if (mutex > DeviceIdx)
{//mutex=35002
if (mutexdev.XCoor <= (bccoor + StackMutexXCoor))
{
return false;//���߷���ֱ�ӱ���
}
}
else
{//mutex=35001
if (bccoor >= (StackMutexXCoor + StackZeroXCoor))
{
if (mutexdev.XCoor >= (bccoor - StackMutexXCoor))
{
return false;
}
}
else
{
return false;
}
}
#endregion
}
else
{
#region mutex����������ԤԼ�ˣ����ǻ�û���У����ͻ����ȴ����У�
int deviceorder = GetDeviceOrderFromManTaskReserve(mutexManTaskReserve, mutex);
if (deviceorder == -1) return false;
GetStackRunReserveX_Zcoor(mutex, out mutXcoor, out mutZcoor);
if (mutex > DeviceIdx)
{
if (mutexdev.XCoor <= (bccoor + StackMutexXCoor))
{
//ȥ��λ�߶Ⱥ���λ�ñ��ã����ߵ�52�У�60000��
InsertStackMutexOrder(mutex, deviceorder, (bccoor + StackMutexXCoor), GetLayerHigh(mutZcoor, mutXcoor));
if (mutexdev.XCoor > 52000)//20120110
{
return true;
}
else
{
if (devinfo.XCoor < mutexdev.XCoor - minStackMutexXCoor)
{
return true;
}
else
{
return false;
}
}
}
}
else
{//mutexС
if (bccoor >= (StackMutexXCoor + StackZeroXCoor))
{
if (mutexdev.XCoor >= (bccoor - StackMutexXCoor))
{
//ȥ��λ�߶Ⱥ���λ�ñ��ã����ߵ�0�У�2000��
InsertStackMutexOrder(mutex, deviceorder, (bccoor - StackMutexXCoor), GetLayerHigh(mutZcoor, mutXcoor));
if (mutexdev.XCoor < 4481)
{
return true;
}
else
{
if (devinfo.XCoor > mutexdev.XCoor + minStackMutexXCoor)
{
return true;
}
else
{
return false;
}
}
}
}
else
{
return false;
}
}
#endregion
}
}
}
}
}
#endregion
#region �������ȿ��ƽ������ͻ��ͳ�
////20111226
//string r1 = "12001,42001,32001,12009,42009,32009,12017,42017,32017";
//if ((r1.IndexOf(DeviceIdx.ToString()) >= 0) &&(devinfo.IfCorrelDoubleFork!="1"))
//{
// if (IFExitTopPriDeviceIdxTaskWait(DeviceIdx+1) == true)
// {
// return false;
// }
//}
#endregion
int CONTROLTASKTYPE = ccf.GetFCONTROLTASKTYPEFromManageTask(mti, fid);
#region ���������Թ����������񵥶�����//20101011
//20100406���ⶥ��ʱ��Ҫ���⣺1102��̽�-11021����1121�͵�λ��-11212�����й�������ʱ��1102��̽�-11022����
if ((ccf.GetCorrel_DeviceIndex(devinfo.DeviceIndex, true) == "0") && (CONTROLTASKTYPE == 1) && (devinfo.IfCorrelDoubleFork == "1"))//�����豸�Թ�������������20101124���Ӷ����豸�Ƿ�˫���ж�
{
string[] CorrelInfo = ccf.GetOwnCorrel_DeviceInfo(devinfo.DeviceIndex);
if (CorrelInfo == null)
{
//20110505
AheadDetectUnallow.Append("��������" + devinfo.DeviceIndex.ToString() + "û���Թ�����");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
if ((CStaticClass.GetDevicePhotoelectric(CorrelInfo[5]) == 1) && (CStaticClass.GetDevicePhotoelectric(CorrelInfo[2]) == 1))//���������������λ//20101124
{
#region �ȴ�������������
//��CStaticClass.DoubleForkWaitTime�涨ʱ���ڵȴ���1102��11027��ת���ȴ�
sql.Remove(0, sql.Length);
sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(TaskIdx).Append(") AND (F_Remark <> '') AND (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
//(Convert.ToDateTime(dv[0]["F_Remark"]).AddSeconds(Convert.ToInt32(CStaticClass.DoubleForkWaitTime)) > DateTime.Now) ||
if ((GetIOControlStatus(minMidx) != Model.CGeneralFunction.TASKSINGLEFORKRUN) ||
((CStaticClass.GetDevicePhotoelectric(CorrelInfo[6]) == 1) && (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 0)))//20101124
{
if ((CStaticClass.GetDevicePhotoelectric(CorrelInfo[6]) == 1)
&& (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 0))//��̽�����//20101124
{
//���ұ��ع��������������������ԣ�����������������
int mfid = GetEnableDoubleForkManageTask(1, devinfo.DeviceIndex, fid);
if (mfid > 0)
{
sql.Remove(0, sql.Length);
sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid);
dbo.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Manage_Task set FUseAwayFork='0',F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid);
dbo.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Monitor_Task set F_UseAwayFork='0' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_ManageTaskIndex=").Append(mfid).Append("");
dbo.ExecuteSql(sql.ToString());
//�����Ѿ�����·����һ������Զ�������ķ���ԭ������Ҫ�ĵ�
AlterRoutePath(mti, mfid, CONTROLTASKTYPE, '0', devinfo.DeviceIndex);
}
return true;
}
else
{
//20110505
AheadDetectUnallow.Append("��������" + devinfo.DeviceIndex.ToString() + "�ȴ�����������");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
else
{//�����ȴ�ʱ�����߹���ǿ��ִ�е�������
if (CStaticClass.GetDevicePhotoelectric(CorrelInfo[4]) == 1)//20101124
{
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")");
dbo.ExecuteSql(sql.ToString());
//20110505
AheadDetectUnallow.Append("��������" + devinfo.DeviceIndex.ToString() + "�ȴ�����������");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")");
dbo.ExecuteSql(sql.ToString());
return true;
}
}
else
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =0) AND (F_Remark = '') AND (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_TaskIndex=").Append(TaskIdx).Append(",F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(devinfo.DeviceIndex).Append(")");
dbo.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Monitor_Task set F_UseAwayFork='1' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and F_ManageTaskIndex=").Append(fid).Append("");
dbo.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Manage_Task set FUseAwayFork='1' where F_ManageTASKKINDINDEX=").Append(mti).Append(" and FID=").Append(fid).Append("");
dbo.ExecuteSql(sql.ToString());
//�����Ѿ�����·����һ������Զ�������ķ���ԭ������Ҫ�ĵ�
AlterRoutePath(mti, fid, CONTROLTASKTYPE, '1', devinfo.DeviceIndex);
return false;
}
}
#endregion
}
else
{
//20110505
AheadDetectUnallow.Append("��������" + devinfo.DeviceIndex.ToString() + "����������״̬��");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
return false;
}
}
#endregion
#region ɽ��ʱ��20250303 12051 �յ����⣬��������������ģʽ
if (CONTROLTASKTYPE == 2 && EndDevice == 12051&&StartDevice!=13008)
{
// ����һ���豸�� 12000�������ϱ�״̬��state�ֽ� 0��1
Model.MDevice devOutMode = Model.CGetInfo.GetDeviceInfo(15001);
if (devOutMode.RunState == 1) // ����ģʽ 1�����У������� 2 ���⣨���ɣ�
{
AheadDetectUnallow.Append("12051����ģʽ��");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
}
}
if (CONTROLTASKTYPE == 2 &&StartDevice == 13008 && EndDevice != 12051)
{
// ����һ���豸�� 12000�������ϱ�״̬��state�ֽ� 0��1
Model.MDevice devOutMode = Model.CGetInfo.GetDeviceInfo(15001);
if (devOutMode.RunState == 2) // ����ģʽ 1�����У������� 2 ���⣨���ɣ�
{
AheadDetectUnallow.Append("12051����ģʽ��");
UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
}
}
#endregion
#region lzm20250225 ע��������Ŀ
//20101011
//#region ˫���Ѷ�����ȡ�������ڴ��ж��Ƿ�����˫�桢��֤˫�������Ƿ�Ϊ˫�漫�޻�λ
//if ((devinfo.DeviceKind == 1) && (devinfo.IfCorrelDoubleFork == "1") && (ccf.GetDeviceOrderFromMonitor(minMidx) == 4))
//{
// string[] DevLanewayIOInfo = ccf.GetDeviceLaneGateInfoFromStackCoor(devinfo.DeviceIndex, minMidx);
// if (DevLanewayIOInfo == null)
// {
// //���������ڵ�ȡ����������Ҫ����
// CommonClassLib.CCarryConvert.WriteDarkCasket("����ִ��ԭ��", minMidx.ToString(), devinfo.DeviceIndex.ToString(), "���������ڵ�ȡ����������Ҫ����");
// return true;
// }
// Dictionary<int, string[]> corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex);
// if (corrinfo == null)//20110412û��������
// {
// #region 20110412�Ѷ����ڶ�����ȡ������������֤�Ƿ���Ҫ������
// string ChangeForkCell = ccf.IfLimitCellChangeFork(minMidx, devinfo.DeviceIndex);
// if (ChangeForkCell != "-")//��������Ҫ��������
// {
// ccf.ChangeEndCellCode(minMidx, ChangeForkCell, devinfo.DeviceIndex);
// }
// #endregion
// #region û��������
// //string IfCorrel = ccf.GetCorrel_DeviceIndex(minMidx);//20110505
// //if (IfCorrel == "")//�޹���
// //{
// //}
// //else if (IfCorrel == "0")//�Թ���
// //{
// // //20110108
// // dbo.ExecuteSql("update T_Monitor_Task set F_UseAwayFork='1' where F_ManageTASKKINDINDEX=" + mti + " and F_ManageTaskIndex=" + fid + "");
// // dbo.ExecuteSql("update T_Manage_Task set FUseAwayFork='1' where F_ManageTASKKINDINDEX=" + mti + " and FID=" + fid + "");
// // #region 20110412�Ѷ����ڶ�����ȡ������������֤�Ƿ���Ҫ������
// // string ChangeForkCell = ccf.IfLimitCellChangeFork(minMidx, devinfo.DeviceIndex);
// // if (ChangeForkCell != "-")//��������Ҫ��������
// // {
// // ccf.ChangeEndCellCode(minMidx, ChangeForkCell, devinfo.DeviceIndex);
// // }
// // #endregion
// //}
// //else
// //{//�й���վ̨
// // #region ˫���Ե�վ̨�ĵ������ڴ˵ȴ�������˫�漫�޻�λ������
// // if ((CStaticClass.GetDevicePhotoelectric(DevLanewayIOInfo[3]) == 1) && (CStaticClass.GetDevicePhotoelectric(DevLanewayIOInfo[1]) == 1))//�л���������λ
// // {
// // #region ������λ�л�
// // bool isend;
// // return GetCorrManageTask(DevLanewayIOInfo, TaskIdx, CONTROLTASKTYPE, mti, fid, dtime,out isend);
// // #endregion
// // }
// // else
// // {
// // CommonClassLib.CCarryConvert.WriteDarkCasket("����ִ��ԭ��", minMidx.ToString(), devinfo.DeviceIndex.ToString(), "������λ�������źŲ���������");
// // }
// // #endregion
// //}
// #endregion
// }
// else
// {
// #region �й���������Ϣ
// #region �ж��Ƿ����пɹ����Ĺ���վ̨����20120906
// //bool isend;
// //GetCorrManageTask(DevLanewayIOInfo, TaskIdx, CONTROLTASKTYPE, mti, fid, dtime,out isend);
// //if (isend == false) return false;
// #endregion
// foreach (int CorrTaskindex in corrinfo.Keys)
// {
// #region ˫�������ڴ���֤���Ƿ�Ϊ˫�漫�޻�λ��˫���޻�λʹ��˫�浹����λ�޸�����
// //�ѵ�����λ��Ϊȡ�����ͻ�������Ŀ����λ������ȡ�����ͻ��������ڵ�����λ���߼���������ǰ����
// //���浹����λ����ʱ��׷�ӵ�����λ---����Ҫ�����ļ��޻�λ��ȡ�����ͻ�����
// #region ������������
// string ChangeForkCell1 = ccf.IfLimitCellChangeFork(CorrTaskindex, devinfo.DeviceIndex);
// #endregion
// if (ChangeForkCell1 != "-") //����������Ҫ��������
// {
// ccf.ChangeEndCellCode(CorrTaskindex, ChangeForkCell1, devinfo.DeviceIndex);
// }
// #endregion
// }
// #endregion
// }
//}
//#endregion
//#region ˫��AGV������ȡ�������ڴ��ж��Ƿ�����˫�桢��֤˫�������Ƿ�Ϊ˫�漫�޻�λ
//if ((devinfo.DeviceKind == 6) && (devinfo.IfCorrelDoubleFork == "1") && (ccf.GetDeviceOrderFromMonitor(minMidx) == 2) && ((CONTROLTASKTYPE == 1) || (CONTROLTASKTYPE == 4)))
//{
// Dictionary<int, string[]> corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex);
// if (corrinfo == null)
// {
// #region ˫���Ե�վ̨�ĵ������ڴ˵ȴ�������˫�漫�޻�λ������
// if (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN)
// {//ûǿ�Ƶ���ִ��
// //���ҹ���վ̨
// int agvCorrel = GetAGVCorrelIndex(TaskIdx);
// if (agvCorrel != -1)
// {
// //���ұ��ع��������������������ԣ�����������������
// int mfid = GetAGVEnableDoubleForkManageTask(CONTROLTASKTYPE, agvCorrel, devinfo.DeviceIndex);
// if (mfid > 0)
// {
// #region ˫��ͬΪǰ���޺��ߺ����޲�����������ִ��
// if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1))
// {
// sql.Remove(0, sql.Length);
// sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")");
// dboM.ExecuteSql(sql.ToString());
// sql.Remove(0, sql.Length);
// sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")");
// dboM.ExecuteSql(sql.ToString());
// return true;
// }
// #endregion
// sql.Remove(0, sql.Length);
// sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid);
// dbo.ExecuteSql(sql.ToString());
// sql.Remove(0, sql.Length);
// sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid);
// dbo.ExecuteSql(sql.ToString());
// return true;
// }
// else
// {
// //20110505
// AheadDetectUnallow.Append("˫��AGV��˫��У��վ̨ȡ��" + "���ȴ���������վ̨" + agvCorrel.ToString() + "��������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// }
// else
// return true;
// }
// else
// {//����ǿ��ִ�е�������
// return true;
// }
// #endregion
// }
//}
//#endregion
//#region ˫��AGV�ij��������ͻ�ȡ�������ڴ��ж��Ƿ�����˫��20110412
//if ((devinfo.DeviceKind == 6) && (devinfo.IfCorrelDoubleFork == "1") && ((ccf.GetDeviceOrderFromMonitor(minMidx) == 2)
// || (ccf.GetDeviceOrderFromMonitor(minMidx) == 4)) && (CONTROLTASKTYPE == 2))
//{
// Dictionary<int, string[]> corrinfo = Model.CGeneralFunction.GetDoubleForkMonitorInfo(minMidx, devinfo.DeviceIndex);
// if (corrinfo == null)
// {
// #region ˫���Ե�վ̨�ĵ������ڴ˵ȴ�������˫�漫�޻�λ������
// if (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN)//20110429����Ӧ��ΪGetIOControlStatus(TaskIdx)��=
// {//ûǿ�Ƶ���ִ��
// //���ҹ���վ̨
// int agvCorrel = GetAGVCorrelConveyorIndex(TaskIdx);
// if (agvCorrel != -1)
// {
// #region ���Ҷ������Ƿ���agvCorrel������������û�У����ٵȴ�������ִ�У�
// if (GetAGVEnableDoubleForkManageTask(2, agvCorrel, devinfo.DeviceIndex) <= 0)//û���ܹ��������񣬲��ٵȴ�������ִ��
// {
// sql.Remove(0, sql.Length);
// sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")");
// dboM.ExecuteSql(sql.ToString());
// return true;
// }
// #endregion
// #region 20110412���ܹ������������ж�agvCorrel�Ƿ��������������Ѿ���ȡ��״̬
// int[] cstates = CStaticClass.GetDeviceState(agvCorrel);
// int cssstate = -1;
// if (cstates != null)
// {
// cssstate = cstates[1];
// }
// if ((cssstate != 0) || (CStaticClass.GetDevicePhotoelectric(agvCorrel - 2, 0) != 1) || (CStaticClass.GetDevicePhotoelectric(agvCorrel, 2) != 1))//20110412���������С��л�����λ
// {
// //20110505
// AheadDetectUnallow.Append("˫��AGV��˫��У��վ̨ȡ��" + "���ȴ���������վ̨" + agvCorrel.ToString() + "��������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// #endregion
// //���ұ��ع���������˫�������ͻ�ȡ�������������ԣ�����������������
// int mfid = GetAGVFromConveyorDoubleForkGetGoodManageTask(2, agvCorrel, devinfo.DeviceIndex);
// if (mfid > 0)
// {
// #region �յ㲻��ͬ�������ֱ�ִ��
// if (IFHaveSameEndDevice(fid, mfid, mti) == false)
// {
// sql.Remove(0, sql.Length);
// sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")");
// dboM.ExecuteSql(sql.ToString());
// sql.Remove(0, sql.Length);
// sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")");
// dboM.ExecuteSql(sql.ToString());
// return true;
// }
// #endregion
// #region ˫��ͬΪǰ���޺��ߺ����޲�����������ִ��
// //if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1))
// //{
// // sql.Remove(0, sql.Length);
// // sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")");
// // dboM.ExecuteSql(sql.ToString());
// // sql.Remove(0, sql.Length);
// // sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")");
// // dboM.ExecuteSql(sql.ToString());
// // return true;
// //}
// #endregion
// sql.Remove(0, sql.Length);
// sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(mfid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid);
// dbo.ExecuteSql(sql.ToString());
// sql.Remove(0, sql.Length);
// sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid);
// dbo.ExecuteSql(sql.ToString());
// return true;
// }
// else
// {
// //20110505
// AheadDetectUnallow.Append("˫��AGV�����ͻ�ȡ��" + "��û�ҵ������������񣬹���վ̨" + agvCorrel.ToString() + "���쳣�����ڵ����أ�");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// }
// else
// return true;
// }
// else
// {//����ǿ��ִ�е�������
// return true;
// }
// #endregion
// }
//}
//#endregion
//#region �񺽶�����������ִ������ǰ�����Ƿ����е�ǰ�����������������У���ȥִ��������������
//if (devinfo.IsShuttleBorad == 1 && devinfo.DeviceKind == 1 && _NumParam3 != devinfo.YCoor && CONTROLTASKTYPE != 0)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Monitor_Task WHERE F_DeviceIndex = '")
// .Append(devinfo.DeviceIndex.ToString()).Append("' AND F_DeviceCommandIndex = 3 AND F_Status = 0 AND F_NumParam3 =")
// .Append(devinfo.YCoor).Append(" AND F_MonitorIndex <> ").Append(minMidx);
// if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0)
// {
// AheadDetectUnallow.Append("�����壺" + devinfo.DeviceIndex.ToString() + "�������ڲ�������������ִ�����ڲ�����");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶�����14003 ,14004�������л��������Ѿ������ҵ����������Ȳ�ִ��
//if (DeviceIdx == 14003 || DeviceIdx == 14004)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 and FENDDEVICE ='14005' and F_ChangeStatus =10 and FSTATUS<>0 AND FID <>").Append(fid.ToString());
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// ////�˴���Ҫ�ж�������19005����һ�����������Ѿ����� ���ܶ�
// //sql.Remove(0, sql.Length);
// //sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE (F_DeviceIndex = {0} ) and F_Status<>0", 19005));
// //dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// //if (dv.Count > 0)
// //{
// // AheadDetectUnallow.Append("��������������19005����ִ�л������񣬵ȴ�����ִ������");
// // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// // return false;
// //}
// AheadDetectUnallow.Append("��������������14005����ִ�л�������"+ dv[0]["FID"].ToString() + "���ȴ�����ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0}) and F_ManTaskReserve<>0 ", 14005));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14005����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶�����14002 ,14001�������л��������Ѿ������ҵ����������Ȳ�ִ��
//if (DeviceIdx == 14002 || DeviceIdx == 14001)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 and FENDDEVICE ='14006' and F_ChangeStatus =10 and FSTATUS<>0 AND FID <>").Append(fid.ToString());
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// ////�˴���Ҫ�ж�������19005����һ�����������Ѿ����� ���ܶ�
// //sql.Remove(0, sql.Length);
// //sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE (F_DeviceIndex = {0} ) and F_Status<>0", 19005));
// //dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// //if (dv.Count > 0)
// //{
// // AheadDetectUnallow.Append("��������������19005����ִ�л������񣬵ȴ�����ִ������");
// // UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// // return false;
// //}
// AheadDetectUnallow.Append("��������������14006����ִ�л�������" + dv[0]["FID"].ToString() + "���ȴ�����ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0}) and F_ManTaskReserve<>0 ", 14006));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14006����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶�����14003 ,14004������ȡ����������л��������Ѿ������Ȳ�ִ��
//if ((DeviceIdx == 14003 || DeviceIdx == 14004)&& order == 4)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 and FENDDEVICE ='14005' and FSTATUS<>0 and FID <>").Append(fid.ToString());
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("�������������������Ѿ����͵Ļ�������" + dv[0]["FID"].ToString() + "���ȴ�����ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0}) and F_ManTaskReserve<>0 ", 14005));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14005����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶�����14001 ,14002������ȡ����������л��������Ѿ������Ȳ�ִ��
//if ((DeviceIdx == 14001 || DeviceIdx == 14002) && order == 4)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 and FENDDEVICE ='14006' and FSTATUS<>0 and FID <>").Append(fid.ToString());
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("�������������������Ѿ����͵Ļ�������" + dv[0]["FID"].ToString() + "���ȴ�����ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0}) and F_ManTaskReserve<>0 ", 14006));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14006����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶���������������14005��������14003��14004�������Ѿ����ͻ�14003��14004�ĵ���ԤԼ����Ϊ0 ����������
//if (DeviceIdx == 14005)
//{
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE ( F_DeviceCommandIndex=4 or F_DeviceCommandIndex=5 )and F_Status <> 0 and (F_DeviceIndex = {0} or F_DeviceIndex = {1}) ", 14003, 14004));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����19003��19004�ѷ��͵�����");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0} or F_DeviceIndex = {1}) and F_ManTaskReserve<>0 ", 14003, 14004));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14003��14004����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶���������������14006��������14001��14002�������Ѿ����ͻ�14001��14002�ĵ���ԤԼ����Ϊ0 ����������
//if (DeviceIdx == 14006)
//{
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Monitor_Task WHERE ( F_DeviceCommandIndex=4 or F_DeviceCommandIndex=5 )and F_Status <> 0 and (F_DeviceIndex = {0} or F_DeviceIndex = {1}) ", 14001, 14002));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14001��14002�ѷ��͵�����");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0} or F_DeviceIndex = {1}) and F_ManTaskReserve<>0 ", 14001, 14002));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("��������������" + devinfo.DeviceIndex.ToString() + "����ʱ����14001��14002����ԤԼ�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶�������������ִ�У������б��Ļ������� �����Ǹ��豸������������
//if (CONTROLTASKTYPE==5)
//{
// if (DeviceIdx == 14005|| DeviceIdx == 14006)
// {
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 AND FID <>").Append(fid.ToString());
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// for (int k = 0; k < dv.Count; k++)
// {
// //�˴��ж����Ѿ��������������񲻷���
// if ((dv[k]["FSTATUS"].ToString() != "0")&& (dv[k]["F_ChangeStatus"].ToString() != "0"))
// {
// AheadDetectUnallow.Append("���Ѿ�����������ִ�еĻ�������" + dv[k]["FID"].ToString() + "���ȴ�����ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
// }
// }
// }
//}
//#endregion
//#region �񺽶�����������ִ������������֮ǰ�жϣ��������ڸ�λ�õĻ�����������ִ�л��������ſ�ִ��ȡ������
//if (devinfo.IsShuttleBorad == 1 && devinfo.DeviceKind == 1 && CONTROLTASKTYPE != 5)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM T_Manage_Task WHERE FPALLETBARCODE = '").Append(fid.ToString())
// .Append("' AND FCONTROLTASKTYPE = 5");
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("�����壺" + devinfo.DeviceIndex.ToString() + "����ִ�л������񣬵ȴ���������ִ������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶��������ʹ���������ʱ�ж��Ƿ����ڳ�������
//if ((devinfo.DeviceKind == 1) && (CONTROLTASKTYPE != 6))
//{
// sql.Remove(0, sql.Length);
// sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE (FCONTROLTASKTYPE = 6) and FSTARTDEVICE = '{0}' and FSTATUS>=0", devinfo.DeviceIndex.ToString()));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// AheadDetectUnallow.Append("����"+ devinfo.DeviceKind .ToString()+ "�ij�������");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
//#region �񺽶��������ʹ������κ���������Ҫ�ж�û�д������ϱ���ͬ��
//if ((devinfo.DeviceKind == 1) )
//{
// sql.Clear();
// sql.Append(string.Format("select count(*)-count(distinct F_Postion) as num from SHUTTLE_POSITION "));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// if (Convert.ToInt32(dv[0]["num"]) != 0)
// {
// AheadDetectUnallow.Append("��������ʱ�г��ϱ���ͬ��");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// }
// }
//}
//#endregion
//#region �񺽶�����14005 14006 ��ȡ��ָ��ǰ�ж�.2�Ƿ�Ϊ1��1��ʾ�����Ѿ��յ�λ .1Ϊ1���������쵽λ .2Ϊ1���������յ�λ
//if ((DeviceIdx == 14005|| DeviceIdx == 14006) && (order == 4|| order == 5))
//{
// if (devinfo.SplitByte_2 != 1)
// {
// AheadDetectUnallow.Append("������"+ DeviceIdx.ToString() + "����δ�յ���ȷλ��");
// UpdateAheadDetectUnallow(AheadDetectUnallow, minMidx);
// return false;
// }
//}
//#endregion
#endregion
return true;
}
catch (Exception ex)
{
RefreshMonitorEventArgs rme = new RefreshMonitorEventArgs("tsStatus", "����ָ����ǰ����ʱ����������" + ex.StackTrace + ex.Message);
OnRefreshMonitor(rme);
return false;
}
finally
{
dv.Dispose();
dvdv.Dispose();
barcodeDV.Dispose();
}
}
private bool IFExitTopPriDeviceIdxTaskWait(int DeviceIdx)
{
sql.Clear();
DataView dv0 = new DataView(); DataView dv = new DataView();
try
{
sql.Append(string.Format("SELECT F_ManageTaskIndex, F_ManageTASKKINDINDEX FROM T_Monitor_Task WHERE (F_DeviceIndex = {0})", DeviceIdx));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
sql.Clear();
sql.Append(string.Format("SELECT top 1 F_DeviceIndex,F_Status FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX = {0}) and F_ManageTaskIndex={1} order by F_MonitorIndex asc", Convert.ToInt32(dv[i]["F_ManageTASKKINDINDEX"]), Convert.ToInt32(dv[i]["F_ManageTASKINDEX"])));
dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv0.Count > 0)
{
if ((dv0[0]["F_DeviceIndex"].ToString() == DeviceIdx.ToString()) && (dv0[0]["F_Status"].ToString() == "0"))
{
return true;
}
}
}
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv0.Dispose();
}
}
private int GetBarcodeCoor(int xcoor, int zcoor)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT BarcodeCoor FROM T_Base_BarcodeCoor WHERE (XCoor = {0}) AND (ZCoor = {1})", xcoor, zcoor)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0][0]);
}
else
{
dv = dbo.ExceSQL(string.Format("SELECT BarcodeCoor FROM T_Base_BarcodeCoor WHERE (XCoor1 = {0}) AND (ZCoor1 = {1})", xcoor, zcoor)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0][0]);
}
else
{
return 0;
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// ���÷�����Ϣ
/// </summary>
/// <param name="minMidx">�豸ָ������</param>
public bool GetSendInfo(int minMidx)
{
DataView dvD = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_DeviceKindIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,").Append(
"F_NumParam5,F_NumParam6,F_TxtParam,F_AheadDetect,F_ManTaskReserve,F_LockedState,").Append(
"F_Associate,F_SerialNumber,F_RouteID,F_DeviceIndex,F_DeviceCommandIndex,").Append(
"F_MonitorIndex,F_ManageTaskIndex,F_ManageTaskKindIndex,F_OutsideAltDevice,").Append(
"F_InsideAltDevice,F_StartDevice,F_EndDevice,F_RouteKind,F_UseAwayFork,F_AgvNo ").Append(
" FROM V_Monitor_Route_Device where F_MonitorIndex=").Append(minMidx);
dvD = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvD.Count > 0)
{
if (dvD[0]["F_AheadDetect"] != DBNull.Value)
{
_AheadDetect = dvD[0]["F_AheadDetect"].ToString();
}
else
{
_AheadDetect = "";
}
if (dvD[0]["F_ManTaskReserve"] != DBNull.Value)
{
_ManTaskReserve = Convert.ToInt32(dvD[0]["F_ManTaskReserve"]);
}
else
{
_ManTaskReserve = 0;
}
if (dvD[0]["F_Associate"] != DBNull.Value)
{
_Associate = Convert.ToInt32(dvD[0]["F_Associate"]);
}
else
{
_Associate = 0;
}
if (dvD[0]["F_LockedState"] != DBNull.Value)
{
_LockedState = Convert.ToInt32(dvD[0]["F_LockedState"]);
}
else
{
_LockedState = 0;
}
if (dvD[0]["F_NumParam1"] != DBNull.Value)
{
_NumParam1 = Convert.ToInt32(dvD[0]["F_NumParam1"]);
}
else
{
_NumParam1 = 0;
}
if (dvD[0]["F_NumParam2"] != DBNull.Value)
{
_NumParam2 = Convert.ToInt32(dvD[0]["F_NumParam2"]);
}
else
{
_NumParam2 = 0;
}
if (dvD[0]["F_NumParam3"] != DBNull.Value)
{
_NumParam3 = Convert.ToInt32(dvD[0]["F_NumParam3"]);
}
else
{
_NumParam3 = 0;
}
if (dvD[0]["F_NumParam4"] != DBNull.Value)
{
_NumParam4 = Convert.ToInt32(dvD[0]["F_NumParam4"]);
}
else
{
_NumParam4 = 0;
}
if (dvD[0]["F_NumParam5"] != DBNull.Value)
{
_NumParam5 = Convert.ToInt32(dvD[0]["F_NumParam5"]);
}
else
{
_NumParam5 = 0;
}
if (dvD[0]["F_NumParam6"] != DBNull.Value)
{
_NumParam6 = Convert.ToInt32(dvD[0]["F_NumParam6"]);
}
else
{
_NumParam6 = 0;
}
if (dvD[0]["F_TxtParam"] != DBNull.Value)
{
_TxtParam = dvD[0]["F_TxtParam"].ToString();
}
else
{
_TxtParam = "-";
}
_serialNumber = Convert.ToInt32(dvD[0]["F_SerialNumber"]);
_routeID = Convert.ToInt32(dvD[0]["F_RouteID"]);
_DeviceIdx = Convert.ToInt32(dvD[0]["F_DeviceIndex"]);
_DeviceOrder = Convert.ToInt32(dvD[0]["F_DeviceCommandIndex"]);
_ManageKindIdx = Convert.ToInt32(dvD[0]["F_ManageTaskKindIndex"]);
_ManageTaskIdx = Convert.ToInt32(dvD[0]["F_ManageTaskIndex"]);
_DeviceKind = Convert.ToInt32(dvD[0]["F_DeviceKindIndex"]);
if (dvD[0]["F_OutsideAltDevice"] != DBNull.Value)
{
_OutsideAltDevice = Convert.ToInt32(dvD[0]["F_OutsideAltDevice"]);
}
else
{
_OutsideAltDevice = 0;
}
if (dvD[0]["F_InsideAltDevice"] != DBNull.Value)
{
_InsideAltDevice = Convert.ToInt32(dvD[0]["F_InsideAltDevice"]);
}
else
{
_InsideAltDevice = 0;
}
_StartDevice = Convert.ToInt32(dvD[0]["F_StartDevice"]);
_EndDevice = Convert.ToInt32(dvD[0]["F_EndDevice"]);
_RouteKind = Convert.ToInt32(dvD[0]["F_RouteKind"]);
if (dvD[0]["F_AgvNo"] != DBNull.Value)
{
_AgvNo = Convert.ToInt32(dvD[0]["F_AgvNo"]);
}
else
{
_AgvNo = 65535;
}
return true;
}
else
{//20120420
CControlError = string.Format("������������GetSendInfoʱ��·�����{0}���豸���������ڣ�", GetDeviceFromMonitor(minMidx).ToString());
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dvD.Dispose();
}
}
/// <summary>
/// ����ָ�����������ŵ�����
/// </summary>
/// <param name="MonitorIndex"></param>
/// <returns></returns>
public bool SendMonitorTask(int MonitorIndex)
{
try
{
lock (thisLock)
{
char[] sep = new char[1] { '-' };
int msgIdx = 0;//��Ϣ����
bool sendok;
int jiangqunum = 0;
int boxnum = 0;// add by lyj20180503
#region ע�� by lyj20180619 ���������豸ָ���������ͬ��ִ�У����;����Ѷ�����ǰλ�ý����豸ָ��
//MonitorIndex = GetDoubleForkMinRouteTask(MonitorIndex);
//if (MonitorIndex == -1) { return false; }
#endregion
//����Ҫ���͵���Ϣ
if (GetSendInfo(MonitorIndex) == false) { return false; }
int deviceIdx = _DeviceIdx;
int deviceKind = _DeviceKind;
int deviceOrder = _DeviceOrder;
int manageKindIdx = ccf.GetManageTaskKindIndexFromMonitor(MonitorIndex);
int manageTaskIdx = ccf.GetManageTaskIndexfromMonitor(MonitorIndex);
int tasktype = ccf.GetFCONTROLTASKTYPEFromManageTask(manageKindIdx, manageTaskIdx);
devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
int relaiddd = ccf.GetRELATIVECONTORLIDFromManageTask(manageKindIdx, manageTaskIdx);
#region add by lyj20180508�й������ͻ����񣬷���ʱ�����Ƿ���ȡ��ָ��������򲻷���
if (deviceKind==40&&deviceOrder==5&&relaiddd>0)
{
bool flags = ccf.getSentOrNoTask(deviceOrder,relaiddd);
if(flags==true)
{
return false;
}
}
#endregion
//if (((deviceKind == 1 && (devinfo.YCoor == 0)) || (deviceKind == 4) && (devinfo.XCoor == 0) && (devinfo.YCoor == 0)) && (devinfo.VirtualStack != deviceIdx))//20130510
//{
// AheadDetectUnallow.Clear();
// AheadDetectUnallow.Append(_DeviceIdx.ToString() + "�Ĺ�ͨѶ���ڵ�������û�ϵ磡");
// UpdateAheadDetectUnallow(AheadDetectUnallow, MonitorIndex);
// return false;
//}
#region add by �Ϻ��ɵ����䴩���� �񺽶���
//if (devinfo.IsShuttleBorad == 1 && devinfo.DeviceKind == 1 && deviceIdx == 11000)
//{
// if (deviceOrder==2)
// {
// int shuttleBoardNum= getShuttleBoradNum(MonitorIndex, deviceIdx);
// if (shuttleBoardNum > 0)
// {
// deviceIdx = shuttleBoardNum;
// }
// else
// {
// return false;
// }
// }
//}
#endregion
else
{
if (deviceOrder == 5 && devinfo.DeviceKind == 1 && jiangqunum > 0 && devinfo.IsShuttleBorad != 1)
{
return false;
}
}
if (ccf.GetManageTaskKindIndexFromMonitor(MonitorIndex) == 4)
{
#region �ֹ�����
string ah = "I" + deviceIdx.ToString();
if ((deviceKind != 1) && ((deviceKind != 4)))
{
ah = "";
}
if (AheadDetectOK(MonitorIndex, ah) == false) //��������������ccf.GetBeDetectedDevices(_DeviceIdx))
{
return false;
}
//CStaticClass.MessageIndex++;
CStaticClass.MessageIndex = 1;
msgIdx = (CStaticClass.MessageIndex);
sdo = CommModeCreate.CreateSendDeviceOrder(deviceIdx);
int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 };
if ((deviceKind == 1) || (deviceKind == 6))
{
#region 20201021_C2�������ϱ������彫Ҫǰ����һ��
//if (devinfo.IsShuttleBorad == 1 && deviceOrder == 4)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_DeviceIndex = ")
// .Append(deviceIdx.ToString());
// DataView dv = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// if (gc[1] != Convert.ToInt32(dv[0]["F_Postion"]))
// {
// sql.Remove(0, sql.Length);
// sql.Append("UPDATE SHUTTLE_POSITION SET F_Postion = ")
// .Append(gc[1].ToString()).Append(" WHERE F_DeviceIndex = ")
// .Append(deviceIdx.ToString());
// dboM.ExecuteSql(sql.ToString());
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "���¹���������λ��",
// deviceIdx.ToString(),
// "������" + gc[1].ToString("D2"));
// }
// }
//}
#endregion
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder,
deviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]);
}
else if (deviceKind == 4)
{
if (ccf.NeedOptimize(deviceIdx) == true)
{
ccf.InsertMonitorOptimizeChildTask(MonitorIndex);
sendok = true;
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[2]);
}
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5]);
}
if (sendok == false)
{
if (sdo.CommLayerError != null)
{
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", sdo.CommLayerError);
OnRefreshMonitor(rmea);
}
return false;
}
else
{
//////////////////////////
ccf.SendOrderSuccess(manageKindIdx, manageTaskIdx, MonitorIndex, deviceIdx, _routeID);
#region ����������������ͬ����ͬʱ���淢�������ɹ�
//20100323
devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
if (devinfo.IfCorrelDoubleFork == "1")
{
int[] mforkMoninfo = Model.CGeneralFunction.MutiForkIfSync(MonitorIndex, deviceIdx, deviceKind);
if (mforkMoninfo != null)
{
Dictionary<int, string[]> corr = Model.CGeneralFunction.GetDoubleForkMonitorInfo(MonitorIndex, deviceIdx);
for (int i = 0; i < mforkMoninfo.GetLength(0); i++)
{
ccf.SendOrderSuccess(ccf.GetManageTaskKindIndexFromMonitor(mforkMoninfo[i]), ccf.GetManageTaskIndexfromMonitor(mforkMoninfo[i]), mforkMoninfo[i], Convert.ToInt32(corr[mforkMoninfo[i]][2]), Convert.ToInt32(corr[mforkMoninfo[i]][3]));
}
}
}
#endregion
return true;
}
#endregion
}
#region �Զ�����(taskkind == 1��2)
//(taskkind == 1��2)�Զ���������ʱ������������
///////////////////////////////////////
//2--6Ӧ�����ݹ����ú���
///////////////////////////////////////
/////////////////////
//20100208
#region ���δ�����RGV���䳵���޸���ǰ����
#endregion
////////////////////
//2����ȡÿ���������ݵĵ�һ���豸״̬
if (GetFirstDeviceIFLocked(MonitorIndex, true) == false)//û�б�����������
{
devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
//7�����ʹ��豸����
//CStaticClass.MessageIndex++;
CStaticClass.MessageIndex = 1;
msgIdx = (CStaticClass.MessageIndex);
sdo = CommModeCreate.CreateSendDeviceOrder(deviceIdx);
//�ж��豸�Ƿ�Ϊ�Ѷ���RGV�ͣ��ǣ�
int[] gc = new int[6] { _NumParam2, _NumParam3, _NumParam1, _NumParam5, _NumParam6, _NumParam4 };//��������
if (gc == null)
{
this.CControlError += string.Format("��������ʱ����ȡ���豸���꣡");
return false;
}
if ((deviceKind == 1) || (deviceKind == 6))
{
//1���Ѷ�����4��RGV��6��AGV������Ҫ�Ż����ȣ��豸����F_NeedOptimize='1'��
//ֱ��д������T_Monitor_Task_Child������������
if (ccf.NeedOptimize(deviceIdx) == true)
{
ccf.InsertMonitorOptimizeChildTask(MonitorIndex);
sendok = true;
}
else
{
#region 20201021_C2�������ϱ������彫Ҫǰ����һ��
//if(devinfo.IsShuttleBorad == 1 && deviceOrder == 4)
//{
// sql.Remove(0, sql.Length);
// sql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_DeviceIndex = ")
// .Append(deviceIdx.ToString());
// DataView dv = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// if (gc[1] != Convert.ToInt32(dv[0]["F_Postion"]))
// {
// sql.Remove(0, sql.Length);
// sql.Append("UPDATE SHUTTLE_POSITION SET F_Postion = ")
// .Append(gc[1].ToString()).Append(" WHERE F_DeviceIndex = ")
// .Append(deviceIdx.ToString());
// dboM.ExecuteSql(sql.ToString());
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "���¹���������λ��",
// deviceIdx.ToString(),
// "������" + gc[1].ToString("D2"));
// }
// }
//}
#endregion
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder,
deviceIdx, gc[0], gc[1], gc[2], gc[3], gc[4], gc[5]);
}
}
else if (_DeviceKind == 4)
{
if (ccf.NeedOptimize(deviceIdx) == true)
{
ccf.InsertMonitorOptimizeChildTask(MonitorIndex);
sendok = true;
}
else
{
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[2]);
}
}
else if (_DeviceKind == 7)
{
int ControlType = ccf.GetFCONTROLTASKTYPEFromManageTask(_ManageKindIdx, _ManageTaskIdx);
#region �����豸ֱ�ӱȶ�
DataView dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Base_PLC_Ask ,T_Monitor_Task WHERE T_Base_PLC_Ask.F_DeviceIndex = T_Monitor_Task.F_DeviceIndex AND T_Base_PLC_Ask.F_BarCode = T_Monitor_Task.F_TxtParam and (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex)).Tables[0].DefaultView;
if ((dv.Count > 0) || (ControlType != 1))
{//�ȶ���ȷ
object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND };
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO=NULL WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1}) and FExceptionNO={2}", obj));
Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
}
else
{//�ȶԴ��󣬸ĵ��쳣������
//�޸�Ŀ��λ�����쳣��
dv = dbo.ExceSQL(string.Format("SELECT F_Remark,F_BindingDevice,F_BarCode FROM T_Base_PLC_Ask WHERE T_Base_PLC_Ask.F_DeviceIndex = {0}", deviceIdx)).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((CStaticClass.DeviceErrorAutoModifyRoutePath == "1") && (dv[0]["F_BarCode"].ToString() != "111111"))
{
object[] obj = new object[5] { _ManageKindIdx, _ManageTaskIdx, Convert.ToInt32(dv[0][" "]), Model.CGeneralFunction.TASKABEND, Convert.ToInt32(dv[0]["F_BindingDevice"]) };
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={3},FSTARTDEVICE ={4}, FSTARTCELL ='-',FENDDEVICE ={2}, FENDCELL ='-', FENDUCODE =0 WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj));
ccf.GetUseableRouteIDSubAndModifyRoute(_ManageTaskIdx, _ManageKindIdx, Convert.ToInt32(dv[0]["F_BindingDevice"]));
}
else
{
Model.MError me;
if (dv[0]["F_BarCode"].ToString() == "-")//ɨ����δ������
{
me = null;
Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
//me = Model.CGetInfo.GetErrorInfo(732);
//dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=32 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex));
}
else if (dv[0]["F_BarCode"].ToString().IndexOf("111111") >= 0)
{//"1111111111"�������
object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND };
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={2} WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj));
Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
//dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=30 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex));
me = Model.CGetInfo.GetErrorInfo(730);
}
else
{//���벻��ȷ
object[] obj = new object[3] { _ManageKindIdx, _ManageTaskIdx, Model.CGeneralFunction.TASKABEND };
dbo.ExecuteSql(string.Format("UPDATE T_Manage_Task SET FExceptionNO={2} WHERE (F_ManageTaskKindIndex ={0}) AND (FID ={1})", obj));
Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
// dbo.ExecuteSql(string.Format("update T_Monitor_Task set F_Status=31 WHERE (T_Monitor_Task.F_MonitorIndex = {0})", MonitorIndex));
me = Model.CGetInfo.GetErrorInfo(731);
}
if (me != null)
{
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("notifyIcon1", "����:" + devinfo.DeviceName + "," + deviceIdx + "�������ϣ�" + me.ErrorName);
OnRefreshMonitor(rmea);
}
}
if (_ManageKindIdx == 1)
{
sql.Remove(0, sql.Length);
sql.Append("update IO_Control set ERROR_TEXT='").Append(devinfo.DeviceName).Append(",").Append(deviceIdx).Append("���벻��ȷ��").Append("' where CONTROL_ID=").Append(manageTaskIdx);
dboM.ExceSQL(sql.ToString());
}
}
}
//20130709 dbo.ExecuteSql(string.Format("UPDATE T_Base_PLC_Ask SET F_BarCode = '-' WHERE (F_DeviceIndex = {0}) ", deviceIdx));
#endregion
return true;
}
else if (_DeviceKind == 8)
{//20130510�ڶ��Ĵ�����������������
//#region ����
////DataView dv = dbo.ExceSQL(string.Format("SELECT F_BoxBarcode FROM T_Base_PLC_Ask WHERE F_BoxBarcode<>'0' and T_Base_PLC_Ask.F_DeviceIndex = {0}", deviceIdx)).Tables[0].DefaultView;
////if (dv.Count > 0)
////{
//// //�����������
//// dboM.ExecuteSql(string.Format("UPDATE IO_CONTROL SET CONTROL_REMARK ={0} WHERE CONTROL_ID={1}", dv[0][0].ToString(), manageTaskIdx));
//// Model.CGeneralFunction.ActionComplete(deviceIdx, MonitorIndex, 0);
//// dbo.ExecuteSql(string.Format("UPDATE T_Base_PLC_Ask SET F_BoxBarcode = '0' WHERE (F_DeviceIndex = {0})", deviceIdx));
////}
//#endregion
//return true;
sendok = true;
}
#region add by lyj20180428���봩������˫��������
else if (_DeviceKind == 40)
{
boxnum = Model.CGeneralFunction.getDoubleForkMonitorCount(MonitorIndex,tasktype,deviceOrder);
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5], boxnum);
}
#endregion
else
{
sendok = sdo.SendDeviceOrder(msgIdx, MonitorIndex, deviceOrder, deviceIdx, gc[5]);
}
if (sendok == false)
{
if (sdo.CommLayerError != null)
{
RefreshMonitorEventArgs rmea = new RefreshMonitorEventArgs("tsStatus", sdo.CommLayerError);
OnRefreshMonitor(rmea);
}
return false;
}
else//���������ɹ�
{
#region 20210425_�Ϻ��ɵ������ͳ��������ɹ������ó�����
//if (tasktype == 6)
//{
// sql.Remove(0, sql.Length);
// sql.Append("UPDATE T_Base_Device SET F_SwitchLock = ").Append(MonitorIndex)
// .Append(" WHERE F_DeviceIndex = ").Append(deviceIdx);
// dbo.ExecuteSql(sql.ToString());
//}
#endregion
sql.Remove(0, sql.Length);
sql.Append("update T_Monitor_Task set F_SendFlag='1' where F_MonitorIndex=").Append(MonitorIndex);
dbo.ExecuteSql(sql.ToString());//20100905ֻ�ط�������
ccf.SendOrderSuccess(manageKindIdx, manageTaskIdx, MonitorIndex, deviceIdx, _routeID);
#region ����������������ͬ����ͬʱ���淢�������ɹ�
//20100323
devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
int[] corrtask = Model.CGeneralFunction.MutiForkIfSync(MonitorIndex, deviceIdx, deviceKind);
if (devinfo.IfCorrelDoubleFork == "1" && devinfo.DeviceKind == 40 && boxnum == 2 )
{
if (corrtask != null)
{
int rfid = 0, rmankind = 0, rdev = 0;
for (int i = 0; i < corrtask.GetLength(0); i++)
{
if (corrtask[i]!=0)
{
rfid = ccf.GetManageTaskIndexfromMonitor(corrtask[i]);
rmankind = ccf.GetManageTaskKindIndexFromMonitor(corrtask[i]);
rdev = ccf.GetDeviceindexFromMonitor(corrtask[i]);
ccf.SendOrderSuccess(rmankind, rfid, corrtask[i], rdev, 0);
}
}
}
}
//else if (devinfo.IfCorrelDoubleFork == "1" && devinfo.DeviceKind == 40 && tasktype == 2 && boxnum == 2)
//{
//}
#endregion
return true;
}
}
else
{
return false;
}
#endregion
}
}
catch (Exception ex)
{//20110608
CControlError = string.Format("������������SendMonitorTaskʱ��{0}", ex.StackTrace + ex.Message);
return false;
}
}
int GetDeviceFromMonitor(int monitorIndex)
{
DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex, F_DeviceIndex FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(monitorIndex).Append(")");
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();
}
}
/// <summary>
/// ��ȡ���õ�Ŀ��λ�ã��������������߳���վ̨
/// </summary>
/// <param name="manageTaskIdx">������������</param>
/// <param name="manageKindIdx">������������</param>
/// <returns></returns>
bool GetUsableDestination(int manageTaskIdx, int manageKindIdx)
{
//20100610����һ��·�����ã����������ٵ��յ��豸
Dictionary<int, int> advDev = new Dictionary<int, int>();
object ob;
DataView dv = new DataView();
DataRowView dr = null;
DataView dvIO = new DataView();
DataTable dtd = new DataTable();
DataTable dt = new DataTable();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT * FROM T_Manage_Task WHERE (FID = ").Append(manageTaskIdx).Append(") AND (F_ManageTaskKindIndex = ").Append(manageKindIdx).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count <= 0)
{
return false;
}
dr = dv[0];
//20091107
sql.Remove(0, sql.Length);
sql.Append("select CONTROL_ID, CONTROL_STATUS from IO_Control where (CONTROL_ID = ").Append(Convert.ToInt32(dr["FID"])).Append(") AND ((CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(") or (CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEREPLY).Append("))");
dvIO = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvIO.Count <= 0)
{
//ֻ�������ĵ���������·�������޸ĵ����Զ�����·��
if (dr["F_ManageTaskKindIndex"].ToString() != "1") return false;
string adviceDev = "";
sql.Remove(0, sql.Length);
sql.Append("SELECT F_TASKKIND, F_DESTINATION FROM T_Base_Destination WHERE (F_Warehouse='").Append(dr["FENDWAREHOUSE"]).Append("') and (F_TASKKIND = ").Append(dr["FCONTROLTASKTYPE"]).Append(") and (F_AbendStation=1) and (F_DESTINATION=").Append(dr["FENDDEVICE"]).Append(")");
dtd = dbo.ExceSQL(sql.ToString()).Tables[0];
if (dtd.Rows.Count > 0)//ԭ���յ���Ӧ��վ̨��ô����������վ̨������Ҫ�ı�
{
adviceDev = dtd.Rows[0]["F_DESTINATION"].ToString();
return false;
}
else
{
//���ҿ���Ŀ��λ��
sql.Remove(0, sql.Length);
sql.Append("SELECT F_TASKKIND, F_DESTINATION FROM T_Base_Destination WHERE (F_Warehouse='").Append(dr["FENDWAREHOUSE"]).Append("') and (F_TASKKIND = ").Append(dr["FCONTROLTASKTYPE"]).Append(") and (F_DESTINATION <>").Append(dr["FENDDEVICE"]).Append(") and (F_AbendStation=0)");
dt = dbo.ExceSQL(sql.ToString()).Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
if (CDisassembleTask.MinRouteID(Convert.ToInt32(dr["FSTARTDEVICE"]), Convert.ToInt32(dt.Rows[i]["F_DESTINATION"]), dr["FUseAwayFork"]) != -1)
{
//20100610ͳ�Ƶ��յ��豸����ִ�е�������
sql.Remove(0, sql.Length);
sql.Append("SELECT count(FENDDEVICE) as counts FROM T_Manage_Task where FENDDEVICE='").Append(dt.Rows[i]["F_DESTINATION"]).Append("' and fstatus>0");
ob = dbo.GetSingle(sql.ToString());
advDev.Add(Convert.ToInt32(dt.Rows[i]["F_DESTINATION"]), Convert.ToInt32(ob));
//20100610 break;
}
}
if (advDev.Count == 0)//20100610
{
return false;
}
else
{//20100610
int mincount = 9999;
foreach (int aaa in advDev.Keys)
{
if (advDev[aaa] < mincount)
{
mincount = advDev[aaa];
adviceDev = aaa.ToString();
}
}
if (adviceDev == "")
{
return false;
}
}
}
else
{//20100610
return false;
}
}
string dtime = DateTime.Now.ToString("u");
dtime = dtime.Substring(0, dtime.Length - 1);
//20091128
dboM.TransBegin();
try
{
sql.Remove(0, sql.Length);
sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(" where CONTROL_ID=").Append(dr["FID"]).Append("");
dboM.ExceSQL(sql.ToString());
//�����������޸�����//
int appid = dboM.GetManageTableIndex("IO_CONTROL_APPLY", true);//CONTROL_APPLY_ID
sql.Remove(0, sql.Length);
sql.Append("INSERT INTO IO_CONTROL_APPLY ( CONTROL_APPLY_ID,CONTROL_ID,CONTROL_APPLY_TYPE,WAREHOUSE_CODE, STOCK_BARCODE, DEVICE_CODE, APPLY_TASK_STATUS, CREATE_TIME, ").Append(
" CONTROL_APPLY_REMARK)").Append(
"VALUES (").Append(appid).Append(",").Append(dr["FID"]).Append(",2,'").Append(dr["FENDWAREHOUSE"]).Append("','").Append(dr["FPALLETBARCODE"]).Append("','").Append(adviceDev).Append("',0,'").Append(dtime).Append("',null)");
dboM.ExceSQL(sql.ToString());
dboM.TransCommit();
//��ManageTaskIdx��ManageKindIdx �ĵ�������ȫ�������ĵ�
sql.Remove(0, sql.Length);
sql.Append("UPDATE T_Monitor_Task SET F_Status = 3 WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")");
dbo.ExceSQL(sql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("CControl.GetUsableDestination", "�Ѷ�������Ŀ��λ�÷����ĵ�", "����������" +
manageKindIdx.ToString() + "-" + manageTaskIdx.ToString(), "���룺" + dr["FPALLETBARCODE"].ToString().ToUpper());
return true;
}
catch (Exception ex)
{
CControlError = string.Format("����ָ������ĵ�ʱ��{0}", ex.StackTrace + ex.Message);
dboM.TransRollback();
return false;
}
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dt.Dispose();
dtd.Dispose();
dv.Dispose();
dvIO.Dispose();
dr = null;
}
}
bool GetRGVIdleDestination(int manageTaskIdx, int manageKindIdx, int RGVGateDevice, bool IfUseNegativeDevice)
{
//20100610 t_Base_device ��F_UsableEndDevice�ֶδ����������߳����Եȵ��豸�����飨�ԷֺŸ�������
//��������λ�ڵ�ǰ�豸ǰ�棨����RGV���߷����ķ����򣩣�ֻ�����ڷ���RGVȡ���͵�һ�������˶�ʱʹ�ã�
//����������ǰ�豸�������豸�������ڷ����ͻ���֮ǰ����������ʹ��.ֱ��RGV����������
//T_Base_RGV_Gate�����ֶΡ�F_EndDevice�����ڼ�������ʱ��������һ����RGV���������ͻ��Ķ�Ӧ�������豸����
//���߳���ʱ��������վ̨һ�������ͻ���Ӧ�ij���վ̨����
//�ɱ���Ŀ��λ�õ�ѡ��ԭ����RGVĿ��λ�ÿ��С����Ŀ��λ�ò���������ִ�еĵ�������������
DataView dv = new DataView();
DataRowView dr = null;
string adviceDev = "";
char[] cc = new char[1] { ';' };
string[] sp;
DataView dvIO = new DataView();
Dictionary<int, int> advDev = new Dictionary<int, int>();
object ob;
DataView dvu = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT * FROM T_Manage_Task WHERE (FID = ").Append(manageTaskIdx).Append(") AND (F_ManageTaskKindIndex = ").Append(manageKindIdx).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count <= 0)
{
return false;
}
dr = dv[0];
//ֻ�������ĵ���������·�������޸ĵ����Զ�����·��
if (dr["F_ManageTaskKindIndex"].ToString() != "1") return false;
sql.Remove(0, sql.Length);
sql.Append("select CONTROL_ID, CONTROL_STATUS from IO_Control where (CONTROL_ID = ").Append(Convert.ToInt32(dr["FID"])).Append(") AND ((CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(") or (CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKCANCEL).Append(") or(CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEREPLY).Append("))");
dvIO = dboM.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvIO.Count <= 0)
{
#region ����T_Base_Device����F_UsableEndDevice���ҿ����յ��豸
sql.Remove(0, sql.Length);
sql.Append("select F_UsableEndDevice from T_Base_Device where F_UsableEndDevice is not null and F_DeviceIndex=").Append(RGVGateDevice).Append("");
dvu = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvu.Count > 0)
{
int enddv = 0, DESTINATION = 0;
sp = dvu[0]["F_UsableEndDevice"].ToString().Split(cc);
for (int i = sp.GetLowerBound(0); i <= sp.GetUpperBound(0); i++)
{
if (int.TryParse(sp[i], out enddv) == false) continue;
enddv = Convert.ToInt32(sp[i]);
if (enddv < 0)
{
//����������ǰ�豸ǰ�����豸������RGV���߷����ķ�������
if (IfUseNegativeDevice == true)
{
enddv = -(enddv);
}
else
{
continue;
}
}
devinfo = Model.CGetInfo.GetDeviceInfo(enddv);
if ((devinfo.HaveGoods == true) || (devinfo.RunState == 2))
{//Ŀ��λ�ñ�ռ�û��߹���
continue;
}
sql.Remove(0, sql.Length);
sql.Append("SELECT F_EndDevice FROM T_Base_RGV_Gate WHERE (F_RGVGateDeviceIndex = ").Append(enddv).Append(") AND (F_EndDevice IS NOT NULL)");
ob = dbo.GetSingle(sql.ToString());
if (ob == null) continue;
DESTINATION = Convert.ToInt32(ob);
if (CDisassembleTask.MinRouteID(Convert.ToInt32(dr["FSTARTDEVICE"]), DESTINATION, dr["FUseAwayFork"]) != -1)
{
//20100609ͳ�Ƶ��յ��豸����ִ�е�������
sql.Remove(0, sql.Length);
sql.Append("SELECT count(FENDDEVICE) as counts FROM T_Manage_Task where FENDDEVICE='").Append(DESTINATION).Append("' and fstatus>0");
ob = dbo.GetSingle(sql.ToString());
advDev.Add(DESTINATION, Convert.ToInt32(ob));
}
}
}
else
{
return false;
}
if (advDev.Count <= 0)
{
return false;
}
else
{
int mincount = 9999;
foreach (int aaa in advDev.Keys)
{
if (advDev[aaa] < mincount)
{
mincount = advDev[aaa];
adviceDev = aaa.ToString();
}
}
if (adviceDev == "")
{
return false;
}
}
#endregion
//20101108int fid = dboM.GetManageTableIndex("IO_CONTROL_APPLY");
string dtime = DateTime.Now.ToString("u");
dtime = dtime.Substring(0, dtime.Length - 1);
dboM.TransBegin();
try
{
sql.Remove(0, sql.Length);
sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKALTERROUTEAPPLY).Append(" where CONTROL_ID=").Append(dr["FID"]).Append(" and CONTROL_STATUS<>").Append(Model.CGeneralFunction.TASKCANCEL).Append("");
dboM.ExceSQL(sql.ToString());
//�����������޸�����
int appid = dboM.GetManageTableIndex("IO_CONTROL_APPLY", true);//CONTROL_APPLY_ID
sql.Remove(0, sql.Length);
sql.Append("INSERT INTO IO_CONTROL_APPLY (CONTROL_APPLY_ID, CONTROL_ID, WAREHOUSE_CODE, STOCK_BARCODE, DEVICE_CODE, APPLY_TASK_STATUS, CREATE_TIME,CONTROL_APPLY_REMARK)").Append(
"VALUES (").Append(appid).Append(",").Append(dr["FID"]).Append(",'").Append(dr["FENDWAREHOUSE"]).Append("','").Append(dr["FPALLETBARCODE"]).Append("','").Append(adviceDev).Append("',0,'").Append(dtime).Append("',null)");
dboM.ExceSQL(sql.ToString());
dboM.TransCommit();
//��ManageTaskIdx��ManageKindIdx �ĵ�������ȫ�������ĵ�
sql.Remove(0, sql.Length);
sql.Append("UPDATE T_Monitor_Task SET F_Status = 3 WHERE (F_ManageTaskIndex = ").Append(manageTaskIdx).Append(") AND (F_ManageTASKKINDINDEX =").Append(manageKindIdx).Append(")");
dbo.ExceSQL(sql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("CControl.GetRGVIdleDestination", "������Ŀ��λ�÷����ĵ�", "����������" +
manageKindIdx.ToString() + "-" + manageTaskIdx.ToString(), "���룺" + dr["FPALLETBARCODE"].ToString().ToUpper());
return true;
}
catch (Exception ex)
{
dboM.TransRollback();
CControlError = string.Format("����ָ������ĵ�ʱ��{0}", ex.StackTrace + ex.Message);
return false;
}
}
else
{
return false;
}
}
catch (Exception ex)
{
CControlError = string.Format("����ָ������ĵ�ʱ��{0}", ex.StackTrace + ex.Message);
return false;
}
finally
{
dv.Dispose();
dr = null;
cc = null;
sp = null;
dvIO.Dispose();
dvu.Dispose();
}
}
/// <summary>
/// �����ڶ����������������Զ��������ĵ�����������
/// </summary>
/// <param name="controlTaskType">������������</param>
/// <param name="devindex">�豸����</param>
/// <returns></returns>
int GetEnableDoubleForkManageTask(int controlTaskType, int devindex, int FID)
{
DataView dv0 = new DataView(); DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex AND F_DeviceIndex=").Append(devindex).Append(" and FCONTROLTASKTYPE=").Append(controlTaskType);
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
sql.Remove(0, sql.Length);
sql.Append("select min(F_MonitorIndex) as mm from T_Monitor_Task where F_ManageTaskIndex=").Append(dv[i]["F_ManageTaskIndex"]).Append(" and F_ManageTASKKINDINDEX=").Append(dv[i]["F_ManageTASKKINDINDEX"]);
dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv0.Count > 0)
{
if (dv0[0]["mm"].ToString() == dv[i]["F_MonitorIndex"].ToString())
{
if (FID != Convert.ToInt32(dv[i]["F_ManageTaskIndex"]))
{
return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]);
}
}
}
}
return -1;
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv0.Dispose();
}
}
/// <summary>
/// ���öѶ����ڶԵ�վ̨ȡ���Ķ�����������
/// </summary>
/// <param name="controlTaskType">������������</param>
/// <param name="Stackdevindex">�Ѷ����豸����</param>
/// <param name="StationDevice">վ̨�豸����</param>
/// <param name="FID">������������</param>
/// <returns></returns>
int GetEnableDoubleForkManageTask(int controlTaskType, int Stackdevindex, int StationDevice, int FID)
{
DataView dv1 = new DataView();
DataView dv0 = new DataView();
DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_ZXY FROM T_Base_Lane_Gate,T_Base_LaneInfo WHERE ").Append(
"(T_Base_Lane_Gate.F_LaneIndex = T_Base_LaneInfo.F_LaneDeviceIndex) and (T_Base_LaneInfo.F_StackIndex = ").Append(
Stackdevindex).Append(") and (F_LaneGateDeviceIndex=").Append(StationDevice).Append(")");
dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv1.Count <= 0) return -1;
char[] cc = new char[1] { '-' };
string[] zxy = dv1[0]["F_ZXY"].ToString().Split(cc);
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX ").Append(
" FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append(
"T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex AND F_DeviceIndex=").Append(
Stackdevindex).Append(" and FCONTROLTASKTYPE=").Append(controlTaskType).Append(" and F_NumParam1=").Append(zxy[0]).Append(
" and F_NumParam2=").Append(zxy[1]).Append(" and F_NumParam3=").Append(zxy[2]).Append(" and F_RELATIVECONTORLID<>").Append(FID);
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
sql.Remove(0, sql.Length);
sql.Append("select min(F_MonitorIndex) as mm from T_Monitor_Task where F_ManageTaskIndex=").Append(dv[i]["F_ManageTaskIndex"]).Append(" and F_ManageTASKKINDINDEX=").Append(dv[i]["F_ManageTASKKINDINDEX"]).Append(" ");
dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv0.Count > 0)
{
if (dv0[0]["mm"].ToString() == dv[i]["F_MonitorIndex"].ToString())
{
if (FID != Convert.ToInt32(dv[i]["F_ManageTaskIndex"]))
{
return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]);
}
}
}
}
return -1;
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv0.Dispose();
dv1.Dispose();
}
}
/// <summary>
///
/// </summary>
/// <param name="Mankind">����������������</param>
/// <param name="FID">������������</param>
/// <param name="ControlTaskType">������������</param>
/// <param name="UseAwayFork">����������Զ��������</param>
void AlterRoutePath(int Mankind, int FID, int ControlTaskType, char UseAwayFork, int NowDevice)
{
DataView dv = new DataView(); DataView dv1 = new DataView(); DataView dvnew = new DataView();
//���ҵ���ǰ��·���Ƿ������������Ļ���ƥ�䣬��ƥ���ĸĵ�
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT T_Monitor_Task.F_MonitorIndex,T_Monitor_Task.F_DeviceIndex FROM T_Monitor_Task,T_Base_Route_Device where ").Append(
" T_Monitor_Task.F_RouteID = T_Base_Route_Device.F_RouteIDSub AND T_Monitor_Task.F_DeviceIndex = T_Base_Route_Device.F_DeviceIndex and T_Monitor_Task.F_ManageTaskIndex=").Append(
FID).Append(" and T_Monitor_Task.F_ManageTASKKINDINDEX=").Append(Mankind).Append(" and T_Base_Route_Device.F_UseAwayFork<>'").Append(UseAwayFork).Append("'");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
sql.Remove(0, sql.Length);
sql.Append("select * from T_Manage_Task where F_ManageTaskKindIndex=").Append(Mankind).Append(" and FID=").Append(FID);
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
//20100702
sql.Remove(0, sql.Length);
sql.Append("SELECT T_Base_Route_Device.F_RouteIDSub FROM T_Base_Route,T_Base_Route_Device where T_Base_Route.F_RouteID = T_Base_Route_Device.F_RouteID ").Append(
" and (T_Base_Route_Device.F_UseAwayFork = '").Append(UseAwayFork).Append("') AND (T_Base_Route_Device.F_DeviceIndex = ").Append(NowDevice).Append(") AND (T_Base_Route.F_StartDevice = ").Append(
dv[0]["FSTARTDEVICE"]).Append(") AND (T_Base_Route.F_EndDevice = ").Append(dv[0]["FENDDEVICE"]).Append(" and F_RouteKind=").Append(ControlTaskType).Append(")");
;
dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv1.Count > 0)
{
int routeidNew = Convert.ToInt32(dv1[0][0]);
//ɾ��ԭ���������޸�·�����񣬲����µ���������ֻ���������豸��ʼ������
sql.Remove(0, sql.Length);
sql.Append("DELETE FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(FID).Append(") AND (F_ManageTASKKINDINDEX =").Append(Mankind).Append(")");
dbo.ExceSQL(sql.ToString());
if (CDisassembleTask.CreateMonitor(Mankind, FID, routeidNew, dv[0], 3) > 0)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(
FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(
NowDevice).Append(") AND (F_RouteID = ").Append(routeidNew).Append(
") AND (F_Status = 3) ");
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(
FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_Status = 3)");
dbo.ExceSQL(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Monitor_Task set F_Status =0 where (F_ManageTaskIndex = ").Append(
FID).Append(") AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_Status = 3)");
dbo.ExceSQL(sql.ToString());
}
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv1.Dispose();
dvnew.Dispose();
}
}
/// <summary>
/// �ж�˫����������
/// </summary>
/// <param name="taskno"></param>
/// <returns></returns>
int GetDoubleForkMinRouteTask(int taskno)
{
DataView dv = new DataView();
try
{
//����˫����ֱ�ӷ���taskno����˫�浫�ǿ���ͬ����ֱ�ӷ���taskno
//˫�治��ͬ���ķ������뵱ǰ�Ѷ���λ�����̵�taskno
int manKind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(taskno);
int manFid = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(taskno);
int deviceindex = Model.CGeneralFunction.GetDeviceIndexFromMonitor(taskno);
int devKind = Model.CGeneralFunction.GetDeviceKindIdx(deviceindex);
int devOrder = Model.CGeneralFunction.GetDeviceOrderFromMonitor(taskno);
devinfo = Model.CGetInfo.GetDeviceInfo(deviceindex);
int nX = Model.CGeneralFunction.GetXCoorFromMonitor(taskno, deviceindex, devOrder);
int nY = Model.CGeneralFunction.GetYCoorFromMonitor(taskno, deviceindex, devOrder);
double nXY = 0, doubleXY = 0, doubleX = 0, doubleY = 0;
nXY = Math.Pow((double)(nX - devinfo.XCoor), 2) + (Math.Pow((double)(nY - devinfo.YCoor), 2));
if (devinfo.IfCorrelDoubleFork == "1")
{
Dictionary<int, string[]> df = Model.CGeneralFunction.GetDoubleForkMonitorInfo(taskno, deviceindex);
if (df == null) return taskno;
if (Model.CGeneralFunction.MutiForkIfSync(taskno, deviceindex, devKind) == null)
{
#region ����ÿ����������
foreach (int cortask in df.Keys)
{
//20120906
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex FROM dbo.T_Monitor_Task WHERE (F_MonitorIndex = ").Append(cortask).Append(") AND (F_status = 0)");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count <= 0)
{
continue;
}
#region ����ָ��ǵ�һ��ָ��ܷ���
int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(cortask);
int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(cortask);
sql.Remove(0, sql.Length);
sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != cortask.ToString()))
{
return -1;
}
}
#endregion
if (devKind == 1)//�Ѷ���
{//�������ڵ�����λ������ִ�и�����20120906���˵����Ľ���������λ��ȡ�����������Ѷ���������Ӧ�����Ƿ��л�
//if (devOrder == 5)//�ͻ�ָ��ʱ�ж�20110505
//{
// if (true == IfChangeForkCell_LastRun(cortask))
// {
// continue;
// }
//}
doubleX = Model.CGeneralFunction.GetXCoorFromMonitor(cortask, deviceindex, devOrder);
doubleY = Model.CGeneralFunction.GetYCoorFromMonitor(cortask, deviceindex, devOrder);
doubleXY = Math.Pow((double)(doubleX - devinfo.XCoor), 2) + (Math.Pow((double)(doubleY - devinfo.YCoor), 2));
if (nXY > doubleXY)
{
nXY = doubleXY;
taskno = cortask;
}
}
else if (devKind == 6)//AGV
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(nX).Append(")");
nXY = Convert.ToInt32(dbo.GetSingle(sql.ToString()));
sql.Remove(0, sql.Length);
sql.Append("SELECT F_Sequence FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(doubleX).Append(")");
doubleXY = Convert.ToInt32(dbo.GetSingle(sql.ToString()));
if (nXY < doubleXY)
{
return taskno;
}
else
{
return Convert.ToInt32(df[0]);
}
}
else
{
return taskno;
}
}
#endregion
//������Сֵ��������
return taskno;
}
else
{
#region ����ÿ����������
foreach (int cortask in df.Keys)
{
#region ����ָ��ǵ�һ��ָ��ܷ���
int rmankind = Model.CGeneralFunction.GetManageTaskKindIndexFromMonitor(cortask);
int rman = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(cortask);
sql.Remove(0, sql.Length);
sql.Append("SELECT MIN(F_MonitorIndex) AS mmi FROM dbo.T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(rman).Append(") AND (F_ManageTASKKINDINDEX = ").Append(rmankind).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((dv[0]["mmi"] != DBNull.Value) && (dv[0]["mmi"].ToString() != cortask.ToString()))
{
return -1;
}
}
#endregion
}
#endregion
return taskno;
}
}
else
{
return taskno;
}
}
catch (Exception ex)
{
CControlError = string.Format("������������GetDoubleForkMinRouteTaskʱ��{0},{1}", sql.ToString(), ex.StackTrace + ex.Message);
return taskno;
}
finally
{
dv.Dispose();
}
}
bool IFAGVGate(int devIndex)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_AGVGateDeviceIndex FROM T_Base_AGV_Gate WHERE (F_AGVGateDeviceIndex = ").Append(devIndex).Append(")");
if (dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView.Count > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// ͬ�������Ѷ���������ҵ��ͨ����ת��λ������ҵ
/// </summary>
/// <param name="taskindex"></param>
/// <param name="ChangeStackCell"></param>
/// <param name="StackIndex"></param>
void ChangeStackCellCode(int taskindex, string ChangeStackCell, int StackIndex)
{//20120820
int[] zxy = ccf.GetCoordinatesFromMonitorTask(taskindex);
StringBuilder zxystr = new StringBuilder();
DataView dvl = new DataView(); DataView dv = new DataView();
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;
char[] cc = new char[1] { '-' };
string[] endCell = ChangeStackCell.Split(cc);
int fid = ccf.GetManageTaskIndexfromMonitor(taskindex);
int Mankind = ccf.GetManageTaskKindIndexFromMonitor(taskindex);
//dbo.TransBegin();
try
{
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(ChangeStackCell).Append("') and F_LaneIndex=").Append(laneway);
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
sql.Remove(0, sql.Length);//20120420
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() + "," + ChangeStackCell
).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 FREMARK='").Append(zxystr.ToString()).Append("',FExceptionNO=").Append(Model.CGeneralFunction.TASKCHANGESTACK).Append(" where FID=").Append(fid).Append(" and F_ManageTaskKindIndex=").Append(Mankind);
dbo.ExecuteSql(sql.ToString());
}
//dbo.TransCommit();
}
catch (Exception ex)
{
throw ex;
//dbo.TransRollback();
}
finally
{
dv.Dispose();
dvl.Dispose();
}
}
int GetIOControlStatus(int TaskIndex)
{
int mankind = ccf.GetManageTaskKindIndexFromMonitor(TaskIndex);
int Fid = ccf.GetManageTaskIndexfromMonitor(TaskIndex);
if (mankind == 1)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT CONTROL_STATUS FROM IO_CONTROL WHERE (CONTROL_ID = ").Append(Fid).Append(")");
object ob = dboM.GetSingle(sql.ToString());
if (ob != null)
{
return Convert.ToInt32(ob);
}
else
{
return 1;
}
}
else
{
return 1;
}
}
/// <summary>
/// ����AGV˫���Ĺ���վ̨,��-1������û�й���
/// </summary>
/// <param name="taskindex">�豸ָ������</param>
/// <returns></returns>
int GetAGVCorrelIndex(int taskindex)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_NumParam2 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
object ob = dbo.GetSingle(sql.ToString());
if (ob != null)
{
int cs = Convert.ToInt32(ob);
if (cs % 2 == 0)
{
return (cs - 1);
}
else
{
return (cs + 1);
}
}
else
{
return -1;
}
}
int GetAGVCorrelConveyorIndex(int taskindex)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_NumParam2 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
object ob = dbo.GetSingle(sql.ToString());
if (ob != null)
{
int cs = Convert.ToInt32(ob);
if (cs % 2 == 0)
{
return (cs + 1);
}
else
{
return (cs - 1);
}
}
else
{
return -1;
}
}
/// <summary>
/// ����AGV�ڴ�վ̨ȡ���ĵ�����������
/// </summary>
/// <param name="controltype">������������</param>
/// <param name="stationIndex">AGVվ̨����</param>
/// <returns></returns>
int GetAGVEnableDoubleForkManageTask(int controltype, int stationIndex, int agv)
{//20110412
DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_MonitorIndex,T_Monitor_Task.F_ManageTaskIndex,T_Monitor_Task.F_ManageTASKKINDINDEX ").Append(
" FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append(
"T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex and FCONTROLTASKTYPE=").Append(
controltype).Append(" and F_NumParam2=").Append(stationIndex).Append(" and F_DeviceIndex=").Append(agv).Append(" and F_Status=0 and F_DeviceCommandIndex=2");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0]["F_ManageTaskIndex"]);
}
return -1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
bool IfInSameLimitX(int fid, int mfid, int manKind)
{
DataView dv = new DataView(); DataView dv1 = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_ForwardLimitX,F_BackLimitX,FEndCol FROM T_Manage_Task,T_Base_LaneInfo WHERE T_Manage_Task.FLANEWAY = T_Base_LaneInfo.F_LaneDeviceIndex and (F_ManageTaskKindIndex = ").Append(manKind).Append(") AND (FID = ").Append(fid).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count == 0)
{
return false;
}
sql.Remove(0, sql.Length);
sql.Append("SELECT F_ForwardLimitX,F_BackLimitX,FEndCol FROM T_Manage_Task,T_Base_LaneInfo WHERE T_Manage_Task.FLANEWAY = T_Base_LaneInfo.F_LaneDeviceIndex and (F_ManageTaskKindIndex = ").Append(manKind).Append(") AND (FID = ").Append(mfid).Append(")");
dv1 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv1.Count == 0)
{
return false;
}
if ((dv[0]["FEndCol"].ToString() == dv[0]["F_ForwardLimitX"].ToString()) && (dv1[0]["F_ForwardLimitX"].ToString() == dv1[0]["FEndCol"].ToString()))
{
return true;
}
if ((dv[0]["FEndCol"].ToString() == dv[0]["F_BackLimitX"].ToString()) && (dv1[0]["F_BackLimitX"].ToString() == dv1[0]["FEndCol"].ToString()))
{
return true;
}
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv1.Dispose();
}
}
int GetAGVFromConveyorDoubleForkGetGoodManageTask(int controltype, int stationIndex, int agv)
{
DataView dv0 = new DataView();
DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT T_Monitor_Task.F_ManageTaskIndex,F_MonitorIndex,T_Manage_Task.F_ManageTaskKindIndex ").Append(
" FROM T_Monitor_Task ,T_Manage_Task where T_Monitor_Task.F_ManageTaskIndex = T_Manage_Task.FID AND ").Append(
"T_Monitor_Task.F_ManageTASKKINDINDEX = T_Manage_Task.F_ManageTaskKindIndex and FCONTROLTASKTYPE=").Append(
controltype).Append(" and F_NumParam2=").Append(stationIndex).Append(" and F_DeviceIndex=").Append(agv).Append(" and F_Status=0 and F_DeviceCommandIndex=2 order by F_MonitorIndex asc");//20110412
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
for (int i = 0; i < dv.Count; i++)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT top 1 F_MonitorIndex ").Append(" FROM T_Monitor_Task where T_Monitor_Task.F_ManageTaskIndex = ")
.Append(dv[i]["F_ManageTaskIndex"].ToString()).Append(
" and F_ManageTASKKINDINDEX = ").Append(dv[i]["F_ManageTaskKindIndex"].ToString()).Append(" order by F_MonitorIndex asc");
dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv0[0]["F_MonitorIndex"].ToString() == dv[i]["F_MonitorIndex"].ToString())
{
return Convert.ToInt32(dv[i]["F_ManageTaskIndex"]);
}
}
}
return -1;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv0.Dispose();
}
}
bool IFHaveSameEndDevice(int fid, int CorrelFid, int mti)
{
DataView dv0 = new DataView(); DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT FENDDEVICE, FENDCELL, FUseAwayFork FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = ").Append(mti).Append(") AND (FID = ").Append(fid).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
sql.Remove(0, sql.Length);
sql.Append("SELECT FENDDEVICE, FENDCELL, FUseAwayFork FROM T_Manage_Task WHERE (F_ManageTaskKindIndex = ").Append(mti).Append(") AND (FID = ").Append(CorrelFid).Append(")");
dv0 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv0.Count > 0)
{
if ((dv[0]["FENDDEVICE"].ToString() == dv0[0]["FENDDEVICE"].ToString()) && (dv[0]["FENDDEVICE"].ToString() == "28001") && (Math.Abs(Convert.ToInt32(dv[0]["FENDCELL"]) - Convert.ToInt32(dv0[0]["FENDCELL"])) == 1))//20110412
{
if ((Convert.ToInt32(dv[0]["FENDCELL"]) > Convert.ToInt32(dv0[0]["FENDCELL"])) && (Convert.ToInt32(dv[0]["FUseAwayFork"]) > Convert.ToInt32(dv0[0]["FUseAwayFork"])))
{
return true;
}
if ((Convert.ToInt32(dv[0]["FENDCELL"]) < Convert.ToInt32(dv0[0]["FENDCELL"])) && (Convert.ToInt32(dv[0]["FUseAwayFork"]) < Convert.ToInt32(dv0[0]["FUseAwayFork"])))
{
return true;
}
return false;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
dv0.Dispose();
}
}
void UpdateAheadDetectUnallow(StringBuilder aheadUnallow, int taskindex)
{
#region 20110505���ӵ���Ϣ��ʾ
int rec = 0;
if (aheadUnallow.Length > 0)
{
rec = dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_ErrorCode ='{0}' WHERE F_MonitorIndex ={1} and F_ErrorCode <>'{0}'", aheadUnallow.ToString(), taskindex));
}
else
{
rec = dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_ErrorCode ='' WHERE F_MonitorIndex ={1} and F_ErrorCode <>''", aheadUnallow.ToString(), taskindex));
}
if (rec > 0)
{
CDataChangeEventArgs cea = new CDataChangeEventArgs(null, null);
OnDataChange("������ǰ����ʱ���쳣", cea);
}
#endregion
}
/// <summary>
/// �����ǵ�����λ��������ִ��
/// </summary>
/// <param name="TaskIndex"></param>
/// <returns></returns>
bool IfChangeForkCell_LastRun(int TaskIndex)
{//20110505
DataView dv = new DataView();
try
{
int laneway = ccf.GetLaneWayFromLaneInfo(ccf.GetDeviceindexFromMonitor(TaskIndex));
int[] zxy = ccf.GetCoordinatesFromMonitorTask(TaskIndex);
string zxystr = (zxy[3].ToString().Length == 1 ? "0" + zxy[0].ToString() : zxy[3].ToString()) + "-" +
((zxy[4].ToString().Length == 1) ? ("0" + zxy[4].ToString()) : (zxy[4].ToString())) + "-" +
((zxy[5].ToString().Length == 1) ? ("0" + zxy[5].ToString()) : (zxy[5].ToString()));
int lanedev = ccf.GetChangeCellStationFromLaneGate(laneway, zxystr);
dv = dbo.ExceSQL(string.Format("SELECT F_ChangeForkCell FROM T_Base_LaneInfo WHERE F_LaneDeviceIndex={0} and (F_ChangeForkCell like '%{1}%' or F_ChangeForkCell like '%{2}%')", laneway, zxystr, lanedev)).Tables[0].DefaultView;
if (dv.Count > 0)//������λ��������ִ��
{
return true;
}
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// ����ʵ�ʹ����ĶѶ����豸����20111020
/// </summary>
/// <param name="deviceIndex">�����Ѷ����豸����</param>
/// <param name="taskIndex">�豸ָ������</param>
/// <param name="manKind">������������</param>
/// <param name="fid">������������</param>
bool AssignStackNo(int deviceIndex, int taskIndex, int manKind, int fid)
{//20120820
DataView dv = new DataView();
Model.MDevice devinfo; int resDev = 0;
try
{
int Xcoor = Model.CGeneralFunction.GetXCoorFromMonitor(taskIndex, deviceIndex, ccf.GetDeviceOrderFromMonitor(taskIndex));
int Zcoor = Model.CGeneralFunction.GetZCoorFromMonitor(taskIndex, deviceIndex, ccf.GetDeviceOrderFromMonitor(taskIndex));
int XcoorS = Model.CGeneralFunction.GetXCoorFromMonitor(taskIndex, deviceIndex, 5);
int ZcoorS = Model.CGeneralFunction.GetZCoorFromMonitor(taskIndex, deviceIndex, 5);
int sno = 0; bool IfCombinedWork = false;
GetSpecialStackNo(deviceIndex, Zcoor, Xcoor, ZcoorS, XcoorS, out sno, out IfCombinedWork);
//�ȿ�����������20111226
if (IfCombinedWork == true)
{
//�����Ѷ������Ͻ�����ҵ
string ChangeStackCell = GetChangeStackCell(deviceIndex);
if (ChangeStackCell != "")
{
ChangeStackCellCode(taskIndex, ChangeStackCell, deviceIndex);
SetStackNo(deviceIndex, sno, manKind, fid);
return true;
}
else
{//20120820û�п��е������Ѷ������õĽ��ӻ�λ
return false;
}
}
//Ȼ�����������������������з����������Ѷ���
resDev = GetPRIStackNo(deviceIndex, Zcoor, Xcoor, ZcoorS, XcoorS);
devinfo = Model.CGetInfo.GetDeviceInfo(resDev);
if (devinfo.RunState == 0 && ccf.GetManTaskReserve(resDev) <= 0 && ccf.GetDeviceLockedState(resDev) == 0)
{//���С�������ִ�С��޹�������ԤԼ��
SetStackNo(deviceIndex, resDev, manKind, fid);
return true;
}
else
{//����35001��ǰλ�ú�����ִ�е�������Ŀ��λ�ÿ����Ƿ�����35002
resDev = devinfo.MutexStack;
devinfo = Model.CGetInfo.GetDeviceInfo(resDev);
if (devinfo.RunState == 0 && ccf.GetManTaskReserve(resDev) <= 0 && ccf.GetDeviceLockedState(resDev) == 0)
{
sql = new StringBuilder(string.Format("SELECT F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_Status > 0) AND (F_DeviceIndex = {0})", devinfo.MutexStack));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if (dv[0]["F_DeviceCommandIndex"].ToString() == "4")//ȡ��
{
if ((GetBarcodeCoor(Convert.ToInt32(dv[0]["F_NumParam2"]), Convert.ToInt32(dv[0]["F_NumParam1"])) + StackMutexXCoor) <= GetBarcodeCoor(Xcoor, Zcoor))
{
SetStackNo(deviceIndex, resDev, manKind, fid);
return true;
}
}
if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//�ͻ�
{
if ((GetBarcodeCoor(Convert.ToInt32(dv[0]["F_NumParam5"]), Convert.ToInt32(dv[0]["F_NumParam4"])) + StackMutexXCoor) <= GetBarcodeCoor(Xcoor, Zcoor))
{
SetStackNo(deviceIndex, resDev, manKind, fid);
return true;
}
}
}
else
{//(resDev - devinfo.MutexStack)�豸����С���豸��ʵ������λ�õ�����ֵҲС
int xcMutex = (resDev - devinfo.MutexStack) * (GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack).XCoor);//20120513
int xMutex = Math.Abs(GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack).XCoor);
int xDev = Math.Abs(GetBarcodeCoor(Xcoor, Zcoor) - Model.CGetInfo.GetDeviceInfo(resDev).XCoor);
devinfo = Model.CGetInfo.GetDeviceInfo(devinfo.MutexStack);//20120513
if ((xDev < xMutex) || ((devinfo.RunState >= 2) && (devinfo.RunState <= 4) && (xcMutex > StackMutexXCoor)))//20120513
{
SetStackNo(deviceIndex, resDev, manKind, fid);
return true;
}
}
}
}
return false;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
private string GetChangeStackCell(int stack)
{//20120820���������Ѷ��������������ж��ĸ������Ѷ���վ̨����
DataView dv = new DataView();
int fids = 0; string cell = ""; int minfids = int.MaxValue;
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_LaneDeviceIndex, F_ChangeStackCell FROM T_Base_LaneInfo where F_StackIndex={0}", stack)).Tables[0].DefaultView;
if (dv.Count > 0)
{
char[] cc = new char[1] { ';' };
string[] sp = dv[0]["F_ChangeStackCell"].ToString().Split(cc);
string ChangeStackCell = string.Empty;
int lanedev = 0;
for (int i = 0; i < sp.GetLength(0); i++)
{//T_Monitor_Task������ F_ChangeStackCell "18001,01-30-02"
int.TryParse(sp[i], out lanedev);
if (lanedev > 0)
{//T_Base_LaneInfo���� F_ChangeStackCell ��F_ChangeForkCell�ֶο�����д������λ��Ӧ����վ̨���豸����
sp[i] = ccf.GetChangeCellFromLaneGate(Convert.ToInt32(dv[0]["F_LaneDeviceIndex"]), lanedev);
}
ChangeStackCell = 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}'", ChangeStackCell)));
if (fids < minfids)
{
minfids = fids;
cell = sp[i];
}
}
}
return cell;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
void SetStackNo(int dummyStackno, int stackno, int manKind, int fid)
{
//20111226���ǵ������׵�վ̨����ǰ���⣬35001-32038��35002-32036
if (StackIfExitTask(stackno) == true) return;
object[] ob = new object[4] { stackno, manKind, fid, dummyStackno };
dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_DeviceIndex ={0} WHERE (F_ManageTASKKINDINDEX = {1}) AND (F_ManageTaskIndex = {2}) AND (F_DeviceIndex = {3})", ob));
dbo.ExecuteSql(string.Format("UPDATE T_Monitor_Task SET F_AheadDetect =replace(F_AheadDetect,{3},{0}) WHERE (F_ManageTASKKINDINDEX = {1}) AND (F_ManageTaskIndex = {2}) ", ob));
}
void GetStackRunX_Zcoor(int StackdeviceIndex, out int Xcoor, out int Zcoor)
{//20111020
DataView dv = new DataView();
try
{
Xcoor = 0;
Zcoor = 1;
sql = new StringBuilder(string.Format("SELECT F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_Status > 0) AND (F_DeviceIndex = {0})", StackdeviceIndex));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//��ȡ��ȡ��
{
Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]);
Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]);
}
else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//�ͻ�
{
Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]);
Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]);
}
}
//else
//{
// int ManTaskReserve = ccf.GetManTaskReserve(StackdeviceIndex);
// if (ManTaskReserve > 0)
// {
// int mti =Convert.ToInt32( ManTaskReserve.ToString().Substring(0, 1));
// int fid = Convert.ToInt32(ManTaskReserve.ToString().Substring(1));
// sql = new StringBuilder(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX={0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid));
// dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// if (dv[0]["F_DeviceIndex"].ToString() == StackdeviceIndex.ToString())
// {
// if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//��ȡ��ȡ��
// {
// Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]);
// Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]);
// }
// else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//�ͻ�
// {
// Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]);
// Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]);
// }
// }
// }
// }
//}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
void GetStackRunReserveX_Zcoor(int StackdeviceIndex, out int Xcoor, out int Zcoor)
{//20111020
Xcoor = 0;
Zcoor = 1; DataView dv = new DataView();
try
{
int ManTaskReserve = ccf.GetManTaskReserve(StackdeviceIndex);
if (ManTaskReserve > 0)
{
int mti = Convert.ToInt32(ManTaskReserve.ToString().Substring(0, 1));
int fid = Convert.ToInt32(ManTaskReserve.ToString().Substring(1));
sql = new StringBuilder(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1, F_NumParam2, F_NumParam3, F_NumParam4, F_NumParam5, F_NumParam6 FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX={0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid));
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if (dv[0]["F_DeviceIndex"].ToString() == StackdeviceIndex.ToString())
{
if ((dv[0]["F_DeviceCommandIndex"].ToString() == "2") || (dv[0]["F_DeviceCommandIndex"].ToString() == "4"))//��ȡ��ȡ��
{
Zcoor = Convert.ToInt32(dv[0]["F_NumParam1"]);
Xcoor = Convert.ToInt32(dv[0]["F_NumParam2"]);
}
else if (dv[0]["F_DeviceCommandIndex"].ToString() == "5")//�ͻ�
{
Zcoor = Convert.ToInt32(dv[0]["F_NumParam4"]);
Xcoor = Convert.ToInt32(dv[0]["F_NumParam5"]);
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// ��������ָ��
/// </summary>
/// <param name="stackno">���öѶ���</param>
/// <param name="order">ָ��</param>
/// <param name="Barcodecoor">���õ�������������</param>
/// <param name="layerhigh">���öѶ����Ļ������߶�</param>
void InsertStackMutexOrder(int stackno, int order, int Barcodecoor, int layerhigh)
{//20111020
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL("SELECT MAX(BarcodeCoor) AS maxcoor, MIN(BarcodeCoor) AS mincoor FROM T_Base_BarcodeCoor").Tables[0].DefaultView;
if (dv.Count > 0)
{
if (Barcodecoor > Convert.ToInt32(dv[0]["maxcoor"]))
{
Barcodecoor = Convert.ToInt32(dv[0]["maxcoor"]);
}
if (Barcodecoor < Convert.ToInt32(dv[0]["mincoor"]))
{
Barcodecoor = Convert.ToInt32(dv[0]["mincoor"]);
}
}
else
{
return;
}
if (order == 2 || order == 4)
{
if (CStaticClass.GetDevicePhotoelectric(stackno, 0) == 0)//20120110
{
order = 2;
}
else
{
order = 1;
}
}
else
{
if (CStaticClass.GetDevicePhotoelectric(stackno, 0) == 1)//20120110
{
order = 3;
}
else
{
order = 1;
}
}
int zc = 0, xc = 0, yc = 0, zc1 = 0, xc1 = 0, yc1 = 0;
if (stackno == 35001)
{
dv = dbo.ExceSQL(string.Format("SELECT TOP 1 ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where BarcodeCoor<={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order)).Tables[0].DefaultView;
}
else
{
dv = dbo.ExceSQL(string.Format("SELECT TOP 1 ABS(MIN(BarcodeCoor - {0})) AS Expr1, XCoor, ZCoor FROM T_Base_BarcodeCoor where BarcodeCoor>={0} and layerhigh<={1} and (brorder=0 or brorder={2}) GROUP BY XCoor, ZCoor ORDER BY Expr1", Barcodecoor, layerhigh, order)).Tables[0].DefaultView;
}
if (dv.Count > 0)
{
if (order == 2)
{
zc = Convert.ToInt32(dv[0]["ZCoor"]);
xc = Convert.ToInt32(dv[0]["XCoor"]);
if (xc == 51) xc = 52;//20120110
if (xc <= 5)
{
zc = 2;
xc = 2;
}
yc = 1;
if (xc == 52) zc = 1;
}
else
{
zc1 = Convert.ToInt32(dv[0]["ZCoor"]);
xc1 = Convert.ToInt32(dv[0]["XCoor"]);
if (xc1 == 51) xc1 = 52;//20120110
if (xc1 <= 5)
{
zc1 = 2;
xc1 = 2;
}
yc1 = 1;
if (xc1 == 52) zc1 = 2;
}
}
else
{
if (order != 1)
{
return;
}
}
dv = dbo.ExceSQL(string.Format("select F_MonitorIndex from T_Monitor_Task where F_DeviceIndex={0} and F_TxtParam='brbrbr'", stackno)).Tables[0].DefaultView;
if (dv.Count <= 0)
{
int hidx = ccf.GetTempManageIdx();
int hmindx = ccf.GetMonitorIndex(hidx, 2);
sql.Remove(0, sql.Length);
sql.Append("insert into T_Monitor_Task(F_MonitorTaskLevel,F_RouteID,F_ManageTaskIndex,F_ManageTaskKindIndex,F_MonitorIndex,").
Append("F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6,F_TxtParam,F_AheadDetect) ").
Append("values(2,").Append(ccf.GetRouteIDsub(stackno)).Append(",").
Append(hidx).Append(",4,").Append(hmindx).Append(",").Append(stackno).
Append(",").Append(order).Append(",").Append(zc).Append(",").Append(xc).Append(",").Append(yc).Append(",").Append(zc1).Append(",").Append(xc1).Append(",").Append(yc1).Append(",'brbrbr','-')");
dbo.ExecuteSql(sql.ToString());
}
}
catch (Exception ex)
{
CControlError = string.Format("���뻥���Ѷ�������ָ��ʱ��{0}", ex.StackTrace + ex.Message);
}
finally
{
dv.Dispose();
}
}
int GetNowDevice(int taskindex)
{
DataView dvb = new DataView();
try
{
sql.Remove(0, sql.Length);
sql.Append("SELECT F_NumParam1 FROM T_Monitor_Task WHERE (F_MonitorIndex = ").Append(taskindex).Append(")");
dvb = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvb.Count > 0)
{
return Convert.ToInt32(dvb[0]["F_NumParam1"]);
}
else
{
return 0;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dvb.Dispose();
}
}
/// <summary>
/// �豸ָ���������Ƿ����ڿ��Թ����Ѷ�����ȡ������
/// </summary>
/// <param name="Stackdev">�Ѷ���</param>
/// <param name="zxy">ȡ����λ</param>
/// <param name="Correlzxy">������λ</param>
/// <param name="nottaskindex">�˴��豸ָ������</param>
/// <returns></returns>
bool IFHaveStackCorrelGetCommand(int Stackdev, string zxy, string Correlzxy, int nottaskindex)
{
DataView dv = new DataView();
char[] cc = new char[1] { '-' };
string[] zxystr = zxy.Split(cc);
string[] zxystrCorrl = Correlzxy.Split(cc);
try
{
int laneway = ccf.GetLaneWayNoFromStack(Stackdev);
int corrdev = 0;
dv = dbo.ExceSQL(string.Format("SELECT F_LaneGateDeviceIndex FROM T_Base_Lane_Gate WHERE (F_LaneIndex = {0}) AND (F_ZXY = '{1}')", laneway, Correlzxy)).Tables[0].DefaultView;
if (dv.Count > 0)
{
corrdev = Convert.ToInt32(dv[0]["F_LaneGateDeviceIndex"]);
}
object[] ob = new object[8] { Stackdev, nottaskindex, Convert.ToInt32(zxystr[0]), Convert.ToInt32(zxystr[1]),Convert.ToInt32(zxystr[2]),
Convert.ToInt32(zxystrCorrl[0]),Convert.ToInt32(zxystrCorrl[1]),Convert.ToInt32(zxystrCorrl[2]) };
dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_DeviceIndex = {0}) AND (F_DeviceCommandIndex =4) AND (F_MonitorIndex<>{1}) and (((F_NumParam1 = {2}) AND (F_NumParam2 = {3}) AND (F_NumParam3 = {4})) or ((F_NumParam1 = {5}) AND (F_NumParam2 = {6}) AND (F_NumParam3 = {7})))", ob)).Tables[0].DefaultView;
if (dv.Count > 0)
{//20120906�����Ѿ��ȴ�������������
sql.Remove(0, sql.Length);//���ͻ��ȴ�˫�������ŵ��ڶѶ���ȡ��TaskIdx
sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(Convert.ToInt32(dv[0]["F_MonitorIndex"])).Append(") AND (F_DeviceIndex=").Append(corrdev).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
return false;
}
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
cc = null;
zxystrCorrl = null;
zxystr = null;
}
}
int GetDeviceOrderFromManTaskReserve(int manTaskReserve, int deviceIndex)
{
DataView dv = new DataView();
try
{
int mti = Convert.ToInt32(manTaskReserve.ToString().Substring(0, 1));
int fid = Convert.ToInt32(manTaskReserve.ToString().Substring(1));
dv = dbo.ExceSQL(string.Format("SELECT F_DeviceIndex,F_DeviceCommandIndex FROM T_Monitor_Task WHERE (F_ManageTASKKINDINDEX = {0}) AND (F_ManageTaskIndex = {1}) order by F_MonitorIndex asc", mti, fid)).Tables[0].DefaultView;
if (dv.Count > 0)
{
if (deviceIndex == Convert.ToInt32(dv[0]["F_DeviceIndex"]))
{
return Convert.ToInt32(dv[0]["F_DeviceCommandIndex"]);
}
else
{
return -1;
}
}
else
{
return -1;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
int GetLayerHigh(int Zcoor, int Xcoor)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT LayerHigh FROM T_Base_BarcodeCoor WHERE (ZCoor = {0}) AND (XCoor = {1})", Zcoor, Xcoor)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return Convert.ToInt32(dv[0][0]);
}
else
{
return 3;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
void InsertUpDeviceUP(int updevice, int Mankind, int ManFID, int mindex)
{
DataRowView drv = null; DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_MonitorTaskLevel, F_RouteID, F_TxtParam, F_UseAwayFork,F_PriorMonitor FROM T_Monitor_Task WHERE F_MonitorIndex={0}", mindex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
mindex = Convert.ToInt32(dv[0]["F_PriorMonitor"]);
drv = dv[0];
}
else
return;
StringBuilder ah = new StringBuilder();
ah.Append("D-").Append(updevice).Append(".7;D").Append(updevice).Append(".0;I").Append(updevice);
if (DeviceAndOrderExitInMonitor(Mankind, ManFID, updevice, 9, 0) == false)
{
#region �������ͻ�����
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,F_UseAwayFork)").Append(
"VALUES (").Append(ManFID).Append(",").Append(Mankind).Append(",").Append(mindex).Append(",").Append(drv["F_MonitorTaskLevel"]
).Append(",").Append(updevice).Append(",").Append(9).Append(",").Append(drv["F_RouteID"]).Append(",").Append(0).Append(",").Append(updevice).Append("," + 0
).Append(",'").Append(ah).Append("','").Append(drv["F_TxtParam"]).Append("','").Append(drv["F_UseAwayFork"]).Append("')");
dbo.ExceSQL(sql.ToString());
#endregion
}
}
catch (Exception ex)
{
CControlError = "���붥��������ָ��ʱ��" + ex.StackTrace + ex.Message;
}
finally
{
dv.Dispose();
drv = null;
}
}
/// <summary>
/// �жϵ��ȱ�T_Monitor_Task�Ƿ����ڵ����������豸������
/// </summary>
/// <param name="Mankind">������������</param>
/// <param name="ManFID">������������</param>
/// <param name="DeviceIndex">�豸����</param>
/// <param name="Order">�豸����</param>
/// <returns></returns>
public bool DeviceAndOrderExitInMonitor(int Mankind, int ManFID, int DeviceIndex, int Order, int ArrowAddress)
{
DataView dv = new DataView();
try
{
if (Order == -1) return true;
sql.Remove(0, sql.Length);
switch (ccf.GetDeviceKindIdx(DeviceIndex))
{
case 1://�Ѷ���
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append(
" AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append(
" AND (F_DeviceCommandIndex = ").Append(Order).Append(")");
break;
case 2://���ͻ�
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append(
" AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append(
" AND (F_DeviceCommandIndex = ").Append(Order).Append(")");
break;
case 4://RGV
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append(
" AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append(
" AND (F_DeviceCommandIndex = ").Append(Order).Append(") and F_NumParam1=").Append(ArrowAddress);
break;
case 6://AGV
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append(
" AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append(
" AND (F_DeviceCommandIndex = ").Append(Order).Append(")");
break;
default:
sql.Append("SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskIndex = ").Append(ManFID).Append(")").Append(
" AND (F_ManageTASKKINDINDEX = ").Append(Mankind).Append(") AND (F_DeviceIndex = ").Append(DeviceIndex).Append(")").Append(
" AND (F_DeviceCommandIndex = ").Append(Order).Append(")");
break;
}
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
CControlError = "ControlSystem.CControl.DeviceAndOrderExitInMonitor:" + ex.StackTrace + ex.Message;
return false;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// �Ѷ����Ƿ����ڱ���ָ����������
/// </summary>
/// <param name="DeviceIndex"></param>
/// <returns></returns>
bool DeviceHandTaskIfRun(int DeviceIndex)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_ManageTASKKINDINDEX=4 and F_DeviceIndex={0} and F_Status>0", DeviceIndex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// �Ѷ����Ƿ����ڱ���ָ���ȴ�����
/// </summary>
/// <param name="DeviceIndex"></param>
/// <returns></returns>
bool DeviceHandTaskIfWaitRun(int DeviceIndex)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_ManageTASKKINDINDEX=4 and F_DeviceIndex={0} and F_Status=0", DeviceIndex)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
bool StackIfExitTask(int stackno)
{
DataView dv = new DataView();
try
{
dv = dbo.ExceSQL(string.Format("SELECT F_MonitorIndex FROM T_Monitor_Task where F_DeviceIndex={0}", stackno)).Tables[0].DefaultView;
if (dv.Count > 0)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
dv.Dispose();
}
}
void GetSpecialStackNo(int virStack, int startZ, int startX, int endZ, int endX, out int stackno, out bool IfCombinedWork)
{
stackno = 0; IfCombinedWork = false;
int Getdevice = 0, Sendevice = 0;
char[] fcc = new char[1] { ';' };
char[] dcc = new char[1] { ',' };
char[] hcc = new char[1] { '-' };
DataView dv = new DataView();
string[] zxys; string[] zx_x; string[] x_x;
try
{
dv = dbo.ExceSQL(string.Format("SELECT T_Base_StackInfo.F_StackIndex, T_Base_StackInfo.F_SpecialZXArea,T_Base_StackInfo.F_PRIZXArea FROM T_Base_StackInfo WHERE T_Base_StackInfo.F_Mutex IS NOT NULL and T_Base_StackInfo.F_VirtualStack={0}", virStack)).Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
zxys = dv[i]["F_SpecialZXArea"].ToString().Split(fcc);//1,0-2;2,0-5
for (int d = 0; d < zxys.GetLength(0); d++)
{
zx_x = zxys[d].Split(dcc);
if (zx_x.GetLength(0) > 1)
{
for (int h = 1; h < zx_x.GetLength(0); h++)
{
x_x = zx_x[h].Split(hcc);
if (x_x.GetLength(0) > 1)
{
if ((Convert.ToInt32(zx_x[0]) == startZ) && (startX >= Convert.ToInt32(x_x[0])) && (startX <= Convert.ToInt32(x_x[1])))
{
Getdevice = Convert.ToInt32(dv[i]["F_StackIndex"]);
}
if ((Convert.ToInt32(zx_x[0]) == endZ) && (endX >= Convert.ToInt32(x_x[0])) && (endX <= Convert.ToInt32(x_x[1])))
{
Sendevice = Convert.ToInt32(dv[i]["F_StackIndex"]);
}
}
}
}
}
}
stackno = Getdevice;
if (Getdevice != Sendevice)
{
devinfo = Model.CGetInfo.GetDeviceInfo(Getdevice);
if (Sendevice == devinfo.VirtualStack)
{
IfCombinedWork = true;
}
else
{
IfCombinedWork = false;
}
}
else
{
IfCombinedWork = false;
}
}
catch (Exception ex)
{
CControlError = "�����Ѷ�����GetSpecialStackNo:" + ex.StackTrace + ex.Message;
}
finally
{
}
}
int GetPRIStackNo(int virStack, int startZ, int startX, int endZ, int endX)
{
int Getdevice = 0;
char[] fcc = new char[1] { ';' };
char[] dcc = new char[1] { ',' };
char[] hcc = new char[1] { '-' };
DataView dv = new DataView();
string[] zxys; string[] zx_x; string[] x_x;
try
{
dv = dbo.ExceSQL(string.Format("SELECT T_Base_StackInfo.F_StackIndex, T_Base_StackInfo.F_SpecialZXArea,T_Base_StackInfo.F_PRIZXArea FROM T_Base_StackInfo WHERE T_Base_StackInfo.F_Mutex IS NOT NULL and T_Base_StackInfo.F_VirtualStack={0}", virStack)).Tables[0].DefaultView;
for (int i = 0; i < dv.Count; i++)
{
zxys = dv[i]["F_PRIZXArea"].ToString().Split(fcc);//1,0-2;2,0-5
for (int d = 0; d < zxys.GetLength(0); d++)
{
zx_x = zxys[d].Split(dcc);
if (zx_x.GetLength(0) > 1)
{
for (int h = 1; h < zx_x.GetLength(0); h++)
{
x_x = zx_x[h].Split(hcc);
if (x_x.GetLength(0) > 1)
{
if ((Convert.ToInt32(zx_x[0]) == startZ) && (startX >= Convert.ToInt32(x_x[0])) && (startX <= Convert.ToInt32(x_x[1])))
{
Getdevice = Convert.ToInt32(dv[i]["F_StackIndex"]);
}
}
}
}
}
}
return Getdevice;
}
catch (Exception ex)
{
CControlError = "�����Ѷ�����GetPRIStackNo:" + ex.StackTrace + ex.Message;
return Getdevice;
}
finally
{
dv.Dispose();
}
}
/// <summary>
/// ��ȡ�ɹ�����������������������
/// </summary>
/// <param name="DevLanewayIOInfo">������������Ϣ</param>
/// <param name="TaskIdx">�豸ָ������</param>
/// <param name="CONTROLTASKTYPE">������������</param>
/// <param name="mti">������������</param>
/// <param name="fid">������������</param>
/// <param name="dtime">��ǰʱ��</param>
/// <returns></returns>
bool GetCorrManageTask(string[] DevLanewayIOInfo, int TaskIdx, int CONTROLTASKTYPE, int mti, int fid, string dtime, out bool IfCorrTaskEnd)
{
IfCorrTaskEnd = false;
DataView dv = new DataView();
try
{
sql.Remove(0, sql.Length);//���ͻ��ȴ�˫�������ŵ��ڶѶ���ȡ��TaskIdx
sql.Append("SELECT F_TaskIndex,F_DeviceIndex,F_Remark FROM T_Base_PLC_Ask WHERE (F_TaskIndex =").Append(Convert.ToInt32(TaskIdx)).Append(") AND (F_Remark <> '') AND (F_DeviceIndex=").Append(DevLanewayIOInfo[0]).Append(")");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
#region �������ȴ���������
string zxy = DevLanewayIOInfo[9];
int waitdevice = Convert.ToInt32(dv[0]["F_DeviceIndex"]);
//DevLanewayIOInfo[8]�������������豸��Ϣ��һ����20120906
char[] cc = new char[1] { ';' };
string[] CorrStations = DevLanewayIOInfo[8].Split(cc);
foreach (string cs in CorrStations)
{
DevLanewayIOInfo = ccf.GetLanewayDeviceInfoFromStackDev(devinfo.DeviceIndex, Convert.ToInt32(cs));//����վ̨����Ϣ
string Correlzxy = DevLanewayIOInfo[9];
DateTime dtq = Convert.ToDateTime(dv[0]["F_Remark"]).AddSeconds(Convert.ToInt32(CStaticClass.DoubleForkWaitTime));
if ((GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN) && (dtq > DateTime.Now))
{
#region û��ʱ,���ǵ�������
//20111231û��ʱ,���ǵ�������
//���ұ��ع��������������������ԣ�����������������
int mfid = GetEnableDoubleForkManageTask(CONTROLTASKTYPE, devinfo.DeviceIndex, int.Parse(DevLanewayIOInfo[0]), fid);
if (mfid > 0)
{
#region ˫��ͬΪǰ���޺��ߺ����޲�����������ִ��
if ((IfInSameLimitX(fid, mfid, mti) == true) && (mti == 1))
{
sql.Remove(0, sql.Length);
sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(fid).Append(")");
dboM.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append(" update IO_CONTROL set CONTROL_STATUS=").Append(Model.CGeneralFunction.TASKSINGLEFORKRUN).Append(" WHERE (CONTROL_ID = ").Append(mfid).Append(")");
dboM.ExecuteSql(sql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("����ִ��ԭ��", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "˫��ͬΪǰ���޺��ߺ����޲�����������ִ��");
IfCorrTaskEnd = true;
return true;
}
#endregion
sql.Remove(0, sql.Length);
sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(fid);
dbo.ExecuteSql(sql.ToString());
sql.Remove(0, sql.Length);
sql.Append("update T_Manage_Task set F_RELATIVECONTORLID=").Append(fid).Append(" where F_ManageTaskKindIndex=").Append(mti).Append(" and FID=").Append(mfid);
dbo.ExecuteSql(sql.ToString());
//�ж��Ƿ�Ϊ1���Ĺ�������:�ǣ���������
if (ccf.GetManageTaskStackFork(mti, mfid) == "1")
{
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_Remark='' where (F_TaskIndex=").Append(TaskIdx).Append(")");
dbo.ExecuteSql(sql.ToString());
IfCorrTaskEnd = true;
}
continue;
}
else
{
//20110505
AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "˫���Ѷ����ȴ���������ȡ��������");
UpdateAheadDetectUnallow(AheadDetectUnallow, TaskIdx);
continue;
}
#endregion
}
else
{
#region 20111230����ִ�м��޻�λ��Ҫ������
#region �Ѷ����ڶ�����ȡ������������֤�Ƿ���Ҫ������
string ChangeForkCell = ccf.IfLimitCellChangeFork(TaskIdx, devinfo.DeviceIndex);
if (ChangeForkCell != "-")//��������Ҫ��������
{
ccf.ChangeEndCellCode(TaskIdx, ChangeForkCell, devinfo.DeviceIndex);
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(waitdevice).Append(")");
dbo.ExecuteSql(sql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("����ִ��ԭ��", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "��������Ҫ��������");
IfCorrTaskEnd = true;
return true;
}
#endregion
#endregion
if ((IFHaveStackCorrelGetCommand(devinfo.DeviceIndex, zxy, Correlzxy, TaskIdx) == true) && (GetIOControlStatus(TaskIdx) != Model.CGeneralFunction.TASKSINGLEFORKRUN))//20101124
{//�������п��Թ��������������¼�ʱ
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_Remark='").Append(dtime).Append("' where (F_DeviceIndex=").Append(waitdevice).Append(")");
dbo.ExecuteSql(sql.ToString());
//20110505
AheadDetectUnallow.Append(devinfo.DeviceIndex.ToString() + "˫���Ѷ�����˫���Ե�վ̨ȡ��" + "���ȴ���������������");
UpdateAheadDetectUnallow(AheadDetectUnallow, TaskIdx);
return false;
}
else
{//��ʱ���߹���ǿ��ִ�е�������
sql.Remove(0, sql.Length);
sql.Append("update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where (F_DeviceIndex=").Append(waitdevice).Append(")");
dbo.ExecuteSql(sql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("����ִ��ԭ��", TaskIdx.ToString(), devinfo.DeviceIndex.ToString(), "��ʱ���߹���ǿ��ִ�е�������");
IfCorrTaskEnd = true;
return true;
}
}
}
#endregion
}
return false;
}
catch (Exception ex)
{
CControlError = "��ȡ�Ѷ�����������GetCorrManageTask:" + ex.StackTrace + ex.Message;
return false;
}
finally
{
dv.Dispose();
}
}
/*
* :getStackNum
* ߣLYJ
* ܣΪӦѶ
* ܣtasknumʾţdeviceIndxʾorderʾ
* ֵѶ ֵΪûֵѶֵʾضѶ
* ڣ2018/01/11
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public int getStacknum(int tasknum, int deviceIndx, int order)
{
int stacknum1 = 0;
int stacknum = 0;
int ordernum = 0;
int x = 0;
int z = 0;
int laneInfo = 0;
int lanesimple = 0;
string lanefromz = string.Empty;
DataView dvlane;
DataView dvmanager;
DataView dvlanestack;
StringBuilder mysql = new StringBuilder();
Model.MDevice deviceinfo = null;
int managernum = 0;
DBOperator dbo = CStaticClass.dbo;
int goallane = 0;
int x1 = 0;
try
{
ordernum = Model.CGeneralFunction.GetDeviceOrderFromMonitor(tasknum);
x = Model.CGeneralFunction.GetXCoorFromMonitor(tasknum, deviceIndx, ordernum);
z = Model.CGeneralFunction.GetZCoorFromMonitor(tasknum, deviceIndx, ordernum);
managernum = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(tasknum);
goallane = getStackGoalLaneNo(tasknum, deviceIndx, ordernum);
if (z > 0)
{
mysql.Append("select top 1 * from ST_CELL where F_Z=").Append(z);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
laneInfo = Convert.ToInt32(dvlane[0]["FLaneWay"]);
}
if (laneInfo > 0)
{
switch (laneInfo)
{
case 18001:
lanesimple = 1;
break;
case 18002:
lanesimple = 2;
break;
case 18003:
lanesimple = 3;
break;
case 18004:
lanesimple = 4;
break;
}
#region add by lyj 20171207 �������жѶ����򲻷���
mysql.Remove(0, mysql.Length);
mysql.Append("select * from T_Base_StackLaneAndLayuerInfo where F_StackStatus<>0 and F_LaneNum=").Append(lanesimple);
dvlanestack = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if(dvlanestack.Count>0)
{
return 0;
}
#endregion
#region add by lyj 20171206 ����������������ִ�еĹ��������� �������Ѷ���
mysql.Remove(0, mysql.Length);
// mysql.Append("select * from T_Manage_Task where FSTATUS=1 and (FSTARTDEVICE=").Append(laneInfo).Append(" or FENDDEVICE=").Append(laneInfo).Append(")");
mysql.Append("select F_ManageTaskIndex from T_Monitor_Task where F_NumParam1 in (select distinct F_Z from ST_CELL where FLaneWay=").Append(laneInfo).Append(") and F_Status=1");
dvmanager = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvmanager.Count > 0)
{
return 0;
}
#endregion
if (order == 4)
{
mysql.Remove(0, mysql.Length);
mysql.Append("select * from T_Base_StackLaneAndLayuerInfo where F_LaneNum=").Append(lanesimple).Append(" order by F_Col desc");
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
#region �����´��������������ĶѶ���̨��
if (dvlane.Count>0)
{
stacknum1 = Convert.ToInt32(dvlane[0]["F_DeviceIndex"]);
if (dvlane.Count == 1)
{
deviceinfo = Model.CGetInfo.GetDeviceInfo(stacknum1);
//if (deviceinfo.RunState == 0 && deviceinfo.ManTaskReserve == 0)
if (deviceinfo.RunState == 0)
{
stacknum = stacknum1;
}
}
else if (dvlane.Count == 2)
{
x1 = Convert.ToInt32(dvlane[0]["F_Col"]);
int inlane = getStackInLaneNo(stacknum1);
if (x1 <= x&&inlane!=goallane)//Ŀ��λ�ò��DZ�����������������Զ�����߶˵ĶѶ���
{
deviceinfo = Model.CGetInfo.GetDeviceInfo(stacknum1);
//if (deviceinfo.RunState == 0 && deviceinfo.ManTaskReserve == 0)
if (deviceinfo.RunState == 0)
{
stacknum = stacknum1;
}
}
else
{
deviceinfo = Model.CGetInfo.GetDeviceInfo(stacknum1);
//if (deviceinfo.RunState == 0 && deviceinfo.ManTaskReserve == 0)
if (deviceinfo.RunState == 0 )
{
sentStackLeave(stacknum1);
}
}
}
}
else if (dvlane.Count == 0)
{
mysql.Remove(0, mysql.Length);
mysql.Append("select top 1 * from T_Base_StackLaneAndLayuerInfo where abs(F_LaneNum-").Append(lanesimple).Append(")>=1 and F_StackStatus=0 order by abs(F_LaneNum-").Append(lanesimple).Append("), F_Col desc");
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
stacknum1 = Convert.ToInt32(dvlane[0]["F_DeviceIndex"]);
}
deviceinfo = Model.CGetInfo.GetDeviceInfo(stacknum1);
// if (deviceinfo.RunState == 0 &&deviceinfo.ManTaskReserve == 0)
if (deviceinfo.RunState == 0)
{
stacknum = stacknum1;
}
#region add by lyj20190310��ʾģʽ��һ����ֻ����һ�ŶѶ���
//mysql.Remove(0, mysql.Length);
//mysql.Append("select * from T_WareHouse_DemoSet where FWarehouseType='T' and FDemoFlag=1");
//dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
//if (dvlane.Count > 0)
//{
if (lanesimple == 1 || lanesimple == 2)
{
stacknum = 11001;
}
//}
#endregion
}
if (stacknum > 0)
{
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Manage_Task set FSTACK=").Append(stacknum).Append(" where FID=").Append(managernum);
int a = dbo.ExecuteSql(mysql.ToString());
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Monitor_Task set F_DeviceIndex=").Append(stacknum).Append(",F_AheadDetect=REPLACE(F_AheadDetect,'11000','").Append(stacknum.ToString()).Append(" ') where F_DeviceIndex=11000 and F_ManageTaskIndex=").Append(managernum);
int b = dbo.ExecuteSql(mysql.ToString());
}
}
else if (order == 5)
{
//mysql.Remove(0, mysql.Length);
//mysql.Append("select F_StackNum from T_Base_Device where F_DeviceKindIndex=10 and F_DeviceIndex=").Append(laneInfo);
//dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
//if (dvlane.Count > 0)
//{
// stacknumonlane = Convert.ToInt32(dvlane[0]["F_StackNum"]);
// if (stacknumonlane > 0)
// {
// deviceinfo1 = Model.CGetInfo.GetDeviceInfo(stacknumonlane);
// //if (deviceinfo1.RunState == 0 && deviceinfo1.ManTaskReserve == 0)
// if (deviceinfo1.RunState == 0)
// {
// sentStackLeave(stacknumonlane);
// }
// }
//}
}
#endregion
}
}
return stacknum; ;
}
catch (Exception gsn)
{
return 0;
}
}
/*
* :sentStackLeave
* ߣLYJ
* ܣĿĿжѶ
* ܣstacknumʾѶ
* ֵtrueʾɹfalseʾʧ
* ڣ2018/01/11
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public bool sentStackLeave(int stacknum)
{
int temlanenum = 0;
StringBuilder mysqlleave = new StringBuilder();
DataView dvlanee;
string sxy = "-36-01";
string sz = string.Empty;
string goalcell = string.Empty;
bool blreturn = false;
#region
mysqlleave.Remove(0, mysqlleave.Length);
// mysqlleave.Append("select F_DeviceIndex from T_Base_Device where F_DeviceKindIndex=10 and F_IsShuttleBorad=0 and F_IsVirtualDevice=0 and F_StackNum=0").Append(" and F_DeviceIndex<>").Append(laneno).Append(" order by F_DeviceIndex desc");
mysqlleave.Append("select F_DeviceIndex from T_Base_Device where F_DeviceKindIndex=10 and F_IsShuttleBorad=0 and F_IsVirtualDevice=0 and F_StackNum=0 order by F_DeviceIndex desc");
dvlanee = dbo.ExceSQL(mysqlleave.ToString()).Tables[0].DefaultView;
if (dvlanee.Count > 0)
{
temlanenum = Convert.ToInt32(dvlanee[0]["F_DeviceIndex"]);
}
switch (temlanenum)
{
case 18001:
sz = "01";
break;
case 18002:
sz = "03";
break;
case 18003:
sz = "05";
break;
case 18004:
sz = "07";
break;
}
#endregion
if (sz != null && !sz.Equals(""))
{
goalcell = sz + sxy;
}
string errorfinfo = string.Empty;
//SControlMonitor scm = new SControlMonitor();
try
{
Model.HandTask ht = new Model.HandTask(stacknum, 2, 0, "0", goalcell, goalcell, 0, "");
if(compareGoalAndSearchManageGoal(goalcell)==false)
{
//blreturn = scm.InsertHandTask(ht, out errorfinfo);
blreturn = ccf.InsertHandTask(ht, out errorfinfo);
}
CommonClassLib.CCarryConvert.WriteDarkCasket("���������Ѷ�������", "���ز����IJ����ͽ���:" + blreturn.ToString(), "�Ѷ������豸����:" + stacknum.ToString(), "Ŀ��λ��:" + goalcell);
return true;
}
catch (Exception ee116) { return false; }
finally
{
// scm = null;
goalcell = null;
}
}
/// <summary>
/// �����ѷ��͵ĶѶ��������� add by lyj 20171124
/// </summary>
/// <returns></returns>
public int getSentStackTask()
{
int senttasknum = 0;
StringBuilder mysql = new StringBuilder();
DBOperator dbo = CStaticClass.dbo;
DataView dvlane;
try
{
mysql.Append("select * from T_Monitor_Task where F_Status=1 and F_DeviceIndex like '1100%'");
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
senttasknum = dvlane.Count;
}
return senttasknum; ;
}
catch (Exception gsn)
{
return 0;
}
finally
{
dvlane = null;
mysql = null;
}
}
/*
* :getStackInLaneNo
* ߣLYJ
* ܣȡѶڵ
* ܣdeviceindexʾ
* ֵضѶڵ
* ڣ2018/01/12
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public int getStackInLaneNo(int deviceindex)
{
int laneno = 0;
StringBuilder mysql = new StringBuilder();
DataView dvlane;
try
{
mysql.Append("select F_LaneNumAll from T_Base_StackLaneAndLayuerInfo where F_DeviceIndex=").Append(deviceindex);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
laneno = Convert.ToInt32(dvlane[0]["F_LaneNumAll"]);
}
return laneno; ;
}
catch (Exception gsn)
{
return 0;
}
finally
{
//dbo = null;
dvlane = null;
mysql = null;
}
}
/*
* :getStackGoalLaneNo
* ߣLYJ
* ܣȡѶڵ
* ܣtasknumʾ, deviceIndxʾ, ordernumʾѶ
* ֵضѶͻλڵ
* ڣ2018/01/15
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public int getStackGoalLaneNo(int tasknum, int deviceIndx, int ordernum)
{
int laneno = 0;
int z = 0;
StringBuilder mysql = new StringBuilder();
DataView dvlane;
try
{
z = Model.CGeneralFunction.GetZCoorFromMonitor(tasknum, deviceIndx, ordernum);
if (z > 0)
{
mysql.Append("select top 1 * from ST_CELL where F_Z=").Append(z);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
laneno = Convert.ToInt32(dvlane[0]["FLaneWay"]);
}
}
return laneno; ;
}
catch (Exception gsn)
{
return 0;
}
finally
{
dvlane = null;
mysql = null;
}
}
/*
* :sentStackLeaveOuter
* ߣLYJ
* ܣѶͻʱĿпеĶѶ
* ܣtasknumʾ, deviceIndxʾ, ordernumʾѶ
* ֵtrueʾɹfalseʾʧ
* ڣ2018/01/12
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public bool sentStackLeaveOuter(int tasknum, int deviceIndx, int ordernum )
{
//int laneno = 0;
StringBuilder mysql = new StringBuilder();
int laneInfo = 0;
int stacknumonlane = 0;
DataView dvlane;
int z = 0;
Model.MDevice deviceinfo1 = null;
try
{
z = Model.CGeneralFunction.GetZCoorFromMonitor(tasknum, deviceIndx, ordernum);
if (z > 0)
{
mysql.Append("select top 1 * from ST_CELL where F_Z=").Append(z);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
laneInfo = Convert.ToInt32(dvlane[0]["FLaneWay"]);
}
}
mysql.Remove(0, mysql.Length);
mysql.Append("select F_StackNum from T_Base_Device where F_DeviceKindIndex=10 and F_DeviceIndex=").Append(laneInfo);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
stacknumonlane = Convert.ToInt32(dvlane[0]["F_StackNum"]);
if (stacknumonlane > 0)
{
deviceinfo1 = Model.CGetInfo.GetDeviceInfo(stacknumonlane);
//if (deviceinfo1.RunState == 0 && deviceinfo1.ManTaskReserve == 0)
if (deviceinfo1.RunState == 0)
{
sentStackLeave(stacknumonlane);
}
}
}
return true; ;
}
catch (Exception gsn)
{
return false;
}
finally
{
dvlane = null;
mysql = null;
}
}
/*
* :getJiangQuTaskNum
* ߣLYJ
* ܣȡmonitorȡ
* ܣ
* ֵmonitorȡ
* ڣ2018/01/15
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public int getJiangQuTaskNum()
{
int jiangqu = 0;
StringBuilder mysql = new StringBuilder();
DataView dvlane;
try
{
mysql.Append("select COUNT(*) as num from T_Monitor_Task where F_DeviceCommandIndex=2 and F_DeviceIndex in(11001,11002,11003)");
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
jiangqu = Convert.ToInt32(dvlane[0]["num"]);
}
return jiangqu; ;
}
catch (Exception gsn)
{
return 0;
}
finally
{
//dbo = null;
dvlane = null;
mysql = null;
}
}
/*
* :compareGoalAndSearchManageGoal
* ߣLYJ
* ܣȽϴĿλúͽȡĿλǷһ£һ·trueһ·false
* ܣgoalcellcodeĿλ
* ֵtrueʾͬfalseʾͬ
* ڣ2018/01/15
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public bool compareGoalAndSearchManageGoal(string goalcellcode)
{
bool reflag = false;
StringBuilder mysql = new StringBuilder();
DataView dvlane;
try
{
mysql.Append("select * from T_Manage_Task where F_ManageTaskKindIndex=4 and FSTARTCELL='").Append(goalcellcode).Append("' or FENDCELL='").Append(goalcellcode).Append("'");
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
reflag=true;
}
return reflag; ;
}
catch (Exception gsn)
{
return false;
}
finally
{
//dbo = null;
dvlane = null;
mysql = null;
}
}
/*
* :compareGoalAndSearchManageGoal
* ߣLYJ
* ܣȽϴĿλúͽȡĿλǷһ£һ·trueһ·false
* ܣgoalcellcodeĿλ
* ֵtrueʾͬfalseʾͬ
* ڣ2018/01/15
* άԱ
* άڣ
* άԭ
* ǰ1.0
* ǰ̰1.0beta
*/
public int isOrNotExistStack(int laneno)
{
int reflag = 0;
StringBuilder mysql = new StringBuilder();
DataView dvlane;
try
{
mysql.Append("select * from T_Base_Device where F_StackNum<>0 and F_DeviceIndex=").Append(laneno);
dvlane = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
reflag = Convert.ToInt32(dvlane[0]["F_StackNum"]);
}
return reflag; ;
}
catch (Exception gsn)
{
return 0;
}
finally
{
//dbo = null;
dvlane = null;
mysql = null;
}
}
public int getShuttleBoradNum(int tasknum, int deviceIndx)
{
int ordernum = 0;
int x = 0;
int z = 0;
int y = 0;
int shutttleboardNum = 0;
DataView dv, dvlane, dvCurrent, dvRunStack;
StringBuilder mysql = new StringBuilder();
Model.MDevice deviceinfo = null;
int managernum = 0;
AheadDetectUnallow.Clear();
int uselifer = 0;//�񺽶���
sql.Remove(0, sql.Length);
sql.Append("select * from T_WareHouse_DemoSet");
dv = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dv.Count > 0)
{
if (Convert.ToInt32(dv[0]["F_Lifter"]) == 1)
{
uselifer = 14005;
}
else if (Convert.ToInt32(dv[0]["F_Lifter"]) == 0)
{
uselifer = 14006;
}
}
try
{
ordernum = Model.CGeneralFunction.GetDeviceOrderFromMonitor(tasknum);
//int elevator = 8;
//�������ֲ�ֵ��ͬ���ֳ�
sql.Clear();
sql.Append(string.Format("select count(*)-count(distinct F_Postion) as num from SHUTTLE_POSITION where F_LaneOut=0 "));
dvCurrent = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvCurrent.Count > 0)
{
if (Convert.ToInt32(dvCurrent[0]["num"])!=0)
{
AheadDetectUnallow.Append("�ֳ�ʱ�г��ϱ�ͬ��");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
shutttleboardNum = 0;
return shutttleboardNum;
}
}
if (ordernum==2)
{
x = Model.CGeneralFunction.GetXCoorFromMonitor(tasknum, deviceIndx, ordernum);
z = Model.CGeneralFunction.GetZCoorFromMonitor(tasknum, deviceIndx, ordernum);
y = Model.CGeneralFunction.GetYCoorFromMonitor(tasknum, deviceIndx, ordernum);
int iTargetZ = Model.CGeneralFunction.GetZCoorFromMonitor(tasknum, deviceIndx, 5);
int iTargetX = Model.CGeneralFunction.GetXCoorFromMonitor(tasknum, deviceIndx, 5);
int iTargetY = Model.CGeneralFunction.GetYCoorFromMonitor(tasknum, deviceIndx, 5);
managernum = Model.CGeneralFunction.GetManageTaskIndexfromMonitor(tasknum);
mysql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_LaneOut=0 and F_Postion = ").Append(y); //F_LaneOut=0 ��ʾ���������� �������Ƴ�ȥF_LaneOut=1
dvCurrent = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
if (dvCurrent.Count > 0) //20210122_�Ϻ��ɵ��������������ڲ��г������������������ó�
{
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(dvCurrent[0]["F_DeviceIndex"]));
if (devinfo.RunState >=2)
{
AheadDetectUnallow.Append("�ֳ�ʱ��ѡ��" + Convert.ToInt32(dvCurrent[0]["F_DeviceIndex"]).ToString() + "״̬Ϊ���Ͽ��л�ͣ�� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
shutttleboardNum = 0;
return shutttleboardNum;
}
//���ڵ�������ʱ��ֵ�ͺ󣬴˴���Ҫ�����ж��иò���������û�л�������,�л�������һֱ��
sql.Clear();
sql.Append("SELECT * FROM T_Manage_Task WHERE ( FCONTROLTASKTYPE=5 ) and FSTACK = ").Append(Convert.ToInt32(dvCurrent[0]["F_DeviceIndex"]));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count == 0)
{
mysql.Remove(0, mysql.Length);
mysql.Append("SELECT F_SwitchLock FROM T_Base_Device WHERE F_DeviceIndex = ")
.Append(dvCurrent[0]["F_DeviceIndex"]);
if (Convert.ToInt32(dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView[0]["F_SwitchLock"]) ==
0)
{
shutttleboardNum = Convert.ToInt32(dvCurrent[0]["F_DeviceIndex"]);
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Manage_Task set FSTACK=").Append(dvCurrent[0]["F_DeviceIndex"].ToString()).Append(" where FID=").Append(managernum);
int a = dbo.ExecuteSql(mysql.ToString());
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Monitor_Task set F_DeviceIndex=").Append(dvCurrent[0]["F_DeviceIndex"].ToString()).Append(",F_AheadDetect=REPLACE(F_AheadDetect,'11000','").Append(shutttleboardNum.ToString()).Append("') where F_DeviceIndex=11000 and F_ManageTaskIndex=").Append(managernum);
int b = dbo.ExecuteSql(mysql.ToString());
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient",
"�Ѿ��ֳ�:",
shutttleboardNum.ToString(),
"���ţ�" + shutttleboardNum.ToString() + "FID��" + managernum.ToString());
}
}
}
//�����������ڲ�yû�г����鿴�������Ƿ��п��еij�
else
{
//һ��y=iTargetY,�ж�û�е������Ļ��������Լ������������Ļ�������
mysql.Remove(0, mysql.Length);
mysql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 5 AND ((FEndLayer = ").Append(iTargetY).Append(") or (FStartLayer = ").Append(iTargetY).Append("))");
if (dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView.Count <= 0)
{
mysql.Remove(0, mysql.Length);
mysql.Append("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE = 6 AND ((FEndLayer = ").Append(iTargetY).Append(") or (FStartLayer = ").Append(iTargetY).Append("))");
if (dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView.Count <= 0)
{
mysql.Remove(0, mysql.Length);
mysql.Append(
"SELECT DISTINCT T_Base_Device.F_DeviceIndex FROM T_Base_Device, SHUTTLE_POSITION WHERE T_Base_Device.F_SwitchLock = 0 AND SHUTTLE_POSITION.F_LaneOut=0 and T_Base_Device.F_DeviceIndex = SHUTTLE_POSITION.F_DeviceIndex AND F_DeviceKindIndex = 1 AND T_Base_Device.F_DeviceIndex NOT IN ")
.Append(
"(SELECT DISTINCT(T_Manage_Task.FSTACK) FROM T_Manage_Task WHERE T_Manage_Task.FSTACK = T_Base_Device.F_DeviceIndex and ((T_Manage_Task.FCONTROLTASKTYPE=2 and T_Manage_Task.F_OutStatus<>10)or(T_Manage_Task.FCONTROLTASKTYPE<>2 and T_Manage_Task.F_OutStatus=0))")
.Append(
" AND T_Base_Device.F_DeviceKindIndex = 1 )");//���� AND SHUTTLE_POSITION.F_LaneOut=0 not in �������뽫�������ij����߽�Ҫִ�������ij�ѡ����
dvRunStack = dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView;
//�����������п��еij����������ó�
if (dvRunStack.Count > 0)
{
for (int i = 0; i < dvRunStack.Count; i++)
{
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]));
if (devinfo.RunState >= 2)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��"+ Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString()+ "״̬Ϊ���ϻ����߻�ͣ�� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
sql.Remove(0, sql.Length);//���Ѿ�����������ԤԼ Ҳ���ܷ�
sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0} ) and F_ManTaskReserve<>0 ", Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"])));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "�Ѿ�����������ԤԼ ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (devinfo.XCoor == 0 && devinfo.YCoor == 0 && devinfo.Battery_Status == 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "״̬��Ϊ0 ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (uselifer == 14005)
{
if (devinfo.XCoor == 1)//��ֵΪ1 ���ܻ���
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "��ֵΪ1 ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
else if (uselifer == 14006)
{
if (devinfo.XCoor == 32)//��ֵΪ1 ���ܻ���
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "��ֵΪ1 ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
//�˴������ж�����ѡ�еij����ڲ㻹�г����Լ��ƿ����� ��continue ��
//�˴��ز�һ�£����� devinfo.YCoor;
sql.Clear();
sql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_LaneOut=0 and F_DeviceIndex = ").Append(Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
//if (Convert.ToInt32(dvlane[0]["F_Postion"]) == elevator)//����������������������ʱ û�л�������ȴ��8��
//{
// AheadDetectUnallow.Append("��������ʱ��ѡ��"+ Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString()+ "��8�� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
// continue;
//}
//ѡ�����ij������ڲ��ƿ������Ѿ��ִ˳� ���ܻ���
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=3 and FSTACK = {0} and FStartLayer = {1} ", Convert.ToInt32(dvlane[0]["F_DeviceIndex"]), Convert.ToInt32(dvlane[0]["F_Postion"])));
DataView dvlane2 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane2.Count > 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "�����ƿ����� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
//ѡ�����ij��г��������Ѿ��ִ˳� ��û�������� ���ܻ���
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=6 and FSTARTDEVICE = {0} and FStartLayer = {1} ", Convert.ToInt32(dvlane[0]["F_DeviceIndex"]), Convert.ToInt32(dvlane[0]["F_Postion"])));
DataView dvlane4 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane4.Count > 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "���ڲ��г������� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
//������14005�ӳ����ж� �񺽶���
//ѡ�����ij��г��������Ѿ��ִ˳� ��û�������� ���ܻ���
if (uselifer == 14005)
{
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=2 and F_OutStatus=0 and FSTACK = {0} and FStartLayer = {1} ", Convert.ToInt32(dvlane[0]["F_DeviceIndex"]), Convert.ToInt32(dvlane[0]["F_Postion"])));
DataView dvlane3 = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane3.Count > 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "���г�������δ�������� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
//������14006�������ж� �񺽶���
//�˴������ж�����ѡ�еij����ڲ㻹���������� �������������Ѿ��������� F_OutStatus=20 ��continue ��
if (uselifer == 14006)
{
sql.Clear();
//sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=1 and F_OutStatus=20 and FSTACK = {0} and FEndLayer = {1} ", Convert.ToInt32(dvlane[0]["F_DeviceIndex"]), Convert.ToInt32(dvlane[0]["F_Postion"])));
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=1 and F_OutStatus=20 and FEndLayer = {0} ", Convert.ToInt32(dvlane[0]["F_Postion"])));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("��������ʱ��ѡ��" + Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]).ToString() + "�IJ㻹�����������Ѿ��������� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
}
//������14005�ӳ����ж� �񺽶���
//�˴���������19003��19004 ����ԤԼ����Ϊ0,�������ɻ�������
if (uselifer == 14005)
{
sql.Remove(0, sql.Length);
sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0} or F_DeviceIndex = {1}) and F_ManTaskReserve<>0 ", 14003, 14004));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("������������ʱ14003��14004����ԤԼ����Ϊ0 ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
Model.MDevice devinfo14003 = Model.CGetInfo.GetDeviceInfo(14003);
Model.MDevice devinfo14004 = Model.CGetInfo.GetDeviceInfo(14004);
Model.MDevice devinfo14005 = Model.CGetInfo.GetDeviceInfo(14005);
if (devinfo14003.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14003�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (devinfo14004.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14004�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (devinfo14005.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14005�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
//������14006�ӳ����ж� �񺽶���
if (uselifer == 14006)
{
sql.Remove(0, sql.Length);
sql.Append(string.Format("SELECT * FROM T_Base_Device WHERE (F_DeviceIndex = {0} or F_DeviceIndex = {1}) and F_ManTaskReserve<>0 ", 14001, 14002));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("������������ʱ14001��14002����ԤԼ����Ϊ0 ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
Model.MDevice devinfo14001 = Model.CGetInfo.GetDeviceInfo(14001);
Model.MDevice devinfo14002 = Model.CGetInfo.GetDeviceInfo(14002);
Model.MDevice devinfo14006 = Model.CGetInfo.GetDeviceInfo(14006);
if (devinfo14001.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14001�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (devinfo14002.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14002�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
if (devinfo14006.SplitByte_0 == 1)
{
AheadDetectUnallow.Append("������������ʱ14006�л� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
// �ж�Ŀ���IJ� �����Ѿ��ֳ������� ���� Ŀ����Ϊy
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=2 and F_OutStatus=0 and FSTACK >{0} and FStartLayer = {1} ", 11000, y));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("������������ʱ��Ŀ���������Ѿ��ֳ��������� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=3 and FSTACK > {0} and FStartLayer = {1} ",11000, y));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("������������ʱ��Ŀ���������Ѿ��ֳ��ƿ����� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
sql.Clear();
sql.Append(string.Format("SELECT * FROM T_Manage_Task WHERE FCONTROLTASKTYPE=1 and FSTACK > {0} and FEndLayer = {1} ", 11000, y));
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
AheadDetectUnallow.Append("������������ʱ��Ŀ���������Ѿ��ֳ��������� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
//sql.Clear();
//sql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_Postion = ").Append(elevator);//������������ʱ �������κ�һ����������������
//dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
//if (dvlane.Count > 0)
//{
// AheadDetectUnallow.Append("������������ʱ����������8���Ĵ����� ");
// UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
// continue;
//}
//�񺽶��� У���κ�һ��������ֵ������Ϊ1 //�񺽶��� ��һ�г��ֶ������������� ���ҵ������ز���ȫ���� ����ʱ���ڷ��յ������Ѽ������������� û�취��
int xcoor1 = 0;
if (uselifer == 14005)
{
xcoor1 = 1;
}
else if (uselifer == 14006)
{
xcoor1 = 32;
}
sql.Clear();
sql.Append("SELECT * FROM SHUTTLE_POSITION where F_LaneOut=0 ");//������������ʱ �������κ�һ����������������
dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
if (dvlane.Count > 0)
{
int num = 0;
for (int s = 0; s < dvlane.Count; s++)
{
Model.MDevice devinfoaa = Model.CGetInfo.GetDeviceInfo(Convert.ToInt32(dvlane[s]["F_DeviceIndex"]));
if (devinfoaa.XCoor == xcoor1)
{
num = num + 1;
}
}
if (num > 0)
{
AheadDetectUnallow.Append("������������ʱ���������ϱ���ֵΪ"+ xcoor1 .ToString()+ "�Ĵ����� ");
UpdateAheadDetectUnallow(AheadDetectUnallow, tasknum);
continue;
}
}
shutttleboardNum = Convert.ToInt32(dvRunStack[i]["F_DeviceIndex"]);
//ͬ�����ֳ����ȴ�����������ʱ�ٷֳ�
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Manage_Task set FSTACK=").Append(shutttleboardNum).Append(" where FID=").Append(managernum);
int a = dbo.ExecuteSql(mysql.ToString());
mysql.Remove(0, mysql.Length);
mysql.Append("update T_Monitor_Task set F_DeviceIndex=").Append(shutttleboardNum).Append(",F_AheadDetect=REPLACE(F_AheadDetect,'11000','").Append(shutttleboardNum.ToString()).Append("') where F_DeviceIndex=10000 and F_ManageTaskIndex=").Append(managernum);
int b = dbo.ExecuteSql(mysql.ToString());
//���ɻ�������
mysql.Remove(0, mysql.Length);
mysql.Append("SELECT * FROM SHUTTLE_POSITION WHERE F_DeviceIndex = ")
.Append(shutttleboardNum);
int iCurrentLayer =
Convert.ToInt32(
dbo.ExceSQL(mysql.ToString()).Tables[0].DefaultView[0]["F_Postion"]);
string strTargetCell = string.Format("{0:D2}-{1:D2}-{2:D2}", z, x, y);
string strStartCell = string.Format("{0:D2}-{1:D2}-{2:D2}", 1, 1, iCurrentLayer);
//��������
int hidx1 = ccf.GetTempManageIdx();
string dTime1 = DateTime.Now.ToString("u");
dTime1 = dTime1.Substring(0, dTime1.Length - 1);
string strBarcode = DateTime.Now.ToString("yyyyMMddhhmmss");
mysql.Remove(0, mysql.Length);
mysql.Append("INSERT INTO T_Manage_Task")
.Append(
"(FPALLETBARCODE,FID,F_ManageTaskKindIndex,F_RELATIVECONTORLID,FCONTROLTASKTYPE,FIntoStepOK,FSTARTDEVICE,FSTARTCELL,FENDDEVICE,FENDCELL,FBEGTIME,WORK_MODE,FUseAwayFork,FSTACK, FStartLayer, FEndLayer) values('")
.Append(managernum)
.Append("',")
.Append(hidx1)
.Append(",2,-1,5,0,'")
.Append(shutttleboardNum)
.Append("','").Append(strStartCell)
.Append("','")
.Append(uselifer.ToString())
.Append("','").Append(strTargetCell)
.Append("','").Append(dTime1)
.Append("',0,0,").Append(shutttleboardNum).Append(",").Append(iCurrentLayer).Append(",")
.Append(iTargetY).Append(")");
dbo.ExecuteSql(mysql.ToString());
#region 20210329_���ɻ��������ͽ���������F_ManTaskReserve�ֶ�����������֤��ֻ���л�������
mysql.Remove(0, mysql.Length);
mysql.Append("UPDATE T_Base_Device SET F_ManTaskReserve = ").Append(2.ToString() + hidx1.ToString())
.Append(" WHERE F_DeviceIndex = ").Append(shutttleboardNum);
dbo.ExecuteSql(mysql.ToString());
#endregion
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient",
"�Զ����ɴ����滻������:",
shutttleboardNum.ToString(),
"��ʼ��ַ��" + strStartCell + "Ŀ��λ�ã�" + strTargetCell + "Ҫ������FID��" + managernum.ToString());
break;
}
}
}
}
//û�п��еij������ֳ�
else
{
shutttleboardNum = 0;
}
}
}
return shutttleboardNum;
}
catch (Exception gsn)
{
return 0;
}
}
}
}