Example #1
0
        private async void button1_Click(object sender, EventArgs e)
        {
            string name = textnamecrt.Text.Trim();

            if (name == "")
            {
                MessageBox.Show("Fill All Input", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (_db.DrugsTypes.Any(t => t.Name == name))
            {
                MessageBox.Show($"{name} already exits", "warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            DrugsType type = new DrugsType {
                Name = name
            };

            _db.DrugsTypes.Add(type);
            await _db.SaveChangesAsync();

            MessageBox.Show("Successfully added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;

            textnamecrt.Text = "";

            _cmb.Items.Clear();
            _cmb.Items.AddRange(_db.DrugsTypes.Select(dt => new CB_DrugsType
            {
                Id   = dt.Id,
                Name = dt.Name
            }).ToArray());
        }
Example #2
0
        private async void button1_Click(object sender, EventArgs e)
        {
            int       id   = ((CB_DrugsType)cmbdel.SelectedItem).Id;
            DrugsType type = _db.DrugsTypes.First(t => t.Id == id);

            type.Deleted = false;
            _db.DrugsTypes.Remove(type);
            await _db.SaveChangesAsync();

            cmbdel.Text = "";
            MessageBox.Show("Successfully deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }