CNSA-216-FP/FWA_MAIN/patSearch.aspx.cs

213 lines
6.2 KiB
C#

using System;
using System.Web.UI;
using System.Data;
using System.Drawing;
using System.Web.UI.WebControls;
namespace FWA_MAIN
{
public partial class patSearch : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtPatID.Text = Convert.ToString(Session["vPatientID"]);
txtFNAME.Text = Convert.ToString(Session["vFNAME"]);
txtLNAME.Text = Convert.ToString(Session["vLNAME"]);
btnPatSearch_OnClick(sender,e);
}
}
protected void btnNew_OnClick(object sender, EventArgs e)
{
Response.Redirect("patNew.aspx");
}
private void BindData()
{
DataSet ds = new DataSet();
string patID = Convert.ToString(Session["vPatientID"]);
string LNAME = Convert.ToString(Session["vLNAME"]);
string FNAME = Convert.ToString(Session["vFNAME"]);
txtPatID.Text = patID;
txtFNAME.Text = FNAME;
txtLNAME.Text = LNAME;
// if (textHasValues)
// {
ds = PharmacyDataTier.PatientInfoSearch(patID, LNAME, FNAME);
// }
// ds = dt.GetStudents();
gvPatient.DataSource = ds.Tables[0];
if (Cache["StudentData"] == null)
{
Cache.Add("StudentData", new DataView(ds.Tables[0]),
null,System.Web.Caching.Cache.NoAbsoluteExpiration,
System.TimeSpan.FromMinutes(10), System.Web.Caching.CacheItemPriority.Default,
null);
}
gvPatient.DataBind();
}
protected void btnPatSearch_OnClick(object sender, EventArgs e)
{
if (txtPatID.Text.Trim().Length > 0 || txtFNAME.Text.Trim().Length > 0 || txtLNAME.Text.Trim().Length > 0)
{
try
{
Session["vPatientID"] = txtPatID.Text.Trim();
Session["vFNAME"] = txtFNAME.Text.Trim();
Session["vLNAME"] = txtLNAME.Text.Trim();
Cache.Remove("StudentData");
BindData();
}
catch (Exception exception)
{
}
}
}
protected void gvPatient_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvPatient, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Click to select this row.";
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
BindData();
}
protected void gvPatient_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
// Determine the index of the selected row
int index = Convert.ToInt32(e.CommandArgument);
// Check if the selected row index is the same as the previous selected row index
if (gvPatient.SelectedIndex == index)
{
// Deselect the row
gvPatient.SelectedIndex = -1;
}
else
{
// Select the row
gvPatient.SelectedIndex = index;
}
// Refresh the GridView to update the style
gvPatient.DataBind();
}
}
protected void btnPatNew_OnClick(object sender, EventArgs e)
{
string patientID;
try
{
Session["vPatientID"] = txtPatID.Text.Trim();
Session["vFNAME"] = txtFNAME.Text.Trim();
Session["vLNAME"] = txtLNAME.Text.Trim();
// Use the patientID value as needed
try
{
patientID = PharmacyDataTier.GetNextPatientID();
patientID = Crypt.Encrypt(patientID);
Response.Redirect("patNew.aspx" + "?" + "ID=" + patientID, false);
}
catch (Exception exception)
{
}
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
protected void bntPatEdit_OnClick(object sender, EventArgs e)
{
string patientID = "0";
Int64 mEditedRecord = 0;
System.Text.StringBuilder sb = new System.Text.StringBuilder();
try
{
Session["vPatientID"] = txtPatID.Text.Trim();
Session["vFNAME"] = txtFNAME.Text.Trim();
Session["vLNAME"] = txtLNAME.Text.Trim();
try
{
patientID = Crypt.Encrypt(gvPatient.SelectedRow.Cells[0].Text);
Response.Redirect("patEdit.aspx" + "?" + "ID=" + patientID, false);
}
catch (Exception exception)
{
}
// Use the patientID value as needed
}
catch (Exception ex)
{
throw new Exception(ex.Message, ex.InnerException);
}
}
protected void btnPatDelete_OnClick(object sender, EventArgs e)
{
try
{
PharmacyDataTier.DeletePatient(gvPatient.SelectedRow.Cells[0].Text);
BindData();
}
catch (Exception exception)
{
}
}
}
}