Example #1
0
 public Search()
 {
     InitializeComponent();
     AddResidentTypes();
     AddFloors();
     AddRooms();
     Resident objResToEdit = null;
 }
        private void submit_btn_Click(object sender, RoutedEventArgs e)
        {
            //Example of casting
            ComboBoxItem studentType = (ComboBoxItem)student_type_drop_down.SelectedItem; //now we have a name for the term item in our combobox (dropdown)
            ComboBoxItem room        = (ComboBoxItem)room_drop_down.SelectedItem;
            var          prevStudID  = studentList[studentList.Count - 1].StudentID;

            //if (student_type_drop_down.SelectedIndex == -1)
            //{
            //    MessageBox.Show("This is a required field");
            //}

            try
            {
                if (studentType.Content.ToString() == "Athlete")
                {
                    BoardingFee = 1200;
                    var floor = floor_drop_down.SelectedItem.ToString();
                    //MessageBox.Show(prevStudID.ToString());
                    aStudent = new Student(prevStudID += 1, name_box.Text, studentType.Content.ToString(), BoardingFee, Convert.ToInt32(floor), Convert.ToInt32(room.Content.ToString()));
                    //Adding new student to List
                    studentList.Add(aStudent);
                    //Writing new data to CSV file
                    source.writeData(studentList);
                }
                else if (studentType.Content.ToString() == "Scholarship Recipient")
                {
                    BoardingFee = 100;
                    var floor = floor_drop_down.SelectedItem.ToString();
                    //MessageBox.Show(floor.Content.ToString());
                    aStudent = new Student(prevStudID += 1, name_box.Text, studentType.Content.ToString(), BoardingFee, Convert.ToInt32(floor), Convert.ToInt32(room.Content.ToString()));
                    //Adding new student to List
                    studentList.Add(aStudent);
                    //Writing new data to CSV file
                    source.writeData(studentList);
                }
                else if (studentType.Content.ToString() == "Student Worker")
                {
                    int wage = 14 * Convert.ToInt32(hours_box.Text);
                    BoardingFee = 1245 - wage;
                    var floor = floor_drop_down.SelectedItem.ToString();
                    aStudent = new Student(prevStudID += 1, name_box.Text, studentType.Content.ToString(), BoardingFee, Convert.ToInt32(floor), Convert.ToInt32(room.Content.ToString()));
                    //Adding new student to the master list that holds ALL students
                    studentList.Add(aStudent);
                    //Writing new data to CSV file
                    source.writeData(studentList);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                SearchPage openSearchPage = new SearchPage();
                openSearchPage.Show();
                this.Close();
            }
        }
        private void Submit_Resident(object sender, RoutedEventArgs e) //Method for reading user inputted data, assigning to Resident type, and writing to the DataSource
        {
            try
            {
                ComboBoxItem residentType = (ComboBoxItem)resident_combo.SelectedItem;
                ComboBoxItem floor        = (ComboBoxItem)floor_combo.SelectedItem;
                double       fee;

                if (residentType.Content.ToString() == "Student Worker")
                {
                    fee       = 1245 - ((Convert.ToDouble(hours_tb.Text) * Convert.ToDouble(pay_tb.Text)) / 2); //Calculates worker Boarding fee
                    aResident = new Student_Worker(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, Convert.ToInt32(hours_tb.Text), Convert.ToDouble(pay_tb.Text));
                    wResident = new Student_Worker(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, Convert.ToInt32(hours_tb.Text), Convert.ToDouble(pay_tb.Text));
                    source.writeDataW(wResident);
                }
                if (residentType.Content.ToString() == "Scholarship Recipient")
                {
                    fee       = 100;
                    aResident = new Scholarship_Resident(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, scholarshipType_tb.Text, Convert.ToDouble(scholarshipAmount_tb.Text));
                    sResident = new Scholarship_Resident(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, scholarshipType_tb.Text, Convert.ToDouble(scholarshipAmount_tb.Text));
                    source.writeDataS(sResident);
                }
                if (residentType.Content.ToString() == "Student Athlete")
                {
                    fee        = 1200;
                    aResident  = new Athlete_Resident(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, sport_tb.Text, role_tb.Text);
                    atResident = new Athlete_Resident(name_tb.Text, Convert.ToInt32(id_tb.Text), Convert.ToInt32(floor.Content.ToString()), residentType.Content.ToString(), Convert.ToInt32(room_tb.Text), fee, sport_tb.Text, role_tb.Text);
                    source.writeDataA(atResident);
                }
            }
            catch
            {
                New_Resident refreshResidentWindow = new New_Resident();
                refreshResidentWindow.Show();
                this.Close();
            }
            finally
            {
                New_Resident refreshResidentWindow = new New_Resident();
                refreshResidentWindow.Show();
                this.Close();
            }
        }
        //Submit button
        private void add_resident_btn(object sender, RoutedEventArgs e)
        {
            //selection 0 = student worker
            //selection 1 = athlete
            //selection 2 = scholarship recipient
            if (student_type_combo_box.SelectedIndex == 0)
            {
                double earnings = 14 * Convert.ToDouble(monthlyhoursBox.Text.ToString());
                double rent     = 1245 - earnings;

                aResident = new Athlete(fullnameBox.Text.ToString(), student_type_combo_box.Text, Convert.ToInt32(studentidBox.Text.ToString()), Convert.ToInt32(room_number_combo_box.Text.ToString()), rent, Convert.ToInt32(floor_number_combo_box.Text.ToString()));
                //Adds a new student to list
                residentWindowList.Add(aResident);
                //Writes the new data to CSV file
                source.writeData(residentWindowList);
                //Show a message box to the user when they add a resident
                MessageBox.Show("A Resident was successfully added.");
            }
            else if (student_type_combo_box.SelectedIndex == 1)
            {
                double rent = 1200;

                aResident = new Athlete(fullnameBox.Text.ToString(), student_type_combo_box.Text, Convert.ToInt32(studentidBox.Text.ToString()), Convert.ToInt32(room_number_combo_box.Text.ToString()), rent, Convert.ToInt32(floor_number_combo_box.Text.ToString()));
                //Adds a new student to list
                residentWindowList.Add(aResident);
                //Writes the new data to CSV file
                source.writeData(residentWindowList);
                MessageBox.Show("A Resident was successfully added.");
            }
            else if (student_type_combo_box.SelectedIndex == 2)
            {
                double rent = 100;

                aResident = new Athlete(fullnameBox.Text.ToString(), student_type_combo_box.Text, Convert.ToInt32(studentidBox.Text.ToString()), Convert.ToInt32(room_number_combo_box.Text.ToString()), rent, Convert.ToInt32(floor_number_combo_box.Text.ToString()));
                //Adds a new student to list
                residentWindowList.Add(aResident);
                //Writes the new data to CSV file
                source.writeData(residentWindowList);
                MessageBox.Show("A Resident was successfully added.");
            }
        }