Ejemplo n.º 1
0
            static void Main(string[] args)
            {
                StudentProfile obj = new StudentProfile();
                string         path;
                string         filepath;
                int            Id, Semester;
                string         newpath;
                float          Cgpa;
                string         Name, deptt, University;
                int            choice;

                Console.WriteLine("Enter the respective number");
                Console.WriteLine("1: STUDENT PROFILE");
                Console.WriteLine("2: STUDENT SEARCH");
                Console.WriteLine("3: DELETE STUDENT RECORD");
                Console.WriteLine("4: LIST TOP 3 OF CLASS");
                Console.WriteLine("5: MARK ATTENDANCE");
                Console.WriteLine("6: VIEW ATTENDANCE");
                choice = int.Parse(Console.ReadLine());
                if (choice == 1)
                {
                    Console.WriteLine("Enter the path make file to enter student record e.g(E:/record.txt)");
                    path = Console.ReadLine();
                    Console.WriteLine("please Enter the ID of the student");
                    Id = int.Parse(Console.ReadLine());
                    try
                    {
                        StreamReader match = new StreamReader(path);
                        string       line;
                        while ((line = match.ReadLine()) != null)
                        {
                            int temp;
                            int.TryParse(line, out temp);
                            if (int.TryParse(line, out temp))
                            {
                                if (Id == temp)
                                {
                                    Console.WriteLine("This ID is already accomodated to a student");
                                    Console.WriteLine("please choose another one");
                                    Console.WriteLine("please Enter the ID of the student");
                                    Id = int.Parse(Console.ReadLine());
                                    match.Close();
                                }
                            }
                        }
                        Console.WriteLine("Enter the name of the student");
                        Name = Console.ReadLine();
                        Console.WriteLine("Enter the cgpa of the student");
                        Cgpa = float.Parse(Console.ReadLine());
                        if (Cgpa > 4.0 || Cgpa < 0.0)
                        {
                            Console.WriteLine("invalid cgpa please enter from 0 to 4");
                            Console.WriteLine("Enter the cgpa of the student");
                            Cgpa = float.Parse(Console.ReadLine());
                        }
                        Console.WriteLine("Enter the Semester of the student");
                        Semester = int.Parse(Console.ReadLine());
                        if (Semester < 1 || Semester > 12)
                        {
                            Console.WriteLine("invalid semester number please enter between 1 to 12");
                            Console.WriteLine("Enter the Semester of the student");
                            Semester = int.Parse(Console.ReadLine());
                        }
                        Console.WriteLine("Enter the department of the student");
                        deptt = Console.ReadLine();
                        Console.WriteLine("Enter the university of the student");
                        University = Console.ReadLine();
                        Console.WriteLine("WRITING IN FILE DONE");
                        match.Close();
                        obj.getdata(path, Id, Name, Cgpa, Semester, deptt, University);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Enter the name of the student");
                        Name = Console.ReadLine();
                        Console.WriteLine("Enter the cgpa of the student");
                        Cgpa = float.Parse(Console.ReadLine());
                        if (Cgpa > 4.0 || Cgpa < 0.0)
                        {
                            Console.WriteLine("invalid cgpa please enter between 0 to 4");
                            Console.WriteLine("Enter the cgpa of the student");
                            Cgpa = float.Parse(Console.ReadLine());
                        }
                        Console.WriteLine("Enter the Semester of the student");
                        Semester = int.Parse(Console.ReadLine());
                        if (Semester < 1 || Semester > 12)
                        {
                            Console.WriteLine("invalid semester number please enter between 1 to 12");
                            Console.WriteLine("Enter the Semester of the student");
                            Semester = int.Parse(Console.ReadLine());
                        }
                        Console.WriteLine("Enter the department of the student");
                        deptt = Console.ReadLine();
                        Console.WriteLine("Enter the university of the student");
                        University = Console.ReadLine();
                        Console.WriteLine("WRITING IN FILE DONE");
                        obj.getdata(path, Id, Name, Cgpa, Semester, deptt, University);
                    }
                }
                else if (choice == 2)
                {
                    Console.WriteLine("please Enter the path of file to search the record e.g (E:/record.txt)");
                    path = Console.ReadLine();
                    int choice1;
                    Console.WriteLine("how do you want to search the record");
                    Console.WriteLine("press 1 to search by ID");
                    Console.WriteLine("press 2 to search by Name");
                    Console.WriteLine("press 3 to search by Semester");
                    choice1 = int.Parse(Console.ReadLine());
                    if (choice1 == 1)
                    {
                        Console.WriteLine("enter the ID to search the record ");
                        int nid = int.Parse(Console.ReadLine());
                        obj.searchbyid(path, nid);
                    }
                    else if (choice1 == 2)
                    {
                        Console.WriteLine("enter the name to search the record ");
                        string newname = Console.ReadLine();
                        obj.searchbyname(path, newname);
                    }
                    else if (choice1 == 3)
                    {
                        Console.WriteLine("enter the semester to search the record ");
                        string id = Console.ReadLine();
                        obj.searchbysem(path, id);
                    }
                }
                else if (choice == 3)
                {
                    Console.WriteLine("enter the path of file from where you want to delete the record e.g (C:/record.txt)");
                    path = Console.ReadLine();
                    int nid;
                    Console.WriteLine("enter the ID to delete its record");
                    nid = int.Parse(Console.ReadLine());
                    obj.deletion(nid, path);
                }
                else if (choice == 4)
                {
                    Console.WriteLine("please give the path of the file for which top 3 will be shown e.g (E:/gpa.txt)");
                    path = Console.ReadLine();

                    //obj.top3ofclass(key1,path);
                }
                else if (choice == 5)
                {
                    Console.WriteLine("please Enter the path of file to search the record e.g (E:/record.txt)");
                    path = Console.ReadLine();
                    Console.WriteLine("now enter the next file to store marked students e.g(E:/markattendance.txt)");
                    filepath = Console.ReadLine();
                    Console.WriteLine(" NOW Enter the semester to mark the attendance");
                    string seme = Console.ReadLine();
                    obj.markAttendance(filepath, path, seme);
                }
                else if (choice == 6)
                {
                    Console.WriteLine("Enter the path of file to view Attendance e.g (E:/marked.txt)");
                    filepath = Console.ReadLine();
                    if (File.Exists(filepath))
                    {
                        StreamReader view = new StreamReader(filepath);
                        string       line;
                        while ((line = view.ReadLine()) != null)
                        {
                            Console.WriteLine(line);
                        }
                    }
                    else
                    {
                        Console.WriteLine("File doesn't exists because you haven't marked the attendance");
                    }
                }
            }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string         StudentId, Name, Dept, Uni, str, first1 = "", second2 = "";
            int            Semester;
            char           choice, search;
            float          CGPA = 0f;
            StudentProfile obj  = new StudentProfile();



            do
            {
                Console.Clear();
                Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                Console.WriteLine("\t\t\t\t\t\t Student Profile");
                Console.WriteLine("\t\t\t----------------------------------------------------------");
                Console.WriteLine("\n\n\t\t\t\t\t 1. Create Profile");
                Console.WriteLine("\t\t\t\t\t 2. Search Student");
                Console.WriteLine("\t\t\t\t\t 3. Delete Student Record");
                Console.WriteLine("\t\t\t\t\t 4. View Top 3 Students Of Class");
                Console.WriteLine("\t\t\t\t\t 5. Mark Attendance");
                Console.WriteLine("\t\t\t\t\t 6. View Attendance");
                Console.Write("\n\t\t\t\t\t Enter number of your choice: ");
                choice = Convert.ToChar(Console.ReadLine());

                if (choice == '1')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t--------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t Create Student Profile");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");

                    Console.Write("Enter ID: ");
                    StudentId = Console.ReadLine();
                    StudentId = obj.CheckUniqueID(StudentId, args[0]);
                    Console.Write("Enter Name: ");
                    Name = Console.ReadLine();
                    Console.Write("Enter University: ");
                    Uni = Console.ReadLine();
                    Console.Write("Enter Department: ");
                    Dept = Console.ReadLine();
                    Console.Write("Enter Semester: ");
                    Semester = Convert.ToInt16(Console.ReadLine());
                    Console.Write("Enter CGPA: ");
                    CGPA = float.Parse(Console.ReadLine());
                    obj.CreateProfile(StudentId, Name, Dept, Uni, Semester, CGPA, args[0]);
                    Console.WriteLine("\n\n\n\t\t\t\tYour Profile Has Been Successfully Created!");
                }
                else if (choice == '2')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t Search Student ");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\n\n\t\t\t\t\t 1. Search By ID");
                    Console.WriteLine("\t\t\t\t\t 2. Search By Name");
                    Console.WriteLine("\t\t\t\t\t 3. Search By Semester");
                    Console.Write("\n\t\t\t\t\t Enter number of your choice: ");
                    search = Convert.ToChar(Console.ReadLine());
                    if (search == '1')
                    {
                        Console.Write("\t\t\t\t\t Enter ID: ");
                        StudentId = Console.ReadLine();
                        Console.WriteLine(obj.SearchStudent(1, StudentId, args[0]));
                    }
                    else if (search == '2')
                    {
                        Console.Write("\t\t\t\t\t Enter Name: ");
                        Name = Console.ReadLine();
                        Console.WriteLine(obj.SearchStudent(2, Name, args[0]));
                    }
                    else if (search == '3')
                    {
                        Console.Write("\t\t\t\t\t Enter Semester: ");
                        Semester = Convert.ToInt16(Console.ReadLine());
                        Console.WriteLine(obj.SearchStudent(3, Semester.ToString(), args[0]));
                    }
                    else
                    {
                        Console.Write("\t\t\t\t\t Invalid Input");
                    }
                }
                else if (choice == '3')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t Delete Student Profile");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");
                    Console.Write("\t\t\t\t\t Enter ID: ");
                    StudentId = Console.ReadLine();
                    string       result = obj.DeleteRecord(StudentId, args[0]);
                    StreamWriter writer = new StreamWriter(args[0]);
                    writer.AutoFlush = true;
                    if (result.Equals("No Record Found!"))
                    {
                        Console.WriteLine(result);
                    }
                    else
                    {
                        writer.WriteLine(result);
                        Console.WriteLine("\t\t\t\t\t The Record Has Been Successfully Deleted!");
                    }
                    writer.Close();
                }
                else if (choice == '4')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t View Top 3 Students of Class");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");
                    Console.Write("Enter Semester: ");
                    Semester = Convert.ToInt16(Console.ReadLine());
                    obj.Top3Students(Semester, args[0]);
                }
                else if (choice == '5')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t Mark Attendance");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");
                    Console.Write("Enter Semester: ");
                    Semester = Convert.ToInt16(Console.ReadLine());
                    obj.MarkAttendance(Semester, args[0], args[1]);
                }
                else if (choice == '6')
                {
                    Console.Clear();
                    Console.WriteLine("\n\t\t\t----------------------------------------------------------");
                    Console.WriteLine("\t\t\t\t\t\t View Attendance");
                    Console.WriteLine("\t\t\t----------------------------------------------------------");
                    Console.Write("\t\t\t\t\t Enter Semester: ");
                    string Sem = Console.ReadLine();
                    Console.Write("\t\t\t\t\t EnterDate: ");
                    string date = Console.ReadLine();
                    Console.WriteLine(obj.ViewAttendance(Sem, date, args[1]));
                }
                else
                {
                    Console.WriteLine("\t\t\t\t\t Invalid Input");
                }



                Console.WriteLine("\t\t\t Press 0: Exit          Press Any Key To Continue ");
                choice = Convert.ToChar(Console.ReadLine());
            } while (choice != '0');

            Console.ReadKey();
        }