您好,登錄后才能下訂單哦!
客戶端用戶登陸后,在主界面中可以看到本單位的所有教室,我們來看一下是如何獲取的:
客戶端代碼:
//根據用戶獲取功能教室列表 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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。