コード例 #1
0
        public void InsertNewAssignmentAtCourse(int cid)
        {
            string   title;
            string   description;
            DateTime subDateTime;
            string   addAnotherAssignment = "";
            DateTime FalseDate            = new DateTime(0001, 1, 1); //Compere for wrong input date

            do
            {
                Assignment assignment = new Assignment();
                bool       isSubmitInWeekentd;

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine();
                Console.WriteLine("\tNew assignment");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                //Input fields
                Console.WriteLine();
                Console.Write("\tTitle : ");
                title = Console.ReadLine();

                Console.Write("\tDescription : ");
                description = Console.ReadLine();


                do
                {
                    Console.Write("\tSubmission date YYYY/MM/DD : ");
                    subDateTime = MyStaticClass.InputDate();
                    if (Convert.ToDateTime(subDateTime).DayOfWeek == DayOfWeek.Saturday || Convert.ToDateTime(subDateTime).DayOfWeek == DayOfWeek.Sunday)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\tSubmissions cannot be submitted at the weekend. Enter an appropriate date.");
                        Console.ForegroundColor = ConsoleColor.White;
                        isSubmitInWeekentd      = true;
                    }
                    else
                    {
                        isSubmitInWeekentd = false;
                    }
                } while (subDateTime == FalseDate || isSubmitInWeekentd);



                //Connect with database
                string qr = "insert into Assignment (title, description, subDateTime, Cid) values(@title, @description, @subDateTime, @Cid)";

                using (SqlConnection con = new SqlConnection(conString))
                {
                    SqlCommand cmd = new SqlCommand(qr, con);

                    cmd.Parameters.AddWithValue("@title", title);
                    cmd.Parameters.AddWithValue("@description", description);
                    cmd.Parameters.AddWithValue("@subDateTime", subDateTime);
                    cmd.Parameters.AddWithValue("@Cid", cid);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        Console.WriteLine();
                        Console.WriteLine("\tRecords Inserted Successfully");
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine("Error Generated. Details: " + e.ToString());
                    }
                }

                //Ask to continue
                do
                {
                    Console.WriteLine();
                    Console.Write("\tWould you like to add another assignment in this course? Y/N : ");
                    addAnotherAssignment = Console.ReadLine();
                } while (addAnotherAssignment.ToUpper() != "Y" && addAnotherAssignment.ToUpper() != "N");
            } while (addAnotherAssignment.ToUpper() != "N");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t=================================================================================\n");
            Console.ForegroundColor = ConsoleColor.White;
        }
コード例 #2
0
        public void InsertCourse()
        {
            string   title;
            string   stream;
            string   type;
            DateTime startDate;
            DateTime endDate;
            string   addAnotherCourse = "";
            DateTime FalseDate        = new DateTime(0001, 1, 1); //Compere for wrong input date

            do
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine();
                Console.WriteLine("\tNew course");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.White;

                //Input fields
                Console.WriteLine();
                Console.Write("\tTitle : ");
                title = Console.ReadLine();

                Console.Write("\tStream : ");
                stream = Console.ReadLine();

                Console.Write("\tType : ");
                type = Console.ReadLine();

                do
                {
                    Console.Write("\tStart date YYYY/MM/DD : ");
                    startDate = MyStaticClass.InputDate();
                } while (startDate == FalseDate);

                do
                {
                    Console.Write("\tEnd date YYYY/MM/DD : ");
                    endDate = MyStaticClass.InputDate();

                    if (startDate > endDate && endDate != FalseDate)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\tEnd date can't be before than start date.");
                        Console.ForegroundColor = ConsoleColor.White;
                    }
                } while (endDate == FalseDate || startDate > endDate);

                //Connect with database
                string qr = "insert into Course (title, stream, type, startDate, endDate) values(@title, @stream, @type, @startDate, @endDate)";

                using (SqlConnection con = new SqlConnection(conString))
                {
                    SqlCommand cmd = new SqlCommand(qr, con);

                    cmd.Parameters.AddWithValue("@title", title);
                    cmd.Parameters.AddWithValue("@stream", stream);
                    cmd.Parameters.AddWithValue("@type", type);
                    cmd.Parameters.AddWithValue("@startDate", startDate);
                    cmd.Parameters.AddWithValue("@endDate", endDate);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        Console.WriteLine();
                        Console.WriteLine("\tRecords Inserted Successfully");
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine("Error Generated. Details: " + e.ToString());
                    }
                }

                //Ask to continue
                do
                {
                    Console.WriteLine();
                    Console.Write("\tWould you like to add another course? Y/N : ");
                    addAnotherCourse = Console.ReadLine();
                } while (addAnotherCourse.ToUpper() != "Y" && addAnotherCourse.ToUpper() != "N");
            } while (addAnotherCourse.ToUpper() != "N");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t=================================================================================\n");
            Console.ForegroundColor = ConsoleColor.White;
        }
コード例 #3
0
        public void InsertStudent()
        {
            string   firstName;
            string   lastName;
            DateTime dateOfBirth;
            decimal  tuitionFees            = 1;
            string   addAnotherStudent      = "";
            bool     notSucceededTheConvert = true;        //Convert from string to decimal
            DateTime FalseDate = new DateTime(0001, 1, 1); //Compere for wrong input date


            do
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine();
                Console.WriteLine("\tNew student");
                Console.ForegroundColor = ConsoleColor.White;


                //Input fields-------------------------------------------------------------------------------------
                Console.WriteLine();
                Console.Write("\tFirst name : ");
                firstName = Console.ReadLine();

                Console.Write("\tLast name : ");
                lastName = Console.ReadLine();

                do
                {
                    Console.Write("\tDate of birth YYYY/MM/DD : ");
                    dateOfBirth = MyStaticClass.InputDate();
                } while (dateOfBirth == FalseDate);

                do
                {
                    Console.Write("\tTuition fees : ");

                    try
                    {
                        tuitionFees            = Convert.ToDecimal(Console.ReadLine().Replace(".", ","));
                        notSucceededTheConvert = false;
                    }
                    catch (Exception)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\tPlease give a right form of fees.");
                        Console.ForegroundColor = ConsoleColor.White;
                        notSucceededTheConvert  = true;
                    }
                } while (notSucceededTheConvert);


                //Connect with database
                string qr = "insert into Student (firstName, lastName, dateOfBirth, tuitionFees) values (@firstName, @lastName, @dateOfBirth, @tuitionFees)";

                using (SqlConnection con = new SqlConnection(conString))
                {
                    SqlCommand cmd = new SqlCommand(qr, con);

                    cmd.Parameters.AddWithValue("@firstName", firstName);
                    cmd.Parameters.AddWithValue("@lastName", lastName);
                    cmd.Parameters.AddWithValue("@dateOfBirth", dateOfBirth);
                    cmd.Parameters.AddWithValue("@tuitionFees", tuitionFees);

                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                        Console.WriteLine();
                        Console.WriteLine("\tRecords Inserted Successfully");
                    }
                    catch (SqlException e)
                    {
                        Console.WriteLine("Error Generated. Details: " + e.ToString());
                    }
                }


                //Ask to continue--------------------------------------------------------------------------------------
                do
                {
                    Console.WriteLine();
                    Console.Write("\tWould you like to add another student? Y/N : ");
                    addAnotherStudent = Console.ReadLine();
                } while (addAnotherStudent.ToUpper() != "Y" && addAnotherStudent.ToUpper() != "N");
            } while (addAnotherStudent.ToUpper() != "N");

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\n\t=================================================================================\n");
            Console.ForegroundColor = ConsoleColor.White;
        }