private void b_confirm_1_Click(object sender, EventArgs e) { if (t_password_1.Text == "") { MessageBox.Show("Nie uzupełniono wymaganego pola z aktualnym hasłem!"); } else if (t_password_1.Text != "") { using (var container = new CinemaEntities()) { string s_sha1_pass_in_the_base = edit_row[1].Value.ToString(); //haslo z bazy z wybranej krotki -> sha1 //MessageBox.Show(s_sha1_pass_in_the_base); byte[] bytes_user_pass = Encoding.Default.GetBytes(t_password_1.Text);//haslo z bazy w bajtach using (var sha1 = SHA1.Create()) { byte[] sha1_user_pass = sha1.ComputeHash(bytes_user_pass); string s_sha1_user_pass = Encoding.Default.GetString(sha1_user_pass); //haslo z bazy -> sha1 if (s_sha1_pass_in_the_base == s_sha1_user_pass) { t_password_2.Enabled = true; t_password_3.Enabled = true; MessageBox.Show("Proszę wprowadzić nowe hasło"); } else { MessageBox.Show("Podane aktualne hasło jest nieprawidłowe!"); } } } } }
public bool check_login_check_password() { using (var container = new CinemaEntities()) { byte[] admin_password = Encoding.Default.GetBytes(password_textBox.Text); //utworzenie skrotu od pobranego hasla (SHA_1) using (var sha1 = SHA1.Create()) { byte[] admin_password_sha1 = sha1.ComputeHash(admin_password); string s_admin_password_sha1 = Encoding.Default.GetString(admin_password_sha1); var number_of_admins = container.ADMINS.Where(a => a.ADMIN_LOGIN == login_textBox.Text && a.PASSWORD == s_admin_password_sha1); if (number_of_admins.Count() == 0) { return(false); } Program_Main.login = login_textBox.Text; Program_Main.password = s_admin_password_sha1; number_of_admins.First().LAST_LOGIN = DateTime.Now; container.SaveChanges(); } } return(true); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Login_Form login_form = new Login_Form(); Main_Form main_form = new Main_Form(); DialogResult dialog_result = DialogResult.No; while (dialog_result != DialogResult.Cancel) { if (dialog_result == DialogResult.No) //jezeli jest niezalogowany { login_form = new Login_Form(); dialog_result = login_form.ShowDialog(); } if (dialog_result == DialogResult.Yes) { main_form = new Main_Form(); dialog_result = main_form.ShowDialog(); } using (var container = new CinemaEntities()) { var number_of_admins = container.ADMINS.Where(a => a.ADMIN_LOGIN == login && a.PASSWORD == password); if (number_of_admins.Count() != 0) { number_of_admins.First().LAST_LOGOUT = DateTime.Now; container.SaveChanges(); } } } }
public void create_combobox_entieties(TextBox textbox, int i) { textbox.Visible = false; ComboBox combobox = new ComboBox(); using (var C_Entities = new CinemaEntities()) { List <string> itemsList = new List <string>(); if (i == 1 || i == 3) //ID_HALLS { foreach (var item in C_Entities.HALLS.ToList()) { itemsList.Add(item.ID_HALL); } } else if (i == 2) //VIP { foreach (var item in C_Entities.TICKETS.ToList()) { itemsList.Add(item.ID_TICKET.ToString()); } } else if (i == 4) //ID_MOVIE { foreach (var item in C_Entities.MOVIES.ToList()) { itemsList.Add(item.ID_MOVIE); } } combobox.DataSource = itemsList; } combobox.Size = new System.Drawing.Size(120, 20); combobox.TabIndex = i + 12; combobox.Location = new System.Drawing.Point(141, 17 + 25 * i); combobox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; comboboxes.Add(combobox); this.Controls.Add(combobox); }
private void Main_Form_Load(object sender, EventArgs e) { using (var C_Entities = new CinemaEntities()) { var movies = from movie in C_Entities.MOVIES select new { movie.ID_MOVIE, movie.TITLE, movie.GENRE, movie.RUNTIME, movie.RATING, movie.RELEASE_DATE, movie.DIRECTION, movie.SCREENPLAY, movie.STARRING, movie.IMAGE, movie.TRAILER, movie.SYNOPSIS }; TableGridView.DataSource = movies.ToList(); } }
private void b_delete_tuple_Click(object sender, EventArgs e) { MessageBoxButtons buttons = MessageBoxButtons.YesNo; if (MessageBox.Show(this, "Czy na pewno chcesz usunąć tę krotkę z bazy?", "Uwaga", buttons) == DialogResult.Yes) { dynamic deleteRow = null; using (var C_Entities = new CinemaEntities()) { if (b_active == 1) { string primary_key = TableGridView.SelectedRows[0].Cells[0].Value.ToString(); //pobranie klucza glownego z krotki deleteRow = C_Entities.MOVIES.Where(movie => movie.ID_MOVIE == primary_key).First(); //deleterow -> cala krotka, gdzie klucz glowny, to primary_key } else if (b_active == 2) { short primary_key = short.Parse(TableGridView.SelectedRows[0].Cells[0].Value.ToString()); deleteRow = C_Entities.PROGRAM.Where(program => program.ID_PROGRAM == primary_key).First(); } else if (b_active == 3) { string primary_key = TableGridView.SelectedRows[0].Cells[0].Value.ToString(); deleteRow = C_Entities.HALLS.Where(hall => hall.ID_HALL == primary_key).First(); } else if (b_active == 4) { string primary_key = TableGridView.SelectedRows[0].Cells[0].Value.ToString(); deleteRow = C_Entities.SEATS.Where(seats => seats.ID_SEAT == primary_key).First(); } else if (b_active == 5) { string primary_key = TableGridView.SelectedRows[0].Cells[0].Value.ToString(); deleteRow = C_Entities.USERS.Where(users => users.USER_LOGIN == primary_key).First(); } else if (b_active == 6) { byte primary_key = byte.Parse(TableGridView.SelectedRows[0].Cells[0].Value.ToString()); deleteRow = C_Entities.TICKETS.Where(ticket => ticket.ID_TICKET == primary_key).First(); } else if (b_active == 7) { short primary_key = short.Parse(TableGridView.SelectedRows[0].Cells[0].Value.ToString()); deleteRow = C_Entities.RESERVATIONS.Where(reservation => reservation.ID_RESERVATION == primary_key).First(); } else if (b_active == 8) { short primary_key_1 = short.Parse(TableGridView.SelectedRows[0].Cells[0].Value.ToString()); string primary_key_2 = TableGridView.SelectedRows[0].Cells[1].Value.ToString(); deleteRow = C_Entities.RESERVATIONS_DETAILS.Where( res_details => res_details.ID_RESERVATION == primary_key_1 && res_details.ID_SEAT == primary_key_2).First(); } else if (b_active == 9) { string primary_key = TableGridView.SelectedRows[0].Cells[0].Value.ToString(); deleteRow = C_Entities.ADMINS.Where(admin => admin.ADMIN_LOGIN == primary_key).First(); } else { MessageBox.Show("Wystąpił błąd podczas usuwania danych!", "Error#8"); } C_Entities.Entry(deleteRow).State = System.Data.Entity.EntityState.Deleted; try { C_Entities.SaveChanges(); } catch (DbUpdateConcurrencyException) { MessageBox.Show("Wystąpił błąd podczas dodawania danych!", "Error#9"); return; } MessageBox.Show("Poprawnie usunięto dane!", "Usuwanie danych"); TableGridView_fill(b_active); } } }
public void TableGridView_fill(int b_active) { switch (b_active) { case 1: { using (var C_Entities = new CinemaEntities()) { var movies = from movie in C_Entities.MOVIES select new { movie.ID_MOVIE, movie.TITLE, movie.GENRE, movie.RUNTIME, movie.RATING, movie.RELEASE_DATE, movie.DIRECTION, movie.SCREENPLAY, movie.STARRING, movie.IMAGE, movie.TRAILER, movie.SYNOPSIS }; TableGridView.DataSource = movies.ToList(); } } break; case 2: { using (var C_Entities = new CinemaEntities()) { var program = from prog in C_Entities.PROGRAM select new { prog.ID_PROGRAM, prog.DATE, prog.TIME, prog.ID_HALL, prog.ID_MOVIE, prog.C2D_3D, prog.VERSION }; TableGridView.DataSource = program.ToList(); } } break; case 3: { using (var C_Entities = new CinemaEntities()) { var halls = from hall in C_Entities.HALLS select new { hall.ID_HALL, hall.SEATS }; TableGridView.DataSource = halls.ToList(); } } break; case 4: { using (var C_Entities = new CinemaEntities()) { var seats = from seat in C_Entities.SEATS select new { seat.ID_SEAT, seat.ID_HALL, seat.VIP }; TableGridView.DataSource = seats.ToList(); } } break; case 5: using (var C_Entities = new CinemaEntities()) { var users = from user in C_Entities.USERS select new { user.USER_LOGIN, user.NAME, user.SURNAME, user.E_MAIL, user.TELEPHONE, user.LAST_LOGIN }; TableGridView.DataSource = users.ToList(); } break; case 6: { using (var C_Entities = new CinemaEntities()) { var tickets = from ticket in C_Entities.TICKETS select new { ticket.ID_TICKET, ticket.TYPE, ticket.PRICE_2D, ticket.PRICE_3D }; TableGridView.DataSource = tickets.ToList(); } } break; case 7: { using (var C_Entities = new CinemaEntities()) { var reservations = from reservation in C_Entities.RESERVATIONS select new { reservation.ID_RESERVATION, reservation.ID_PROGRAM, reservation.USER_LOGIN }; TableGridView.DataSource = reservations.ToList(); } } break; case 8: { using (var C_Entities = new CinemaEntities()) { var details = from detail in C_Entities.RESERVATIONS_DETAILS select new { detail.ID_RESERVATION, detail.ID_SEAT, detail.ID_TICKET, }; TableGridView.DataSource = details.ToList(); } } break; case 9: { using (var C_Entities = new CinemaEntities()) { var admins = from admin in C_Entities.ADMINS select new { admin.ADMIN_LOGIN, admin.NAME, admin.SURNAME, admin.E_MAIL, admin.TELEPHONE, admin.LAST_LOGIN, admin.LAST_LOGOUT }; TableGridView.DataSource = admins.ToList(); } } break; default: { MessageBox.Show("Żądanie wypełnienia TableGridView danymi z nieistniającej tabeli!"); } break; } }
public bool update_row() { dynamic editRow = null; if (active_table == 1) //MOVIES { // MOVIES editRow; using (var C_Entities = new CinemaEntities()) { string primary_key = row_to_edit[0].Value.ToString(); //pobranie klucza glownego z krotki -> row_to_edit ->pole w klasie editRow = C_Entities.MOVIES.Where(movie => movie.ID_MOVIE == primary_key).First(); //edit row -> cala krotka, gdzie klucz glowny, to primary_key } if (editRow != null) { editRow.TITLE = textboxes[1].Text; editRow.GENRE = textboxes[2].Text; editRow.RUNTIME = TimeSpan.Parse(datetimepickers[0].Text); editRow.RATING = byte.Parse(comboboxes[0].Text); editRow.RELEASE_DATE = datetimepickers[1].Value; editRow.DIRECTION = textboxes[6].Text; editRow.SCREENPLAY = textboxes[7].Text; editRow.STARRING = textboxes[8].Text; editRow.IMAGE = textboxes[9].Text; editRow.TRAILER = textboxes[10].Text; editRow.SYNOPSIS = textboxes[11].Text; } } else if (active_table == 2) //PROGRAM { //PROGRAM editRow; using (var C_Entities = new CinemaEntities()) { short primary_key = short.Parse(row_to_edit[0].Value.ToString()); editRow = C_Entities.PROGRAM.Where(program => program.ID_PROGRAM == primary_key).First(); } if (editRow != null) { editRow.DATE = datetimepickers[0].Value; editRow.TIME = TimeSpan.Parse(datetimepickers[1].Text); editRow.ID_HALL = comboboxes[0].Text; editRow.ID_MOVIE = comboboxes[1].Text; editRow.C2D_3D = comboboxes[2].Text; editRow.VERSION = comboboxes[3].Text; if (check_if_date_available(datetimepickers[0].Value, TimeSpan.Parse(datetimepickers[1].Text)) == false) { MessageBox.Show("Podany termin jest zajęty!", "Error#10"); return(false); } } } else if (active_table == 4) //SEATS { //SEATS editRow; using (var C_Entities = new CinemaEntities()) { string primary_key = row_to_edit[0].Value.ToString(); editRow = C_Entities.SEATS.Where(seats => seats.ID_SEAT == primary_key).First(); } if (editRow != null) { editRow.ID_HALL = comboboxes[0].Text; editRow.VIP = bool.Parse(textboxes[2].Text); } } else if (active_table == 5) //USERS { //USERS editRow; using (var C_Entities = new CinemaEntities()) { string primary_key = row_to_edit[0].Value.ToString(); editRow = C_Entities.USERS.Where(users => users.USER_LOGIN == primary_key).First(); } if (editRow != null) { if (pass_textbox_user.Text != "") { editRow.PASSWORD = pass_textbox_user.Text; } editRow.PASSWORD = pass_textbox_user.Text; pass_textbox_user.Text = ""; editRow.NAME = textboxes[2].Text; editRow.SURNAME = textboxes[3].Text; editRow.E_MAIL = textboxes[4].Text; editRow.TELEPHONE = textboxes[5].Text; } } else if (active_table == 6) //TICKETS { //TICKETS editRow; using (var C_Entities = new CinemaEntities()) { byte primary_key = byte.Parse(row_to_edit[0].Value.ToString()); editRow = C_Entities.TICKETS.Where(ticket => ticket.ID_TICKET == primary_key).First(); } if (editRow != null) { editRow.TYPE = textboxes[1].Text; editRow.PRICE_2D = decimal.Parse(textboxes[2].Text); editRow.PRICE_3D = decimal.Parse(textboxes[3].Text); } } else if (active_table == 8) //RES_DETAILS { //RESERVATIONS_DETAILS editRow; using (var C_Entities = new CinemaEntities()) { //short primary_key_1 = short.Parse(textboxes[0].Text); short primary_key_1 = short.Parse(row_to_edit[0].Value.ToString()); string primary_key_2 = row_to_edit[1].Value.ToString(); editRow = C_Entities.RESERVATIONS_DETAILS.Where( res_details => res_details.ID_RESERVATION == primary_key_1 && res_details.ID_SEAT == primary_key_2).First(); // MessageBox.Show(primary_key_1.ToString() + " " + primary_key_2); } if (editRow != null) { editRow.ID_TICKET = byte.Parse(textboxes[2].Text); } } else if (active_table == 9) //ADMINS { //ADMINS editRow; using (var C_Entities = new CinemaEntities()) { string primary_key = row_to_edit[0].Value.ToString(); editRow = C_Entities.ADMINS.Where(admin => admin.ADMIN_LOGIN == primary_key).First(); } if (editRow != null) { if (pass_textbox_user.Text != "") { editRow.PASSWORD = pass_textbox_user.Text; } editRow.PASSWORD = pass_textbox_user.Text; pass_textbox_user.Text = ""; editRow.NAME = textboxes[2].Text; editRow.SURNAME = textboxes[3].Text; editRow.E_MAIL = textboxes[4].Text; editRow.TELEPHONE = textboxes[5].Text; } } else { MessageBox.Show("Wystąpił błąd aplikacji", "Error#4"); return(false); } try { using (var C_Entities = new CinemaEntities()) { C_Entities.Entry(editRow).State = System.Data.Entity.EntityState.Modified; C_Entities.SaveChanges(); } } catch (DbUpdateConcurrencyException) { MessageBox.Show("Wystąpił błąd podczas aktualizowania danych!", "Error#5"); return(false); } this.DialogResult = DialogResult.OK; return(true); }
public bool insert_row() { using (var C_Entities = new CinemaEntities()) { if (active_table == 1) //MOVIES { var newRow = new MOVIES(); newRow.ID_MOVIE = textboxes[0].Text; newRow.TITLE = textboxes[1].Text; newRow.GENRE = textboxes[2].Text; newRow.RUNTIME = TimeSpan.Parse(datetimepickers[0].Text); newRow.RATING = byte.Parse(comboboxes[0].Text); newRow.RELEASE_DATE = datetimepickers[1].Value; newRow.DIRECTION = textboxes[6].Text; newRow.SCREENPLAY = textboxes[7].Text; newRow.STARRING = textboxes[8].Text; newRow.IMAGE = textboxes[9].Text; newRow.TRAILER = textboxes[10].Text; newRow.SYNOPSIS = textboxes[11].Text; C_Entities.MOVIES.Add(newRow); } else if (active_table == 2) //PROGRAM { var newRow = new PROGRAM(); newRow.DATE = datetimepickers[0].Value; newRow.TIME = TimeSpan.Parse(datetimepickers[1].Text); newRow.ID_HALL = comboboxes[0].Text; newRow.ID_MOVIE = comboboxes[1].Text; newRow.C2D_3D = comboboxes[2].Text; newRow.VERSION = comboboxes[3].Text; if (check_if_date_available() == false) { MessageBox.Show("Podany termin jest zajęty!", "Error#10"); return(false); } C_Entities.PROGRAM.Add(newRow); } else if (active_table == 4) //SEATS { var newRow = new SEATS(); newRow.ID_SEAT = textboxes[0].Text; newRow.ID_HALL = comboboxes[0].Text; newRow.VIP = bool.Parse(textboxes[2].Text); C_Entities.SEATS.Add(newRow); } else if (active_table == 6) //TICKETS { var newRow = new TICKETS(); newRow.TYPE = textboxes[1].Text; newRow.PRICE_2D = decimal.Parse(textboxes[2].Text); newRow.PRICE_3D = decimal.Parse(textboxes[3].Text); C_Entities.TICKETS.Add(newRow); } else if (active_table == 9) //ADMINS { var newRow = new ADMINS(); newRow.ADMIN_LOGIN = textboxes[0].Text; newRow.PASSWORD = textboxes[1].Text; newRow.NAME = textboxes[2].Text; newRow.SURNAME = textboxes[3].Text; newRow.E_MAIL = textboxes[4].Text; newRow.TELEPHONE = textboxes[5].Text; C_Entities.ADMINS.Add(newRow); } else { MessageBox.Show("Wystąpił błąd aplikacji", "Error#7"); return(false); } try { C_Entities.SaveChanges(); } catch (DbUpdateConcurrencyException) { MessageBox.Show("Wystąpił błąd podczas dodawania danych!", "Error#6"); return(false); } } this.DialogResult = DialogResult.OK; return(true); }
bool check_if_date_available([Optional] DateTime date_a, [Optional] TimeSpan time_a) { TimeSpan time_to_prepare_hall = new TimeSpan(0, 10, 0); TimeSpan twenty_four_hours = new TimeSpan(24, 0, 0); DateTime DATE = datetimepickers[0].Value; DateTime DATE_next = DATE.AddDays(1); DateTime DATE_prev = DATE.AddDays(-1); TimeSpan TIME = TimeSpan.Parse(datetimepickers[1].Text); string ID_HALL = comboboxes[0].Text; string MOVIE = comboboxes[1].Text; using (var C_Entities = new CinemaEntities()) { TimeSpan runtime = C_Entities.MOVIES.Where(movie => movie.ID_MOVIE == MOVIE).First().RUNTIME; //czas trwania dodawanego filmu var program = (from pr in C_Entities.PROGRAM join movie in C_Entities.MOVIES on pr.ID_MOVIE equals movie.ID_MOVIE select new { DATE = pr.DATE, TIME = pr.TIME, ID_HALL = pr.ID_HALL, RUNTIME = movie.RUNTIME }).ToList(); foreach (var item in program) { if (item.ID_HALL.Equals(ID_HALL)) { if (item.DATE.Equals(DATE)) { if (TIME <= item.TIME + (item.RUNTIME + time_to_prepare_hall) && item.TIME <= TIME + (runtime + time_to_prepare_hall)) { if (item.DATE != date_a && item.TIME != time_a) { return(false); } } } else if (item.DATE.Equals(DATE_next)) { if (TIME - twenty_four_hours <= item.TIME + (item.RUNTIME + time_to_prepare_hall) && item.TIME <= TIME + (runtime + time_to_prepare_hall) - twenty_four_hours) { return(false); } } else if (item.DATE.Equals(DATE_prev)) { if (TIME + twenty_four_hours <= item.TIME + (item.RUNTIME + time_to_prepare_hall) && item.TIME <= TIME + (runtime + time_to_prepare_hall) + twenty_four_hours) { return(false); } } } } } return(true); }