客户端代码:
//发出的数据类型为int类型 ItemID为用户对应的ID ResMessage resMessage = tcpConnnection.SendReceiveObject<ResMessage>("ReqResetPsw", "ResResetPsw", 5000, itemID); if (resMessage.Message == "操作成功") { paramHelper.ChangeParam("操作成功"); MessageBox.Show("操作成功,用户密码为:123456"); button1.Enabled = false; } else { MessageBox.Show("出现错误,错误信息为:" + resMessage.Message); }
服务器端代码:
//客户端管理员修改用户的密码 NetworkComms.AppendGlobalIncomingPacketHandler<int>("ReqResetPsw", HandleResetPassword);
处理方法:
//根据管理员提供的用户ID修改相应用户的密码 private void HandleResetPassword(PacketHeader header, Connection connection, int itemID) { Users theUser= DoUsers.GetUsers(itemID); //把密码恢复成123456 theUser.Password = "123456"; DoUsers.Save(theUser); ResMessage theMessage = new ResMessage(); theMessage.Message = "操作成功"; connection.SendObject("ResResetPsw", theMessage); }
操作类:
DoUsers
Users类:
[ProtoContract] public class Users { #region Constructors public Users() { } #endregion #region Private Properties private int id = -1; private string userID = string.Empty; private string name = string.Empty; private string password = string.Empty; private string declaring = string.Empty; private int status = -1; private bool isMale = false; private int userLevel = -1; private bool enabled = false; private DateTime registerTime = DateTime.UtcNow; private DateTime lastLoginTime = DateTime.UtcNow; private int depID = -1; private string department = string.Empty; #endregion #region Public Properties [ProtoMember(1)] public int Id { get { return id; } set { id = value; } } [ProtoMember(2)] public string UserID { get { return userID; } set { userID = value; } } [ProtoMember(3)] public string Name { get { return name; } set { name = value; } } [ProtoMember(4)] public string Password { get { return password; } set { password = value; } } [ProtoMember(5)] public string Declaring { get { return declaring; } set { declaring = value; } } [ProtoMember(6)] public int Status { get { return status; } set { status = value; } } [ProtoMember(7)] public bool IsMale { get { return isMale; } set { isMale = value; } } [ProtoMember(8)] public int UserLevel { get { return userLevel; } set { userLevel = value; } } [ProtoMember(9)] public bool Enabled { get { return enabled; } set { enabled = value; } } [ProtoMember(10)] public DateTime RegisterTime { get { return registerTime; } set { registerTime = value; } } [ProtoMember(11)] public DateTime LastLoginTime { get { return lastLoginTime; } set { lastLoginTime = value; } } [ProtoMember(12)] public int DepID { get { return depID; } set { depID = value; } } [ProtoMember(13)] public string Department { get { return department; } set { department = value; } } #endregion }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。