public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer clientPeer)
        {
            //获得传递过来的参数,通过ParameterCode获得参数
            string username = (string)DictTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username);
            string password = (string)DictTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password);

            //使用Manager进行数据库的操作
            IUserInfoManager userManager = new UserInfoManager();

            UserInfo userinfo = new UserInfo()
            {
                Username = username, Password = password, RegistDate = DateTime.Now
            };
            //添加用户
            bool result = userManager.Add(userinfo);

            //响应客户端
            Dictionary <byte, object> respData = new Dictionary <byte, object>();

            respData.Add((byte)ParameterCode.RegistResult, result);

            OperationResponse op = new OperationResponse(operationRequest.OperationCode, respData);

            clientPeer.SendOperationResponse(op, sendParameters);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 2.1 方式添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string strUserName = textBox1.Text.Trim();
            string strPwd      = textBox2.Text.Trim();

            if (string.IsNullOrEmpty(strUserName) || string.IsNullOrEmpty(strPwd))
            {
                MessageBox.Show("用户名和密码不可为空!");
                return;
            }

            //1.调用用户的业务逻辑,实现用户信息添加
            UserInfo _user = new UserInfo();

            _user.userName = strUserName;
            _user.userPwd  = strPwd;

            UserInfoManager usermanager = new UserInfoManager();
            DataSet         _Dt         = usermanager.GetList(string.Format("userName='******'", strUserName));

            if (_Dt.Tables != null && _Dt.Tables[0].Rows.Count > 0)
            {
                MessageBox.Show("同名称用户已存在,请输入其它用户名!");
                return;
            }
            if (usermanager.Add(_user))
            {
                _user.ID = usermanager.GetMaxId();
            }
            else
            {
                MessageBox.Show("添加失败!");
            }

            //2.添加成功将用户信息(需要获取此)添加到当前_RecordListView和RecordList列表中
            if (RecordList == null)
            {
                RecordList = new List <UserInfo>();
            }
            RecordList.Add(_user);

            _RecordListView.AddObject(_user);//刷新ListView 列表
        }
Ejemplo n.º 3
0
        public int AddUser(UserInfoEntity userEntity)
        {
            UserInfoManager mgr = new UserInfoManager();

            return(mgr.Add(userEntity));
        }