diff --git a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs index 28729aa..af1e6ba 100644 --- a/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs +++ b/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs @@ -248,5 +248,161 @@ namespace Louis__Pharmacy_CNSA212_FP } } + public static DataSet RefillSearch(string id) + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "SearchRefills"; + // Define input parameter + cmdString.Parameters.Add("@ID", SqlDbType.VarChar, 8).Value = id; + // 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 double GetNextRefillID() + { + try + { + // open connection + myConn.Open(); + //clear any parameters + cmdString.Parameters.Clear(); + // command + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + cmdString.CommandText = "GetNextRefillID"; + // Define input parameter + cmdString.Parameters.Add("@TableName", SqlDbType.NVarChar, 128).Value = "Refill"; + + object result = cmdString.ExecuteScalar(); + double value = 0; + try + { + value = Convert.ToDouble(result); + + } + catch (Exception e) + { + MessageBox.Show("Error Getting next Refill ID", "ERROR", MessageBoxButtons.OK); + } + + + // return dataSet + return value; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + + public DataSet AddRefill(string refillID, DateTime date, string patientID, string medicationID, string rxNum) + { + try + { + myConn.Open(); + + cmdString.Parameters.Clear(); + + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + + cmdString.CommandText = "AddNewRefill"; + + cmdString.Parameters.Add("@refillID", SqlDbType.Char, 10).Value = refillID; + cmdString.Parameters.Add("@date", SqlDbType.Date).Value = date; + cmdString.Parameters.Add("@patientID", SqlDbType.VarChar, 8).Value = patientID; + cmdString.Parameters.Add("@medicationID", SqlDbType.VarChar, 7).Value = medicationID; + cmdString.Parameters.Add("@rxNum", SqlDbType.VarChar, 11).Value = rxNum; + + SqlDataAdapter aAdapter = new SqlDataAdapter(); + + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + aAdapter.Fill(aDataSet); + + return aDataSet; + } + catch (Exception ex) + { + throw new ArgumentException(ex.Message); + } + finally + { + myConn.Close(); + } + } + + public DataSet UpdateRefill(string refillID, DateTime date, string patientID, string medicationID, string rxNum) + { + try + { + myConn.Open(); + + cmdString.Parameters.Clear(); + + cmdString.Connection = myConn; + cmdString.CommandType = CommandType.StoredProcedure; + cmdString.CommandTimeout = 1500; + + cmdString.CommandText = "UpdateRefills"; + + cmdString.Parameters.Add("@refillID", SqlDbType.Char, 10).Value = refillID; + cmdString.Parameters.Add("@date", SqlDbType.Date).Value = date; + cmdString.Parameters.Add("@patientID", SqlDbType.VarChar, 8).Value = patientID; + cmdString.Parameters.Add("@medicationID", SqlDbType.VarChar, 7).Value = medicationID; + cmdString.Parameters.Add("@rxNum", SqlDbType.VarChar, 11).Value = rxNum; + + SqlDataAdapter aAdapter = new SqlDataAdapter(); + + aAdapter.SelectCommand = cmdString; + DataSet aDataSet = new DataSet(); + + aAdapter.Fill(aDataSet); + + 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/frmRefillAdd.Designer.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.Designer.cs index 120a0ff..d510f44 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.Designer.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.Designer.cs @@ -39,12 +39,13 @@ this.txtMedicationID = new System.Windows.Forms.TextBox(); this.txtRxNumber = new System.Windows.Forms.TextBox(); this.btnAdd = new System.Windows.Forms.Button(); + this.lblPurpose = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblRefillID // this.lblRefillID.AutoSize = true; - this.lblRefillID.Location = new System.Drawing.Point(103, 75); + this.lblRefillID.Location = new System.Drawing.Point(99, 119); this.lblRefillID.Name = "lblRefillID"; this.lblRefillID.Size = new System.Drawing.Size(47, 13); this.lblRefillID.TabIndex = 0; @@ -53,7 +54,7 @@ // lblRefillDate // this.lblRefillDate.AutoSize = true; - this.lblRefillDate.Location = new System.Drawing.Point(103, 146); + this.lblRefillDate.Location = new System.Drawing.Point(99, 190); this.lblRefillDate.Name = "lblRefillDate"; this.lblRefillDate.Size = new System.Drawing.Size(59, 13); this.lblRefillDate.TabIndex = 1; @@ -62,7 +63,7 @@ // lblPatientID // this.lblPatientID.AutoSize = true; - this.lblPatientID.Location = new System.Drawing.Point(103, 221); + this.lblPatientID.Location = new System.Drawing.Point(99, 265); this.lblPatientID.Name = "lblPatientID"; this.lblPatientID.Size = new System.Drawing.Size(57, 13); this.lblPatientID.TabIndex = 2; @@ -71,7 +72,7 @@ // lblMedicationID // this.lblMedicationID.AutoSize = true; - this.lblMedicationID.Location = new System.Drawing.Point(425, 75); + this.lblMedicationID.Location = new System.Drawing.Point(421, 119); this.lblMedicationID.Name = "lblMedicationID"; this.lblMedicationID.Size = new System.Drawing.Size(76, 13); this.lblMedicationID.TabIndex = 3; @@ -80,7 +81,7 @@ // lblRxNumber // this.lblRxNumber.AutoSize = true; - this.lblRxNumber.Location = new System.Drawing.Point(425, 146); + this.lblRxNumber.Location = new System.Drawing.Point(421, 190); this.lblRxNumber.Name = "lblRxNumber"; this.lblRxNumber.Size = new System.Drawing.Size(63, 13); this.lblRxNumber.TabIndex = 4; @@ -88,35 +89,35 @@ // // txtRefillID // - this.txtRefillID.Location = new System.Drawing.Point(173, 75); + this.txtRefillID.Location = new System.Drawing.Point(169, 119); this.txtRefillID.Name = "txtRefillID"; this.txtRefillID.Size = new System.Drawing.Size(100, 20); this.txtRefillID.TabIndex = 5; // // txtRefillDate // - this.txtRefillDate.Location = new System.Drawing.Point(173, 146); + this.txtRefillDate.Location = new System.Drawing.Point(169, 190); this.txtRefillDate.Name = "txtRefillDate"; this.txtRefillDate.Size = new System.Drawing.Size(100, 20); this.txtRefillDate.TabIndex = 6; // // txtPatientID // - this.txtPatientID.Location = new System.Drawing.Point(173, 221); + this.txtPatientID.Location = new System.Drawing.Point(169, 265); this.txtPatientID.Name = "txtPatientID"; this.txtPatientID.Size = new System.Drawing.Size(100, 20); this.txtPatientID.TabIndex = 7; // // txtMedicationID // - this.txtMedicationID.Location = new System.Drawing.Point(517, 75); + this.txtMedicationID.Location = new System.Drawing.Point(513, 119); this.txtMedicationID.Name = "txtMedicationID"; this.txtMedicationID.Size = new System.Drawing.Size(100, 20); this.txtMedicationID.TabIndex = 8; // // txtRxNumber // - this.txtRxNumber.Location = new System.Drawing.Point(517, 146); + this.txtRxNumber.Location = new System.Drawing.Point(513, 190); this.txtRxNumber.Name = "txtRxNumber"; this.txtRxNumber.Size = new System.Drawing.Size(100, 20); this.txtRxNumber.TabIndex = 9; @@ -128,12 +129,24 @@ this.btnAdd.Size = new System.Drawing.Size(75, 23); this.btnAdd.TabIndex = 10; this.btnAdd.UseVisualStyleBackColor = true; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); + // + // lblPurpose + // + this.lblPurpose.AutoSize = true; + this.lblPurpose.Font = new System.Drawing.Font("Microsoft Sans Serif", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblPurpose.Location = new System.Drawing.Point(308, 43); + this.lblPurpose.Name = "lblPurpose"; + this.lblPurpose.Size = new System.Drawing.Size(106, 37); + this.lblPurpose.TabIndex = 11; + this.lblPurpose.Text = "label1"; // // frmRefillAdd // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.lblPurpose); this.Controls.Add(this.btnAdd); this.Controls.Add(this.txtRxNumber); this.Controls.Add(this.txtMedicationID); @@ -147,6 +160,7 @@ this.Controls.Add(this.lblRefillID); this.Name = "frmRefillAdd"; this.Text = "frmRefillAdd"; + this.Load += new System.EventHandler(this.frmRefillAdd_Load); this.ResumeLayout(false); this.PerformLayout(); @@ -165,5 +179,6 @@ private System.Windows.Forms.TextBox txtMedicationID; private System.Windows.Forms.TextBox txtRxNumber; private System.Windows.Forms.Button btnAdd; + private System.Windows.Forms.Label lblPurpose; } } \ No newline at end of file diff --git a/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs index 265080f..71a7f59 100644 --- a/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs +++ b/Louis'-Pharmacy_CNSA212-FP/frmRefillAdd.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -12,9 +13,92 @@ namespace Louis__Pharmacy_CNSA212_FP { public partial class frmRefillAdd : Form { - public frmRefillAdd() + private static bool isAdd; + + public frmRefillAdd(bool isNew) { + isAdd = isNew; InitializeComponent(); + + if (isNew) + { + lblPurpose.Text = "Add Refill"; + btnAdd.Text = "Add"; + } + else + { + lblPurpose.Text = "Edit Refill"; + btnAdd.Text = "Edit"; + } + } + + private void frmRefillAdd_Load(object sender, EventArgs e) + { + txtRefillID.Enabled = false; + string refillID = ""; + + if (isAdd) + { + double nextID = PharmacyDataTier.GetNextRefillID(); + txtRefillID.Text = nextID.ToString(); + } + else + { + DataSet ds = new DataSet(); + + txtRefillID.Text = ds.Tables[0].Rows[0]["Refill_id"].ToString(); + FillRefill(refillID); + } + } + + public void FillRefill(string refillID) + { + DataSet ds = new DataSet(); + PharmacyDataTier data = new PharmacyDataTier(); + + ds = PharmacyDataTier.RefillSearch(refillID); + txtRefillID.Text = ds.Tables[0].Rows[0]["Refill_id"].ToString(); + txtRefillDate.Text = ds.Tables[0].Rows[0]["RefillDate"].ToString(); + txtPatientID.Text = ds.Tables[0].Rows[0]["Patient_id"].ToString(); + txtMedicationID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString(); + txtRxNumber.Text = ds.Tables[0].Rows[0]["RxNum"].ToString(); + } + + private void btnAdd_Click(object sender, EventArgs e) + { + string refillID = ""; + DateTime date = new DateTime(); + string patientID = ""; + string medicationID = ""; + string rxNum = ""; + + if (isAdd) + { + refillID = txtRefillID.Text.Trim(); + date = DateTime.Parse(txtRefillDate.Text.Trim()); + patientID = txtPatientID.Text.Trim(); + medicationID= txtMedicationID.Text.Trim(); + rxNum = txtRxNumber.Text.Trim(); + + DataSet ds = new DataSet(); + PharmacyDataTier phaDT = new PharmacyDataTier(); + + ds = phaDT.AddRefill(refillID, date, patientID, medicationID, rxNum); + } + else + { + refillID = txtRefillID.Text.Trim(); + date = DateTime.Parse(txtRefillDate.Text.Trim()); + patientID = txtPatientID.Text.Trim(); + medicationID = txtMedicationID.Text.Trim(); + rxNum = txtRxNumber.Text.Trim(); + + DataSet ds = new DataSet(); + PharmacyDataTier phaDT = new PharmacyDataTier(); + + ds = phaDT.UpdateRefill(refillID, date, patientID, medicationID, rxNum); + } } } } +