Example #1
0
        // Add Student duymesine basildiqda bash verenler
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            // Add student forumundaki inputlara daxil edilenlerin yerlerine oyulmasi
            string firstname = txtFirstname.Text;
            string lastname  = txtLastname.Text;
            string email     = txtEmail.Text;
            // secilmish qrupun ID nomresinin  groupID-ye verilmesi
            string groupId = ((GroupCombo)cmbGroups.SelectedItem).Value;

            // Group tipinden deyishen yaradiriq
            // ve Qrup siyahisinin ID-lerinden secilmishini deyishene veririk
            Group selectedGroup = GroupList.GetGroupById(groupId);

            if (selectedGroup == null) // eger secilmish qrup yoxdursa
            {
                MessageBox.Show("Group doesn't exist");
                return;
            }

            // Studentlerin siyahisina yeni studentin elave elave edilmesi
            StudentList.Add(new Student
            {
                Firstname = firstname,
                Lastname  = lastname,
                Email     = email,
                Group     = selectedGroup
            });

            //txtFirstname.Text = "";
            //txtLastname.Text = "";
            //txtEmail.Text = "";
        }
        private void btnDelGroup_Click(object sender, EventArgs e)
        {
            DialogResult question = MessageBox.Show("Are you sure?", "All book list in for this author will be deleted!", MessageBoxButtons.YesNo);

            if (question == DialogResult.Yes)
            {   //=========================  Group-un silinmesi ====================================
                // downcast edirik ve comboBoxda secilmish groupun ID nomresini groupID-ye veririk
                string groupID = ((GroupCombo)cmbDel.SelectedItem).Value;

                // GroupList-den secilmish qrupu ID-ye gore tapib veririk Group tipinde groupToDeleted-e
                // bir nov apcast olunur ki Group-un icinden lazim olana catsin
                Group groupToDeleted = GroupList.GetGroupById(groupID);

                // GroupList-den Group classina girib Groups siyahisindan
                // ID-ci uyqun geleni silirik
                GroupList.Groups.Remove(groupToDeleted);
                //==================================================================================

                //=========== Silinen Group-un Student siyahisinin silinmesi =====================//

                // silinen group-un icindeki studentleri yeni List massivine yiqiriq
                List <Student> studentToBedeleted = StudentList.GetStudentsByGroup(groupToDeleted);

                // ve hemin massiv siralanir ve siyahidaki studentName-ler silinir
                foreach (Student studentName in studentToBedeleted)
                {
                    StudentList.Students.Remove(studentName);
                }

                // Group-larin siyahisi yenilenir
                UpdateCombo();
            }
            else
            {
                MessageBox.Show("You are cancelled deletion!");
            }
        }