110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using RemoteObject;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CarClient
{
public partial class ClientForm : Form
{
public ClientForm()
{
InitializeComponent();
}
RemoteObject.RemoteData rd;
private void btGet_Click(object sender, EventArgs e)
{
TcpClientChannel channel = new TcpClientChannel();
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(RemoteObject.RemoteData), "tcp://192.168.200.2:8086/hi");
rd = (RemoteObject.RemoteData)Activator.CreateInstance(typeof(RemoteObject.RemoteData));
rd_ErrorEvent();
}
private int rd_ErrorEvent()
{
int i=0;
DataSet ds = rd.GetData("select * from employee");
if (ds.Tables[0].Rows[0][1] .ToString()== "admin")
{
i= 1;
}
else
{
i= 0;
}
if (i == 1)
{
this.dgv.DataSource = rd.GetData("select * from employee").Tables[0].DefaultView;
}
else
{
MessageBox.Show("请输入正确的用户名和密码!");
}
return 1;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RemoteObject;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
namespace CarTest
{
public partial class ServerForm : Form
{
public ServerForm()
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
RemoteData rd=new RemoteData();
DataSet ds=rd.GetData("select * from employee");
this.dvg.DataSource = ds.Tables[0].DefaultView;
}
private void ServerForm_Load(object sender, EventArgs e)
{
TcpServerChannel channel = new TcpServerChannel(8086);
ChannelServices.RegisterChannel(channel,false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(RemoteObject.RemoteData), "hi", WellKnownObjectMode.Singleton);
RemoteObject.RemoteData.SinkEvent+=new SinkHandle(RemoteData_SinkEvent);
}
private void RemoteData_SinkEvent(string fax)
{
this.tbServer.Text = fax;
}
}
}