Ejemplo n.º 1
0
        private void AlertBtn_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGridView1.SelectedRows.Count > 0)
                {
                    int  index     = dataGridView1.SelectedRows[0].Index;
                    int  id        = 0;
                    bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);

                    if (!converted)
                    {
                        return;
                    }

                    Type newType = db.data.Types.Find(id);

                    var newTypeForm = new NewTypeForm();
                    newTypeForm.TypeNameTextBox.Text = newType.TypeName;
                    do
                    {
                        DialogResult result = newTypeForm.ShowDialog(this);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }

                        if (newTypeForm.TypeNameTextBox.Text.Trim() == "")
                        {
                            MessageBox.Show("Усі поля повинні бути заповнені!");
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    } while (true);


                    newType.TypeName = newTypeForm.TypeNameTextBox.Text;

                    db.data.Entry(newType).State = EntityState.Modified;
                    db.data.SaveChanges();
                    dataGridView1.Refresh();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Some error occured: " + exception.Message + " - " + exception.Source);
                throw;
            }
        }
Ejemplo n.º 2
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var newTypeForm = new NewTypeForm();
                do
                {
                    DialogResult result = newTypeForm.ShowDialog(this);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (newTypeForm.TypeNameTextBox.Text.Trim() == "")
                    {
                        MessageBox.Show("Усі поля повинні бути заповнені!");
                        continue;
                    }
                    else
                    {
                        break;
                    }
                } while (true);

                Type newType = new Type();
                newType.TypeName = newTypeForm.TypeNameTextBox.Text;

                db.data.Types.Add(newType);
                db.data.SaveChanges();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Some error occured: " + exception.Message + " - " + exception.Source);
                throw;
            }
        }