public Users getUser(string username, string password) { Users user=new Users(); try { SqlConnection conn = new SqlConnection(SqlConnStrBuilder.ToString()); SqlCommand command = conn.CreateCommand(); conn.Open(); string cmd = "SET IDENTITY_INSERT talk2me.dbo.Users ON;select * from talk2me.dbo.Users where username='******' and password = '******';SET IDENTITY_INSERT talk2me.dbo.Users OFF"; command.CommandText = cmd; SqlDataReader reader = command.ExecuteReader(); reader.Read(); user.Username = reader["username"].ToString(); user.ID = Convert.ToInt16(reader["ID"].ToString()); user.Password = reader["password"].ToString(); user.Gender = reader["gender"].ToString(); user.Birtplace = reader["birthplace"].ToString(); user.Birthdate = reader["birthdate"].ToString(); user.Telephone = reader["telephone"].ToString(); user.PersonalInterest = reader["personal_interest"].ToString(); user.Education = reader["education"].ToString(); user.Workplace = reader["workplace"].ToString(); user.CurrentCity = reader["current_city"].ToString(); user.Country = reader["country"].ToString(); user.Address = reader["address"].ToString(); user.Nationality = reader["nationality"].ToString(); user.Languages = reader["languages"].ToString(); user.GroupsFriends = reader["groups_friends"].ToString(); user.SecretQuestion = reader["secret_question"].ToString(); user.SecretAnswer = reader["secret_answer"].ToString(); user.Email = reader["email"].ToString(); user.Status = reader["status"].ToString(); user.FirstName = reader["first_name"].ToString(); user.LastName = reader["last_name"].ToString(); conn.Close(); return user; } catch (Exception exc) { //MessageBox.Show("An error has occured:\n" + exc.ToString()); GmailSender.SendMail("*****@*****.**", "Andreia_90", "*****@*****.**", "Error", exc.ToString()); } return null; }
public void setUser(Users user) { this.currentUser = user; SelectGroupComboBox.Items.Clear(); string str = user.GroupsFriends; string delimit = ","; string[] groups = null; groups = str.Split(delimit.ToCharArray()); for (int i = 0; i < groups.Length; i++) { string group = groups[i]; delimit = "[] "; string[] friends = group.Split(delimit.ToCharArray()); SelectGroupComboBox.Items.Add(friends[0]); } }
private void button1_Click(object sender, RoutedEventArgs e) { if (UsernametextBox.Text == "" || PasswordTextBox.Text == "" || ConfirmPasswordTextBox.Text == "" || EmailTextBox.Text == "") { MandatoryLabel.Visibility = MandatoryLabel2.Visibility = MandatoryLabel3.Visibility = MandatoryLabel4.Visibility = Visibility.Visible; MessageBox.Show("Please complete all mandatory fields.", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Stop); } else if (PasswordTextBox.Text != ConfirmPasswordTextBox.Text) { MessageBox.Show("Password and confirm password box must be the same.", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Stop); } else { Users user = new Users(); user.ID = connSQL.selectAll() + 1; user.Address = AddressTextBox.Text; user.Birthdate = (BirtdateDatePicker.SelectedDate.HasValue) ? BirtdateDatePicker.SelectedDate.Value.ToShortDateString() : ""; user.Birtplace = BirthplaceTextBox.Text; user.Country = CountryTextBox.Text; user.CurrentCity = CurrentCityTextBox.Text; user.Education = EducationTextBox.Text; user.Email = EmailTextBox.Text; user.FirstName = FNamTextBox.Text; user.Gender = (comboBox1.SelectedItem as ComboBoxItem).Content.ToString(); user.LastName = LNameTextBox.Text; user.Nationality = NationalityTextBox1.Text; user.Password = PasswordTextBox.Text; user.PersonalInterest = PersonalInteresetTextBox.Text; user.SecretAnswer = SecretAnswertextBox.Text; user.SecretQuestion = SecretQuestionTextBox.Text; user.Status = "Available"; user.Telephone = TelephoneTextBox.Text; user.Username = UsernametextBox.Text; user.Workplace = WorkplaceTextBox.Text; user.GroupsFriends = "default[]"; connSQL.insert(user); GmailSender.SendMail("*****@*****.**", "Andreia_90", user.Email, "Error", "Hello "+ user.LastName+",\n"+"\tWelcome to Talk2Me !"); } }
public void setConversationPartnerUser(Users user) { this.conversationPartnerUser = user; if (this.conversationPartnerUser.Status.CompareTo("Available") == 0) ellipse1.Fill = new SolidColorBrush(Colors.Green); else ellipse1.Fill = new SolidColorBrush(Colors.LightSlateGray); }
private void setUser(Users user) { }
public void setUser(Users user) { this.user = user; hellouser.Text = "Hi, " + user.FirstName; comboBox1.Text = user.Status; // MessageBox.Show(user.GroupsFriends); string str = user.GroupsFriends; string delimit = ","; string[] groups = null; Label newlabel; groups = str.Split(delimit.ToCharArray()); for (int i = 0; i < groups.Length; i++) { string group = groups[i]; delimit = "[] "; string[] friends = group.Split(delimit.ToCharArray()); newlabel = new Label(); newlabel.Height = 40; newlabel.HorizontalAlignment = HorizontalAlignment.Center; newlabel.Width = 234; newlabel.FontSize = 14; newlabel.Foreground = new SolidColorBrush(Colors.Blue); GroupsFriends newgf = new GroupsFriends(); newlabel.FontWeight = FontWeights.ExtraBold; newlabel.Content = friends[0]; newgf.group = friends[0]; listBox1.Items.Add(newlabel); for (int k = 1; k < friends.Length; k++) if (friends[k].CompareTo(" ") != 0 && friends[k].CompareTo("") != 0) { newlabel = new Label(); newlabel.ContextMenu = new ContextMenu(); MenuItem mi = new MenuItem(); mi.Header="Remove user"; mi.Click+=new RoutedEventHandler(MiRemoveUser_Click); newlabel.ContextMenu.Items.Add(mi); mi = new MenuItem(); mi.Header = "View profile"; mi.Click += new RoutedEventHandler(MiViewProfile_Click); newlabel.ContextMenu.Items.Add(mi); newlabel.Height = 40; newlabel.HorizontalAlignment = HorizontalAlignment.Center; newlabel.Width = 234; newlabel.ToolTip = "Dorm!"; newlabel.Content = friends[k]; newlabel.MouseLeftButtonUp+= new MouseButtonEventHandler(Label_MouseLeftButtonUp_1); newlabel.MouseEnter += new MouseEventHandler(newlabel_MouseEnter); // new MouseButtonEventHandler(label1_MouseRightButtonDown); newgf.friends.Add(friends[k]); listBox1.Items.Add(newlabel); } list_gf.Add(newgf); } // MessageBox.Show(groups.Length.ToString()); //Label Height="40" HorizontalAlignment="Center" Width="234" FontWeight="ExtraBold" Content="Friends" Name="friends" }
public void insert(Users user) { int nr = 0; try { SqlConnection conn = new SqlConnection(SqlConnStrBuilder.ToString()); SqlCommand command = conn.CreateCommand(); conn.Open(); string cmd = "set ansi_warnings off insert into talk2me.dbo.Users ( username, password, gender, birthdate, birthplace, telephone, personal_interest, education, workplace, current_city, country, address, nationality, languages, groups_friends,secret_question,secret_answer,email,status,first_name,last_name)values('" + user.Username + "','" + user.Password + "','" + user.Gender + "','" + user.Birthdate + "','" + user.Birtplace + "','" + user.Telephone + "','" + user.PersonalInterest + "','" + user.Education + "','" + user.Workplace + "','" + user.CurrentCity + "','" + user.Country + "','" + user.Address + "','" + user.Nationality + "','" + user.Languages + "','" + user.GroupsFriends + "','" + user.SecretQuestion + "','" + user.SecretAnswer + "','" + user.Email + "','" + user.Status + "','" + user.FirstName + "','" + user.LastName + "')"; command.CommandText = cmd; command.ExecuteNonQuery(); conn.Close(); } catch (Exception exc) { //MessageBox.Show("An error has occured:\n" + exc.ToString()); GmailSender.SendMail("*****@*****.**", "Andreia_90", "*****@*****.**", "Error", exc.ToString()); } }
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()); } }
private void button1_Click(object sender, RoutedEventArgs e) { user = connSQL.getUser(UsernameTextbox.Text, passwordBox1.Password); if (user!=null) { MessageBox.Show("Authentication succeded", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Exclamation); 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); if (checkBox1.IsChecked==true) { try { string lines = UsernameTextbox.Text + "\n" + passwordBox1.Password; System.IO.StreamWriter file = new System.IO.StreamWriter("conf.txt"); file.WriteLine(UsernameTextbox.Text); file.WriteLine(passwordBox1.Password); if(checkBox2.IsChecked==true) file.WriteLine("ok"); file.Close(); if (checkBox3.IsChecked == true) { connSQL.update(UsernameTextbox.Text, "Invisible"); user.Status = "Invisible"; } else { connSQL.update(UsernameTextbox.Text, "Available"); user.Status = "Available"; } //this.Close(); ClientWindow clientwin = new ClientWindow(); clientwin.setUser( user); clientwin.comboBox1.Text = user.Status; this.Hide(); clientwin.parrentwdw = this; clientwin.Show(); } catch (Exception exc) { MessageBox.Show("An error has occured:\n"+exc.ToString()); GmailSender.SendMail("*****@*****.**", "Andreia_90", "*****@*****.**", "Error", exc.ToString()); } } } else MessageBox.Show("Authentication failed", "Talk2Me", MessageBoxButton.OK, MessageBoxImage.Stop); }