Esempio n. 1
0
        private void AddTermButton_Click(object sender, EventArgs e)
        {
            AddTermForm addForm = new AddTermForm();
            string      value = "";
            string      commandText, fieldName;

            if (activeTable == "term")
            {
                addForm.Text += "семестру";
                fieldName     = "TermName";
            }
            else
            {
                addForm.Text += "дiсциплiни";
                fieldName     = "SubjectName";
            }
            addForm.ShowDialog();
            if (addForm.DialogResult == DialogResult.OK)
            {
                value = addForm.ValueTextBox.Text;
            }
            commandText = "INSERT INTO " + activeTable + "(" + fieldName + ") VALUES ('" + value + "')";
            ExecuteQuery(commandText);
            if (activeTable == "term")
            {
                ShowTerms();
            }
            else
            {
                ShowSubjects();
            }
        }
Esempio n. 2
0
 private void EditTermButton_Click(object sender, EventArgs e)
 {
     if (TermDataGrid.CurrentCell != null)
     {
         int         index = TermDataGrid.CurrentCell.RowIndex; // № по порядку в таблице представления
         int         ID    = (int)TermDataGrid[0, index].Value;
         string      commandText;
         string      fieldName    = activeTable == "term" ? "TermName" : "SubjectName";
         string      editingValue = Convert.ToString(TermDataGrid[1, index].Value);
         AddTermForm editForm     = new AddTermForm();
         if (activeTable == "term")
         {
             editForm.Text = "Редагування семестру";
         }
         else
         {
             editForm.Text = "Редагування дiсциплiни";
         }
         editForm.ValueTextBox.Text = editingValue;
         editForm.AddButton.Text    = "Зберегти";
         editForm.ShowDialog();
         if (editForm.DialogResult == DialogResult.OK)
         {
             commandText = "UPDATE " + activeTable + " SET " + fieldName + "=\n'" + editForm.ValueTextBox.Text + "' WHERE ID=" + Convert.ToString(ID);
             ExecuteQuery(commandText);
             if (activeTable == "term")
             {
                 ShowTerms();
             }
             else
             {
                 ShowSubjects();
             }
             TermDataGrid.ClearSelection();
             TermDataGrid[1, index].Selected = true;
         }
     }
     else
     {
         MessageBox.Show("Не обрано даних для редагування!", "Помилка!", MessageBoxButtons.OK);
     }
 }