Exemple #1
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            IList <Student> students      = new List <Student>();
            var             location      = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var             directoryName = Path.GetDirectoryName(location);

            if (File.Exists(directoryName + FilePath))
            {
                using (StreamReader studentsReader = new StreamReader(directoryName + FilePath, Encoding.GetEncoding("UTF-8")))
                {
                    string line;
                    if (SkipFirstLineDocument)
                    {
                        line = studentsReader.ReadLine();
                    }

                    line = studentsReader.ReadLine();
                    while (line != null)
                    {
                        var data = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        try
                        {
                            students.Add(new Student(
                                             int.Parse(data[0]),
                                             data[1],
                                             data[2],
                                             data[3],
                                             (Genders)Enum.Parse(typeof(Genders), data[4], true),
                                             (StudentTypes)Enum.Parse(typeof(StudentTypes), data[5], true),
                                             int.Parse(data[6]),
                                             int.Parse(data[7]),
                                             int.Parse(data[8]),
                                             float.Parse(data[9]),
                                             float.Parse(data[10]),
                                             float.Parse(data[1])));
                        }
                        catch (SystemException se)
                        {
                            if (se is FormatException || se is ArgumentNullException || se is IndexOutOfRangeException)
                            {
                                Console.WriteLine("Incorrect file data.");
                                return;
                            }

                            throw;
                        }

                        line = studentsReader.ReadLine();
                    }
                }

                var onlineStudentsChart = from s in students
                                          where s.StudentType == StudentTypes.Online
                                          orderby s.Result descending
                                          select s;

                string[] headerItems = new string[]
                {
                    "ID",
                    "First name",
                    "Last Name",
                    "Email",
                    "Gender",
                    "Student type",
                    "Exam result",
                    "Homework sent",
                    "Homework evaluated",
                    "Teamwork",
                    "Attendances",
                    "Bonus",
                    "Result"
                };

                var excel = new ExcelGenerator(
                    directoryName + "\\students.xlsx",
                    "Online students",
                    headerItems,
                    onlineStudentsChart.ToList());
                excel.Generate();
                Console.WriteLine("Done");
            }
            else
            {
                Console.WriteLine("The file is not foud -" + (directoryName + FilePath));
            }
        }
Exemple #2
0
      public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;

            IList<Student> students = new List<Student>();
            var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var directoryName = Path.GetDirectoryName(location);

            if (File.Exists(directoryName + FilePath))
            {
                using (StreamReader studentsReader = new StreamReader(directoryName + FilePath, Encoding.GetEncoding("UTF-8")))
                {
                    string line;
                    if (SkipFirstLineDocument)
                    {
                        line = studentsReader.ReadLine();
                    }

                    line = studentsReader.ReadLine();
                    while (line != null)
                    {
                        var data = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        try
                        {
                            students.Add(new Student(
                                int.Parse(data[0]),
                                data[1],
                                data[2],
                                data[3],
                                (Genders)Enum.Parse(typeof(Genders), data[4], true),
                                (StudentTypes)Enum.Parse(typeof(StudentTypes), data[5], true),
                                int.Parse(data[6]),
                                int.Parse(data[7]),
                                int.Parse(data[8]),
                                float.Parse(data[9]),
                                float.Parse(data[10]),
                                float.Parse(data[1])));
                        }
                        catch (SystemException se)
                        {
                            if (se is FormatException || se is ArgumentNullException || se is IndexOutOfRangeException)
                            {
                                Console.WriteLine("Incorrect file data.");
                                return;
                            }

                            throw;
                        }

                        line = studentsReader.ReadLine();
                    }
                }

                var onlineStudentsChart = from s in students
                                          where s.StudentType == StudentTypes.Online
                                          orderby s.Result descending
                                          select s;

                string[] headerItems = new string[] 
            { 
                "ID", 
                "First name", 
                "Last Name", 
                "Email", 
                "Gender", 
                "Student type", 
                "Exam result",
                "Homework sent", 
                "Homework evaluated",
                "Teamwork", 
                "Attendances", 
                "Bonus", 
                "Result"
            };

               var excel = new ExcelGenerator(
                        directoryName + "\\students.xlsx",
                        "Online students",
                        headerItems,
                        onlineStudentsChart.ToList());
                excel.Generate();
                Console.WriteLine("Done");
            }
            else
            {
                Console.WriteLine("The file is not foud -" + (directoryName + FilePath));
            }
        }
Exemple #3
0
        public static void Main()
        {
            string filename = @"../../data/Students-data.txt";
            IList<Student> students = new List<Student>();

            if (File.Exists(filename))
            {
                using (StreamReader stReader = new StreamReader(filename, Encoding.GetEncoding("UTF-8")))
                {
                    string line = stReader.ReadLine();
                    line = stReader.ReadLine();
                    while (line != null)
                    {
                        var data = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        students.Add(new Student(
                            int.Parse(data[0]),
                            data[1],
                            data[2],
                            data[3],
                            (Genders)Enum.Parse(typeof(Genders), data[4], true),
                            (StudentTypes)Enum.Parse(typeof(StudentTypes), data[5], true),
                            int.Parse(data[6]),
                            int.Parse(data[7]),
                            int.Parse(data[8]),
                            float.Parse(data[9]),
                            float.Parse(data[10]),
                            float.Parse(data[11])));

                        line = stReader.ReadLine();
                    }
                }
            }

            var onlineStudentsChart = from st in students
                                      where st.StudentType == StudentTypes.Online
                                      orderby st.Result descending
                                      select st;

            foreach (var student in onlineStudentsChart)
            {
                Console.WriteLine(student.ToString());
            }

            // Excel file generation
            string[] headerItems = new string[] 
            { 
                "ID", 
                "First name", 
                "Last Name", 
                "Email", 
                "Gender", 
                "Student type", 
                "Exam result",
                "Homework sent", 
                "Homework evaluated",
                "Teamwork", 
                "Attendances", 
                "Bonus", 
                "Result"
            };

            ExcelGenerator<Student> excelGenerator = new ExcelGenerator<Student>(
                @"../../students.xls",
                "Online students",
                headerItems,
                onlineStudentsChart.ToList());

            excelGenerator.GenerateFromCollection(new string[] { ", " });
        }
Exemple #4
0
        public static void Main()
        {
            string          filename = @"../../data/Students-data.txt";
            IList <Student> students = new List <Student>();

            if (File.Exists(filename))
            {
                using (StreamReader stReader = new StreamReader(filename, Encoding.GetEncoding("UTF-8")))
                {
                    string line = stReader.ReadLine();
                    line = stReader.ReadLine();
                    while (line != null)
                    {
                        var data = line.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                        students.Add(new Student(
                                         int.Parse(data[0]),
                                         data[1],
                                         data[2],
                                         data[3],
                                         (Genders)Enum.Parse(typeof(Genders), data[4], true),
                                         (StudentTypes)Enum.Parse(typeof(StudentTypes), data[5], true),
                                         int.Parse(data[6]),
                                         int.Parse(data[7]),
                                         int.Parse(data[8]),
                                         float.Parse(data[9]),
                                         float.Parse(data[10]),
                                         float.Parse(data[11])));

                        line = stReader.ReadLine();
                    }
                }
            }

            var onlineStudentsChart = from st in students
                                      where st.StudentType == StudentTypes.Online
                                      orderby st.Result descending
                                      select st;

            foreach (var student in onlineStudentsChart)
            {
                Console.WriteLine(student.ToString());
            }

            // Excel file generation
            string[] headerItems = new string[]
            {
                "ID",
                "First name",
                "Last Name",
                "Email",
                "Gender",
                "Student type",
                "Exam result",
                "Homework sent",
                "Homework evaluated",
                "Teamwork",
                "Attendances",
                "Bonus",
                "Result"
            };

            ExcelGenerator <Student> excelGenerator = new ExcelGenerator <Student>(
                @"../../students.xls",
                "Online students",
                headerItems,
                onlineStudentsChart.ToList());

            excelGenerator.GenerateFromCollection(new string[] { ", " });
        }