diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index 365bb56..b3b51e3 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -51,6 +51,44 @@ namespace Louis__Pharmacy_CNSA212_FP } } + + public static DataSet PrescriptionInfoSearch(string rxID, string patientID) + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "PerscriptionInfoSearch"; + // Define input parameter + cmdString.Parameters.Add("@rxID", SqlDbType.VarChar, 11).Value = rxID; + cmdString.Parameters.Add("@patientID", SqlDbType.VarChar, 8).Value = patientID; + // adapter and dataset + SqlDataAdapter aAdapter = new SqlDataAdapter(); + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + // fill adapter + aAdapter.Fill(aDataSet); + + // return dataSet + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + public DataSet GetStudents(string StuID) { diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs index 91fd4ae..bf9189c 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs @@ -402,6 +402,7 @@ namespace Louis__Pharmacy_CNSA212_FP this.btnPrescriptionSearch.TabIndex = 4; this.btnPrescriptionSearch.Text = "Search"; this.btnPrescriptionSearch.UseVisualStyleBackColor = true; + this.btnPrescriptionSearch.Click += new System.EventHandler(this.btnPrescriptionSearch_Click); // // txtPrescriptionPatID // diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs index 6b2a686..d730c01 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs @@ -23,8 +23,24 @@ namespace Louis__Pharmacy_CNSA212_FP private void frmInfo_Load(object sender, EventArgs e) { + KeyPreview = true; + KeyDown += frmInfo_KeyDown; + } + private void frmInfo_KeyDown(object sender, KeyEventArgs e) + { + // esc not funtional + if (e.KeyCode == Keys.Escape) // Check if the pressed key is Escape + {this.Close(); // Close the form + } + + if (e.KeyCode == Keys.Enter){ + btnPatientSearch_Click(sender, e); + } + + } + private void addUpdatePatientAndPhysicianToolStripMenuItem_Click(object sender, EventArgs e) { @@ -121,5 +137,78 @@ namespace Louis__Pharmacy_CNSA212_FP } + + private void btnPrescriptionSearch_Click(object sender, EventArgs e) + { + string rxID = ""; + string patientID = ""; + + DataSet ds = new DataSet(); + + if (txtPrescriptionPatID.Text.Length+txtRxNumber.Text.Length > 0) + { + + + try + { + + patientID = txtPrescriptionPatID.Text; + + try + { + + rxID = txtRxNumber.Text; + + try + { + + + ds = PharmacyDataTier.PrescriptionInfoSearch(rxID, patientID); + + + if (ds.Tables[0].Rows.Count > 0) // There is a record. + { + dgvPrescription.Visible = true; + // Get data source. + dgvPrescription.DataSource = ds.Tables[0]; + dgvPrescription.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen; + + // Set the row and column header styles. + dgvPrescription.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; + dgvPrescription.ColumnHeadersDefaultCellStyle.BackColor = Color.Green; + } + else + { + dgvPatient.Visible = false; // Hide the DataGridView if no results are found. + MessageBox.Show("No records found."); + } + + + } + catch (Exception exception) + { + + ep1.SetError(btnPrescriptionSearch, "Error Searching"); + + } + + + } + catch (Exception exception) + { + + ep1.SetError(txtRxNumber, "Invalid Value"); + + } + + } + catch (Exception exception) + { + + ep1.SetError(txtPrescriptionPatID, "Invalid Value"); + + } + } + } } }