Пример #1
0
        private void buttonEneter_Click(object sender, EventArgs e)
        {
            try
            {
                bool dataread = false;
                foreach (workload_of_teachersDataSet.SpecialnostRow specialnost in workload_of_teachersDataSet.Specialnost)
                {
                    if (DataRowState.Added == specialnost.RowState)
                    {
                        specialnostTableAdapter.Insert(specialnost.Nazvanie, specialnost.NazvaniePolnoe, specialnost.Code);
                        dataread = true;
                    }
                    if (DataRowState.Modified == specialnost.RowState)
                    {
                        specialnostTableAdapter.Update(specialnost.Nazvanie, specialnost.NazvaniePolnoe, specialnost.Code,
                                                       (int)specialnost["IdSpecialnost", DataRowVersion.Original], (string)specialnost["Nazvanie", DataRowVersion.Original], (string)specialnost["NazvaniePolnoe", DataRowVersion.Original], (string)specialnost["Code", DataRowVersion.Original]);
                        dataread = true;
                    }
                    if (DataRowState.Deleted == specialnost.RowState)
                    {
                        //=================== [ Каскадное удаление ] =================
                        int    idspecialnost       = (int)specialnost["IdSpecialnost", DataRowVersion.Original];
                        string specialnostnazvanie = (string)specialnost["Nazvanie", DataRowVersion.Original];
                        //Predmet
                        workload_of_teachersDataSetTableAdapters.PredmetTableAdapter          predmettableadapter          = new workload_of_teachersDataSetTableAdapters.PredmetTableAdapter();
                        workload_of_teachersDataSetTableAdapters.Predmet_CourseTableAdapter   predmet_coursetableadapter   = new workload_of_teachersDataSetTableAdapters.Predmet_CourseTableAdapter();
                        workload_of_teachersDataSetTableAdapters.Predmet_SemesterTableAdapter predmet_semestertableadapter = new workload_of_teachersDataSetTableAdapters.Predmet_SemesterTableAdapter();
                        predmettableadapter.FillByCascading(workload_of_teachersDataSet.Predmet, idspecialnost, -1);

                        foreach (workload_of_teachersDataSet.PredmetRow predmet in workload_of_teachersDataSet.Predmet)
                        {
                            workload_of_teachersDataSet workload_Of_TeachersDataSetTemp = new workload_of_teachersDataSet();
                            predmet_coursetableadapter.FillByIDPredmet(workload_Of_TeachersDataSetTemp.Predmet_Course, predmet.IdPredmet);
                            workload_of_teachersDataSet.Predmet_Course.Merge(workload_Of_TeachersDataSetTemp.Predmet_Course);
                        }
                        //Practice
                        workload_of_teachersDataSetTableAdapters.PracticeTableAdapter          practicetableadapter          = new workload_of_teachersDataSetTableAdapters.PracticeTableAdapter();
                        workload_of_teachersDataSetTableAdapters.Practice_SemesterTableAdapter practice_semestertableadapter = new workload_of_teachersDataSetTableAdapters.Practice_SemesterTableAdapter();
                        practicetableadapter.FillByCascading(workload_of_teachersDataSet.Practice, idspecialnost, -1, -1, -1);

                        //Gryppa
                        workload_of_teachersDataSetTableAdapters.GryppaTableAdapter gryppatableadapter = new workload_of_teachersDataSetTableAdapters.GryppaTableAdapter();
                        gryppatableadapter.FillByCascading(workload_of_teachersDataSet.Gryppa, idspecialnost, -1, -1, -1);

                        if (workload_of_teachersDataSet.Predmet.Count > 0 || workload_of_teachersDataSet.Practice.Count > 0 || workload_of_teachersDataSet.Gryppa.Count > 0)
                        {
                            workload_of_teachersDataSetTableAdapters.Load_PrepodTableAdapter load_prepodtableadapter = new workload_of_teachersDataSetTableAdapters.Load_PrepodTableAdapter();
                            foreach (workload_of_teachersDataSet.Predmet_CourseRow predmet_course in workload_of_teachersDataSet.Predmet_Course)
                            {
                                workload_of_teachersDataSet workload_Of_TeachersDataSetTemp = new workload_of_teachersDataSet();
                                load_prepodtableadapter.FillByCascading(workload_Of_TeachersDataSetTemp.Load_Prepod, -1, predmet_course.IdPredmet_Course, -1);
                                workload_of_teachersDataSet.Load_Prepod.Merge(workload_Of_TeachersDataSetTemp.Load_Prepod);
                            }
                            foreach (workload_of_teachersDataSet.PracticeRow practice in workload_of_teachersDataSet.Practice)
                            {
                                workload_of_teachersDataSet workload_Of_TeachersDataSetTemp = new workload_of_teachersDataSet();
                                load_prepodtableadapter.FillByCascading(workload_Of_TeachersDataSetTemp.Load_Prepod, -1, -1, practice.IdPractice);
                                workload_of_teachersDataSet.Load_Prepod.Merge(workload_Of_TeachersDataSetTemp.Load_Prepod);
                            }
                            foreach (workload_of_teachersDataSet.GryppaRow gryppa in workload_of_teachersDataSet.Gryppa)
                            {
                                workload_of_teachersDataSet workload_Of_TeachersDataSetTemp = new workload_of_teachersDataSet();
                                load_prepodtableadapter.FillByCascading(workload_Of_TeachersDataSetTemp.Load_Prepod, gryppa.IdGryppa, -1, -1);
                                workload_of_teachersDataSet.Load_Prepod.Merge(workload_Of_TeachersDataSetTemp.Load_Prepod);
                            }
                            FormDialog form = new FormDialog("Каскадное удаление специальности", String.Format("Удаление специальности {0} приведёт к удалению {1} предметов(а), {2} практик(и) и {3} групп(ы) принадлежащей этой специальности. Также будут удалены {4} педагогических(ая) нагрузок(а) преподавателей(я).",
                                                                                                               specialnostnazvanie, workload_of_teachersDataSet.Predmet.Count, workload_of_teachersDataSet.Practice.Count, workload_of_teachersDataSet.Gryppa.Count, workload_of_teachersDataSet.Load_Prepod.Count), 5);
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                //Load_Prepod Delete
                                foreach (workload_of_teachersDataSet.Load_PrepodRow load_prepod in workload_of_teachersDataSet.Load_Prepod)
                                {
                                    load_prepodtableadapter.DeleteQuery(load_prepod.IdLoad_Prepod);
                                }
                                //Predmet Delete
                                foreach (workload_of_teachersDataSet.PredmetRow predmet in workload_of_teachersDataSet.Predmet)
                                {
                                    predmet_semestertableadapter.DeleteQueryPredmet(predmet.IdPredmet);
                                    predmet_coursetableadapter.DeleteQueryPredmet(predmet.IdPredmet);
                                    predmettableadapter.DeleteQuery(predmet.IdPredmet);
                                }
                                //Practice Delete
                                foreach (workload_of_teachersDataSet.PracticeRow practice in workload_of_teachersDataSet.Practice)
                                {
                                    practice_semestertableadapter.DeleteQueryPractice(practice.IdPractice);
                                    practicetableadapter.DeleteQuery(practice.IdPractice);
                                }
                                //Gryppa Delete
                                foreach (workload_of_teachersDataSet.GryppaRow gryppa in workload_of_teachersDataSet.Gryppa)
                                {
                                    gryppatableadapter.DeleteQuery(gryppa.IdGryppa);
                                }
                                specialnostTableAdapter.Delete((int)specialnost["IdSpecialnost", DataRowVersion.Original], (string)specialnost["Nazvanie", DataRowVersion.Original], (string)specialnost["NazvaniePolnoe", DataRowVersion.Original], (string)specialnost["Code", DataRowVersion.Original]);
                                dataread = true;
                            }
                        }
                        else
                        {
                            specialnostTableAdapter.Delete((int)specialnost["IdSpecialnost", DataRowVersion.Original], (string)specialnost["Nazvanie", DataRowVersion.Original], (string)specialnost["NazvaniePolnoe", DataRowVersion.Original], (string)specialnost["Code", DataRowVersion.Original]);
                            dataread = true;
                        }
                    }
                }
                if (dataread == true)
                {
                    this.DialogResult = DialogResult.OK;                  //Есть изменения
                }
                else
                {
                    this.DialogResult = DialogResult.Ignore; //Нету изменений
                }
                this.Close();
                //specialnostTableAdapter.Update(this.workload_of_teachersDataSet.Specialnost);
            }
            catch (Exception error)
            {
                MessageBox.Show("Сообщение об ошибке: " + error.Message + "\nПроверьте корректность вводимых данных, а также наличие соединения с базой данных. Если ошибка продолжает появляться обратитесь к системному администратору или к разработчику данной программы.", "Ошибка при сохранении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void buttonEneter_Click(object sender, EventArgs e)
        {
            try
            {
                bool dataread = false;
                foreach (workload_of_teachersDataSet.VidPracticeRow vidpractice in workload_of_teachersDataSet.VidPractice)
                {
                    if (DataRowState.Added == vidpractice.RowState)
                    {
                        vidPracticeTableAdapter.Insert(vidpractice.Nazvanie, vidpractice.NazvaniePolnoe, vidpractice.Type);
                        dataread = true;
                    }
                    if (DataRowState.Modified == vidpractice.RowState)
                    {
                        vidPracticeTableAdapter.Update(vidpractice.Nazvanie, vidpractice.NazvaniePolnoe, vidpractice.Type,
                                                       (int)vidpractice["IdVidPractice", DataRowVersion.Original], (string)vidpractice["Nazvanie", DataRowVersion.Original], (string)vidpractice["NazvaniePolnoe", DataRowVersion.Original], (bool)vidpractice["Type", DataRowVersion.Original]);
                        dataread = true;
                    }
                    if (DataRowState.Deleted == vidpractice.RowState)
                    {
                        //=================== [ Каскадное удаление ] =================
                        int    idvidpractice       = (int)vidpractice["IdVidPractice", DataRowVersion.Original];
                        string vidpracticenazvanie = (string)vidpractice["Nazvanie", DataRowVersion.Original];

                        //Practice
                        workload_of_teachersDataSetTableAdapters.PracticeTableAdapter          practicetableadapter          = new workload_of_teachersDataSetTableAdapters.PracticeTableAdapter();
                        workload_of_teachersDataSetTableAdapters.Practice_SemesterTableAdapter practice_semestertableadapter = new workload_of_teachersDataSetTableAdapters.Practice_SemesterTableAdapter();
                        practicetableadapter.FillByCascading(workload_of_teachersDataSet.Practice, -1, -1, -1, idvidpractice);

                        if (workload_of_teachersDataSet.Practice.Count > 0)
                        {
                            workload_of_teachersDataSetTableAdapters.Load_PrepodTableAdapter load_prepodtableadapter = new workload_of_teachersDataSetTableAdapters.Load_PrepodTableAdapter();
                            foreach (workload_of_teachersDataSet.PracticeRow practice in workload_of_teachersDataSet.Practice)
                            {
                                workload_of_teachersDataSet workload_Of_TeachersDataSetTemp = new workload_of_teachersDataSet();
                                load_prepodtableadapter.FillByCascading(workload_Of_TeachersDataSetTemp.Load_Prepod, -1, -1, practice.IdPractice);
                                workload_of_teachersDataSet.Load_Prepod.Merge(workload_Of_TeachersDataSetTemp.Load_Prepod);
                            }
                            FormDialog form = new FormDialog("Каскадное удаление вида практики", String.Format("Удаление вида практики {0} приведёт к удалению {1} практик(и) принадлежащей этому виду практик. Также будут удалены {2} педагогических(ая) нагрузок(а) преподавателей(я).",
                                                                                                               vidpracticenazvanie, workload_of_teachersDataSet.Practice.Count, workload_of_teachersDataSet.Load_Prepod.Count), 5);
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                //Load_Prepod Delete
                                foreach (workload_of_teachersDataSet.Load_PrepodRow load_prepod in workload_of_teachersDataSet.Load_Prepod)
                                {
                                    load_prepodtableadapter.DeleteQuery(load_prepod.IdLoad_Prepod);
                                }
                                //Practice Delete
                                foreach (workload_of_teachersDataSet.PracticeRow practice in workload_of_teachersDataSet.Practice)
                                {
                                    practice_semestertableadapter.DeleteQueryPractice(practice.IdPractice);
                                    practicetableadapter.DeleteQuery(practice.IdPractice);
                                }
                                vidPracticeTableAdapter.Delete((int)vidpractice["IdVidPractice", DataRowVersion.Original], (string)vidpractice["Nazvanie", DataRowVersion.Original], (string)vidpractice["NazvaniePolnoe", DataRowVersion.Original], (bool)vidpractice["Type", DataRowVersion.Original]);
                                dataread = true;
                            }
                        }
                        else
                        {
                            vidPracticeTableAdapter.Delete((int)vidpractice["IdVidPractice", DataRowVersion.Original], (string)vidpractice["Nazvanie", DataRowVersion.Original], (string)vidpractice["NazvaniePolnoe", DataRowVersion.Original], (bool)vidpractice["Type", DataRowVersion.Original]);
                            dataread = true;
                        }
                    }
                }
                if (dataread == true)
                {
                    this.DialogResult = DialogResult.OK;                  //Есть изменения
                }
                else
                {
                    this.DialogResult = DialogResult.Ignore; //Нету изменений
                }
                this.Close();
                //vidPracticeTableAdapter.Update(this.workload_of_teachersDataSet.VidPractice);
            }
            catch (Exception error)
            {
                MessageBox.Show("Сообщение об ошибке: " + error.Message + "\nПроверьте корректность вводимых данных, а также наличие соединения с базой данных. Если ошибка продолжает появляться обратитесь к системному администратору или к разработчику данной программы.", "Ошибка при сохранении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }