Beispiel #1
0
        //修改密码委托
        private void ModifyPwd(string newPwd)
        {
            //密码修改消息定义
            var mode      = "modify";
            var modifyMes = new IdPwd
            {
                id       = account.id,
                password = newPwd
            };
            var data = JsonConvert.SerializeObject(modifyMes);

            //ws定义
            ws            = new WebSocket("ws://" + server + "/mode=" + mode);
            ws.OnMessage += (s, ee) => {
                var recMes = JsonConvert.DeserializeObject <BasicData>(ee.Data);
                //数据代码正常
                if (recMes.code == "200")
                {
                    AppendLog(recMes.mes);
                }
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                {
                    GridHigh.IsEnabled = true;
                }));
            };
            ws.OnClose += (s, ee) => {
                //AppendLog("服务器通讯结束!");
            };
            ws.Connect();
            ws.Send(data);
        }
Beispiel #2
0
        //登录操作
        private void BtnLogin_Click(object sender, RoutedEventArgs e)
        {
            //信息填入
            var mode     = "login";
            var loginMes = new IdPwd
            {
                id       = TextID.Text,
                password = PwdBoxPwd.Password
            };
            var data = JsonConvert.SerializeObject(loginMes);

            //ws通信
            ws            = new WebSocket("ws://" + server + "/mode=" + mode);
            ws.OnMessage += (s, ee) => {
                var recData = JsonConvert.DeserializeObject <AccountData>(ee.Data);
                if (recData.code == "100")
                {
                    account = JsonConvert.DeserializeObject <Account>(recData.data.ToString());
                    //更新窗体数据
                    Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
                    {
                        GridBasic.Visibility = Visibility.Hidden;
                        GridHigh.Visibility  = Visibility.Visible;
                        TextAccount.Text     = "当前账户:" + account.name + "(" + account.role + ")";
                        if (account.role != "teacher")
                        {
                            BtnLogView.IsEnabled = false;
                        }
                    }));
                    File.WriteAllText("./config.json", data);
                    AppendLog("登录成功。当前登录账户:" + account.name);
                }
                else
                {
                    AppendLog("抱歉,登录错误。错误代码:" + recData.code + ",错误信息:" + recData.mes);
                }
            };
            ws.OnClose += (s, ee) => {
                //AppendLog("服务器通讯结束!");
            };
            ws.Connect();
            //发送消息
            ws.Send(data);
        }