Example #1
0
        private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ConnSQL connSQL = new ConnSQL();

            connSQL.update(user.Username, (comboBox1.SelectedItem as ComboBoxItem).Content.ToString());
            if ((comboBox1.SelectedItem as ComboBoxItem).Content.ToString().CompareTo("Offline") == 0)
            {

                StateStatus mess = new StateStatus();
                mess.Id = 1;
                mess.State = "Offline";
                mess.Status = "";
                mess.User = user.Username;
                byte[] buff = mess.Serialize();

                ClientServerCommunicator.SendData(ClientServerCommunicator.server_socket, buff, 5);

                parrentwdw.Show();
                signout = true;
                this.Close();
            }

            if ((comboBox1.SelectedItem as ComboBoxItem).Content.ToString().CompareTo("Available") == 0)
            {
                


                StateStatus mess = new StateStatus() ;
                mess.Id = 1;
                mess.State ="Available";
                mess.Status = "";
                mess.User = user.Username;
                byte[] buff = mess.Serialize();

                ClientServerCommunicator.SendData(ClientServerCommunicator.server_socket, buff, 5);
            }


            if ((comboBox1.SelectedItem as ComboBoxItem).Content.ToString().CompareTo("Invisible") == 0)
            {
                

                StateStatus mess = new StateStatus();
                mess.Id = 1;
                mess.State = "Invisible";
                mess.Status = "";
                mess.User = user.Username;
                byte[] buff = mess.Serialize();

                ClientServerCommunicator.SendData(ClientServerCommunicator.server_socket, buff, 5);
            }
        }
Example #2
0
        public MainWindow()
        {
          
            
            connSQL = new ConnSQL();
            InitializeComponent();
            try
                {
                    string line;
                    System.IO.StreamReader file =
                        new System.IO.StreamReader("conf.txt");
                 
                            line = file.ReadLine();
                            if (line != null)
                            {
                                UsernameTextbox.Text = line;
                                line = file.ReadLine();
                                if (line != null)
                                {
                                    passwordBox1.Password = line;
                                    checkBox1.IsChecked = true;
                                    line = file.ReadLine();
                                    if (line != null && line.CompareTo("ok") == 0)
                                    {
                                        checkBox2.IsChecked = true;
                                        user = connSQL.getUser(UsernameTextbox.Text, passwordBox1.Password);
                                        if (user != null)
                                        {
                                            ClientServerCommunicator.InitConection();
                                            Login mess = new Login();
                                            mess.Username = UsernameTextbox.Text;
                                            mess.Password = passwordBox1.Password;
                                            byte[] buff = mess.Serialize();
                                            ClientServerCommunicator.SendData(ClientServerCommunicator.server_socket, buff, 3);

                                            MessageBox.Show("Authentication succeded", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                        }
                                        else MessageBox.Show("Authentication failed", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Stop);
                                        if (user != null)
                                        {
                      //                      this.Close();
                                            if (checkBox3.IsChecked == true)
                                            {
                                                connSQL.update(UsernameTextbox.Text, "Invisible");
                                                user.Status = "Invisible";
                                                
                                            }
                                            else
                                            {
                                                connSQL.update(UsernameTextbox.Text, "Available");
                                                user.Status = "Available";
                                                
                                            }
                                            ClientWindow clientwin = new ClientWindow();
                                            clientwin.setUser(user);
                                            
                                            this.Hide();
                                            clientwin.Show();
                                        }
                                    }
                                }
                            }
                        
                    
                    file.Close();
                }
                catch (Exception exc)
                {
                    MessageBox.Show("An error has occured:\n" + exc.ToString());
                    GmailSender.SendMail("*****@*****.**", "Andreia_90", "*****@*****.**", "Error", exc.ToString());
                }
            
        }