static void Main(string[] args) { Console.SetBufferSize(Console.BufferWidth, 32766); do { Menu.Index(); string userName = MainApplication.LoginUsernameInput(); string passWord = MainApplication.LoginPasswordInput(); User user = DataBaseCommunication.LogInByUserNameAndPassWord(userName, passWord); // ean o user den iparxei sthn database tote to id tha einai 0 (default integer value) // opws einai domimeno to table users sthn database den ginetai na iparxei user me id = 0 if (user.ID != 0) // trexei to kurios programma { Console.Write("\r\npress any key to continue the app"); Console.ReadKey(); Console.Clear(); MainApplication mainApp = new MainApplication(user); mainApp.Run(); } Console.ReadKey(); Console.Clear(); } while (true); }
private void btnDelete_Click(object sender, EventArgs e) { if (user.Licence == "UserA") { if (comboBox1.SelectedItem.ToString() == user.UserName) { DataBaseCommunication dbTool = new DataBaseCommunication(); string returnedMessage = dbTool.DeleteMessage(int.Parse(textBox1.Text)); MessageBox.Show(returnedMessage); } else { MessageBox.Show("Delete canceled\r\nYou are a UserA\r\nYou can edit and delete only your messages"); } } else if (user.Licence == "Simple User") // ston Simple User den xreiazetai na kanw kapoion elegxo giati einai o monos xrhsths sto combobox me ta usernames { // kata to form load den prostithetai to username kapoiou allou xrhsth sto combobox me ta usernames DataBaseCommunication dbTool = new DataBaseCommunication(); string returnedMessage = dbTool.DeleteMessage(int.Parse(textBox1.Text)); MessageBox.Show(returnedMessage); } else if (user.Licence == "UserB") { if (comboBox1.SelectedItem.ToString() == user.UserName) { DataBaseCommunication dbTool = new DataBaseCommunication(); string returnedMessage = dbTool.DeleteMessage(int.Parse(textBox1.Text)); MessageBox.Show(returnedMessage); } else { MessageBox.Show("Delete canceled\r\nYou are a UserB\r\nYou can edit other users messages but you can delete only your messages "); } } else if (user.Licence == "UserC") { if (comboBox1.SelectedItem.ToString() != "admin") { DataBaseCommunication dbTool = new DataBaseCommunication(); string returnedMessage = dbTool.DeleteMessage(int.Parse(textBox1.Text)); MessageBox.Show(returnedMessage); } else { MessageBox.Show("Delete canceled\r\nYou can not delete this message because it belongs to Administrator"); } } else { DataBaseCommunication dbTool = new DataBaseCommunication(); string returnedMessage = dbTool.DeleteMessage(int.Parse(textBox1.Text)); MessageBox.Show(returnedMessage); } ResetFormTools(); fillComboboxWithUsers(querry); }
private void button2_Click(object sender, EventArgs e) { var dbTool = new DataBaseCommunication(); string message = dbTool.DeleteUser(Convert.ToString(comboBox1.SelectedItem)); MessageBox.Show(message); ResetFormTools(); fillComboboxWithUsers(); }
private void button1_Click(object sender, EventArgs e) { SqlConnection sqlConnection = new SqlConnection(connectionString); var dbTool = new DataBaseCommunication(); string message = dbTool.UpdateUser(/*UserIdsFromComboBox[numberOfSelectedItem]*/ Convert.ToString(comboBox1.SelectedItem), lastNameTxt.Text, firstNameTxt.Text, Convert.ToString(comboBox2.SelectedItem), passWordTxt.Text); MessageBox.Show(message); ResetFormTools(); fillComboboxWithUsers(); }
private void Statistics_Load(object sender, EventArgs e) { DataBaseCommunication dbTool = new DataBaseCommunication(); string querry1 = "SELECT COUNT(UserID) FROM USERS"; string querry2 = "SELECT COUNT(UserID) FROM DELETEDUSERS"; string querry3 = "SELECT COUNT(MessageID) FROM MESSAGES"; string querry4 = "SELECT COUNT(DISTINCT MessageID) FROM USERSMESSAGES"; richTextBox1.Text += "MESSAGES AND USERS STATISTICS\r\n\r\n\r\n\r\n\r\n*EXISTNG USERS: " + dbTool.HowManyExistsInDatabase(querry1) + "\r\n\r\n"; richTextBox1.Text += "*DELETED USERS : " + dbTool.HowManyExistsInDatabase(querry2) + "\r\n\r\n"; richTextBox1.Text += "*TOTAL NUMBER OF SENDED MESSAGES : " + dbTool.HowManyExistsInDatabase(querry3) + "\r\n\r\n"; richTextBox1.Text += "*ACTIVE MESSAGES : " + dbTool.HowManyExistsInDatabase(querry4) + "\r\n\r\n*message deactivated when deleted\r\n from sender and from receiver" + "\r\n\r\n"; }
//public static string YesNoMethod() //{ // while (true) // { // Console.CursorVisible = false; // string selectedItem = Menu.SelectMenu(yesNoMenu, 3); // if (selectedItem == "Yes") // return selectedItem; // else if (selectedItem == "No") // return selectedItem; // else // { } // } //} public static void Index() { while (true) { Console.CursorVisible = false; Console.WriteLine("CHAT APPLICATION"); string selectedFirstMenuItem = SelectMenu(indexMenu, 6); if (selectedFirstMenuItem == "Log in") { break; } else if (selectedFirstMenuItem == "Register") { Console.Clear(); Console.WriteLine("You will register as a Simple User.\r\nAfter the registration chat with administrator to update you\r\n\r\n"); string registerUserName = MainApplication.AskUserNameFromUserAndTakeUserName(); string registerPassWord = MainApplication.AskPassWordFromUserAndTakePassword(); string registerFirstName = MainApplication.AskFirstNameFromUserAndTakeFirstName(); string registerLastName = MainApplication.AskLastNameFromUserAndTakeLastName(); DataBaseCommunication dbTool = new DataBaseCommunication(); dbTool.CreateUserToDatabase(registerUserName, registerPassWord, registerFirstName, registerLastName, "Simple User"); Console.WriteLine("\r\nPress any key to log in..."); Console.ReadKey(); // break; Console.Clear(); } else if (selectedFirstMenuItem == "Information about the application") { Console.Clear(); MainApplication.InformationAboutThisApplication(); Console.ReadKey(); Console.Clear(); } else if (selectedFirstMenuItem == "Exit") { Environment.Exit(0); } else { } } }
private void button2_Click(object sender, EventArgs e) { string sDateTime = Convert.ToString(DateTime.Now); DataBaseCommunication dbWformTool = new DataBaseCommunication(); string returnString = dbWformTool.SendMessage(richTextBox1.Text, comboBox1.SelectedItem.ToString(), UserIdsFromComboBox[numberOfSelectedItem], user.UserName, user.ID, sDateTime); MessageBox.Show(returnString); // this code will save the context of the richbox1.text var saveFileDialog1 = new SaveFileDialog { InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal), Filter = string.Format("{0}Text files (*.txt)|*.txt|All files (*.*)|*.*", ""), RestoreDirectory = true, ShowHelp = true, CheckFileExists = false }; while (saveFileDialog1.ShowDialog() != DialogResult.OK) // epeidi to minima prepei na apothikeuetai oti kai na ginei vasi requirments to parathiro de tha stamatisei na mexri na patithei to button OK { MessageBox.Show("You must save the message!"); } File.WriteAllText(saveFileDialog1.FileName, "Sender UserName: "******"\r\nDateTime: " + sDateTime + "\r\nReceiver UserName: "******"\r\n" + "\r\n" + richTextBox1.Text); MessageBox.Show("Message saved to a txt file!"); richTextBox1.ResetText(); richTextBox2.ResetText(); UserIdsFromComboBox.Clear(); comboBox1.Items.Clear(); comboBox1.ResetText(); button2.Enabled = false; FillComboboWithUSers(); }
public MainApplication(User connectedUser) { user = connectedUser; DbTool = new DataBaseCommunication(); }
private void btnEdit_Click(object sender, EventArgs e) { //var saveFileDialog1 = new SaveFileDialog //{ // InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal), // Filter = string.Format("{0}Text files (*.txt)|*.txt|All files (*.*)|*.*", ""), // RestoreDirectory = true, // ShowHelp = true, // CheckFileExists = false //}; if (user.Licence == "UserA") { if (comboBox1.SelectedItem.ToString() == user.UserName) { DataBaseCommunication dbTool = new DataBaseCommunication(); string message = dbTool.EditMessage(MessageIdsFromComboBox[numberOfSelectedItem2], richTextBox1.Text, richTextBox2.Text, richTextBox3.Text); MessageBox.Show(message); //while (saveFileDialog1.ShowDialog() != DialogResult.OK) //{ // MessageBox.Show("You must save the message"); //} //File.WriteAllText(saveFileDialog1.FileName, "Sender UserName: "******"\r\nDatetime: " + richTextBox2.Text + "\r\nReceiver UserName: "******"\r\n" + "\r\n" + richTextBox1.Text); //MessageBox.Show("Message saved to a txt file!"); } else { MessageBox.Show("Update canceled\r\nYou are a UserA\r\nYou can edit and delete only your messages"); } } else if (user.Licence == "Simple User") // ston Simple User den xreiazetai na kanw kapoion elegxo giati einai o monos xrhsths sto combobox me ta usernames { // kata to form load den prosthetai to username kapoiou allou xrhsth sto combobox me ta usernames DataBaseCommunication dbTool = new DataBaseCommunication(); string message = dbTool.EditMessage(MessageIdsFromComboBox[numberOfSelectedItem2], richTextBox1.Text, richTextBox2.Text, richTextBox3.Text); MessageBox.Show(message); //while (saveFileDialog1.ShowDialog() != DialogResult.OK) //{ // MessageBox.Show("You must save the message"); //} //File.WriteAllText(saveFileDialog1.FileName, "Sender UserName: "******"\r\nDatetime: " + richTextBox2.Text + "\r\nReceiver UserName: "******"\r\n" + "\r\n" + richTextBox1.Text); //MessageBox.Show("Message saved to a txt file!"); } else if (user.Licence == "UserC" || user.Licence == "UserB") { if (comboBox1.SelectedItem.ToString() != "admin") { DataBaseCommunication dbWformTool = new DataBaseCommunication(); string message = dbWformTool.EditMessage(MessageIdsFromComboBox[numberOfSelectedItem2], richTextBox1.Text, richTextBox2.Text, richTextBox3.Text); MessageBox.Show(message); //while (saveFileDialog1.ShowDialog() != DialogResult.OK) //{ // MessageBox.Show("You must save the message"); //} //File.WriteAllText(saveFileDialog1.FileName, "Sender UserName: "******"\r\nDatetime: " + richTextBox2.Text + "\r\nReceiver UserName: "******"\r\n" + "\r\n" + richTextBox1.Text); //MessageBox.Show("Message saved to a txt file!"); } else { MessageBox.Show("You can not edit this message. It belongs to Administrator"); } } else { DataBaseCommunication dbWformTool = new DataBaseCommunication(); string message = dbWformTool.EditMessage(MessageIdsFromComboBox[numberOfSelectedItem2], richTextBox1.Text, richTextBox2.Text, richTextBox3.Text); MessageBox.Show(message); //while (saveFileDialog1.ShowDialog() != DialogResult.OK) //{ // MessageBox.Show("You must save the message"); //} //File.WriteAllText(saveFileDialog1.FileName, "Sender UserName: "******"\r\nDatetime: " + richTextBox2.Text + "\r\nReceiver UserName: "******"\r\n" + "\r\n" + richTextBox1.Text); //MessageBox.Show("Message saved to txt file!"); } ResetFormTools(); fillComboboxWithUsers(querry); }