From f716bf0e54bb3a2da4af04f5826a7d46c452ffee Mon Sep 17 00:00:00 2001 From: EggMan20339 <99349302+EggMan20339@users.noreply.github.com> Date: Tue, 20 Feb 2024 17:26:44 -0500 Subject: [PATCH] made cmuPrescription Edit pull data --- .../PharmacyDataTier.cs | 39 ++++ .../frmInfo.Designer.cs | 4 +- Louis'-Pharmacy_CNSA212-FP/frmInfo.cs | 210 +++++++++++------- Louis'-Pharmacy_CNSA212-FP/frmPrescription.cs | 14 ++ 4 files changed, 183 insertions(+), 84 deletions(-) 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 4773895..d59d10c 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs @@ -968,19 +968,21 @@ 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 // this.cmuPrescription.ImageScalingSize = new System.Drawing.Size(20, 20); this.cmuPrescription.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.cmuPrescriptionNew, this.cmuPrescriptionEdit, this.cmuPrescriptionDelete, this.cmuPrescriptionRefillThis, this.cmuPrescriptionViewRefills }); this.cmuPrescription.Name = "cmuPrescription"; - this.cmuPrescription.Size = new System.Drawing.Size(244, 136); + this.cmuPrescription.Size = new System.Drawing.Size(244, 114); // // cmuPrescriptionNew // diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs index fea7ea7..cfdc05d 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; @@ -706,5 +745,10 @@ 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) {