Exemple #1
0
        /// <summary>
        /// Event handler for the 'Compute' button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uxCompute_Click(object sender, EventArgs e)
        {
            LinkedListCell <KeyValuePair <double, string> > copy = _elements;
            double sum = 0;

            while (copy != null)
            {
                if (copy.Data.Value.Contains("KB"))
                {
                    sum += ConvertKilobytes(copy.Data.Key);
                }

                else if (copy.Data.Value.Contains("GB"))
                {
                    sum += ConvertGigabytes(copy.Data.Key);
                }

                else
                {
                    sum += copy.Data.Key;
                }
                copy = copy.Next;
            }
            uxNumMB.Text = sum.ToString();
        }
Exemple #2
0
        /// <summary>
        /// Reads in a text file and stores the data from each
        /// line into a linked list
        /// </summary>
        /// <param name="fn">The name of the file</param>
        private void ReadFile(string fn)
        {
            using (StreamReader sr = new StreamReader(fn))
            {
                while (!sr.EndOfStream)
                {
                    try
                    {
                        string[] parts = sr.ReadLine().Split(' ');

                        double num = Convert.ToDouble(parts[0]);
                        LinkedListCell <KeyValuePair <double, string> > cell = new LinkedListCell <KeyValuePair <double, string> >();

                        cell.Data = new KeyValuePair <double, string>(num, parts[1]);
                        cell.Next = _elements;

                        _elements = cell;
                    }

                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
        }