diff --git a/Louis'-Pharmacy_CNSA212-FP/App.config b/Louis'-Pharmacy_CNSA212-FP/App.config index baa7298..57109bf 100644 --- a/Louis'-Pharmacy_CNSA212-FP/App.config +++ b/Louis'-Pharmacy_CNSA212-FP/App.config @@ -3,7 +3,7 @@ - diff --git a/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj b/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj index 4d4ce36..eac7e83 100644 --- a/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj +++ b/Louis'-Pharmacy_CNSA212-FP/Louis'-Pharmacy_CNSA212-FP.csproj @@ -34,6 +34,7 @@ + @@ -88,6 +89,7 @@ frmWelcome.cs + diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs new file mode 100644 index 0000000..c2d1a9d --- /dev/null +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -0,0 +1,135 @@ +using System; +using System.Configuration; +using System.Data; +using System.Windows.Forms; +using System.Data.SqlClient; +using System.Runtime.Versioning; + +namespace Louis__Pharmacy_CNSA212_FP +{ + public class PharmacyDataTier + { + + static String connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; + static SqlConnection myConn = new SqlConnection(connString); + static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand(); + + public static DataSet PatientInfoSearch(string id, string lname, string fname) + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "PatientInfoSearch"; + // Define input parameter + cmdString.Parameters.Add("@patientID", SqlDbType.VarChar, 6).Value = id; + cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 30).Value = lname; + cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 30).Value = fname; + // 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 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 static DataSet PhysicianInfoSearch(string fname,string lname, string phyID) + { + + + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "PhysicianInfoSearch"; + // Define input parameter + cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 11).Value = fname; + cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 8).Value = lname; + cmdString.Parameters.Add("@phyID", SqlDbType.VarChar, 8).Value = phyID; + // 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(); + } + } + + } +} \ No newline at end of file diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs index 397e575..247b07a 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.Designer.cs @@ -240,28 +240,14 @@ namespace Louis__Pharmacy_CNSA212_FP this.btnPatientSearch.TabIndex = 4; this.btnPatientSearch.Text = "Search"; this.btnPatientSearch.UseVisualStyleBackColor = false; + this.btnPatientSearch.Click += new System.EventHandler(this.btnPatientSearch_Click); // // dgvPatient // this.dgvPatient.AllowUserToAddRows = false; this.dgvPatient.AllowUserToDeleteRows = false; this.dgvPatient.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvPatient.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.pat_id, - this.FirstName, - this.LastName, - this.MiddleInitials, - this.City, - this.UsState, - this.Zip, - this.Ibs, - this.Height_feet, - this.Height_inches, - this.Ailment, - this.DOB, - this.PhoneNumber, - this.Gender, - this.Medications}); + this.dgvPatient.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.pat_id, this.FirstName, this.LastName, this.MiddleInitials, this.City, this.UsState, this.Zip, this.Ibs, this.Height_feet, this.Height_inches, this.Ailment, this.DOB, this.PhoneNumber, this.Gender, this.Medications }); this.dgvPatient.Location = new System.Drawing.Point(3, 3); this.dgvPatient.Name = "dgvPatient"; this.dgvPatient.ReadOnly = true; @@ -416,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 // @@ -455,14 +442,7 @@ namespace Louis__Pharmacy_CNSA212_FP this.dgvPrescription.AllowUserToAddRows = false; this.dgvPrescription.AllowUserToDeleteRows = false; this.dgvPrescription.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvPrescription.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.RxNum_id, - this.numRefills, - this.pastNumRefills, - this.PrescribedBy, - this.Physician_id, - this.Medication_id, - this.Patient_id}); + this.dgvPrescription.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.RxNum_id, this.numRefills, this.pastNumRefills, this.PrescribedBy, this.Physician_id, this.Medication_id, this.Patient_id }); this.dgvPrescription.Location = new System.Drawing.Point(3, 3); this.dgvPrescription.Name = "dgvPrescription"; this.dgvPrescription.Size = new System.Drawing.Size(652, 195); @@ -586,24 +566,14 @@ namespace Louis__Pharmacy_CNSA212_FP this.btnPhysicianSearch.TabIndex = 4; this.btnPhysicianSearch.Text = "Search"; this.btnPhysicianSearch.UseVisualStyleBackColor = true; + this.btnPhysicianSearch.Click += new System.EventHandler(this.btnPhysicianSearch_Click); // // dgvPhysician // this.dgvPhysician.AllowUserToAddRows = false; this.dgvPhysician.AllowUserToDeleteRows = false; this.dgvPhysician.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dgvPhysician.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Phys_id, - this.namefirst, - this.namelast, - this.initialsmiddle, - this.cit, - this.state, - this.zipp, - this.dobb, - this.numberphone, - this.gennder, - this.Specialty}); + this.dgvPhysician.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Phys_id, this.namefirst, this.namelast, this.initialsmiddle, this.cit, this.state, this.zipp, this.dobb, this.numberphone, this.gennder, this.Specialty }); this.dgvPhysician.Location = new System.Drawing.Point(3, 3); this.dgvPhysician.Name = "dgvPhysician"; this.dgvPhysician.ReadOnly = true; @@ -724,7 +694,6 @@ namespace Louis__Pharmacy_CNSA212_FP this.splcPhysician.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dgvPhysician)).EndInit(); this.ResumeLayout(false); - } #endregion diff --git a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs index 5b38cca..2d91add 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs @@ -8,15 +8,13 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -using Microsoft.VisualBasic; -using System.Configuration; -using System.Collections; -using System.Data.SqlClient; namespace Louis__Pharmacy_CNSA212_FP { public partial class frmInfo : Form { + private ErrorProvider ep1 = new ErrorProvider(); + public frmInfo() { InitializeComponent(); @@ -25,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) { @@ -36,5 +50,251 @@ namespace Louis__Pharmacy_CNSA212_FP { } + + private void btnPatientSearch_Click(object sender, EventArgs e) + { + string fname = ""; + string lname = ""; + string id = ""; + + DataSet ds = new DataSet(); + + if (txtPatientFirst.Text.Length + txtPatientLast.Text.Length + txtPatientID.Text.Length > 0) + { + + try + { + + fname = txtPatientFirst.Text; + + try + { + + lname = txtPatientLast.Text; + + try + { + + id = txtPatientID.Text; + + try + { + + + ds = PharmacyDataTier.PatientInfoSearch(id,lname,fname); + + + if (ds.Tables[0].Rows.Count > 0) // There is a record. + { + dgvPatient.Visible = true; + // Get data source. + dgvPatient.DataSource = ds.Tables[0]; + dgvPatient.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen; + + // Set the row and column header styles. + dgvPatient.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; + dgvPatient.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(btnPatientSearch, "Error Searching"); + + } + + + } + catch (Exception exception) + { + + ep1.SetError(txtPatientID, "Invalid Value"); + + } + + } + catch (Exception exception) + { + + ep1.SetError(txtPatientLast, "Invalid Value"); + + } + + } + catch (Exception exception) + { + ep1.SetError(txtPatientFirst, "Invalid Value"); + } + + } + + + } + + 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"); + + } + } + } + + private void btnPhysicianSearch_Click(object sender, EventArgs e) + { + string fname = ""; + string lname = ""; + string phyID = "";; + + DataSet ds = new DataSet(); + + if (txtPhysicianFirst.Text.Length+txtPhysicianLast.Text.Length+txtPhysicianID.Text.Length > 0) + { + + try + { + + fname = txtPhysicianFirst.Text; + + try + { + + lname = txtPhysicianLast.Text; + + try + { + + phyID = txtPhysicianID.Text; + + try + { + + + ds = PharmacyDataTier.PhysicianInfoSearch(fname, lname, phyID); + + + if (ds.Tables[0].Rows.Count > 0) // There is a record. + { + dgvPhysician.Visible = true; + // Get data source. + dgvPhysician.DataSource = ds.Tables[0]; + dgvPhysician.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen; + + // Set the row and column header styles. + dgvPhysician.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; + dgvPhysician.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(btnPhysicianSearch, "Error Searching"); + + } + + + } + catch (Exception exception) + { + + ep1.SetError(txtPhysicianID, "Invalid Value"); + + } + + } + catch (Exception exception) + { + + ep1.SetError(txtPhysicianLast, "Invalid Value"); + + } + + } + catch (Exception exception) + { + ep1.SetError(txtPhysicianFirst, "Invalid Value"); + } + + } + + } } }