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

146 lines
4.5 KiB
C#
Raw Normal View History

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)
{
}
protected void btnNew_OnClick(object sender, EventArgs e)
{
Response.Redirect("patNew.aspx");
}
private void BindData()
{
DataSet ds = new DataSet();
string patID = Convert.ToString(Session["vPatID"]);
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["vPatID"] = 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.";
}
// if (e.Row.RowType == DataControlRowType.DataRow)
// {
// // Clear any previous selection style
// e.Row.Style.Remove(HtmlTextWriterStyle.BackgroundColor);
//
// if (e.Row.RowIndex == gvPatient.SelectedIndex)
// {
// // Apply the selected style
// e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "LightBlue");
// }
// }
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in gvPatient.Rows)
{
// if (row.RowIndex == gvPatient.SelectedIndex)
// {
// row.BackColor = Color.Aqua;
// row.ToolTip = string.Empty;
// }
// else
// {
// row.BackColor = Color.Black;
// row.ToolTip = "Click to select this row.";
// }
}
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();
}
}
}
}