Esempio n. 1
0
        private void ViewTablebutton_Click(object sender, EventArgs e)
        {
            DataTable src_table;

            switch (ChooseTableComboBox.GetItemText(ChooseTableComboBox.SelectedItem))
            {
            case "faculties":
                src_table = UniDB.faculties;
                break;

            case "departments":
                src_table = UniDB.departments;
                break;

            case "teachers":
                src_table = UniDB.teachers;
                break;

            case "students":
                src_table = UniDB.students;
                break;

            case "grades":
                src_table = UniDB.grades;
                break;

            case "disciplines":
                src_table = UniDB.disciplines;
                break;

            case "stud_groups":
                src_table = UniDB.stud_groups;
                break;

            case "disciplines_teachers":
                src_table = UniDB.disciplines_teachers;
                break;

            default:       // "students_disciplines"
                src_table = UniDB.students_disciplines;
                break;
            }
            view_table_src.DataSource = src_table;

            BindingSource  view_table_colums = new BindingSource();
            IList <string> namesColums       = new List <string>();

            foreach (var colum in src_table.Columns)
            {
                namesColums.Add(colum.ToString());
            }
            view_table_colums.DataSource   = namesColums;
            view_table_src.Filter          = null;
            ChooseFieldComboBox.DataSource = view_table_colums;
        }
Esempio n. 2
0
        private void Updatebutton_Click(object sender, EventArgs e)
        {
            TableGridView.CurrentCell.Value = UpdatetextBox.Text;
            try
            {
                switch (ChooseTableComboBox.GetItemText(ChooseTableComboBox.SelectedItem))
                {
                case "faculties":
                    builder.DataAdapter      = faculties1;
                    faculties1.UpdateCommand = builder.GetUpdateCommand();
                    faculties1.Update(UniDB.faculties);
                    break;

                case "departments":
                    builder.DataAdapter        = departments1;
                    departments1.UpdateCommand = builder.GetUpdateCommand();
                    departments1.Update(UniDB.departments);
                    break;

                case "teachers":
                    builder.DataAdapter     = teachers1;
                    teachers1.UpdateCommand = builder.GetUpdateCommand();
                    teachers1.Update(UniDB.teachers);
                    break;

                case "students":
                    builder.DataAdapter     = students1;
                    students1.UpdateCommand = builder.GetUpdateCommand();
                    students1.Update(UniDB.students);
                    break;

                case "grades":
                    builder.DataAdapter   = grades1;
                    grades1.UpdateCommand = builder.GetUpdateCommand();
                    grades1.Update(UniDB.grades);
                    break;

                case "disciplines":
                    builder.DataAdapter        = disciplines1;
                    disciplines1.UpdateCommand = builder.GetUpdateCommand();
                    disciplines1.Update(UniDB.disciplines);
                    break;

                case "stud_groups":
                    builder.DataAdapter        = stud_groups1;
                    stud_groups1.UpdateCommand = builder.GetUpdateCommand();
                    stud_groups1.Update(UniDB.stud_groups);
                    break;

                case "disciplines_teachers":
                    builder.DataAdapter      = dis_teach1;
                    dis_teach1.UpdateCommand = builder.GetUpdateCommand();
                    dis_teach1.Update(UniDB.disciplines_teachers);
                    break;

                default:       // "students_disciplines"
                    builder.DataAdapter      = stud_disc1;
                    stud_disc1.UpdateCommand = builder.GetUpdateCommand();
                    stud_disc1.Update(UniDB.students_disciplines);
                    break;
                }
            }
            catch (SqlException ex)
            {
                for (int i = 0; i < ex.Errors.Count; i++)
                {
                    errorMessages.Append("Index #" + i + "\n" +
                                         "Message: " + ex.Errors[i].Message + "\n" +
                                         "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                                         "Source: " + ex.Errors[i].Source + "\n" +
                                         "Procedure: " + ex.Errors[i].Procedure + "\n");
                }
                MessageBox.Show(errorMessages.ToString());
            }
        }