private void SetPDetailForUpdate(Prescription pDetail) { textBoxPrescriptionID.Text = pDetail.PrescriptionID.ToString(); textBoxPatientID.Text = pDetail.PatientID.ToString(); textBoxStaffID.Text = pDetail.StaffID.ToString(); dateCreate.Value = pDetail.Date; DataTable dtMedicine = Medicine.GetListMedicine(); for (int i = 0; i < dtMedicine.Rows.Count; i++) { Medicine newMedicine = Medicine.GetMedicine(Convert.ToInt32(dtMedicine.Rows[i][0])); listMedicine.Add(newMedicine); comboBoxMedicine.Items.Add(newMedicine.MedicineName); comboBoxMedicine.AutoCompleteCustomSource.Add(newMedicine.MedicineName); } comboBoxMedicine.SelectedIndex = 0; DataTable dtPD = PrescriptionDetail.GetListPrescriptionDetail(pDetail.PrescriptionID); for (int i = 0; i < dtPD.Rows.Count; i++) { PrescriptionDetail newDP = new PrescriptionDetail(); newDP.PrescriptionID = Convert.ToInt32(dtPD.Rows[i][0]); newDP.MedicineID = Convert.ToInt32(dtPD.Rows[i][1]); newDP.Quantity = Convert.ToInt16(dtPD.Rows[i][2]); newDP.Instruction = dtPD.Rows[i][3].ToString(); listDP.Add(newDP); Medicine newMedicine = Medicine.GetMedicine(newDP.MedicineID); listSelectedMedicine.Items.Add(newMedicine.MedicineName); } if (listSelectedMedicine.Items.Count > 0) listSelectedMedicine.SelectedIndex = 0; }
public static int InsertPrescriptionDetail(PrescriptionDetail newPD) { String sqlInsert = @"INSERT INTO PRESCRIPTIONDETAIL(PRESCRIPTIONID, MEDICINEID, QUANTITY, INSTRUCTION) VALUES (@PRESCRIPTIONID,@MEDICINEID,@QUANTITY,@INSTRUCTION)"; SqlParameter[] sqlParameters = { new SqlParameter("@PRESCRIPTIONID", newPD.PrescriptionID), new SqlParameter("@MEDICINEID", newPD.MedicineID), new SqlParameter("@QUANTITY", newPD.Quantity), new SqlParameter("@INSTRUCTION", newPD.Instruction) }; return(SqlResult.ExecuteNonQuery(sqlInsert, sqlParameters)); }
public static int InsertPrescriptionDetail(PrescriptionDetail newPD) { String sqlInsert = @"INSERT INTO PRESCRIPTIONDETAIL(PRESCRIPTIONID, MEDICINEID, QUANTITY, INSTRUCTION) VALUES (@PRESCRIPTIONID,@MEDICINEID,@QUANTITY,@INSTRUCTION)"; SqlParameter[] sqlParameters = { new SqlParameter("@PRESCRIPTIONID", newPD.PrescriptionID), new SqlParameter("@MEDICINEID", newPD.MedicineID), new SqlParameter("@QUANTITY", newPD.Quantity), new SqlParameter("@INSTRUCTION",newPD.Instruction)}; return SqlResult.ExecuteNonQuery(sqlInsert, sqlParameters); }
private void buttonInsert_Click(object sender, EventArgs e) { if (!superValidator1.Validate()) return; if (listMedicine.Count > 0) { int selectedIndex = comboBoxMedicine.SelectedIndex; if (int.Parse(textBoxInputQuantity.Text) > listMedicine[selectedIndex].Quantity) MessageBox.Show("Số lượng thuốc không đáp ứng đủ nhu cầu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { PrescriptionDetail newPD = new PrescriptionDetail(listMedicine[selectedIndex].MedicineID, 0, int.Parse(textBoxInputQuantity.Text), textBoxInputInstruction.Text); if (DidPrescriptionHaveMedicine(newPD.MedicineID)) { for (int i = 0; i < listDP.Count; i++) { if (newPD.MedicineID == listDP[i].MedicineID) { listDP[i].Instruction = textBoxInputInstruction.Text; listDP[i].Quantity = int.Parse(textBoxInputQuantity.Text); listSelectedMedicine_SelectedIndexChanged(sender, e); textBoxInputInstruction.Text = ""; textBoxInputQuantity.Text = ""; break; } } } else { listDP.Add(newPD); listSelectedMedicine.Items.Add(listMedicine[selectedIndex].MedicineName); listSelectedMedicine.SelectedIndex = listSelectedMedicine.Items.Count - 1; textBoxInputInstruction.Text = ""; textBoxInputQuantity.Text = ""; } } } }