using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Text ;
using System.Windows.Forms ;
using System.ServiceModel ;
namespace wcfControlMonitorClient
{
/// <summary>
/// Creator:Richard.liu and Jack.Ma
/// �豸ʵʱ״̬��ʾ
/// </summary>
public partial class FrmDeviceStatus : Form
{
#region ��������
Model . MDevice _d evice = null ;
int _d eviceIndex ;
DataView dv ;
string sqlstr = string . Empty ;
DBFactory . DBOperator dbo = CStaticClass . dbo ;
/// <summary>
/// ����Ҫ��ʾ���豸����
/// </summary>
public int DeviceIndex
{
set { _d eviceIndex = value ; }
}
private static FrmDeviceStatus _f ormInstance ;
public static FrmDeviceStatus FormInstance
{
get
{
if ( _f ormInstance = = null )
{
_f ormInstance = new FrmDeviceStatus ( ) ;
}
return _f ormInstance ;
}
set { _f ormInstance = value ; }
}
#endregion
#region ���캯��/��ʼ��
public FrmDeviceStatus ( )
{
InitializeComponent ( ) ;
_f ormInstance = this ;
}
private void FrmDeviceStatus_Load ( object sender , EventArgs e )
{
//StringBuilder sql=new StringBuilder();
//sql.Append("SELECT F_LaneGateDeviceIndex from T_Base_Lane_Gate where F_LaneGateDeviceIndex=").Append(_deviceIndex);
//DataView dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
//if (dvlane.Count > 0)
//{
// sql = new StringBuilder();
// sql.Append("SELECT F_DeviceIndex from T_Base_PLC_Ask where F_DeviceIndex=").Append(_deviceIndex);
// dvlane = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvlane.Count > 0)
// {
// this.btCancelDoubleFork.Visible = true;
// }
// else
// {
// this.btCancelDoubleFork.Visible = false;
// }
// this.btLogicHaveGoods.Visible = true;
// this.btLogicNoneGoods.Visible = true;
// textBox1.Visible = true;
//}
//else
//{
// this.btCancelDoubleFork.Visible = false;
// this.btLogicHaveGoods.Visible = false;
// this.btLogicNoneGoods.Visible = false;
// textBox1.Visible = false;
//}
btnRefresh_Click ( null , EventArgs . Empty ) ;
}
#endregion
#region �����豸״̬
private void btnRefresh_Click ( object sender , EventArgs e )
{
try
{
_d evice = Model . CGetInfo . GetDeviceInfo ( _d eviceIndex ) ;
//20100108
if ( _d evice = = null )
{
MessageBox . Show ( "��ѡ�����豸�����ݿ�û�м�¼��" , "������ʾ��" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
return ;
}
#region ��ʾ�����ް�ť
StringBuilder sql = new StringBuilder ( ) ;
sql . Append ( "SELECT F_LaneGateDeviceIndex from T_Base_Lane_Gate where F_LaneGateDeviceIndex=" ) . Append ( _d eviceIndex ) ;
DataView dvlane = dbo . ExceSQL ( sql . ToString ( ) ) . Tables [ 0 ] . DefaultView ;
if ( dvlane . Count > 0 )
{
sql = new StringBuilder ( ) ;
sql . Append ( "SELECT F_DeviceIndex from T_Base_PLC_Ask where F_DeviceIndex=" ) . Append ( _d eviceIndex ) ;
dvlane = dbo . ExceSQL ( sql . ToString ( ) ) . Tables [ 0 ] . DefaultView ;
if ( dvlane . Count > 0 )
{
this . btCancelDoubleFork . Visible = true ;
}
else
{
this . btCancelDoubleFork . Visible = false ;
}
this . btLogicHaveGoods . Visible = true ;
this . btLogicNoneGoods . Visible = true ;
textBox1 . Visible = true ;
}
else
{
this . btCancelDoubleFork . Visible = false ;
this . btLogicHaveGoods . Visible = false ;
this . btLogicNoneGoods . Visible = false ;
textBox1 . Visible = false ;
}
#endregion
//�豸����
this . lblDeviceIndex . Value = _d evice . DeviceIndex ;
//�豸����
this . lblDeviceName . Text = _d evice . DeviceName ;
//�豸ָ������
this . lblTaskIndex . Text = _d evice . TaskNo . ToString ( ) ;
#region ��ʾĿ��λ�ú���������
sqlstr = string . Format ( "SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6, F_TxtParam FROM T_Monitor_Task WHERE (F_MonitorIndex ={0})" , _d evice . TaskNo ) ;
dv = dbo . ExceSQL ( sqlstr ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
int order = Convert . ToInt32 ( dv [ 0 ] [ "F_DeviceCommandIndex" ] ) ;
string info = string . Empty ;
int Z = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam1" ] ) ;
int X = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam2" ] ) ;
int Y = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam3" ] ) ;
int Z1 = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam4" ] ) ;
int X1 = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam5" ] ) ;
int Y1 = Convert . ToInt32 ( dv [ 0 ] [ "F_NumParam6" ] ) ;
if ( _d evice . DeviceKind = = 1 )
{
switch ( order )
{
case 1 : //��ԭ��
info = string . Format ( "��ԭ��:01��01��" ) ;
break ;
case 2 : //��ȡ
info = string . Format ( "��ȡ:{0:D2}��-{1:D2}��-{2:D2}��" , Z , X , Y ) ;
break ;
case 3 : //����
info = string . Format ( "����:{0:D2}��-{1:D2}��-{2:D2}��" , Z1 , X1 , Y1 ) ;
break ;
case 4 : //ȡ
info = string . Format ( "ȡ��:{0:D2}��-{1:D2}��-{2:D2}��" , Z , X , Y ) ;
break ;
case 5 : //��
info = string . Format ( "�ͻ�:{0:D2}��-{1:D2}��-{2:D2}��" , Z1 , X1 , Y1 ) ;
break ;
case 6 :
info = string . Format ( "ȡ�ͻ�:{0:D2}��-{1:D2}��-{2:D2}�� �� {3:D2}��-{4:D2}��-{5:D2}��" , Z , X , Y , Z1 , X1 , Y1 ) ;
break ;
}
if ( _d evice . ManTaskReserve . ToString ( ) . Length > 0 ) {
string fid = _d evice . ManTaskReserve . ToString ( ) . Substring ( 1 ) ;
string sql1 = $"select FPALLETBARCODE from T_Manage_Task where FID={fid}" ;
DataView data = dbo . ExceSQL ( sql1 ) . Tables [ 0 ] . DefaultView ;
if ( data . Count > 0 )
{
this . lblBarcode . Text = data [ 0 ] [ "FPALLETBARCODE" ] . ToString ( ) ;
}
}
}
else if ( _d evice . DeviceKind = = 2 )
{
switch ( order )
{
case 1 : //��ת
info = string . Format ( "��ת" ) ;
break ;
case 2 : //��ת
info = string . Format ( "��ת" ) ;
break ;
case 6 : //�ͳ�
info = string . Format ( "{0}�ͳ���{1}" , Z , Z1 ) ;
break ;
case 8 : //����
info = string . Format ( "����" ) ;
break ;
case 9 : //�½�
info = string . Format ( "�½�" ) ;
break ;
}
this . lblBarcode . Text = dv [ 0 ] [ "F_TxtParam" ] . ToString ( ) ;
}
else if ( _d evice . DeviceKind = = 4 )
{
switch ( order )
{
case 7 : //�˶�
info = string . Format ( "�˶�:{0}" , Z ) ;
break ;
case 8 : //ȡ
info = string . Format ( "ȡ��:{0}" , Z ) ;
break ;
case 9 : //��
info = string . Format ( "�ͻ�:{0}" , Z ) ;
break ;
}
this . lblBarcode . Text = dv [ 0 ] [ "F_TxtParam" ] . ToString ( ) ;
}
this . lblArrowLocation . Text = info ;
//this.lblBarcode.Text = dv[0]["F_TxtParam"].ToString();
}
else
{
//20140109
if ( _d evice . DeviceKind = = 2 )
{
if ( _d evice . RunState = = 5 & & _d evice . SplitByte_0 = = 1 )
{
//������
object bcode = dbo . GetSingle ( string . Format ( "SELECT F_PALLETBARCODE FROM T_Base_Device WHERE (F_DeviceIndex = {0})" , _d evice . DeviceIndex ) ) ;
if ( bcode ! = null )
{
this . lblBarcode . Text = bcode . ToString ( ) ;
}
else
{
this . lblBarcode . Text = "" ;
}
}
else
{
//������
this . lblBarcode . Text = "" ;
}
}
else
{
//������
this . lblBarcode . Text = "" ;
}
//Ŀ��λ��
this . lblArrowLocation . Text = "" ;
}
#endregion
if ( _d evice . DeviceKind = = 3 1 )
{
this . lblTaskIndex . Text = GetMonitorTaskIndexFromBarCode ( new StringBuilder ( _d evice . Barcode ) ) . ToString ( ) ;
this . lblBarcode . Text = _d evice . Barcode ;
this . lblBarcode . Enabled = true ;
}
else
{
this . lblBarcode . Enabled = false ;
}
if ( ( _d evice . DeviceKind = = 1 ) )
{
//this.lblTaskIndex.Text = GetMonitorTaskIndexFromBarCode(new StringBuilder(_device.Barcode)).ToString();
//this.lblBarcode.Text = _device.Barcode;
this . lblBarcode . Enabled = true ;
//this.gb03.Visible = false;
//this.textBox2.Text = _device.Battery_Status.ToString();
//this.textBox3.Text = _device.Mile.ToString();
//this.textBox4.Text = _device.Time.ToString();//����
}
else
{
//this.gb03.Visible = false;
}
if ( _d evice . DeviceIndex > = 3 0 0 0 2 & & _d evice . DeviceIndex < = 3 0 0 0 5 )
{
lblBarcode . Enabled = true ;
}
if ( ( _d eviceIndex < 3 0 0 0 2 | | _d eviceIndex > 3 0 0 0 9 ) & & ( ! _d eviceIndex . ToString ( ) . StartsWith ( "1510" ) ) )
{
//�豸״̬
switch ( _d evice . RunState )
{
case 0 :
lblDeviceStatus . Text = "����" ;
break ;
case 1 :
lblDeviceStatus . Text = "����" ;
break ;
case 2 :
lblDeviceStatus . Text = "����" ;
break ;
case 3 :
lblDeviceStatus . Text = "����" ;
break ;
case 4 :
lblDeviceStatus . Text = "ͣ��" ;
break ;
case 5 : //20090920
lblDeviceStatus . Text = "��������" ;
break ;
}
}
else if ( _d eviceIndex . ToString ( ) . StartsWith ( "1510" ) ) {
switch ( _d evice . RunState )
{
case 0 :
lblDeviceStatus . Text = "����" ;
break ;
case 1 :
lblDeviceStatus . Text = "����" ;
break ;
default :
break ;
}
}
else
{ //AGV�����ź�
switch ( _d evice . RunState )
{
case 0 :
lblDeviceStatus . Text = "��" ;
break ;
case 3 :
lblDeviceStatus . Text = "����" ;
break ;
case 1 :
lblDeviceStatus . Text = "ȡ����(ȡ������)" ;
break ;
case 2 :
lblDeviceStatus . Text = "ȡ������" ;
break ;
case 4 :
lblDeviceStatus . Text = "����(������)" ;
break ;
case 5 :
lblDeviceStatus . Text = "������" ;
break ;
case 6 :
lblDeviceStatus . Text = "ȡ������" ;
break ;
case 7 :
lblDeviceStatus . Text = "������" ;
break ;
case 9 :
lblDeviceStatus . Text = "AGV���뿪" ;
break ;
}
}
if ( _d evice . ErrorCode > = 3 0 )
{
Model . MError err = Model . CGetInfo . GetErrorInfo ( Convert . ToInt32 ( _d evice . DeviceKind . ToString ( ) + _d evice . ErrorCode . ToString ( ) ) ) ;
if ( err ! = null )
{
this . lblErrorName . Text = err . ErrorName + "�����룺" + _d evice . ErrorCode . ToString ( ) ;
}
else
{
this . lblErrorName . Text = _d evice . ErrorCode . ToString ( ) ;
}
}
else
{
this . lblErrorName . Text = "" ;
}
if ( ( _d evice . DeviceKind = = 1 ) )
{
label_X . Text = "��ǰX���꣺" ;
label_Y . Text = "��ǰY���꣺" ;
this . lblNowX . Text = string . Format ( "{0:D2}��" , _d evice . XCoor ) ;
this . lblNowY . Text = string . Format ( "{0:D2}��" , _d evice . YCoor ) ;
//this.lblNowY.Text = _device.YCoor.ToString();
}
else if ( ( _d evice . DeviceKind = = 4 ) )
{
label_X . Text = "��ǰX���꣺" ;
label_Y . Text = "��ǰY���꣺" ;
this . lblNowX . Text = string . Format ( "{0:D2}��" , _d evice . XCoor ) ; //����
this . lblNowY . Text = string . Format ( "{0:D2}" , _d evice . YCoor ) ;
}
else if ( _d evice . DeviceIndex . ToString ( ) . StartsWith ( "3000" ) ) {
label_X . Text = "�Ƿ�����ȡ��" ;
label_Y . Text = "�Ƿ������Ż�" ;
this . lblNowX . Text = _d evice . SplitByte_0 = = 1 ? "����ȡ��" : "������ȡ��" ; //����
this . lblNowY . Text = _d evice . SplitByte_6 = = 1 ? "������" : "��������" ;
DataView dv1 = dbo . ExceSQL ( "select F_AGVTaskBarCode from T_AGVIOStation where F_PLCOtherDevice =" + this . _d eviceIndex ) . Tables [ 0 ] . DefaultView ;
lblBarcode . Text = dv1 [ 0 ] [ "F_AGVTaskBarCode" ] . ToString ( ) ;
}
else
{
label_X . Text = "��ǰX���꣺" ;
label_Y . Text = "��ǰY���꣺" ;
this . lblNowX . Text = "" ;
this . lblNowY . Text = "" ;
}
cB_Empty . Enabled = false ;
if ( _d evice . DeviceKind = = 2 )
{
dv = dbo . ExceSQL ( "select F_DeviceIndex from T_Base_Device where F_HaveGoods >0 and F_DeviceIndex =" + this . _d eviceIndex ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
lblGoods . Text = "������" ;
}
else
{
lblGoods . Text = "������" ;
}
}
else
{
lblGoods . Text = "" ;
}
// label_X.Text = "��ǰX���꣺";
if ( _d evice . DeviceKind = = 7 )
{
lblErrorName . Text = "" ;
dv = dbo . ExceSQL ( string . Format ( "SELECT F_BarCode ,F_Time,F_TempFirstProject,F_FirstProject,F_Hight,f_Size FROM T_Base_PLC_Ask WHERE (F_DeviceIndex = {0})" , _d evice . DeviceIndex ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
this . lblBarcode . Text = dv [ 0 ] [ "F_BarCode" ] . ToString ( ) ;
lblDeviceStatus . Text = dv [ 0 ] [ "F_Time" ] . ToString ( ) ;
label_X . Text = "��������" ;
lblNowY . Text = dv [ 0 ] [ "F_Hight" ] . ToString ( ) ;
label_Y . Text = "�߶�" ;
if ( Convert . ToInt32 ( dv [ 0 ] [ "F_Hight" ] ) > 3 0 )
{
lblNowY . Text = dv [ 0 ] [ "F_Hight" ] . ToString ( ) ;
var dv1 = dbo . ExceSQL ( string . Format ( "SELECT F_ErrorName FROM T_Base_Device_State WHERE (F_DeviceKindIndex = {0} and F_DeviceErrorIndex={1})" , _d evice . DeviceKind , Convert . ToInt32 ( dv [ 0 ] [ "F_Hight" ] ) ) ) . Tables [ 0 ] . DefaultView ;
if ( dv1 . Count > 0 )
{
//label5.Text = "";
lblErrorName . Text = dv1 [ 0 ] [ "F_ErrorName" ] . ToString ( ) ;
}
else
{
lblErrorName . Text = dv1 [ 0 ] [ "F_Hight" ] . ToString ( ) ;
}
}
if ( dv [ 0 ] [ "F_Size" ] . ToString ( ) ! = null )
{
label13 . Text = "����" ;
lblGoods . Text = dv [ 0 ] [ "F_Size" ] . ToString ( ) ;
}
else {
label13 . Text = "�Ƿ������" ;
}
cB_Empty . Checked = ( dv [ 0 ] [ "F_TempFirstProject" ] . ToString ( ) = = "0" ? false : true ) ; //20170215
if ( _d evice . DeviceIndex . ToString ( ) . Length < = 5 )
{
this . lblBarcode . Enabled = true ;
cB_Empty . Enabled = true ;
}
}
//lblErrorName.Text = "";
//lblDeviceStatus.Text = "";
}
//�Ƿ�������
//20120417��ԤԼ�ĵ�������
dv = dbo . ExceSQL ( string . Format ( "SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_ManageTaskKindIndex = 4 and F_MonitorIndex={0})" , Convert . ToInt32 ( this . lblTaskIndex . Text ) ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
lblManTask . Text = "�ֹ�����" ;
}
else
{
dv = dbo . ExceSQL ( string . Format ( "select F_ManTaskReserve from T_Base_Device where F_ManTaskReserve>0 and F_DeviceIndex ={0}" , this . _d eviceIndex ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
int mankind = Convert . ToInt32 ( dv [ 0 ] [ 0 ] . ToString ( ) . Substring ( 0 , 1 ) ) ;
long fid = Convert . ToInt64 ( dv [ 0 ] [ 0 ] . ToString ( ) . Substring ( 1 ) ) ;
lblManTask . Text = fid . ToString ( ) ;
dv = dbo . ExceSQL ( string . Format ( "SELECT F_TxtParam FROM T_Monitor_Task WHERE (F_ManageTaskKindIndex = {0} and F_ManageTaskIndex={1})" , mankind , fid ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
lblBarcode . Text = dv [ 0 ] [ 0 ] . ToString ( ) ; ;
}
}
else
{
lblManTask . Text = "" ;
}
}
dv = dbo . ExceSQL ( string . Format ( "SELECT F_DeviceIndex,F_PalletBarcodeLength,F_BarCode FROM T_Base_PLC_Ask WHERE (F_Askkind = 4 OR F_Askkind = 13 OR F_Askkind = 14) AND (F_BindingDevice = {0})" , this . _d eviceIndex ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
// gbBarcode.Visible = true;
CStaticClass . WcfControl . BeginGetReadedAndReportedBarcode ( this . _d eviceIndex , new AsyncCallback ( CallbackGetReadedAndReportedBarcode ) , null ) ;
}
else
{
// gbBarcode.Visible = false;
}
if ( _d evice . Dbw1Address ! = - 1 )
{
btnReset . Visible = true ;
btnAnswer . Visible = true ;
}
else
{
btnReset . Visible = false ;
btnAnswer . Visible = false ;
}
if ( _d evice . DeviceIndex . ToString ( ) . StartsWith ( "3000" ) )
{
AGVStatesUpdate . Visible = true ;
btnReset . Visible = false ;
btnAnswer . Visible = false ;
}
else {
AGVStatesUpdate . Visible = false ;
btnReset . Visible = true ;
btnAnswer . Visible = true ;
}
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
void CallbackGetReadedAndReportedBarcode ( IAsyncResult ar )
{
string errortext , ReadedBarcode , ReportedBarcode ;
try
{
bool rt = CStaticClass . WcfControl . EndGetReadedAndReportedBarcode ( out ReadedBarcode , out ReportedBarcode , out errortext , ar ) ;
if ( rt = = true )
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
//lblReadedBarcode.Text = ReadedBarcode;
//lblReportedBarcode.Text = ReportedBarcode;
} ) ) ;
}
else
{
this . BeginInvoke ( new MethodInvoker ( delegate ( )
{
//lblReadedBarcode.Text ="";
//lblReportedBarcode.Text = "";
} ) ) ;
if ( errortext ! = "" )
{
MessageBox . Show ( errortext , "������ʾ��" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
}
}
}
catch ( Exception ex ) //20170115
{
throw ex ;
}
}
#endregion
#region �رմ���
private void btnClose_Click ( object sender , EventArgs e )
{
this . Close ( ) ;
}
#endregion
private void button2_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫ���豸��" + this . _d eviceIndex + "��������������" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
try
{
CStaticClass . WcfControl . BeginSetLogicHaveGoods ( false , this . _d eviceIndex , new AsyncCallback ( SetLogicHaveGoodsCallBack ) , null ) ;
btnRefresh_Click ( sender , e ) ;
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
private void button1_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫ���豸��" + this . _d eviceIndex + "��������������" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
try
{
CStaticClass . WcfControl . BeginSetLogicHaveGoods ( true , this . _d eviceIndex , new AsyncCallback ( SetLogicHaveGoodsCallBack ) , null ) ;
btnRefresh_Click ( sender , e ) ;
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
private void button3_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫ���豸��" + this . _d eviceIndex + "���͡�����Ӧ��������" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
string errtext = string . Empty ;
try
{
CStaticClass . WcfControl . BeginSendDeviceReset ( this . _d eviceIndex , 2 , new AsyncCallback ( SendDeviceResetCallBack ) , 2 ) ;
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
void SetLogicHaveGoodsCallBack ( IAsyncResult ar )
{
string errtext = string . Empty ;
try
{
if ( CStaticClass . WcfControl . EndSetLogicHaveGoods ( out errtext , ar ) = = false )
{
MessageBox . Show ( errtext , "������ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
catch ( Exception ex )
{
throw ex ;
}
}
void SendDeviceResetCallBack ( IAsyncResult ar )
{
string errtext = string . Empty ;
try
{
if ( CStaticClass . WcfControl . EndSendDeviceReset ( out errtext , ar ) = = false )
{
MessageBox . Show ( errtext , "������ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
else
{
if ( ar . AsyncState ! = null )
{
//if ((((int)ar.AsyncState) == 4)&&(_device.DeviceKind==4))
//{
// CStaticClass.WcfControl.BeginSendDeviceReset(_deviceIndex, 2, new AsyncCallback(SendDeviceResetCallBack), null);
//}
if ( ( ( int ) ar . AsyncState ) = = 2 | | ( ( int ) ar . AsyncState ) = = 4 )
{
CStaticClass . WcfControl . BeginSendDeviceReset ( _d eviceIndex , 0 , new AsyncCallback ( SendDeviceResetCallBack ) , null ) ;
}
}
}
}
catch ( Exception ex )
{
throw ex ;
}
}
private void lblDeviceIndex_ValueChanged ( object sender , EventArgs e )
{
_d eviceIndex = int . Parse ( lblDeviceIndex . Value . ToString ( ) ) ;
}
private void FrmDeviceStatus_FormClosing ( object sender , FormClosingEventArgs e )
{
_f ormInstance = null ;
}
private void button4_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫ���豸��" + this . _d eviceIndex + "���͡��豸��λ������" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
string errtext = string . Empty ;
try
{
CStaticClass . WcfControl . BeginSendDeviceReset ( this . _d eviceIndex , 4 , new AsyncCallback ( SendDeviceResetCallBack ) , 4 ) ;
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
int GetMonitorTaskIndexFromBarCode ( StringBuilder BarCode )
{ //20110216
string bc = BarCode . ToString ( ) ;
DataView dv = dbo . ExceSQL ( string . Format ( "SELECT T_Monitor_Task.F_MonitorIndex FROM T_Base_Device,T_Monitor_Task WHERE T_Base_Device.F_DeviceIndex = T_Monitor_Task.F_DeviceIndex and ((T_Base_Device.F_DeviceKindIndex = 13) OR (T_Base_Device.F_DeviceKindIndex = 31)) and (F_TxtParam = '{0}') and F_Status>0 order by F_MonitorIndex asc" , bc ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return Convert . ToInt32 ( dv [ 0 ] [ "F_MonitorIndex" ] ) ;
}
else
{
return - 1 ;
}
}
void WriteDBDataCallback ( IAsyncResult ar )
{
string errtext ;
try
{
if ( CStaticClass . WcfControl . EndWriteDBData ( out errtext , ar ) = = false )
{
MessageBox . Show ( "������ʾ" , errtext , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
catch ( Exception ex )
{
throw ex ;
}
}
private void lblBarcode_KeyPress ( object sender , KeyPressEventArgs e )
{
try
{
if ( e . KeyChar = = '\r' )
{
if ( MessageBox . Show ( "��ȷ��Ҫ���豸��" + this . _d eviceIndex + "����¼�ġ����롿����" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
if ( _d eviceIndex = = 1 7 0 0 1 | | _d eviceIndex = = 1 7 0 0 3 | | _d eviceIndex = = 1 7 0 0 4 | | _d eviceIndex = = 1 7 0 0 5 ) { //���������������߶ȣ�Ӱ���Ͱ����ĶԽ�
MessageBox . Show ( "����վ̨ɨ�������ܲ��룬������ɨ������" ) ;
return ;
}
int type = 1 ; //1��asc��Ĭ��Ϊʵ�����̣��л�
if ( cB_Empty . Checked = = false ) //������
{
type = 0 ; //0��asc��
}
string barcode = lblBarcode . Text ;
CStaticClass . WcfControl . BeginWriteDBData ( _d eviceIndex , "db2" , barcode , new AsyncCallback ( WriteDBDataCallback ) , null ) ;
}
}
catch ( Exception ex )
{
MessageBox . Show ( ex . Message , "��ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
}
private void btCancelDoubleFork_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫȡ����" + this . _d eviceIndex + "����˫����������" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
StringBuilder sql = new StringBuilder ( ) ;
sql . Append ( "update T_Base_PLC_Ask set F_TaskIndex=0,F_Remark='' where F_DeviceIndex=" ) . Append ( _d eviceIndex ) ;
dbo . ExecuteSql ( sql . ToString ( ) ) ;
}
private void btnSolutions_Click ( object sender , EventArgs e )
{ //20151120
try
{
if ( _d evice ! = null )
{
if ( _d evice . ErrorCode > = 3 0 )
{
FrmDeviceErrorSolutions . FormInstance . Show ( ) ;
FrmDeviceErrorSolutions . FormInstance . comboBox1 . SelectedValue = _d evice . DeviceKind ;
FrmDeviceErrorSolutions . FormInstance . textBox1 . Text = _d evice . ErrorCode . ToString ( ) ;
FrmDeviceErrorSolutions . FormInstance . button1_Click ( sender , e ) ;
}
}
}
catch ( Exception ex )
{
throw ex ;
}
}
private void AGVStatesUpdate_Click ( object sender , EventArgs e )
{
if ( MessageBox . Show ( "��ȷ��Ҫ��λ��" + this . _d eviceIndex + "����AGV�������뿪�ź�����" , "������ʾ��" , MessageBoxButtons . OKCancel , MessageBoxIcon . Question ) ! = DialogResult . OK )
{
return ;
}
StringBuilder sql = new StringBuilder ( ) ;
sql . Append ( "update T_AGVIOStation set F_AGVStatus=9 where F_PLCOtherDevice=" ) . Append ( _d eviceIndex ) ;
int count = dbo . ExecuteSql ( sql . ToString ( ) ) ;
if ( count = = 1 )
{
MessageBox . Show ( "״̬���³ɹ�" ) ;
}
else {
MessageBox . Show ( "״̬���³ɹ�" ) ;
}
}
}
}