예제 #1
0
 private void AddEditInstructorsCategoriesForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         try
         {
             if (Instructor_comboBox.SelectedIndex == -1)
             {
                 Instructor_comboBox.Focus();
                 throw new Exception("Не выбран инструктор");
             }
             if (Category_comboBox.SelectedIndex == -1)
             {
                 Category_comboBox.Focus();
                 throw new Exception("Не выбрана категория");
             }
             AutoschoolDataSet TempDS = new AutoschoolDataSet();
             TempDS = BusinessLogic.ReadInstructorByID(Convert.ToInt32(Instructor_comboBox.SelectedValue.ToString()));
             if (TempDS.Instructors[0]["WorkStatusName"].ToString() != "Работает")
             {
                 DialogResult result = MessageBox.Show("Вы выбрали отсутствующего инструктора. Вы уверены, что хотите продолжить?", "Выбор отсутствующего сотрудника", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (result == DialogResult.No)
                 {
                     e.Cancel = true;
                     return;
                 }
             }
             TempDS = BusinessLogic.ReadInstructorsCategoriesByInstructorIdANDCategoryId(
                 Convert.ToInt32(Instructor_comboBox.SelectedValue), Convert.ToInt32(Category_comboBox.SelectedValue));
             if (TempDS.InstructorsCategories.Rows.Count > 0)
             {
                 throw new Exception("Такая связка между инструктором и категорией уже существует");
             }
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.Message, "Ошибка");
             e.Cancel = true;
             return;
         }
         if (dataRow != null)
         {
             dataRow["Instructor"] = Instructor_comboBox.SelectedValue;
             dataRow["Category"]   = Category_comboBox.SelectedValue;
         }
         else
         {
             instructorsCategoriesDataTable.AddInstructorsCategoriesRow(instructorsDataTable[Instructor_comboBox.SelectedIndex],
                                                                        categoriesDataTable[Category_comboBox.SelectedIndex]);
         }
     }
 }
        private void AddEditReplacementCarrierForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                try
                {
                    if (Instructor_comboBox.SelectedIndex == -1)
                    {
                        Instructor_comboBox.Focus();
                        throw new Exception("Не выбран инструктор");
                    }
                    AutoschoolDataSet TempDS = new AutoschoolDataSet();
                    TempDS = BusinessLogic.ReadInstructorByID(Convert.ToInt32(Instructor_comboBox.SelectedValue.ToString()));
                    if (TempDS.Instructors[0]["WorkStatusName"].ToString() != "Работает")
                    {
                        DialogResult result = MessageBox.Show("Вы выбрали отсутствующего инструктора. Вы уверены, что хотите продолжить?", "Выбор отсутствующего сотрудника", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                    if (SelectedReplaceableCarrierID == -1)
                    {
                        throw new Exception("Не выбрано заменяемое ТС");
                    }
                    if (SelectedReplacingCarrierID == -1)
                    {
                        throw new Exception("Не выбрано заменяющее ТС");
                    }
                    TempDS = BusinessLogic.ReadReplacementsCarriersByCarrierUseID(Convert.ToInt32(BusinessLogic.ReadCarriersUsesByInstructorCarrierID(Convert.ToInt32(Instructor_comboBox.SelectedValue), Convert.ToInt32(ReplaceableCarriers_dataGridView.SelectedRows[0].Cells["ID1Column"].Value)).CarriersUses[0]["ID"].ToString()));
                    if (dataRow != null)
                    {
                        for (int i = 0; i < TempDS.ReplacementsCarriers.Rows.Count; i++)
                        {
                            if (dataRow["ID"].ToString() == TempDS.ReplacementsCarriers.Rows[i]["ID"].ToString())
                            {
                                continue;
                            }
                            DateTime BeginReplacementInBdRow = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateBeginReplacement"].ToString()).Date;
                            DateTime EndReplacementInBdRow   = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateEndReplacement"].ToString()).Date;
                            DateTime Begin = Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date;
                            DateTime End   = Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date;
                            if (BeginReplacementInBdRow > Begin && End < BeginReplacementInBdRow)
                            {
                                continue;
                            }
                            if (EndReplacementInBdRow < Begin)
                            {
                                continue;
                            }
                            else
                            {
                                throw new Exception("Выбранное заменяемое ТС у данного водителя уже заменяется в указанное время");
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < TempDS.ReplacementsCarriers.Rows.Count; i++)
                        {
                            DateTime BeginReplacementInBdRow = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateBeginReplacement"].ToString()).Date;
                            DateTime EndReplacementInBdRow   = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateEndReplacement"].ToString()).Date;
                            DateTime Begin = Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date;
                            DateTime End   = Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date;
                            if (BeginReplacementInBdRow > Begin && End < BeginReplacementInBdRow)
                            {
                                continue;
                            }
                            if (EndReplacementInBdRow < Begin)
                            {
                                continue;
                            }
                            else
                            {
                                throw new Exception("Выбранное заменяемое ТС у данного водителя уже заменяется в указанное время");
                            }
                        }
                    }

                    TempDS = BusinessLogic.ReadReplacementsCarriersByCarrierReplacementID(SelectedReplacingCarrierID);
                    if (dataRow != null)
                    {
                        for (int i = 0; i < TempDS.ReplacementsCarriers.Rows.Count; i++)
                        {
                            if (dataRow["ID"].ToString() == TempDS.ReplacementsCarriers.Rows[i]["ID"].ToString())
                            {
                                continue;
                            }
                            DateTime BeginReplacementInBdRow = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateBeginReplacement"].ToString()).Date;
                            DateTime EndReplacementInBdRow   = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateEndReplacement"].ToString()).Date;
                            DateTime Begin = Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date;
                            DateTime End   = Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date;
                            if (BeginReplacementInBdRow > Begin && End < BeginReplacementInBdRow)
                            {
                                continue;
                            }
                            if (EndReplacementInBdRow < Begin)
                            {
                                continue;
                            }
                            else
                            {
                                throw new Exception("Выбранное заменяющее ТС уже используется в указанное время");
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < TempDS.ReplacementsCarriers.Rows.Count; i++)
                        {
                            DateTime BeginReplacementInBdRow = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateBeginReplacement"].ToString()).Date;
                            DateTime EndReplacementInBdRow   = Convert.ToDateTime(TempDS.ReplacementsCarriers.Rows[i]["DateEndReplacement"].ToString()).Date;
                            DateTime Begin = Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date;
                            DateTime End   = Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date;
                            if (BeginReplacementInBdRow > Begin && End < BeginReplacementInBdRow)
                            {
                                continue;
                            }
                            if (EndReplacementInBdRow < Begin)
                            {
                                continue;
                            }
                            else
                            {
                                throw new Exception("Выбранное заменяющее ТС уже используется в указанное время");
                            }
                        }
                    }

                    TempDS = BusinessLogic.ReadByCarrierID_AND_CrossInBeginEndDates(
                        SelectedReplacingCarrierID,
                        Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date,
                        Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date);
                    if (TempDS.CarriersRepairs.Rows.Count > 0)
                    {
                        throw new Exception("Выбранное заменяющее ТС само находится в ремонте в одни из указанных дней");
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message, "Ошибка");
                    e.Cancel = true;
                    return;
                }
                int CarrierUseID = Convert.ToInt32(BusinessLogic.ReadCarriersUsesByInstructorCarrierID(Convert.ToInt32(Instructor_comboBox.SelectedValue), Convert.ToInt32(ReplaceableCarriers_dataGridView.SelectedRows[0].Cells["ID1Column"].Value)).CarriersUses[0]["ID"].ToString());
                if (dataRow != null)
                {
                    dataRow["CarrierUse"]           = CarrierUseID;
                    dataRow["CarrierReplacement"]   = SelectedReplacingCarrierID;
                    dataRow["DateBeginReplacement"] = Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date;
                    dataRow["DateEndReplacement"]   = Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date;
                }
                else
                {
                    replacementsCarriersDataTable.AddReplacementsCarriersRow((AutoschoolDataSet.CarriersUsesRow)carriersUsesDataTable.Rows.Find(CarrierUseID),
                                                                             (AutoschoolDataSet.CarriersRow)carriersDataTable.Rows.Find(SelectedReplacingCarrierID),
                                                                             Convert.ToDateTime(BeginReplacement_dateTimePicker.Text).Date,
                                                                             Convert.ToDateTime(EndReplacement_dateTimePicker.Text).Date);
                }
            }
        }
예제 #3
0
        private void AddEditStudent_FormClosing(object sender, FormClosingEventArgs e)
        {
            // проверку следует проводить только при нажатии кнопки "Сохранить"
            if (DialogResult == DialogResult.OK)
            {
                // используем обработку исключительных ситуаций для проверки
                // на правильность ввода и вывода информации об ошибках
                try
                {
                    if (Group_comboBox.SelectedIndex == -1)
                    {
                        Group_comboBox.Focus();
                        throw new Exception("Не выбрана группа курсанта");
                    }
                    if (Surname_textBox.Text.Trim() == "")
                    {
                        Surname_textBox.Focus();
                        throw new Exception("Не указана фамилия студента");
                    }
                    if (FirstName_textBox.Text.Trim() == "")
                    {
                        FirstName_textBox.Focus();
                        throw new Exception("Не указано имя студента");
                    }

                    /*if (PatronymicName_textBox.Text.Trim() == "")
                     * {
                     *  PatronymicName_textBox.Focus();
                     *  throw new Exception("Не указано отчество студента");
                     * }*/
                    if (PhoneNumber_maskedTextBox.Text.Trim() == "+7 (   )    -")
                    {
                        PhoneNumber_maskedTextBox.Focus();
                        throw new Exception("Не указан номер телефона студента");
                    }

                    /*if (PhoneNumber_maskedTextBox.Text.Trim().Contains(" "))
                     * {
                     *  PhoneNumber_maskedTextBox.Focus();
                     *  throw new Exception("Номер телефона не может содержать пробелы");
                     * }*/
                    AutoschoolDataSet TempDS = new AutoschoolDataSet();
                    TempDS = BusinessLogic.ReadInstructorByID(Convert.ToInt32(Instructor_comboBox.SelectedValue.ToString()));
                    if (TempDS.Instructors[0]["WorkStatusName"].ToString() != "Работает")
                    {
                        DialogResult result = MessageBox.Show("Вы выбрали отсутствующего инструктора. Вы уверены, что хотите продолжить?", "Выбор отсутствующего сотрудника", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (result == DialogResult.No)
                        {
                            e.Cancel = true;
                            return;
                        }
                    }
                    if (SelectedCarrierUseID == -1)
                    {
                        Instructor_comboBox.Focus();
                        throw new Exception("Не выбрана связка инструктора с транспортным средством. \nСначала выберите инструктора из списка, а затем выберите одну из его ТС в таблице ниже. ");
                    }
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message, "Ошибка");
                    e.Cancel = true;
                    return;
                }
                // редактирование
                if (dataRow != null)
                {
                    dataRow["Surname"]        = Surname_textBox.Text;
                    dataRow["FirstName"]      = FirstName_textBox.Text;
                    dataRow["PatronymicName"] = PatronymicName_textBox.Text;
                    dataRow["PhoneNumber"]    = PhoneNumber_maskedTextBox.Text;
                    dataRow["Retraining"]     = Retraining_checkBox.Checked;
                    dataRow["Group"]          = Group_comboBox.SelectedValue;
                    dataRow["CarrierUse"]     = SelectedCarrierUseID;
                    dataRow["Photo"]          = ImageByte /*memoryStream.ToArray()*/;
                }
                else //добавление
                {
                    dataSetForCarriersUses = BusinessLogic.ReadCarriersUsesByID(SelectedCarrierUseID);
                    carriersUsesDataTable  = dataSetForCarriersUses.CarriersUses;
                    studentsDataTable.AddStudentsRow(Surname_textBox.Text, FirstName_textBox.Text,
                                                     PatronymicName_textBox.Text, PhoneNumber_maskedTextBox.Text, Retraining_checkBox.Checked,
                                                     groupsDataTable[Group_comboBox.SelectedIndex], carriersUsesDataTable[0], /*memoryStream.ToArray()*/ ImageByte);
                }
            }
        }
 private void AddEditCarrierUse_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         try
         {
             if (Instructor_comboBox.SelectedIndex == -1)
             {
                 Instructor_comboBox.Focus();
                 throw new Exception("Не выбран инструктор");
             }
             if (SelectedCarrierID == -1)
             {
                 throw new Exception("Не выбрано ТС");
             }
             AutoschoolDataSet TempDS = new AutoschoolDataSet();
             TempDS = BusinessLogic.ReadInstructorByID(Convert.ToInt32(Instructor_comboBox.SelectedValue.ToString()));
             if (TempDS.Instructors[0]["WorkStatusName"].ToString() != "Работает")
             {
                 DialogResult result = MessageBox.Show("Вы выбрали отсутствующего инструктора. Вы уверены, что хотите продолжить?", "Выбор отсутствующего сотрудника", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                 if (result == DialogResult.No)
                 {
                     e.Cancel = true;
                     return;
                 }
             }
             TempDS = BusinessLogic.ReadCarriersStatusesByID(Convert.ToInt32(Carriers_dataGridView["Status", Carriers_dataGridView.SelectedRows[0].Index].Value.ToString()));
             if (TempDS.CarriersStatuses[0][1].ToString() == "Резерв")
             {
                 throw new Exception("Нельзя назначить инструктору в качестве постоянного ТС то, которое является резервным");
             }
             TempDS = BusinessLogic.ReadInstructorsCategoriesByInstructorID(Convert.ToInt32(Instructor_comboBox.SelectedValue));
             bool Find = false;
             for (int i = 0; i < TempDS.InstructorsCategories.Rows.Count; i++)
             {
                 if (Convert.ToInt32(Carriers_dataGridView["CategoryColumn", Carriers_dataGridView.SelectedRows[0].Index].Value) == Convert.ToInt32(TempDS.InstructorsCategories.Rows[i][2].ToString()))
                 {
                     Find = true;
                     break;
                 }
             }
             if (!Find)
             {
                 throw new Exception("Выбранный инструктор не обладает категорией, необходимой для управления данным транспортным средством");
             }
             TempDS = BusinessLogic.ReadCarriersUsesByInstructorCarrierID(Convert.ToInt32(Instructor_comboBox.SelectedValue),
                                                                          SelectedCarrierID);
             if (dataRow == null)
             {
                 if (TempDS.CarriersUses.Rows.Count > 0)
                 {
                     throw new Exception("Такая связка между инструктором и транспортным средством уже существует");
                 }
             }
             else
             {
                 if (TempDS.CarriersUses.Rows.Count > 0 && TempDS.CarriersUses[0].ID.ToString() != dataRow[0].ToString())
                 {
                     throw new Exception("Такая связка между инструктором и транспортным средством уже существует");
                 }
             }
         }
         catch (Exception exp)
         {
             MessageBox.Show(exp.Message, "Ошибка");
             e.Cancel = true;
             return;
         }
         if (dataRow != null)
         {
             dataRow["Instructor"] = Instructor_comboBox.SelectedValue;
             dataRow["Carrier"]    = SelectedCarrierID;
         }
         else
         {
             carriersUsesDataTable.AddCarriersUsesRow(instructorsDataTable[Instructor_comboBox.SelectedIndex],
                                                      (AutoschoolDataSet.CarriersRow)carriersDataTable.Rows.Find(SelectedCarrierID));
         }
     }
 }