CNSA-212-FP/Louis'-Pharmacy_CNSA212-FP/PharmacyDataTier.cs

541 lines
19 KiB
C#
Raw Normal View History

2024-02-14 17:40:16 -05:00
using System;
using System.Configuration;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
2024-02-14 19:43:07 -05:00
using System.Runtime.Versioning;
2024-02-14 17:40:16 -05:00
namespace Louis__Pharmacy_CNSA212_FP
{
public class PharmacyDataTier
{
2024-02-14 17:40:16 -05:00
static String connString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
static SqlConnection myConn = new SqlConnection(connString);
static System.Data.SqlClient.SqlCommand cmdString = new System.Data.SqlClient.SqlCommand();
2024-02-16 13:57:58 -05:00
public static void UpdatePatient(
string Patient_id,
string FirstName,
string LastName,
string MiddleIntials,
int lbs,
int Height_feet,
int Height_inches,
DateTime DOB,
string Gender,
string City,
Int16 Zip,
string UsState,
string PhoneNumber)
{
try
{
myConn.Open();
cmdString.Parameters.Clear();
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "UpdatePatient";
cmdString.Parameters.Add("@Patient_id", SqlDbType.VarChar, 8).Value = Patient_id;
cmdString.Parameters.Add("@FirstName", SqlDbType.VarChar, 30).Value = FirstName;
cmdString.Parameters.Add("@LastName", SqlDbType.VarChar, 30).Value = LastName;
cmdString.Parameters.Add("@MiddleIntials", SqlDbType.VarChar).Value = MiddleIntials;
cmdString.Parameters.Add("@lbs", SqlDbType.Int).Value = lbs;
cmdString.Parameters.Add("@Height_feet", SqlDbType.Int).Value = Height_feet;
cmdString.Parameters.Add("@Height_inches", SqlDbType.Int).Value = Height_inches;
cmdString.Parameters.Add("@DOB", SqlDbType.DateTime).Value = DOB;
cmdString.Parameters.Add("@Gender", SqlDbType.Char).Value = Gender;
cmdString.Parameters.Add("@City", SqlDbType.VarChar, 30).Value = City;
cmdString.Parameters.Add("@Zip", SqlDbType.SmallInt).Value = Zip;
cmdString.Parameters.Add("@UsState", SqlDbType.Char, 2).Value = UsState;
cmdString.Parameters.Add("@PhoneNumber", SqlDbType.Char,14).Value = PhoneNumber;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static void CreatePatient(
string Patient_id,
string FirstName,
string LastName,
string MiddleIntials,
int lbs,
int Height_feet,
int Height_inches,
DateTime DOB,
string Gender,
string City,
Int16 Zip,
string UsState,
string PhoneNumber)
{
try
{
myConn.Open();
cmdString.Parameters.Clear();
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "CreatePatient";
cmdString.Parameters.Add("@Patient_id", SqlDbType.VarChar, 8).Value = Patient_id;
cmdString.Parameters.Add("@FirstName", SqlDbType.VarChar, 30).Value = FirstName;
cmdString.Parameters.Add("@LastName", SqlDbType.VarChar, 30).Value = LastName;
cmdString.Parameters.Add("@MiddleIntials", SqlDbType.VarChar).Value = MiddleIntials;
cmdString.Parameters.Add("@lbs", SqlDbType.Int).Value = lbs;
cmdString.Parameters.Add("@Height_feet", SqlDbType.Int).Value = Height_feet;
cmdString.Parameters.Add("@Height_inches", SqlDbType.Int).Value = Height_inches;
cmdString.Parameters.Add("@DOB", SqlDbType.DateTime).Value = DOB;
cmdString.Parameters.Add("@Gender", SqlDbType.Char).Value = Gender;
cmdString.Parameters.Add("@City", SqlDbType.VarChar, 30).Value = City;
cmdString.Parameters.Add("@Zip", SqlDbType.SmallInt).Value = Zip;
cmdString.Parameters.Add("@UsState", SqlDbType.Char, 2).Value = UsState;
cmdString.Parameters.Add("@PhoneNumber", SqlDbType.Char,14).Value = PhoneNumber;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static void DeletePatient(string Patient_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 = "DeletePatient";
// Define input parameter
cmdString.Parameters.Add("@Patient_id", SqlDbType.VarChar, 8).Value = Patient_id;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
2024-02-14 18:21:17 -05:00
public static DataSet PatientInfoSearch(string id, string lname, string fname)
2024-02-14 17:40:16 -05:00
{
try
{
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
2024-02-16 11:32:00 -05:00
cmdString.CommandText = "SearchPatients";
2024-02-14 17:40:16 -05:00
// Define input parameter
2024-02-16 11:32:00 -05:00
cmdString.Parameters.Add("@ID", SqlDbType.VarChar, 8).Value = id;
2024-02-14 18:21:17 -05:00
cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 30).Value = lname;
cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 30).Value = fname;
2024-02-14 17:40:16 -05:00
// 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();
}
}
2024-02-15 12:04:26 -05:00
public static DataSet PatientInfoSearch(string id)
{
try
{
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
2024-02-16 11:32:00 -05:00
cmdString.CommandText = "SearchPatients";
2024-02-15 12:04:26 -05:00
// Define input parameter
2024-02-16 11:32:00 -05:00
cmdString.Parameters.Add("@ID", SqlDbType.VarChar, 8).Value = id;
cmdString.Parameters.Add("@lname", SqlDbType.VarChar, 30).Value = "";
cmdString.Parameters.Add("@fname", SqlDbType.VarChar, 30).Value = "";
2024-02-15 12:04:26 -05:00
// 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();
}
}
2024-02-14 17:40:16 -05:00
2024-02-14 19:27:21 -05:00
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();
}
}
2024-02-14 17:40:16 -05:00
2024-02-14 19:43:07 -05:00
public static DataSet PhysicianInfoSearch(string fname,string lname, string phyID)
2024-02-14 17:40:16 -05:00
{
try
{
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
2024-02-14 19:43:07 -05:00
cmdString.CommandText = "PhysicianInfoSearch";
2024-02-14 17:40:16 -05:00
// Define input parameter
2024-02-14 19:43:07 -05:00
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;
2024-02-14 17:40:16 -05:00
// 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();
}
}
2024-02-15 12:04:26 -05:00
public static double GetNextPatientID()
{
try
{
// open connection
myConn.Open();
//clear any parameters
cmdString.Parameters.Clear();
// command
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "GetNextPatientID";
// Define input parameter
cmdString.Parameters.Add("@TableName", SqlDbType.NVarChar, 128).Value = "PATIENT";
object result = cmdString.ExecuteScalar();
double value = 0;
try
{
value = Convert.ToDouble(result);
}
catch(Exception e)
{
MessageBox.Show("Error Getting next Patient ID","ERROR",MessageBoxButtons.OK);
}
// return dataSet
return value;
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static DataSet RefillSearch(DateTime date, 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("@date", SqlDbType.Date).Value = date;
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 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 static void 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;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static void 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;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
}
}