using framework_business;
using framework_library;
using System;
using System.Collections;
using System.Linq;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
public partial class controls_module_medicallistings : UserControl, ISurfaceControlBase
{
#region methods
///
/// ReloadControl
///
///
public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false)
{
try
{
SurfaceItemId = controlFieldData.surfaceItemId;
BindListingDates();
if (readOnly)
SetReadOnly();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// bind dates dropdown
///
private void BindListingDates()
{
try
{
ddListingDates.Items.Clear();
ArrayList listingDates = xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientListing), "surfaceItemId", SurfaceItemId.ToString(), "listingDate DESC");
ddListingDates.DataSource = listingDates;
ddListingDates.DataTextField = "listingDate";
ddListingDates.DataTextFormatString = "{0:dd/MM/yyyy}";
ddListingDates.DataValueField = "recId";
ddListingDates.DataBind();
if (ddListingDates.Items.Count > 0)
{
ddListingDates.SelectedIndex = 0;
SetSelectedListing();
}
else
{
ddListingDates.Items.Add(new ListItem("No Listings Found", "0"));
divListingDetails.Visible = false;
}
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// set listing
///
private void SetSelectedListing()
{
try
{
foreach (oMedicalPatientListing listing in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientListing), "recId", ddListingDates.SelectedValue.ToString()))
{
MedicalPatientListing = listing;
dtListingDate.Text = listing.listingDate.ToString("dd/MM/yyyy");
txtNotes.Value = listing.notes;
ClearAllBoxes();
string listingsValue = listing.scores;
string boxNumber = string.Empty, boxValue = string.Empty;
foreach (string value in listingsValue.Split(';'))
{
string[] itemArray = value.Split('_');
boxNumber = itemArray[0];
if (itemArray.Count() > 1)
boxValue = itemArray[1];
;
TextBox txtBoxListingScore = (TextBox)FindControl("listingScore" + boxNumber);
if (txtBoxListingScore != null)
{
txtBoxListingScore.Text = boxValue;
}
}
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "UpdateColors", "UpdateColors(0);", true);
}
if (ddListingDates.SelectedIndex == 0)//first element
lnkNext.Visible = false;
else
lnkNext.Visible = true;
if (ddListingDates.SelectedIndex == ddListingDates.Items.Count - 1)//last element
lnkPrev.Visible = false;
else
lnkPrev.Visible = true;
SetReadOnly();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// set listing boxes as readonly
///
private void SetReadOnly()
{
try
{
dtListingDate.Enabled = false;
txtNotes.Disabled = true;
lnkSave.Visible = false;
for (int i = 1; i <= 29; i++)
{
if (upListings.FindControl("listingScore" + i.ToString()) != null)
{
TextBox txtBox = (TextBox)upListings.FindControl("listingScore" + i.ToString());
txtBox.ReadOnly = true;
}
}
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
private void SetEnabled()
{
try
{
dtListingDate.Enabled = true;
txtNotes.Disabled = false;
lnkSave.Visible = true;
lnkEdit.Visible = false;
lnkClone.Visible = false;
for (int i = 1; i <= 29; i++)
{
if (upListings.FindControl("listingScore" + i.ToString()) != null)
{
TextBox txtBox = (TextBox)upListings.FindControl("listingScore" + i.ToString());
txtBox.ReadOnly = false;
}
}
divListingDetails.Visible = true;
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "UpdateColors", "UpdateColors(0);", true);
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Clear All Entries
///
private void ClearAllBoxes()
{
try
{
for (int i = 1; i <= 30; i++)
{
TextBox txtBoxListingScore = (TextBox)FindControl("listingScore" + i);
if (txtBoxListingScore != null)
{
txtBoxListingScore.Text = "";
}
}
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// Save Control Data
///
///
public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData)
{
if (divListingDetails.Visible && lnkSave.Visible)
{
SaveListings();
}
}
///
/// Save listings
///
///
private bool SaveListings()
{
bool result = false;
try
{
if (MedicalPatientListing == null)
{
MedicalPatientListing = new oMedicalPatientListing();
}
MedicalPatientListing.listingDate = utils.formatStringToDate(dtListingDate.Text);
MedicalPatientListing.notes = txtNotes.Value;
MedicalPatientListing.surfaceItemId = SurfaceItemId;
string saveString = string.Empty;
for (int i = 1; i <= 30; i++)
{
TextBox txtBoxListingScore = (TextBox)FindControl("listingScore" + i);
if (txtBoxListingScore != null && txtBoxListingScore.Text != "")
{
if (i == 1)
saveString += i.ToString() + "_" + txtBoxListingScore.Text;
else
saveString += ";" + i.ToString() + "_" + txtBoxListingScore.Text;
}
}
if (saveString != String.Empty)
{
MedicalPatientListing.scores = saveString;
if (MedicalPatientListing.recId > 0)
result = xData.UpdateTyped("recId", MedicalPatientListing.recId.ToString(), typeof(oMedicalPatientListing), MedicalPatientListing);
else
{
MedicalPatientListing.recId = xData.SaveTyped("recId", typeof(oMedicalPatientListing), MedicalPatientListing);
if (MedicalPatientListing.recId > 0)
result = true;
}
BindListingDates();
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "UpdateColors", "UpdateColors(0);", true);
lnkEdit.Visible = true;
lnkClone.Visible = true;
upListings.Update();
}
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
return result;
}
#endregion
#region events
///
/// Page Init
///
///
///
protected void Page_Init(object sender, EventArgs e)
{
}
///
/// Page Load
///
///
///
protected void Page_Load(object sender, EventArgs e)
{
//ScriptManager.RegisterStartupScript(Page, Page.GetType(), "UpdateColors", "UpdateColors(0);", true);
}
///
/// add new listing
///
///
///
protected void btnNew_Click(object sender, EventArgs e)
{
try
{
MedicalPatientListing = new oMedicalPatientListing();
dtListingDate.Text = DateTime.Now.ToString("dd/MM/yyyy");
txtNotes.Value = "";
ClearAllBoxes();
SetEnabled();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// go to previous listing
///
///
///
protected void lnkPrev_Click(object sender, EventArgs e)
{
try
{
ddListingDates.SelectedIndex = ddListingDates.SelectedIndex + 1;
SetSelectedListing();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// go to next listing
///
///
///
protected void lnkNext_Click(object sender, EventArgs e)
{
try
{
ddListingDates.SelectedIndex = ddListingDates.SelectedIndex - 1;
SetSelectedListing();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// save listing
///
///
///
protected void lnkSave_Click(object sender, EventArgs e)
{
try
{
SaveListings();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// edit item
///
///
///
protected void lnkEdit_Click(object sender, EventArgs e)
{
try
{
SetEnabled();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// clone item
///
///
///
protected void lnkClone_Click(object sender, EventArgs e)
{
try
{
SetEnabled();
MedicalPatientListing.recId = 0;
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
///
/// date selection change
///
///
///
protected void ddListingDates_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SetSelectedListing();
}
catch (Exception ex)
{
exception.HandleException("listings:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]);
Response.Redirect("/error", false);
}
}
#endregion
#region properties
///
/// MPL getter and setter
///
public oMedicalPatientListing MedicalPatientListing
{
get
{
if (utils.verifySession("medicalPatientListing") && Session["medicalPatientListing"] != null)
{
return (oMedicalPatientListing)Session["medicalPatientListing"];
}
else
{
return null;
}
}
set
{
Session["medicalPatientListing"] = value;
}
}
public int SurfaceItemId
{
get
{
if (utils.verifySession("listingSurfaceItemId") && Session["listingSurfaceItemId"] != null)
return (int)Session["listingSurfaceItemId"];
else
return 0;
}
set
{
Session["listingSurfaceItemId"] = value;
}
}
#endregion
}