Ejemplo n.º 1
0
        private void btnFind_Click(object sender, RoutedEventArgs e)
        {
            entertainment = EntertainmentUtil.FindEntertainmentBy(txtUpdateEtName.Text);
            if (entertainment != null)
            {
                lblResult.Foreground = Brushes.Green;
                lblResult.Content    = $"Found '{entertainment.EnterName}'.";

                txtUpdateEtName.Text         = entertainment.EnterName;
                txtLink.Text                 = entertainment.Links;
                txtAuthorEnter.Text          = entertainment.AuthorEnter;
                cbbListEtUpdateCategory.Text = entertainment.Category;
                btnUpadte.IsEnabled          = true;
            }
            else
            {
                lblResult.Foreground = Brushes.Red;
                lblResult.Content    = $"Nothing found.";
            }
        }
Ejemplo n.º 2
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            var et = new RememberUtility.Model.Entertainment();

            // txtEtName
            if (txtEtName.Text != "")
            {
                et.EnterName = txtEtName.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "et name cannot be null. Please choose a type";
            }

            // txtLink
            if (txtLink.Text != "")
            {
                et.Links = txtLink.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Links cannot be null. Please choose a type";
            }

            // txtAuthorEnter
            if (txtAuthorEnter.Text != "")
            {
                et.AuthorEnter = txtAuthorEnter.Text.Trim();
            }
            else
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Author Enter cannot be null. Please choose a type";
            }

            if (lstListEtCategory.SelectedIndex == -1)
            {
                AddEtResult.Foreground = Brushes.Red;
                AddEtResult.Content    = "Category aren't choose. Please choose a type";
            }

            if (txtLink.Text != "" && txtEtName.Text != "" && txtAuthorEnter.Text != "" && lstListEtCategory.SelectedIndex >= 0)
            {
                dynamic categoryInList = (lstListEtCategory.SelectedItem);
                string  catchCustom    = categoryInList as string;
                if (catchCustom.ToString() == CategoriesEntertainmentConstant.Custom)
                {
                    if (txtBtnCustomTextBox.Text == "")
                    {
                        AddEtResult.Foreground = Brushes.Red;
                        AddEtResult.Content    = "Category custom is emtpy. Please pick one.";
                        return;
                    }
                    else
                    {
                        et.Category = txtBtnCustomTextBox.Text;
                    }
                }
                else
                {
                    // use dynamic as type to cast your anonymous object to
                    categoryInList = (lstListEtCategory.SelectedItem);

                    // add category here
                    et.Category = categoryInList as string;
                }

                var findet = entertainmentUtil.FindEntertainmentBy(txtEtName.Text);
                if (findet != null)
                {
                    if (et.EnterName.ToLower() != findet.EnterName.ToLower())
                    {
                        entertainmentUtil.AddEntertainment(et);
                        AddEtResult.Foreground = Brushes.Green;

                        if (et.EnterName.Length <= 10)
                        {
                            AddEtResult.Content = $"Add '{et.EnterName}' Successful";
                        }
                        else
                        {
                            AddEtResult.Content = $"Add et Successful";
                        }

                        txtEtName.Text         = string.Empty;
                        txtLink.Text           = string.Empty;
                        txtAuthorEnter.Text    = string.Empty;
                        lstListEtCategory.Text = string.Empty;
                    }
                    else
                    {
                        AddEtResult.Foreground = Brushes.Red;
                        AddEtResult.Content    = $"'{txtEtName.Text}' duplicate. Add failed.";
                    }
                }
                else
                {
                    entertainmentUtil.AddEntertainment(et);
                    AddEtResult.Foreground = Brushes.Green;
                    AddEtResult.Content    = "Add et Successful";

                    txtEtName.Text         = string.Empty;
                    txtLink.Text           = string.Empty;
                    txtAuthorEnter.Text    = string.Empty;
                    lstListEtCategory.Text = string.Empty;
                }
            }
        }
Ejemplo n.º 3
0
        private void btnFind_Click(object sender, RoutedEventArgs e)
        {
            if (txtFind.Text != "")
            {
                var selectedValue = comboxBoxEnterLink.SelectedValue as string;
                if (selectedValue == TypeEntertainmentsConstant.EnterName)
                {
                    var result = entertainmentUtil.FindEntertainmentBy(txtFind.Text);
                    if (result != null)
                    {
                        lblFindResult.Foreground = Brushes.Green;
                        lblFindResult.Content    = $"Found '{txtFind.Text}'";

                        // Send value to EntertainemntMain
                        foreach (Window item in Application.Current.Windows)
                        {
                            if (item is EntertainemntMain)
                            {
                                ((EntertainemntMain)item).GetName(txtFind.Text);
                            }
                        }

                        if (cbxAutoClose.IsChecked.Value) // if true
                        {
                            Close();
                        }
                    }
                    else
                    {
                        lblFindResult.Foreground = Brushes.Red;
                        lblFindResult.Content    = $"Nothing found";
                    }
                }
                else if (selectedValue == TypeEntertainmentsConstant.Link)
                {
                    var result = entertainmentUtil.FindEntertainmentByLink(txtFind.Text);
                    if (result != null)
                    {
                        lblFindResult.Foreground = Brushes.Green;
                        lblFindResult.Content    = $"Found '{txtFind.Text}'";

                        // Send value to EntertainemntMain
                        foreach (Window item in Application.Current.Windows)
                        {
                            if (item is EntertainemntMain)
                            {
                                ((EntertainemntMain)item).GetName(txtFind.Text);
                            }
                        }

                        if (cbxAutoClose.IsChecked.Value) // if true
                        {
                            Close();
                        }
                    }
                    else
                    {
                        lblFindResult.Foreground = Brushes.Red;
                        lblFindResult.Content    = $"Nothing found";
                    }
                }
                else
                {
                    lblFindResult.Foreground = Brushes.Red;
                    lblFindResult.Content    = $"Nothing found";
                }
            }
            else
            {
                lblFindResult.Foreground = Brushes.Red;
                lblFindResult.Content    = $"You must type a Et name";
            }
        }