Пример #1
0
        public void deleteRecoed(string path)
        {
            string id;

            Console.WriteLine("Please Enter id:");
            id = Console.ReadLine();
            string       line;
            StreamReader read = new StreamReader(path);
            List <setterAndGetterMethods> list = new List <setterAndGetterMethods>();

            while ((line = read.ReadLine()) != null)
            {
                setterAndGetterMethods s = new setterAndGetterMethods();
                s.setStudentId(line.Trim());
                line = read.ReadLine();
                s.setStudentName(line.Trim());
                line = read.ReadLine();
                s.setStudentSemester(line.Trim());
                line = read.ReadLine();
                s.setCgpa(line.Trim());
                line = read.ReadLine();
                s.setDepartment(line.Trim());
                line = read.ReadLine();
                s.setUniversity(line.Trim());
                list.Add(s);
            }

            read.Close();
            StreamWriter file1 = new StreamWriter(path);

            file1.AutoFlush = true;
            char ch = '0';

            foreach (var thing in list)
            {
                if (id != thing.getId())
                {
                    file1.Write(thing.getId() + "\t");
                    file1.Write("\r" + thing.getName() + "\t");
                    file1.Write("\r" + thing.getSemester() + "\t");
                    file1.Write("\r" + thing.getCgpa() + "\t");
                    file1.Write("\r" + thing.getDepartment() + "\t");
                    file1.Write("\r" + thing.getUni() + "\t");
                    file1.WriteLine();
                }
                else
                {
                    ch = '1';
                    Console.WriteLine("Record is successfully deleted");
                }
            }
            file1.Close();
            if (ch == '0')
            {
                Console.WriteLine("No Record is found for this id:" + id);
            }
        }
Пример #2
0
        public void Top3Students(string path)
        {
            {
                string trim;
                double first, second, third;
                first = second = third = 0;
                Console.Clear();
                string       line;
                StreamReader read = new StreamReader(path);
                List <setterAndGetterMethods> list = new List <setterAndGetterMethods>();
                while ((line = read.ReadLine()) != null)
                {
                    setterAndGetterMethods stu = new setterAndGetterMethods();

                    stu.setStudentId(line.Trim());
                    line = read.ReadLine();
                    stu.setStudentName(line.Trim());
                    line = read.ReadLine();
                    stu.setStudentSemester(line.Trim());
                    line = read.ReadLine();
                    trim = line.Trim();
                    stu.setCgpa(trim);
                    line = read.ReadLine();
                    stu.setDepartment(line.Trim());
                    line = read.ReadLine();
                    stu.setUniversity(line.Trim());
                    list.Add(stu);
                }
                read.Close();


                setterAndGetterMethods obj = list[0];
                first = double.Parse(obj.getCgpa());
                int count = 0;
                foreach (var stu in list)
                {
                    if (first <= double.Parse(stu.getCgpa()))
                    {
                        first = double.Parse(stu.getCgpa());
                        count++;
                    }
                }
                foreach (var stu in list)
                {
                    if (first > double.Parse(stu.getCgpa()))
                    {
                        if (second < double.Parse(stu.getCgpa()))
                        {
                            second = double.Parse(stu.getCgpa());
                        }
                    }
                }
                foreach (var stu in list)
                {
                    if (first > double.Parse(stu.getCgpa()))
                    {
                        if (second > double.Parse(stu.getCgpa()))
                        {
                            if (third < double.Parse(stu.getCgpa()))
                            {
                                third = double.Parse(stu.getCgpa());
                            }
                        }
                    }
                }


                foreach (var stu in list)
                {
                    if (first == double.Parse(stu.getCgpa()) || second == double.Parse(stu.getCgpa()) || third == double.Parse(stu.getCgpa()))
                    {
                        Console.Write(stu.getId() + "\t");
                        Console.Write(stu.getName() + "\t");
                        Console.Write(stu.getSemester() + "\t");
                        Console.Write(stu.getCgpa() + "\t");
                        Console.Write(stu.getDepartment() + "\t");
                        Console.Write(stu.getUni() + "\t");
                        Console.WriteLine();
                    }
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            string         path  = @"C:\Users\Ahsan\Documents\visual studio 2013\Projects\VP_Assignment_1\VP_Assignment_1\bin\Debug\Student.txt";
            char           loop  = 'y';
            markAttendence atten = new markAttendence();

            do
            {
                Program obj = new Program();
                Console.WriteLine("1. Create Student profile");

                Console.WriteLine("2. Search Student");

                Console.WriteLine("3. Delete Student Record");

                Console.WriteLine("4. List top 03 of class");

                Console.WriteLine("5. Mark student attendance");

                Console.WriteLine("6. View attendance");

                Console.WriteLine("---------------------------");

                char option;
                option = Console.ReadKey().KeyChar;
                if (option == '1')
                {
                    char loopDecision;
                    List <setterAndGetterMethods> list = new List <setterAndGetterMethods>();
                    do
                    {
                        char chack = '0';
                        Console.Clear();
                        string getData             = "";
                        setterAndGetterMethods stu = new setterAndGetterMethods();
                        Console.Write("Enter Student Enrollment:: ");
                        getData = Console.ReadLine();
                        string       line;
                        StreamReader read = new StreamReader(path);
                        while ((line = read.ReadLine()) != null)
                        {
                            if (line.Trim() == getData.Trim())
                            {
                                Console.WriteLine("Please use the Unire ID");
                                chack = '1';
                                System.Console.ReadKey();
                                break;
                            }
                        }
                        read.Close();
                        if (chack == '0')
                        {
                            stu.setStudentId(getData);
                            getData = null;
                            Console.Write("Enter Student Name:: ");
                            getData = Console.ReadLine();
                            stu.setStudentName(getData);
                            getData = null;
                            Console.Write("Enter Student semester:: ");
                            getData = Console.ReadLine();
                            stu.setStudentSemester(getData);
                            getData = null;
                            Console.Write("Enter Student CGPA:: ");
                            getData = Console.ReadLine();
                            stu.setCgpa(getData);
                            getData = null;
                            Console.Write("Enter Student Department::");
                            getData = Console.ReadLine();
                            stu.setDepartment(getData);
                            getData = null;
                            Console.Write("Enter Student University:: ");
                            getData = Console.ReadLine();
                            stu.setUniversity(getData);
                            getData = null;

                            list.Add(stu);
                        }
                        Console.Clear();
                        Console.WriteLine("Again (Y/N)?");
                        loopDecision = Console.ReadKey().KeyChar;
                        Console.Clear();
                    } while (loopDecision == 'y' || loopDecision == 'Y');

                    foreach (var item in list)
                    {
                        StreamWriter file = File.AppendText(path);
                        file.AutoFlush = true;
                        file.Write(item.getId() + "\t");
                        file.Write("\r" + item.getName() + "\t");
                        file.Write("\r" + item.getSemester() + "\t");
                        file.Write("\r" + item.getCgpa() + "\t");
                        file.Write("\r" + item.getDepartment() + "\t");
                        file.Write("\r" + item.getUni() + "\t");
                        file.WriteLine();
                        file.Close();
                    }
                }
                else if (option == '2')
                {
                    int countStudent = 0;;
                    Console.Clear();

                    Console.WriteLine("1. Search by Student ID");

                    Console.WriteLine("2. Search By Student Name");

                    Console.WriteLine("3. Search All Students");

                    char searchOption;
                    searchOption = Console.ReadKey().KeyChar;
                    if (searchOption == '1')
                    {
                        Console.Clear();
                        Console.Write("Enter The ID of The Student:: ");
                        string StudenID;
                        StudenID = Console.ReadLine();
                        string       line;
                        StreamReader read = new StreamReader(path);
                        while ((line = read.ReadLine()) != null)
                        {
                            if (StudenID.Trim() == line.Trim())
                            {
                                Console.Write(line);
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                Console.WriteLine();
                                read.Close();
                                break;
                            }

                            for (int i = 1; i < 6; i++)
                            {
                                line = read.ReadLine();
                            }
                        }
                    }
                    else if (searchOption == '2')
                    {
                        Console.Clear();
                        Console.Write("Enter The Name of The Student:: ");
                        string name;
                        name = Console.ReadLine();
                        string       line;
                        StreamReader read = new StreamReader(path);
                        string       temp = read.ReadLine();

                        while ((line = read.ReadLine()) != null)
                        {
                            if (name == line.Trim())
                            {
                                Console.Write(temp + "\t");
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                line = read.ReadLine().Trim();
                                Console.Write(line + "\t");
                                read.Close();
                                Console.WriteLine();
                                break;
                            }

                            for (int i = 1; i < 6; i++)
                            {
                                line = read.ReadLine();
                                temp = line;
                            }
                        }
                    }
                    else if (searchOption == '3')
                    {
                        Console.Clear();
                        StreamReader read  = new StreamReader(path);
                        string[]     lines = File.ReadAllLines(path);
                        //string line;
                        foreach (string line in lines)
                        {
                            Console.WriteLine(line);
                        }
                    }
                }
                else if (option == '3')
                {
                    DeletionOfRecord DR = new DeletionOfRecord();
                    DR.deleteRecoed(path);
                }
                else if (option == '4')
                {
                    FindTop3 TTS = new FindTop3();
                    TTS.Top3Students(path);
                }
                else if (option == '5')
                {
                    atten.Attend(path);
                }

                else if (option == '6')
                {
                    atten.ViewAtten();
                }
                Console.WriteLine("Again(y/n)");
                loop = Console.ReadKey().KeyChar;
            } while (loop == 'y' || loop == 'Y');
        }