Exemplo n.º 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     btnNext.Visible = false;
     UpdateDb();
     (new Edit(owner)).ShowDialog();
     CourseDataSet.AcceptChanges();
     FillDb();
     this.Refresh();
 }
Exemplo n.º 2
0
        private void bthDel_Click(object sender, EventArgs e)
        {
            btnNext.Visible = false;
            try
            {
                if (MessageBox.Show("\tВы уверены?", "\tУдаление", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    switch (owner)
                    {
                    case "btnTrainees":
                        traineesTableAdapter.DeleteQuery(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                        break;

                    case "btnLectures":
                        lecturerTableAdapter.DeleteQuery(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                        break;

                    case "btnGroup":
                        groupTableAdapter.DeleteQuery(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                        break;

                    case "btnCourses":
                        courseTableAdapter.DeleteQuery(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                        break;

                    case "btnExams":
                        examTableAdapter.DeleteQuery(dataGridView1.SelectedRows[0].Cells[2].Value.ToString(), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[1].Value), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                        break;

                    case "btnDiscipline":
                        disciplineTableAdapter.DeleteQuery(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                        break;

                    case "btnPayment":
                        paymentTableAdapter.DeleteQuery(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[1].Value));
                        break;

                    case "btnTimeSheet":
                        timeSheetTableAdapter.DeleteQuery(Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                        break;
                    }
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("\tПожалуйста, удалите сначала все связанные данные", "Ошибка удаления");
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show("\tПожалуйста, выберите данные", "\tОшибка");
            }
            CourseDataSet.AcceptChanges();
            FillDb();
            this.Refresh();
        }
Exemplo n.º 3
0
Arquivo: Edit.cs Projeto: kaonkit/DB
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("\tВы уверены?", "\tУдаление", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    using (SqlConnection sqlCon = new SqlConnection(Main.Connection))
                    {
                        sqlCon.Open();

                        if (!forEdit)
                        {
                            switch (owner)
                            {
                            case "btnTrainees":
                                traineesTableAdapter.Insert(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    ((DateTimePicker)Controls[4]).Value,
                                    Controls[5].Text,
                                    Controls[6].Text
                                    );
                                break;

                            case "btnLectures":
                                lecturerTableAdapter.Insert(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    Int32.Parse(Controls[4].Text),
                                    Controls[5].Text,
                                    Controls[6].Text
                                    );
                                break;

                            case "btnGroup":
                                groupTableAdapter.Insert(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    Int32.Parse(Controls[4].Text));
                                break;

                            case "btnCourses":
                                courseTableAdapter.Insert(
                                    Controls[2].Text,
                                    Controls[3].Text);
                                break;

                            case "btnExams":
                                examTableAdapter.Insert(
                                    Int32.Parse(Controls[6].Text.Substring(4)),
                                    Int32.Parse(Controls[3].Text),
                                    ((DateTimePicker)Controls[4]).Value,
                                    Int32.Parse(Controls[5].Text));
                                break;

                            case "btnDiscipline":
                                disciplineTableAdapter.Insert(
                                    Controls[2].Text,
                                    Int32.Parse(Controls[3].Text),
                                    Controls[5].Text);
                                break;

                            case "btnPayment":
                                paymentTableAdapter.Insert(
                                    Int32.Parse(Controls[6].Text.Substring(4)),
                                    Int32.Parse(Controls[3].Text),
                                    ((DateTimePicker)Controls[4]).Value,
                                    Int32.Parse(Controls[5].Text));
                                break;

                            case "btnTimeSheet":
                                timeSheetTableAdapter.Insert(
                                    Int32.Parse(Controls[2].Text),
                                    Int32.Parse(Controls[7].Text.Substring(4)),
                                    Controls[4].Text,
                                    Int32.Parse(Controls[5].Text),
                                    Int32.Parse(Controls[6].Text));
                                break;
                            }
                        }
                        else
                        {
                            switch (owner)
                            {
                            case "btnTrainees":
                                traineesTableAdapter.UpdateQuery(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    ((DateTimePicker)Controls[4]).Value,
                                    Controls[5].Text,
                                    Controls[6].Text,
                                    Int32.Parse(id));
                                break;

                            case "btnLectures":
                                lecturerTableAdapter.UpdateQuery(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    Int32.Parse(Controls[4].Text),
                                    Controls[5].Text,
                                    Controls[6].Text,
                                    Int32.Parse(id));
                                break;

                            case "btnGroup":
                                groupTableAdapter.UpdateQuery(
                                    Controls[2].Text,
                                    Controls[3].Text,
                                    Int32.Parse(Controls[4].Text));
                                break;

                            case "btnCourses":
                                courseTableAdapter.UpdateQuery(
                                    Controls[2].Text,
                                    Controls[3].Text);
                                break;

                            case "btnExams":
                                examTableAdapter.UpdateQuery(
                                    Int32.Parse(Controls[6].Text.Substring(4)),
                                    Int32.Parse(Controls[3].Text),
                                    ((DateTimePicker)Controls[4]).Value.ToString(),
                                    Int32.Parse(Controls[5].Text));
                                break;

                            case "btnDiscipline":
                                disciplineTableAdapter.UpdateQuery(
                                    Controls[2].Text.Trim(),
                                    Int32.Parse(Controls[3].Text),
                                    Controls[5].Text,
                                    Int32.Parse(id));
                                break;

                            case "btnPayment":
                                paymentTableAdapter.UpdateQuery(
                                    Int32.Parse(Controls[6].Text.Substring(4)),
                                    Int32.Parse(Controls[3].Text),
                                    ((DateTimePicker)Controls[4]).Value.ToString(),
                                    Int32.Parse(Controls[5].Text));
                                break;

                            case "btnTimeSheet":
                                timeSheetTableAdapter.UpdateQuery(
                                    Int32.Parse(Controls[2].Text),
                                    Int32.Parse(Controls[7].Text.Substring(4)),
                                    Controls[4].Text,
                                    Int32.Parse(Controls[5].Text),
                                    Int32.Parse(Controls[6].Text),
                                    Int32.Parse(id));
                                break;
                            }
                        }
                        CourseDataSet.AcceptChanges();
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(@"Error: " + ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            btnNext.Visible = false;
            object[] args = null;
            UpdateDb();
            try
            {
                switch (owner)
                {
                case "btnTrainees":
                    var st = new CourseDataSet.TraineesDataTable();
                    traineesTableAdapter.FillBy(st, Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                    args = st.Rows[0].ItemArray;
                    break;

                case "btnLectures":
                    var st1 = new CourseDataSet.LecturerDataTable();
                    lecturerTableAdapter.FillBy(st1, Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                    args = st1.Rows[0].ItemArray;
                    break;

                case "btnGroup":
                    var st2 = new CourseDataSet.GroupDataTable();
                    groupTableAdapter.FillBy(st2, dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                    args = st2.Rows[0].ItemArray;
                    break;

                case "btnCourses":
                    var st3 = new CourseDataSet.CourseDataTable();
                    courseTableAdapter.FillBy(st3, dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                    args = st3.Rows[0].ItemArray;
                    break;

                case "btnExams":
                    var st4 = new CourseDataSet.ExamDataTable();
                    examTableAdapter.FillBy(st4, dataGridView1.SelectedRows[0].Cells[2].Value.ToString(), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[1].Value), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                    args = st4.Rows[0].ItemArray;
                    break;

                case "btnDiscipline":
                    var st5 = new CourseDataSet.DisciplineDataTable();
                    disciplineTableAdapter.FillBy(st5, Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                    args = st5.Rows[0].ItemArray;
                    break;

                case "btnPayment":
                    var st6 = new CourseDataSet.PaymentDataTable();
                    paymentTableAdapter.FillBy(st6, Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value), Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[1].Value));
                    args = st6.Rows[0].ItemArray;
                    break;

                case "btnTimeSheet":
                    var st7 = new CourseDataSet.TimeSheetDataTable();
                    timeSheetTableAdapter.FillBy(st7, Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value));
                    args = st7.Rows[0].ItemArray;
                    break;
                }
                (new Edit(owner, args)).ShowDialog();
                CourseDataSet.AcceptChanges();
                FillDb();
                this.Refresh();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                MessageBox.Show("\tПожалуйста, выберите данные", "\tОшибка");
            }
        }