Пример #1
0
        /// <summary>
        /// Adds the Subtitle's selection of the user in the treeview and save them as a tree data structure.
        /// Checks if the subtitle exists, if it is accurate and if the subtitle file has been used before. 
        /// It notifies the user for 'all' errors.
        /// It allows the user to re-upload a subtitle file with different subtitle properties.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSubtitle_Click(object sender, RoutedEventArgs e)
        {
            // used in the check of duplicate subtitle triplet of properties.
            bool toAdd = false;

            // get the user's selection
            dataCodec = CodecCB.Text;
            TreeNode t0 = new TreeNode() { controlType = DCodecLabel.Content.ToString(), controlValue = dataCodec };

            // Gets the data from the subtitle panel
            dataSubCodec = string.IsNullOrWhiteSpace(subCodecCB.Text) ? "0" : subCodecCB.Text;
            dataSubCharEncoding = string.IsNullOrWhiteSpace(subtitleCharacterEncoding.Text) ? "0" : subtitleCharacterEncoding.Text;
            dataSubLanguage = string.IsNullOrWhiteSpace(SubtitleLanguage.Text) ? "0" : SubtitleLanguage.Text;

            // check that the user's selection is valid
            if (dataSubCodec == "0" || dataSubCharEncoding == "0" || dataSubLanguage == "0")
            {
                System.Windows.MessageBox.Show("Please Choose a Subtitle Codec, Encoding and Language to Proceed.", "Information Needed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                TreeNode t1 = new TreeNode() { controlType = subCLabel.Content.ToString(), controlValue = dataSubCodec };
                TreeNode t2 = new TreeNode() { controlType = subCELabel.Content.ToString(), controlValue = dataSubCharEncoding };
                TreeNode t3 = new TreeNode() { controlType = subLLabel.Content.ToString(), controlValue = dataSubLanguage };
                TreeNode t4 = new TreeNode() { controlType = "Subtitle File", controlValue = subFilename, fullFileLocation = subpath };

                // check if the nodes already exist
                for (int i=0; i<tree.Count(); i++)
                {
                    if ((tree[i].Nodes.Count) != 0)
                    {
                        for (int j = 0; j < (tree[i].Nodes.Count); j = j + 3)
                        {
                            if (tree[i].Nodes[j].controlValue == dataSubCodec && tree[i].Nodes[j + 1].controlValue == dataSubCharEncoding && tree[i].Nodes[j + 2].controlValue == dataSubLanguage)
                            {
                                toAdd = false;
                                break;
                            }
                            else
                            {
                                toAdd = true;
                            }
                        }
                    }
                    else
                    {
                        toAdd = true;
                    }
                }
                //if subtitle exists, inform the user and exit without entering any nodes
                if(toAdd == false)
                {
                    System.Windows.MessageBox.Show("The subtitle you chose has already been entered in the subtitle list.", "Already Exists!", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    // if the subtitle file is invalid or unexisted
                    if (subFilename == "0" || string.IsNullOrWhiteSpace(subtitleLocation.Content.ToString()))
                    {
                        System.Windows.MessageBox.Show("Please Choose a Subtitle File to Upload.", "Information Needed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    else
                    {
                        // if the same subtitle file has already been used, ask the user if he wants to proceed anyway
                        if (GUIHelper.findSingleNodeValueOnTree(tree, subFilename) == true)
                        {
                            MessageBoxResult result = System.Windows.MessageBox.Show("The subtitle file you chose has already been entered in the subtitle list. Would you like to Proceed Anyway?", "Proceed Anyway?", MessageBoxButton.YesNo, MessageBoxImage.Question);
                            // if the user wants to proceed anyway then enter the nodes in Tree
                            if (result == MessageBoxResult.Yes)
                            {
                                tmS.Nodes.Add(t1);
                                tmS.Nodes.Add(t2);
                                tmS.Nodes.Add(t3);
                                tmS.Nodes.Add(t4);
                                tmBasic.Nodes.Add(t0);
                            }
                        }
                        else
                        {
                            // if all good => happily enter the nodes in tree
                            tmS.Nodes.Add(t1);
                            tmS.Nodes.Add(t2);
                            tmS.Nodes.Add(t3);
                            tmS.Nodes.Add(t4);
                            tmBasic.Nodes.Add(t0);
                        }
                    }
                }
            }
            // add tree as itemsource to the data profile's treeview
            dataTree.ItemsSource = tree;
        }
Пример #2
0
        /// <summary>
        /// Adds the user's selection of private data in the treeview and save them as a tree data structure.
        /// Check if the same data exists
        /// It notifies the user for 'all' errors.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddPrivateData_Click(object sender, RoutedEventArgs e)
        {
            bool toAdd = true;

            // get the user's selection
            dataCodec = CodecCB.Text;
            TreeNode t0 = new TreeNode() { controlType = DCodecLabel.Content.ToString(), controlValue = dataCodec };

            //gets secondary data - aka bit rate (secondary = not subtitle and not obligatory to add)
            dataBitRate = string.IsNullOrWhiteSpace(bitRate.Text) ? "0" : bitRate.Text.Trim();

            // error messages if the databitrate is not valid or there is no data file
            if (string.IsNullOrWhiteSpace(dataLocation.Content.ToString()) || dataFilename == "0")
            {
                System.Windows.MessageBox.Show("Please Choose a Data File to Upload.", "Information Needed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                toAdd = false;
            }
            else if(dataBitRate == "0")
            {
                System.Windows.MessageBox.Show("Please Enter a Valid Data Bit Rate value.", "Information Needed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                toAdd = false;
            }

            if(toAdd)
            {
                // create the child node
                TreeNode t1 = new TreeNode() { controlType = DBitLabel.Content.ToString(), controlValue = dataBitRate };
                TreeNode t2 = new TreeNode() { controlType = "Data File ", controlValue = dataFilename, fullFileLocation = path };

                // check that the bit rate node does not already exists
                // TODO: Why does this return true?
                if (GUIHelper.findSingleNodeValueOnTree(tree, dataFilename) == false && GUIHelper.findSingleNodeValueOnTree(tree, dataBitRate) == false)
                {
                    tmBasic.Nodes.Add(t0);
                    tmSec.Nodes.Add(t1);
                    tmSec.Nodes.Add(t2);
                }
                else
                {
                    System.Windows.MessageBox.Show("Duplicate Value. You have already entered the specified bit rate.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            Console.WriteLine("tmBasic has " + tmBasic.Nodes.Count + " Node count from the method itself.");
            dataTree.ItemsSource = tree;
        }