コード例 #1
0
 private void SubmitChange_Click(object sender, EventArgs e) //Подтверждение изменений на панели просмотра
 {
     if (classroomsBox.Visible)
     {
         floorNumber.Enabled = false;
         Floor floor = new Floor();
         int   i     = 0;
         bool  flag  = false;
         foreach (Floor f in mainList)
         {
             if (i == bufIndex)
             {
                 floor = f;
                 i     = f.Number;
             }
             if (f.Number == (int)floorNumber.Value)
             {
                 flag = true;
             }
             i++;
         }
         if (flag)
         {
             mainList.RemoveAt(bufIndex);
             foreach (Floor f in mainList)
             {
                 if (f.Number == (int)floorNumber.Value)
                 {
                     foreach (Classroom c in floor.classrooms)
                     {
                         int index;
                         if (!SList <Classroom> .IsSimilarKey(c.Number, f.classrooms, out index))
                         {
                             f.classrooms.Add(c);
                         }
                     }
                 }
             }
         }
         else
         {
             floor.Number = (int)floorNumber.Value;
             floor.Path   = "Classroom" + floor.Number + ".txt";
             File.Delete(mainPath + "\\Classroom" + i + ".txt");
             mainList.RemoveAt(bufIndex);
             mainList.Insert(bufIndex, floor);
         }
     }
     else
     {
         classroomNumber.Enabled = false;
         ownerName.Enabled       = false;
         square.Enabled          = false;
         safety.Enabled          = false;
         department.Enabled      = false;
         capacity.Enabled        = false;
         int i = 0;
         foreach (Floor f in mainList)
         {
             if (f.Number == (int)floorNumber.Value)
             {
                 bool flag = false;
                 foreach (Classroom c in f.classrooms)
                 {
                     if (c.Number == (int)classroomNumber.Value && f.classrooms.IndexOf(c) != bufIndex)
                     {
                         flag = true;
                     }
                 }
                 if (!flag)
                 {
                     Classroom classroom = new Classroom((int)classroomNumber.Value, ownerName.Text, (double)square.Value, safety.Checked, department.Text, (int)capacity.Value);
                     f.classrooms.RemoveAt(bufIndex);
                     f.classrooms.Insert(bufIndex, classroom);
                 }
                 else
                 {
                     MessageBox.Show("Аудитория с таким номером уже есть на данном этаже");
                     CancelChange_Click(sender, e);
                 }
                 break;
             }
             i++;
         }
     }
     changeData.Visible   = true;
     removeData.Visible   = true;
     submitChange.Visible = false;
     cancelChange.Visible = false;
     if (!classroomsBox.Visible)
     {
         changeImage.Visible = true;
         removeImage.Visible = true;
     }
 }
コード例 #2
0
ファイル: Add.cs プロジェクト: maxfetisov/PPO
        private void Submit_Click(object sender, EventArgs e) //Подтверждение создания элемента + проверка на его "валидность"
        {
            int       index;
            Floor     floor = new Floor((int)floorNumber.Value);
            Classroom classroom;

            if (openImage.FileName != "")
            {
                classroom = new Classroom((int)classroomNumber.Value, ownerName.Text, (double)square.Value, safety.Checked, department.Text, (int)capacity.Value, openImage.FileName);
            }
            else
            {
                classroom = new Classroom((int)classroomNumber.Value, ownerName.Text, (double)square.Value, safety.Checked, department.Text, (int)capacity.Value);
            }
            if (SList <Floor> .IsSimilarKey((int)floorNumber.Value, Main.mainList, out index))
            {
                foreach (Floor f in Main.mainList)
                {
                    if (f.Number == floor.Number)
                    {
                        if (classroom.IsValid())
                        {
                            if (!SList <Classroom> .IsSimilarKey(classroom.Number, f.classrooms, out index))
                            {
                                f.classrooms.Add(classroom);
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("Аудитория с таким номером уже существует");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Неверный формат заполнения");
                        }
                        break;
                    }
                }
            }
            else
            {
                if (floor.IsValid())
                {
                    if (classroom.IsValid())
                    {
                        Main.mainList.Add(floor);
                        foreach (Floor f in Main.mainList)
                        {
                            if (f.Number == floor.Number)
                            {
                                f.classrooms.Add(classroom);
                                this.Close();
                                break;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Неверный формат заполнения");
                }
            }
        }