281 lines
8.0 KiB
C#
281 lines
8.0 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using System.Data;
|
|
using System.Drawing.Imaging;
|
|
using System.Net.NetworkInformation;
|
|
|
|
namespace Louis__Pharmacy_CNSA212_FP
|
|
{
|
|
public partial class frmMedication : Form
|
|
{
|
|
private readonly bool isAdd;
|
|
private frmInfo SourceForm;
|
|
ErrorProvider epLocal = new ErrorProvider();
|
|
public frmMedication(frmInfo sourceForm, bool isNew)
|
|
{
|
|
|
|
|
|
SourceForm = sourceForm;
|
|
|
|
isAdd = isNew;
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
if (isNew)
|
|
{
|
|
lblDisPurpose.Text = "Add Medication";
|
|
btnGO.Text = "Create";
|
|
}
|
|
else
|
|
{
|
|
lblDisPurpose.Text = "Edit Medication";
|
|
btnGO.Text = "Update";
|
|
}
|
|
KeyPreview = true;
|
|
KeyDown += frmMedication_KeyDown;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void frmMedication_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Escape)
|
|
Close();
|
|
|
|
if (e.KeyCode == Keys.Enter) btnGO_Click(sender, e);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
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.txtMedicationNumber.Text = Medication_id;
|
|
SourceForm.btnMedicationSearch_Click(sender, e);
|
|
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)
|
|
{
|
|
|
|
}
|
|
}
|
|
} |