Пример #1
0
        /// <summary>
        /// Appends the table, built from data contained in the list and preceded by the header,
        /// to the end of the text file.
        /// THE STUDENT SHOULD IMPLEMENT THIS METHOD ACCORDING THE TASK.
        /// </summary>
        /// <param name="fileName">The name of the text file</param>
        /// <param name="header">The header of the table</param>
        /// <param name="list">The list from which the table to be formed</param>
        public static void PrintToFile(string fileName, string header, LinkList <Operation> list)
        {
            if (!File.Exists(fileName))
            {
                File.Create(fileName).Close();
            }

            list.Begin();

            if (list.Exist())
            {
                using (var writer = new StreamWriter(fileName, true)) // True means Append text to file
                {
                    writer.AutoFlush = true;
                    writer.WriteLine(new string('-', 73));
                    writer.WriteLine(string.Format("| {0,-69} |", header));
                    writer.WriteLine(new string('-', 73));
                    writer.WriteLine(string.Format("| {0,5} | {1,-30} | {2,-10} | {3, 6} | {4, 6} |", "Diena", "Vardas Pavarde", "Kodas", "Kiekis", "Kaina"));
                    writer.WriteLine(new string('-', 73));

                    for (list.Begin(); list.Exist(); list.Next())
                    {
                        Operation operation = list.Get();

                        writer.WriteLine(string.Format("| {0,5} | {1,-30} | {2,-10} | {3, 6} | {4, 6} |", operation.Day, operation.FullName, operation.Code, operation.Amount, operation.Cost));
                    }

                    writer.WriteLine(new string('-', 73));
                    writer.Dispose();
                    writer.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Finds the smallest quantity value in the list.
        /// THE STUDENT SHOULD IMPLEMENT THIS METHOD ACCORDING THE TASK.
        /// </summary>
        /// <param name="list">The data for the calculation.</param>
        /// <returns>The smallest quantity value.</returns>
        public static int MinQuantity(LinkList <Operation> list)
        {
            int min = 99999;

            for (list.Begin(); list.Exist(); list.Next())
            {
                Operation temp = list.Get();

                if (temp.Amount < min)
                {
                    min = temp.Amount;
                }
            }

            return(min);
        }