Beispiel #1
0
        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);
        }
Beispiel #2
0
        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();
                    }
                }
            }
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        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);
        }