using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Text ;
using System.Windows.Forms ;
using DBFactory ;
namespace wcfControlMonitorClient
{
/// <summary>
/// 20101011�����ӳ�����վ̨���Զ���
/// </summary>
public partial class FrmIOStation : Form
{
DBOperator dbo = CStaticClass . dbo ;
DBOperator dboM = CStaticClass . dboM ;
private static FrmIOStation _f ormInstance ;
public static FrmIOStation FormInstance
{
get
{
if ( _f ormInstance = = null )
{
_f ormInstance = new FrmIOStation ( ) ;
}
return _f ormInstance ;
}
set { _f ormInstance = value ; }
}
public FrmIOStation ( )
{
InitializeComponent ( ) ;
DataView dv = dbo . ExceSQL ( "select Device_Index,Device_Name,InOut_Value from T_InOutModel" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
this . comboBox1 . DisplayMember = "Device_Name" ;
this . comboBox1 . ValueMember = "Device_Index" ;
this . comboBox1 . DataSource = dv ;
}
_f ormInstance = this ;
}
private void button1_Click ( object sender , EventArgs e )
{
if ( this . comboBox1 . SelectedValue = = null )
{
MessageBox . Show ( "��ѡ��������վ̨��" , "������ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
this . comboBox1 . Focus ( ) ;
return ;
}
if ( this . comboBox2 . Text . Trim ( ) = = "" )
{
MessageBox . Show ( "��ѡ�����������ԣ�" , "������ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
this . comboBox2 . Focus ( ) ;
return ;
}
if ( "����վ̨����վ̨" . IndexOf ( this . comboBox2 . Text . Trim ( ) ) < 0 )
{
MessageBox . Show ( "��ѡ�����������ԣ�" , "������ʾ" , MessageBoxButtons . OK , MessageBoxIcon . Warning ) ;
this . comboBox2 . Focus ( ) ;
return ;
}
// string iotype = " (T_Base_Route.F_RouteKind <> 0) ";
if ( this . comboBox2 . Text . Trim ( ) = = "����վ̨" )
{
// iotype = " (T_Base_Route.F_RouteKind = 1) ";
dbo . ExecuteSql ( "update T_InOutModel set InOut_Value=0 where Device_Index=" + this . comboBox1 . SelectedValue ) ;
// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where START_DEVICE=" + this.comboBox1.SelectedValue);
// dbo.ExecuteSql("update t_base_route set F_Status=0,F_AutoUpdate=0 where F_EndDevice=" + this.comboBox1.SelectedValue);
//// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where END_DEVICE=" + this.comboBox1.SelectedValue);
MessageBox . Show ( $"��{this.comboBox1.SelectedValue}վ̨����ģʽ�ɹ�" ) ;
}
else
{
//iotype = " (T_Base_Route.F_RouteKind = 2) ";
dbo . ExecuteSql ( "update T_InOutModel set InOut_Value=1 where Device_Index=" + this . comboBox1 . SelectedValue ) ;
MessageBox . Show ( $"��{this.comboBox1.SelectedValue}վ̨����ģʽ�ɹ�" ) ;
// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where END_DEVICE=" + this.comboBox1.SelectedValue);
// dbo.ExecuteSql("update t_base_route set F_Status=0,F_AutoUpdate=0 where F_StartDevice=" + this.comboBox1.SelectedValue);
// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where START_DEVICE=" + this.comboBox1.SelectedValue);
}
//
//DataView dv = dbo.ExceSQL("SELECT DISTINCT T_Base_Route.F_RouteID, T_Base_Route.F_RouteKind, "+
// "T_Base_Route_Device.F_DeviceIndex FROM T_Base_Route,T_Base_Route_Device where "+
// "T_Base_Route.F_RouteID = T_Base_Route_Device.F_RouteID and "+iotype+
// " AND (T_Base_Route_Device.F_DeviceIndex = "+this.comboBox1.SelectedValue +")").Tables[0].DefaultView;
//DataView dvf;
// for(int i=0;i<dv.Count;i++)
// {
// dbo.ExecuteSql("update t_base_route set F_Status=1,F_AutoUpdate=1 where f_routeid=" + dv[i]["F_RouteID"]);
// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=1 where CONTROL_ROUTE_ID='" + dv[i]["F_RouteID"] + "' and CONTROL_ROUTE_STATUS=0");
// if (dv[i]["F_RouteKind"].ToString() == "1")
// {
// dvf = dbo.ExceSQL("SELECT DISTINCT T_Base_Route.F_RouteID, T_Base_Route.F_RouteKind, " +
// "T_Base_Route_Device.F_DeviceIndex FROM T_Base_Route,T_Base_Route_Device where " +
// "T_Base_Route.F_RouteID = T_Base_Route_Device.F_RouteID and T_Base_Route.F_RouteKind = 2 " +
// " AND (T_Base_Route_Device.F_DeviceIndex = " + this.comboBox1.SelectedValue + ")").Tables[0].DefaultView;
// for (int f = 0; f < dvf.Count; f++)
// {
// dbo.ExecuteSql("update t_base_route set F_Status=0,F_AutoUpdate=0 where f_routeid=" + dvf[f]["F_RouteID"]);
// // dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where CONTROL_ROUTE_ID='" + dvf[f]["F_RouteID"] + "' and CONTROL_ROUTE_STATUS=1");
// }
// }
// else if (dv[i]["F_RouteKind"].ToString() == "2")
// {
// dvf = dbo.ExceSQL("SELECT DISTINCT T_Base_Route.F_RouteID, T_Base_Route.F_RouteKind, " +
// "T_Base_Route_Device.F_DeviceIndex FROM T_Base_Route,T_Base_Route_Device where " +
// "T_Base_Route.F_RouteID = T_Base_Route_Device.F_RouteID and T_Base_Route.F_RouteKind = 1 " +
// " AND (T_Base_Route_Device.F_DeviceIndex = " + this.comboBox1.SelectedValue + ")").Tables[0].DefaultView;
// for (int f = 0; f < dvf.Count; f++)
// {
// dbo.ExecuteSql("update t_base_route set F_Status=0,F_AutoUpdate=0 where f_routeid=" + dvf[f]["F_RouteID"]);
// dboM.ExceSQL("update IO_CONTROL_ROUTE set CONTROL_ROUTE_STATUS=0 where CONTROL_ROUTE_ID='" + dvf[f]["F_RouteID"] + "' and CONTROL_ROUTE_STATUS=1");
// }
// }
// }
}
private void FrmIOStation_FormClosing ( object sender , FormClosingEventArgs e )
{
_f ormInstance = null ;
}
}
}