Exemple #1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string[] text = addText.Text.Split(' ');
            string[] FIO  = new string[3];

            for (int i = 0; i < text.Length; ++i)
            {
                FIO[i] = text[i];
            }

            switch (table)
            {
            case Tables.Genre:
                Genre genre = new Genre()
                {
                    Name = addText.Text
                };
                db.Genres.Add(genre);
                break;

            case Tables.Country:
                Country country = new Country()
                {
                    CountryName = addText.Text
                };
                db.Countrys.Add(country);
                break;

            case Tables.Actor:
                Actor actor = new Actor()
                {
                    FirstName  = FIO[1],
                    LastName   = FIO[2],
                    SecondName = FIO[3]
                };
                db.Actors.Add(actor);
                break;

            case Tables.Producer:
                Producer producer = new Producer()
                {
                    FirstName  = FIO[1],
                    LastName   = FIO[2],
                    SecondName = FIO[3]
                };
                db.Producers.Add(producer);
                break;

            default:
                break;
            }
            db.SaveChanges();
        }
Exemple #2
0
        public void AddDisk(string name, string format, int copy, int cost)
        {
            using (Contex db = new Contex())
            {
                Disk disk = new Disk
                {
                    Name   = name,
                    cost   = cost,
                    format = format,
                    copy   = copy,
                };
                //diskGl = disk;
                db.Disks.Add(disk);
                db.SaveChanges();

                /*using (Contex My = new Contex())
                 * {*/
                for (int i = 0; i < ArrayMoviesDisk.movies.Count; i++)
                {
                    //var movie = ArrayMoviesDisk.movies[i];
                    int movieId = Convert.ToInt32(ArrayMoviesDisk.arrayList[i]);
                    //int movieId = movie.Id;
                    //Movie movie2 = My.Movies.Include(s => s.).First
                    //MessageBox.Show(movie2.Name);
                    Movie movie2 = db.Movies.First(s => s.Id == movieId);
                    //Movie movie = My.Movies.Where(k => k.Id == movieId).FirstOrDefault();
                    //Movie movie1 = movie;
                    int       diskId    = disk.Id;
                    MovieDisk movieDisk = new MovieDisk
                    {
                        MovieId = movieId,
                        DiskId  = diskId,
                    };
                    db.MovieDisks.Add(movieDisk);
                }
                db.SaveChanges();
                //}
            }
        }
Exemple #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataAll.SelectedRows.Count == 0)
            {
                return;
            }
            Form1        from1  = new Form1();
            DialogResult result = MessageBox.Show(
                "Вы уверены в этом?",
                "Сообщение",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Information,
                MessageBoxDefaultButton.Button1,
                MessageBoxOptions.ServiceNotification
                );

            from1.MaximizeBox = true;
            switch (table)
            {
            case Tables.Movie:
                if (result == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataAll.SelectedRows)
                    {
                        Movie movie = row.DataBoundItem as Movie;
                        if (movie == null)
                        {
                            continue;
                        }
                        Movie dbMovie = My.Movies.Find(movie.Id);
                        My.Movies.Remove(dbMovie);
                    }
                    My.SaveChanges();
                    UpdateTable();
                }
                break;

            case Tables.Client:
                if (result == DialogResult.Yes)
                {
                    LogicClient LogCl    = new LogicClient();
                    int         idClient = Convert.ToInt32(dataAll[0, dataAll.CurrentCell.RowIndex].Value);
                    int         idPassCL = Convert.ToInt32(dataAll[9, dataAll.CurrentCell.RowIndex].Value);
                    LogCl.RemoveClient(idClient, idPassCL);
                    UpdateTable();

                    //ObjectContext objectContext = (new Contex() as IObjectContextAdapter).ObjectContext;
                    //SqlConnection connection = new SqlConnection(@"Data source=.\SQLEXPRESS;InitialCatalog=Kinosoft4");
                    //ObjectQuery<DbDataRecord> disk = objectContext.CreateQuery<DbDataRecord>("SELECT * FROM Client, Passport");
                    //dataAll.DataSource = disk.ToList();
                }
                break;

            case Tables.Disk:
                if (result == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataAll.SelectedRows)
                    {
                        Disk disk = row.DataBoundItem as Disk;
                        if (disk == null)
                        {
                            continue;
                        }
                        Disk dbDisk = My.Disks.Find(disk.Id);
                        My.Disks.Remove(dbDisk);
                    }
                    My.SaveChanges();
                    UpdateTable();
                }
                break;

            case Tables.Employee:
                LogicEmployees logEmp     = new LogicEmployees();
                int            idEmployee = Convert.ToInt16(dataAll[0, dataAll.CurrentCell.RowIndex].Value);
                int            idPassEmp  = Convert.ToInt16(dataAll[8, dataAll.CurrentCell.RowIndex].Value);
                logEmp.RemoveEmployee(idEmployee, idPassEmp);
                UpdateTable();

                //if (result == DialogResult.Yes)
                //{
                //    foreach (DataGridViewRow row in dataAll.SelectedRows)
                //    {
                //        Employee employee = new Employee();
                //        if (employee == null)
                //            continue;
                //        Employee dbEmployee = My.Employees.Find(employee.Id);
                //        My.Employees.Remove(dbEmployee);
                //    }
                //    My.SaveChanges();
                //    UpdateTable();
                //}
                break;

            case Tables.Order:
                if (result == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in dataAll.SelectedRows)
                    {
                        Order order = row.DataBoundItem as Order;
                        if (order == null)
                        {
                            continue;
                        }
                        Order dborder = My.Orders.Find(order.Id);
                        My.Orders.Remove(dborder);
                    }
                    My.SaveChanges();
                    UpdateTable();
                }
                break;

            default:
                break;
            }
        }