private void buttonWriteEdDb_Click(object sender, EventArgs e) { try { EdPlanProcessor.EducationalPlan.Specialty.CodeSpecialty = this.textBoxCodeSpecialty.Text; EdPlanProcessor.EducationalPlan.Specialty.NameSpecialty = this.textBoxSpecialty.Text; EdPlanProcessor.EducationalPlan.Specialization.CodeSpecialization = this.textBoxCodeSpecialization.Text; EdPlanProcessor.EducationalPlan.Specialization.NameSpecialization = this.textBoxSpecialization.Text; EdPlanProcessor.EducationalPlan.Fgos = comboBoxFGOS.Text; EdPlanProcessor.EducationalPlan.LevelEducation = this.comboBoxLevelEducation.Text; EdPlanProcessor.EducationalPlan.Year = int.Parse(this.comboBoxYear.Text); DbWorker dbWorker = new DbWorker(connection); try { dbWorker.OpenDB(); } catch (TypeInitializationException error) { //MessageBox.Show(error.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } dbWorker.WriteEducationalPlanDB(EdPlanProcessor.EducationalPlan); dbWorker.WriteEducationalProgramsDB(EdPlanProcessor.ListEducationalPrograms, EdPlanProcessor.EducationalPlan.IdEducationalPlan); dbWorker.CloseDB(); } catch (System.NullReferenceException) { MessageBox.Show("Не удалось выполнить запись, проверьте корректность введенных данных. \nВозможно вы не выбрали один из файлов", "Ошибка при попытке записи", MessageBoxButtons.OK); } }
private void button5_Click(object sender, EventArgs e) { DbWorker dbWorker; OpenFileDialog ofdOpen = new OpenFileDialog(); if (ofdOpen.ShowDialog() != DialogResult.OK) return; dbWorker = new DbWorker("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofdOpen.FileName); ofdOpen.Dispose(); try { dbWorker.OpenDB(); } catch (TypeInitializationException error) { MessageBox.Show(error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } dbWorker.WriteEducationalPlanDB(EdPlanProcessor.EducationalPlan); dbWorker.CloseDB(); }