设置预约规则的客户端代码:
int stopHourInt = (int)stopHour.Value; int stopMinuteInt = (int)stopMinute.Value; //截止的时间 int stopTimeInt = stopHourInt * 100 + stopMinuteInt; //提前的天数 int dayspan = (int)numDay.Value; //声明一个ClassRoomConfig类 并设定具体的值 ClassRoomConfig classRoomConfig=new ClassRoomConfig (); classRoomConfig.DaySpan=dayspan ; classRoomConfig.StopTime=stopTimeInt; classRoomConfig.Id = roomConfigID; classRoomConfig.RoomID=this.itemID ; //发送预约规则个服务器端,并获取返回结果 ResMessage resMessage=tcpConnnection.SendReceiveObject<ResMessage>("AddRoomConfig","ResRoomConfig",5000, classRoomConfig); if (resMessage.Message == "操作成功") { GetCurrentRoomConfig(); MessageBox.Show("添加设置完成"); } else { MessageBox.Show("出现错误,错误为" + resMessage.Message); }
服务器端处理代码如下:
构造函数中声明:
//学校管理员添加教室的相关设置 NetworkComms.AppendGlobalIncomingPacketHandler<ClassRoomConfig>("AddRoomConfig", HandleAddRoomConfig);
处理方法:
private void HandleAddRoomConfig(PacketHeader header, Connection connection, ClassRoomConfig classRoomConfig) { DoClassRoomConfig.Save(classRoomConfig); ResMessage theMessage = new ResMessage(); theMessage.Message = "操作成功"; connection.SendObject("ResRoomConfig", theMessage); }
操作类:
DoClassRoomConfig
数据库类:
DBClassRoomConfig