diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index 91f5b79..37ce6b5 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -530,6 +530,45 @@ namespace Louis__Pharmacy_CNSA212_FP myConn.Close(); } } + + public static DataSet PrescriptionInfoSearch(string rxID) + { + 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 = "%"; + cmdString.Parameters.Add("@physicianID", SqlDbType.VarChar, 8).Value = "%"; + cmdString.Parameters.Add("@medID", SqlDbType.VarChar, 8).Value = "%"; + // 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 NumberofRefills(string rxID) { diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs index c02ffb8..509006b 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs @@ -1010,12 +1010,14 @@ namespace Louis__Pharmacy_CNSA212_FP // dgvRx // this.dgvRx.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvRx.ContextMenuStrip = this.cmuPrescription; this.dgvRx.Location = new System.Drawing.Point(0, 236); this.dgvRx.Name = "dgvRx"; this.dgvRx.RowHeadersWidth = 51; this.dgvRx.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgvRx.Size = new System.Drawing.Size(730, 248); this.dgvRx.TabIndex = 0; + this.dgvRx.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvRx_CellContentClick); // // cmuPrescription // diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs index 0c59fb7..66b9ee7 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs @@ -53,6 +53,7 @@ namespace Louis__Pharmacy_CNSA212_FP private bool physicianIsActive; private bool patientIsActive; private bool medicationIsActive; + private bool prescriptionIsActive; private void frmInfoTabChange(object sender, EventArgs e) { @@ -61,6 +62,7 @@ namespace Louis__Pharmacy_CNSA212_FP patientIsActive = false; physicianIsActive = false; medicationIsActive = false; + prescriptionIsActive = false; if (tbcInfo.SelectedIndex == 0) @@ -75,6 +77,10 @@ namespace Louis__Pharmacy_CNSA212_FP { physicianIsActive = true; } + else if (tbcInfo.SelectedIndex == 3) + { + prescriptionIsActive = true; + } } @@ -108,6 +114,10 @@ namespace Louis__Pharmacy_CNSA212_FP { cmuMedicationDelete_Click(sender, e); } + if (prescriptionIsActive && e.KeyCode == Keys.Delete) + { + cmuPrescriptionDelete_Click(sender, e); + } @@ -121,6 +131,17 @@ namespace Louis__Pharmacy_CNSA212_FP else if (e.KeyCode == Keys.Enter && patientIsActive && dgvPatient.Focused) { cmuPatientEdit_Click(sender,e); + } + + // if data grid view is not focused, run the search function + if (e.KeyCode == Keys.Enter && prescriptionIsActive && !dgvPrescription.Focused) + { + btnPatientSearch_Click(sender,e); + } + // if data grid view is focused, run the edit function + else if (e.KeyCode == Keys.Enter && prescriptionIsActive && dgvPrescription.Focused) + { + cmuPrescriptionEdit_Click(sender,e); } @@ -242,84 +263,84 @@ namespace Louis__Pharmacy_CNSA212_FP } - //public void btnPrescriptionSearch_Click(object sender, EventArgs e) - //{ - // string medID = ""; - // string medicationName = ""; - - - // if (txtPrescriptionPatID.Text.Length+txtRxNumber.Text.Length > 0) - // { - - - // try - // { - - // medicationName = txtPrescriptionPatID.Text; - - // try - // { - - // medID = txtRxNumber.Text; - - // try - // { - - - // ds = PharmacyDataTier.MedicationInfoSearch(medID,medicationName); - - - // if (ds.Tables[0].Rows.Count > 0) // There is a record. - // { - // dgvRx.Visible = true; - // // Get data source. - // dgvRx.DataSource = ds.Tables[0]; - // dgvRx.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen; - - // // Set the row and column header styles. - // dgvRx.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; - // dgvRx.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(btnMedicationSearch, "Error Searching"); - - // } - - - // } - // catch (Exception exception) - // { - - // ep1.SetError(txtRxNumber, "Invalid Value"); - - // } - - // } - // catch (Exception exception) - // { - - // ep1.SetError(txtPrescriptionPatID, "Invalid Value"); - - // } - // } - - - // cmuMedicationEdit.Enabled = dgvRx.Rows.Count > 0; - // cmuMedicationDelete.Enabled = dgvRx.Rows.Count > 0; - - // dgvRx.Focus(); - - //} + // public void btnPrescriptionSearch_Click(object sender, EventArgs e) + // { + // string medID = ""; + // string medicationName = ""; + // + // + // if (txtPrescriptionPatID.Text.Length+txtRxNumber.Text.Length > 0) + // { + // + // + // try + // { + // + // medicationName = txtPrescriptionPatID.Text; + // + // try + // { + // + // medID = txtRxNumber.Text; + // + // try + // { + // + // + // ds = PharmacyDataTier.MedicationInfoSearch(medID,medicationName); + // + // + // if (ds.Tables[0].Rows.Count > 0) // There is a record. + // { + // dgvRx.Visible = true; + // // Get data source. + // dgvRx.DataSource = ds.Tables[0]; + // dgvRx.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen; + // + // // Set the row and column header styles. + // dgvRx.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; + // dgvRx.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(btnMedicationSearch, "Error Searching"); + // + // } + // + // + // } + // catch (Exception exception) + // { + // + // ep1.SetError(txtRxNumber, "Invalid Value"); + // + // } + // + // } + // catch (Exception exception) + // { + // + // ep1.SetError(txtPrescriptionPatID, "Invalid Value"); + // + // } + // } + // + // + // cmuMedicationEdit.Enabled = dgvRx.Rows.Count > 0; + // cmuMedicationDelete.Enabled = dgvRx.Rows.Count > 0; + // + // dgvRx.Focus(); + // + // } @@ -623,6 +644,24 @@ namespace Louis__Pharmacy_CNSA212_FP private void cmuPrescriptionEdit_Click(object sender, EventArgs e) { + + if (dgvRx.Rows.Count > 0) + { + + dgvRx.DataSource = ds.Tables[0]; + // Console.WriteLine( dgvPatient.SelectedRows.Count); + DataGridViewRow row = new DataGridViewRow(); + row = dgvRx.SelectedRows[0]; + string prescID = ""; + prescID = (row.Cells[0].Value).ToString(); + frmPrescription PrescriptionAdd = new frmPrescription(this, false); + PrescriptionAdd.MdiParent = MdiParent; + PrescriptionAdd.StartPosition = FormStartPosition.CenterScreen; + PrescriptionAdd.Show(); + PrescriptionAdd.Focus(); + PrescriptionAdd.FillPrescription(prescID); + + } } @@ -639,16 +678,16 @@ namespace Louis__Pharmacy_CNSA212_FP string patID = ""; - if (txtRxPatientID.Text.Length + txtRxNumber.Text.Length > 0) + if (txtRxPatientID.Text.Length + txtRxPrescriptionID.Text.Length + txtRxPhysicianID.Text.Length + txtRxMedicationID.Text.Length> 0) { try { - rxNum = txtRxPrescriptionID.Text; - medID = txtRxMedicationID.Text; - physID = txtRxPhysicianID.Text; - patID = txtRxPatientID.Text; + rxNum = txtRxPrescriptionID.Text; + medID = txtRxMedicationID.Text; + physID = txtRxPhysicianID.Text; + patID = txtRxPatientID.Text; @@ -749,6 +788,11 @@ namespace Louis__Pharmacy_CNSA212_FP } } + + private void dgvRx_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } } } } diff --git a/Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs b/Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs index aa53b3d..f05a744 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs @@ -65,6 +65,20 @@ namespace Louis__Pharmacy_CNSA212_FP txtCompletedRefills.Text = ds.Tables[0].Rows[0]["Completed_refills"].ToString(); txtMaxRefills.Text = ds.Tables[0].Rows[0]["Max_refills"].ToString(); } + public void FillPrescription(string rxNum) + { + var ds = new DataSet(); + var data = new PharmacyDataTier(); + + ds = PharmacyDataTier.PrescriptionInfoSearch(rxNum); + txtRxNum.Text = ds.Tables[0].Rows[0]["RxNum_id"].ToString(); + txtPatID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString(); + txtMedID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString(); + txtPhysName.Text = ds.Tables[0].Rows[0]["PrescribedBy"].ToString(); + txtPhysID.Text = ds.Tables[0].Rows[0]["Physician_id"].ToString(); + txtCompletedRefills.Text = ds.Tables[0].Rows[0]["pastNumRefills"].ToString(); + txtMaxRefills.Text = ds.Tables[0].Rows[0]["numRefills"].ToString(); + } private void btnCancel_Click(object sender, EventArgs e) {