CNSA-212-FP/Louis'-Pharmacy_CNSA212-FP/frmInfo.cs
2024-02-20 16:57:25 -05:00

716 lines
22 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Louis__Pharmacy_CNSA212_FP
{
public partial class frmInfo : Form
{
private ErrorProvider ep1 = new ErrorProvider();
public DataSet ds = new DataSet();
public frmInfo()
{
InitializeComponent();
dgvPatient.DoubleClick += cmuPatientEdit_Click;
dgvPhysician.DoubleClick += cmuPhysicianEdit_Click;
dgvRx.DoubleClick += cmuRxEdit_Click;
tbcInfo.SelectedIndexChanged += frmInfoTabChange;
}
private void frmInfo_Load(object sender, EventArgs e)
{
KeyPreview = true;
KeyDown += frmInfo_KeyDown;
cmuPatientEdit.Enabled = false;
cmuPatientDelete.Enabled = false;
cmuPhysicianEdit.Enabled = false;
cmuPhysicianDelete.Enabled = false;
cmuMedicationEdit.Enabled = false;
cmuMedicationDelete.Enabled = false;
txtPatientFirst.Focus();
patientIsActive = true;
}
private bool physicianIsActive;
private bool patientIsActive;
private bool medicationIsActive;
private void frmInfoTabChange(object sender, EventArgs e)
{
Console.WriteLine(tbcInfo.SelectedIndex);
patientIsActive = false;
physicianIsActive = false;
medicationIsActive = false;
if (tbcInfo.SelectedIndex == 0)
{
patientIsActive = true;
}
else if (tbcInfo.SelectedIndex == 1)
{
medicationIsActive = true;
}
else if (tbcInfo.SelectedIndex == 2)
{
physicianIsActive = true;
}
}
private void frmInfo_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{this.Close();
}
// if data grid view is not focused, run the search function
if (e.KeyCode == Keys.Enter && physicianIsActive && !dgvPhysician.Focused){
btnPhysicianSearch_Click(sender, e);
}
// if data grid view is focused, run the edit function
else if (e.KeyCode == Keys.Enter && physicianIsActive && dgvPhysician.Focused)
{
cmuPhysicianEdit_Click(sender, e);
}
if (patientIsActive && e.KeyCode == Keys.Delete)
{
cmuPatientDelete_Click(sender, e);
}
if (physicianIsActive && e.KeyCode == Keys.Delete)
{
cmuPhysicianDelete_Click(sender, e);
}
if (medicationIsActive && e.KeyCode == Keys.Delete)
{
cmuMedicationDelete_Click(sender, e);
}
// if data grid view is not focused, run the search function
if (e.KeyCode == Keys.Enter && patientIsActive && !dgvPatient.Focused)
{
btnPatientSearch_Click(sender,e);
}
// if data grid view is focused, run the edit function
else if (e.KeyCode == Keys.Enter && patientIsActive && dgvPatient.Focused)
{
cmuPatientEdit_Click(sender,e);
}
// if data grid view is not focused, run the search function
if (e.KeyCode == Keys.Enter && medicationIsActive && !dgvRx.Focused)
{
btnRxSearch_Click(sender,e);
}
// if data grid view is focused, run the edit function
else if (e.KeyCode == Keys.Enter && medicationIsActive && dgvRx.Focused)
{
cmuRxEdit_Click(sender,e);
}
}
private void addUpdatePatientAndPhysicianToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void pATIENTBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
}
public void btnPatientSearch_Click(object sender, EventArgs e)
{
string fname = "";
string lname = "";
string id = "";
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");
}
}
cmuPatientEdit.Enabled = dgvPatient.Rows.Count > 0;
cmuPatientDelete.Enabled = dgvPatient.Rows.Count > 0;
dgvPatient.Focus();
}
//public void btnPrescriptionSearch_Click(object sender, EventArgs e)
//{
// string medID = "";
// string medicationName = "";
// if (txtPrescriptionPatID.Text.Length+txtRxNumber.Text.Length > 0)
// {
// try
// {
// medicationName = txtPrescriptionPatID.Text;
// try
// {
// medID = txtRxNumber.Text;
// try
// {
// ds = PharmacyDataTier.MedicationInfoSearch(medID,medicationName);
// if (ds.Tables[0].Rows.Count > 0) // There is a record.
// {
// dgvRx.Visible = true;
// // Get data source.
// dgvRx.DataSource = ds.Tables[0];
// dgvRx.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
// // Set the row and column header styles.
// dgvRx.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
// dgvRx.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(btnMedicationSearch, "Error Searching");
// }
// }
// catch (Exception exception)
// {
// ep1.SetError(txtRxNumber, "Invalid Value");
// }
// }
// catch (Exception exception)
// {
// ep1.SetError(txtPrescriptionPatID, "Invalid Value");
// }
// }
// cmuMedicationEdit.Enabled = dgvRx.Rows.Count > 0;
// cmuMedicationDelete.Enabled = dgvRx.Rows.Count > 0;
// dgvRx.Focus();
//}
public void btnPhysicianSearch_Click(object sender, EventArgs e)
{
string fname = "";
string lname = "";
string phyID = "";;
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");
}
}
cmuPhysicianEdit.Enabled = dgvPhysician.Rows.Count > 0;
cmuPhysicianDelete.Enabled = dgvPhysician.Rows.Count > 0;
dgvPhysician.Focus();
}
private void cmuPatientNew_Click(object sender, EventArgs e)
{
frmPatient PatientAdd = new frmPatient(this, true);
PatientAdd.MdiParent = MdiParent;
PatientAdd.StartPosition = FormStartPosition.CenterScreen;
PatientAdd.Show();
PatientAdd.Focus();
}
private void cmuPatientEdit_Click(object sender, EventArgs e)
{
if (dgvPatient.Rows.Count > 0)
{
dgvPatient.DataSource = ds.Tables[0];
// Console.WriteLine( dgvPatient.SelectedRows.Count);
DataGridViewRow row = new DataGridViewRow();
row = dgvPatient.SelectedRows[0];
string patid = "";
patid = (row.Cells[3].Value).ToString();
frmPatient PatientAdd = new frmPatient(this, false);
PatientAdd.MdiParent = MdiParent;
PatientAdd.StartPosition = FormStartPosition.CenterScreen;
PatientAdd.Show();
PatientAdd.Focus();
PatientAdd.FillPatient(patid);
}
}
private void dgvPatient_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
cmuPatientEdit_Click(sender, e);
}
private void Panel1_Paint(object sender, PaintEventArgs e)
{
}
private void cmuPatientDelete_Click(object sender, EventArgs e)
{
if (dgvPatient.Rows.Count > 0)
{
dgvPatient.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvPatient.SelectedRows[0];
string patid = "";
patid = (row.Cells[3].Value).ToString();
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete Patient: " + patid,
"Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
PharmacyDataTier.DeletePatient(patid);
}
btnPatientSearch_Click(sender, e);
}
}
private void cmuPhysicianNew_Click(object sender, EventArgs e)
{
frmPhysician physicianAdd = new frmPhysician(this, true);
physicianAdd.MdiParent = MdiParent;
physicianAdd.StartPosition = FormStartPosition.CenterScreen;
physicianAdd.Show();
physicianAdd.Focus();
}
private void cmuPhysicianEdit_Click(object sender, EventArgs e)
{
if (dgvPhysician.Rows.Count > 0)
{
dgvPhysician.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvPhysician.SelectedRows[0];
string phyID = "";
phyID = (row.Cells[0].Value).ToString();
frmPhysician PhysicianAdd = new frmPhysician(this, false);
PhysicianAdd.MdiParent = MdiParent;
PhysicianAdd.StartPosition = FormStartPosition.CenterScreen;
PhysicianAdd.Show();
PhysicianAdd.Focus();
PhysicianAdd.FillPhysician(phyID);
}
}
private void cmuPhysicianDelete_Click(object sender, EventArgs e)
{
if (dgvPhysician.Rows.Count > 0)
{
dgvPhysician.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvPhysician.SelectedRows[0];
string phyID = "";
phyID = (row.Cells[0].Value).ToString();
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete Physician: " + phyID,
"Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
PharmacyDataTier.DeletePhysician(phyID);
}
btnPhysicianSearch_Click(sender, e);
}
}
// private void PhysicianReset(object sender, EventArgs e)
// {
// txtPhysicianFirst.Text = "";
// txtPhysicianLast.Text = "";
// txtPhysicianID.Text = "";
// dgvPhysician.Visible = false;
// }
private void dgvPhysician_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void dgvPhysician_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
}
private void cmuRxNew_Click(object sender, EventArgs e)
{
frmMedication medicationAdd = new frmMedication(this, true);
medicationAdd.MdiParent = MdiParent;
medicationAdd.StartPosition = FormStartPosition.CenterScreen;
medicationAdd.Show();
medicationAdd.Focus();
}
private void cmuRxEdit_Click(object sender, EventArgs e)
{
if (dgvRx.Rows.Count > 0)
{
dgvRx.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvRx.SelectedRows[0];
string rxID = "";
rxID = (row.Cells[0].Value).ToString();
frmMedication prescriptionAdd = new frmMedication(this, false);
prescriptionAdd.MdiParent = MdiParent;
prescriptionAdd.StartPosition = FormStartPosition.CenterScreen;
prescriptionAdd.Show();
prescriptionAdd.Focus();
prescriptionAdd.FillMedication(rxID);
}
}
private void cmuMedicationDelete_Click(object sender, EventArgs e)
{
if (dgvRx.Rows.Count > 0)
{
dgvRx.DataSource = ds.Tables[0];
DataGridViewRow row = new DataGridViewRow();
row = dgvRx.SelectedRows[0];
string medID = "";
medID = (row.Cells[0].Value).ToString();
DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete medication: " + medID,
"Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
PharmacyDataTier.DeleteMedication(medID);
}
btnRxSearch_Click(sender, e);
}
}
private void lblDisMedicationNum_Click(object sender, EventArgs e)
{
}
private void Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void cmuPrescriptionNew_Click(object sender, EventArgs e)
{
}
private void cmuPrescriptionEdit_Click(object sender, EventArgs e)
{
}
private void cmuPrescriptionDelete_Click(object sender, EventArgs e)
{
}
private void btnRxSearch_Click(object sender, EventArgs e)
{
string rxNum = "";
string physID = "";
string medID = "";
string patID = "";
if (txtRxPatientID.Text.Length + txtRxNumber.Text.Length > 0)
{
try
{
rxNum = txtRxPrescriptionID.Text;
medID = txtRxMedicationID.Text;
physID = txtRxPhysicianID.Text;
patID = txtRxPatientID.Text;
try
{
ds = PharmacyDataTier.PrescriptionInfoSearch(rxNum, medID, physID, patID);
if (ds.Tables[0].Rows.Count > 0) // There is a record.
{
dgvRx.Visible = true;
// Get data source.
dgvRx.DataSource = ds.Tables[0];
dgvRx.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen;
// Set the row and column header styles.
dgvRx.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
dgvRx.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(btnMedicationSearch, "Error Searching");
}
}
catch (Exception exception)
{
ep1.SetError(txtPrescriptionPatID, "Invalid Value");
}
}
cmuMedicationEdit.Enabled = dgvRx.Rows.Count > 0;
cmuMedicationDelete.Enabled = dgvRx.Rows.Count > 0;
dgvRx.Focus();
}
private void txtRxPatientID_TextChanged(object sender, EventArgs e)
{
}
private void cmuAddRefill_Click(object sender, EventArgs e)
{
}
}
}