Partly created add/update functionality for the refill form.

This commit is contained in:
Adam McCane 2024-02-16 18:23:41 -05:00
parent e0d893f017
commit dbaaa9f097
3 changed files with 266 additions and 11 deletions

View File

@ -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();
}
}
} }
} }

View File

@ -39,12 +39,13 @@
this.txtMedicationID = new System.Windows.Forms.TextBox(); this.txtMedicationID = new System.Windows.Forms.TextBox();
this.txtRxNumber = new System.Windows.Forms.TextBox(); this.txtRxNumber = new System.Windows.Forms.TextBox();
this.btnAdd = new System.Windows.Forms.Button(); this.btnAdd = new System.Windows.Forms.Button();
this.lblPurpose = new System.Windows.Forms.Label();
this.SuspendLayout(); this.SuspendLayout();
// //
// lblRefillID // lblRefillID
// //
this.lblRefillID.AutoSize = true; 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.Name = "lblRefillID";
this.lblRefillID.Size = new System.Drawing.Size(47, 13); this.lblRefillID.Size = new System.Drawing.Size(47, 13);
this.lblRefillID.TabIndex = 0; this.lblRefillID.TabIndex = 0;
@ -53,7 +54,7 @@
// lblRefillDate // lblRefillDate
// //
this.lblRefillDate.AutoSize = true; 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.Name = "lblRefillDate";
this.lblRefillDate.Size = new System.Drawing.Size(59, 13); this.lblRefillDate.Size = new System.Drawing.Size(59, 13);
this.lblRefillDate.TabIndex = 1; this.lblRefillDate.TabIndex = 1;
@ -62,7 +63,7 @@
// lblPatientID // lblPatientID
// //
this.lblPatientID.AutoSize = true; 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.Name = "lblPatientID";
this.lblPatientID.Size = new System.Drawing.Size(57, 13); this.lblPatientID.Size = new System.Drawing.Size(57, 13);
this.lblPatientID.TabIndex = 2; this.lblPatientID.TabIndex = 2;
@ -71,7 +72,7 @@
// lblMedicationID // lblMedicationID
// //
this.lblMedicationID.AutoSize = true; 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.Name = "lblMedicationID";
this.lblMedicationID.Size = new System.Drawing.Size(76, 13); this.lblMedicationID.Size = new System.Drawing.Size(76, 13);
this.lblMedicationID.TabIndex = 3; this.lblMedicationID.TabIndex = 3;
@ -80,7 +81,7 @@
// lblRxNumber // lblRxNumber
// //
this.lblRxNumber.AutoSize = true; 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.Name = "lblRxNumber";
this.lblRxNumber.Size = new System.Drawing.Size(63, 13); this.lblRxNumber.Size = new System.Drawing.Size(63, 13);
this.lblRxNumber.TabIndex = 4; this.lblRxNumber.TabIndex = 4;
@ -88,35 +89,35 @@
// //
// txtRefillID // 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.Name = "txtRefillID";
this.txtRefillID.Size = new System.Drawing.Size(100, 20); this.txtRefillID.Size = new System.Drawing.Size(100, 20);
this.txtRefillID.TabIndex = 5; this.txtRefillID.TabIndex = 5;
// //
// txtRefillDate // 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.Name = "txtRefillDate";
this.txtRefillDate.Size = new System.Drawing.Size(100, 20); this.txtRefillDate.Size = new System.Drawing.Size(100, 20);
this.txtRefillDate.TabIndex = 6; this.txtRefillDate.TabIndex = 6;
// //
// txtPatientID // 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.Name = "txtPatientID";
this.txtPatientID.Size = new System.Drawing.Size(100, 20); this.txtPatientID.Size = new System.Drawing.Size(100, 20);
this.txtPatientID.TabIndex = 7; this.txtPatientID.TabIndex = 7;
// //
// txtMedicationID // 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.Name = "txtMedicationID";
this.txtMedicationID.Size = new System.Drawing.Size(100, 20); this.txtMedicationID.Size = new System.Drawing.Size(100, 20);
this.txtMedicationID.TabIndex = 8; this.txtMedicationID.TabIndex = 8;
// //
// txtRxNumber // 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.Name = "txtRxNumber";
this.txtRxNumber.Size = new System.Drawing.Size(100, 20); this.txtRxNumber.Size = new System.Drawing.Size(100, 20);
this.txtRxNumber.TabIndex = 9; this.txtRxNumber.TabIndex = 9;
@ -128,12 +129,24 @@
this.btnAdd.Size = new System.Drawing.Size(75, 23); this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 10; this.btnAdd.TabIndex = 10;
this.btnAdd.UseVisualStyleBackColor = true; 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 // frmRefillAdd
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.lblPurpose);
this.Controls.Add(this.btnAdd); this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtRxNumber); this.Controls.Add(this.txtRxNumber);
this.Controls.Add(this.txtMedicationID); this.Controls.Add(this.txtMedicationID);
@ -147,6 +160,7 @@
this.Controls.Add(this.lblRefillID); this.Controls.Add(this.lblRefillID);
this.Name = "frmRefillAdd"; this.Name = "frmRefillAdd";
this.Text = "frmRefillAdd"; this.Text = "frmRefillAdd";
this.Load += new System.EventHandler(this.frmRefillAdd_Load);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -165,5 +179,6 @@
private System.Windows.Forms.TextBox txtMedicationID; private System.Windows.Forms.TextBox txtMedicationID;
private System.Windows.Forms.TextBox txtRxNumber; private System.Windows.Forms.TextBox txtRxNumber;
private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.Label lblPurpose;
} }
} }

View File

@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Net.NetworkInformation;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -12,9 +13,92 @@ namespace Louis__Pharmacy_CNSA212_FP
{ {
public partial class frmRefillAdd : Form public partial class frmRefillAdd : Form
{ {
public frmRefillAdd() private static bool isAdd;
public frmRefillAdd(bool isNew)
{ {
isAdd = isNew;
InitializeComponent(); 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);
}
} }
} }
} }