예제 #1
0
        private void TestEditLecturer()
        {
            Console.WriteLine("Testing Edit Lecturer");
            string[] id = new string[] { "v3111111", "v", "3111111", "v31234", "v1234567" };
            string   lecturerIDToDelete = "";

            for (int i = 0; i < id.Count(); i++)
            {
                if (lc.SearchLecturer(id[i]) != null)
                {
                    Console.WriteLine("\t\t Found Lecturer {0} !", id[i]);
                    lecturerIDToDelete = id[i];
                    lc.DeleteLecturer(id[i]);
                }
            }
            id = new string[] { "v3111111", "v", "3111111", "v31234", "v1234567", "v3222222" };
            string fn = "huy"; string ln = "le"; string mn = "phat";

            for (int i = 0; i < id.Count(); i++)
            {
                if (!lecturerIDToDelete.Equals(id[i]))
                {
                    lc.DeleteLecturer(lecturerIDToDelete);
                }
                else
                {
                    lc.DeleteLecturer(id[i]);
                }
                Console.WriteLine("New lecturer infomation(id, first name, last name, middle name)\n({0}, {1}, {2}, {3})", id[i], fn, ln, mn);
                if (lc.UpdateLecturer(id[i], fn, mn, ln))
                {
                    Console.WriteLine("Updated lecturer {0}!", id[i]);
                    Console.WriteLine();
                    TestDisplayLecturerList();
                }
                else
                {
                    Console.WriteLine("Fail to update lecturer {0}!", id[i]);
                    Console.WriteLine();
                    TestDisplayLecturerList();
                }
            }
            Console.WriteLine();
        }
예제 #2
0
 private void btnupdate_Click(object sender, EventArgs e)
 {
     try
     {
         int  empidlength = txtemployeeid.Text.Length;
         bool isvalidated = validatefields();
         if (isvalidated)
         {
             if (empidlength != 6)
             {
                 throw new Exception("Employee id should be 6 digit number");
             }
             int      lecturerid = Convert.ToInt32(lbllecturerid.Text);
             Lecturer lecturer   = new Lecturer();
             lecturer.lecturerid   = lecturerid;
             lecturer.lecturername = txtlecturername.Text;
             lecturer.center       = combocenter.SelectedItem.ToString();
             lecturer.employeeid   = txtemployeeid.Text;
             lecturer.building     = combobuilding.SelectedItem.ToString();
             lecturer.faculty      = combofaculty.SelectedItem.ToString();
             lecturer.level        = Convert.ToInt32(combolevel.SelectedItem.ToString());
             lecturer.department   = combodepartment.SelectedItem.ToString();
             lecturer.rank         = txtrank.Text;
             string message = LecturerController.UpdateLecturer(lecturer);
             MessageBox.Show(message);
             loadgrid(txtlecturerfilter.Text);
             clear();
         }
         else
         {
             MessageBox.Show("please fill in all fields!");
         }
     }
     catch (FormatException fe)
     {
         MessageBox.Show("please select a specific lecturer");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #3
0
        internal void EditLecturer()
        {
            int lecturerCount = lecturerController.LecturerCount();

            if (lecturerCount > 0)
            {
                Console.WriteLine("Please enter only one course id as displayed below");
                DisplayLecturer();
                Console.Write("> ");
                var lecturerIdToChange = Console.ReadLine();
                while (lecturerController.SearchLecturer(lecturerIdToChange) == null)
                {
                    Console.WriteLine("Sorry! The lecturer you wanna edit does not exist. Try again!");
                    Console.Write("> ");
                    lecturerIdToChange = Console.ReadLine();
                }
                Lecturer oldLecturer = lecturerController.SearchLecturer(lecturerIdToChange);
                Console.Write("You will change old id \"{0}\" to new id or press [Enter] to unchange: ", oldLecturer.Id);
                string updatedId = Console.ReadLine();
                Console.Write("You will change old first name \"{0}\" to new name or press [Enter] to unchange: ", oldLecturer.FirstName);
                string updatedFName = Console.ReadLine();
                Console.Write("You will change old middle name \"{0}\" to new name or press [Enter] to unchange: ", oldLecturer.MiddleName);
                string updatedMName = Console.ReadLine();
                Console.Write("You will change old last name \"{0}\" to new name or press [Enter] to unchange: ", oldLecturer.LastName);
                string updatedLName = Console.ReadLine();

                if (updatedId == "")
                {
                    updatedId = oldLecturer.Id;
                }
                if (updatedFName == "")
                {
                    updatedFName = oldLecturer.FirstName;
                }
                if (updatedMName == "")
                {
                    updatedMName = oldLecturer.MiddleName;
                }
                if (updatedLName == "")
                {
                    updatedLName = oldLecturer.LastName;
                }

                // Keep old information of lecturer to modify if it happens error during updating
                string id    = oldLecturer.Id;
                string fName = oldLecturer.FirstName;
                string mName = oldLecturer.MiddleName;
                string lName = oldLecturer.LastName;

                // Delete course to edit by its id
                lecturerController.DeleteLecturer(lecturerIdToChange);

                if (lecturerController.UpdateLecturer(updatedId, updatedFName, updatedMName, updatedLName))
                {
                    Console.WriteLine("\nYou updated new information for lecturer id: " + updatedId);
                }
                else
                {
                    // Recreate old lecturer if updating fail
                    lecturerController.CreateLecturer(id, fName, mName, lName);
                    Console.WriteLine("\nYou failed to update new information for lecturer id: " + id);
                    Console.WriteLine();
                }
            }
            else
            {
                Console.WriteLine("Opp! empty lecturer list. You should use selection 1 to add a lecturer.");
            }
            Console.WriteLine("Press[Enter] button to continue...");
            Console.ReadLine();
        }