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

281 lines
8.0 KiB
C#
Raw Normal View History

2024-02-19 18:24:58 -08:00
using System;
using System.Windows.Forms;
2024-02-19 13:27:27 -08:00
using System.Data;
2024-02-19 18:24:58 -08:00
using System.Drawing.Imaging;
using System.Net.NetworkInformation;
2024-02-19 13:27:27 -08:00
namespace Louis__Pharmacy_CNSA212_FP
{
public partial class frmMedication : Form
{
2024-02-19 18:24:58 -08:00
private readonly bool isAdd;
private frmInfo SourceForm;
ErrorProvider epLocal = new ErrorProvider();
2024-02-19 13:27:27 -08:00
public frmMedication(frmInfo sourceForm, bool isNew)
{
2024-02-19 18:24:58 -08:00
SourceForm = sourceForm;
isAdd = isNew;
2024-02-19 13:27:27 -08:00
InitializeComponent();
2024-02-19 18:24:58 -08:00
if (isNew)
{
lblDisPurpose.Text = "Add Medication";
btnGO.Text = "Create";
}
else
{
lblDisPurpose.Text = "Edit Medication";
btnGO.Text = "Update";
}
KeyPreview = true;
KeyDown += frmMedication_KeyDown;
2024-02-19 18:24:58 -08:00
}
2024-02-19 18:24:58 -08:00
private void frmMedication_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
Close();
if (e.KeyCode == Keys.Enter) btnGO_Click(sender, e);
2024-02-19 13:27:27 -08:00
}
public void FillMedication(string rxID)
{
var ds = new DataSet();
var data = new PharmacyDataTier();
ds = PharmacyDataTier.MedicationInfoSearch(rxID);
txtMedID.Text = ds.Tables[0].Rows[0]["Medication_id"].ToString();
txtName.Text = ds.Tables[0].Rows[0]["MedicationName"].ToString();
txtIntake.Text = ds.Tables[0].Rows[0]["IntakeMethod"].ToString();
txtFrequency.Text = ds.Tables[0].Rows[0]["Frequency"].ToString();
txtDosage.Text = ds.Tables[0].Rows[0]["Dosage"].ToString();
txtPurpose.Text = ds.Tables[0].Rows[0]["Purpose"].ToString();
txtRxNum.Text = ds.Tables[0].Rows[0]["RxNum"].ToString();
}
2024-02-19 18:24:58 -08:00
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void btnGO_Click(object sender, EventArgs e)
{
var hasFailed = false;
var Medication_id = "";
var MedicationName = "";
var IntakeMethod = "";
var Frequency = "";
var Dosage = "";
var Purpose = "";
var RxNum = "";
if (txtMedID.Text.Length + txtName.Text.Length + txtIntake.Text.Length + txtFrequency.Text.Length + txtDosage.Text.Length + txtPurpose.Text.Length + txtRxNum.Text.Length > 0)
{
try
{
RxNum = txtRxNum.Text;
if (RxNum.Length > 30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtRxNum, "Invalid Value");
hasFailed = true;
}
try
{
Purpose = txtPurpose.Text;
if (Purpose.Length > 100)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtPurpose, "Invalid Value");
hasFailed = true;
}
try
{
Dosage = txtDosage.Text;
if (Dosage.Length > 30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtDosage, "Invalid Value");
hasFailed = true;
}
try
{
Frequency = txtFrequency.Text;
if (Frequency.Length > 30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtFrequency, "Invalid Value");
hasFailed = true;
}
try
{
IntakeMethod = txtIntake.Text;
if (IntakeMethod.Length>30)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtIntake, "Invalid Value");
hasFailed = true;
}
try
{
MedicationName = txtName.Text;
if (MedicationName.Length>60)
{
throw new Exception();
}
}
catch (Exception exception)
{
epLocal.SetError(txtName, "Invalid Value");
hasFailed = true;
}
try
{
Medication_id = txtMedID.Text;
if (Medication_id.Length>7)
{
throw new Exception();
}
while (Medication_id.Length < 7)
{
Medication_id = "0" + Medication_id;
}
}
catch (Exception exception)
{
epLocal.SetError(txtMedID, "Invalid Value");
hasFailed = true;
}
if (!hasFailed)
{
if (isAdd)
{
PharmacyDataTier.CreateMedication(
Medication_id,
MedicationName,
IntakeMethod,
Frequency,
Dosage,
Purpose,
RxNum);
}
else
{
PharmacyDataTier.UpdateMedication(
Medication_id,
MedicationName,
IntakeMethod,
Frequency,
Dosage,
Purpose,
RxNum);
}
SourceForm.txtRxNumber.Text = Medication_id;
//SourceForm.btnPrescriptionSearch_Click(sender, e);
2024-02-19 18:24:58 -08:00
Close();
}
}
}
private void frmMedication_Load(object sender, EventArgs e)
{
txtMedID.Enabled = false;
if (isAdd)
{
var nextID = PharmacyDataTier.GetNextMedicationID();
txtMedID.Text = nextID.ToString();
}
}
private void txtMedID_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtMedID,"");
}
private void txtName_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtName,"");
}
private void txtIntake_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtIntake,"");
}
private void txtFrequency_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtFrequency,"");
}
private void txtDosage_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtDosage,"");
}
private void txtPurpose_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtPurpose,"");
}
private void txtRxNum_TextChanged(object sender, EventArgs e)
{
epLocal.SetError(txtRxNum,"");
}
private void label7_Click(object sender, EventArgs e)
{
}
2024-02-19 13:27:27 -08:00
}
}