Exemplo n.º 1
0
        //
        //Редактирование картин
        //
        private void bEditPic_Click(object sender, EventArgs e)
        {
            int id = IdConverter(dGVPicturesList);

            if (id > 0)
            {
                Pictures    pictures = db.Pictures.Find(id);
                FormPicture editForm = new FormPicture(pictures);

                List <Authors> authors = db.Authors.ToList();
                editForm.cbAuthor.DataSource    = authors;
                editForm.cbAuthor.ValueMember   = "AuthorId";
                editForm.cbAuthor.DisplayMember = "Name";
                editForm.cbAuthor.SelectedItem  = editForm.picture.Authors;

                List <Genres> genres = db.Genres.ToList();
                editForm.cbGenre.DataSource    = genres;
                editForm.cbGenre.ValueMember   = "GenreId";
                editForm.cbGenre.DisplayMember = "Name";
                editForm.cbGenre.SelectedItem  = editForm.picture.PictureGenre;

                db.Statuses.Load();
                var fibNumbers = db.Statuses.Local.ToList();
                foreach (Statuses rrr in fibNumbers)
                {
                    editForm.cbStatus.Items.Add(rrr.Status);
                }

                editForm.cbStatus.SelectedItem = editForm.picture.Status.ToString();

                DialogResult result = editForm.ShowDialog(this);

                switch (result)
                {
                case DialogResult.Cancel:
                    return;

                case DialogResult.Abort:
                    dbDelete.PictureDel(editForm.picture, db);
                    dGVPicturesList.Refresh();
                    break;

                case DialogResult.OK:
                    editForm.picture.Status = db.Statuses.Find(editForm.cbStatus.SelectedItem.ToString());
                    dbEdit.PicturesEdit(pictures, editForm.picture, db);
                    dGVPicturesList.Refresh();
                    break;

                default:
                    Console.WriteLine("Ой-ой");
                    break;
                }
            }
        }
Exemplo n.º 2
0
        //
        //Добавление картин
        //
        private void bAddPic_Click(object sender, EventArgs e)
        {
            FormPicture addForm = new FormPicture(null);

            List <Authors> authors = db.Authors.ToList();

            addForm.cbAuthor.DataSource    = authors;
            addForm.cbAuthor.ValueMember   = "AuthorId";
            addForm.cbAuthor.DisplayMember = "Name";

            List <Genres> genres = db.Genres.ToList();

            addForm.cbGenre.DataSource    = genres;
            addForm.cbGenre.ValueMember   = "GenreId";
            addForm.cbGenre.DisplayMember = "Name";

            db.Statuses.Load();
            var fibNumbers = db.Statuses.Local.ToList();

            foreach (Statuses rrr in fibNumbers)
            {
                addForm.cbStatus.Items.Add(rrr.Status);
            }

            DialogResult result = addForm.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            addForm.picture.Status = db.Statuses.Find(addForm.cbStatus.SelectedItem.ToString());
            if (dbAdd.PictureAdd(addForm.picture, db))
            {
                MessageBox.Show("Новый объект добавлен");
            }
            else
            {
                MessageBox.Show("Ай-ай");
            }
        }