private void dgvMedicine_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (((DataGridView)sender).Columns[e.ColumnIndex].CellType == typeof(DataGridViewImageCell) && dgvMedicine.Columns[e.ColumnIndex].Name == "Delete" && e.RowIndex >= 0) { var confirmResult = MessageBox.Show("هل انت متأكد من مسح هذا الدواء؟", "تأكيد المسح", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { int id; if (int.TryParse(dgvMedicine.Rows[e.RowIndex].Cells["Id"].Value.ToString(), out id)) { Medicine Medicine = medicineRepository.Find(id); if (Medicine != null) { medicineRepository.Remove(id); medicineRepository.save(); Invoke(new Action(() => { FillDataGridView(); })); } else { MessageBox.Show("خطأ "); } } else { MessageBox.Show("اختيار خطأ"); } } } }
private void btadd_Click(object sender, EventArgs e) { Medicine medicine = new Medicine(); medicine.Name = txtMName.Text; medicine.ConcentrationOfTheDrug = Convert.ToInt32(txtMConceration.Text); medicine.FinishDate = txtMEnd.Text; medicine.Quantity = Convert.ToInt32(txtMQuantity.Text); medicine.TimesPerDay = Convert.ToInt32(txtMTimesPerDay.Text); MedicineRepository medicineRepository = new MedicineRepository(); medicineRepository.Add(medicine); medicineRepository.save(); FillDataGridView(); }
private void btadd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMedcineName.Text) || txtMedcineName.Text.Length < 3) { return; } Medicine medicine = new Medicine(); medicine.Name = txtMedcineName.Text; medicine.ConcentrationOfTheDrug = Convert.ToInt32(txtMedcineConceration.Text); medicine.Quantity = 3; medicine.TimesPerDay = 4; MedicineRepository medicineRepository = new MedicineRepository(); medicineRepository.Add(medicine); medicineRepository.save(); FillDataGridView(); txtMedcineName.Clear(); txtMedcineConceration.Clear(); }