Physician Update and create work. now only need to add delete functionality

This commit is contained in:
EggMan20339 2024-02-19 11:56:51 -05:00
parent e972237938
commit b29be83709
4 changed files with 274 additions and 15 deletions

View File

@ -127,6 +127,60 @@ namespace Louis__Pharmacy_CNSA212_FP
} }
} }
public static void CreatePhysician(
string Physician_id,
string FirstName,
string LastName,
string MiddleInit,
DateTime DOB,
string Gender,
string City,
Int16 Zip,
string UsState,
string PhoneNumber,
string Speciality)
{
try
{
myConn.Open();
cmdString.Parameters.Clear();
cmdString.Connection = myConn;
cmdString.CommandType = CommandType.StoredProcedure;
cmdString.CommandTimeout = 1500;
cmdString.CommandText = "CreatePhysician";
cmdString.Parameters.Add("@Physician_id", SqlDbType.VarChar, 8).Value = Physician_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 = MiddleInit;
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.VarChar, 2).Value = UsState;
cmdString.Parameters.Add("@PhoneNumber", SqlDbType.VarChar, 14).Value = PhoneNumber;
cmdString.Parameters.Add("@Speciality", SqlDbType.VarChar, 100).Value = Speciality;
cmdString.ExecuteNonQuery();
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
finally
{
myConn.Close();
}
}
public static void DeletePatient(string Patient_id) public static void DeletePatient(string Patient_id)

View File

@ -942,7 +942,7 @@ namespace Louis__Pharmacy_CNSA212_FP
private System.Windows.Forms.DataGridViewTextBoxColumn numberphone; private System.Windows.Forms.DataGridViewTextBoxColumn numberphone;
private System.Windows.Forms.DataGridViewTextBoxColumn gennder; private System.Windows.Forms.DataGridViewTextBoxColumn gennder;
private System.Windows.Forms.DataGridViewTextBoxColumn Specialty; private System.Windows.Forms.DataGridViewTextBoxColumn Specialty;
private System.Windows.Forms.TextBox txtPhysicianID; public System.Windows.Forms.TextBox txtPhysicianID;
private System.Windows.Forms.Label lblPhysicianID; private System.Windows.Forms.Label lblPhysicianID;
public System.Windows.Forms.TextBox txtPatientID; public System.Windows.Forms.TextBox txtPatientID;
private System.Windows.Forms.Label lblPatientID; private System.Windows.Forms.Label lblPatientID;

View File

@ -226,8 +226,8 @@ namespace Louis__Pharmacy_CNSA212_FP
} }
} }
} }
private void btnPhysicianSearch_Click(object sender, EventArgs e) public void btnPhysicianSearch_Click(object sender, EventArgs e)
{ {
string fname = ""; string fname = "";
@ -398,7 +398,7 @@ namespace Louis__Pharmacy_CNSA212_FP
DataGridViewRow row = new DataGridViewRow(); DataGridViewRow row = new DataGridViewRow();
row = dgvPhysician.SelectedRows[0]; row = dgvPhysician.SelectedRows[0];
string phyID = ""; string phyID = "";
// phyID = (row.Cells[4].Value).ToString(); phyID = (row.Cells[1].Value).ToString();
frmPhysician PhysicianAdd = new frmPhysician(this, false); frmPhysician PhysicianAdd = new frmPhysician(this, false);
PhysicianAdd.MdiParent = MdiParent; PhysicianAdd.MdiParent = MdiParent;
PhysicianAdd.StartPosition = FormStartPosition.CenterScreen; PhysicianAdd.StartPosition = FormStartPosition.CenterScreen;

View File

@ -1,20 +1,18 @@
using System; using System;
using System.Windows.Forms;
using System.Data; using System.Data;
using System.Windows.Forms;
namespace Louis__Pharmacy_CNSA212_FP namespace Louis__Pharmacy_CNSA212_FP
{ {
public partial class frmPhysician : Form public partial class frmPhysician : Form
{ {
private readonly bool isAdd;
private bool isAdd;
private frmInfo SourceForm; private frmInfo SourceForm;
public frmPhysician(frmInfo sourceForm, bool isNew) public frmPhysician(frmInfo sourceForm, bool isNew)
{ {
SourceForm = sourceForm; SourceForm = sourceForm;
isAdd = isNew; isAdd = isNew;
InitializeComponent(); InitializeComponent();
@ -30,17 +28,225 @@ namespace Louis__Pharmacy_CNSA212_FP
lblDisPurpose.Text = "Edit Physician"; lblDisPurpose.Text = "Edit Physician";
btnGO.Text = "Update"; btnGO.Text = "Update";
} }
} }
private void btnClose_Click(object sender, EventArgs e) private void btnClose_Click(object sender, EventArgs e)
{ {
Close(); Close();
} }
private void btnGO_Click(object sender, EventArgs e) private void btnGO_Click(object sender, EventArgs e)
{ {
var epLocal = new ErrorProvider();
var hasFailed = false;
var Physician_id = "";
var FirstName = "";
var LastName = "";
var MiddleIntials = "";
var City = "";
short Zip = 0;
var UsState = "";
var DOB = new DateTime(1753, 1, 1);
var PhoneNumber = "";
var Gender = "";
var Speciality = "";
if (txtFirstName.Text.Length + txtLastName.Text.Length + txtMiddleInit.Text.Length + txtCity.Text.Length +
txtZip.Text.Length + txtState.Text.Length + txtDOB.Text.Length + txtGender.Text.Length
+ txtPhone.Text.Length + txtSpeciality.Text.Length > 0)
{
try
{
if (txtSpeciality.Text.Length <= 100)
Speciality = txtSpeciality.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtSpeciality, "Invalid Value");
hasFailed = true;
}
try
{
if (txtGender.Text.Length == 1)
Gender = txtGender.Text.ToUpper();
else if (txtGender.Text.Length == 0)
Gender = "NA";
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtGender, "Invalid Value");
hasFailed = true;
}
try
{
if (txtPhone.Text.Length <= 14)
PhoneNumber = txtPhone.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtPhone, "Invalid Value");
hasFailed = true;
}
try
{
if (txtDOB.Text.Length > 0)
DOB = DateTime.Parse(txtDOB.Text);
else
DOB = new DateTime(1753, 1, 1);
}
catch (Exception exception)
{
epLocal.SetError(txtDOB, "Invalid Value");
hasFailed = true;
}
try
{
if (txtState.Text.Length <= 2)
UsState = txtState.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtState, "Invalid Value");
hasFailed = true;
}
try
{
if (txtZip.Text.Length <= 5)
Zip = short.Parse(txtZip.Text);
else if (txtZip.Text.Length == 0)
Zip = 0;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtZip, "Invalid Value");
hasFailed = true;
}
try
{
if (txtCity.Text.Length <= 30)
City = txtCity.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtCity, "Invalid Value");
hasFailed = true;
}
try
{
if (txtMiddleInit.Text.Length <= 1)
MiddleIntials = txtMiddleInit.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtMiddleInit, "Invalid Value");
hasFailed = true;
}
try
{
if (txtLastName.Text.Length <= 30)
LastName = txtLastName.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtLastName, "Invalid Value");
hasFailed = true;
}
try
{
if (txtFirstName.Text.Length <= 30)
FirstName = txtFirstName.Text;
else
throw new Exception();
}
catch (Exception exception)
{
epLocal.SetError(txtFirstName, "Invalid Value");
hasFailed = true;
}
try
{
if (txtPhyID.Text.Length <= 8)
Physician_id = txtPhyID.Text;
else
throw new Exception();
while (Physician_id.Length < 8) Physician_id = "0" + Physician_id;
}
catch (Exception exception)
{
epLocal.SetError(txtPhyID, "Invalid Value");
hasFailed = true;
}
try
{
Zip = short.Parse(txtZip.Text);
}
catch (Exception exception)
{
epLocal.SetError(txtZip, "Invalid Value");
hasFailed = true;
}
try
{
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
if (!hasFailed)
{
PharmacyDataTier.CreatePhysician(
Physician_id,
FirstName,
LastName,
MiddleIntials,
DOB,
Gender,
City,
Zip,
UsState,
PhoneNumber,
Speciality);
SourceForm.txtPhysicianID.Text = Physician_id;
SourceForm.btnPhysicianSearch_Click(sender, e);
Close();
}
}
} }
private void frmPhysician_Load(object sender, EventArgs e) private void frmPhysician_Load(object sender, EventArgs e)
@ -53,7 +259,7 @@ namespace Louis__Pharmacy_CNSA212_FP
txtPhyID.Text = nextID.ToString(); txtPhyID.Text = nextID.ToString();
} }
} }
public void FillPhysician(string phyID) public void FillPhysician(string phyID)
{ {
var ds = new DataSet(); var ds = new DataSet();
@ -72,6 +278,5 @@ namespace Louis__Pharmacy_CNSA212_FP
txtPhone.Text = ds.Tables[0].Rows[0]["PhoneNumber"].ToString(); txtPhone.Text = ds.Tables[0].Rows[0]["PhoneNumber"].ToString();
txtSpeciality.Text = ds.Tables[0].Rows[0]["Specialty"].ToString(); txtSpeciality.Text = ds.Tables[0].Rows[0]["Specialty"].ToString();
} }
} }
} }