You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
400 lines
17 KiB
400 lines
17 KiB
3 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using ICommLayer;
|
||
|
using DBFactory;
|
||
|
using System.Security.Cryptography;
|
||
|
|
||
|
namespace MidDataTable
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 20230313 AGV �м�����ͨѶ�ӿ�������
|
||
|
/// �����豸״̬��
|
||
|
/// �����ߣ�zcy
|
||
|
/// </summary>
|
||
|
public class CGetDeviceState:IGetDeviceState
|
||
|
{
|
||
|
|
||
|
string _commLayerError;
|
||
|
|
||
|
public string CommLayerError
|
||
|
{
|
||
|
get { return _commLayerError; }
|
||
|
set { _commLayerError = value; }
|
||
|
}
|
||
|
|
||
|
public static DBOperator dbo = CommonClassLib.AppSettings.dbo; //20130510
|
||
|
public static DBOperator dboM = CommonClassLib.AppSettings.dboM; //20130510
|
||
|
public CGetDeviceState()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
//~CGetDeviceState()
|
||
|
//{
|
||
|
//
|
||
|
//}
|
||
|
/// <summary>
|
||
|
public int[] GetDeviceState(int DeviceIndex, int TaskIndex)
|
||
|
{
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
public string GetStringData(int DeviceIndex, int TaskIndex)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
//AGV ����������ǰ״̬����WCS����������
|
||
|
//dv.AGV_TASK_ID, dv.FID, dv.AGV_TASK_STATUS
|
||
|
/// <summary>
|
||
|
/// ��ȡagv����
|
||
|
/// </summary>
|
||
|
/// <param name="Fid"></param>
|
||
|
/// <param name="TaskIndex"></param>
|
||
|
/// <param name="status"></param>
|
||
|
/// <param name="WCS_FLAG"></param>
|
||
|
public void GetAGVState(int Fid, int TaskIndex, int status, int WCS_FLAG)
|
||
|
{
|
||
|
DataView valist0 = dbo.ExceSQL(string.Format("select * from t_monitor_task where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex)).Tables[0].DefaultView;
|
||
|
|
||
|
if (valist0.Count > 0)
|
||
|
{
|
||
|
int iAGVStatus = status;
|
||
|
int newTaskStart = 0;
|
||
|
int newTaskEnd = 0;
|
||
|
switch (iAGVStatus)
|
||
|
{
|
||
|
case 1: //�ѽ���
|
||
|
//if (Convert.ToInt32(valist0[0]["F_Status"]) != 9)
|
||
|
//{
|
||
|
// dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status = 9 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
// dbo.ExceSQL(string.Format("update T_Manage_Task set FCurrentLocation == 1001 where FID = {0} ", Fid));
|
||
|
|
||
|
//}
|
||
|
break;
|
||
|
case 2: //�ѷ���
|
||
|
//if (Convert.ToInt32(valist0[0]["F_Status"]) != 10)
|
||
|
//{
|
||
|
// dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status =10 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
//}
|
||
|
break;
|
||
|
case 3: //ȡ������
|
||
|
if (Convert.ToInt32(valist0[0]["F_Status"]) != 3)
|
||
|
{
|
||
|
dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status =3 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
}
|
||
|
{
|
||
|
#region ���ݻ��ѳ������� AGV ȡ�����ɣ������Զ���������ȥ����
|
||
|
newTaskStart = Convert.ToInt32(valist0[0]["F_NumParam2"]); //������������
|
||
|
newTaskEnd = GetPilerLocat(newTaskStart);//���������յ�
|
||
|
if (newTaskEnd != -1)
|
||
|
{
|
||
|
string newBarcode = "D-" + valist0[0]["F_TxtParam"];
|
||
|
if (WCS_FLAG == 0 )
|
||
|
{
|
||
|
if (GetManageTaskCountForStartAndEndDevice(newTaskStart, newTaskEnd, newBarcode) == 0)
|
||
|
{
|
||
|
var ssss = string.Format("INSERT INTO T_Manage_Task(FID, F_ManageTaskKindIndex,FPALLETBARCODE,FMANAGETASKTYPE,FCONTROLTASKTYPE, FTASKLEVEL, FSTARTWAREHOUSE,FENDWAREHOUSE, FSTARTCELL, FSTARTDEVICE, FENDDEVICE, FENDCELL, FSTATUS, FBEGTIME, FIntoStepOK)VALUES('{0}',{1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}')"
|
||
|
, GetTempManageIdx(), 2, newBarcode, 1, 4, 1, 1, 1, "-", newTaskStart, newTaskEnd, "-", 0, DateTime.Now.ToString("u"), 0);
|
||
|
dbo.ExceSQL(ssss);
|
||
|
}
|
||
|
|
||
|
dbo.ExceSQL(string.Format("update AGV_TASK set WCS_FLAG =1 where AGV_TASK_ID = {0} ", TaskIndex));
|
||
|
|
||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "AGVȡ�����ɣ����ɵ���������", newTaskStart.ToString(), TaskIndex.ToString());
|
||
|
}
|
||
|
|
||
|
}
|
||
|
#endregion
|
||
|
}
|
||
|
//Dbo.Deleteable<T_Monitor_Task>().Where(it => it.F_ManageTaskIndex == Fid&& it.F_MonitorIndex == TaskIndex).ExecuteCommand();
|
||
|
|
||
|
break;
|
||
|
case 4: //�ͻ�����
|
||
|
if (Convert.ToInt32(valist0[0]["F_Status"]) != 4)
|
||
|
{
|
||
|
//���µ���ָ������
|
||
|
dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status = 4 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
dbo.ExceSQL(string.Format("update T_Manage_Task set FSTATUS == 999 where FID = {0} ", Fid));
|
||
|
//վ̨����
|
||
|
dbo.ExceSQL(string.Format("update T_Base_Device set F_HaveGoods == 0 where F_DeviceIndex = {0} ", valist0[0]["F_NumParam5"].ToString()));
|
||
|
//�����������յ���״̬
|
||
|
dboM.ExceSQL(string.Format("update IO_CONTROL set CONTROL_STATUS == 999,END_DEVICE_CODE = {0} where CONTROL_ID = {1} ", Fid, valist0[0]["F_NumParam5"].ToString()));
|
||
|
}
|
||
|
#region ���ݻ�������ǰ�������� AGV �ͻ����ɣ������Զ�������ȥɨ��
|
||
|
newTaskStart = Convert.ToInt32(valist0[0]["F_NumParam5"]); //ɨ����������
|
||
|
newTaskEnd = GetScannerLocat(newTaskStart);//ɨ�������յ�
|
||
|
if (newTaskEnd != -1)
|
||
|
{
|
||
|
string newBarcode = "S-" + valist0[0]["F_TxtParam"];
|
||
|
if (WCS_FLAG != 2)
|
||
|
{
|
||
|
if (GetManageTaskCountForStartAndEndDevice(newTaskStart, newTaskEnd, newBarcode) == 0)
|
||
|
{
|
||
|
object ob = new object[15] { GetTempManageIdx(), 2, "S-" + valist0[0]["F_TxtParam"], 1, 4, 1, 1, 1, "-", newTaskStart, newTaskEnd, "-", 0, DateTime.Now.ToString("u"), 0 };
|
||
|
dbo.ExceSQL(string.Format("INSERT INTO T_Manage_Task(FID, F_ManageTaskKindIndex,FPALLETBARCODE,FMANAGETASKTYPE,FCONTROLTASKTYPE, FTASKLEVEL, FSTARTWAREHOUSE,FENDWAREHOUSE, FSTARTCELL, FSTARTDEVICE, FENDDEVICE, FENDCELL, FSTATUS, FBEGTIME, FIntoStepOK)VALUES({0},{1},'{2}',{3},{4},{5},{6},'{7}','{8}','{9}',{10},{11},'{12}',{13},'{14}'})", ob));
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
dbo.ExceSQL(string.Format("update AGV_TASK set WCS_FLAG =2 where AGV_TASK_ID = {0} ", TaskIndex));
|
||
|
|
||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "AGV�ͻ����ɣ�����ɨ��������", newTaskStart.ToString(), TaskIndex.ToString());
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
//ɾ��AGV����
|
||
|
dbo.ExceSQL(string.Format("delete AGV_TASK where FID = {0} and AGV_TASK_ID = {1}", Fid, TaskIndex));
|
||
|
//ɾ������ָ��
|
||
|
dbo.ExceSQL(string.Format("delete T_Monitor_Task where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
//ɾ����������
|
||
|
dbo.ExceSQL(string.Format("delete T_Manage_Task where FID = {0}", Fid));
|
||
|
|
||
|
break;
|
||
|
case 5: //��������
|
||
|
|
||
|
//ɾ��AGV����
|
||
|
dbo.ExceSQL(string.Format("delete AGV_TASK where FID = {0} and AGV_TASK_ID = {1}", Fid, TaskIndex));
|
||
|
//ɾ������ָ��
|
||
|
dbo.ExceSQL(string.Format("delete T_Monitor_Task where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
//ɾ����������
|
||
|
dbo.ExceSQL(string.Format("delete T_Manage_Task where FID = {0}", Fid));
|
||
|
break;
|
||
|
case 6: //����ɾ��
|
||
|
if (Convert.ToInt32(valist0[0]["F_Status"]) != 900)
|
||
|
{
|
||
|
if (Convert.ToInt32(valist0[0]["F_Status"]) == 9 || Convert.ToInt32(valist0[0]["F_Status"]) == 10)
|
||
|
{
|
||
|
//����ָ�����±���
|
||
|
dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status = 900 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
|
||
|
//ɾ��AGV����
|
||
|
dbo.ExceSQL(string.Format("delete AGV_TASK where FID = {0} and AGV_TASK_ID = {1}", Fid, TaskIndex));
|
||
|
}
|
||
|
else if (Convert.ToInt32(valist0[0]["F_Status"]) == 3)
|
||
|
{
|
||
|
int start = Convert.ToInt32(valist0[0]["F_NumParam2"]);
|
||
|
int end = Convert.ToInt32(valist0[0]["F_NumParam5"]);
|
||
|
if (GetPilerLocat(start) != -1) //��������ȡ������AGVɾ����������Ϊ���ɣ�����������
|
||
|
{
|
||
|
//����ָ�����±���
|
||
|
dbo.ExceSQL(string.Format("update T_Monitor_Task set F_Status = 900 where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
|
||
|
//ɾ��AGV����
|
||
|
dbo.ExceSQL(string.Format("delete AGV_TASK where FID = {0} and AGV_TASK_ID = {1}", Fid, TaskIndex));
|
||
|
|
||
|
//�����������ɣ��Ѿ������������ˣ������ܻص���λ�ˣ�
|
||
|
dbo.ExceSQL(string.Format("update T_Manage_Task set FSTATUS == 999 where FID = {0} ", Fid));
|
||
|
//�����������յ���״̬
|
||
|
dboM.ExceSQL(string.Format("update IO_CONTROL set CONTROL_STATUS == 999,END_DEVICE_CODE = {0} where CONTROL_ID = {1} ", Fid, valist0[0]["F_NumParam5"].ToString()));
|
||
|
|
||
|
//ɾ������ָ��
|
||
|
dbo.ExceSQL(string.Format("delete T_Monitor_Task where F_ManageTaskIndex = {0} and F_MonitorIndex = {1}", Fid, TaskIndex));
|
||
|
//ɾ����������
|
||
|
dbo.ExceSQL(string.Format("delete T_Manage_Task where FID = {0}", Fid));
|
||
|
}
|
||
|
else if (GetPilerLocat(end) != -1) //����������AGVɾ��������Ҳɾ��������״̬���¹��������ɵ�������
|
||
|
{
|
||
|
|
||
|
}
|
||
|
else //AGVվ̨���ƿ⣬AGVɾ��������Ҳɾ����״̬���¹���
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//������AGV�������� zcy 20230310
|
||
|
|
||
|
dbo.ExceSQL(string.Format("delete AGV_TASK where FID = {0} and AGV_TASK_ID = {1}", Fid, TaskIndex));
|
||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("RGVTASK", "AGV ������ɾ��", Fid.ToString(), "�Ҳ�����Ӧ�ĵ����������Զ���RGV����ɾ����");
|
||
|
|
||
|
}
|
||
|
}
|
||
|
public int GetManageTaskCountForStartAndEndDevice(int start, int end, string barcode)
|
||
|
{
|
||
|
DataView dv = new DataView();
|
||
|
string sql = string.Empty;
|
||
|
try
|
||
|
{
|
||
|
|
||
|
{
|
||
|
sql = string.Format("SELECT * FROM T_Manage_Task WHERE FSTARTDEVICE = '{0}' and FENDDEVICE = '{1}' and FPALLETBARCODE = '{2}'",
|
||
|
start, end, barcode);
|
||
|
}
|
||
|
dv = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
|
||
|
return dv.Count;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
dv.Dispose();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
//���������ߣ����ز����̻����������ߵ�λ��
|
||
|
public int GetPilerLocat(int device)
|
||
|
{
|
||
|
DataView valist = dbo.ExceSQL(string.Format("select * from T_Base_PLC_Ask where F_DeviceIndex = {0} and F_Askkind = 9", device)).Tables[0].DefaultView;
|
||
|
|
||
|
|
||
|
if (valist.Count > 0)
|
||
|
{
|
||
|
return Convert.ToInt32(valist[0]["F_TempFirstProject"]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
//���������ߣ�����ɨ�������������ߵ�λ��
|
||
|
public int GetScannerLocat(int device)
|
||
|
{
|
||
|
DataView valist = dbo.ExceSQL(string.Format("select * from T_Base_PLC_Ask where F_DeviceIndex = {0} and F_Askkind = 9", device)).Tables[0].DefaultView;
|
||
|
|
||
|
|
||
|
if (valist.Count > 0)
|
||
|
{
|
||
|
return Convert.ToInt32(valist[0]["F_FirstProject"]);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
StringBuilder sql = new StringBuilder();
|
||
|
public static int GetTempManageIdx()
|
||
|
{
|
||
|
//20100108
|
||
|
DataSet ds = new DataSet();
|
||
|
try
|
||
|
{
|
||
|
int maxIdx = 10001;
|
||
|
|
||
|
ds = dbo.ExceSQL("SELECT F_ManageTaskIndex FROM T_Base_Manage_Task_Index_Temp_Task");
|
||
|
if (ds.Tables[0].DefaultView.Count > 0)
|
||
|
{
|
||
|
if ((Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1) >= 19998)
|
||
|
{
|
||
|
maxIdx = 10001;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
maxIdx = (Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
maxIdx = 10001;
|
||
|
}
|
||
|
//�ж���ʱ�����������Ƿ����ظ�ֵ
|
||
|
if (IFExitTempManageIndex(maxIdx) == true)
|
||
|
{
|
||
|
RecordMaxTempManageTaskFID(maxIdx);
|
||
|
maxIdx = GetTempManageIdx();
|
||
|
return maxIdx;
|
||
|
}
|
||
|
|
||
|
RecordMaxTempManageTaskFID(maxIdx);
|
||
|
return maxIdx;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{//20100108
|
||
|
|
||
|
throw ex;
|
||
|
//return 0;
|
||
|
}
|
||
|
finally
|
||
|
{//20100108
|
||
|
ds.Dispose();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public static bool IFExitTempManageIndex(int fid)
|
||
|
{
|
||
|
//20100108
|
||
|
DataView dv = new DataView();
|
||
|
try
|
||
|
{
|
||
|
dv = dbo.ExceSQL(string.Format("SELECT fid FROM T_Manage_Task WHERE F_ManageTaskKindIndex=2 and fid = {0}", fid)).Tables[0].DefaultView;
|
||
|
if (dv.Count > 0)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{//20100108
|
||
|
throw ex;
|
||
|
}
|
||
|
finally
|
||
|
{//20100108
|
||
|
dv.Dispose();
|
||
|
}
|
||
|
}
|
||
|
public static void RecordMaxTempManageTaskFID(int fid)
|
||
|
{//20100108
|
||
|
DataView dv = new DataView();
|
||
|
try
|
||
|
{//20100108
|
||
|
dv = dbo.ExceSQL("select F_ManageTaskIndex from T_Base_Manage_Task_Index_Temp_Task").Tables[0].DefaultView;
|
||
|
if (dv.Count > 0)
|
||
|
{
|
||
|
//if (fid == 19998)
|
||
|
//{
|
||
|
// dbo.ExceSQL("UPDATE T_Base_Manage_Task_Index_Temp_Task SET F_ManageTaskIndex =10001");
|
||
|
// return;
|
||
|
//}
|
||
|
//if (fid > Convert.ToInt32(dv[0]["F_ManageTaskIndex"]))
|
||
|
//{
|
||
|
//20101124
|
||
|
|
||
|
dbo.ExceSQL(string.Format("UPDATE T_Base_Manage_Task_Index_Temp_Task SET F_ManageTaskIndex ={0}", fid));
|
||
|
return;
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
|
||
|
dbo.ExceSQL(string.Format("INSERT INTO T_Base_Manage_Task_Index_Temp_Task (F_ManageTaskIndex)VALUES ({0})", fid));
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{//20100108
|
||
|
|
||
|
throw ex;
|
||
|
//return 0;
|
||
|
}
|
||
|
finally
|
||
|
{//20100108
|
||
|
dv.Dispose();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|