客户端用户登陆后,在主界面中可以看到本单位的所有教室,我们来看一下是如何获取的:
客户端代码:
//根据用户获取功能教室列表 private void GetRooms(Users user) { //把当前用户信息发送个服务器端,并获取到本用户相关的教室列表 RoomList roomList = newTcpConnection.SendReceiveObject<RoomList>("GetRooms", "RoomList", 5000, user); IList<Cla***oom> cla***omms= roomList.Cla***ooms; listBox1.DataSource = cla***omms; listBox1.DisplayMember = "RoomName"; listBox1.ValueMember = "ID"; }
RoomList类 (可由protobuf.net 序列化)
//根据单位名称获取功能室列表 [ProtoContract] public class RoomList { [ProtoMember(1)] public IList<Cla***oom> Cla***ooms; public RoomList() { } public RoomList(IList<Cla***oom> rooms) { this.Cla***ooms = rooms; } }
服务器端的处理方法:
在构造函数中声明:
//根据用户的单位,获取所有功能教室 列表 NetworkComms.AppendGlobalIncomingPacketHandler<Users>("GetRooms", HandleGetRooms);
处理方法:
private void HandleGetRooms(PacketHeader header, Connection connection, Users theUser) { IList<Cla***oom> theRooms = DoCla***oom.GetCla***oomByUserDep(theUser.Department); RoomList roomList = new RoomList(theRooms); //把获取到的数据发回去 connection.SendObject("RoomList", roomList); }
DoCla***oom.GetCla***oomByUserDep方法
//根据用户单位获取单位的功能教室列表 public static IList<Cla***oom> GetCla***oomByUserDep(string depName) { IDataReader reader = DBCla***oom.GetCla***oomByDepName(depName); return LoadListFromReader(reader); }
LoadListFromReader方法
DBCla***oom.GetCla***oomByDepName方法
//根据单位名称获取功能教师列表 public static IDataReader GetCla***oomByDepName(string department) { SqlParameterHelper sph = new SqlParameterHelper(GetWriteConnectionString(), "Cla***oom_SelectCla***oomByDepName", 1); sph.DefineSqlParameter("@Department", SqlDbType.NVarChar, 200, ParameterDirection.Input, department); return sph.ExecuteReader(); }
相关存储过程:
CREATE PROCEDURE [dbo].Cla***oom_SelectCla***oomByDepName @Department nvarchar(200) AS SELECT [Id], [RoomName], [DepID], [Department] FROM [dbo].[Cla***oom] where Department=@Department
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。