コード例 #1
0
        private void DrugViewDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (DrugViewDataGridView1.Columns[e.ColumnIndex].Name == "DrugDelete")
            {
                Drug drg = (Drug)this.DrugViewDataGridView1.CurrentCell.OwningRow.DataBoundItem;

                var confirmResult = MessageBox.Show($"Are you sure you want to delete {drg.Name}?",
                                                    "Confirm Deletion",
                                                    MessageBoxButtons.YesNo);

                if (confirmResult == DialogResult.Yes)
                {
                    try
                    {
                        this.drugs.Remove(drg);
                        DrugViewDataGridView1.DataSource = null;
                        DrugViewDataGridView1.DataSource = drugs;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Oops, unable to delete Drug.\n{ex.Message}");
                    }
                }
            }


            if (DrugViewDataGridView1.Columns[e.ColumnIndex].Name == "DrugEdit")
            {
                Drug drg = (Drug)this.DrugViewDataGridView1.CurrentCell.OwningRow.DataBoundItem;

                AddDrugForm editDrug     = new AddDrugForm(drg);
                var         actionResult = editDrug.ShowDialog(this);

                if (actionResult == DialogResult.OK || actionResult == DialogResult.Cancel)
                {
                    DrugViewDataGridView1.DataSource = null;
                    DrugViewDataGridView1.DataSource = drugs;
                }
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: miryb/MiryPharma
        private void AddDrugsButton_Click(object sender, EventArgs e)
        {
            AddDrugForm addDrug = new AddDrugForm(drugs);

            addDrug.ShowDialog();
        }