private void btnConfirm_Click(object sender, EventArgs e) { DrugModel drug = new DrugModel(); for (int i = 0; i < dgvDrugList.RowCount - 1; i++) { if (i < listOfDrugs.Count) { drug.Id = listOfDrugs[i].Id; } else { drug.Id = new Guid(); } drug.ProductCode = Convert.ToInt32(dgvDrugList.Rows[i].Cells[0].Value); drug.Name = dgvDrugList.Rows[i].Cells[1].Value.ToString(); drug.Manufacturer = dgvDrugList.Rows[i].Cells[2].Value.ToString(); drug.Type = dgvDrugList.Rows[i].Cells[3].Value.ToString(); drug.Quantity = Convert.ToInt32(dgvDrugList.Rows[i].Cells[4].Value); drug.Price = Convert.ToInt32(dgvDrugList.Rows[i].Cells[5].Value); InstructionModel instruction = new InstructionModel(); instruction.Dose = dgvDrugList.Rows[i].Cells[6].Value.ToString(); string[] symptoms = dgvDrugList.Rows[i].Cells[7].Value.ToString().Split(' '); instruction.Symptoms = symptoms; string[] sideEffects = dgvDrugList.Rows[i].Cells[8].Value.ToString().Split(' '); instruction.SideEffects = sideEffects; instruction.Warning = dgvDrugList.Rows[i].Cells[9].Value.ToString(); instruction.Usage = dgvDrugList.Rows[i].Cells[10].Value.ToString(); drug.Instruction = instruction; FarmacyManager.Instance.upsertDrug(drug); this.Close(); } }
private void btnDelete_Click(object sender, EventArgs e) { DrugModel drug = new DrugModel(); var selectedRow = dgvDrugList.SelectedRows; for (int i = 0; i < selectedRow.Count; i++) { if (selectedRow[i].Index < listOfDrugs.Count) { drug.Id = listOfDrugs[selectedRow[i].Index].Id; drug.Name = selectedRow[i].Cells[1].Value.ToString(); drug.Manufacturer = selectedRow[i].Cells[2].Value.ToString(); drug.Type = selectedRow[i].Cells[3].Value.ToString(); drug.Quantity = Convert.ToInt32(selectedRow[i].Cells[4].Value); drug.Price = Convert.ToInt32(selectedRow[i].Cells[5].Value); InstructionModel instruction = new InstructionModel(); instruction.Dose = selectedRow[i].Cells[6].Value.ToString(); string[] symptoms = selectedRow[i].Cells[7].Value.ToString().Split(' '); instruction.Symptoms = symptoms; string[] sideEffects = selectedRow[i].Cells[8].Value.ToString().Split(' '); instruction.SideEffects = sideEffects; instruction.Warning = selectedRow[i].Cells[9].Value.ToString(); instruction.Usage = selectedRow[i].Cells[10].Value.ToString(); drug.Instruction = instruction; FarmacyManager.Instance.deleteDrug(drug); dgvDrugList.Rows.Clear(); fillList(); } } }