Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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);
        }