コード例 #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;
                    }

                    Component newComponent = db.data.Components.Find(id);

                    var newComponentForm = new NewComponentForm();
                    newComponentForm.ComponentNameTextBox.Text = newComponent.PartName;

                    do
                    {
                        DialogResult result = newComponentForm.ShowDialog(this);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }

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

                    newComponent.PartName = newComponentForm.ComponentNameTextBox.Text;

                    db.data.Entry(newComponent).State = EntityState.Modified;
                    db.data.SaveChanges();
                    dataGridView1.Refresh();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Some error occured: " + exception.Message + " - " + exception.Source);
                throw;
            }
        }
コード例 #2
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var newComponentForm = new NewComponentForm();

                do
                {
                    DialogResult result = newComponentForm.ShowDialog(this);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

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

                Component newComponent = new Component();
                newComponent.PartName = newComponentForm.ComponentNameTextBox.Text;

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