Exemplo n.º 1
0
        private void Button_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (txtAccount.Text != string.Empty && txtPassword.Password != string.Empty)
            {
                ChattingRoomEntities db = new ChattingRoomEntities();
                string password         = Auth.Hash(txtPassword.Password);
                User   user             = db.Users.FirstOrDefault(x =>
                                                                  x.Account == txtAccount.Text &&
                                                                  x.Password == password
                                                                  );

                if (user == null)
                {
                    MessageBox.Show("Can not find this user.");
                }
                else
                {
                    ((MainWindow)Application.Current.MainWindow).Connection(user);
                }
            }
            else
            {
                MessageBox.Show("Account or password is empty");
            }
        }
Exemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            // 載入使用者清單
            ChattingRoomEntities db = new ChattingRoomEntities();

            pnlUserList.ItemsSource = db.Users.ToList();

            // 建立Socket Server
            _server = new SocketServer();
            _server.OnSocketServerAcceptedSuccess += _server_OnSocketServerAcceptedSuccess;
            _server.OnSocketServerAcceptedFailed  += _server_OnSocketServerAcceptedFailed;

            // 啟動伺服器
            TurnOnServer();
        }
Exemplo n.º 3
0
        private void Button_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            ChattingRoomEntities db = new ChattingRoomEntities();

            if (db.Users.Any(x => x.Account == txtAccount.Text))
            {
                MessageBox.Show("This account is existed.");
            }
            else
            {
                db.Users.Add(new User()
                {
                    Name     = txtName.Text,
                    Account  = txtAccount.Text,
                    Password = Auth.Hash(txtPassword.Password)
                });
                db.SaveChanges();
                MessageBox.Show("Regist success! Please try to login your account.");
                ((Frame)Application.Current.MainWindow.FindName("pnlFrame")).Navigate(new PageSignin());
            }
        }