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

130 lines
3.8 KiB
C#

using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FWA_MAIN
{
public partial class MediSearch : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtMedID.Text = Convert.ToString(Session["vMedID"]);
txtMedName.Text = Convert.ToString(Session["vMedName"]);
txtRxNum.Text = Convert.ToString(Session["vRxNum"]);
btnMediSearch_OnClick(sender,e);
}
}
private void BindData()
{
DataSet ds = new DataSet();
string medID = Convert.ToString(Session["vMedID"]);
string medicationname = Convert.ToString(Session["vMedName"]);
//string RxNum = Convert.ToString(Session["vRxNum"]);
txtMedID.Text = medID;
txtMedName.Text = medicationname;
//txtRxNum.Text = RxNum;
// if (textHasValues)
// {
ds = PharmacyDataTier.MedicationInfoSearch(medID, medicationname);
// }
// ds = dt.GetStudents();
gvMedication.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);
}
gvMedication.DataBind();
}
protected void btnMediSearch_OnClick(object sender, EventArgs e)
{
if (txtMedID.Text.Trim().Length > 0 || txtMedName.Text.Trim().Length > 0 || txtRxNum.Text.Trim().Length > 0)
{
try
{
Session["vMedID"] = txtMedID.Text.Trim();
Session["vMedName"] = txtMedName.Text.Trim();
Session["vRxNum"] = txtRxNum.Text.Trim();
Cache.Remove("StudentData");
BindData();
}
catch (Exception exception)
{
}
}
}
protected void gvMedication_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvMedication, "Select$" + e.Row.RowIndex);
e.Row.ToolTip = "Click to select this row.";
}
}
protected void gvMedication_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 (gvMedication.SelectedIndex == index)
{
// Deselect the row
gvMedication.SelectedIndex = -1;
}
else
{
// Select the row
gvMedication.SelectedIndex = index;
}
// Refresh the GridView to update the style
gvMedication.DataBind();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}
}
}