private void ShowGenres_btn_Click(object sender, EventArgs e) { listBox1.Items.Clear(); List <Genre> genres = ReadFromDatabase.ReadAllGenres(); listBox1.Items.AddRange(genres.ToArray()); }
private void ShowAuthors_btn_Click(object sender, EventArgs e) { listBox1.Items.Clear(); List <Author> authors = ReadFromDatabase.ReadAllAuthors(); listBox1.Items.AddRange(authors.ToArray()); }
private void selialize_btn_Click(object sender, RoutedEventArgs e) { List <Book> listBooks = ReadFromDatabase.ReadAllBooks(); // BinaryFormatter: FileStream fs, fs1, fs2; BinaryFormatter formatter = new BinaryFormatter(); using (fs = new FileStream("ListBooks.txt", FileMode.OpenOrCreate)) { formatter.Serialize(fs, listBooks); fs.Close(); Title = "Collection of a PC is Serialize"; } // XmlSerializer: XmlSerializer xml_formatter = new XmlSerializer(typeof(Book)); using (fs1 = new FileStream("list_books.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs1, listBooks); fs1.Close(); } // JsonSerializer: using (fs2 = new FileStream("books_serialize.json", FileMode.OpenOrCreate)) { // JsonSerializer.Serialize<List<Book>>(fs2, listBooks); Title = "Data has been saved to file"; fs2.Close(); } }
void EditArea() { int index = (this.Owner as WorkAreas).lbox.Items.IndexOf(this.update_Area); int idTable = update_Area.Id; List <WorkArea> all = ReadFromDatabase.ShowAllAreas(num).ToList(); WorkArea update = all.Where(i => i.Id == idTable).FirstOrDefault(); update.SiteName = name_txt.Text; update.Login = login_txt.Text; update.Password = paswd_txt.Text; update.Phone = Convert.ToInt32(phone_txt.Text); update.URL = url_txt.Text; update.Email = email_txt.Text; update.Coments = coments_txt.Text; update.DateCreate = DateTime.Now; string res = EditRecord.EditInfo(update, num); MessageBox.Show(res, "Result Update"); (this.Owner as WorkAreas).lbox.Items.RemoveAt(index); (this.Owner as WorkAreas).lbox.Items.Insert(index, update); this.Close(); }
private void show_authors_Click(object sender, RoutedEventArgs e) { listBox1.Items.Clear(); Author[] authors = ReadFromDatabase.ReadAllAuthors().ToArray(); foreach (Author a in authors) { listBox1.Items.Add(a); } }
private void show_books_Click(object sender, RoutedEventArgs e) { listBox1.Items.Clear(); Book[] books = ReadFromDatabase.ReadAllBooks().ToArray(); foreach (Book b in books) { listBox1.Items.Add(b); } }
private void show_genres_Click(object sender, RoutedEventArgs e) { listBox1.Items.Clear(); Genre[] genres = ReadFromDatabase.ReadAllGenres().ToArray(); foreach (Genre g in genres) { listBox1.Items.Add(g); } }
void AddUser() { if (name_txt.Text == null && login_txt.Text == null && paswd_txt.Text == null && email_txt.Text == null && phone_txt.Text == null && fname_txt.Text == null && role_txt.Text == null && age_txt.Text == null) { MessageBox.Show("All fields is empty", "empty", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (name_txt.Text == null || login_txt.Text == null || paswd_txt.Text == null || email_txt.Text == null || phone_txt.Text == null || fname_txt.Text == null || role_txt.Text == null || age_txt.Text == null) { MessageBox.Show("Some of field are empty", "empty", MessageBoxButton.OK, MessageBoxImage.Warning); } else { //try //{ List <User> users = ReadFromDatabase.ShowAllUsers().ToList(); int num_table = users.Count + 1; User add_wa = new User { Last_Name = name_txt.Text, First_Name = fname_txt.Text, Login = login_txt.Text, Password = paswd_txt.Text, Email = email_txt.Text, Phone = Convert.ToInt32(phone_txt.Text), Role = role_txt.Text, Id_WorkArea = num_table, Age = Convert.ToInt32(age_txt.Text), Date_Registr = DateTime.Now }; db.Users.Add(add_wa); db.SaveChanges(); db.Database.ExecuteSqlCommand( $"CREATE TABLE [dbo].[WorkAreas_{num_table}] (" + $"[Id] INT IDENTITY(1, 1) NOT NULL," + $"[SiteName] NVARCHAR(50) NULL," + $"[Email] NVARCHAR(50) NULL," + $"[Login] NVARCHAR(50) NULL," + $"[Password] NVARCHAR(50) NULL," + $"[URL] NVARCHAR(50) NULL," + $"[Phone] NVARCHAR(50) NULL," + $"[Coments] NVARCHAR(50) NULL," + $"[DateCreate] DATETIME NULL)"); MessageBox.Show($"User - {name_txt.Text} has created!"); this.Close(); //} //catch(Exception ex) { MessageBox.Show(ex.Message, "Something went wrong..", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public Show_Users() { InitializeComponent(); try { list.ItemsSource = ReadFromDatabase.Read_All_Users(); } catch (Exception ex) { MessageBox.Show(ex.Message, "System Exception..Failed..", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { int size = ReadFromDatabase.ShowAllAreas(num_table).Count(); List <WorkArea> lArea = ReadFromDatabase.ShowAllAreas(num_table).ToList(); for (int i = 0; i < size; i++) { lbox.Items.Add(lArea[i]); } if (lbox.Items.Count == 0) { lbox.Items.Add("The table is empty. Try to add new info"); } }
void EnteredAdminUser(User check_user) { flag = true; num_table = check_user.Id_WorkArea; currrent_id = check_user.Id; List <UsersSessions> list = null; try { list = ReadFromDatabase.AllUsersSessions(num_table).ToList(); } catch { } if (list == null) { db.Database.ExecuteSqlCommand( $"CREATE TABLE [dbo].[UserSessions_{num_table}] (" + $"[Id] INT IDENTITY(1, 1) NOT NULL," + $"[CurLogin] NVARCHAR(50) NULL," + $"[CurPassword] NVARCHAR(50) NULL," + $"[RememberMe] Bit NULL," + $"[IsActive] Bit NULL," + $"[AccessToken] uniqueidentifier NULL," + $"[DateEnter] datetime NULL," + $"[DateLeave] datetime NULL)"); session = new UsersSessions(); session.CurLogin = login_txt.Text; session.CurPassword = passwd_txt.Password; session.RememberMe = Convert.ToBoolean(remeber_check.IsChecked); session.DateEnter = DateTime.Now; session.AccessToken = Guid.NewGuid(); WorkAreas area_window = new WorkAreas(check_user.Id_WorkArea, check_user.Role, $"{check_user.First_Name} {check_user.Last_Name}", this); area_window.Owner = this; area_window.ShowDialog(); } else { session = new UsersSessions(); session.CurLogin = login_txt.Text; session.CurPassword = passwd_txt.Password; session.RememberMe = Convert.ToBoolean(remeber_check.IsChecked); session.DateEnter = DateTime.Now; session.AccessToken = Guid.NewGuid(); new WorkAreas(check_user.Id_WorkArea, check_user.Role, $"{check_user.First_Name} {check_user.Last_Name}", this).ShowDialog(); } }
public UsersInfo() { InitializeComponent(); int size = ReadFromDatabase.ShowAllUsers().Count(); List <User> lArea = ReadFromDatabase.ShowAllUsers().ToList(); for (int i = 0; i < size; i++) { listusers.Items.Clear(); listusers.Items.Add(lArea[i]); } if (listusers.Items.Count == 0) { listusers.Items.Add("The table is empty. Try to add new info"); } }
public Register() { InitializeComponent(); role_txt.IsReadOnly = true; db = new MyContext(); int size = ReadFromDatabase.ShowAllUsers().Count(); if (size == 0) { MessageBox.Show("To get startet you should create an aplication owner with tha Admin role. Jast you will have this role./nAll" + "subsequent users will play the role 'user'", "Create 1st Owner", MessageBoxButton.OK, MessageBoxImage.Information); role_txt.Text = "admin"; } else { role_txt.Text = "user"; } }
private void login_btn_Click(object sender, EventArgs e) { // Получаем список всех юзеров с таблици: List <User> users = ReadFromDatabase.ReadAllUsers(); bool flag = false; string mode = string.Empty; string login = login_txt.Text; string password = pass_txt.Text; if (login == "" && password == "") { MessageBox.Show("All fields are EMPTY", "1st fill out log & pass", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (login == "" || password == "") { MessageBox.Show("Some fo the field is EMPTY", "1st fill out log & pass", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { for (int i = 0; i < users.Count; i++) { if (login == users[i].Login && password == users[i].Password && users[i].Role == "admin") { flag = true; mode = users[i].Role; // .. If you are Admin(owner): new Work_Area(mode, users[i].First_Name, users[i].Last_Name).ShowDialog(); } else if (login == users[i].Login && password == users[i].Password && users[i].Role == "user") { flag = true; mode = users[i].Role; new Work_Area(mode, users[i].First_Name, users[i].Last_Name).ShowDialog(); } } } if (!flag) { MessageBox.Show("Wrong Login & Password..\nTry again", "User doesn't exist", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public MainWindow() { InitializeComponent(); db = new MyContext(); session = new UsersSessions(); int indx = ReadFromDatabase.ShowAllUsers().Count() - 1; try { User last_user = ReadFromDatabase.ShowAllUsers().ToArray()[indx]; UsersSessions[] sessions = ReadFromDatabase.AllUsersSessions(last_user.Id_WorkArea).ToArray(); if (sessions[sessions.Count() - 1].RememberMe == true) { remeber_check.IsChecked = true; login_txt.Text = last_user.Login; passwd_txt.Password = last_user.Password; } } catch { } }
private void exec_btn_Click(object sender, RoutedEventArgs e) { if (mode.Equals("Add")) { // Если мы оставили все поля пустыми: if (name_txt.Text == "" && birth_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButton.OK, MessageBoxImage.Warning); } // Если мы оставили все поля пустыми: else if (name_txt.Text == "" || birth_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButton.OK, MessageBoxImage.Warning); } else { try { Author author = new Author { Id = autoIncrement, Name = name_txt.Text, Date_of_Birth = int.Parse(birth_txt.Text), }; // Add to Books table of databese: string msg = InsertToDatabase.InsertAuthor(author); MessageBox.Show(msg, "Added"); (this.Owner as MainWindow).listBox1.Items.Add(author); (this.Owner as MainWindow).listBox1.Items.Clear(); authors = ReadFromDatabase.ReadAllAuthors().ToArray(); // Ubdate listbox to curent datas from a table Books: foreach (Author b in authors) { (this.Owner as MainWindow).listBox1.Items.Add(b); } ClearFields(); this.Close(); } catch { MessageBox.Show("Вы ввели символи, или строку вместо целого числа", "Не правильный формат", MessageBoxButton.OK, MessageBoxImage.Warning); } } } else if (mode.Equals("Update")) { // Если мы оставили все поля пустыми: if (name_txt.Text == "" && birth_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButton.OK, MessageBoxImage.Warning); } // Если мы оставили все поля пустыми: else if (name_txt.Text == "" || birth_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButton.OK, MessageBoxImage.Warning); } else { try { My_Context db = new My_Context(); int index = (this.Owner as MainWindow).listBox1.Items.IndexOf(this.author); // Get Id entity from the Table: int id = author.Id; // Get entity from DbSet to Id and edit it: List <Author> all = ReadFromDatabase.ReadAllAuthors(); Author updated = all.Where(u => u.Id == id).FirstOrDefault(); //updated.Id = index + 1; updated.Name = name_txt.Text; updated.Date_of_Birth = int.Parse(birth_txt.Text); // Update to Database: db.Entry(updated).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); //MessageBox.Show(msg, "Updated"); (this.Owner as MainWindow).listBox1.Items.RemoveAt(index); (this.Owner as MainWindow).listBox1.Items.Insert(index, updated); (this.Owner as MainWindow).listBox1.Items.Clear(); authors = ReadFromDatabase.ReadAllAuthors().ToArray(); foreach (Author b in authors) { (this.Owner as MainWindow).listBox1.Items.Add(b); } this.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.Message, "System Exception..Failed..", MessageBoxButton.OK, MessageBoxImage.Error); } } } else { MessageBox.Show("Incorrect sting parameter 'mode'..", "Something went wrong...", MessageBoxButton.OK, MessageBoxImage.Warning); } }
static void Main(string[] args) { DataBase db = new DataBase(@"DESKTOP-LTPHR86\CLOVER", "Figures"); string name, type, result = ""; float a, b, c, area, perim; int tops, edges, choice = 0, result1 = 0; do { Console.Clear(); choice = Menu(); switch (choice) { case 1: Console.Clear(); Console.WriteLine("1 - Add new triangle in the table:"); Console.WriteLine("2 - Show all triangles from the table"); Console.WriteLine("3 - Edit triangle by Id"); Console.WriteLine("4 - Delete triangle by Id"); Console.WriteLine("5 - Return back"); Console.Write("\nChose any one of the figures.."); int choice1 = int.Parse(Console.ReadLine()); switch (choice1) { case 1: Console.Clear(); Triangle tr = SetTriangle(out name, out type, out a, out b, out c, out area, out perim, out tops, out edges); try { result = db.Add($"insert into Triangles(Name,Type,A,B,C,Area,Perimeter,Tops,Edges) values('{name}','{type}',{a},{b},{c},{area},{perim},{tops},{edges})"); Console.ForegroundColor = (result == "Insert was Successfully!Congratulation!!!") ? ConsoleColor.Green : ConsoleColor.Red; Console.WriteLine(result); Console.ResetColor(); Pause(); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); Pause(); } break; case 2: Console.Clear(); string conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; List <Triangle> list = ReadFromDatabase.ReadAllTriangles(conn); for (int i = 0; i < list.Count; i++) { Console.WriteLine(new string('-', 120)); Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine($"\n{i + 1} Triangle:\n"); Console.ForegroundColor = RandColors()[rand.Next(0, 5)]; Console.WriteLine(list[i]); Console.ResetColor(); Console.WriteLine("\n" + new string('-', 120)); } Pause(); break; case 3: Console.Write("Enter any id of triangle to Update: "); int editId = int.Parse(Console.ReadLine()); Triangle editTr = SetTriangle(out name, out type, out a, out b, out c, out area, out perim, out tops, out edges); string editQuery = $"Update Triangles SET Name='{name}',Type='{type}',A={a},B={b},C={c},Area={area},Perimeter={perim},Tops={tops},Edges={edges} where Id={editId}"; try { result1 = db.Update(editQuery); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); Pause(); } if (result1 == 1) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTriangle has updated successfully!!!"); Console.ResetColor(); Pause(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"\nThe method of an Update() return {result1}\nSomething went wrong...Try to fix this!"); Console.ResetColor(); Pause(); } break; case 4: Console.Write("Enter any id of triangle to Delete from the table: "); int deleteId = int.Parse(Console.ReadLine()); string delQuery = $"Delete from Triangles where Id={deleteId}"; try { result1 = db.Delete(delQuery); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); Pause(); } if (result1 == 1) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\nTriangle has deleted successfully!!!"); Console.ResetColor(); Pause(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"\nThe method of an Delete() return {result}\nSomething went wrong...Try to fix this!"); Console.ResetColor(); Pause(); } break; case 5: break; } break; } }while (choice != 0); }
private void add_btn_Click(object sender, EventArgs e) { if (mode.Equals("Add")) // mode == "Add" { // Если мы оставили все поля пустыми: if (title_txt.Text == "" && age_txt.Text == "" && author_txt.Text == "" && genre_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // Если мы оставили все поля пустыми: else if (title_txt.Text == "" || age_txt.Text == "" || author_txt.Text == "" || genre_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { Book book = new Book { Id = autoIncrement, Title = title_txt.Text, Age_Release = int.Parse(age_txt.Text), Id_Author = int.Parse(author_txt.Text), Id_Genre = int.Parse(genre_txt.Text), Date_Updated = DateTime.Now }; // Add to Books table of databese: string msg = InsertToDatabase.InsertBook(book); MessageBox.Show(msg, "Added"); (this.Owner as Main_Form).listBox1.Items.Add(book); (this.Owner as Main_Form).listBox1.Items.Clear(); (this.Owner as Main_Form).listBox1.Items.AddRange(ReadFromDatabase.ReadAllBooks().ToArray()); ClearFields(); this.Close(); } catch { MessageBox.Show("Вы ввели символи, или строку вместо целого числа", "Не правильный формат", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else if (mode.Equals("Edit")) { // Если мы оставили все поля пустыми: if (title_txt.Text == "" && age_txt.Text == "" && author_txt.Text == "" && genre_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // Если мы оставили все поля пустыми: else if (title_txt.Text == "" || age_txt.Text == "" || author_txt.Text == "" || genre_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int index = (this.Owner as Main_Form).listBox1.Items.IndexOf(this.book); Book updated = new Book(); updated.Id = index + 1; updated.Title = title_txt.Text; updated.Age_Release = int.Parse(age_txt.Text); updated.Id_Author = int.Parse(author_txt.Text); updated.Id_Genre = int.Parse(genre_txt.Text); updated.Date_Updated = DateTime.Now; string msg = UpdateFromDatrabase.EditBook(updated); MessageBox.Show(msg, "Updated"); (this.Owner as Main_Form).listBox1.Items.RemoveAt(index); (this.Owner as Main_Form).listBox1.Items.Insert(index, updated); (this.Owner as Main_Form).listBox1.Items.Clear(); (this.Owner as Main_Form).listBox1.Items.AddRange(ReadFromDatabase.ReadAllBooks().ToArray()); this.Close(); } } else if (mode.Equals("ServiceWCF")) { // Если мы оставили все поля пустыми: if (title_txt.Text == "" && age_txt.Text == "" && author_txt.Text == "" && genre_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } // Если мы оставили все поля пустыми: else if (title_txt.Text == "" || age_txt.Text == "" || author_txt.Text == "" || genre_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { BookService service = new BookService(); service.Title = title_txt.Text; service.Age_Release = int.Parse(age_txt.Text); service.Id_Author = int.Parse(author_txt.Text); service.Id_Genre = int.Parse(genre_txt.Text); service.Date_Updated = DateTime.Now; client.Insert_Book(service); ClearFields(); Close(); } catch (DataException dex) { MessageBox.Show(dex.Message, "Something went wrong...", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void ShowBook_btn_Click(object sender, EventArgs e) { listBox1.Items.Clear(); Book[] books = ReadFromDatabase.ReadAllBooks().ToArray(); listBox1.Items.AddRange(books); }
private void add_btn_Click(object sender, EventArgs e) { if (mode.Equals("Add")) { if (name_txt.Text == "" && date_of_birth_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (name_txt.Text == "" || date_of_birth_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { try { Author author = new Author { Id = autoIncrement, Name = name_txt.Text, Date_of_Birth = int.Parse(date_of_birth_txt.Text) }; string msg = InsertToDatabase.InsertAuthor(author); MessageBox.Show(msg, "Added"); (this.Owner as Main_Form).listBox1.Items.Add(author); (this.Owner as Main_Form).listBox1.Items.Clear(); (this.Owner as Main_Form).listBox1.Items.AddRange(ReadFromDatabase.ReadAllAuthors().ToArray()); name_txt.Text = ""; date_of_birth_txt.Text = ""; this.Close(); } catch { MessageBox.Show("Вы ввели символи, или строку вместо целого числа", "Не правильный формат", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } else if (mode.Equals("Edit")) { if (name_txt.Text == "" && date_of_birth_txt.Text == "") { MessageBox.Show("Вы оставили все поля пустыми", "Все поля пустые...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (name_txt.Text == "" || date_of_birth_txt.Text == "") { MessageBox.Show("Какое то пеле оставили пустым", "Пустое к-ето поле...", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { int index = (this.Owner as Main_Form).listBox1.Items.IndexOf(this.author); Author updated = new Author(); updated.Id = index + 1; updated.Name = name_txt.Text; updated.Date_of_Birth = int.Parse(date_of_birth_txt.Text); string msg = UpdateFromDatrabase.EditAuthor(updated); MessageBox.Show(msg, "Updated"); (this.Owner as Main_Form).listBox1.Items.RemoveAt(index); (this.Owner as Main_Form).listBox1.Items.Insert(index, updated); (this.Owner as Main_Form).listBox1.Items.Clear(); (this.Owner as Main_Form).listBox1.Items.AddRange(ReadFromDatabase.ReadAllAuthors().ToArray()); this.Close(); } } }