示例#1
0
        private async void dgvShows_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                var      showId   = dgvShows.Rows[e.RowIndex].Cells["ShowId"].Value;
                var      action   = dgvShows.Columns[e.ColumnIndex].Name;
                MenuForm menuForm = (MenuForm)this.MdiParent;
                var      show     = await _apiService.GetById <Model.Show>(showId);

                CustomMessageBox messageBox = new CustomMessageBox();

                if (action == "Edit" || action == "Title")
                {
                    AddEditShowForm form = new AddEditShowForm(menuForm, int.Parse(showId.ToString()))
                    {
                        MdiParent = menuForm,
                        Dock      = DockStyle.Fill
                    };
                    form.Show();
                }
                else if (action == "Delete")
                {
                    DialogResult dialogResult = MessageBox.Show($"Are you sure you want to permanently delete '{show.Title}'?", "Delete show?", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        await _apiService.Delete <Model.Show>(showId);

                        foreach (Form frm in menuForm.MdiChildren)
                        {
                            frm.Close();
                        }
                        ShowsForm form = new ShowsForm {
                            MdiParent = menuForm,
                            Dock      = DockStyle.Fill
                        };
                        form.Show();
                        messageBox.Show("Show deleted successfully", "success");
                    }
                }
                else
                {
                    return;
                }
            }
        }
示例#2
0
        private async void SaveBtn_Click(object sender, EventArgs e)
        {
            var messageBox = new CustomMessageBox();

            if (string.IsNullOrWhiteSpace(ShowTitle.Text) || ShowTitle.Text.Length < 4)
            {
                messageBox.Show("The title field requires 4 letters!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Description.Text) || Description.Text.Length < 5)
            {
                messageBox.Show("The description field requires 5 letters!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Cast.Text) || Cast.Text.Length < 15)
            {
                messageBox.Show("The cast field requires 15 letters!", "error");
                return;
            }
            if (string.IsNullOrWhiteSpace(ImageLink.Text) || !ImageLink.Text.Contains(".jpg"))
            {
                messageBox.Show("Enter a valid '.jpg' image link!", "error");
                return;
            }
            if (string.IsNullOrWhiteSpace(TrailerLink.Text))
            {
                messageBox.Show("Enter a trailer id", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Rating.Text) || !decimal.TryParse(Rating.Text, out decimal n))
            {
                messageBox.Show("Enter a valid rating (0-10)!", "error");
                return;
            }
            decimal rating = decimal.Parse(Rating.Text);

            if (rating < 0 || rating > 10)
            {
                messageBox.Show("Enter a valid rating (0-10)!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Price.Text) || !decimal.TryParse(Price.Text, out decimal m))
            {
                messageBox.Show("Enter a valid price (1-200)!", "error");
                return;
            }
            decimal price = decimal.Parse(Price.Text);

            if (price < 1 || price > 200)
            {
                messageBox.Show("Enter a valid price (1-200)!", "error");
                return;
            }
            if (Year.Value < Year.Minimum || Year.Value > Year.Maximum)
            {
                messageBox.Show("Enter a valid year (1800-2025)!", "error");
                return;
            }

            if (Seasons.Value < 1 || Seasons.Value > 100)
            {
                messageBox.Show("Enter a valid seasons number (1-100)!", "error");
                return;
            }

            if (string.IsNullOrWhiteSpace(Genre.Text) || Genre.Text.Length < 4)
            {
                messageBox.Show("The genre field requires 4 letters!", "error");
                return;
            }

            Model.Requests.InsertShowRequest request = new Model.Requests.InsertShowRequest()
            {
                Title           = ShowTitle.Text,
                Year            = (int)Year.Value,
                NumberOfSeasons = (int)Seasons.Value,
                Rating          = decimal.Parse(Rating.Text),
                Description     = Description.Text,
                Cast            = Cast.Text,
                ImageLink       = ImageLink.Text,
                Ongoing         = Ongoing.Checked,
                Price           = decimal.Parse(Price.Text),
                TrailerLink     = $"https://www.youtube.com/embed/{TrailerLink.Text}",
                Genre           = Genre.Text
            };

            if (_showId.HasValue)
            {
                await _apiService.Update <Model.Show>(_showId, request);
            }
            else
            {
                await _apiService.Insert <Model.Show>(request);
            }

            this.Close();
            foreach (Form frm in _menuForm.MdiChildren)
            {
                frm.Close();
            }
            ShowsForm form = new ShowsForm {
                MdiParent = _menuForm,
                Dock      = DockStyle.Fill
            };

            form.Show();
            if (_showId.HasValue)
            {
                messageBox.Show("Show updated successfully!", "success");
            }
            else
            {
                messageBox.Show("Show added successfully!", "success");
            }
        }