预约系统中,新用户可以自己注册,然后管理员开通。
注册界面如下:
客户端新用户注册代码:
button1_Click((txtUserID.Text.Trim ()==|| txtUserName.Text.Trim ()=== ==== = newTcpConnection.SendReceiveObject<ResMessage>(, , (resMessage.Message == +
服务器端的相关处理代码:
构造函数中声明:
//注册新用户 NetworkComms.AppendGlobalIncomingPacketHandler<Users>("ReqRegUser", HandlRegUser);
处理方法
private void HandlRegUser(PacketHeader header, Connection connection, Users Users) { string userID = Users.UserID; Users oldUser =DoUsers.GetUserByID(userID); // =-1代表不存在相关记录 if (oldUser.Id == -1) { DoUsers.Save(Users); ResMessage resMessage = new ResMessage("操作成功"); connection.SendObject("ResRegUser", resMessage); } else { ResMessage resMessage = new ResMessage("用户ID已经存在"); connection.SendObject("ResRegUser", resMessage); } }
DoUsers.GetUserByID方法
public static Users GetUserByID(string userID) { using (IDataReader reader = DBUsers.GetOneByUserID(userID)) { Users theUser = PopulateFromReader(reader); return theUser; } }
DoUsers中的Save方法
public static bool Save(Users Users) { if (Users.Id > 0) { return Update(Users); } else { return Create(Users); } }
Update和Create方法
private static bool Create(Users Users) { int newID = 0; newID = DBUsers.Create( Users.UserID, Users.Name, Users.Password, Users.Declaring, Users.Status, Users.IsMale, Users.UserLevel, Users.Enabled, Users.RegisterTime, Users.LastLoginTime, Users.DepID, Users.Department); Users.Id = newID; return (newID > 0); } /// <summary> /// Updates this instance of Users. Returns true on success. /// </summary> /// <returns>bool</returns> private static bool Update(Users Users) { return DBUsers.Update( Users.Id, Users.UserID, Users.Name, Users.Password, Users.Declaring, Users.Status, Users.IsMale, Users.UserLevel, Users.Enabled, Users.RegisterTime, Users.LastLoginTime, Users.DepID, Users.Department); }
DBUsers类
DBUsers类