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 FormPrescriptionDetail(Prescription pDetail,String userAction)
        {
            InitializeComponent();
            this.PDetail = pDetail;
            this.UserAction = userAction;
            SetPDetailForUpdate(pDetail);

        }
Beispiel #3
0
 public static int InsertPrescription(Prescription newP)
 {
     String sqlInsert = @"INSERT INTO PRESCRIPTION(STAFFID, PATIENTID, DATE)
                         VALUES        (@STAFFID,@PATIENTID,@DATE)";
     SqlParameter[] sqlParameters = { new SqlParameter("@STAFFID", newP.StaffID),
                                     new SqlParameter("@PATIENTID", newP.PatientID),
                                    new SqlParameter("@DATE",newP.Date)};
     return SqlResult.ExecuteNonQuery(sqlInsert, sqlParameters);
 }
Beispiel #4
0
 public static int UpdatePrescription(Prescription updateP)
 {
     string sqlUpdate = @"UPDATE       PRESCRIPTION
                         SET                PATIENTID =@PATIENTID, DATE =@DATE
                         WHERE         PRESCRIPTIONID=@PRESCRIPTIONID ";
     SqlParameter[] sqlParameters = { new SqlParameter("@PRESCRIPTIONID", updateP.PrescriptionID),
                                     new SqlParameter("@PATIENTID", updateP.PatientID),
                                    new SqlParameter("@DATE", updateP.Date)};
     return SqlResult.ExecuteNonQuery(sqlUpdate, sqlParameters);
 }
Beispiel #5
0
 public static Prescription GetPrescription(int pID)
 {
     Prescription newPrescription = new Prescription();
     string sqlSelect = @"SELECT        PRESCRIPTIONID, STAFFID, PATIENTID, DATE
                         FROM            PRESCRIPTION
                         WHERE        PRESCRIPTIONID=@PRESCRIPTIONID";
     SqlParameter[] sqlParameters = { new SqlParameter("@PRESCRIPTIONID", pID) };
     DataTable dataTable = SqlResult.ExecuteQuery(sqlSelect, sqlParameters);
     if (dataTable.Rows.Count > 0)
     {
         newPrescription.PrescriptionID = Convert.ToInt32(dataTable.Rows[0][0]);
         newPrescription.StaffID = Convert.ToInt32(dataTable.Rows[0][1]);
         newPrescription.PatientID = Convert.ToInt32(dataTable.Rows[0][2]);
         newPrescription.Date = DateTime.Parse(dataTable.Rows[0][3].ToString());
     }
     return newPrescription;
 }
 public FormPrescriptionDetail(Prescription pDetail)
 {
     InitializeComponent();
     this.PDetail = pDetail;
 }
 private void buttonOk_Click(object sender, EventArgs e)
 {
     
     try 
     {
         Prescription newPrescription = new Prescription();
         newPrescription.Date = dateCreate.Value;
         newPrescription.PatientID = int.Parse(textBoxPatientID.Text);
         newPrescription.StaffID = int.Parse(textBoxStaffID.Text);
         if(this.UserAction=="edit")
         {
             newPrescription.PrescriptionID = Convert.ToInt32(textBoxPrescriptionID.Text);
             DialogResult dialogResult = MessageBox.Show("Xác nhận cập nhập thông tin toa thuốc", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
             if (dialogResult == DialogResult.OK)
             {
                 if (Prescription.UpdatePrescription(newPrescription) > 0)
                 {
                     PrescriptionDetail.DeletePrescriptionDetail(newPrescription.PrescriptionID);
                     for (int i = 0; i < listDP.Count; i++)
                     {
                         PrescriptionDetail newPD = listDP[i];
                         newPD.PrescriptionID = Convert.ToInt32(textBoxPrescriptionID.Text);
                         PrescriptionDetail.InsertPrescriptionDetail(newPD);
                     }
                     listDP.Clear();
                     MessageBox.Show("Cập nhập thông tin toa thuốc thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
         }
         else
         {
             newPrescription.PrescriptionID = 0;
             if (Prescription.InsertPrescription(newPrescription) > 0)
             {
                 int prescriptionID = Prescription.GetPrescriptionInsertedID();
                 for (int i = 0; i < listDP.Count; i++)
                 {
                     listDP[i].PrescriptionID = prescriptionID;
                     PrescriptionDetail.InsertPrescriptionDetail(listDP[i]);
                 }
                 MessageBox.Show("Thêm toa thuốc thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 listDP.Clear();
             }
         }
     }
     catch
     {
         MessageBox.Show("Lỗi dữ liệu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     this.Close();
 }