using framework_business; using framework_library; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.Serialization; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Xml; using Telerik.Web.UI; public partial class controls_surface_surface_form : ISurfaceBase { private const string surfacePath = "~/controls/surface/"; private const string controlPath = "~/controls/"; private const string tempPath = "~/upload/temp/"; private bool mailSent = false; //TSP JasR 2016-01-26 - used for patient registration // This will be a list of all the fields that needs to be totaled - Dictionary //private Dictionary totals = new Dictionary(); //private Dictionary average = new Dictionary(); #region override /// /// Reload Control /// /// /// /// /// public override void ReloadControl(oSurfaceItem item, bool isView, bool isNew, bool isPersisting = false) { oUser user = handler.ReturnUser(); if (!isPersisting) { if (item.recId > 0 || isNew) { //CVH 2017-06-30 Disable inline edit for all users if (1 == 0) //if ((user.userType > (int)pNums.UserType.SuperUser && user.userType != (int)pNums.UserType.CustomUser) // || (user.mimicUserType > (int)pNums.UserType.SuperUser && user.userType == (int)pNums.UserType.CustomUser)) { //surface field handling BindFieldTypes(); BindSequence(); BindLookupCategories(); BindSurfaceApps(); BindContent(); BindComposite(); BindActionTypes(); chkToggleLayout.Visible = true; pnlSurfaceFieldModal.Visible = true; } else { chkToggleLayout.Visible = false; EnableInlineButtons(false); pnlParentSurfaceOptions.Visible = false; } if (base.SurfaceApp.isPublished) PopulateSurfaceFormCustom(item, isNew); else PopulateSurfaceForm(item, isNew); //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); SetPatientType("PatientType_PatientType_PatientType"); TogglePanels("pnlSurfaceForm"); } } } /// /// Overridible Save Control /// public override void SaveControl(bool finish, bool draft, bool closing) { PerformSave(finish, draft, closing); } #endregion #region methods /// /// Set Aggreagete Data /// /// private void SetAggregates(DataTable surfaceData, int surfaceId) { try { Dictionary localTotals = SurfaceGridTotals; Dictionary localAverages = SurfaceGridAverages; foreach (oSurfaceGridOptions gridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", surfaceId.ToString())) { if (gridOptions.showAggregate) { foreach (oSurfaceGridAggregate agg in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridAggregate), "surfaceId", surfaceId.ToString())) { foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", agg.surfaceFieldId.ToString())) { if (localTotals.ContainsKey(field.surfaceFieldName)) localTotals.Remove(field.surfaceFieldName); localTotals.Add(field.surfaceFieldName, 0); if (localAverages.ContainsKey(field.surfaceFieldName)) localAverages.Remove(field.surfaceFieldName); localAverages.Add(field.surfaceFieldName, 0); } } } } SurfaceGridTotals = localTotals; SurfaceGridAverages = localAverages; //CVH 2017-03-22 Moving, otherwise keys = 0 sumDataTable(surfaceData); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Child Grid /// /// private void BindChildGrid(oSurface childSurface) { try { foreach (oSurface mainSurface in MainSurface) { DataTable FieldTable = MainFieldTable; var fieldTableEnum = FieldTable.AsEnumerable(); var gridData = from grids in fieldTableEnum where grids.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Grid) && grids.Field("relationalSurface").Equals(childSurface.name) select grids; foreach (DataRow gridRow in gridData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(gridRow["isControlled"].ToString(), out _isControlled); bool.TryParse(gridRow["isReadOnly"].ToString(), out _isReadOnly); int _surfaceId = int.Parse(gridRow["surfaceId"].ToString()); int _parentId = int.Parse(gridRow["parentId"].ToString()); string _surfaceFieldName = gridRow["surfaceFieldName"].ToString(); string _relationalSurface = gridRow["relationalSurface"].ToString(); string _relationalValues = gridRow["relationalValues"].ToString(); bool _defaultToCurrent = false; bool.TryParse(gridRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(gridRow["isComparable"].ToString(), out _isComparable); var grpData = from groups in fieldTableEnum where groups.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) && groups.Field("recId").Equals(_parentId) select groups; foreach (DataRow grpRow in grpData.ToList()) { HtmlGenericControl divGridHolder = null; Panel panelGridHolder = null; Panel panelCompareHolder = null; Panel panelFormHolder = null; UpdatePanel upGroup = null; string _grpFieldName = grpRow["surfaceFieldName"].ToString(); if (pnlSurfaceForm.FindControl("div" + _surfaceFieldName) != null) divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + _surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + base.SurfaceApp.recId.ToString() + "_" + _surfaceFieldName); if (pnlSurfaceForm.FindControl("up" + _grpFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceForm.FindControl("up" + _grpFieldName); if (divGridHolder != null) { DataTable childData = new DataTable(); int surfaceChildId = childSurface.recId; if (surfaceChildId > 0) { int rowLimit = 0; int.TryParse(_relationalValues, out rowLimit); //CVH 2017-05-12 Populate Device Management child grid based on user email address if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && childSurface.name.EndsWith("DeviceManagement")) { List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "itemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetDeviceManagerChildData", listDevice); if (panelGridHolder != null) panelGridHolder.Enabled = false; } else if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "ScholarInformation" && childSurface.name.Contains("Mentorship")) { //CVH 2017-05-23 Mentorship child grids List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "ProfilesItemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); oDynamicParam param2 = new oDynamicParam(); param2.paramDisplayName = "option"; param2.paramObject = (_surfaceFieldName.ToUpper().Contains("MENTEE") ? "2" : "1"); listDevice.Add(param2); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetMentorshipChildSurfaceData", listDevice); } //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data else if (_isControlled) { childData = xData.GetChildSurfaceQueryDataSummarized(surfaceChildId, base.SurfaceAppItemId, rowLimit); } else { if (childSurface.isPublished) childData = xData.GetChildPublishedSurfaceData(surfaceChildId, base.SurfaceAppItemId, handler.ReturnUser().recId, rowLimit); else childData = xData.GetChildSurfaceQueryData(surfaceChildId, base.SurfaceAppItemId, rowLimit); if (childData.Rows.Count == 0 && _defaultToCurrent) { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //childData = xData.GetChildSurfaceQueryData(gridSurface.recId, 0, 0); childData = xData.GetChildSurfaceQueryData(surfaceChildId, 0, 0); } } if (panelGridHolder != null) { Repeater repeater = null; //foreach (Control rpt in divGridHolder.Controls) foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { repeater = (Repeater)rpt; SetAggregates(childData, childSurface.recId); repeater.DataSource = childData; repeater.DataBind(); utils.disposeSession("childButtons"); } } if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !_isReadOnly && !_isControlled) { //CVH 2016-12-20 Child grid default edit mode foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); RepeaterItem childRptItem = repeater.Items[0]; EditChild(editChildItemId, childRptItem); } break; } } } if (_relationalValues == "1" && panelFormHolder != null) { panelFormHolder.Visible = true; if (childData.Rows.Count > 0) { int childSurfaceItemId = childData.Rows[0].Field("itemID"); oSurfaceItem childItem = new oSurfaceItem(); foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childSurfaceItemId.ToString())) { childItem = item; } //PopulateSurfaceView(childItem, true); foreach (oSurfaceField childFields in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", childSurface.recId.ToString() + "," + (int)pNums.FieldType.Group)) { if (pnlSurfaceForm.FindControl("upv" + childSurface.recId.ToString() + childFields.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceForm.FindControl("upv" + childSurface.recId.ToString() + childFields.surfaceFieldName); } } } if (upGroup != null) upGroup.Update(); } } break; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Set Active for Child app so that rebind will select the appropriate tab /// /// private void SetActiveTabForChild(int surfaceId) { try { foreach (oSurface child in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", surfaceId.ToString())) { ArrayList gridFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence"); foreach (oSurfaceField gridField in gridFields) { if (gridField.relationalSurface == child.name) { foreach (oSurfaceField group in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", gridField.parentId.ToString())) { foreach (oSurfaceField tab in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", group.parentId.ToString())) { HtmlGenericControl myTab; if (pnlSurfaceForm.Visible) { myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); } else { myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_v" + tab.surfaceFieldName); } if (myTab != null) base.ActiveTabPanel = myTab.ClientID; break; } break; } break; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Populates the content surface field on the surface form during page initialization (otherwise viewstate is lost) /// /// private void PopulateSurfaceFormContentType(oSurfaceItem _surfaceItem) { try { //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", _surfaceItem.surfaceId + ",1," + ((int)pNums.FieldType.Content).ToString(), "sequence"); ArrayList surfaceFieldData = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId, "recId"); foreach (oSurfaceField field in surfaceFields) { if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab || field.surfaceFieldTypeId != (int)pNums.FieldType.Tab) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Content: //content Label lblContent = (Label)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (lblContent != null) { foreach (oContent contentItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "recId", field.contentId.ToString())) { lblContent.Text = contentItem.contentHTML; } } //view labels Label lblvContent = (Label)pnlSurfaceForm.FindControl("lblf" + field.surfaceFieldName); if (lblvContent != null) { foreach (oContent contentItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "recId", field.contentId.ToString())) { lblvContent.Text = contentItem.contentHTML; } } break; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Populate the surface compare view /// /// /// REVISION 001: Add functionality for field type Grid /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 14 December 2015 /// private void PopulateSurfaceCompareView(oSurfaceItem _surfaceItem, int colNum, string parentSurfaceField = "") { try { //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); ArrayList surfaceFieldData = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId, "recId"); //CVH 2017-02-07 Determine Divide Action to be used in formula field oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction lookupFieldAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) { if (act.actionType == (int)pNums.ActionType.Calculation) { if (act.action == "Divide") divideAction = act; else if (act.action == "Lookup") lookupAction = act; else if (act.action == "Lookup Field") lookupFieldAction = act; } else if (act.actionType == (int)pNums.ActionType.Aggregation) { if (act.action == "Sum") aggrSumAction = act; } } foreach (oSurfaceField field in surfaceFields) { if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab || field.surfaceFieldTypeId != (int)pNums.FieldType.Tab) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { #region Text case pNums.FieldType.Text://Textbox Label lbl = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lbl = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lbl = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lbl != null) { lbl.Text = ""; if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupFieldAction.recId) { List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = field.recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = _surfaceItem.recId; listLookup.Add(look2); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) lbl.Text = dtValue.Rows[0][0].ToString(); else lbl.Text = ""; } else { foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lbl.Text = data.surfaceFieldValueChar; break; } } } } break; #endregion #region Number case pNums.FieldType.Number: //number Label lblNum = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblNum = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblNum = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblNum != null) { lblNum.Text = ""; //CVH 2017-02-24 New action type Aggregation Sum if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); lblNum.Text = Math.Floor(decFormula).ToString(); } } else { foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lblNum.Text = data.surfaceFieldValueNum.ToString(); break; } } } } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal Label lblDecimal = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblDecimal = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblDecimal = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblDecimal != null) { lblDecimal.Text = ""; //CVH 2017-02-24 New action type Aggregation Sum if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); lblDecimal.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); } } else { foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lblDecimal.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); break; } } } } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist Label lblPicklist = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblPicklist = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblPicklist = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblPicklist != null) { lblPicklist.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) { if (field.alternateView && look.customCode != "") { lblPicklist.Text += look.customCode; } else { lblPicklist.Text += look.display; } break; } break; } } } break; #endregion #region MultiPicklist case pNums.FieldType.MultiPicklist: //MultiPicklist Label lblMultiPicklist = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblMultiPicklist = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblMultiPicklist = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblMultiPicklist != null) { lblMultiPicklist.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { string valueIds = data.surfaceFieldValueChar.ToString(); foreach (string valueId in valueIds.Split(',')) { foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", valueId)) { if (lblMultiPicklist.Text != "") lblMultiPicklist.Text += ", "; if (field.alternateView && look.customCode != "") { lblMultiPicklist.Text += look.customCode; } else { lblMultiPicklist.Text += look.display; } } } break; } } } break; #endregion #region Date case pNums.FieldType.Date: //date Label lblDate = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblDate = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblDate = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblDate != null) { lblDate.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lblDate.Text = data.surfaceFieldValueDate.ToString("dd/MM/yyyy"); break; } } } break; #endregion #region Checkbox case pNums.FieldType.Checkbox: //checkbox Label lblCheckbox = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCheckbox = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCheckbox = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblCheckbox != null) { lblCheckbox.Text = "No"; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { if (data.surfaceFieldValueBool == true) { lblCheckbox.Text = "Yes"; } break; } } } break; #endregion #region RadioButtonList /*JasR 2016-01-15 RadioButtonList*/ case pNums.FieldType.RadioButtonList: //radiobuttonlist Label lblRadioButtonList = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblRadioButtonList = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblRadioButtonList = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblRadioButtonList != null) { lblRadioButtonList.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) { lblRadioButtonList.Text = look.display; break; } break; } } } break; #endregion #region Caption //JasR 2016-01-27 Caption case pNums.FieldType.Caption: Label lblCaption = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCaption = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCaption = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblCaption != null) { lblCaption.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lblCaption.Text = data.surfaceFieldValueChar; break; } } } break; #endregion #region FormulaField case pNums.FieldType.FormulaField: Label lblFormula = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblFormula = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblFormula = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblFormula != null) { lblFormula.Text = ""; //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; //get source field foreach (oSurfaceField srcField in surfaceFields) { if (srcField.recId == field.actionSource) { foreach (oSurfaceFieldData data in surfaceFieldData) { if (srcField.recId == data.surfaceFieldID) { //catering for field types char, number, decimal if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out sourceValue); else if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) { conversionSuccess = true; sourceValue = data.surfaceFieldValueDecimal; } else conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out sourceValue); break; } } break; } } if (conversionSuccess) { lblFormula.Text = CalculateLookup(field, sourceValue); } } //CVH 2017-02-24 New action type Aggregation Sum else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); lblFormula.Text = utils.returnFormattedDecimal(decFormula.ToString()); } } else { foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { //CVH 2017-02-07 Divide Calculation Formula is saved in Char column if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) lblFormula.Text = data.surfaceFieldValueChar; else lblFormula.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); break; } } } } break; #endregion #region CheckboxList case pNums.FieldType.CheckboxList: //checkboxlist Label lblCheckboxList = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCheckboxList = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCheckboxList = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblCheckboxList != null) { lblCheckboxList.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") { string display = ""; //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { string lookupId = ""; if (temp.IndexOf("~R~") >= 0) lookupId = temp.Substring(0, temp.IndexOf("~R~")); else lookupId = temp; foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) { if (display == "") display = look.display; else display += ", " + look.display; break; } } lblCheckboxList.Text = display; } } } break; #endregion #region Image case pNums.FieldType.Image: //Image img = (Image)pnlSurfaceView.FindControl("imgv" + field.surfaceFieldName); Label lblImage = null; if (parentSurfaceField != "") { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblImage = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblImage = (Label)pnlSurfaceForm.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lblImage != null) { lblImage.Text = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { //not working //img.Attributes["src"] = "/upload/surface/"+data.surfaceFieldValueChar; if (data.surfaceFieldValueChar != String.Empty) { lblImage.Text = "
"; } else { lblImage.Text = "
"; } break; } } } break; #endregion } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void RebindChildGridBatchEdit() { try { if (base.SurfaceAppItem != null) { foreach (oSurfaceField gridField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Grid)) { oSurface childSurface = new oSurface(); foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", gridField.relationalSurface)) { //surfaceId = surf.recId; childSurface = surf; break; } if (childSurface.recId > 0) { foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { //find the div and bind all repeaters inside it Panel panelGridHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + gridField.surfaceId.ToString() + "_" + gridField.surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + gridField.surfaceId.ToString() + "_" + gridField.surfaceFieldName); if (panelGridHolder != null) { int rowLimit = 0; int.TryParse(gridField.relationalValues, out rowLimit); DataTable childData = new DataTable(); //CVH 2017-05-12 Populate Device Management child grid based on user email address if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && childSurface.name.EndsWith("DeviceManagement")) { List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "itemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetDeviceManagerChildData", listDevice); if (panelGridHolder != null) panelGridHolder.Enabled = false; } else if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "ScholarInformation" && childSurface.name.Contains("Mentorship")) { //CVH 2017-05-23 Mentorship child grids List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "ProfilesItemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); oDynamicParam param2 = new oDynamicParam(); param2.paramDisplayName = "option"; param2.paramObject = (gridField.surfaceFieldName.ToUpper().Contains("MENTEE") ? "2" : "1"); listDevice.Add(param2); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetMentorshipChildSurfaceData", listDevice); } else if (gridField.isControlled) { childData = xData.GetChildSurfaceQueryDataSummarized(childSurface.recId, base.SurfaceAppItemId, rowLimit); } else { childData = xData.GetChildSurfaceQueryData(childSurface.recId, base.SurfaceAppItem.recId, rowLimit); } Repeater repeater = null; foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { repeater = (Repeater)rpt; SetAggregates(childData, childSurface.recId); repeater.DataSource = childData; repeater.DataBind(); utils.disposeSession("childButtons"); } } //CVH 2017-02-23 Only put into edit mode if field is not Read Only if (repeater != null && repeater.Items.Count > 0 && !gridField.isReadOnly && !gridField.isControlled) { RepeaterItem rptItem = repeater.Items[0]; LinkButton lnkEdit = (LinkButton)rptItem.FindControl("lnkEdit"); if (lnkEdit != null) { int editChildItemId = int.Parse(lnkEdit.CommandArgument); RepeaterItem childRptItem = repeater.Items[0]; EditChild(editChildItemId, childRptItem); } } } } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Populate the surface form /// GR 2017-04-26 Revised to LinQ /// Performance Upgrade /// private void PopulateSurfaceForm(oSurfaceItem _surfaceItem, bool isNew) { bool wizardcompleted = false; try { bool blnSaveClicked = false; // TPS - We need to ensure that dropdown lists without events don't re-bind and clear the selection of pick lists still to be saved if (ViewState["saveClicked"] != null) blnSaveClicked = (bool)ViewState["saveClicked"]; if (!blnSaveClicked) // Do not allow the re-bind of the surface form in the middle of saving { //first fetch the field and data records DataTable surfaceFieldsTable = MainFieldTable; //xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "surfaceId"); DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId); //ArrayList surfaceFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); //ArrayList surfaceFieldData = utils.ConvertDataTableToListParallel(surfaceFieldDataTable, typeof(oSurfaceFieldData)); //var fieldDataQ = surfaceFieldData.OfType().AsQueryable(); var fieldDataTableEnum = surfaceFieldDataTable.AsEnumerable(); var fieldTableEnum = surfaceFieldsTable.AsEnumerable(); oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } oSetup setup = handler.ReturnSetup(); //CVH 2017-02-07 Determine Divide Action to be used in formula field oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction lookupFieldAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); oSurfaceAction fieldAggrSumAction = new oSurfaceAction(); oSurfaceAction fieldAggrDiffAction = new oSurfaceAction(); oSurfaceAction fieldAggrDistinctionAction = new oSurfaceAction(); oSurfaceAction fieldAggrPassedAction = new oSurfaceAction(); oSurfaceAction fieldAggrFailedAction = new oSurfaceAction(); foreach (DataRow actRow in xData.GetTypedTable("recId", typeof(oSurfaceAction)).Rows) { if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.Calculation) { if (actRow["action"].ToString() == "Divide") { divideAction.action = actRow["action"].ToString(); divideAction.actionType = int.Parse(actRow["actionType"].ToString()); divideAction.isActive = bool.Parse(actRow["isActive"].ToString()); divideAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Lookup") { lookupAction.action = actRow["action"].ToString(); lookupAction.actionType = int.Parse(actRow["actionType"].ToString()); lookupAction.isActive = bool.Parse(actRow["isActive"].ToString()); lookupAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Lookup Field") { lookupFieldAction.action = actRow["action"].ToString(); lookupFieldAction.actionType = int.Parse(actRow["actionType"].ToString()); lookupFieldAction.isActive = bool.Parse(actRow["isActive"].ToString()); lookupFieldAction.recId = int.Parse(actRow["recId"].ToString()); } } else if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.Aggregation) { if (actRow["action"].ToString() == "Sum") { aggrSumAction.action = actRow["action"].ToString(); aggrSumAction.actionType = int.Parse(actRow["actionType"].ToString()); aggrSumAction.isActive = bool.Parse(actRow["isActive"].ToString()); aggrSumAction.recId = int.Parse(actRow["recId"].ToString()); } } else if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.FieldAggregation) { if (actRow["action"].ToString() == "Sum") { fieldAggrSumAction.action = actRow["action"].ToString(); fieldAggrSumAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrSumAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrSumAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Difference") { fieldAggrDiffAction.action = actRow["action"].ToString(); fieldAggrDiffAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrDiffAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrDiffAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Distinction Count") { fieldAggrDistinctionAction.action = actRow["action"].ToString(); fieldAggrDistinctionAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrDistinctionAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrDistinctionAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Failed Count") { fieldAggrFailedAction.action = actRow["action"].ToString(); fieldAggrFailedAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrFailedAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrFailedAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Passed Count") { fieldAggrPassedAction.action = actRow["action"].ToString(); fieldAggrPassedAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrPassedAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrPassedAction.recId = int.Parse(actRow["recId"].ToString()); } } //JR 2017-06-10 not sure why this is needed. we only have a few actions, so the performance increase won't be that heavy //if (divideAction.recId > 0 && lookupAction.recId > 0 && aggrSumAction.recId > 0) //{ // break; //} } //CVH 2017-06-28 Used to populate Profiles Dean when populating School picklist TextBox txtSTUD1ProfilesDean = null; //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default string groupIdsWithData = ""; #region Header Groups and Groups var groupHeadData = from groupHeads in surfaceFieldsTable.AsEnumerable() where groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.HeaderGroup) || groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groupHeads; foreach (DataRow groupHeadRow in groupHeadData.ToList()) { string _surfaceFieldName = groupHeadRow["surfaceFieldName"].ToString(); int _surfaceFieldTypeId = int.Parse(groupHeadRow["surfaceFieldTypeId"].ToString()); int _accessLevel = 0; int.TryParse(groupHeadRow["accessLevel"].ToString(), out _accessLevel); Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + _surfaceFieldName); bool isHidden = false; bool.TryParse(groupHeadRow["isHidden"].ToString(), out isHidden); if (groupControl != null & !isHidden) { //CVH 2017-01-13 Ignore security on group if TSP and group is IOD groups hardcoded to show/hide depending on user selection if ((setup.code == "SHOU-1") && (_surfaceFieldName == "PatientInformation_EmployerDetailsInjuryonDuty" || _surfaceFieldName == "PatientInformation_MedicalAidIfapplicable")) { //do nothing } else if (setup.code == "GLOB-1" && _surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup && !_surfaceItem.isWizardCompleted) { groupControl.Visible = false; } else { groupControl.Visible = ((usr.userType >= _accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= _accessLevel && usr.userType == (int)pNums.UserType.CustomUser)); } } } #endregion #region Label Fields var labelData = from labels in fieldTableEnum where labels.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Label) select labels; foreach (DataRow LabelRow in labelData.ToList()) { //setup field values bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(LabelRow["isControlled"].ToString(), out _isControlled); bool.TryParse(LabelRow["isReadOnly"].ToString(), out _isReadOnly); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _surfaceId = int.Parse(LabelRow["surfaceId"].ToString()); string _surfaceFieldName = LabelRow["surfaceFieldName"].ToString(); string _surfaceFieldDisplay = LabelRow["surfaceFieldDisplay"].ToString(); string _controlText = LabelRow["controlText"].ToString(); if (_controlText != String.Empty) _surfaceFieldDisplay = _controlText; string _relationalSurface = LabelRow["relationalSurface"].ToString(); string _relationalValues = LabelRow["relationalValues"].ToString(); string _relationalFields = LabelRow["relationalFields"].ToString(); bool _defaultToCurrent = false; bool.TryParse(LabelRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(LabelRow["isComparable"].ToString(), out _isComparable); int _surfaceDateTypeId = 0; int.TryParse(LabelRow["surfaceDateTypeId"].ToString(), out _surfaceDateTypeId); int _actionType = 0; int.TryParse(LabelRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(LabelRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(LabelRow["actionSource"].ToString(), out _actionSource); string _actionValue = LabelRow["actionValue"].ToString(); int _recId = int.Parse(LabelRow["recId"].ToString()); string itemId = _surfaceItem.recId.ToString(); if (_isReadOnly)//hide labels on new { Control divControl; divControl = FindControl("srt" + _surfaceFieldName); if (divControl != null) divControl.Visible = false; } else { bool isImage = false; string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; if (_relationalSurface == "user") { foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = user.userDisplay; } } else if (_relationalSurface == "date") { if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; } } else if (_relationalSurface == "static") { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = _relationalValues; } else { if (itemId != "0") { //just read from char sourceFieldLabel = _surfaceFieldDisplay; var lData = from llblData in fieldDataTableEnum where llblData.Field("surfaceFieldID").Equals(_recId) select llblData; foreach (DataRow txtRow in lData.ToList()) { sourceFieldValue = txtRow["surfaceFieldValueChar"].ToString(); break; } } else //item doesn't exist, so will have to read label values from source { #region read label from source /* CVH 2017-05-19 Cater for linked surface labels in Form Edit mode */ if (base.SurfaceApp.isLinkedSurface && _relationalSurface != base.SurfaceApp.recId.ToString()) { sourceFieldLabel = _surfaceFieldDisplay; //int _recId = int.Parse(LabelRow["recId"].ToString()); var lData = from lblData in fieldDataTableEnum where lblData.Field("surfaceFieldID").Equals(_recId) select lblData; foreach (DataRow lblRow in lData.ToList()) { sourceFieldValue = lblRow["surfaceFieldValueChar"].ToString(); break; } } else { //jas bool isLabelFromChild = false; if (_relationalSurface != _surfaceItem.surfaceId.ToString()) { foreach (oSurfaceField relSurfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", _relationalFields)) { foreach (oSurfaceField relParentSurfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", relSurfaceField.surfaceId.ToString() + ",parentSurfaceItemId")) { foreach (oSurfaceFieldData parentFieldData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceFieldValueNum", relParentSurfaceField.surfaceId.ToString() + "," + relParentSurfaceField.recId.ToString() + "," + _surfaceItem.recId.ToString())) { isLabelFromChild = true; itemId = parentFieldData.surfaceItemId.ToString(); } } } } //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface if (!isLabelFromChild && _relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) itemId = base.ParentSurfaceItemId.ToString(); foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", _relationalSurface.ToString() + "," + _relationalFields.ToString())) { sourceFieldLabel = sourceField.surfaceFieldDisplay; foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _relationalSurface.ToString() + "," + _relationalFields.ToString() + "," + itemId)) { pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); switch (sourceType) { case pNums.FieldType.Text: case pNums.FieldType.Caption: case pNums.FieldType.Address: case pNums.FieldType.MultiPicklist: sourceFieldValue = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Number: sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); break; case pNums.FieldType.Decimal: sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); break; case pNums.FieldType.Date: string format = "dd/MM/yyyy"; if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) format = "MMMM yyyy"; else if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) format = "yyyy"; sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); break; case pNums.FieldType.Picklist: case pNums.FieldType.RadioButtonList: sourceFieldValue = ""; foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) { sourceFieldValue = look.display; break; } break; case pNums.FieldType.Checkbox: sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; break; case pNums.FieldType.FormulaField: sourceFieldValue = ""; //CVH 2017-02-13 New action Lookup need to recalc on load if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) { decimal lookupSrcValue = 0m; bool conversionSuccess = false; var sourceFieldData = from srcFields in fieldTableEnum where srcFields.Field("recId").Equals(sourceField.actionSource) select srcFields; foreach (DataRow lookupSourceFieldRow in sourceFieldData.ToList()) { int _recIdL = int.Parse(lookupSourceFieldRow["recId"].ToString()); int _surfaceFieldTypeId = int.Parse(lookupSourceFieldRow["surfaceFieldTypeId"].ToString()); var sData = from srcData in fieldDataTableEnum where srcData.Field("surfaceFieldID").Equals(_recIdL) select srcData; foreach (DataRow srcDataRow in sData.ToList()) { string _surfaceFieldValueChar = srcDataRow["surfaceFieldValueChar"].ToString(); int _surfaceFieldValueNum = int.Parse(srcDataRow["surfaceFieldValueNum"].ToString()); decimal _surfaceFieldValueDecimal = decimal.Parse(srcDataRow["surfaceFieldValueDecimal"].ToString()); if (_surfaceFieldTypeId == (int)pNums.FieldType.Number) conversionSuccess = decimal.TryParse(_surfaceFieldValueNum.ToString(), out lookupSrcValue); else if (_surfaceFieldTypeId == (int)pNums.FieldType.Decimal) { conversionSuccess = true; lookupSrcValue = _surfaceFieldValueDecimal; } else conversionSuccess = decimal.TryParse(_surfaceFieldValueChar, out lookupSrcValue); } } if (conversionSuccess) { sourceFieldValue = CalculateLookup(LabelRow, lookupSrcValue); } } //CVH 2017-02-07 New action Divide is saved in Char else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) { sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) { if (act.action == "Age") { //need to calculate age, it isn't always saved in the age field //get age source (date of birth) data DateTime? dob = null; foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) { dob = dobData.surfaceFieldValueDate; break; } if (dob != null) { oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); sourceFieldValue = age.years.ToString(); } } break; } } //CVH 2017-02-24 New action type Aggregation Sum else if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); } } else { sourceFieldValue = sourceData.surfaceFieldValueChar; } break; case pNums.FieldType.CheckboxList: sourceFieldValue = ""; //split string to get lookup IDs foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { string lookupId = ""; if (temp.IndexOf("~R~") >= 0) { lookupId = temp.Substring(0, temp.IndexOf("~R~")); } else { lookupId = temp; } //get lookup foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) { if (sourceFieldValue == String.Empty) sourceFieldValue = look.display; else sourceFieldValue += ", " + look.display; break; } } break; case pNums.FieldType.Image: HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "Div"); if (imageLabelDiv != null) { string imageUrl = "/images/placeholder.png"; imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } if (imageLabelDiv != null) { string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } isImage = true; break; case pNums.FieldType.Attachment: HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "LabelfAttachments"); int intItemIdAt = 0; int.TryParse(itemId, out intItemIdAt); if (attachDiv != null && intItemIdAt > 0) BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); break; case pNums.FieldType.Note: HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "LabelfNotes"); int intItemIdN = 0; int.TryParse(itemId, out intItemIdN); if (notesDiv != null && intItemIdN > 0) BindNotes(intItemIdN, notesDiv); break; } } } } #endregion } } Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + _surfaceFieldName + "Label"); if (lblLabel != null) { // Dirk Strauss - 11 May 2017 - Display Field Text was not being applied to labels. if (!(String.IsNullOrEmpty(_surfaceFieldDisplay))) lblLabel.Text = _surfaceFieldDisplay; else lblLabel.Text = sourceFieldLabel; } if (!isImage) { Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + _surfaceFieldName + "Value"); if (lblValue != null) { lblValue.Text = sourceFieldValue; } } } //CVH 2016-12-12 Don't expand collapsed group just for label groupIdsWithData += ""; } #endregion #region TextBoxes var textData = from textboxes in fieldTableEnum where textboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Text) select textboxes; foreach (DataRow textRow in textData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(textRow["isControlled"].ToString(), out _isControlled); bool.TryParse(textRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(textRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(textRow["recId"].ToString()); int _parentId = int.Parse(textRow["parentId"].ToString()); string _surfaceFieldName = textRow["surfaceFieldName"].ToString(); int _actionType = 0; int.TryParse(textRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(textRow["action"].ToString(), out _action); TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtTextbox != null) { txtTextbox.Text = ""; if (_actionType == (int)pNums.ActionType.Calculation && _action == lookupFieldAction.recId) { List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = _recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = _surfaceItem.recId; listLookup.Add(look2); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) txtTextbox.Text = dtValue.Rows[0][0].ToString(); enabled = false; } else if (!base.IsClone || (base.IsClone && _isCloneable)) { var tData = from txtData in fieldDataTableEnum where txtData.Field("surfaceFieldID").Equals(_recId) select txtData; foreach (DataRow txtRow in tData.ToList()) { txtTextbox.Text = txtRow["surfaceFieldValueChar"].ToString(); break; } } //CVH 2017-06-28 Get textbox to populate on Picklist load if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && _surfaceFieldName.EndsWith("Dean") && txtTextbox.Text == "") txtSTUD1ProfilesDean = txtTextbox; //CVH 2017-05-12 Populate Device Management User labels from selected picklist if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "DeviceManagement" && _surfaceFieldName.Contains("Profiles")) { enabled = false; } /* CVH 2016-01-20 */ txtTextbox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Numbers var numData = from numboxes in fieldTableEnum where numboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Number) select numboxes; foreach (DataRow numRow in numData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(numRow["isControlled"].ToString(), out _isControlled); bool.TryParse(numRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(numRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(numRow["recId"].ToString()); int _parentId = int.Parse(numRow["parentId"].ToString()); string _surfaceFieldName = numRow["surfaceFieldName"].ToString(); string _surfaceFieldDisplay = numRow["surfaceFieldDisplay"].ToString(); string _controlledValue = numRow["controlledValue"].ToString(); int _actionType = 0; int.TryParse(numRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(numRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(numRow["actionSource"].ToString(), out _actionSource); string _actionValue = numRow["actionValue"].ToString(); TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtNumberBox != null) { if (_isControlled) { int nextNumber = 0; int.TryParse(_controlledValue, out nextNumber); nextNumber++; txtNumberBox.Enabled = false; txtNumberBox.Text = nextNumber.ToString(); } else txtNumberBox.Text = ""; if (setup.code == "STUD-1" && _surfaceFieldDisplay.StartsWith("% of Subjects Failed")) { //leave num textbox blank if item ID = 0 if (base.SurfaceAppItemId != 0) { List listPortion = new List(); oDynamicParam por1 = new oDynamicParam(); por1.paramDisplayName = "surfaceId"; por1.paramObject = _surfaceItem.surfaceId; listPortion.Add(por1); oDynamicParam por2 = new oDynamicParam(); por2.paramDisplayName = "surfaceItemId"; por2.paramObject = base.SurfaceAppItemId; listPortion.Add(por2); DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePercentageTertiarySubjectsFailed", listPortion); if (dtPortion != null && dtPortion.Rows.Count > 0 && dtPortion.Rows[0][0].ToString() != "") { decimal decFailed = Convert.ToDecimal(dtPortion.Rows[0][0].ToString()); txtNumberBox.Text = Math.Floor(decFailed).ToString(); } enabled = false; } } else if (setup.code == "STUD-1" && _surfaceFieldDisplay.StartsWith("% of Subjects Passed")) { //leave num textbox blank if item ID = 0 if (base.SurfaceAppItemId != 0) { List listPortion = new List(); oDynamicParam por1 = new oDynamicParam(); por1.paramDisplayName = "surfaceId"; por1.paramObject = _surfaceItem.surfaceId; listPortion.Add(por1); oDynamicParam por2 = new oDynamicParam(); por2.paramDisplayName = "surfaceItemId"; por2.paramObject = base.SurfaceAppItemId; listPortion.Add(por2); DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePercentageTertiarySubjectsPassed", listPortion); if (dtPortion != null && dtPortion.Rows.Count > 0 && dtPortion.Rows[0][0].ToString() != "") { decimal decFailed = Convert.ToDecimal(dtPortion.Rows[0][0].ToString()); txtNumberBox.Text = Math.Floor(decFailed).ToString(); } enabled = false; } } else if (setup.code == "STUD-1" && _surfaceFieldDisplay.StartsWith("Course Aggregate")) { //leave num textbox blank if item ID = 0 if (base.SurfaceAppItemId != 0) { List listPortion = new List(); oDynamicParam por1 = new oDynamicParam(); por1.paramDisplayName = "surfaceId"; por1.paramObject = _surfaceItem.surfaceId; listPortion.Add(por1); oDynamicParam por2 = new oDynamicParam(); por2.paramDisplayName = "surfaceItemId"; por2.paramObject = base.SurfaceAppItemId; listPortion.Add(por2); DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculateTertiaryAggregate", listPortion); if (dtPortion != null && dtPortion.Rows.Count > 0 && dtPortion.Rows[0][0].ToString() != "") { decimal decFailed = Convert.ToDecimal(dtPortion.Rows[0][0].ToString()); txtNumberBox.Text = Math.Floor(decFailed).ToString(); } enabled = false; } } //CVH 2017-05-12 Only clone fields that are cloneable else if (!base.IsClone || (base.IsClone && !_isControlled) || (base.IsClone && _isCloneable)) { //CVH 2017-02-28 New action type Aggregation Sum if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); txtNumberBox.Text = Math.Floor(decFormula).ToString(); } } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrSumAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtNumberBox.Text = Math.Floor(decFormula).ToString(); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrDistinctionAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationDistinction(_surfaceItem.recId, _actionValue); txtNumberBox.Text = Math.Floor(decFormula).ToString(); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrFailedAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationFailed(_surfaceItem.recId, _actionValue); txtNumberBox.Text = Math.Floor(decFormula).ToString(); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrPassedAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationPassed(_surfaceItem.recId, _actionValue); txtNumberBox.Text = Math.Floor(decFormula).ToString(); } else { var nData = from numberData in fieldDataTableEnum where numberData.Field("surfaceFieldID").Equals(_recId) select numberData; foreach (DataRow numDRow in nData.ToList()) { txtNumberBox.Text = numDRow["surfaceFieldValueNum"].ToString(); break; } } } //CVH 2017-02-28 If Aggregation Sum action, always disable if ((_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) || (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrDistinctionAction.recId) || (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrFailedAction.recId) || (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrPassedAction.recId) || (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrSumAction.recId)) txtNumberBox.Enabled = false; else txtNumberBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Decimals var decData = from decboxes in fieldTableEnum where decboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Decimal) select decboxes; foreach (DataRow decRow in decData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(decRow["isControlled"].ToString(), out _isControlled); bool.TryParse(decRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(decRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(decRow["recId"].ToString()); int _parentId = int.Parse(decRow["parentId"].ToString()); string _surfaceFieldName = decRow["surfaceFieldName"].ToString(); string _surfaceFieldDisplay = decRow["surfaceFieldDisplay"].ToString(); int _actionType = 0; int.TryParse(decRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(decRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(decRow["actionSource"].ToString(), out _actionSource); string _actionValue = decRow["actionValue"].ToString(); TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtDecimalBox != null) { txtDecimalBox.Text = ""; if (setup.code == "STUD-1" && _surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) { //leave decimal textbox blank if item ID = 0 if (base.SurfaceAppItemId != 0) { //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) List listPortion = new List(); oDynamicParam por1 = new oDynamicParam(); por1.paramDisplayName = "surfaceId"; por1.paramObject = _surfaceItem.surfaceId; listPortion.Add(por1); oDynamicParam por2 = new oDynamicParam(); por2.paramDisplayName = "surfaceItemId"; por2.paramObject = base.SurfaceAppItemId; listPortion.Add(por2); oDynamicParam por3 = new oDynamicParam(); por3.paramDisplayName = "option"; por3.paramObject = _surfaceFieldDisplay.Contains("Primary") ? "Primary" : _surfaceFieldDisplay.Contains("Member") ? "Member" : ""; listPortion.Add(por3); DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); if (dtPortion != null && dtPortion.Rows.Count > 0) txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); enabled = false; } } //else if (setup.code == "STUD-1" && _surfaceFieldDisplay.StartsWith("Shortfall")) //{ // //leave decimal textbox blank if item ID = 0 // if (base.SurfaceAppItemId != 0) // { // //Jas 2017-06-10 Calculate Shortfall as: Total Cost - Total Funding // List listShortfall = new List(); // oDynamicParam por1 = new oDynamicParam(); // por1.paramDisplayName = "surfaceId"; // por1.paramObject = _surfaceItem.surfaceId; // listShortfall.Add(por1); // oDynamicParam por2 = new oDynamicParam(); // por2.paramDisplayName = "surfaceItemId"; // por2.paramObject = base.SurfaceAppItemId; // listShortfall.Add(por2); // DataTable dtShortfall = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculateShortfall", listShortfall); // if (dtShortfall != null && dtShortfall.Rows.Count > 0) // txtDecimalBox.Text = utils.returnFormattedDecimal(dtShortfall.Rows[0][0].ToString()); // enabled = false; // } //} else { //CVH 2017-02-28 New action type Aggregation Sum if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); } } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrSumAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtDecimalBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrDiffAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationDiff(_surfaceItem.recId, _actionValue); txtDecimalBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrSumAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtDecimalBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } else if (_actionType == (int)pNums.ActionType.FieldAggregation && _action == fieldAggrDiffAction.recId) { decimal decFormula = xData.GetSurfaceFieldAggregationDiff(_surfaceItem.recId, _actionValue); txtDecimalBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } else { //CVH 2017-05-12 Only clone cloneable fields if (!base.IsClone || (base.IsClone && _isCloneable)) { var dData = from decimalData in fieldDataTableEnum where decimalData.Field("surfaceFieldID").Equals(_recId) select decimalData; foreach (DataRow decDRow in dData.ToList()) { txtDecimalBox.Text = utils.returnFormattedDecimal(decDRow["surfaceFieldValueDecimal"].ToString()); break; } } } } //CVH 2017-02-28 If Aggregation Sum action, always disable if ((_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) || _actionType == (int)pNums.ActionType.FieldAggregation) txtDecimalBox.Enabled = false; else txtDecimalBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Picklists var pickData = from piclists in fieldTableEnum where piclists.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Picklist) select piclists; foreach (DataRow pickRow in pickData.ToList()) { bool _isCustomSource = false; bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(pickRow["isCustomSource"].ToString(), out _isCustomSource); bool.TryParse(pickRow["isControlled"].ToString(), out _isControlled); bool.TryParse(pickRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(pickRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(pickRow["recId"].ToString()); int _parentId = int.Parse(pickRow["parentId"].ToString()); string _surfaceFieldName = pickRow["surfaceFieldName"].ToString(); // Pro-Pro-20 - Dirk Strauss - 16 May 2017 string _surfaceFieldDisplay = pickRow["surfaceFieldDisplay"].ToString(); //GR 2017-07-04 handle custom source binding string _relationalObject = pickRow["relationalObject"].ToString(); string _relationalFields = pickRow["relationalFields"].ToString(); string _relationalValues = pickRow["relationalValues"].ToString(); string _relationalOrderBy = pickRow["relationalOrderBy"].ToString(); string _relationalWhere = pickRow["relationalWhere"].ToString(); int _lookupCategory = 0; int.TryParse(pickRow["lookupCategory"].ToString(), out _lookupCategory); DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(_surfaceFieldName); TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + _surfaceFieldName); RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + _surfaceFieldName); //CVH 2017-03-01 First off clear reason if (txtPicklistReason != null) txtPicklistReason.Text = ""; if (ddDropdownlist != null) { //bool blnSaveClicked = false; // TPS - We need to ensure that dropdown lists without events don't re-bind and clear the selection of pick lists still to be saved //if (ViewState["saveClicked"] != null) // blnSaveClicked = (bool)ViewState["saveClicked"]; if (!blnSaveClicked) // Do not allow the re-bind of the surface form in the middle of saving { if (_isCustomSource)//GR 2017-07-04 handle custom source binding { if (_relationalObject != String.Empty) { string fieldSelect = String.Empty; String[] flds = _relationalFields.Split(char.Parse(",")); foreach (string f in flds) { if (fieldSelect == String.Empty) fieldSelect = f; else fieldSelect += " + ' ' + " + f; } string query = "Select " + _relationalValues + ", " + fieldSelect + " AS Display FROM " + _relationalObject + " "; if (_relationalWhere != String.Empty) { query += "WHERE " + _relationalWhere + " "; } if (_relationalOrderBy != String.Empty) { query += "ORDER By " + _relationalOrderBy + " "; } DataTable customDT = xData.GetCustomTypedTable(query); ddDropdownlist.DataSource = customDT; ddDropdownlist.DataTextField = "Display"; ddDropdownlist.DataValueField = _relationalValues; ddDropdownlist.DataBind(); ddDropdownlist.Items.Insert(0, new ListItem("select", "0")); } } else { ddDropdownlist.SelectedIndex = -1; } //CVH 2017-05-12 Populate Device Management Users picklist with Profile email addresses if (handler.ReturnSetup().code == "STUD-1" && (base.SurfaceApp.name == "DeviceManagement" || base.SurfaceApp.name.StartsWith("Mentorship")) && _surfaceFieldName.EndsWith("Email")) { List listDevice = new List(); oDynamicParam param = new oDynamicParam(); param.paramDisplayName = "option"; param.paramObject = (base.SurfaceApp.name == "DeviceManagement" ? "1" : "2"); listDevice.Add(param); DataTable dtProfileEmails = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetProfileEmailAddresses", listDevice); if (dtProfileEmails != null) { ddDropdownlist.DataSource = dtProfileEmails; ddDropdownlist.DataValueField = "itemId"; ddDropdownlist.DataTextField = "Email"; ddDropdownlist.DataBind(); } ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); } //CVH 2016-10-21 Also check !="0" otherwise it adds extra "Select" item for normal dropdowns (relationalObject saves as "0") //if (field.relationalObject.Length > 0) else if (_relationalObject.Length > 0 && _relationalObject != "0") { if (_relationalObject == "oSurface") { int surfaceFieldId = 0; int.TryParse(pickRow["relationalFields"].ToString(), out surfaceFieldId); DataTable dtSurfaceData = xData.GetSurfaceModulePicklist(surfaceFieldId); ddDropdownlist.DataSource = dtSurfaceData; ddDropdownlist.DataTextField = "DataText"; ddDropdownlist.DataValueField = "DataValue"; ddDropdownlist.DataBind(); if (ddDropdownlist.Items.Count == 0) { enabled = false; ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); } else ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); } else { Assembly asm = typeof(oModule).Assembly; Type type = asm.GetType(_relationalObject); DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", _relationalObject); foreach (DataRow row in dtModule.Rows) { DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); ddDropdownlist.DataSource = dtModuleData; ddDropdownlist.DataValueField = row["valueField"].ToString(); ddDropdownlist.DataTextField = row["displayField"].ToString(); } ddDropdownlist.DataBind(); if (ddDropdownlist.Items.Count == 0) { enabled = false; ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); } else ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); } } //CVH 2017-05-12 Only clone if cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var pData = from picklistData in fieldDataTableEnum where picklistData.Field("surfaceFieldID").Equals(_recId) select picklistData; if (pData.Count() > 0) { foreach (DataRow picRow in pData.ToList()) { string _surfaceFieldValueChar = picRow["surfaceFieldValueChar"].ToString(); if (handler.ReturnSetup().code == "STUD-1" && (base.SurfaceApp.name == "DeviceManagement" || base.SurfaceApp.name.StartsWith("Mentorship")) && _surfaceFieldName.EndsWith("Email")) { if (ddDropdownlist.Items.FindByText(_surfaceFieldValueChar) != null) ddDropdownlist.Items.FindByText(_surfaceFieldValueChar).Selected = true; } else if (_relationalObject.Length > 0 && _relationalObject != "0") { if (_relationalObject == "oSurface") { if (ddDropdownlist.Items.FindByText(_surfaceFieldValueChar) != null) { ddDropdownlist.Items.FindByText(_surfaceFieldValueChar).Selected = true; //CVH 2017-06-28 Populate Profiles Dean based on selected School if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && _surfaceFieldName.EndsWith("School") && txtSTUD1ProfilesDean != null && _surfaceFieldValueChar != "") { string school = _surfaceFieldValueChar; foreach (oSurface schoolSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "surface", "School Setup")) { DataTable dtSchool = xData.GetSurfaceQueryDataPaged(schoolSurface.recId, 0, 100, "", "", User.recId); DataColumn colSchool = null; DataColumn colDean = null; foreach (DataColumn col in dtSchool.Columns) { if (col.ColumnName.EndsWith("School")) colSchool = col; else if (col.ColumnName.EndsWith("Dean")) colDean = col; } if (colSchool != null && colDean != null) { foreach (DataRow row in dtSchool.Rows) { if (row[colSchool].ToString() == school) { txtSTUD1ProfilesDean.Text = row[colDean].ToString(); break; } } } } } } } else { if (ddDropdownlist.Items.FindByValue(_surfaceFieldValueChar) != null) ddDropdownlist.SelectedValue = _surfaceFieldValueChar; } } else { int _surfaceFieldLookupID = 0; int.TryParse(picRow["surfaceFieldLookupID"].ToString(), out _surfaceFieldLookupID); if (ddDropdownlist.Items.FindByValue(_surfaceFieldLookupID.ToString()) != null) ddDropdownlist.SelectedValue = _surfaceFieldLookupID.ToString(); if (txtPicklistReason != null) { txtPicklistReason.Text = _surfaceFieldValueChar; //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", _lookupCategory + ",1"); if (catWantsReason != null && catWantsReason.Count > 0) { txtPicklistReason.Visible = true; txtPicklistReason.Enabled = false; foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", _surfaceFieldLookupID.ToString())) { if (lookupItem.wantsReason) { txtPicklistReason.Enabled = true; if (rfvPicklistReason != null) rfvPicklistReason.ControlToValidate = txtPicklistReason.ID; } else { txtPicklistReason.Enabled = false; txtPicklistReason.Text = ""; } } } else txtPicklistReason.Visible = false; } } break; } } else if (txtPicklistReason != null) { //always disable reason if no selection txtPicklistReason.Enabled = false; ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", _lookupCategory + ",1"); if (catWantsReason != null && catWantsReason.Count > 0) txtPicklistReason.Visible = true; else txtPicklistReason.Visible = false; } } else if (txtPicklistReason != null) { //always disable reason if no selection txtPicklistReason.Enabled = false; ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", _lookupCategory + ",1"); if (catWantsReason != null && catWantsReason.Count > 0) txtPicklistReason.Visible = true; else txtPicklistReason.Visible = false; } ddDropdownlist.Enabled = enabled; //if dropdownlist is not enabled, reason shouldn't be enabled either if (txtPicklistReason != null && !ddDropdownlist.Enabled) txtPicklistReason.Enabled = false; if (_surfaceFieldName == "PatientType_PatientType_PatientType") { SetPatientType("PatientType_PatientType_PatientType"); } //CVH 2016-12-12 Group default collapse if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedIndex != -1 && ddDropdownlist.SelectedValue != "0" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; //CVH 2017-01-18 Toggle View Action: If checkedchanged event is linked to picklist, call method to set controls Visible=false/true depending on selected value if (ddDropdownlist.AutoPostBack) SetToggleViewActionVisibilityPicklist(ddDropdownlist); } } } #endregion #region Multi Picklists var mpickData = from mpiclists in fieldTableEnum where mpiclists.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.MultiPicklist) select mpiclists; foreach (DataRow pickRow in mpickData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(pickRow["isControlled"].ToString(), out _isControlled); bool.TryParse(pickRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(pickRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(pickRow["recId"].ToString()); int _parentId = int.Parse(pickRow["parentId"].ToString()); string _surfaceFieldName = pickRow["surfaceFieldName"].ToString(); string _relationalObject = pickRow["relationalObject"].ToString(); int _lookupCategory = 0; int.TryParse(pickRow["lookupCategory"].ToString(), out _lookupCategory); ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (listBox != null) { if (_relationalObject.Length > 0 && _relationalObject != "0") { Assembly asm = typeof(oModule).Assembly; Type type = asm.GetType(_relationalObject); DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", _relationalObject); foreach (DataRow row in dtModule.Rows) { DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); listBox.DataSource = dtModuleData; listBox.DataValueField = row["valueField"].ToString(); listBox.DataTextField = row["displayField"].ToString(); } listBox.DataBind(); } listBox.ClearSelection(); var pData = from picklistData in fieldDataTableEnum where picklistData.Field("surfaceFieldID").Equals(_recId) select picklistData; //CVH 2-17-05-12 Only clone if cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { foreach (DataRow picRow in pData.ToList()) { string valueIds = picRow["surfaceFieldValueChar"].ToString(); foreach (string valueId in valueIds.Split(',')) { foreach (ListItem item in listBox.Items) { if (item.Value == valueId) { item.Selected = true; break; } } } } } listBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (listBox.GetSelectedIndices().Count() > 0 && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Dates var dateData = from dates in fieldTableEnum where dates.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Date) select dates; foreach (DataRow dtRow in dateData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(dtRow["isControlled"].ToString(), out _isControlled); bool.TryParse(dtRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(dtRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(dtRow["recId"].ToString()); int _parentId = int.Parse(dtRow["parentId"].ToString()); string _surfaceFieldName = dtRow["surfaceFieldName"].ToString(); bool _defaultToCurrent = bool.Parse(dtRow["defaultToCurrent"].ToString()); string _defaultValue = dtRow["defaultValue"].ToString(); int _surfaceDateTypeId = 0; int.TryParse(dtRow["surfaceDateTypeId"].ToString(), out _surfaceDateTypeId); TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtDate != null) { string format = "dd/MM/yyyy"; if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) format = "MMMM yyyy"; else if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) format = "yyyy"; if (_defaultToCurrent) txtDate.Text = DateTime.Now.ToString(format); else if (_defaultValue != "") txtDate.Text = _defaultValue; else txtDate.Text = ""; //CVH 2017-05-12 Only clone if cloneable if (!base.IsClone || (base.IsClone && !_defaultToCurrent) || (base.IsClone && _isCloneable)) { var pData = from picklistData in fieldDataTableEnum where picklistData.Field("surfaceFieldID").Equals(_recId) select picklistData; foreach (DataRow dteRow in pData.ToList()) { if (dteRow["surfaceFieldValueDate"].ToString() != "") { txtDate.Text = DateTime.Parse(dteRow["surfaceFieldValueDate"].ToString()).ToString(format); //CVH 2016-12-21 Show empty textbox if date is min date if (DateTime.Parse(dteRow["surfaceFieldValueDate"].ToString()) == DateTime.Parse("1900/01/01")) txtDate.Text = ""; } //CVH 2016-12-12 Group default collapse - don't apply if set to current date or minimum date if (txtDate.Text != "" && txtDate.Text != DateTime.Now.ToString(format) && txtDate.Text != _surfaceItem.dateCreated.ToString(format) && DateTime.Parse(dteRow["surfaceFieldValueDate"].ToString()) != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } /* CVH 2016-01-20 */ txtDate.Enabled = enabled; } } #endregion #region Checkboxes var boxData = from boxes in fieldTableEnum where boxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Checkbox) select boxes; foreach (DataRow bxRow in boxData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _isCloneable = false; bool.TryParse(bxRow["isControlled"].ToString(), out _isControlled); bool.TryParse(bxRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(bxRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(bxRow["recId"].ToString()); int _parentId = int.Parse(bxRow["parentId"].ToString()); string _surfaceFieldName = bxRow["surfaceFieldName"].ToString(); CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (chkBox != null) { chkBox.Checked = false; //CVH 2017-05-12 Only clone when cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var bData = from checkData in fieldDataTableEnum where checkData.Field("surfaceFieldID").Equals(_recId) select checkData; foreach (DataRow chkRow in bData.ToList()) { chkBox.Checked = bool.Parse(chkRow["surfaceFieldValueBool"].ToString()); break; } } /* CVH 2016-01-20 */ chkBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (chkBox.Checked && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Radiobutton Lists var radioData = from radios in fieldTableEnum where radios.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RadioButtonList) select radios; foreach (DataRow radRow in radioData.ToList()) { bool _isCustomSource = false; bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(radRow["isCustomSource"].ToString(), out _isCustomSource); bool.TryParse(radRow["isControlled"].ToString(), out _isControlled); bool.TryParse(radRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(radRow["required"].ToString(), out _required); bool.TryParse(radRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(radRow["recId"].ToString()); int _parentId = int.Parse(radRow["parentId"].ToString()); string _surfaceFieldName = radRow["surfaceFieldName"].ToString(); //GR 2017-07-04 handle custom source binding string _relationalObject = radRow["relationalObject"].ToString(); string _relationalFields = radRow["relationalFields"].ToString(); string _relationalValues = radRow["relationalObject"].ToString(); string _relationalOrderBy = radRow["relationalObject"].ToString(); string _relationalWhere = radRow["relationalWhere"].ToString(); int _lookupCategory = 0; int.TryParse(radRow["lookupCategory"].ToString(), out _lookupCategory); RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(_surfaceFieldName); TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + _surfaceFieldName); RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + _surfaceFieldName); if (radioButtonList != null) { if (_isCustomSource)//GR 2017-07-04 handle custom source binding { if (_relationalObject != String.Empty) { string fieldSelect = String.Empty; String[] flds = _relationalFields.Split(char.Parse(",")); foreach (string f in flds) { if (fieldSelect == String.Empty) fieldSelect = f; else fieldSelect += " + ' ' + " + f; } string query = "Select " + _relationalValues + ", " + fieldSelect + " AS Display FROM " + _relationalObject + " "; if (_relationalWhere != String.Empty) { query += "WHERE " + _relationalWhere + " "; } if (_relationalOrderBy != String.Empty) { query += "ORDER By " + _relationalOrderBy + " "; } DataTable customDT = xData.GetCustomTypedTable(query); radioButtonList.DataSource = customDT; radioButtonList.DataTextField = "Display"; radioButtonList.DataValueField = _relationalValues; radioButtonList.DataBind(); } } else { radioButtonList.SelectedIndex = -1; //CVH 2016-11-30 Set default reason visible / not visible, otherwise not handled correctly when editing, but no data saved if (txtReason != null) { //always disable reason if no data selected txtReason.Text = ""; txtReason.Enabled = false; ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", _lookupCategory + ",1"); if (catWantsReason != null && catWantsReason.Count > 0) txtReason.Visible = true; else txtReason.Visible = false; } } //CVH 2017-05-12 Only clone if cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var rData = from radiosData in fieldDataTableEnum where radiosData.Field("surfaceFieldID").Equals(_recId) && !radiosData.Field("surfaceFieldLookupID").Equals(0) select radiosData; if (rData.Count() > 0) { foreach (DataRow radDataRow in rData.ToList()) { string _surfaceFieldValueChar = radDataRow["surfaceFieldValueChar"].ToString(); int _surfaceFieldLookupID = 0; int.TryParse(radDataRow["surfaceFieldLookupID"].ToString(), out _surfaceFieldLookupID); if (_isCustomSource) { radioButtonList.SelectedValue = _surfaceFieldValueChar; } else { if (radioButtonList.Items.FindByValue(_surfaceFieldLookupID.ToString()) != null) radioButtonList.SelectedValue = _surfaceFieldLookupID.ToString(); } //IOD stuff if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = (radioButtonList.SelectedItem.Text == "Yes"); Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); if (MedGroup != null) MedGroup.Visible = !(radioButtonList.SelectedItem.Text == "Yes"); UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); if (uIODPanel != null) uIODPanel.Update(); UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); if (uMedPanel != null) uMedPanel.Update(); } if (txtReason != null) { txtReason.Text = ""; txtReason.Text = _surfaceFieldValueChar; foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", _surfaceFieldLookupID.ToString())) { //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); if (catWantsReason != null && catWantsReason.Count > 0) { txtReason.Visible = true; if (lookupItem.wantsReason) { txtReason.Enabled = true; if (rfvRadioButtonListReason != null) { if (_required) { rfvRadioButtonListReason.ControlToValidate = txtReason.ID; rfvRadioButtonListReason.Enabled = true; } else rfvRadioButtonListReason.Enabled = false; } } else txtReason.Enabled = false; } else txtReason.Visible = false; } } } } else { //CVH 2017-01-10 TSP If there is no data, and the field is IOD, show the medical aid group and hide the employer group if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = false; Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); if (MedGroup != null) MedGroup.Visible = true; UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); if (uIODPanel != null) uIODPanel.Update(); UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); if (uMedPanel != null) uMedPanel.Update(); } } } //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state if (radioButtonList.AutoPostBack) SetToggleViewActionVisibilityRadioButtonList(radioButtonList); radioButtonList.Enabled = enabled; if (txtReason != null && !radioButtonList.Enabled) txtReason.Enabled = false; //CVH 2016-12-12 Group default collapse if (radioButtonList.SelectedItem != null && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Placeholders //no action #endregion #region Captions var captData = from caps in fieldTableEnum where caps.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Caption) select caps; foreach (DataRow capRow in captData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool.TryParse(capRow["isControlled"].ToString(), out _isControlled); bool.TryParse(capRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(capRow["required"].ToString(), out _required); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(capRow["recId"].ToString()); int _parentId = int.Parse(capRow["parentId"].ToString()); string _surfaceFieldName = capRow["surfaceFieldName"].ToString(); TextBox textArea = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (textArea != null) { textArea.Text = ""; var tData = from capData in fieldDataTableEnum where capData.Field("surfaceFieldID").Equals(_recId) select capData; if (tData.Count() > 0) { foreach (DataRow capDataRow in tData.ToList()) { textArea.Text = capDataRow["surfaceFieldValueChar"].ToString(); } } textArea.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (textArea.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Formula Fields var ffData = from fflds in fieldTableEnum where fflds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.FormulaField) select fflds; foreach (DataRow ffRow in ffData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(ffRow["isControlled"].ToString(), out _isControlled); bool.TryParse(ffRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(ffRow["required"].ToString(), out _required); bool.TryParse(ffRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(ffRow["recId"].ToString()); int _parentId = int.Parse(ffRow["parentId"].ToString()); int _surfaceId = int.Parse(ffRow["surfaceId"].ToString()); string _surfaceFieldName = ffRow["surfaceFieldName"].ToString(); string _controlledValue = ffRow["controlledValue"].ToString(); int _actionType = 0; int.TryParse(ffRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(ffRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(ffRow["actionSource"].ToString(), out _actionSource); string _actionValue = ffRow["actionValue"].ToString(); TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtFormulaBox != null) { txtFormulaBox.Text = ""; //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate if (_actionType == (int)pNums.ActionType.Calculation && _action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; var sfData = from sflds in fieldTableEnum where sflds.Field("recId").Equals(_actionSource) select sflds; foreach (DataRow srcFRow in sfData.ToList()) { int _srcRecId = int.Parse(srcFRow["recId"].ToString()); int _srcFieldTypeId = int.Parse(srcFRow["surfaceFieldTypeId"].ToString()); var srcData = from sourceData in fieldDataTableEnum where sourceData.Field("surfaceFieldID").Equals(_srcRecId) select sourceData; if (srcData.Count() > 0) { foreach (DataRow srcFDataRow in srcData.ToList()) { int _srcDataFieldNum = 0; int.TryParse(srcFDataRow["surfaceFieldValueNum"].ToString(), out _srcDataFieldNum); decimal _srcDataFieldDecimal = 0; decimal.TryParse(srcFDataRow["surfaceFieldValueDecimal"].ToString(), out _srcDataFieldDecimal); string _srcDataFieldChar = srcFDataRow["surfaceFieldValueChar"].ToString(); //catering for field types char, number, decimal if (_srcFieldTypeId == (int)pNums.FieldType.Number) conversionSuccess = decimal.TryParse(_srcDataFieldNum.ToString(), out sourceValue); else if (_srcFieldTypeId == (int)pNums.FieldType.Decimal) { conversionSuccess = true; sourceValue = _srcDataFieldDecimal; } else conversionSuccess = decimal.TryParse(_srcDataFieldChar, out sourceValue); } } } if (conversionSuccess) { txtFormulaBox.Text = CalculateLookup(ffRow, sourceValue); } } //CVH 2017-02-24 New action type Aggregation Sum else if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } } //CVH 2017-05-12 Only clone when cloneable else if (!base.IsClone || (base.IsClone && _isCloneable)) { var fldData = from ffldData in fieldDataTableEnum where ffldData.Field("surfaceFieldID").Equals(_recId) select ffldData; if (fldData.Count() > 0) { foreach (DataRow FFDataRow in fldData.ToList()) { string _ffFieldDataChar = FFDataRow["surfaceFieldValueChar"].ToString(); decimal _ffFieldDataDecimal = 0; decimal.TryParse(FFDataRow["surfaceFieldValueDecimal"].ToString(), out _ffFieldDataDecimal); int _ffFieldDataSurfaceItemId = int.Parse(FFDataRow["surfaceItemId"].ToString()); //CVH 2017-02-07 Divide Calculation Formula is saved in Char column if (_actionType == (int)pNums.ActionType.Calculation && _action == divideAction.recId) { txtFormulaBox.Text = _ffFieldDataChar; } else if (_actionType == (int)pNums.ActionType.Calculation && _action != divideAction.recId) { foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", _action.ToString())) { if (act.action == "Age") { //need to calculate age, it isn't always saved in the age field //get age source (date of birth) data DateTime? dob = null; foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", _surfaceId + "," + _ffFieldDataSurfaceItemId + "," + _actionSource)) { dob = dobData.surfaceFieldValueDate; break; } if (dob != null) { oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); txtFormulaBox.Text = age.years.ToString(); txtFormulaBox.Enabled = false; } } break; } } else { if (_ffFieldDataDecimal != 0) txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(_ffFieldDataDecimal)); if (_ffFieldDataChar != string.Empty) txtFormulaBox.Text = _ffFieldDataChar; } } } } if (_actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; List sicParams = new List(); oDynamicParam sicParam = new oDynamicParam(); sicParam.paramDisplayName = "userId"; sicParam.paramObject = userId; sicParams.Add(sicParam); DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); if (nextCodeTable.Rows.Count > 0) { txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); if (txtFormulaBox.Text == "-1") txtFormulaBox.Text = ""; } else { txtFormulaBox.Text = ""; } } if (_actionType == (int)pNums.ActionType.FieldAggregation) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } if (_actionType == (int)pNums.ActionType.FieldAggregation) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } //txtFormulaBox.Enabled = enabled; //CVH 2017-02-07 Divide Calculation Formula field is always read only //JR same with field aggregation if ((_actionType == (int)pNums.ActionType.Calculation && (_action == divideAction.recId || _action == lookupAction.recId)) || (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) || _actionType == (int)pNums.ActionType.FieldAggregation) txtFormulaBox.Enabled = false; else txtFormulaBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Address Fields var addrData = from addrFlds in fieldTableEnum where addrFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Address) select addrFlds; foreach (DataRow addrRow in addrData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(addrRow["isControlled"].ToString(), out _isControlled); bool.TryParse(addrRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(addrRow["required"].ToString(), out _required); bool.TryParse(addrRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(addrRow["recId"].ToString()); int _parentId = int.Parse(addrRow["parentId"].ToString()); int _surfaceId = int.Parse(addrRow["surfaceId"].ToString()); string _surfaceFieldName = addrRow["surfaceFieldName"].ToString(); bool found = false; int itemNoClr = 0; do { found = false; itemNoClr++; if (itemNoClr == 2 && handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(_surfaceFieldName + itemNoClr + "dd"); if (ddSuburb != null) { found = true; ddSuburb.DataSource = SuburbTable; ddSuburb.DataValueField = "display"; ddSuburb.DataTextField = "display"; ddSuburb.DataBind(); ddSuburb.Items.Insert(0, new ListItem("Select", "0")); ddSuburb.SelectedIndex = 0; } } else { TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName + itemNoClr); if (txtAddress != null) { txtAddress.Text = ""; found = true; //JR 2017-02-12 Set default Province for SBF if (itemNoClr == 4 && handler.ReturnSetup().code == "STUD-1") { txtAddress.Text = "Western Cape"; txtAddress.Enabled = false; } } } } while (found && itemNoClr < 50); //CVH 2017-05-12 Only clone when cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var addressData = from addresses in fieldDataTableEnum where addresses.Field("surfaceFieldID").Equals(_recId) select addresses; if (addressData.Count() > 0) { foreach (DataRow addrDataRow in addressData.ToList()) { string _addrDataChar = addrDataRow["surfaceFieldValueChar"].ToString(); int itemNo = 0; foreach (string addressLine in _addrDataChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { itemNo++; if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(_surfaceFieldName + itemNo + "dd"); if (ddSuburb != null) { //CVH 2017-02-27 Clear selection, otherwise get exception when index 0 is selected when binding ddSuburb.Items.Clear(); if (SuburbTable.Rows.Count > 0) { ddSuburb.DataSource = SuburbTable; ddSuburb.DataValueField = "display"; ddSuburb.DataTextField = "display"; ddSuburb.DataBind(); } ddSuburb.Items.Insert(0, new ListItem("Select", "0")); ddSuburb.SelectedIndex = 0; //find addressLine.Substring(3) if (addressLine != String.Empty) { if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) ddSuburb.SelectedValue = addressLine.Substring(3); } } } else { TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName + itemNo); if (txtAddress != null && addressLine != String.Empty && addressLine.Substring(1, 1) == itemNo.ToString()) { /* CVH 2016-01-20 */ txtAddress.Enabled = enabled; txtAddress.Text = addressLine.Substring(3); //JR 2017-02-12 Set default Province for SBF if (itemNo == 4 && handler.ReturnSetup().code == "STUD-1") { txtAddress.Text = "Western Cape"; txtAddress.Enabled = false; } //CVH 2016-12-12 Group default collapse if (txtAddress.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } } } } } } #endregion #region CheckboxLists var cblData = from checkblsts in fieldTableEnum where checkblsts.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.CheckboxList) select checkblsts; foreach (DataRow chklstRow in cblData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(chklstRow["isControlled"].ToString(), out _isControlled); bool.TryParse(chklstRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(chklstRow["required"].ToString(), out _required); bool.TryParse(chklstRow["isCloneable"].ToString(), out _isCloneable); bool _alternateView = false; bool.TryParse(chklstRow["alternateView"].ToString(), out _alternateView); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(chklstRow["recId"].ToString()); int _parentId = int.Parse(chklstRow["parentId"].ToString()); int _surfaceId = int.Parse(chklstRow["surfaceId"].ToString()); string _surfaceFieldName = chklstRow["surfaceFieldName"].ToString(); if (_alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(_surfaceFieldName); if (checkboxList != null) { checkboxList.SelectedIndex = -1; //CVH 2017-05-12 Only clone when cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var chklstData = from chlstsDs in fieldDataTableEnum where chlstsDs.Field("surfaceFieldID").Equals(_recId) && !chlstsDs.Field("surfaceFieldValueChar").Equals("") select chlstsDs; if (chklstData.Count() > 0) { foreach (DataRow chlstDataRow in chklstData.ToList()) { string chlstFielDataChar = chlstDataRow["surfaceFieldValueChar"].ToString(); //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly foreach (string temp in chlstFielDataChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { string lookupId = ""; if (temp.IndexOf("~R~") >= 0) { lookupId = temp.Substring(0, temp.IndexOf("~R~")); } else { lookupId = temp; } if (checkboxList.Items.FindByValue(lookupId) != null) checkboxList.Items.FindByValue(lookupId).Selected = true; } } } } checkboxList.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (checkboxList.Items.GetSelectedItems().Count() > 0 && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } else { Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(_surfaceFieldName); if (checkboxPanel != null) { //CVH 2016-10-11 Clear checked items foreach (Control lblClear in checkboxPanel.Controls) { if (lblClear != null && lblClear.Controls.Count > 0) { Control ctrlClear = lblClear.Controls[0]; if (ctrlClear.GetType() == typeof(CheckBox)) { CheckBox chkClear = (CheckBox)ctrlClear; chkClear.Checked = false; TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); if (txtClear != null) { txtClear.Text = ""; txtClear.Enabled = false; } } } } //CVH 2017-05-12 Only clone when cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var chklstData = from chlstsDs in fieldDataTableEnum where chlstsDs.Field("surfaceFieldID").Equals(_recId) && !chlstsDs.Field("surfaceFieldValueChar").Equals("") select chlstsDs; if (chklstData.Count() > 0) { foreach (DataRow chlstDataRow in chklstData.ToList()) { string chlstFielDataChar = chlstDataRow["surfaceFieldValueChar"].ToString(); foreach (string temp in chlstFielDataChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { string lookupId = ""; string reason = ""; if (temp.IndexOf("~R~") >= 0) { lookupId = temp.Substring(0, temp.IndexOf("~R~")); reason = temp.Substring(temp.IndexOf("~R~") + 3); } else { lookupId = temp; } foreach (Control lblWrapper in checkboxPanel.Controls) { CheckBox chk = (CheckBox)lblWrapper.FindControl(_surfaceFieldName + "_" + lookupId); //CheckBox chk = (CheckBox)checkboxPanel.FindControl(field.surfaceFieldName + "_" + lookupId); if (chk != null) { chk.Checked = true; //try to find textbox for wants reason TextBox txtChkReason = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); if (txtChkReason != null) { txtChkReason.Text = reason; txtChkReason.Enabled = true; } //CVH 2016-12-12 Group default collapse if (!groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } } } } } //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state foreach (Control ctrlToggle in checkboxPanel.Controls) { if (ctrlToggle.GetType() == typeof(CheckBox)) { CheckBox chkToggle = (CheckBox)ctrlToggle; if (chkToggle.AutoPostBack) SetToggleViewActionVisibilityCheckboxList(chkToggle); } } checkboxPanel.Enabled = enabled; } } } #endregion #region Relational Fields var relData = from relFlds in fieldTableEnum where relFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RelationalField) select relFlds; foreach (DataRow relFldRow in relData.ToList()) { string _relationalFields = relFldRow["relationalFields"].ToString(); foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", _relationalFields)) { if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) { SetSurfaceControlState(_surfaceItem, fieldDataTableEnum, relFldRow, relatedField); } } } #endregion #region Controls var cntrlData = from ctrlFlds in fieldTableEnum where ctrlFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Control) select ctrlFlds; foreach (DataRow ctrlRow in cntrlData.ToList()) { SetSurfaceControlState(_surfaceItem, fieldDataTableEnum, ctrlRow); } #endregion #region Buttons var btnData = from btnFlds in fieldTableEnum where btnFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Button) select btnFlds; foreach (DataRow btnFldRow in relData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool.TryParse(btnFldRow["isControlled"].ToString(), out _isControlled); bool.TryParse(btnFldRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(btnFldRow["required"].ToString(), out _required); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(btnFldRow["recId"].ToString()); int _parentId = int.Parse(btnFldRow["parentId"].ToString()); string _surfaceFieldName = btnFldRow["surfaceFieldName"].ToString(); Button btn = (Button)pnlSurfaceForm.FindControl(_surfaceFieldName); if (btn != null) { if (_surfaceFieldName == "PatientProfile_PatientStatus") { foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) { if (visitLog.signOutDate.Year > 1900) { btn.Text = "Status: In Progress"; btn.AddCssClass("btn-success"); btn.RemoveCssClass("btn-warning"); btn.RemoveCssClass("btn-danger"); } else { btn.Text = "Status: Pending"; btn.AddCssClass("btn-warning"); btn.RemoveCssClass("btn-success"); btn.RemoveCssClass("btn-danger"); } break; } } } } #endregion #region Images var imgData = from imgFlds in fieldTableEnum where imgFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Image) select imgFlds; foreach (DataRow imgFldRow in imgData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(imgFldRow["isControlled"].ToString(), out _isControlled); bool.TryParse(imgFldRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(imgFldRow["required"].ToString(), out _required); bool.TryParse(imgFldRow["isCloneable"].ToString(), out _isCloneable); bool _alternateView = false; bool.TryParse(imgFldRow["alternateView"].ToString(), out _alternateView); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(imgFldRow["recId"].ToString()); int _parentId = int.Parse(imgFldRow["parentId"].ToString()); int _surfaceId = int.Parse(imgFldRow["surfaceId"].ToString()); string _surfaceFieldName = imgFldRow["surfaceFieldName"].ToString(); HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "Div"); if (imageDiv != null) { string imageUrl = "/images/placeholder.png"; //CVH 2017-05-12 Only clone when cloneable if (!base.IsClone || (base.IsClone && _isCloneable)) { var imgsData = from imgs in fieldDataTableEnum where imgs.Field("surfaceFieldID").Equals(_recId) && !imgs.Field("surfaceFieldValueChar").Equals("") select imgs; if (imgsData.Count() > 0) { foreach (DataRow imgDataRow in imgsData.ToList()) { imageUrl = "/upload/surface/" + imgDataRow["surfaceFieldValueChar"].ToString(); //CVH 2016-12-12 Group default collapse if (!groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } } imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } } #endregion #region Grid Fields //get grid field data var gridData = from grids in fieldTableEnum where grids.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Grid) select grids; foreach (DataRow gridRow in gridData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(gridRow["isControlled"].ToString(), out _isControlled); bool.TryParse(gridRow["isReadOnly"].ToString(), out _isReadOnly); int _surfaceId = int.Parse(gridRow["surfaceId"].ToString()); string _surfaceFieldName = gridRow["surfaceFieldName"].ToString(); string _relationalSurface = gridRow["relationalSurface"].ToString(); string _relationalValues = gridRow["relationalValues"].ToString(); bool _defaultToCurrent = false; bool.TryParse(gridRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(gridRow["isComparable"].ToString(), out _isComparable); /* CVH 2016-01-20 */ bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; #region Grid //find the div and bind all repeaters inside it HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + _surfaceFieldName); Panel panelGridHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + _surfaceId.ToString() + "_" + _surfaceFieldName); Panel panelCompareHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + _surfaceId.ToString() + "_" + _surfaceFieldName); Panel panelFormHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + _surfaceId.ToString() + "_" + _surfaceFieldName); if (divGridHolder != null) { DataTable childData = new DataTable(); int surfaceId = 0; oSurface childSurface = new oSurface(); bool isChildPublished = false; foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", _relationalSurface)) { surfaceId = surf.recId; childSurface = surf; isChildPublished = surf.isPublished; break; } if (surfaceId > 0) { int rowLimit = 0; int.TryParse(_relationalValues, out rowLimit); //CVH 2017-05-12 Populate Device Management child grid based on user email address if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && childSurface.name.EndsWith("DeviceManagement")) { List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "itemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetDeviceManagerChildData", listDevice); if (panelGridHolder != null) panelGridHolder.Enabled = false; } else if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "ScholarInformation" && childSurface.name.Contains("Mentorship")) { //CVH 2017-05-23 Mentorship child grids List listDevice = new List(); oDynamicParam param1 = new oDynamicParam(); param1.paramDisplayName = "ProfilesItemId"; param1.paramObject = base.SurfaceAppItemId; listDevice.Add(param1); oDynamicParam param2 = new oDynamicParam(); param2.paramDisplayName = "option"; param2.paramObject = (_surfaceFieldName.ToUpper().Contains("MENTEE") ? "2" : "1"); listDevice.Add(param2); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_GetMentorshipChildSurfaceData", listDevice); } //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data else if (_isControlled) { childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); } else { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, base.SurfaceAppItemId, usr.recId, rowLimit); else childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); if ((childData.Rows.Count == 0 && _defaultToCurrent) || (base.SurfaceAppItemId == 0 && _defaultToCurrent && childData.Rows.Count > 0)) { DataTable masterDataItems = new DataTable(); //get child surface fields ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); if (childData.Rows.Count == 0) { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, 0, usr.recId, 0); else childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); } } } if (panelGridHolder != null) { Repeater repeater = null; //foreach (Control rpt in divGridHolder.Controls) foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { repeater = (Repeater)rpt; SetAggregates(childData, surfaceId); repeater.DataSource = childData; repeater.DataBind(); utils.disposeSession("childButtons"); } } if (_isComparable && panelCompareHolder != null) { BindCompareDropdowns(childSurface, _surfaceFieldName); panelCompareHolder.Visible = true; panelGridHolder.Visible = false; } //CVH 2017-02-23 Only put in edit mode when field is not Read Only else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !_isReadOnly && !_isControlled) { //CVH 2016-12-20 Child grid default edit mode foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); RepeaterItem childRptItem = repeater.Items[0]; EditChild(editChildItemId, childRptItem); } break; } } } } } #endregion } #endregion BindSurfaceAttachments(_surfaceItem.recId, false); BindSurfaceNotes(_surfaceItem.recId, false); #region Group Fields //CVH 2016-12-12 Expand/Collapse groups depending on data loaded string expandGroups = ""; var groupData = from groups in fieldTableEnum where groups.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groups; foreach (DataRow groupRow in groupData.ToList()) { bool _isControlled = false; bool.TryParse(groupRow["isControlled"].ToString(), out _isControlled); int _recId = int.Parse(groupRow["recId"].ToString()); string _surfaceFieldName = groupRow["surfaceFieldName"].ToString(); if (_isControlled && groupIdsWithData.Contains("|" + _recId + "|")) { if (expandGroups == String.Empty) expandGroups = "tog" + _surfaceFieldName; else expandGroups += ",tog" + _surfaceFieldName; } } ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; #endregion //handle last if (base.SurfaceApp.isWizzard) { //GR added check now to see if wizard completed if (base.SurfaceAppItem != null) { wizardcompleted = base.SurfaceAppItem.isWizardCompleted; } if (!wizardcompleted && ((usr.userType == (int)pNums.UserType.WebsiteUser || usr.mimicUserType == (int)pNums.UserType.WebsiteUser) || setup.code == "GLOB-1")) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; if (tabData.Count() > 0) { ArrayList fieldTabs1 = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); pnlWizzardButtons.Visible = true; pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; SetLastTabUsed(fieldTabs1); } } else { var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; ArrayList fieldTabs2 = new ArrayList(); if (tabData.Count() > 0) { fieldTabs2 = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 MaintainActiveTab(fieldTabs2); SetTabsVisible(fieldTabs2); } //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one if ((setup.code == "SHOU-1" || setup.code == "GLOB-1") && ((usr.userType >= (int)pNums.UserType.PowerUser && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= (int)pNums.UserType.PowerUser && usr.userType == (int)pNums.UserType.CustomUser)) && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null && base.SurfaceAppItem.recId != 0) { int tabIndex = 0; foreach (oSurfaceField tab in fieldTabs2) { tabIndex++; //CVH 2017-05-05 User should have access to the tab, otherwise shouldn't increase counter.... //if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) if (tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) break; } if (tabIndex > 0) { //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; //GR 2017-03-18 set hidden tab index for inital page load if (!Page.IsPostBack) { hfTabIndex.Value = (tabIndex - 1).ToString(); } else hfTabIndex.Value = ""; } } if (setup.code == "SHOU-1" && ((usr.userType < (int)pNums.UserType.PowerUser && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType < (int)pNums.UserType.PowerUser && usr.userType == (int)pNums.UserType.CustomUser))) { pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = true; pnlWizzardButtons.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; btnSaveSingle.ValidationGroup = ""; btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; if (tabData.Count() > 0) { ArrayList fieldTabs = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); SetTabsVisibleNoWizard(fieldTabs, false); } } SetCustomVisible(); PerformCustomPopulateAddOn(); upSurface.Update(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #region Populate Surface Form BACKUPs ////CVH 2017-03-17 Reverting to pre-2017-03-13 ///// ///// Populate the surface form ///// //private void PopulateSurfaceFormBAK(oSurfaceItem _surfaceItem, bool isNew) //{ // bool wizardcompleted = false; // try // { // //first fetch the field and data records // DataTable surfaceFieldsTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); // DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId); // //if (isClone) // //{ // // _surfaceItem.recId = 0; // // base.SurfaceAppItem = null; // // base.SurfaceAppItemId = 0; // //} // ArrayList surfaceFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); // ArrayList surfaceFieldData = utils.ConvertDataTableToListParallel(surfaceFieldDataTable, typeof(oSurfaceFieldData)); // var fieldDataQ = surfaceFieldData.OfType().AsQueryable(); // //Parallel.ForEach(surfaceFields.Cast(), field => // //{ // //GR disable validation if in edit mode and isDisableRequired // //if (base.SurfaceApp.isDisableRequired && _surfaceItem.recId > 0) // //{ // // btnSave.ValidationGroup = "none"; // // btnSaveAndNew.ValidationGroup = "none"; // // btnSaveBack.ValidationGroup = "none"; // // btnSaveDraft.ValidationGroup = "none"; // // btnFinish.ValidationGroup = "none"; // // btnNext.ValidationGroup = "none"; // //} // oUser usr = new oUser(); // if (utils.verifySession("user")) // { usr = (oUser)Session["user"]; } // oSetup setup = handler.ReturnSetup(); // //CVH 2017-02-07 Determine Divide Action to be used in formula field // oSurfaceAction divideAction = new oSurfaceAction(); // oSurfaceAction lookupAction = new oSurfaceAction(); // oSurfaceAction aggrSumAction = new oSurfaceAction(); // foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) // { // if (act.actionType == (int)pNums.ActionType.Calculation) // { // if (act.action == "Divide") // divideAction = act; // else if (act.action == "Lookup") // lookupAction = act; // } // else if (act.actionType == (int)pNums.ActionType.Aggregation) // { // if (act.action == "Sum") // aggrSumAction = act; // } // } // //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default // string groupIdsWithData = ""; // foreach (oSurfaceField field in surfaceFields) // { // //CVH 2017-01-12 Process all non-grid fields, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Grid) // continue; // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) // { // Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + field.surfaceFieldName); // if (groupControl != null) // { // //CVH 2017-01-13 Ignore security on group if TSP and group is IOD groups hardcoded to show/hide depending on user selection // if ((setup.code == "SHOU-1") && // (field.surfaceFieldName == "PatientInformation_EmployerDetailsInjuryonDuty" || field.surfaceFieldName == "PatientInformation_MedicalAidIfapplicable")) // { // //do nothing // } // else if (setup.code == "GLOB-1" && // field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup && // !_surfaceItem.isWizardCompleted) // { // groupControl.Visible = false; // } // else // { // groupControl.Visible = usr.userType >= field.accessLevel; // } // } // } // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab || field.surfaceFieldTypeId != (int)pNums.FieldType.Group) // { // pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); // switch (typ) // { // #region Label // case pNums.FieldType.Label: // if (field.isReadOnly)//hide labels on new // { // Control divControl; // divControl = FindControl("srt" + field.surfaceFieldName); // if (divControl != null) // divControl.Visible = false; // } // else // { // bool isImage = false; // string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; // if (field.relationalSurface == "user") // { // foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = user.userDisplay; // } // } // else if (field.relationalSurface == "date") // { // if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; // } // } // else // { // string itemId = _surfaceItem.recId.ToString(); // //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface // if (field.relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) // itemId = base.ParentSurfaceItemId.ToString(); // foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString())) // { // sourceFieldLabel = sourceField.surfaceFieldDisplay; // foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString() + "," + itemId)) // { // pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); // switch (sourceType) // { // #region Text|Caption|Address|MultiPicklist // case pNums.FieldType.Text: // case pNums.FieldType.Caption: // case pNums.FieldType.Address: // case pNums.FieldType.MultiPicklist: // sourceFieldValue = sourceData.surfaceFieldValueChar; // break; // #endregion // #region Number // case pNums.FieldType.Number: // sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: // sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); // break; // #endregion // #region Date // case pNums.FieldType.Date: // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); // break; // #endregion // #region Picklist|RadioButtonList // case pNums.FieldType.Picklist: // case pNums.FieldType.RadioButtonList: // sourceFieldValue = ""; // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) // { // sourceFieldValue = look.display; // break; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: // sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: // sourceFieldValue = ""; // //CVH 2017-02-13 New action Lookup need to recalc on load // if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) // { // decimal lookupSrcValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField lookupSrcField in surfaceFields) // { // if (lookupSrcField.recId == sourceField.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(lookupSrcField.recId))) // { // if (lookupSrcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out lookupSrcValue); // else if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // lookupSrcValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out lookupSrcValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // sourceFieldValue = CalculateLookup(field, lookupSrcValue); // } // } // //CVH 2017-02-07 New action Divide is saved in Char // else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) // { // sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // sourceFieldValue = age.years.ToString(); // } // } // break; // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // sourceFieldValue = sourceData.surfaceFieldValueChar; // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: // sourceFieldValue = ""; // //split string to get lookup IDs // foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // //get lookup // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) // { // if (sourceFieldValue == String.Empty) // sourceFieldValue = look.display; // else // sourceFieldValue += ", " + look.display; // break; // } // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageLabelDiv != null) // { // string imageUrl = "/images/placeholder.png"; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // if (imageLabelDiv != null) // { // string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // isImage = true; // break; // #endregion // #region Attachment // case pNums.FieldType.Attachment: // HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfAttachments"); // int intItemIdAt = 0; // int.TryParse(itemId, out intItemIdAt); // if (attachDiv != null && intItemIdAt > 0) // BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); // break; // #endregion // #region Note // case pNums.FieldType.Note: // HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfNotes"); // int intItemIdN = 0; // int.TryParse(itemId, out intItemIdN); // if (notesDiv != null && intItemIdN > 0) // BindNotes(intItemIdN, notesDiv); // break; // #endregion // } // } // } // } // Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Value"); // if (lblValue != null) // { // lblValue.Text = sourceFieldValue; // } // } // } // //CVH 2016-12-12 Don't expand collapsed group just for label // groupIdsWithData += ""; // break; // #endregion // #region Text // case pNums.FieldType.Text://Textbox // TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtTextbox != null) // { // txtTextbox.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtTextbox.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtTextbox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Number // case pNums.FieldType.Number: //number // TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtNumberBox != null) // { // if (field.isControlled) // { // int nextNumber = 0; // int.TryParse(field.controlledValue, out nextNumber); // nextNumber++; // txtNumberBox.Enabled = false; // txtNumberBox.Text = nextNumber.ToString(); // } // else // txtNumberBox.Text = ""; // if (!base.IsClone || (base.IsClone && !field.isControlled)) // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtNumberBox.Text = Math.Floor(decFormula).ToString(); // enabled = false; // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtNumberBox.Text = data.surfaceFieldValueNum.ToString(); // break; // } // } // } // } // txtNumberBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: //decimal // TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDecimalBox != null) // { // txtDecimalBox.Text = ""; // if (setup.code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) // { // //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) // List listPortion = new List(); // oDynamicParam por1 = new oDynamicParam(); // por1.paramDisplayName = "surfaceId"; // por1.paramObject = _surfaceItem.surfaceId; // listPortion.Add(por1); // oDynamicParam por2 = new oDynamicParam(); // por2.paramDisplayName = "surfaceItemId"; // por2.paramObject = base.SurfaceAppItemId; // listPortion.Add(por2); // DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); // if (dtPortion != null && dtPortion.Rows.Count > 0) // txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); // enabled = false; // } // else // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); // enabled = false; // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // break; // } // } // } // } // txtDecimalBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Picklist // case pNums.FieldType.Picklist: //picklist // DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // //CVH 2017-03-01 First off clear reason // if (txtPicklistReason != null) // txtPicklistReason.Text = ""; // if (ddDropdownlist != null) // { // ddDropdownlist.SelectedIndex = -1; // //CVH 2016-10-21 Also check !="0" otherwise it adds extra "Select" item for normal dropdowns (relationalObject saves as "0") // //if (field.relationalObject.Length > 0) // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // ddDropdownlist.DataSource = dtModuleData; // ddDropdownlist.DataValueField = row["valueField"].ToString(); // ddDropdownlist.DataTextField = row["displayField"].ToString(); // } // ddDropdownlist.DataBind(); // if (ddDropdownlist.Items.Count == 0) // { // enabled = false; // ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); // } // else // ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldValueChar.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldValueChar.ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldLookupID.ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtPicklistReason.Visible = true; // if (lookupItem.wantsReason) // { // txtPicklistReason.Enabled = true; // if (rfvPicklistReason != null) // rfvPicklistReason.ControlToValidate = txtPicklistReason.ID; // } // else // { // txtPicklistReason.Enabled = false; // txtPicklistReason.Text = ""; // } // } // else // txtPicklistReason.Visible = false; // } // } // } // break; // } // } // } // else if (txtPicklistReason != null) // { // //always disable reason if no selection // txtPicklistReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtPicklistReason.Visible = true; // else // txtPicklistReason.Visible = false; // } // ddDropdownlist.Enabled = enabled; // //if dropdownlist is not enabled, reason shouldn't be enabled either // if (txtPicklistReason != null && !ddDropdownlist.Enabled) txtPicklistReason.Enabled = false; // if (field.surfaceFieldName == "PatientType_PatientType_PatientType") // { // SetPatientType("PatientType_PatientType_PatientType"); // } // //CVH 2016-12-12 Group default collapse // if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedIndex != -1 && ddDropdownlist.SelectedValue != "0" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2017-01-18 Toggle View Action: If checkedchanged event is linked to picklist, call method to set controls Visible=false/true depending on selected value // if (ddDropdownlist.AutoPostBack) // SetToggleViewActionVisibilityPicklist(ddDropdownlist); // } // break; // #endregion // #region MultiPicklist // case pNums.FieldType.MultiPicklist: //MultiPicklist // ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (listBox != null) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // listBox.DataSource = dtModuleData; // listBox.DataValueField = row["valueField"].ToString(); // listBox.DataTextField = row["displayField"].ToString(); // } // listBox.DataBind(); // } // listBox.ClearSelection(); // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // string valueIds = data.surfaceFieldValueChar.ToString(); // foreach (string valueId in valueIds.Split(',')) // { // foreach (ListItem item in listBox.Items) // { // if (item.Value == valueId) // { // item.Selected = true; // break; // } // } // } // } // } // } // listBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (listBox.GetSelectedIndices().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Date // case pNums.FieldType.Date: //date // TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDate != null) // { // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // if (field.defaultToCurrent) // txtDate.Text = DateTime.Now.ToString(format); // else if (field.defaultValue != "") // txtDate.Text = field.defaultValue; // else // txtDate.Text = ""; // if (!base.IsClone || (base.IsClone && !field.defaultToCurrent)) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDate.Text = data.surfaceFieldValueDate.ToString(format); // //CVH 2016-12-12 Group default collapse - don't apply if set to current date or minimum date // if (txtDate.Text != "" && txtDate.Text != DateTime.Now.ToString(format) && txtDate.Text != _surfaceItem.dateCreated.ToString(format) && data.surfaceFieldValueDate != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2016-12-21 Show empty textbox if date is min date // if (data.surfaceFieldValueDate == DateTime.Parse("1900/01/01")) // txtDate.Text = ""; // break; // } // } // } // /* CVH 2016-01-20 */ // txtDate.Enabled = enabled; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: //checkbox // CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (chkBox != null) // { // chkBox.Checked = false; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // chkBox.Checked = data.surfaceFieldValueBool; // break; // } // } // /* CVH 2016-01-20 */ // chkBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (chkBox.Checked && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Grid // case pNums.FieldType.Grid: //grid // //CVH 2017-01-12 Process all non-grid fields, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // // so not handled here, see next for loop // break; // #endregion // #region RadioButtonList // case pNums.FieldType.RadioButtonList: //radiobuttonlist // RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // if (radioButtonList != null) // { // radioButtonList.SelectedIndex = -1; // //CVH 2016-11-30 Set default reason visible / not visible, otherwise not handled correctly when editing, but no data saved // if (txtReason != null) // { // //always disable reason if no data selected // txtReason.Text = ""; // txtReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtReason.Visible = true; // else // txtReason.Visible = false; // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldLookupID.ToString() != "0") // { // if (radioButtonList.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // radioButtonList.SelectedValue = data.surfaceFieldLookupID.ToString(); // //IOD stuff // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = (radioButtonList.SelectedItem.Text == "Yes"); // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = !(radioButtonList.SelectedItem.Text == "Yes"); // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // if (txtReason != null) // { // txtReason.Text = ""; // txtReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtReason.Visible = true; // if (lookupItem.wantsReason) // { // txtReason.Enabled = true; // if (rfvRadioButtonListReason != null) // { // if (field.required) // { // rfvRadioButtonListReason.ControlToValidate = txtReason.ID; // rfvRadioButtonListReason.Enabled = true; // } // else // rfvRadioButtonListReason.Enabled = false; // } // } // else // txtReason.Enabled = false; // } // else // txtReason.Visible = false; // } // } // } // } // } // else // { // //CVH 2017-01-10 TSP If there is no data, and the field is IOD, show the medical aid group and hide the employer group // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = false; // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = true; // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // if (radioButtonList.AutoPostBack) // SetToggleViewActionVisibilityRadioButtonList(radioButtonList); // radioButtonList.Enabled = enabled; // if (txtReason != null && !radioButtonList.Enabled) txtReason.Enabled = false; // //CVH 2016-12-12 Group default collapse // if (radioButtonList.SelectedItem != null && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Placeholder // case pNums.FieldType.Placeholder: // //no action // break; // #endregion // #region Caption // case pNums.FieldType.Caption: // TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtCaption != null) // { // txtCaption.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtCaption.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtCaption.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtCaption.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: //decimal // TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtFormulaBox != null) // { // txtFormulaBox.Text = ""; // //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) // { // decimal sourceValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField srcField in surfaceFields) // { // if (srcField.recId == field.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (srcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out sourceValue); // else if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // sourceValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out sourceValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // txtFormulaBox.Text = CalculateLookup(field, sourceValue); // enabled = false; // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); // enabled = false; // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // //CVH 2017-02-07 Divide Calculation Formula is saved in Char column // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) // { // txtFormulaBox.Text = data.surfaceFieldValueChar; // enabled = false; // } // else if (field.actionType == (int)pNums.ActionType.Calculation && field.action != divideAction.recId) // { // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", field.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", field.surfaceId + "," + data.surfaceItemId + "," + field.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // txtFormulaBox.Text = age.years.ToString(); // enabled = false; // } // } // break; // } // } // else // { // if (data.surfaceFieldValueDecimal != 0) // txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // if (data.surfaceFieldValueChar != string.Empty) // txtFormulaBox.Text = data.surfaceFieldValueChar; // } // break; // } // } // } // if (field.actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") // { // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // List sicParams = new List(); // oDynamicParam sicParam = new oDynamicParam(); // sicParam.paramDisplayName = "userId"; // sicParam.paramObject = userId; // sicParams.Add(sicParam); // DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); // if (nextCodeTable.Rows.Count > 0) // { // txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); // if (txtFormulaBox.Text == "-1") // txtFormulaBox.Text = ""; // } // else // { // txtFormulaBox.Text = ""; // } // } // txtFormulaBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Address // case pNums.FieldType.Address: // /* CVH 2016-07-29 Clear address textboxes, in case no data */ // bool found = false; // int itemNoClr = 0; // do // { // found = false; // itemNoClr++; // if (itemNoClr == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr + "dd"); // if (ddSuburb != null) // { // found = true; // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr); // if (txtAddress != null) // { // txtAddress.Text = ""; // found = true; // //JR 2017-02-12 Set default Province for SBF // if (itemNoClr == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // } // } // } while (found && itemNoClr < 50); // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // int itemNo = 0; // foreach (string addressLine in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // itemNo++; // if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo + "dd"); // if (ddSuburb != null) // { // //CVH 2017-02-27 Clear selection, otherwise get exception when index 0 is selected when binding // ddSuburb.Items.Clear(); // if (SuburbTable.Rows.Count > 0) // { // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // } // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // //find addressLine.Substring(3) // if (addressLine != String.Empty) // { // if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) // ddSuburb.SelectedValue = addressLine.Substring(3); // } // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo); // if (txtAddress != null && addressLine != String.Empty && addressLine.Substring(1, 1) == itemNo.ToString()) // { // /* CVH 2016-01-20 */ // txtAddress.Enabled = enabled; // txtAddress.Text = addressLine.Substring(3); // //JR 2017-02-12 Set default Province for SBF // if (itemNo == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // //CVH 2016-12-12 Group default collapse // if (txtAddress.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: //checkboxlist // /* CVH 2016-09-27 Cater for Wants Reason. alternateView does not use wantsReason */ // if (field.alternateView) // { // CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxList != null) // { // checkboxList.SelectedIndex = -1; // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // if (checkboxList.Items.FindByValue(lookupId) != null) // checkboxList.Items.FindByValue(lookupId).Selected = true; // } // } // } // } // checkboxList.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (checkboxList.Items.GetSelectedItems().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // else // { // Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxPanel != null) // { // //CVH 2016-10-11 Clear checked items // foreach (Control lblClear in checkboxPanel.Controls) // { // if (lblClear != null && lblClear.Controls.Count > 0) // { // Control ctrlClear = lblClear.Controls[0]; // if (ctrlClear.GetType() == typeof(CheckBox)) // { // CheckBox chkClear = (CheckBox)ctrlClear; // chkClear.Checked = false; // TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); // if (txtClear != null) // { // txtClear.Text = ""; // txtClear.Enabled = false; // } // } // } // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // string reason = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // reason = temp.Substring(temp.IndexOf("~R~") + 3); // } // else // { // lookupId = temp; // } // foreach (Control lblWrapper in checkboxPanel.Controls) // { // CheckBox chk = (CheckBox)lblWrapper.FindControl(field.surfaceFieldName + "_" + lookupId); // //CheckBox chk = (CheckBox)checkboxPanel.FindControl(field.surfaceFieldName + "_" + lookupId); // if (chk != null) // { // chk.Checked = true; // //try to find textbox for wants reason // TextBox txtChkReason = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); // if (txtChkReason != null) // { // txtChkReason.Text = reason; // txtChkReason.Enabled = true; // } // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // foreach (Control ctrlToggle in checkboxPanel.Controls) // { // if (ctrlToggle.GetType() == typeof(CheckBox)) // { // CheckBox chkToggle = (CheckBox)ctrlToggle; // if (chkToggle.AutoPostBack) // SetToggleViewActionVisibilityCheckboxList(chkToggle); // } // } // checkboxPanel.Enabled = enabled; // } // } // break; // #endregion // #region RelationalField // case pNums.FieldType.RelationalField: // foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", field.relationalFields.ToString())) // { // if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) // { // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field); // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // break; // #endregion // #region Button // case pNums.FieldType.Button: // Button btn = (Button)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (btn != null) // { // if (field.surfaceFieldName == "PatientProfile_PatientStatus") // { // foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) // { // if (visitLog.signOutDate.Year > 1900) // { // btn.Text = "Status: In Progress"; // btn.AddCssClass("btn-success"); // btn.RemoveCssClass("btn-warning"); // btn.RemoveCssClass("btn-danger"); // } // else // { // btn.Text = "Status: Pending"; // btn.AddCssClass("btn-warning"); // btn.RemoveCssClass("btn-success"); // btn.RemoveCssClass("btn-danger"); // } // break; // } // } // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageDiv != null) // { // string imageUrl = "/images/placeholder.png"; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (data.surfaceFieldValueChar != "") // { // imageUrl = "/upload/surface/" + data.surfaceFieldValueChar; // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // } // } // imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // break; // #endregion // } // } // } // //GR added call to get grid fields to avoid unecessary loops // ArrayList gridFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", _surfaceItem.surfaceId + "," + (int)pNums.FieldType.Grid); // //CVH 2017-01-12 Process all non-grid fields first, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // foreach (oSurfaceField field in gridFields) // { // //only process grid fields // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Grid) // continue; // /* CVH 2017-04-12 Read-only not working */ // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // #region Grid // //find the div and bind all repeaters inside it // HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + field.surfaceFieldName); // Panel panelGridHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelCompareHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelFormHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // if (divGridHolder != null) // { // DataTable childData = new DataTable(); // int surfaceId = 0; // oSurface childSurface = new oSurface(); // foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // surfaceId = surf.recId; // childSurface = surf; // break; // } // if (surfaceId > 0) // { // int rowLimit = 0; // int.TryParse(field.relationalValues, out rowLimit); // //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data // if (field.isControlled) // { // List list = new List(); // oDynamicParam par1 = new oDynamicParam(); // par1.paramDisplayName = "SurfaceID"; // par1.paramObject = surfaceId; // list.Add(par1); // oDynamicParam par2 = new oDynamicParam(); // par2.paramDisplayName = "ParentSurfaceItemId"; // par2.paramObject = base.SurfaceAppItemId; // list.Add(par2); // oDynamicParam par3 = new oDynamicParam(); // par3.paramDisplayName = "RowLimit"; // par3.paramObject = rowLimit; // list.Add(par3); // childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceDataSummarized", list); // } // else // { // List list = new List(); // oDynamicParam par1 = new oDynamicParam(); // par1.paramDisplayName = "SurfaceID"; // par1.paramObject = surfaceId; // list.Add(par1); // oDynamicParam par2 = new oDynamicParam(); // par2.paramDisplayName = "ParentSurfaceItemId"; // par2.paramObject = base.SurfaceAppItemId; // list.Add(par2); // oDynamicParam par3 = new oDynamicParam(); // par3.paramDisplayName = "RowLimit"; // par3.paramObject = rowLimit; // list.Add(par3); // childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); // if ((childData.Rows.Count == 0 && field.defaultToCurrent) || (base.SurfaceAppItemId == 0 && field.defaultToCurrent && childData.Rows.Count > 0)) // { // DataTable masterDataItems = new DataTable(); // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); // if (childData.Rows.Count == 0) // { // list = new List(); // par1 = new oDynamicParam(); // par1.paramDisplayName = "SurfaceID"; // par1.paramObject = surfaceId; // list.Add(par1); // par2 = new oDynamicParam(); // par2.paramDisplayName = "ParentSurfaceItemId"; // par2.paramObject = 0; // list.Add(par2); // childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); // //masterDataItems = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); // } // //else // //{ // // masterDataItems = childData.Copy(); // //} // ////if (_surfaceItem.recId == 0) // //if (base.SurfaceAppItemId == 0 || base.IsClone) // //{ // // if (!PerformSave(false, true)) // // return; // //} // //foreach (DataRow row in masterDataItems.Rows) // //{ // // string masterItem = row["itemID"].ToString(); // // oSurfaceItem copyItem = new oSurfaceItem(); // // copyItem.createdBy = userId; // // copyItem.dateCreated = DateTime.Now; // // copyItem.isActive = true; // // copyItem.isDeleted = false; // // copyItem.isWizardCompleted = false; // // copyItem.lastTabCompleted = 0; // // copyItem.surfaceId = surfaceId; // // copyItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), copyItem); // // //ArrayList copyItems = new ArrayList(); // // foreach (oSurfaceFieldData copyData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceItemId", masterItem)) // // { // // //change surfaceItem and parentSurfaceItemId field // // copyData.recId = 0; // // copyData.surfaceItemId = copyItem.recId; // // foreach (oSurfaceField childField in childFields) // // { // // if (childField.recId == copyData.surfaceFieldID) // // { // // if (childField.surfaceFieldName == "ParentSurfaceItemId") // // { // // copyData.surfaceFieldValueNum = base.SurfaceAppItemId; // // } // // break; // // } // // } // // copyData.recId = xData.SaveTyped("recId", typeof(oSurfaceFieldData), copyData); // // } // //} // ////get newly created data // //list = new List(); // //par1 = new oDynamicParam(); // //par1.paramDisplayName = "SurfaceID"; // //par1.paramObject = surfaceId; // //list.Add(par1); // //par2 = new oDynamicParam(); // //par2.paramDisplayName = "ParentSurfaceItemId"; // //par2.paramObject = base.SurfaceAppItemId; // //list.Add(par2); // //childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); // } // } // if (panelGridHolder != null) // { // Repeater repeater = null; // //foreach (Control rpt in divGridHolder.Controls) // foreach (Control rpt in panelGridHolder.Controls) // { // if (rpt.GetType() == typeof(Repeater)) // { // repeater = (Repeater)rpt; // SetAggregates(childData, surfaceId); // repeater.DataSource = childData; // repeater.DataBind(); // } // } // if (field.isComparable && panelCompareHolder != null) // { // BindCompareDropdowns(childSurface, field.surfaceFieldName); // panelCompareHolder.Visible = true; // panelGridHolder.Visible = false; // } // //CVH 2017-02-23 Only put in edit mode when field is not Read Only // else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !field.isReadOnly && !field.isControlled) // { // //CVH 2016-12-20 Child grid default edit mode // foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) // { // //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) // if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) // { // int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); // RepeaterItem childRptItem = repeater.Items[0]; // EditChild(editChildItemId, childRptItem); // } // break; // } // } // } // if (field.relationalValues == "1" && panelFormHolder != null) // { // panelFormHolder.Visible = true; // if (childData.Rows.Count > 0) // { // int childSurfaceItemId = childData.Rows[0].Field("itemID"); // oSurfaceItem childItem = new oSurfaceItem(); // foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childSurfaceItemId.ToString())) // { // childItem = item; // } // //PopulateSurfaceView(childItem, true); // } // } // } // //CVH 2016-12-12 Group default collapse // //CVH 2017-02-17 Keep group collapsed, even if there are records in grid. This is required for TSP, and no other client requires it differently. // // If this changes, create a collapsed group option in surface admin: Collapsed, Collapsed if Empty, Open // //if (childData != null && childData.Rows.Count > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // // groupIdsWithData += "|" + field.parentId + "|"; // } // #endregion // } // BindSurfaceAttachments(_surfaceItem.recId, false); // BindSurfaceNotes(_surfaceItem.recId, false); // //GR added call to get grid fields to avoid unecessary loops // ArrayList groupFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", _surfaceItem.surfaceId + "," + (int)pNums.FieldType.Group); // //CVH 2016-12-12 Expand/Collapse groups depending on data loaded // string expandGroups = ""; // foreach (oSurfaceField groupField in groupFields) // { // if (groupField.surfaceFieldTypeId == (int)pNums.FieldType.Group) // { // if (groupField.isControlled && groupIdsWithData.Contains("|" + groupField.recId + "|")) // { // if (expandGroups == String.Empty) // expandGroups = "tog" + groupField.surfaceFieldName; // else // expandGroups += ",tog" + groupField.surfaceFieldName; // } // } // } // ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; // //CVH 2017-01-10 Only register script when not page load, otherwise javascript error method not defined that breaks other javascript // if (Page.IsPostBack) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroupsPopulate", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); // //if (base.SurfaceApp.linkUser && user.userType == (int)pNums.UserType.AdminUser) // //{ // // BindUsersToLink(); // // ddUserLink.SelectedIndex = 0; // // if (base.SurfaceAppItem != null && ddUserLink.Items.FindByValue(base.SurfaceAppItem.userLink.ToString()) != null) // // ddUserLink.SelectedValue = base.SurfaceAppItem.userLink.ToString(); // // pnlUserLink.Visible = true; // //} // //handle last // if (base.SurfaceApp.isWizzard) // { // //GR added check now to see if wizard completed // if (base.SurfaceAppItem != null) // { // wizardcompleted = base.SurfaceAppItem.isWizardCompleted; // } // if (!wizardcompleted && (usr.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) // //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) // ArrayList fieldTabs1 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // pnlWizzardButtons.Visible = true; // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // SetLastTabUsed(fieldTabs1); // } // else // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // ArrayList fieldTabs2 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // MaintainActiveTab(fieldTabs2); // SetTabsVisible(fieldTabs2); // //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one // if ((setup.code == "SHOU-1" || setup.code == "GLOB-1") && usr.userType >= (int)pNums.UserType.PowerUser && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null) // { // int tabIndex = 0; // foreach (oSurfaceField tab in fieldTabs2) // { // tabIndex++; // if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) // break; // } // if (tabIndex > 0) // { // //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; // //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; // HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; // //GR 2017-03-18 set hidden tab index for inital page load // if (!Page.IsPostBack) // { // hfTabIndex.Value = (tabIndex - 1).ToString(); // } // else // hfTabIndex.Value = ""; // //if (Page.IsPostBack) // //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showFirstNonWizard", script, true); // } // } // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) // { // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = true; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // btnSaveSingle.ValidationGroup = ""; // btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // btnSave.ValidationGroup = ""; // btnSaveAndNew.ValidationGroup = ""; // btnSaveBack.ValidationGroup = ""; // btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // } // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) // ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // SetTabsVisibleNoWizard(fieldTabs, false); // } // SetCustomVisible(); // PerformCustomPopulateAddOn(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} ///// ///// Populate the surface form ///// GR 2017-04-13 Revised to use the query data ///// //private void PopulateSurfaceFormBAK1(oSurfaceItem _surfaceItem, bool isNew) //{ // bool wizardcompleted = false; // try // { // //first fetch the field and data records // DataTable surfaceFieldsTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); // DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId); // ArrayList surfaceFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); // ArrayList surfaceFieldData = utils.ConvertDataTableToListParallel(surfaceFieldDataTable, typeof(oSurfaceFieldData)); // var fieldDataQ = surfaceFieldData.OfType().AsQueryable(); // oUser usr = new oUser(); // if (utils.verifySession("user")) // { usr = (oUser)Session["user"]; } // oSetup setup = handler.ReturnSetup(); // //CVH 2017-02-07 Determine Divide Action to be used in formula field // oSurfaceAction divideAction = new oSurfaceAction(); // oSurfaceAction lookupAction = new oSurfaceAction(); // oSurfaceAction aggrSumAction = new oSurfaceAction(); // foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) // { // if (act.actionType == (int)pNums.ActionType.Calculation) // { // if (act.action == "Divide") // divideAction = act; // else if (act.action == "Lookup") // lookupAction = act; // } // else if (act.actionType == (int)pNums.ActionType.Aggregation) // { // if (act.action == "Sum") // aggrSumAction = act; // } // } // //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default // string groupIdsWithData = ""; // foreach (oSurfaceField field in surfaceFields) // { // //CVH 2017-01-12 Process all non-grid fields, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Grid) // continue; // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) // { // Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + field.surfaceFieldName); // if (groupControl != null) // { // //CVH 2017-01-13 Ignore security on group if TSP and group is IOD groups hardcoded to show/hide depending on user selection // if ((setup.code == "SHOU-1") && // (field.surfaceFieldName == "PatientInformation_EmployerDetailsInjuryonDuty" || field.surfaceFieldName == "PatientInformation_MedicalAidIfapplicable")) // { // //do nothing // } // else if (setup.code == "GLOB-1" && // field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup && // !_surfaceItem.isWizardCompleted) // { // groupControl.Visible = false; // } // else // { // groupControl.Visible = usr.userType >= field.accessLevel; // } // } // } // /* CVH 2016-01-20 */ // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab || field.surfaceFieldTypeId != (int)pNums.FieldType.Group) // { // pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); // switch (typ) // { // #region Label // case pNums.FieldType.Label: // if (field.isReadOnly)//hide labels on new // { // Control divControl; // divControl = FindControl("srt" + field.surfaceFieldName); // if (divControl != null) // divControl.Visible = false; // } // else // { // bool isImage = false; // string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; // if (field.relationalSurface == "user") // { // foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = user.userDisplay; // } // } // else if (field.relationalSurface == "date") // { // if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; // } // } // else // { // string itemId = _surfaceItem.recId.ToString(); // //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface // if (field.relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) // itemId = base.ParentSurfaceItemId.ToString(); // foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString())) // { // sourceFieldLabel = sourceField.surfaceFieldDisplay; // foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString() + "," + itemId)) // { // pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); // switch (sourceType) // { // case pNums.FieldType.Text: // case pNums.FieldType.Caption: // case pNums.FieldType.Address: // case pNums.FieldType.MultiPicklist: // sourceFieldValue = sourceData.surfaceFieldValueChar; // break; // case pNums.FieldType.Number: // sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); // break; // case pNums.FieldType.Decimal: // sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); // break; // case pNums.FieldType.Date: // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); // break; // case pNums.FieldType.Picklist: // case pNums.FieldType.RadioButtonList: // sourceFieldValue = ""; // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) // { // sourceFieldValue = look.display; // break; // } // break; // case pNums.FieldType.Checkbox: // sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; // break; // case pNums.FieldType.FormulaField: // sourceFieldValue = ""; // //CVH 2017-02-13 New action Lookup need to recalc on load // if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) // { // decimal lookupSrcValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField lookupSrcField in surfaceFields) // { // if (lookupSrcField.recId == sourceField.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(lookupSrcField.recId))) // { // if (lookupSrcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out lookupSrcValue); // else if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // lookupSrcValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out lookupSrcValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // sourceFieldValue = CalculateLookup(field, lookupSrcValue); // } // } // //CVH 2017-02-07 New action Divide is saved in Char // else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) // { // sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // sourceFieldValue = age.years.ToString(); // } // } // break; // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // sourceFieldValue = sourceData.surfaceFieldValueChar; // } // break; // case pNums.FieldType.CheckboxList: // sourceFieldValue = ""; // //split string to get lookup IDs // foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // //get lookup // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) // { // if (sourceFieldValue == String.Empty) // sourceFieldValue = look.display; // else // sourceFieldValue += ", " + look.display; // break; // } // } // break; // case pNums.FieldType.Image: // HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageLabelDiv != null) // { // string imageUrl = "/images/placeholder.png"; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // if (imageLabelDiv != null) // { // string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // isImage = true; // break; // case pNums.FieldType.Attachment: // HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfAttachments"); // int intItemIdAt = 0; // int.TryParse(itemId, out intItemIdAt); // if (attachDiv != null && intItemIdAt > 0) // BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); // break; // case pNums.FieldType.Note: // HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfNotes"); // int intItemIdN = 0; // int.TryParse(itemId, out intItemIdN); // if (notesDiv != null && intItemIdN > 0) // BindNotes(intItemIdN, notesDiv); // break; // } // } // } // } // Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Value"); // if (lblValue != null) // { // lblValue.Text = sourceFieldValue; // } // } // } // //CVH 2016-12-12 Don't expand collapsed group just for label // groupIdsWithData += ""; // break; // #endregion // #region Text // case pNums.FieldType.Text://Textbox // TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtTextbox != null) // { // txtTextbox.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtTextbox.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtTextbox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Number // case pNums.FieldType.Number: //number // TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtNumberBox != null) // { // if (field.isControlled) // { // int nextNumber = 0; // int.TryParse(field.controlledValue, out nextNumber); // nextNumber++; // txtNumberBox.Enabled = false; // txtNumberBox.Text = nextNumber.ToString(); // } // else // txtNumberBox.Text = ""; // if (!base.IsClone || (base.IsClone && !field.isControlled)) // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtNumberBox.Text = Math.Floor(decFormula).ToString(); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtNumberBox.Text = data.surfaceFieldValueNum.ToString(); // break; // } // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtNumberBox.Enabled = false; // else // txtNumberBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: //decimal // TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDecimalBox != null) // { // txtDecimalBox.Text = ""; // if (setup.code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) // { // //leave decimal textbox blank if item ID = 0 // if (base.SurfaceAppItemId != 0) // { // //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) // List listPortion = new List(); // oDynamicParam por1 = new oDynamicParam(); // por1.paramDisplayName = "surfaceId"; // por1.paramObject = _surfaceItem.surfaceId; // listPortion.Add(por1); // oDynamicParam por2 = new oDynamicParam(); // por2.paramDisplayName = "surfaceItemId"; // por2.paramObject = base.SurfaceAppItemId; // listPortion.Add(por2); // DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); // if (dtPortion != null && dtPortion.Rows.Count > 0) // txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); // } // } // else // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // break; // } // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtDecimalBox.Enabled = false; // else // txtDecimalBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Picklist // case pNums.FieldType.Picklist: //picklist // DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // //CVH 2017-03-01 First off clear reason // if (txtPicklistReason != null) // txtPicklistReason.Text = ""; // if (ddDropdownlist != null) // { // ddDropdownlist.SelectedIndex = -1; // //CVH 2016-10-21 Also check !="0" otherwise it adds extra "Select" item for normal dropdowns (relationalObject saves as "0") // //if (field.relationalObject.Length > 0) // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // ddDropdownlist.DataSource = dtModuleData; // ddDropdownlist.DataValueField = row["valueField"].ToString(); // ddDropdownlist.DataTextField = row["displayField"].ToString(); // } // ddDropdownlist.DataBind(); // if (ddDropdownlist.Items.Count == 0) // { // enabled = false; // ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); // } // else // ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldValueChar.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldValueChar.ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldLookupID.ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtPicklistReason.Visible = true; // if (lookupItem.wantsReason) // { // txtPicklistReason.Enabled = true; // if (rfvPicklistReason != null) // rfvPicklistReason.ControlToValidate = txtPicklistReason.ID; // } // else // { // txtPicklistReason.Enabled = false; // txtPicklistReason.Text = ""; // } // } // else // txtPicklistReason.Visible = false; // } // } // } // break; // } // } // } // else if (txtPicklistReason != null) // { // //always disable reason if no selection // txtPicklistReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtPicklistReason.Visible = true; // else // txtPicklistReason.Visible = false; // } // ddDropdownlist.Enabled = enabled; // //if dropdownlist is not enabled, reason shouldn't be enabled either // if (txtPicklistReason != null && !ddDropdownlist.Enabled) txtPicklistReason.Enabled = false; // if (field.surfaceFieldName == "PatientType_PatientType_PatientType") // { // SetPatientType("PatientType_PatientType_PatientType"); // } // //CVH 2016-12-12 Group default collapse // if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedIndex != -1 && ddDropdownlist.SelectedValue != "0" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2017-01-18 Toggle View Action: If checkedchanged event is linked to picklist, call method to set controls Visible=false/true depending on selected value // if (ddDropdownlist.AutoPostBack) // SetToggleViewActionVisibilityPicklist(ddDropdownlist); // } // break; // #endregion // #region MultiPicklist // case pNums.FieldType.MultiPicklist: //MultiPicklist // ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (listBox != null) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // listBox.DataSource = dtModuleData; // listBox.DataValueField = row["valueField"].ToString(); // listBox.DataTextField = row["displayField"].ToString(); // } // listBox.DataBind(); // } // listBox.ClearSelection(); // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // string valueIds = data.surfaceFieldValueChar.ToString(); // foreach (string valueId in valueIds.Split(',')) // { // foreach (ListItem item in listBox.Items) // { // if (item.Value == valueId) // { // item.Selected = true; // break; // } // } // } // } // } // } // listBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (listBox.GetSelectedIndices().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Date // case pNums.FieldType.Date: //date // TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDate != null) // { // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // if (field.defaultToCurrent) // txtDate.Text = DateTime.Now.ToString(format); // else if (field.defaultValue != "") // txtDate.Text = field.defaultValue; // else // txtDate.Text = ""; // if (!base.IsClone || (base.IsClone && !field.defaultToCurrent)) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDate.Text = data.surfaceFieldValueDate.ToString(format); // //CVH 2016-12-12 Group default collapse - don't apply if set to current date or minimum date // if (txtDate.Text != "" && txtDate.Text != DateTime.Now.ToString(format) && txtDate.Text != _surfaceItem.dateCreated.ToString(format) && data.surfaceFieldValueDate != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2016-12-21 Show empty textbox if date is min date // if (data.surfaceFieldValueDate == DateTime.Parse("1900/01/01")) // txtDate.Text = ""; // break; // } // } // } // /* CVH 2016-01-20 */ // txtDate.Enabled = enabled; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: //checkbox // CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (chkBox != null) // { // chkBox.Checked = false; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // chkBox.Checked = data.surfaceFieldValueBool; // break; // } // } // /* CVH 2016-01-20 */ // chkBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (chkBox.Checked && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Grid // case pNums.FieldType.Grid: //grid // //CVH 2017-01-12 Process all non-grid fields, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // // so not handled here, see next for loop // break; // #endregion // #region RadioButtonList // case pNums.FieldType.RadioButtonList: //radiobuttonlist // RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // if (radioButtonList != null) // { // radioButtonList.SelectedIndex = -1; // //CVH 2016-11-30 Set default reason visible / not visible, otherwise not handled correctly when editing, but no data saved // if (txtReason != null) // { // //always disable reason if no data selected // txtReason.Text = ""; // txtReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtReason.Visible = true; // else // txtReason.Visible = false; // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldLookupID.ToString() != "0") // { // if (radioButtonList.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // radioButtonList.SelectedValue = data.surfaceFieldLookupID.ToString(); // //IOD stuff // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = (radioButtonList.SelectedItem.Text == "Yes"); // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = !(radioButtonList.SelectedItem.Text == "Yes"); // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // if (txtReason != null) // { // txtReason.Text = ""; // txtReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtReason.Visible = true; // if (lookupItem.wantsReason) // { // txtReason.Enabled = true; // if (rfvRadioButtonListReason != null) // { // if (field.required) // { // rfvRadioButtonListReason.ControlToValidate = txtReason.ID; // rfvRadioButtonListReason.Enabled = true; // } // else // rfvRadioButtonListReason.Enabled = false; // } // } // else // txtReason.Enabled = false; // } // else // txtReason.Visible = false; // } // } // } // } // } // else // { // //CVH 2017-01-10 TSP If there is no data, and the field is IOD, show the medical aid group and hide the employer group // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = false; // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = true; // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // if (radioButtonList.AutoPostBack) // SetToggleViewActionVisibilityRadioButtonList(radioButtonList); // radioButtonList.Enabled = enabled; // if (txtReason != null && !radioButtonList.Enabled) txtReason.Enabled = false; // //CVH 2016-12-12 Group default collapse // if (radioButtonList.SelectedItem != null && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Placeholder // case pNums.FieldType.Placeholder: // //no action // break; // #endregion // #region Caption // case pNums.FieldType.Caption: // TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtCaption != null) // { // txtCaption.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtCaption.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtCaption.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtCaption.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: //decimal // TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtFormulaBox != null) // { // txtFormulaBox.Text = ""; // //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) // { // decimal sourceValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField srcField in surfaceFields) // { // if (srcField.recId == field.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (srcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out sourceValue); // else if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // sourceValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out sourceValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // txtFormulaBox.Text = CalculateLookup(field, sourceValue); // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // //CVH 2017-02-07 Divide Calculation Formula is saved in Char column // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) // { // txtFormulaBox.Text = data.surfaceFieldValueChar; // } // else if (field.actionType == (int)pNums.ActionType.Calculation && field.action != divideAction.recId) // { // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", field.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", field.surfaceId + "," + data.surfaceItemId + "," + field.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // txtFormulaBox.Text = age.years.ToString(); // txtFormulaBox.Enabled = false; // } // } // break; // } // } // else // { // if (data.surfaceFieldValueDecimal != 0) // txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // if (data.surfaceFieldValueChar != string.Empty) // txtFormulaBox.Text = data.surfaceFieldValueChar; // } // break; // } // } // } // if (field.actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") // { // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // List sicParams = new List(); // oDynamicParam sicParam = new oDynamicParam(); // sicParam.paramDisplayName = "userId"; // sicParam.paramObject = userId; // sicParams.Add(sicParam); // DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); // if (nextCodeTable.Rows.Count > 0) // { // txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); // if (txtFormulaBox.Text == "-1") // txtFormulaBox.Text = ""; // } // else // { // txtFormulaBox.Text = ""; // } // } // //txtFormulaBox.Enabled = enabled; // //CVH 2017-02-07 Divide Calculation Formula field is always read only // if ((field.actionType == (int)pNums.ActionType.Calculation && (field.action == divideAction.recId || field.action == lookupAction.recId)) || // (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId)) // txtFormulaBox.Enabled = false; // else // txtFormulaBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Address // case pNums.FieldType.Address: // /* CVH 2016-07-29 Clear address textboxes, in case no data */ // bool found = false; // int itemNoClr = 0; // do // { // found = false; // itemNoClr++; // if (itemNoClr == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr + "dd"); // if (ddSuburb != null) // { // found = true; // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr); // if (txtAddress != null) // { // txtAddress.Text = ""; // found = true; // //JR 2017-02-12 Set default Province for SBF // if (itemNoClr == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // } // } // } while (found && itemNoClr < 50); // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // int itemNo = 0; // foreach (string addressLine in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // itemNo++; // if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo + "dd"); // if (ddSuburb != null) // { // //CVH 2017-02-27 Clear selection, otherwise get exception when index 0 is selected when binding // ddSuburb.Items.Clear(); // if (SuburbTable.Rows.Count > 0) // { // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // } // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // //find addressLine.Substring(3) // if (addressLine != String.Empty) // { // if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) // ddSuburb.SelectedValue = addressLine.Substring(3); // } // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo); // if (txtAddress != null && addressLine != String.Empty && addressLine.Substring(1, 1) == itemNo.ToString()) // { // /* CVH 2016-01-20 */ // txtAddress.Enabled = enabled; // txtAddress.Text = addressLine.Substring(3); // //JR 2017-02-12 Set default Province for SBF // if (itemNo == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // //CVH 2016-12-12 Group default collapse // if (txtAddress.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: //checkboxlist // /* CVH 2016-09-27 Cater for Wants Reason. alternateView does not use wantsReason */ // if (field.alternateView) // { // CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxList != null) // { // checkboxList.SelectedIndex = -1; // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // if (checkboxList.Items.FindByValue(lookupId) != null) // checkboxList.Items.FindByValue(lookupId).Selected = true; // } // } // } // } // checkboxList.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (checkboxList.Items.GetSelectedItems().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // else // { // Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxPanel != null) // { // //CVH 2016-10-11 Clear checked items // foreach (Control lblClear in checkboxPanel.Controls) // { // if (lblClear != null && lblClear.Controls.Count > 0) // { // Control ctrlClear = lblClear.Controls[0]; // if (ctrlClear.GetType() == typeof(CheckBox)) // { // CheckBox chkClear = (CheckBox)ctrlClear; // chkClear.Checked = false; // TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); // if (txtClear != null) // { // txtClear.Text = ""; // txtClear.Enabled = false; // } // } // } // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // string reason = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // reason = temp.Substring(temp.IndexOf("~R~") + 3); // } // else // { // lookupId = temp; // } // foreach (Control lblWrapper in checkboxPanel.Controls) // { // CheckBox chk = (CheckBox)lblWrapper.FindControl(field.surfaceFieldName + "_" + lookupId); // //CheckBox chk = (CheckBox)checkboxPanel.FindControl(field.surfaceFieldName + "_" + lookupId); // if (chk != null) // { // chk.Checked = true; // //try to find textbox for wants reason // TextBox txtChkReason = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); // if (txtChkReason != null) // { // txtChkReason.Text = reason; // txtChkReason.Enabled = true; // } // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // foreach (Control ctrlToggle in checkboxPanel.Controls) // { // if (ctrlToggle.GetType() == typeof(CheckBox)) // { // CheckBox chkToggle = (CheckBox)ctrlToggle; // if (chkToggle.AutoPostBack) // SetToggleViewActionVisibilityCheckboxList(chkToggle); // } // } // checkboxPanel.Enabled = enabled; // } // } // break; // #endregion // #region RelationalField // case pNums.FieldType.RelationalField: // foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", field.relationalFields.ToString())) // { // if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) // { // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field); // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // break; // #endregion // #region Button // case pNums.FieldType.Button: // Button btn = (Button)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (btn != null) // { // if (field.surfaceFieldName == "PatientProfile_PatientStatus") // { // foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) // { // if (visitLog.signOutDate.Year > 1900) // { // btn.Text = "Status: In Progress"; // btn.AddCssClass("btn-success"); // btn.RemoveCssClass("btn-warning"); // btn.RemoveCssClass("btn-danger"); // } // else // { // btn.Text = "Status: Pending"; // btn.AddCssClass("btn-warning"); // btn.RemoveCssClass("btn-success"); // btn.RemoveCssClass("btn-danger"); // } // break; // } // } // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageDiv != null) // { // string imageUrl = "/images/placeholder.png"; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (data.surfaceFieldValueChar != "") // { // imageUrl = "/upload/surface/" + data.surfaceFieldValueChar; // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // } // } // imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // break; // #endregion // } // } // } // //GR added call to get grid fields to avoid unecessary loops // ArrayList gridFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", _surfaceItem.surfaceId + "," + (int)pNums.FieldType.Grid); // //CVH 2017-01-12 Process all non-grid fields first, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // foreach (oSurfaceField field in gridFields) // { // //only process grid fields // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Grid) // continue; // /* CVH 2016-01-20 */ // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // #region Grid // //find the div and bind all repeaters inside it // HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + field.surfaceFieldName); // Panel panelGridHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelCompareHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelFormHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // if (divGridHolder != null) // { // DataTable childData = new DataTable(); // int surfaceId = 0; // oSurface childSurface = new oSurface(); // foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // surfaceId = surf.recId; // childSurface = surf; // break; // } // if (surfaceId > 0) // { // int rowLimit = 0; // int.TryParse(field.relationalValues, out rowLimit); // //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data // if (field.isControlled) // { // childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); // } // else // { // childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); // if ((childData.Rows.Count == 0 && field.defaultToCurrent) || (base.SurfaceAppItemId == 0 && field.defaultToCurrent && childData.Rows.Count > 0)) // { // DataTable masterDataItems = new DataTable(); // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); // if (childData.Rows.Count == 0) // { // childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); // } // } // } // if (panelGridHolder != null) // { // Repeater repeater = null; // //foreach (Control rpt in divGridHolder.Controls) // foreach (Control rpt in panelGridHolder.Controls) // { // if (rpt.GetType() == typeof(Repeater)) // { // repeater = (Repeater)rpt; // SetAggregates(childData, surfaceId); // repeater.DataSource = childData; // repeater.DataBind(); // } // } // if (field.isComparable && panelCompareHolder != null) // { // BindCompareDropdowns(childSurface, field.surfaceFieldName); // panelCompareHolder.Visible = true; // panelGridHolder.Visible = false; // } // //CVH 2017-02-23 Only put in edit mode when field is not Read Only // else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !field.isReadOnly && !field.isControlled) // { // //CVH 2016-12-20 Child grid default edit mode // foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) // { // //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) // if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) // { // int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); // RepeaterItem childRptItem = repeater.Items[0]; // EditChild(editChildItemId, childRptItem); // } // break; // } // } // } // if (field.relationalValues == "1" && panelFormHolder != null) // { // panelFormHolder.Visible = true; // if (childData.Rows.Count > 0) // { // int childSurfaceItemId = childData.Rows[0].Field("itemID"); // oSurfaceItem childItem = new oSurfaceItem(); // foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childSurfaceItemId.ToString())) // { // childItem = item; // } // //PopulateSurfaceView(childItem, true); // } // } // } // } // #endregion // } // BindSurfaceAttachments(_surfaceItem.recId, false); // BindSurfaceNotes(_surfaceItem.recId, false); // //GR added call to get grid fields to avoid unecessary loops // ArrayList groupFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", _surfaceItem.surfaceId + "," + (int)pNums.FieldType.Group); // //CVH 2016-12-12 Expand/Collapse groups depending on data loaded // string expandGroups = ""; // foreach (oSurfaceField groupField in groupFields) // { // if (groupField.surfaceFieldTypeId == (int)pNums.FieldType.Group) // { // if (groupField.isControlled && groupIdsWithData.Contains("|" + groupField.recId + "|")) // { // if (expandGroups == String.Empty) // expandGroups = "tog" + groupField.surfaceFieldName; // else // expandGroups += ",tog" + groupField.surfaceFieldName; // } // } // } // ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; // //CVH 2017-01-10 Only register script when not page load, otherwise javascript error method not defined that breaks other javascript // if (Page.IsPostBack) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroupsPopulate", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); // //handle last // if (base.SurfaceApp.isWizzard) // { // //GR added check now to see if wizard completed // if (base.SurfaceAppItem != null) // { // wizardcompleted = base.SurfaceAppItem.isWizardCompleted; // } // if (!wizardcompleted && (usr.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) // //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) // ArrayList fieldTabs1 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // pnlWizzardButtons.Visible = true; // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // SetLastTabUsed(fieldTabs1); // } // else // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // ArrayList fieldTabs2 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // MaintainActiveTab(fieldTabs2); // SetTabsVisible(fieldTabs2); // //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one // if ((setup.code == "SHOU-1" || setup.code == "GLOB-1") && usr.userType >= (int)pNums.UserType.PowerUser && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null) // { // int tabIndex = 0; // foreach (oSurfaceField tab in fieldTabs2) // { // tabIndex++; // if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) // break; // } // if (tabIndex > 0) // { // //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; // //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; // HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; // //GR 2017-03-18 set hidden tab index for inital page load // if (!Page.IsPostBack) // { // hfTabIndex.Value = (tabIndex - 1).ToString(); // } // else // hfTabIndex.Value = ""; // } // } // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) // { // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = true; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // btnSaveSingle.ValidationGroup = ""; // btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // btnSave.ValidationGroup = ""; // btnSaveAndNew.ValidationGroup = ""; // btnSaveBack.ValidationGroup = ""; // btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // } // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) // ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // SetTabsVisibleNoWizard(fieldTabs, false); // } // SetCustomVisible(); // PerformCustomPopulateAddOn(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} ///// ///// Populate the surface form ///// GR 2017-04-13 Revised to use the query data ///// //private void PopulateSurfaceFormBak2(oSurfaceItem _surfaceItem, bool isNew) //{ // bool wizardcompleted = false; // try // { // //first fetch the field and data records // DataTable surfaceFieldsTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); // DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId); // ArrayList surfaceFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); // ArrayList surfaceFieldData = utils.ConvertDataTableToListParallel(surfaceFieldDataTable, typeof(oSurfaceFieldData)); // var fieldDataQ = surfaceFieldData.OfType().AsQueryable(); // oUser usr = new oUser(); // if (utils.verifySession("user")) // { usr = (oUser)Session["user"]; } // oSetup setup = handler.ReturnSetup(); // //CVH 2017-02-07 Determine Divide Action to be used in formula field // oSurfaceAction divideAction = new oSurfaceAction(); // oSurfaceAction lookupAction = new oSurfaceAction(); // oSurfaceAction aggrSumAction = new oSurfaceAction(); // foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) // { // if (act.actionType == (int)pNums.ActionType.Calculation) // { // if (act.action == "Divide") // divideAction = act; // else if (act.action == "Lookup") // lookupAction = act; // } // else if (act.actionType == (int)pNums.ActionType.Aggregation) // { // if (act.action == "Sum") // aggrSumAction = act; // } // } // //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default // string groupIdsWithData = ""; // string expandGroups = ""; // foreach (oSurfaceField field in surfaceFields) // { // //CVH 2017-01-12 Process all non-grid fields, then loop again for grid fields. This is necessary to clear all the fields before saving the Draft item when copying child grid data from master // //if (field.surfaceFieldTypeId == (int)pNums.FieldType.Grid) // // continue; // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) // { // Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + field.surfaceFieldName); // if (groupControl != null) // { // //CVH 2017-01-13 Ignore security on group if TSP and group is IOD groups hardcoded to show/hide depending on user selection // if ((setup.code == "SHOU-1") && // (field.surfaceFieldName == "PatientInformation_EmployerDetailsInjuryonDuty" || field.surfaceFieldName == "PatientInformation_MedicalAidIfapplicable")) // { // //do nothing // } // else if (setup.code == "GLOB-1" && // field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup && // !_surfaceItem.isWizardCompleted) // { // groupControl.Visible = false; // } // else // { // groupControl.Visible = usr.userType >= field.accessLevel; // } // } // } // /* CVH 2016-01-20 */ // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab) // { // pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); // switch (typ) // { // case pNums.FieldType.Group: // if (field.isControlled && groupIdsWithData.Contains("|" + field.recId + "|")) // { // if (expandGroups == String.Empty) // expandGroups = "tog" + field.surfaceFieldName; // else // expandGroups += ",tog" + field.surfaceFieldName; // } // break; // #region Label // case pNums.FieldType.Label: // if (field.isReadOnly)//hide labels on new // { // Control divControl; // divControl = FindControl("srt" + field.surfaceFieldName); // if (divControl != null) // divControl.Visible = false; // } // else // { // bool isImage = false; // string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; // if (field.relationalSurface == "user") // { // foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = user.userDisplay; // } // } // else if (field.relationalSurface == "date") // { // if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; // } // } // else // { // string itemId = _surfaceItem.recId.ToString(); // //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface // if (field.relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) // itemId = base.ParentSurfaceItemId.ToString(); // foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString())) // { // sourceFieldLabel = sourceField.surfaceFieldDisplay; // foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString() + "," + itemId)) // { // pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); // switch (sourceType) // { // #region Text|Caption|Address|MultiPicklist // case pNums.FieldType.Text: // case pNums.FieldType.Caption: // case pNums.FieldType.Address: // case pNums.FieldType.MultiPicklist: // sourceFieldValue = sourceData.surfaceFieldValueChar; // break; // #endregion // #region Number // case pNums.FieldType.Number: // sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: // sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); // break; // #endregion // #region Date // case pNums.FieldType.Date: // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); // break; // #endregion // #region Picklist|RadioButtonList // case pNums.FieldType.Picklist: // case pNums.FieldType.RadioButtonList: // sourceFieldValue = ""; // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) // { // sourceFieldValue = look.display; // break; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: // sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: // sourceFieldValue = ""; // //CVH 2017-02-13 New action Lookup need to recalc on load // if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) // { // decimal lookupSrcValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField lookupSrcField in surfaceFields) // { // if (lookupSrcField.recId == sourceField.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(lookupSrcField.recId))) // { // if (lookupSrcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out lookupSrcValue); // else if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // lookupSrcValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out lookupSrcValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // sourceFieldValue = CalculateLookup(field, lookupSrcValue); // } // } // //CVH 2017-02-07 New action Divide is saved in Char // else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) // { // sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // sourceFieldValue = age.years.ToString(); // } // } // break; // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // sourceFieldValue = sourceData.surfaceFieldValueChar; // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: // sourceFieldValue = ""; // //split string to get lookup IDs // foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // //get lookup // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) // { // if (sourceFieldValue == String.Empty) // sourceFieldValue = look.display; // else // sourceFieldValue += ", " + look.display; // break; // } // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageLabelDiv != null) // { // string imageUrl = "/images/placeholder.png"; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // if (imageLabelDiv != null) // { // string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // isImage = true; // break; // #endregion // #region Attachment // case pNums.FieldType.Attachment: // HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfAttachments"); // int intItemIdAt = 0; // int.TryParse(itemId, out intItemIdAt); // if (attachDiv != null && intItemIdAt > 0) // BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); // break; // #endregion // #region Note // case pNums.FieldType.Note: // HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfNotes"); // int intItemIdN = 0; // int.TryParse(itemId, out intItemIdN); // if (notesDiv != null && intItemIdN > 0) // BindNotes(intItemIdN, notesDiv); // break; // #endregion // } // } // } // } // Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Value"); // if (lblValue != null) // { // lblValue.Text = sourceFieldValue; // } // } // } // //CVH 2016-12-12 Don't expand collapsed group just for label // groupIdsWithData += ""; // break; // #endregion // #region Text // case pNums.FieldType.Text://Textbox // case pNums.FieldType.Caption://Caption // TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtTextbox != null) // { // txtTextbox.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtTextbox.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtTextbox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Number // case pNums.FieldType.Number: //number // TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtNumberBox != null) // { // if (field.isControlled) // { // int nextNumber = 0; // int.TryParse(field.controlledValue, out nextNumber); // nextNumber++; // txtNumberBox.Enabled = false; // txtNumberBox.Text = nextNumber.ToString(); // } // else // txtNumberBox.Text = ""; // if (!base.IsClone || (base.IsClone && !field.isControlled)) // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtNumberBox.Text = Math.Floor(decFormula).ToString(); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtNumberBox.Text = data.surfaceFieldValueNum.ToString(); // break; // } // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtNumberBox.Enabled = false; // else // txtNumberBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: //decimal // TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDecimalBox != null) // { // txtDecimalBox.Text = ""; // if (setup.code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) // { // //leave decimal textbox blank if item ID = 0 // if (base.SurfaceAppItemId != 0) // { // //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) // List listPortion = new List(); // oDynamicParam por1 = new oDynamicParam(); // por1.paramDisplayName = "surfaceId"; // por1.paramObject = _surfaceItem.surfaceId; // listPortion.Add(por1); // oDynamicParam por2 = new oDynamicParam(); // por2.paramDisplayName = "surfaceItemId"; // por2.paramObject = base.SurfaceAppItemId; // listPortion.Add(por2); // DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); // if (dtPortion != null && dtPortion.Rows.Count > 0) // txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); // } // } // else // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // break; // } // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtDecimalBox.Enabled = false; // else // txtDecimalBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Picklist // case pNums.FieldType.Picklist: //picklist // DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // //CVH 2017-03-01 First off clear reason // if (txtPicklistReason != null) // txtPicklistReason.Text = ""; // if (ddDropdownlist != null) // { // ddDropdownlist.SelectedIndex = -1; // //CVH 2016-10-21 Also check !="0" otherwise it adds extra "Select" item for normal dropdowns (relationalObject saves as "0") // //if (field.relationalObject.Length > 0) // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // ddDropdownlist.DataSource = dtModuleData; // ddDropdownlist.DataValueField = row["valueField"].ToString(); // ddDropdownlist.DataTextField = row["displayField"].ToString(); // } // ddDropdownlist.DataBind(); // if (ddDropdownlist.Items.Count == 0) // { // enabled = false; // ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); // } // else // ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldValueChar.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldValueChar.ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldLookupID.ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtPicklistReason.Visible = true; // if (lookupItem.wantsReason) // { // txtPicklistReason.Enabled = true; // if (rfvPicklistReason != null) // rfvPicklistReason.ControlToValidate = txtPicklistReason.ID; // } // else // { // txtPicklistReason.Enabled = false; // txtPicklistReason.Text = ""; // } // } // else // txtPicklistReason.Visible = false; // } // } // } // break; // } // } // } // else if (txtPicklistReason != null) // { // //always disable reason if no selection // txtPicklistReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtPicklistReason.Visible = true; // else // txtPicklistReason.Visible = false; // } // ddDropdownlist.Enabled = enabled; // //if dropdownlist is not enabled, reason shouldn't be enabled either // if (txtPicklistReason != null && !ddDropdownlist.Enabled) txtPicklistReason.Enabled = false; // if (field.surfaceFieldName == "PatientType_PatientType_PatientType") // { // SetPatientType("PatientType_PatientType_PatientType"); // } // //CVH 2016-12-12 Group default collapse // if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedIndex != -1 && ddDropdownlist.SelectedValue != "0" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2017-01-18 Toggle View Action: If checkedchanged event is linked to picklist, call method to set controls Visible=false/true depending on selected value // if (ddDropdownlist.AutoPostBack) // SetToggleViewActionVisibilityPicklist(ddDropdownlist); // } // break; // #endregion // #region MultiPicklist // case pNums.FieldType.MultiPicklist: //MultiPicklist // ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (listBox != null) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // listBox.DataSource = dtModuleData; // listBox.DataValueField = row["valueField"].ToString(); // listBox.DataTextField = row["displayField"].ToString(); // } // listBox.DataBind(); // } // listBox.ClearSelection(); // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // string valueIds = data.surfaceFieldValueChar.ToString(); // foreach (string valueId in valueIds.Split(',')) // { // foreach (ListItem item in listBox.Items) // { // if (item.Value == valueId) // { // item.Selected = true; // break; // } // } // } // } // } // } // listBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (listBox.GetSelectedIndices().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Date // case pNums.FieldType.Date: //date // TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDate != null) // { // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // if (field.defaultToCurrent) // txtDate.Text = DateTime.Now.ToString(format); // else if (field.defaultValue != "") // txtDate.Text = field.defaultValue; // else // txtDate.Text = ""; // if (!base.IsClone || (base.IsClone && !field.defaultToCurrent)) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtDate.Text = data.surfaceFieldValueDate.ToString(format); // //CVH 2016-12-12 Group default collapse - don't apply if set to current date or minimum date // if (txtDate.Text != "" && txtDate.Text != DateTime.Now.ToString(format) && txtDate.Text != _surfaceItem.dateCreated.ToString(format) && data.surfaceFieldValueDate != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2016-12-21 Show empty textbox if date is min date // if (data.surfaceFieldValueDate == DateTime.Parse("1900/01/01")) // txtDate.Text = ""; // break; // } // } // } // /* CVH 2016-01-20 */ // txtDate.Enabled = enabled; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: //checkbox // CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (chkBox != null) // { // chkBox.Checked = false; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // chkBox.Checked = data.surfaceFieldValueBool; // break; // } // } // /* CVH 2016-01-20 */ // chkBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (chkBox.Checked && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Grid // case pNums.FieldType.Grid: //grid // //find the div and bind all repeaters inside it // HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + field.surfaceFieldName); // Panel panelGridHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelCompareHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelFormHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // if (divGridHolder != null) // { // DataTable childData = new DataTable(); // int surfaceId = 0; // oSurface childSurface = new oSurface(); // foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // surfaceId = surf.recId; // childSurface = surf; // break; // } // if (surfaceId > 0) // { // int rowLimit = 0; // int.TryParse(field.relationalValues, out rowLimit); // //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data // if (field.isControlled) // { // childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); // } // else // { // childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); // if ((childData.Rows.Count == 0 && field.defaultToCurrent) || (base.SurfaceAppItemId == 0 && field.defaultToCurrent && childData.Rows.Count > 0)) // { // DataTable masterDataItems = new DataTable(); // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); // if (childData.Rows.Count == 0) // { // childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); // } // } // } // if (panelGridHolder != null) // { // Repeater repeater = null; // //foreach (Control rpt in divGridHolder.Controls) // foreach (Control rpt in panelGridHolder.Controls) // { // if (rpt.GetType() == typeof(Repeater)) // { // repeater = (Repeater)rpt; // SetAggregates(childData, surfaceId); // repeater.DataSource = childData; // repeater.DataBind(); // } // } // if (field.isComparable && panelCompareHolder != null) // { // BindCompareDropdowns(childSurface, field.surfaceFieldName); // panelCompareHolder.Visible = true; // panelGridHolder.Visible = false; // } // //CVH 2017-02-23 Only put in edit mode when field is not Read Only // else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !field.isReadOnly && !field.isControlled) // { // //CVH 2016-12-20 Child grid default edit mode // foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) // { // //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) // if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) // { // int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); // RepeaterItem childRptItem = repeater.Items[0]; // EditChild(editChildItemId, childRptItem); // } // break; // } // } // } // if (field.relationalValues == "1" && panelFormHolder != null) // { // panelFormHolder.Visible = true; // if (childData.Rows.Count > 0) // { // int childSurfaceItemId = childData.Rows[0].Field("itemID"); // oSurfaceItem childItem = new oSurfaceItem(); // foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childSurfaceItemId.ToString())) // { // childItem = item; // } // //PopulateSurfaceView(childItem, true); // } // } // } // } // break; // #endregion // #region RadioButtonList // case pNums.FieldType.RadioButtonList: //radiobuttonlist // RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // if (radioButtonList != null) // { // radioButtonList.SelectedIndex = -1; // //CVH 2016-11-30 Set default reason visible / not visible, otherwise not handled correctly when editing, but no data saved // if (txtReason != null) // { // //always disable reason if no data selected // txtReason.Text = ""; // txtReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtReason.Visible = true; // else // txtReason.Visible = false; // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldLookupID.ToString() != "0") // { // if (radioButtonList.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // radioButtonList.SelectedValue = data.surfaceFieldLookupID.ToString(); // //IOD stuff // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = (radioButtonList.SelectedItem.Text == "Yes"); // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = !(radioButtonList.SelectedItem.Text == "Yes"); // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // if (txtReason != null) // { // txtReason.Text = ""; // txtReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtReason.Visible = true; // if (lookupItem.wantsReason) // { // txtReason.Enabled = true; // if (rfvRadioButtonListReason != null) // { // if (field.required) // { // rfvRadioButtonListReason.ControlToValidate = txtReason.ID; // rfvRadioButtonListReason.Enabled = true; // } // else // rfvRadioButtonListReason.Enabled = false; // } // } // else // txtReason.Enabled = false; // } // else // txtReason.Visible = false; // } // } // } // } // } // else // { // //CVH 2017-01-10 TSP If there is no data, and the field is IOD, show the medical aid group and hide the employer group // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = false; // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = true; // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // if (radioButtonList.AutoPostBack) // SetToggleViewActionVisibilityRadioButtonList(radioButtonList); // radioButtonList.Enabled = enabled; // if (txtReason != null && !radioButtonList.Enabled) txtReason.Enabled = false; // //CVH 2016-12-12 Group default collapse // if (radioButtonList.SelectedItem != null && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Placeholder // case pNums.FieldType.Placeholder: // //no action // break; // #endregion // #region Caption // case pNums.FieldType.Caption: // TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtCaption != null) // { // txtCaption.Text = ""; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // txtCaption.Text = data.surfaceFieldValueChar; // break; // } // } // /* CVH 2016-01-20 */ // txtCaption.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtCaption.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: //decimal // TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtFormulaBox != null) // { // txtFormulaBox.Text = ""; // //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) // { // decimal sourceValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField srcField in surfaceFields) // { // if (srcField.recId == field.actionSource) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (srcField.recId == data.surfaceFieldID) // { // //catering for field types char, number, decimal // if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(data.surfaceFieldValueNum.ToString(), out sourceValue); // else if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // sourceValue = data.surfaceFieldValueDecimal; // } // else // conversionSuccess = decimal.TryParse(data.surfaceFieldValueChar, out sourceValue); // break; // } // } // break; // } // } // if (conversionSuccess) // { // txtFormulaBox.Text = CalculateLookup(field, sourceValue); // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // //CVH 2017-02-07 Divide Calculation Formula is saved in Char column // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) // { // txtFormulaBox.Text = data.surfaceFieldValueChar; // } // else if (field.actionType == (int)pNums.ActionType.Calculation && field.action != divideAction.recId) // { // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", field.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", field.surfaceId + "," + data.surfaceItemId + "," + field.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // txtFormulaBox.Text = age.years.ToString(); // txtFormulaBox.Enabled = false; // } // } // break; // } // } // else // { // if (data.surfaceFieldValueDecimal != 0) // txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(data.surfaceFieldValueDecimal)); // if (data.surfaceFieldValueChar != string.Empty) // txtFormulaBox.Text = data.surfaceFieldValueChar; // } // break; // } // } // } // if (field.actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") // { // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // List sicParams = new List(); // oDynamicParam sicParam = new oDynamicParam(); // sicParam.paramDisplayName = "userId"; // sicParam.paramObject = userId; // sicParams.Add(sicParam); // DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); // if (nextCodeTable.Rows.Count > 0) // { // txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); // if (txtFormulaBox.Text == "-1") // txtFormulaBox.Text = ""; // } // else // { // txtFormulaBox.Text = ""; // } // } // //txtFormulaBox.Enabled = enabled; // //CVH 2017-02-07 Divide Calculation Formula field is always read only // if ((field.actionType == (int)pNums.ActionType.Calculation && (field.action == divideAction.recId || field.action == lookupAction.recId)) || // (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId)) // txtFormulaBox.Enabled = false; // else // txtFormulaBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Address // case pNums.FieldType.Address: // /* CVH 2016-07-29 Clear address textboxes, in case no data */ // bool found = false; // int itemNoClr = 0; // do // { // found = false; // itemNoClr++; // if (itemNoClr == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr + "dd"); // if (ddSuburb != null) // { // found = true; // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr); // if (txtAddress != null) // { // txtAddress.Text = ""; // found = true; // //JR 2017-02-12 Set default Province for SBF // if (itemNoClr == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // } // } // } while (found && itemNoClr < 50); // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // int itemNo = 0; // foreach (string addressLine in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // itemNo++; // if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo + "dd"); // if (ddSuburb != null) // { // //CVH 2017-02-27 Clear selection, otherwise get exception when index 0 is selected when binding // ddSuburb.Items.Clear(); // if (SuburbTable.Rows.Count > 0) // { // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // } // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // //find addressLine.Substring(3) // if (addressLine != String.Empty) // { // if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) // ddSuburb.SelectedValue = addressLine.Substring(3); // } // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo); // if (txtAddress != null && addressLine != String.Empty && addressLine.Substring(1, 1) == itemNo.ToString()) // { // /* CVH 2016-01-20 */ // txtAddress.Enabled = enabled; // txtAddress.Text = addressLine.Substring(3); // //JR 2017-02-12 Set default Province for SBF // if (itemNo == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // //CVH 2016-12-12 Group default collapse // if (txtAddress.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: //checkboxlist // /* CVH 2016-09-27 Cater for Wants Reason. alternateView does not use wantsReason */ // if (field.alternateView) // { // CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxList != null) // { // checkboxList.SelectedIndex = -1; // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // if (checkboxList.Items.FindByValue(lookupId) != null) // checkboxList.Items.FindByValue(lookupId).Selected = true; // } // } // } // } // checkboxList.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (checkboxList.Items.GetSelectedItems().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // else // { // Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxPanel != null) // { // //CVH 2016-10-11 Clear checked items // foreach (Control lblClear in checkboxPanel.Controls) // { // if (lblClear != null && lblClear.Controls.Count > 0) // { // Control ctrlClear = lblClear.Controls[0]; // if (ctrlClear.GetType() == typeof(CheckBox)) // { // CheckBox chkClear = (CheckBox)ctrlClear; // chkClear.Checked = false; // TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); // if (txtClear != null) // { // txtClear.Text = ""; // txtClear.Enabled = false; // } // } // } // } // if (surfaceFieldData != null && surfaceFieldData.Count > 0) // { // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldValueChar.ToString() != "") // { // foreach (string temp in data.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // string reason = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // reason = temp.Substring(temp.IndexOf("~R~") + 3); // } // else // { // lookupId = temp; // } // foreach (Control lblWrapper in checkboxPanel.Controls) // { // CheckBox chk = (CheckBox)lblWrapper.FindControl(field.surfaceFieldName + "_" + lookupId); // //CheckBox chk = (CheckBox)checkboxPanel.FindControl(field.surfaceFieldName + "_" + lookupId); // if (chk != null) // { // chk.Checked = true; // //try to find textbox for wants reason // TextBox txtChkReason = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); // if (txtChkReason != null) // { // txtChkReason.Text = reason; // txtChkReason.Enabled = true; // } // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // foreach (Control ctrlToggle in checkboxPanel.Controls) // { // if (ctrlToggle.GetType() == typeof(CheckBox)) // { // CheckBox chkToggle = (CheckBox)ctrlToggle; // if (chkToggle.AutoPostBack) // SetToggleViewActionVisibilityCheckboxList(chkToggle); // } // } // checkboxPanel.Enabled = enabled; // } // } // break; // #endregion // #region RelationalField // case pNums.FieldType.RelationalField: // foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", field.relationalFields.ToString())) // { // if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) // { // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // SetSurfaceControlState(_surfaceItem, surfaceFieldData, field); // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // break; // #endregion // #region Button // case pNums.FieldType.Button: // Button btn = (Button)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (btn != null) // { // if (field.surfaceFieldName == "PatientProfile_PatientStatus") // { // foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) // { // if (visitLog.signOutDate.Year > 1900) // { // btn.Text = "Status: In Progress"; // btn.AddCssClass("btn-success"); // btn.RemoveCssClass("btn-warning"); // btn.RemoveCssClass("btn-danger"); // } // else // { // btn.Text = "Status: Pending"; // btn.AddCssClass("btn-warning"); // btn.RemoveCssClass("btn-success"); // btn.RemoveCssClass("btn-danger"); // } // break; // } // } // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageDiv != null) // { // string imageUrl = "/images/placeholder.png"; // foreach (oSurfaceFieldData data in fieldDataQ.Where(p => p.surfaceFieldID.Equals(field.recId))) // { // if (field.recId == data.surfaceFieldID) // { // if (data.surfaceFieldValueChar != "") // { // imageUrl = "/upload/surface/" + data.surfaceFieldValueChar; // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // } // } // imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // break; // #endregion // } // } // } // BindSurfaceAttachments(_surfaceItem.recId, false); // BindSurfaceNotes(_surfaceItem.recId, false); // ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; // //CVH 2017-01-10 Only register script when not page load, otherwise javascript error method not defined that breaks other javascript // if (Page.IsPostBack) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroupsPopulate", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); // //handle last // if (base.SurfaceApp.isWizzard) // { // //GR added check now to see if wizard completed // if (base.SurfaceAppItem != null) // { // wizardcompleted = base.SurfaceAppItem.isWizardCompleted; // } // if (!wizardcompleted && (usr.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) // //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) // ArrayList fieldTabs1 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // pnlWizzardButtons.Visible = true; // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // SetLastTabUsed(fieldTabs1); // } // else // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // ArrayList fieldTabs2 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // MaintainActiveTab(fieldTabs2); // SetTabsVisible(fieldTabs2); // //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one // if ((setup.code == "SHOU-1" || setup.code == "GLOB-1") && usr.userType >= (int)pNums.UserType.PowerUser && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null) // { // int tabIndex = 0; // foreach (oSurfaceField tab in fieldTabs2) // { // tabIndex++; // if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) // break; // } // if (tabIndex > 0) // { // //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; // //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; // HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; // //GR 2017-03-18 set hidden tab index for inital page load // if (!Page.IsPostBack) // { // hfTabIndex.Value = (tabIndex - 1).ToString(); // } // else // hfTabIndex.Value = ""; // } // } // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) // { // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = true; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // btnSaveSingle.ValidationGroup = ""; // btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // btnSave.ValidationGroup = ""; // btnSaveAndNew.ValidationGroup = ""; // btnSaveBack.ValidationGroup = ""; // btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // } // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) // ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // SetTabsVisibleNoWizard(fieldTabs, false); // } // SetCustomVisible(); // PerformCustomPopulateAddOn(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} ///// ///// Populate the surface form ///// GR 2017-04-13 Revised to use the query data ///// //private void PopulateSurfaceFormTest(oSurfaceItem _surfaceItem, bool isNew) //{ // bool wizardcompleted = false; // try // { // //get the item data // DataTable surfaceFieldsTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); // DataTable surfaceItemData = xData.GetSurfaceQueryItemData(_surfaceItem.surfaceId, _surfaceItem.recId); // //get the fields // ArrayList surfFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); // //create querable fields list // var fieldsQ = surfFields.OfType().AsQueryable(); // oUser usr = new oUser(); // if (utils.verifySession("user")) // { usr = (oUser)Session["user"]; } // oSetup setup = handler.ReturnSetup(); // //CVH 2017-02-07 Determine Divide Action to be used in formula field // oSurfaceAction divideAction = new oSurfaceAction(); // oSurfaceAction lookupAction = new oSurfaceAction(); // oSurfaceAction aggrSumAction = new oSurfaceAction(); // foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) // { // if (act.actionType == (int)pNums.ActionType.Calculation) // { // if (act.action == "Divide") // divideAction = act; // else if (act.action == "Lookup") // lookupAction = act; // } // else if (act.actionType == (int)pNums.ActionType.Aggregation) // { // if (act.action == "Sum") // aggrSumAction = act; // } // } // //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default // string groupIdsWithData = ""; // string expandGroups = ""; // //enumerate the item // foreach (DataRow fieldItemRow in surfaceItemData.Rows) // { // //enumerate each column in the item to pick up the field // foreach (DataColumn fieldItemCol in surfaceItemData.Columns) // { // var fields = fieldsQ.Where(p => p.surfaceFieldName.Equals(fieldItemCol.ColumnName)); // foreach (oSurfaceField field in fields) // { // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) // { // Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + field.surfaceFieldName); // if (groupControl != null) // { // //CVH 2017-01-13 Ignore security on group if TSP and group is IOD groups hardcoded to show/hide depending on user selection // if ((setup.code == "SHOU-1") && // (field.surfaceFieldName == "PatientInformation_EmployerDetailsInjuryonDuty" || field.surfaceFieldName == "PatientInformation_MedicalAidIfapplicable")) // { // //do nothing // } // else if (setup.code == "GLOB-1" && // field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup && // !_surfaceItem.isWizardCompleted) // { // groupControl.Visible = false; // } // else // { // groupControl.Visible = usr.userType >= field.accessLevel; // } // } // } // /* CVH 2016-01-20 */ // bool enabled = !field.isReadOnly && !field.isControlled; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !field.isControlled)//if controlled value, should always be readonly // enabled = true; // if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab) // { // pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); // switch (typ) // { // case pNums.FieldType.Group: // if (field.isControlled && groupIdsWithData.Contains("|" + field.recId + "|")) // { // if (expandGroups == String.Empty) // expandGroups = "tog" + field.surfaceFieldName; // else // expandGroups += ",tog" + field.surfaceFieldName; // } // break; // #region Label // case pNums.FieldType.Label: // if (field.isReadOnly)//hide labels on new // { // Control divControl; // divControl = FindControl("srt" + field.surfaceFieldName); // if (divControl != null) // divControl.Visible = false; // } // else // { // bool isImage = false; // string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; // if (field.relationalSurface == "user") // { // foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = user.userDisplay; // } // } // else if (field.relationalSurface == "date") // { // if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) // { // sourceFieldLabel = field.surfaceFieldDisplay; // sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; // } // } // else // { // string itemId = _surfaceItem.recId.ToString(); // //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface // if (field.relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) // itemId = base.ParentSurfaceItemId.ToString(); // foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString())) // { // sourceFieldLabel = sourceField.surfaceFieldDisplay; // foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", field.relationalSurface.ToString() + "," + field.relationalFields.ToString() + "," + itemId)) // { // pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); // switch (sourceType) // { // case pNums.FieldType.Text: // case pNums.FieldType.Caption: // case pNums.FieldType.Address: // case pNums.FieldType.MultiPicklist: // sourceFieldValue = sourceData.surfaceFieldValueChar; // break; // case pNums.FieldType.Number: // sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); // break; // case pNums.FieldType.Decimal: // sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); // break; // case pNums.FieldType.Date: // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); // break; // case pNums.FieldType.Picklist: // case pNums.FieldType.RadioButtonList: // sourceFieldValue = ""; // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) // { // sourceFieldValue = look.display; // break; // } // break; // case pNums.FieldType.Checkbox: // sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; // break; // case pNums.FieldType.FormulaField: // sourceFieldValue = ""; // //CVH 2017-02-13 New action Lookup need to recalc on load // if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) // { // decimal lookupSrcValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField lookupSrcField in fieldsQ.Where(p => p.recId.Equals(sourceField.actionSource))) // { // //catering for field types char, number, decimal // if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Number || lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // conversionSuccess = decimal.TryParse(fieldItemRow[lookupSrcField.surfaceFieldName].ToString(), out lookupSrcValue); // break; // } // if (conversionSuccess) // { // sourceFieldValue = CalculateLookup(field, lookupSrcValue); // } // } // //CVH 2017-02-07 New action Divide is saved in Char // else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) // { // sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // sourceFieldValue = age.years.ToString(); // } // } // break; // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // sourceFieldValue = sourceData.surfaceFieldValueChar; // } // break; // case pNums.FieldType.CheckboxList: // sourceFieldValue = ""; // //split string to get lookup IDs // foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // //get lookup // foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) // { // if (sourceFieldValue == String.Empty) // sourceFieldValue = look.display; // else // sourceFieldValue += ", " + look.display; // break; // } // } // break; // case pNums.FieldType.Image: // HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageLabelDiv != null) // { // string imageUrl = "/images/placeholder.png"; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // if (imageLabelDiv != null) // { // string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; // imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // isImage = true; // break; // case pNums.FieldType.Attachment: // HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfAttachments"); // int intItemIdAt = 0; // int.TryParse(itemId, out intItemIdAt); // if (attachDiv != null && intItemIdAt > 0) // BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); // break; // case pNums.FieldType.Note: // HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "LabelfNotes"); // int intItemIdN = 0; // int.TryParse(itemId, out intItemIdN); // if (notesDiv != null && intItemIdN > 0) // BindNotes(intItemIdN, notesDiv); // break; // } // } // } // } // Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + field.surfaceFieldName + "Value"); // if (lblValue != null) // { // lblValue.Text = sourceFieldValue; // } // } // } // //CVH 2016-12-12 Don't expand collapsed group just for label // groupIdsWithData += ""; // break; // #endregion // #region Text // case pNums.FieldType.Text://Textbox // case pNums.FieldType.Caption://Caption // TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtTextbox != null) // { // txtTextbox.Text = ""; // txtTextbox.Text = fieldItemRow[field.surfaceFieldName].ToString(); // /* CVH 2016-01-20 */ // txtTextbox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Number // case pNums.FieldType.Number: //number // TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtNumberBox != null) // { // if (field.isControlled) // { // int nextNumber = 0; // int.TryParse(field.controlledValue, out nextNumber); // nextNumber++; // txtNumberBox.Enabled = false; // txtNumberBox.Text = nextNumber.ToString(); // } // else // txtNumberBox.Text = ""; // if (!base.IsClone || (base.IsClone && !field.isControlled)) // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtNumberBox.Text = Math.Floor(decFormula).ToString(); // } // } // else // { // txtNumberBox.Text = fieldItemRow[field.surfaceFieldName].ToString(); // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtNumberBox.Enabled = false; // else // txtNumberBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: //decimal // TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDecimalBox != null) // { // txtDecimalBox.Text = ""; // if (setup.code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) // { // //leave decimal textbox blank if item ID = 0 // if (base.SurfaceAppItemId != 0) // { // //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) // List listPortion = new List(); // oDynamicParam por1 = new oDynamicParam(); // por1.paramDisplayName = "surfaceId"; // por1.paramObject = _surfaceItem.surfaceId; // listPortion.Add(por1); // oDynamicParam por2 = new oDynamicParam(); // por2.paramDisplayName = "surfaceItemId"; // por2.paramObject = base.SurfaceAppItemId; // listPortion.Add(por2); // DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); // if (dtPortion != null && dtPortion.Rows.Count > 0) // txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); // } // } // else // { // //CVH 2017-02-28 New action type Aggregation Sum // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); // } // } // else // { // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(fieldItemRow[field.surfaceFieldName])); // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // txtDecimalBox.Enabled = false; // else // txtDecimalBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Picklist // case pNums.FieldType.Picklist: //picklist // DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // //CVH 2017-03-01 First off clear reason // if (txtPicklistReason != null) // txtPicklistReason.Text = ""; // if (ddDropdownlist != null) // { // ddDropdownlist.SelectedIndex = -1; // //CVH 2016-10-21 Also check !="0" otherwise it adds extra "Select" item for normal dropdowns (relationalObject saves as "0") // //if (field.relationalObject.Length > 0) // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // ddDropdownlist.DataSource = dtModuleData; // ddDropdownlist.DataValueField = row["valueField"].ToString(); // ddDropdownlist.DataTextField = row["displayField"].ToString(); // } // ddDropdownlist.DataBind(); // if (ddDropdownlist.Items.Count == 0) // { // enabled = false; // ddDropdownlist.Items.Insert(0, new ListItem("No available items", "0")); // } // else // ddDropdownlist.Items.Insert(0, new ListItem("Select", "0")); // } // ArrayList FieldDataList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _surfaceItem.surfaceId + "," + field.recId + "," + _surfaceItem.recId); // if (FieldDataList.Count > 0) // { // foreach (oSurfaceFieldData data in FieldDataList) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldValueChar.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldValueChar.ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // ddDropdownlist.SelectedValue = data.surfaceFieldLookupID.ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtPicklistReason.Visible = true; // if (lookupItem.wantsReason) // { // txtPicklistReason.Enabled = true; // if (rfvPicklistReason != null) // rfvPicklistReason.ControlToValidate = txtPicklistReason.ID; // } // else // { // txtPicklistReason.Enabled = false; // txtPicklistReason.Text = ""; // } // } // else // txtPicklistReason.Visible = false; // } // } // } // break; // } // } // else if (txtPicklistReason != null) // { // //always disable reason if no selection // txtPicklistReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtPicklistReason.Visible = true; // else // txtPicklistReason.Visible = false; // } // ddDropdownlist.Enabled = enabled; // //if dropdownlist is not enabled, reason shouldn't be enabled either // if (txtPicklistReason != null && !ddDropdownlist.Enabled) txtPicklistReason.Enabled = false; // if (field.surfaceFieldName == "PatientType_PatientType_PatientType") // { // SetPatientType("PatientType_PatientType_PatientType"); // } // //CVH 2016-12-12 Group default collapse // if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedIndex != -1 && ddDropdownlist.SelectedValue != "0" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2017-01-18 Toggle View Action: If checkedchanged event is linked to picklist, call method to set controls Visible=false/true depending on selected value // if (ddDropdownlist.AutoPostBack) // SetToggleViewActionVisibilityPicklist(ddDropdownlist); // } // break; // #endregion // #region MultiPicklist // case pNums.FieldType.MultiPicklist: //MultiPicklist // ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (listBox != null) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(field.relationalObject); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", field.relationalObject); // foreach (DataRow row in dtModule.Rows) // { // DataTable dtModuleData = xData.GetTypedByCriteriaSpecificTable("recId", type, "", ""); // listBox.DataSource = dtModuleData; // listBox.DataValueField = row["valueField"].ToString(); // listBox.DataTextField = row["displayField"].ToString(); // } // listBox.DataBind(); // } // listBox.ClearSelection(); // string valueIds = fieldItemRow[field.surfaceFieldName].ToString(); // foreach (string valueId in valueIds.Split(',')) // { // foreach (ListItem item in listBox.Items) // { // if (item.Value == valueId) // { // item.Selected = true; // break; // } // } // } // listBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (listBox.GetSelectedIndices().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Date // case pNums.FieldType.Date: //date // TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtDate != null) // { // string format = "dd/MM/yyyy"; // if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // if (field.defaultToCurrent) // txtDate.Text = DateTime.Now.ToString(format); // else if (field.defaultValue != "") // txtDate.Text = field.defaultValue; // else // txtDate.Text = ""; // if (!base.IsClone || (base.IsClone && !field.defaultToCurrent)) // { // txtDate.Text = fieldItemRow[field.surfaceFieldName].ToString(); // //CVH 2016-12-12 Group default collapse - don't apply if set to current date or minimum date // if (txtDate.Text != "" && txtDate.Text != DateTime.Now.ToString(format) && txtDate.Text != _surfaceItem.dateCreated.ToString(format) && DateTime.Parse(utils.fixDate(fieldItemRow[field.surfaceFieldName].ToString())) != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // //CVH 2016-12-21 Show empty textbox if date is min date // if (DateTime.Parse(utils.fixDate(fieldItemRow[field.surfaceFieldName].ToString())) == DateTime.Parse("1900/01/01")) // txtDate.Text = ""; // } // /* CVH 2016-01-20 */ // txtDate.Enabled = enabled; // } // break; // #endregion // #region Checkbox // case pNums.FieldType.Checkbox: //checkbox // CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (chkBox != null) // { // string boolVal = fieldItemRow[field.surfaceFieldName].ToString(); // chkBox.Checked = false; // if (boolVal.ToLower() == "yes" || boolVal == "1" || boolVal.ToLower() == "true") // { // chkBox.Checked = true; // } // /* CVH 2016-01-20 */ // chkBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (chkBox.Checked && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Grid // case pNums.FieldType.Grid: //grid // //find the div and bind all repeaters inside it // HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + field.surfaceFieldName); // Panel panelGridHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelCompareHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // Panel panelFormHolder = null; // if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName) != null) // panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + field.surfaceId.ToString() + "_" + field.surfaceFieldName); // if (divGridHolder != null) // { // DataTable childData = new DataTable(); // int surfaceId = 0; // oSurface childSurface = new oSurface(); // foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // surfaceId = surf.recId; // childSurface = surf; // break; // } // if (surfaceId > 0) // { // int rowLimit = 0; // int.TryParse(field.relationalValues, out rowLimit); // //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data // if (field.isControlled) // { // childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); // } // else // { // childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); // if ((childData.Rows.Count == 0 && field.defaultToCurrent) || (base.SurfaceAppItemId == 0 && field.defaultToCurrent && childData.Rows.Count > 0)) // { // DataTable masterDataItems = new DataTable(); // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); // if (childData.Rows.Count == 0) // { // childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); // } // } // } // if (panelGridHolder != null) // { // Repeater repeater = null; // //foreach (Control rpt in divGridHolder.Controls) // foreach (Control rpt in panelGridHolder.Controls) // { // if (rpt.GetType() == typeof(Repeater)) // { // repeater = (Repeater)rpt; // SetAggregates(childData, surfaceId); // repeater.DataSource = childData; // repeater.DataBind(); // } // } // if (field.isComparable && panelCompareHolder != null) // { // BindCompareDropdowns(childSurface, field.surfaceFieldName); // panelCompareHolder.Visible = true; // panelGridHolder.Visible = false; // } // //CVH 2017-02-23 Only put in edit mode when field is not Read Only // else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !field.isReadOnly && !field.isControlled) // { // //CVH 2016-12-20 Child grid default edit mode // foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) // { // //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) // if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) // { // int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); // RepeaterItem childRptItem = repeater.Items[0]; // EditChild(editChildItemId, childRptItem); // } // break; // } // } // } // } // } // break; // #endregion // #region RadioButtonList // case pNums.FieldType.RadioButtonList: //radiobuttonlist // RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); // RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + field.surfaceFieldName); // if (radioButtonList != null) // { // radioButtonList.SelectedIndex = -1; // //CVH 2016-11-30 Set default reason visible / not visible, otherwise not handled correctly when editing, but no data saved // if (txtReason != null) // { // //always disable reason if no data selected // txtReason.Text = ""; // txtReason.Enabled = false; // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", field.lookupCategory + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtReason.Visible = true; // else // txtReason.Visible = false; // } // ArrayList FieldDataList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _surfaceItem.surfaceId + "," + field.recId + "," + _surfaceItem.recId); // if (FieldDataList.Count > 0) // { // foreach (oSurfaceFieldData data in FieldDataList) // { // if (field.recId == data.surfaceFieldID && data.surfaceFieldLookupID.ToString() != "0") // { // if (radioButtonList.Items.FindByValue(data.surfaceFieldLookupID.ToString()) != null) // radioButtonList.SelectedValue = data.surfaceFieldLookupID.ToString(); // //IOD stuff // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = (radioButtonList.SelectedItem.Text == "Yes"); // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = !(radioButtonList.SelectedItem.Text == "Yes"); // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // if (txtReason != null) // { // txtReason.Text = ""; // txtReason.Text = data.surfaceFieldValueChar; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", data.surfaceFieldLookupID.ToString())) // { // //if any of the items linked to this category has wantsReason = true, need to set visible Reason field, then if selected item wants reason, set enabled = true // ArrayList catWantsReason = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "categoryId,wantsReason", lookupItem.categoryId + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // { // txtReason.Visible = true; // if (lookupItem.wantsReason) // { // txtReason.Enabled = true; // if (rfvRadioButtonListReason != null) // { // if (field.required) // { // rfvRadioButtonListReason.ControlToValidate = txtReason.ID; // rfvRadioButtonListReason.Enabled = true; // } // else // rfvRadioButtonListReason.Enabled = false; // } // } // else // txtReason.Enabled = false; // } // else // txtReason.Visible = false; // } // } // } // } // } // else // { // //CVH 2017-01-10 TSP If there is no data, and the field is IOD, show the medical aid group and hide the employer group // if (radioButtonList.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryOnDuty") // { // Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); // if (IODGroup != null) // IODGroup.Visible = false; // Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); // if (MedGroup != null) // MedGroup.Visible = true; // UpdatePanel uIODPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); // if (uIODPanel != null) // uIODPanel.Update(); // UpdatePanel uMedPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); // if (uMedPanel != null) // uMedPanel.Update(); // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // if (radioButtonList.AutoPostBack) // SetToggleViewActionVisibilityRadioButtonList(radioButtonList); // radioButtonList.Enabled = enabled; // if (txtReason != null && !radioButtonList.Enabled) txtReason.Enabled = false; // //CVH 2016-12-12 Group default collapse // if (radioButtonList.SelectedItem != null && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Placeholder // case pNums.FieldType.Placeholder: // //no action // break; // #endregion // #region Caption // case pNums.FieldType.Caption: // TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtCaption != null) // { // txtCaption.Text = ""; // txtCaption.Text = fieldItemRow[field.surfaceFieldName].ToString(); // /* CVH 2016-01-20 */ // txtCaption.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtCaption.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: //decimal // TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (txtFormulaBox != null) // { // txtFormulaBox.Text = ""; // //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) // { // decimal sourceValue = 0m; // bool conversionSuccess = false; // //get source field // foreach (oSurfaceField srcField in fieldsQ.Where(p => p.recId.Equals(field.actionSource))) // { // //catering for field types char, number, decimal // if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number || srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // conversionSuccess = decimal.TryParse(fieldItemRow[srcField.surfaceFieldName].ToString(), out sourceValue); // } // if (conversionSuccess) // { // txtFormulaBox.Text = CalculateLookup(field, sourceValue); // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(field.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); // txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // //CVH 2017-02-07 Divide Calculation Formula is saved in Char column // if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) // { // txtFormulaBox.Text = fieldItemRow[field.surfaceFieldName].ToString(); // } // else if (field.actionType == (int)pNums.ActionType.Calculation && field.action != divideAction.recId) // { // foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", field.action.ToString())) // { // if (act.action == "Age") // { // //need to calculate age, it isn't always saved in the age field // //get age source (date of birth) data // DateTime? dob = null; // foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", field.surfaceId + "," + _surfaceItem.recId + "," + field.actionSource)) // { // dob = dobData.surfaceFieldValueDate; // break; // } // if (dob != null) // { // oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); // txtFormulaBox.Text = age.years.ToString(); // txtFormulaBox.Enabled = false; // } // } // break; // } // } // else // { // if (fieldItemRow[field.surfaceFieldName].ToString() != string.Empty) // txtFormulaBox.Text = fieldItemRow[field.surfaceFieldName].ToString(); // } // break; // } // if (field.actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") // { // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // List sicParams = new List(); // oDynamicParam sicParam = new oDynamicParam(); // sicParam.paramDisplayName = "userId"; // sicParam.paramObject = userId; // sicParams.Add(sicParam); // DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); // if (nextCodeTable.Rows.Count > 0) // { // txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); // if (txtFormulaBox.Text == "-1") // txtFormulaBox.Text = ""; // } // else // { // txtFormulaBox.Text = ""; // } // } // //txtFormulaBox.Enabled = enabled; // //CVH 2017-02-07 Divide Calculation Formula field is always read only // if ((field.actionType == (int)pNums.ActionType.Calculation && (field.action == divideAction.recId || field.action == lookupAction.recId)) || // (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId)) // txtFormulaBox.Enabled = false; // else // txtFormulaBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // break; // #endregion // #region Address // case pNums.FieldType.Address: // /* CVH 2016-07-29 Clear address textboxes, in case no data */ // bool found = false; // int itemNoClr = 0; // do // { // found = false; // itemNoClr++; // if (itemNoClr == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr + "dd"); // if (ddSuburb != null) // { // found = true; // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNoClr); // if (txtAddress != null) // { // txtAddress.Text = ""; // found = true; // //JR 2017-02-12 Set default Province for SBF // if (itemNoClr == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // } // } // } while (found && itemNoClr < 50); // int itemNo = 0; // foreach (string addressLine in fieldItemRow[field.surfaceFieldName].ToString().Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // itemNo++; // if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo + "dd"); // if (ddSuburb != null) // { // //CVH 2017-02-27 Clear selection, otherwise get exception when index 0 is selected when binding // ddSuburb.Items.Clear(); // if (SuburbTable.Rows.Count > 0) // { // ddSuburb.DataSource = SuburbTable; // ddSuburb.DataValueField = "display"; // ddSuburb.DataTextField = "display"; // ddSuburb.DataBind(); // } // ddSuburb.Items.Insert(0, new ListItem("Select", "0")); // ddSuburb.SelectedIndex = 0; // //find addressLine.Substring(3) // if (addressLine != String.Empty) // { // if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) // ddSuburb.SelectedValue = addressLine.Substring(3); // } // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + itemNo); // if (txtAddress != null && addressLine != String.Empty && addressLine.Substring(1, 1) == itemNo.ToString()) // { // /* CVH 2016-01-20 */ // txtAddress.Enabled = enabled; // txtAddress.Text = addressLine.Substring(3); // //JR 2017-02-12 Set default Province for SBF // if (itemNo == 4 && // handler.ReturnSetup().code == "STUD-1") // { // txtAddress.Text = "Western Cape"; // txtAddress.Enabled = false; // } // //CVH 2016-12-12 Group default collapse // if (txtAddress.Text != "" && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: //checkboxlist // /* CVH 2016-09-27 Cater for Wants Reason. alternateView does not use wantsReason */ // if (field.alternateView) // { // CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxList != null) // { // checkboxList.SelectedIndex = -1; // if (fieldItemRow[field.surfaceFieldName].ToString() != "") // { // //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly // foreach (string temp in fieldItemRow[field.surfaceFieldName].ToString().Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // } // else // { // lookupId = temp; // } // if (checkboxList.Items.FindByValue(lookupId) != null) // checkboxList.Items.FindByValue(lookupId).Selected = true; // } // } // checkboxList.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (checkboxList.Items.GetSelectedItems().Count() > 0 && !groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // else // { // Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (checkboxPanel != null) // { // //CVH 2016-10-11 Clear checked items // foreach (Control lblClear in checkboxPanel.Controls) // { // if (lblClear != null && lblClear.Controls.Count > 0) // { // Control ctrlClear = lblClear.Controls[0]; // if (ctrlClear.GetType() == typeof(CheckBox)) // { // CheckBox chkClear = (CheckBox)ctrlClear; // chkClear.Checked = false; // TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); // if (txtClear != null) // { // txtClear.Text = ""; // txtClear.Enabled = false; // } // } // } // } // if (fieldItemRow[field.surfaceFieldName].ToString() != "") // { // foreach (string temp in fieldItemRow[field.surfaceFieldName].ToString().Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // string lookupId = ""; // string reason = ""; // if (temp.IndexOf("~R~") >= 0) // { // lookupId = temp.Substring(0, temp.IndexOf("~R~")); // reason = temp.Substring(temp.IndexOf("~R~") + 3); // } // else // { // lookupId = temp; // } // foreach (Control lblWrapper in checkboxPanel.Controls) // { // CheckBox chk = (CheckBox)lblWrapper.FindControl(field.surfaceFieldName + "_" + lookupId); // //CheckBox chk = (CheckBox)checkboxPanel.FindControl(field.surfaceFieldName + "_" + lookupId); // if (chk != null) // { // chk.Checked = true; // //try to find textbox for wants reason // TextBox txtChkReason = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); // if (txtChkReason != null) // { // txtChkReason.Text = reason; // txtChkReason.Enabled = true; // } // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // } // } // } // //CVH 2016-10-11 Toggle View Action: If checkedchanged event is linked to checkboxlist, call method to set controls Visible=false/true depending on checked state // foreach (Control ctrlToggle in checkboxPanel.Controls) // { // if (ctrlToggle.GetType() == typeof(CheckBox)) // { // CheckBox chkToggle = (CheckBox)ctrlToggle; // if (chkToggle.AutoPostBack) // SetToggleViewActionVisibilityCheckboxList(chkToggle); // } // } // checkboxPanel.Enabled = enabled; // } // } // break; // #endregion // #region RelationalField // case pNums.FieldType.RelationalField: // foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", field.relationalFields.ToString())) // { // if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) // { // ArrayList FieldDataList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _surfaceItem.surfaceId + "," + field.recId + "," + _surfaceItem.recId); // SetSurfaceControlState(_surfaceItem, FieldDataList, field, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // ArrayList FieldDataListC = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _surfaceItem.surfaceId + "," + field.recId + "," + _surfaceItem.recId); // SetSurfaceControlState(_surfaceItem, FieldDataListC, field); // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // break; // #endregion // #region Button // case pNums.FieldType.Button: // Button btn = (Button)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (btn != null) // { // if (field.surfaceFieldName == "PatientProfile_PatientStatus") // { // foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) // { // if (visitLog.signOutDate.Year > 1900) // { // btn.Text = "Status: In Progress"; // btn.AddCssClass("btn-success"); // btn.RemoveCssClass("btn-warning"); // btn.RemoveCssClass("btn-danger"); // } // else // { // btn.Text = "Status: Pending"; // btn.AddCssClass("btn-warning"); // btn.RemoveCssClass("btn-success"); // btn.RemoveCssClass("btn-danger"); // } // break; // } // } // //CVH 2016-12-12 Don't add parent Id for group collapse, if set to default collapse can remain collapsed even with data loaded // } // break; // #endregion // #region Image // case pNums.FieldType.Image: // HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); // if (imageDiv != null) // { // string imageUrl = "/images/placeholder.png"; // if (fieldItemRow[field.surfaceFieldName].ToString() != "") // { // imageUrl = "/upload/surface/" + fieldItemRow[field.surfaceFieldName].ToString(); // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + field.parentId + "|")) // groupIdsWithData += "|" + field.parentId + "|"; // } // imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); // } // break; // #endregion // } // } // } // } // } // BindSurfaceAttachments(_surfaceItem.recId, false); // BindSurfaceNotes(_surfaceItem.recId, false); // ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; // //CVH 2017-01-10 Only register script when not page load, otherwise javascript error method not defined that breaks other javascript // if (Page.IsPostBack) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroupsPopulate", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); // //handle last // if (base.SurfaceApp.isWizzard) // { // //GR added check now to see if wizard completed // if (base.SurfaceAppItem != null) // { // wizardcompleted = base.SurfaceAppItem.isWizardCompleted; // } // if (!wizardcompleted && (usr.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) // //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) // ArrayList fieldTabs1 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // pnlWizzardButtons.Visible = true; // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // SetLastTabUsed(fieldTabs1); // } // else // { // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // ArrayList fieldTabs2 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // MaintainActiveTab(fieldTabs2); // SetTabsVisible(fieldTabs2); // //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one // if ((setup.code == "SHOU-1" || setup.code == "GLOB-1") && usr.userType >= (int)pNums.UserType.PowerUser && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null) // { // int tabIndex = 0; // foreach (oSurfaceField tab in fieldTabs2) // { // tabIndex++; // if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) // break; // } // if (tabIndex > 0) // { // //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; // //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; // HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; // //GR 2017-03-18 set hidden tab index for inital page load // if (!Page.IsPostBack) // { // hfTabIndex.Value = (tabIndex - 1).ToString(); // } // else // hfTabIndex.Value = ""; // } // } // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) // { // pnlFormButtons.Visible = false; // pnlFormButtonsSingleItem.Visible = true; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = false; // lnkRefresh.Visible = false; lnkBack.Visible = false; // btnSaveSingle.ValidationGroup = ""; // btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // btnSave.ValidationGroup = ""; // btnSaveAndNew.ValidationGroup = ""; // btnSaveBack.ValidationGroup = ""; // btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; // } // } // } // else // { // pnlFormButtons.Visible = true; // pnlFormButtonsSingleItem.Visible = false; // pnlWizzardButtons.Visible = false; // lnkSave.Visible = true; // lnkRefresh.Visible = true; lnkBack.Visible = true; // //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 // //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) // ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); // SetTabsVisibleNoWizard(fieldTabs, false); // } // SetCustomVisible(); // PerformCustomPopulateAddOn(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} #endregion //CVH 2017-03-17 Reverting to pre-2017-03-13 private void SetSurfaceControlState(oSurfaceItem _surfaceItem, ArrayList surfaceFieldData, oSurfaceField field, oSurfaceField relatedField = null) { string fieldName = field.surfaceFieldName; string controlledValue = field.controlledValue; bool altView = field.alternateView; int fieldRecId = field.recId; bool isControlled = field.isControlled; if (relatedField != null) { controlledValue = relatedField.controlledValue; fieldRecId = relatedField.recId; } string controlType = string.Empty; string controlPath = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", controlledValue)) { controlType = module.module; controlPath = module.control; controlName = module.objectName + fieldName; } oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); if (surfaceFieldData != null && surfaceFieldData.Count > 0 && !base.IsClone) { ArrayList fieldData = new ArrayList(surfaceFieldData.Cast() .Where(d => d.surfaceFieldID == fieldRecId) .ToList()); foreach (oSurfaceFieldData data in fieldData) { if (fieldRecId == data.surfaceFieldID) { controlFieldData = data; } } } if (controlFieldData.surfaceFieldID == 0 || base.IsClone) //set default values if populating blank form { controlFieldData.surfaceFieldID = fieldRecId; controlFieldData.surfaceItemId = _surfaceItem.recId; controlFieldData.surfaceId = _surfaceItem.surfaceId; } switch (controlType) { case "BodyMap": string bodyPartList = controlFieldData.surfaceFieldValueChar; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); break; case "Surface Notes": dynamic surfaceControl = this.FindControl(controlName); if (surfaceControl != null) { surfaceControl.Confidential = isControlled; surfaceControl.ReloadControl(controlFieldData, altView); } break; default: //find Control and call reloadControl() dynamic moduleControl = this.FindControl(controlName); if (moduleControl != null) { moduleControl.ReloadControl(controlFieldData, altView); } break; } } private void SetSurfaceControlState(oSurfaceItem _surfaceItem, EnumerableRowCollection fieldDataTableEnum, DataRow fieldRow, oSurfaceField relatedField = null) { string fieldName = fieldRow["surfaceFieldName"].ToString(); string controlledValue = fieldRow["controlledValue"].ToString(); bool isControlled = false; bool.TryParse(fieldRow["isControlled"].ToString(), out isControlled); bool altView = false; bool.TryParse(fieldRow["alternateView"].ToString(), out altView); int fieldRecId = int.Parse(fieldRow["recId"].ToString()); if (relatedField != null) { controlledValue = relatedField.controlledValue; fieldRecId = relatedField.recId; } string controlType = string.Empty; string controlPath = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", controlledValue)) { controlType = module.module; controlPath = module.control; controlName = module.objectName + fieldName; } oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); var ctlData = from ctrls in fieldDataTableEnum where ctrls.Field("surfaceFieldID").Equals(fieldRecId) select ctrls; if (ctlData.Count() > 0) { foreach (DataRow ctrlDataRow in ctlData.ToList()) { controlFieldData.surfaceFieldID = int.Parse(ctrlDataRow["surfaceFieldID"].ToString()); controlFieldData.surfaceItemId = int.Parse(ctrlDataRow["surfaceItemId"].ToString()); controlFieldData.surfaceId = int.Parse(ctrlDataRow["surfaceId"].ToString()); controlFieldData.surfaceFieldValueDate = DateTime.Parse(ctrlDataRow["surfaceFieldValueDate"].ToString()); controlFieldData.surfaceFieldValueDecimal = decimal.Parse(ctrlDataRow["surfaceFieldValueDecimal"].ToString()); controlFieldData.surfaceFieldValueChar = ctrlDataRow["surfaceFieldValueChar"].ToString(); controlFieldData.surfaceFieldValueNum = int.Parse(ctrlDataRow["surfaceFieldValueNum"].ToString()); controlFieldData.surfaceFieldValueBool = bool.Parse(ctrlDataRow["surfaceFieldValueBool"].ToString()); controlFieldData.surfaceFieldValueTime = DateTime.Parse(ctrlDataRow["surfaceFieldValueTime"].ToString()); controlFieldData.surfaceFieldLookupID = int.Parse(ctrlDataRow["surfaceFieldLookupID"].ToString()); } } if (controlFieldData.surfaceFieldID == 0 || base.IsClone) //set default values if populating blank form { controlFieldData.surfaceFieldID = fieldRecId; controlFieldData.surfaceItemId = _surfaceItem.recId; controlFieldData.surfaceId = _surfaceItem.surfaceId; } switch (controlType) { case "BodyMap": string bodyPartList = controlFieldData.surfaceFieldValueChar; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); break; case "Surface Notes": dynamic surfaceControl = this.FindControl(controlName); if (surfaceControl != null) { surfaceControl.Confidential = isControlled; surfaceControl.ReloadControl(controlFieldData, altView); } break; default: dynamic noteControl = this.FindControl(controlName); if (noteControl != null) { noteControl.ReloadControl(controlFieldData, altView); } break; } } private void SetSurfaceControlState(oSurfaceItem _surfaceItem, DataRow fieldRow, oSurfaceField relatedField = null) { string fieldName = fieldRow["surfaceFieldName"].ToString(); string controlledValue = fieldRow["controlledValue"].ToString(); bool isControlled = false; bool.TryParse(fieldRow["isControlled"].ToString(), out isControlled); bool altView = false; bool.TryParse(fieldRow["alternateView"].ToString(), out altView); int fieldRecId = int.Parse(fieldRow["recId"].ToString()); if (relatedField != null) { controlledValue = relatedField.controlledValue; fieldRecId = relatedField.recId; } string controlType = string.Empty; string controlPath = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", controlledValue)) { controlType = module.module; controlPath = module.control; controlName = module.objectName + fieldName; } oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); controlFieldData.surfaceFieldID = fieldRecId; controlFieldData.surfaceItemId = _surfaceItem.recId; controlFieldData.surfaceId = _surfaceItem.surfaceId; switch (controlType) { case "BodyMap": string bodyPartList = controlFieldData.surfaceFieldValueChar; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); break; case "Surface Notes": dynamic surfaceControl = this.FindControl(controlName); if (surfaceControl != null) { surfaceControl.Confidential = isControlled; surfaceControl.ReloadControl(controlFieldData, altView); } break; default: dynamic noteControl = this.FindControl(controlName); if (noteControl != null) { noteControl.ReloadControl(controlFieldData, altView); } break; } } /// /// Bind the Users to Link /// private void BindUsersToLink() { try { DataTable userData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oUser), "isActive,userType,customerCode", "1," + ((int)pNums.UserType.WebsiteUser).ToString() + "," + handler.ReturnSetup().code.ToString() + "", "name", "pal_", true); ddUserLink.DataSource = userData; ddUserLink.DataTextField = "email"; ddUserLink.DataValueField = "recId"; ddUserLink.DataBind(); ddUserLink.Items.Insert(0, new ListItem("none", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit The Surface /// /// private void EditSurface(int itemId, RepeaterItem rptItem) { try { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; base.ActiveTabPanel = String.Empty; pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), base.SurfaceAppGridEditTypeId); switch (editType) { case pNums.SurfaceGridEditType.Form: Session["surfaceAppItem"] = base.SurfaceAppItem; //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(item, false); } else { PopulateSurfaceForm(item, false); } SetPatientType("PatientType_PatientType_PatientType"); //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); break; case pNums.SurfaceGridEditType.Row: if (rptItem != null) { ToggleRowEdit(itemId, item, true, rptItem); if (rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } } break; /* CVH 2016-02-02 Batch edit mode */ case pNums.SurfaceGridEditType.Batch: if (rptItem != null) { ToggleGridEdit(true, (Repeater)rptItem.Parent, itemId, item.surfaceId); } break; default: //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(item, false); } else { PopulateSurfaceForm(item, false); } //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); SetPatientType("PatientType_PatientType_PatientType"); TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); break; } break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void CloneSurface(int itemId) { try { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.IsClone = true; pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), base.SurfaceAppGridEditTypeId); //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(item, false); } else { PopulateSurfaceForm(item, false); } //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); SetPatientType("PatientType_PatientType_PatientType"); TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Update Surface Action Fields - eg Aggregation Sum, needs to be updated after child data has been saved /// private void UpdateSurfaceActionFields(oSurfaceItem _surfaceItem) { try { //only grid fields, non grid fields will populate correctly on load foreach (oSurfaceField actField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,isGrid,actionType", _surfaceItem.surfaceId + ",1,1," + pNums.ActionType.Aggregation.GetHashCode())) { //sum is only action linked to Aggregation action type, so assume this is sum for now //get specific field data record and update, shouldn't be too resource intense, currently only 1 field foreach (oSurfaceFieldData actData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _surfaceItem.surfaceId + "," + actField.recId + "," + _surfaceItem.recId)) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), actField.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Number: int actionSurfaceIdNum = 0; if (int.TryParse(actField.actionValue, out actionSurfaceIdNum)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceIdNum, actField.actionSource, _surfaceItem.recId); int intTemp = 0; if (!int.TryParse(Math.Truncate(decFormula).ToString(), out intTemp)) intTemp = 0; actData.surfaceFieldValueNum = intTemp; TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(actField.surfaceFieldName); if (txtNumberBox != null) txtNumberBox.Text = intTemp.ToString(); } break; case pNums.FieldType.Decimal: case pNums.FieldType.FormulaField: int actionSurfaceId = 0; if (int.TryParse(actField.actionValue, out actionSurfaceId)) { actData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, actField.actionSource, _surfaceItem.recId); TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(actField.surfaceFieldName); if (txtDecimalBox != null) txtDecimalBox.Text = utils.returnFormattedDecimal(actData.surfaceFieldValueDecimal.ToString()); } break; } xData.UpdateTyped("recId", actData.recId.ToString(), typeof(oSurfaceFieldData), actData); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface form /// private bool SaveSurfaceForm(ref oSurfaceItem _surfaceItem, ref ArrayList surfaceData, ref bool createParentSurfaceItem) { try { //handle any custom save add on code PerformCustomSaveAddOn(_surfaceItem); oUser user = handler.ReturnUser(); //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", _surfaceItem.surfaceId + "", "sequence"); DataTable surfaceFieldData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId, "recId"); DataTable myDataTable = new DataTable(); myDataTable = surfaceFieldData.Clone(); //CVH 2017-02-07 Determine Divide Action to be used in formula field oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction lookupFieldAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) { if (act.actionType == (int)pNums.ActionType.Calculation) { if (act.action == "Divide") divideAction = act; else if (act.action == "Lookup") lookupAction = act; else if (act.action == "Lookup Field") lookupFieldAction = act; } else if (act.actionType == (int)pNums.ActionType.Aggregation) { if (act.action == "Sum") aggrSumAction = act; } } //TSP string firstName = "", surname = "", email = "", patientNumber = "", contactNumber = "", registrationDate = ""; foreach (oSurfaceField field in surfaceFields) { if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab && field.surfaceFieldTypeId != (int)pNums.FieldType.Group && field.isActive) { oSurfaceFieldData fieldData = new oSurfaceFieldData(); myDataTable.Clear(); //get the data for this field ID var v = from enVal in surfaceFieldData.AsEnumerable() where (enVal.Field("surfaceFieldID") == field.recId) select enVal; v.CopyToDataTable(myDataTable, LoadOption.OverwriteChanges); foreach (oSurfaceFieldData fd in utils.ConvertDataTableToList(myDataTable, typeof(oSurfaceFieldData))) { fieldData = fd; break; } fieldData.surfaceFieldID = field.recId; fieldData.surfaceId = _surfaceItem.surfaceId; fieldData.surfaceItemId = _surfaceItem.recId; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { #region Text case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtTextbox != null) { if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupFieldAction.recId) { string unsavedItemValueToMatch = ""; //if item is not yet saved, get value to match from form control. cater for picklist & textbox for now if (_surfaceItem.recId == 0) { foreach (oSurfaceField valueField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", field.actionSource.ToString())) { if (valueField.surfaceFieldTypeId == pNums.FieldType.Text.GetHashCode()) { TextBox txtValue = (TextBox)pnlSurfaceForm.FindControl(valueField.surfaceFieldName); if (txtValue != null) unsavedItemValueToMatch = txtValue.Text; } else if (valueField.surfaceFieldTypeId == pNums.FieldType.Picklist.GetHashCode()) { DropDownList ddValue = (DropDownList)pnlSurfaceForm.FindControl(valueField.surfaceFieldName); if (ddValue != null && ddValue.SelectedItem != null && ddValue.SelectedItem.Value != "0") unsavedItemValueToMatch = ddValue.SelectedItem.Text; } } } List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = field.recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = _surfaceItem.recId; listLookup.Add(look2); oDynamicParam look3 = new oDynamicParam(); look3.paramDisplayName = "unsavedItemValueToMatch"; look3.paramObject = unsavedItemValueToMatch; listLookup.Add(look3); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) { txtTextbox.Text = dtValue.Rows[0][0].ToString(); fieldData.surfaceFieldValueChar = txtTextbox.Text; } else { txtTextbox.Text = ""; fieldData.surfaceFieldValueChar = ""; } } else { if (field.isUnique)//check for unique { string textToCheck = txtTextbox.Text; //CVH 2017-01-12 Only check for duplicate if the item is active (not draft) otherwise initial save to copy master data fails and screen doesn't complete loading if (_surfaceItem.isActive && IsDuplicate(fieldData.surfaceItemId, field, textToCheck)) return false; } fieldData.surfaceFieldValueChar = txtTextbox.Text; //TSP - JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_FirstNames") firstName = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_Surname") surname = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_EmailAddress") email = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_MobileNumber") contactNumber = txtTextbox.Text; } } break; #endregion #region Number case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtNumberBox != null) { if (field.surfaceFieldName != "ParentSurfaceItemId") { //CVH 2017-02-24 New action type Aggregation Sum if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); int intTemp = 0; if (!int.TryParse(Math.Truncate(decFormula).ToString(), out intTemp)) intTemp = 0; fieldData.surfaceFieldValueNum = intTemp; } } else { if (field.isUnique)//check for unique { string textToCheck = txtNumberBox.Text; if (IsDuplicate(fieldData.surfaceItemId, field, textToCheck, true)) return false; } int valueNum = 0; int.TryParse(txtNumberBox.Text, out valueNum); if (field.isControlled && fieldData.surfaceFieldValueNum != valueNum)// && valueNum >= Convert.ToInt32(field.controlledValue)) { int nextNumber = 0; int.TryParse(field.controlledValue, out nextNumber); nextNumber++; field.controlledValue = nextNumber.ToString(); xData.UpdateTyped("recId", field.recId.ToString(), typeof(oSurfaceField), field); fieldData.surfaceFieldValueNum = nextNumber; txtNumberBox.Text = nextNumber.ToString(); } else fieldData.surfaceFieldValueNum = valueNum; //TSP - JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_PatientNumber") patientNumber = valueNum.ToString(); } } /* CVH 2016-07-22 If this surface is a grid on a parent surface, create a new surface item and save in viewstate */ else if (field.surfaceFieldName == "ParentSurfaceItemId") { if (_surfaceItem.recId <= 0) //only on new save, not update { //if no parent surface item has been created yet, save item only, //will bubble event to parent surface control to save surface data after //child item and data has been created int parentSurfaceItemId = 0; //CVH 2016-10-19 Only create parent if surface is currently on parent surface, otherwise save parentSurfaceItemId = 0 if (base.ParentSurfaceItemId == 0 && base.IsChildSurface) { if (base.IsChildSurface && base.ParentSurfaceId == 0) throw new Exception("The parent surface Id for the child surface " + base.SurfaceApp.name + " is 0."); int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; oSurfaceItem parentItem = new oSurfaceItem(); parentItem.createdBy = userId; parentItem.dateCreated = DateTime.Now; //always set parent as not active. when saving the parent item it will override this setting parentItem.isActive = false; parentItem.isDeleted = false; parentItem.surfaceId = base.ParentSurfaceId; parentItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), parentItem); parentSurfaceItemId = parentItem.recId; base.ParentSurfaceItemId = parentSurfaceItemId; createParentSurfaceItem = true; } else { parentSurfaceItemId = base.ParentSurfaceItemId; } fieldData.surfaceFieldValueNum = parentSurfaceItemId; } } } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtDecimalBox != null) { if (handler.ReturnSetup().code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) { //leave decimal textbox blank if item ID = 0 if (base.SurfaceAppItemId != 0) { //CVH 2017-03-08 Calculate Portion as: SUM(Primary Caregiver Portion) + SUM(Household Members Portion) List listPortion = new List(); oDynamicParam por1 = new oDynamicParam(); por1.paramDisplayName = "surfaceId"; por1.paramObject = _surfaceItem.surfaceId; listPortion.Add(por1); oDynamicParam por2 = new oDynamicParam(); por2.paramDisplayName = "surfaceItemId"; por2.paramObject = base.SurfaceAppItemId; listPortion.Add(por2); oDynamicParam por3 = new oDynamicParam(); por3.paramDisplayName = "option"; por3.paramObject = field.surfaceFieldDisplay.Contains("Primary") ? "Primary" : field.surfaceFieldDisplay.Contains("Member") ? "Member" : ""; listPortion.Add(por3); DataTable dtPortion = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculatePortionOfTotalMonthlyIncome", listPortion); decimal valueDecimal = 0; if (dtPortion != null && dtPortion.Rows.Count > 0) { txtDecimalBox.Text = utils.returnFormattedDecimal(dtPortion.Rows[0][0].ToString()); decimal.TryParse(txtDecimalBox.Text, out valueDecimal); } fieldData.surfaceFieldValueDecimal = valueDecimal; } } //CVH 2017-02-24 New action type Aggregation Sum else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { fieldData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); } } else //CVH 2017-02-07 Divide Calculation Formula need to calculate and save it on form save if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) { decimal? source1 = null; decimal? source2 = null; //need to do calculation based on two source fields foreach (oSurfaceField sourceField in surfaceFields) { int src2FieldId = 0; int.TryParse(field.actionValue, out src2FieldId); decimal divideTemp = 0; if (sourceField.recId == field.actionSource) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source1 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source1 = divideTemp; } break; } } else if (src2FieldId > 0 && sourceField.recId == src2FieldId) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source2 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source2 = divideTemp; } break; } } } if (source1 != null && source2 != null && source2 != 0) fieldData.surfaceFieldValueDecimal = (source1.Value / source2.Value); else fieldData.surfaceFieldValueDecimal = 0; } else { decimal valueDecimal = 0; decimal.TryParse(txtDecimalBox.Text, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; } } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { //CVH 2017-05-12 Populate Device Management Users picklist with Profile email addresses if (handler.ReturnSetup().code == "STUD-1" && (base.SurfaceApp.name == "DeviceManagement" || base.SurfaceApp.name.StartsWith("Mentorship")) && field.surfaceFieldName.EndsWith("Email")) { if (ddDropdownlist.SelectedItem != null && ddDropdownlist.SelectedValue != "0") fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedItem.Text; else fieldData.surfaceFieldValueChar = ""; } //CVH 2016-10-21 Also check !="0", relationalObject saves as "0" else if (field.relationalObject.Length > 0 && field.relationalObject != "0")//module picklist or custom source picklist { if (field.relationalObject == "oSurface" && ddDropdownlist.SelectedItem != null) { if (ddDropdownlist.SelectedItem.Value == "0") fieldData.surfaceFieldValueChar = ""; else fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedItem.Text; } else fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedValue.ToString(); } else { int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); fieldData.surfaceFieldLookupID = lookupId; //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } //CVH 2017-05-25 SBF Default Profiles Status to "Applicant" if none selected if (base.SurfaceApp.name == "Profiles" && field.surfaceFieldName.EndsWith("_Status") && lookupId == 0) { if (ddDropdownlist.Items.FindByText("Applicant") != null) { if (int.TryParse(ddDropdownlist.Items.FindByText("Applicant").Value, out lookupId)) fieldData.surfaceFieldLookupID = lookupId; } } TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); if (txtReason != null) fieldData.surfaceFieldValueChar = txtReason.Text; } } break; #endregion #region MultiPicklist case pNums.FieldType.MultiPicklist: //MultiPicklist ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (listBox != null) { string lbSelectedValues = string.Empty; foreach (ListItem item in listBox.Items) { if (item.Selected) { if (lbSelectedValues == String.Empty) lbSelectedValues = item.Value.ToString(); else lbSelectedValues += "," + item.Value; } } fieldData.surfaceFieldValueChar = lbSelectedValues; } break; #endregion #region Date case pNums.FieldType.Date: //date TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtDate != null) { if (txtDate.Text != String.Empty) { if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text + "/01/01"); else fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text); } //TSP JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_RegistrationDate") registrationDate = txtDate.Text; } break; #endregion #region Checkbox case pNums.FieldType.Checkbox: //checkbox CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (chkBox != null) { //TSP JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_EmailSent") { mailSent = chkBox.Checked; chkBox.Checked = true; } fieldData.surfaceFieldValueBool = chkBox.Checked; } break; #endregion #region Grid case pNums.FieldType.Grid: //grid //no action - no data saved, it shows user control of grid surface app break; #endregion #region RadioButtonList case pNums.FieldType.RadioButtonList: //radiobuttonlist //HtmlGenericControl radiodiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName); RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); //DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (radioButtonList != null) { //RadioButton rb = radiodiv.Controls.OfType() // .FirstOrDefault(r => r.Checked); if (field.isCustomSource) { fieldData.surfaceFieldValueChar = radioButtonList.SelectedValue; } else { int rbSelectedID = 0; int.TryParse(radioButtonList.SelectedValue, out rbSelectedID); fieldData.surfaceFieldLookupID = rbSelectedID; TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); if (txtReason != null) fieldData.surfaceFieldValueChar = txtReason.Text; } } break; #endregion #region Placeholder case pNums.FieldType.Placeholder: //no action break; #endregion #region Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtCaption != null) { fieldData.surfaceFieldValueChar = txtCaption.Text; } break; #endregion #region FormulaField case pNums.FieldType.FormulaField: fieldData.surfaceFieldValueChar = ""; TextBox txtFieldBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtFieldBox != null) { //CVH 2017-02-07 Divide Calculation Formula need to calculate and save it on form save if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) { decimal? source1 = null; decimal? source2 = null; //if first source field is decimal, format it as a decimal, otherwise format as int bool divDecimal = false; //need to do calculation based on two source fields foreach (oSurfaceField sourceField in surfaceFields) { int src2FieldId = 0; int.TryParse(field.actionValue, out src2FieldId); decimal divideTemp = 0; if (sourceField.recId == field.actionSource) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source1 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source1 = divideTemp; } break; } if (sourceField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) divDecimal = true; } else if (src2FieldId > 0 && sourceField.recId == src2FieldId) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source2 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source2 = divideTemp; } break; } } } if (source1 != null && source2 != null && source2 != 0) { if (divDecimal) fieldData.surfaceFieldValueChar = utils.returnFormattedDecimal((source1 / source2).ToString()); else fieldData.surfaceFieldValueChar = Decimal.Round((source1.Value / source2.Value), 0).ToString(); txtFieldBox.Text = fieldData.surfaceFieldValueChar; } else { fieldData.surfaceFieldValueChar = ""; } } //CVH 2017-02-13 Lookup Calculation Formula else if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; //get source field foreach (oSurfaceField srcField in surfaceFields) { if (srcField.recId == field.actionSource) { TextBox txtSrc = (TextBox)pnlSurfaceForm.FindControl(srcField.surfaceFieldName); if (txtSrc != null) { conversionSuccess = decimal.TryParse(txtSrc.Text, out sourceValue); } break; } } if (conversionSuccess) { fieldData.surfaceFieldValueChar = CalculateLookup(field, sourceValue); txtFieldBox.Text = fieldData.surfaceFieldValueChar; } } //CVH 2017-02-24 New action type Aggregation Sum else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) fieldData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, _surfaceItem.recId); } else { decimal valueDecimal = 0; if (decimal.TryParse(txtFieldBox.Text, out valueDecimal)) { fieldData.surfaceFieldValueDecimal = valueDecimal; } else //assume textbox { fieldData.surfaceFieldValueChar = txtFieldBox.Text; } if (field.actionType == (int)pNums.ActionType.GenerateCode) { Session["surfaceCodeUsed"] = txtFieldBox.Text; } } } break; #endregion #region Address case pNums.FieldType.Address: TextBox txtAddress1 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "1"); TextBox txtAddress2 = null; DropDownList ddAddress2 = null; if (handler.ReturnSetup().code == "STUD-1") ddAddress2 = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName + "2dd"); else txtAddress2 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "2"); TextBox txtAddress3 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "3"); TextBox txtAddress4 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "4"); TextBox txtAddress5 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "5"); TextBox txtAddress6 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "6"); string addressFull = string.Empty; if (txtAddress1 != null) addressFull += "~1~" + txtAddress1.Text + "~|~"; else addressFull += "~|~"; if (handler.ReturnSetup().code == "STUD-1") { if (ddAddress2 != null) addressFull += "~2~" + ddAddress2.SelectedValue + "~|~"; else addressFull += "~|~"; } else { if (txtAddress2 != null) addressFull += "~2~" + txtAddress2.Text + "~|~"; else addressFull += "~|~"; } if (txtAddress3 != null) addressFull += "~3~" + txtAddress3.Text + "~|~"; else addressFull += "~|~"; if (txtAddress4 != null) addressFull += "~4~" + txtAddress4.Text + "~|~"; else addressFull += "~|~"; if (txtAddress5 != null) { /* CVH 2016-08-15 Default Country field to South Africa for now */ if (txtAddress5.Text == String.Empty) addressFull += "~5~South Africa~|~"; else addressFull += "~5~" + txtAddress5.Text + "~|~"; } else { addressFull += "~|~"; } if (txtAddress6 != null) addressFull += "~6~" + txtAddress6.Text; //remove the last "~|~" if line 4 is empty if (addressFull.Substring(addressFull.Length - 4).Equals("~|~") && addressFull.Length > 4) addressFull = addressFull.Substring(0, addressFull.Length - 4); fieldData.surfaceFieldValueChar = addressFull; break; #endregion #region CheckboxList case pNums.FieldType.CheckboxList: //checkboxlist /* CVH 2016-09-27 Cater for wants reason. alternateView does not use wantsReason */ if (field.alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (checkboxList != null) { string checkedValues = ""; foreach (ListItem item in checkboxList.Items) { if (item.Selected) { //CVH 2016-10-31 Need to save values in the same way as not alternateview, otherwise stored procs don't retrieve data correctly checkedValues += item.Value.ToString() + "~R~~|~"; } } fieldData.surfaceFieldValueChar = checkedValues; } } else { //CVH START 20170317 Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (checkboxPanel != null) { string checkedValues = ""; foreach (Control ctrl in checkboxPanel.Controls) { if (ctrl.GetType() == typeof(CheckBox)) { CheckBox chk = (CheckBox)ctrl; if (chk.Checked) { string chkVal = ""; string chkReason = ""; if (chk.ID.LastIndexOf("_") > 0) { chkVal = chk.ID.Substring(chk.ID.LastIndexOf("_") + 1); //get reason TextBox txt = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); if (txt != null) chkReason += txt.Text; } checkedValues += chkVal + "~R~" + chkReason + "~|~"; } else { checkedValues += "~R~~|~"; } } } fieldData.surfaceFieldValueChar = checkedValues; } //CVH END 20170317 } break; #endregion #region Image case pNums.FieldType.Image: RadAsyncUpload radImageUpload = (RadAsyncUpload)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (radImageUpload != null) { int surfaceItemId = fieldData.surfaceItemId; if (radImageUpload.UploadedFiles.Count > 0) { foreach (UploadedFile file in radImageUpload.UploadedFiles) { string ext = radImageUpload.UploadedFiles[0].GetExtension(); string newfilename = Guid.NewGuid().ToString() + ext; //upload file string tempPath = Server.MapPath("~/upload/temp/") + newfilename; string destDir = Server.MapPath("~/upload/surface/" + surfaceItemId.ToString() + "/"); utils.validateFolder(Server.MapPath("~/upload/temp/")); utils.validateFolder(destDir); //upload file fieldData.surfaceFieldValueChar = surfaceItemId.ToString() + "/" + newfilename; file.SaveAs(tempPath); //resize the file utils.ResizeImageMaxWidth(tempPath, destDir, newfilename, true, true, 800); if (surfaceItemId == 0)//put new image paths in session to move after surfaceitem save - cause we need the id { if (utils.verifySession("SurfaceItemImagesNotLinked")) Session["SurfaceItemImagesNotLinked"] += ";" + destDir.TrimEnd('/') + "|" + newfilename + "|" + fieldData.surfaceFieldID; else Session["SurfaceItemImagesNotLinked"] = destDir.TrimEnd('/') + "|" + newfilename + "|" + fieldData.surfaceFieldID; } else { //CVH 2016-11-18 Show updated image (otherwise previous image loads) HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "Div"); if (imageDiv != null) { string imageUrl = "/upload/surface/" + surfaceItemId.ToString() + "/" + newfilename; imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } } } } } break; #endregion #region Control case pNums.FieldType.Control: string controlType = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", field.controlledValue)) { controlType = module.module; controlName = module.objectName + field.surfaceFieldName; } switch (controlType) { case "BodyMap": string itemId = fieldData.surfaceItemId.ToString(); string fieldId = fieldData.surfaceFieldID.ToString(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "formSaveClick", "formSaveClick(" + itemId + "," + fieldId + ");", true); break; default: //find module Control and call saveControlData() dynamic moduleControl = this.FindControl(controlName); if (moduleControl != null) { moduleControl.SaveControlData(ref fieldData); } break; } break; #endregion } surfaceData.Add(fieldData); } } //using global user //if (utils.verifySession("user")) //{ // oUser user = (oUser)Session["user"]; if (user.userType == (int)pNums.UserType.WebsiteUser && handler.ReturnSetup().code == "SHOU-1" && !mailSent && email != string.Empty) { mailSent = SendRegistrationEmail(firstName, surname, email, patientNumber, contactNumber, registrationDate); } //} if (base.SurfaceApp.linkUser) { if (user.userType == (int)pNums.UserType.WebsiteUser) _surfaceItem.userLink = user.recId; //else //{ // if (ddUserLink.SelectedValue != "0") // { // _surfaceItem.userLink = Convert.ToInt32(ddUserLink.SelectedValue.ToString()); // } //} } return true; } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); return false; } } private bool SaveBulkUpdate(oSurfaceItem _surfaceItem, ArrayList bulkFields, ref ArrayList surfaceData) { try { DataTable surfaceFieldData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId, "recId"); DataTable myDataTable = new DataTable(); myDataTable = surfaceFieldData.Clone(); foreach (oSurfaceField bulkField in bulkFields) { if (bulkField.surfaceFieldTypeId != pNums.FieldType.Tab.GetHashCode() && bulkField.surfaceFieldTypeId != pNums.FieldType.Group.GetHashCode()) { oSurfaceFieldData fieldData = new oSurfaceFieldData(); myDataTable.Clear(); //get the data for this field ID var v = from enVal in surfaceFieldData.AsEnumerable() where (enVal.Field("surfaceFieldID") == bulkField.recId) select enVal; v.CopyToDataTable(myDataTable, LoadOption.OverwriteChanges); foreach (oSurfaceFieldData fd in utils.ConvertDataTableToList(myDataTable, typeof(oSurfaceFieldData))) { fieldData = fd; break; } fieldData.surfaceFieldID = bulkField.recId; fieldData.surfaceId = _surfaceItem.surfaceId; fieldData.surfaceItemId = _surfaceItem.recId; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), bulkField.surfaceFieldTypeId); switch (typ) { #region Number case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtNumberBox != null) { if (bulkField.surfaceFieldName != "ParentSurfaceItemId") { int valueNum = 0; int.TryParse(txtNumberBox.Text, out valueNum); fieldData.surfaceFieldValueNum = valueNum; } } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtDecimalBox != null) { decimal valueDecimal = 0; decimal.TryParse(txtDecimalBox.Text, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (ddDropdownlist != null) { if (bulkField.relationalObject.Length > 0 && bulkField.relationalObject != "0")//module picklist { if (bulkField.relationalObject == "oSurface" && ddDropdownlist.SelectedItem != null) fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedItem.Text; else fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedValue.ToString(); } else { int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); fieldData.surfaceFieldLookupID = lookupId; //no wants reason included for now, not required } } break; #endregion #region Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtCaption != null) { fieldData.surfaceFieldValueChar = txtCaption.Text; } break; #endregion } surfaceData.Add(fieldData); } } return true; } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); return false; } } /// /// Check for existing unique values /// /// /// private bool IsDuplicate(int surfaceItemId, oSurfaceField field, string textToCheck, bool isNum = false) { foreach (oSurfaceFieldData dataItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceFieldId,surfaceItemId", field.recId.ToString() + ",~<>" + surfaceItemId.ToString())) { if (isNum) { if (dataItem.surfaceFieldValueNum.ToString() == textToCheck) { lblResult.Text = field.surfaceFieldDisplay + " is not unique."; pnlResult.Visible = true; return true; } } else { if (dataItem.surfaceFieldValueChar.ToLower() == textToCheck.ToLower()) { lblResult.Text = field.surfaceFieldDisplay + " is not unique."; pnlResult.Visible = true; return true; } } } return false; } /// /// TSP - Method to send patient registration email. /// /// /// /// /// /// /// /// private bool SendRegistrationEmail(string firstName, string surname, string email, string patientNumber, string contactNumber, string registrationDate) { //use template to get body string emailBody = string.Empty, emailSubject = string.Empty; oEmail mail = new oEmail(); bool emailSent = false; foreach (oTemplate registrationTemplate in xData.GetTypedByCriteriaSpecific("recId", typeof(oTemplate), "templateTypeId", ((int)pNums.TemplateType.InternalResponse).ToString())) { if (registrationTemplate.templateName.ToLower() == "patient registration notification") { emailBody = registrationTemplate.templateContent; emailSubject = registrationTemplate.templateName; break; } } emailBody = emailBody.Replace("{FirstName}", firstName); emailBody = emailBody.Replace("{Surname}", surname); emailBody = emailBody.Replace("{Email}", email); emailBody = emailBody.Replace("{PatientNumber}", patientNumber); emailBody = emailBody.Replace("{ContactNumber}", contactNumber); emailBody = emailBody.Replace("{RegistrationDate}", registrationDate); emailBody = emailBody.Replace("{WebAddress}", ConfigurationManager.AppSettings["WebAddy"]); oSetup setup = handler.ReturnSetup(); mail.fromAddress = ConfigurationManager.AppSettings["from"]; mail.bccAddress = ConfigurationManager.AppSettings["bcc"]; mail.toAddress = ConfigurationManager.AppSettings["admin"]; mail.Body = emailBody; emailSent = communication.SendAnEmail(mail); return emailSent; } private void ToggleHeadingButtonVisibility(bool show, LinkButton btn) { try { /* CVH 2016-08-31 Need to toggle visibility of Add New button. Should only be visible on Grid. Can't use noShow, it will break GridSurfaceOptions */ string classname = "noShowSurfaceAdd"; if (show) { //show Add New - remove class noShow btn.CssClass = String.Join(" ", btn .CssClass .Split(' ') .Except(new string[] { "", classname }) .ToArray() ); } else { //hide Add New - add class noShow btn.CssClass = String.Join(" ", btn .CssClass .Split(' ') .Except(new string[] { "", classname }) .Concat(new string[] { classname }) .ToArray() ); } } catch { } } /// /// Method to Toggle Panels /// /// private void TogglePanels(string panelName) { switch (panelName) { case "pnlSurfaceForm": ToggleHeadingButtonVisibility(false, btnNew); pnlSurfaceForm.Visible = true; break; } upHeading.Update(); //clear result pnlResult.Visible = false; } /// /// Set all rows in grid to edit mode true/false /// /// /// AUTHOR: Charlene van Heerden /// DATE WRITTEN: 1 February 2016 /// private void ToggleGridEdit(bool editMode, Repeater rptEdit, int itemID, int surfaceId) { try { ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString(), "sequence"); //change edit + delete column headings HtmlTableCell thEdit = (HtmlTableCell)rptEdit.Controls[0].Controls[0].FindControl("thEdit"); HtmlTableCell thRemove = (HtmlTableCell)rptEdit.Controls[0].Controls[0].FindControl("thRemove"); if (editMode) { if (thEdit != null) thEdit.InnerText = "Save"; if (thRemove != null) thRemove.InnerText = "Cancel"; } else { if (thEdit != null) thEdit.InnerText = "Edit"; if (thRemove != null) thRemove.InnerText = "Delete"; } foreach (RepeaterItem repeaterItem in rptEdit.Items) { LinkButton lnkEdit = null, lnkSaveRow = null, lnkRemove = null, lnkCancel = null, lnkView = null; lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); lnkSaveRow = (LinkButton)repeaterItem.FindControl("lnkSaveRow"); lnkRemove = (LinkButton)repeaterItem.FindControl("lnkRemove"); lnkCancel = (LinkButton)repeaterItem.FindControl("lnkCancel"); lnkView = (LinkButton)repeaterItem.FindControl("lnkView"); if (editMode) { if (lnkEdit != null) lnkEdit.AddCssClass("noShow"); if (lnkSaveRow != null) lnkSaveRow.RemoveCssClass("noShow"); if (lnkRemove != null) lnkRemove.AddCssClass("noShow"); if (lnkCancel != null) lnkCancel.RemoveCssClass("noShow"); if (lnkView != null) lnkView.AddCssClass("noShow"); } else { if (lnkEdit != null) lnkEdit.RemoveCssClass("noShow"); if (lnkSaveRow != null) lnkSaveRow.AddCssClass("noShow"); if (lnkRemove != null) lnkRemove.RemoveCssClass("noShow"); if (lnkCancel != null) lnkCancel.AddCssClass("noShow"); if (lnkView != null) lnkView.RemoveCssClass("noShow"); } foreach (oSurfaceField field in surfaceFields) { if ((field.isGrid && field.isActive && field.surfaceFieldTypeId != (int)pNums.FieldType.Tab && field.surfaceFieldTypeId != (int)pNums.FieldType.Group && field.surfaceFieldTypeId != (int)pNums.FieldType.HeaderGroup && field.surfaceFieldTypeId != (int)pNums.FieldType.Attachment && field.surfaceFieldTypeId != (int)pNums.FieldType.Button && field.surfaceFieldTypeId != (int)pNums.FieldType.Composite && field.surfaceFieldTypeId != (int)pNums.FieldType.Content && field.surfaceFieldTypeId != (int)pNums.FieldType.Control && field.surfaceFieldTypeId != (int)pNums.FieldType.Debtors && field.surfaceFieldTypeId != (int)pNums.FieldType.FormulaField && field.surfaceFieldTypeId != (int)pNums.FieldType.Grid && field.surfaceFieldTypeId != (int)pNums.FieldType.Label && field.surfaceFieldTypeId != (int)pNums.FieldType.Mediswitch && field.surfaceFieldTypeId != (int)pNums.FieldType.Note && field.surfaceFieldTypeId != (int)pNums.FieldType.Placeholder && field.surfaceFieldTypeId != (int)pNums.FieldType.RelationalField && field.surfaceFieldTypeId != (int)pNums.FieldType.Sales) || field.surfaceFieldName == "ParentSurfaceItemId" ) { Label lbl = (Label)repeaterItem.FindControl("lbl" + field.surfaceFieldName); pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); if (lbl != null) { if (field.isCurrency && lbl.Parent.GetType() == typeof(HtmlGenericControl)) { HtmlGenericControl currencyLabelParent = (HtmlGenericControl)lbl.Parent; if (editMode) { currencyLabelParent.Attributes.Remove("class"); currencyLabelParent.Attributes.Add("class", "input-group noShow"); } else { currencyLabelParent.Attributes.Remove("class"); currencyLabelParent.Attributes.Add("class", "input-group"); } } else { if (editMode) lbl.AddCssClass("noShow"); else lbl.RemoveCssClass("noShow"); } } HtmlTableCell tdCell = (HtmlTableCell)repeaterItem.FindControl("td" + field.surfaceFieldName); if (tdCell != null) { if (editMode) { tdCell.Attributes.Add("class", "noPad"); tdCell.Attributes.Add("onfocus", "setChildFocus(this)"); } else tdCell.Attributes.Remove("class"); } switch (typ) { case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtTextbox != null) { if (editMode) { txtTextbox.RemoveCssClass("noShow"); } else { txtTextbox.AddCssClass("noShow"); } } break; case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtNumberBox != null) { if (editMode) { txtNumberBox.RemoveCssClass("noShow"); } else { txtNumberBox.AddCssClass("noShow"); } } break; case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtDecimalBox != null) { if (field.isCurrency && txtDecimalBox.Parent.GetType() == typeof(HtmlGenericControl)) { HtmlGenericControl decimalParent = (HtmlGenericControl)txtDecimalBox.Parent; if (decimalParent != null) { if (editMode) { decimalParent.Attributes.Remove("class"); decimalParent.Attributes.Add("class", "input-group"); } else { decimalParent.Attributes.Remove("class"); decimalParent.Attributes.Add("class", "input-group noShow"); } } } else { if (editMode) { txtDecimalBox.RemoveCssClass("noShow"); } else { txtDecimalBox.AddCssClass("noShow"); } } } break; case pNums.FieldType.Picklist: //picklist //CVH 2017-04-05 Enable wants reason on grid HtmlGenericControl ddlParent = (HtmlGenericControl)repeaterItem.FindControl("div" + field.surfaceFieldName); DropDownList ddl = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); if (ddl != null && ddlParent != null) { if (editMode) { if (ddl.Items.FindByText(lbl.Text) != null) { ddl.ClearSelection(); ddl.Items.FindByText(lbl.Text).Selected = true; } ddlParent.Attributes.Remove("class"); } else { ddlParent.Attributes.Add("class", "noShow"); } } break; case pNums.FieldType.MultiPicklist: ListBox listBox = (ListBox)repeaterItem.FindControl(field.surfaceFieldName); if (listBox != null) { if (editMode) { string selectedItem = lbl.Text; listBox.ClearSelection(); foreach (string item in selectedItem.Split(';')) { foreach (ListItem lst in listBox.Items) { if (lst.Text.Trim() == item.Trim()) lst.Selected = true; } } //listBox.RemoveCssClass("noShow"); listBox.Visible = true; } else { //listBox.AddCssClass("noShow"); listBox.Visible = false; } } break; case pNums.FieldType.Date: //date TextBox txtDate = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtDate != null) { HtmlGenericControl dateParent = (HtmlGenericControl)txtDate.Parent; if (dateParent != null) { if (editMode) { dateParent.Attributes.Remove("class"); dateParent.Attributes.Add("class", "input-group date"); } else { dateParent.Attributes.Remove("class"); dateParent.Attributes.Add("class", "input-group date noShow"); } } } break; case pNums.FieldType.Checkbox: //checkbox if (repeaterItem.FindControl(field.surfaceFieldName).GetType().Name == "CheckBox") { CheckBox chkBox = (CheckBox)repeaterItem.FindControl(field.surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox CheckBox lblchk = (CheckBox)repeaterItem.FindControl("lblchk" + field.surfaceFieldName); if (chkBox != null && lblchk != null) { if (editMode) { lblchk.AddCssClass("noShow"); chkBox.RemoveCssClass("noShow"); } else { lblchk.RemoveCssClass("noShow"); chkBox.AddCssClass("noShow"); } } } else if (repeaterItem.FindControl(field.surfaceFieldName).GetType().Name == "HtmlInputCheckBox") { HtmlInputCheckBox chkBox = (HtmlInputCheckBox)repeaterItem.FindControl(field.surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox HtmlInputCheckBox lblchk = (HtmlInputCheckBox)repeaterItem.FindControl("lblchk" + field.surfaceFieldName); if (chkBox != null && lblchk != null) { if (editMode) { lblchk.Attributes.Add("class", "noShow"); chkBox.Attributes.Remove("class"); } else { chkBox.Attributes.Add("class", "noShow"); lblchk.Attributes.Remove("class"); } } } break; case pNums.FieldType.Grid: //grid //no action - no data is saved in grid field type break; case pNums.FieldType.Placeholder: //no action break; case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtCaption != null) { if (editMode) { txtCaption.RemoveCssClass("noShow"); } else { txtCaption.AddCssClass("noShow"); } } break; case pNums.FieldType.RelationalField: if (lbl != null) lbl.RemoveCssClass("noShow"); break; case pNums.FieldType.RadioButtonList: //radiobuttonlist //CVH 2017-04-05 Enable radiobuttonlist on grid, built as dropdown HtmlGenericControl rblParent = (HtmlGenericControl)repeaterItem.FindControl("div" + field.surfaceFieldName); DropDownList rblddl = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); if (rblddl != null && rblParent != null) { if (editMode) { if (rblddl.Items.FindByText(lbl.Text) != null) { rblddl.ClearSelection(); rblddl.Items.FindByText(lbl.Text).Selected = true; } rblParent.Attributes.Remove("class"); } else { rblParent.Attributes.Add("class", "noShow"); } } break; } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Toggle Rows to Edit Mode /// private void ToggleRowEdit(int itemId, oSurfaceItem item, bool editMode, RepeaterItem rptItem) { try { ArrayList surfaceDataList = new ArrayList(); LinkButton lnkEdit = (LinkButton)rptItem.FindControl("lnkEdit"); if (int.Parse((lnkEdit).CommandArgument) == itemId) { SetRowMode(rptItem, item, editMode, ref surfaceDataList); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Set Row Mode /// /// /// /// /// /// REVISION 001: Add functionality for field type Grid /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 15 December 2015 /// private void SetRowMode(RepeaterItem repeaterItem, oSurfaceItem surfaceItem, bool editMode, ref ArrayList surfaceData) { try { //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceItem.surfaceId.ToString(), "sequence"); DataTable surfaceFieldData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", surfaceItem.surfaceId + "," + surfaceItem.recId, "recId"); oSetup _setup = handler.ReturnSetup(); DataTable myDataTable = new DataTable(); myDataTable = surfaceFieldData.Clone(); Label lblLabel = null; LinkButton lnkEdit = null, lnkSaveRow = null, lnkRemove = null, lnkCancel = null, lnkView = null; lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); lnkSaveRow = (LinkButton)repeaterItem.FindControl("lnkSaveRow"); lnkRemove = (LinkButton)repeaterItem.FindControl("lnkRemove"); lnkCancel = (LinkButton)repeaterItem.FindControl("lnkCancel"); lnkView = (LinkButton)repeaterItem.FindControl("lnkView"); /* CVH 2016-01-30 Change column headings */ HtmlTableCell thEdit = (HtmlTableCell)repeaterItem.Parent.Controls[0].Controls[0].FindControl("thEdit"); HtmlTableCell thDelete = (HtmlTableCell)repeaterItem.Parent.Controls[0].Controls[0].FindControl("thDelete"); if (editMode) { /* CVH 2016-01-30 Change column headings */ if (thEdit != null) thEdit.InnerText = "Save"; if (thDelete != null) thDelete.InnerText = "Cancel"; if (lblLabel != null) lblLabel.AddCssClass("noShow"); if (lnkEdit != null) lnkEdit.AddCssClass("noShow"); if (lnkSaveRow != null) lnkSaveRow.RemoveCssClass("noShow"); if (lnkRemove != null) lnkRemove.AddCssClass("noShow"); if (lnkCancel != null) lnkCancel.RemoveCssClass("noShow"); if (lnkView != null) lnkView.AddCssClass("noShow"); if (_setup.code == "STUD-1")//handle custom hide of panle buttons { pnlFormButtons.Visible = false; upButtons.Update(); } } else { /* CVH 2016-01-30 Change column headings */ if (thEdit != null) thEdit.InnerText = "Edit"; if (thDelete != null) thDelete.InnerText = "Delete"; if (lblLabel != null) lblLabel.RemoveCssClass("noShow"); if (lnkEdit != null) lnkEdit.RemoveCssClass("noShow"); if (lnkSaveRow != null) lnkSaveRow.AddCssClass("noShow"); if (lnkRemove != null) lnkRemove.RemoveCssClass("noShow"); if (lnkCancel != null) lnkCancel.AddCssClass("noShow"); if (lnkView != null) lnkView.RemoveCssClass("noShow"); if (_setup.code == "STUD-1")//handle custom hide of panle buttons { pnlFormButtons.Visible = true; upButtons.Update(); } } /* CVH 2016-01-30 Add/Remove noShow for all other rows Edit & Delete buttons */ foreach (RepeaterItem rptOtherItem in ((Repeater)repeaterItem.Parent).Items) { if (rptOtherItem != repeaterItem) { //find Edit & Delete buttons LinkButton lnkEditOther = (LinkButton)rptOtherItem.FindControl("lnkEdit"); LinkButton lnkRemoveOther = (LinkButton)rptOtherItem.FindControl("lnkRemove"); LinkButton lnkViewOther = (LinkButton)rptOtherItem.FindControl("lnkView"); if (editMode) { if (lnkEditOther != null) lnkEditOther.AddCssClass("noShow"); if (lnkRemoveOther != null) lnkRemoveOther.AddCssClass("noShow"); if (lnkViewOther != null) lnkViewOther.AddCssClass("noShow"); } else { if (lnkEditOther != null) lnkEditOther.RemoveCssClass("noShow"); if (lnkRemoveOther != null) lnkRemoveOther.RemoveCssClass("noShow"); if (lnkViewOther != null) lnkViewOther.RemoveCssClass("noShow"); } } } foreach (oSurfaceField field in surfaceFields) { myDataTable.Clear(); //get the data for this field ID var v = from enVal in surfaceFieldData.AsEnumerable() where (enVal.Field("surfaceFieldID") == field.recId) select enVal; v.CopyToDataTable(myDataTable, LoadOption.OverwriteChanges); foreach (oSurfaceFieldData fieldData in utils.ConvertDataTableToList(myDataTable, typeof(oSurfaceFieldData))) { fieldData.surfaceFieldID = field.recId; fieldData.surfaceId = surfaceItem.surfaceId; fieldData.surfaceItemId = surfaceItem.recId; lblLabel = (Label)repeaterItem.FindControl("lbl" + field.surfaceFieldName); if (editMode) { if (lblLabel != null) lblLabel.AddCssClass("noShow"); } else { if (lblLabel != null) lblLabel.RemoveCssClass("noShow"); } if ((field.isGrid && field.isActive && field.surfaceFieldTypeId != (int)pNums.FieldType.Tab && field.surfaceFieldTypeId != (int)pNums.FieldType.Group && field.surfaceFieldTypeId != (int)pNums.FieldType.HeaderGroup && field.surfaceFieldTypeId != (int)pNums.FieldType.Attachment && field.surfaceFieldTypeId != (int)pNums.FieldType.Button && field.surfaceFieldTypeId != (int)pNums.FieldType.Composite && field.surfaceFieldTypeId != (int)pNums.FieldType.Content && field.surfaceFieldTypeId != (int)pNums.FieldType.Control && field.surfaceFieldTypeId != (int)pNums.FieldType.Debtors && field.surfaceFieldTypeId != (int)pNums.FieldType.FormulaField && field.surfaceFieldTypeId != (int)pNums.FieldType.Grid && field.surfaceFieldTypeId != (int)pNums.FieldType.Label && field.surfaceFieldTypeId != (int)pNums.FieldType.Mediswitch && field.surfaceFieldTypeId != (int)pNums.FieldType.Note && field.surfaceFieldTypeId != (int)pNums.FieldType.Placeholder && field.surfaceFieldTypeId != (int)pNums.FieldType.RelationalField && field.surfaceFieldTypeId != (int)pNums.FieldType.Sales) || field.surfaceFieldName == "ParentSurfaceItemId" ) { Label lblToSort = (Label)repeaterItem.FindControl("lblToSort" + field.surfaceFieldName); Label lbl = (Label)repeaterItem.FindControl("lbl" + field.surfaceFieldName); pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { #region Text case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtTextbox != null) { //txtTextbox.Visible = editMode; if (editMode) { txtTextbox.RemoveCssClass("noShow"); string tmpVal = string.Empty; string value = string.Empty; if (myDataTable.Rows.Count > 0) tmpVal = myDataTable.Rows[0]["surfaceFieldValueChar"].ToString(); List unique = tmpVal.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { value = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } txtTextbox.Text = value; lbl.Text = value; lblToSort.Text = value; } else { txtTextbox.AddCssClass("noShow"); List unique = txtTextbox.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { fieldData.surfaceFieldValueChar = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { fieldData.surfaceFieldValueChar = String.Empty; } lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } } break; #endregion #region Number case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtNumberBox != null) { //txtNumberBox.Visible = editMode; if (editMode) { txtNumberBox.RemoveCssClass("noShow"); string Numvalue = string.Empty; if (myDataTable.Rows.Count > 0) Numvalue = myDataTable.Rows[0]["surfaceFieldValueNum"].ToString(); txtNumberBox.Text = Numvalue; lbl.Text = Numvalue; lblToSort.Text = Numvalue; } else { txtNumberBox.AddCssClass("noShow"); int valueNum = 0; List unique = txtNumberBox.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { int.TryParse(unique[0].Replace(",,,,", "").Replace(",,,,,", ""), out valueNum); } fieldData.surfaceFieldValueNum = valueNum; lbl.Text = fieldData.surfaceFieldValueNum.ToString(); lblToSort.Text = fieldData.surfaceFieldValueNum.ToString(); } } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal //CVH 2017-04-05 Show editable currency box in edit mode TextBox txtDecimalBox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtDecimalBox != null) { if (field.isCurrency && txtDecimalBox.Parent.GetType() == typeof(HtmlGenericControl)) { HtmlGenericControl decimalParent = (HtmlGenericControl)txtDecimalBox.Parent; HtmlGenericControl lblParent = (HtmlGenericControl)lbl.Parent; if (decimalParent != null && lblParent != null) { if (editMode) { decimalParent.Attributes.Remove("class"); decimalParent.Attributes.Add("class", "input-group"); lblParent.Attributes.Remove("class"); lblParent.Attributes.Add("class", "input-group noShow"); string tmpVal = string.Empty; string value = string.Empty; if (myDataTable.Rows.Count > 0) tmpVal = myDataTable.Rows[0]["surfaceFieldValueDecimal"].ToString(); List unique = tmpVal.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { value = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } //string Decimalvalue = string.Empty; //if (myDataTable.Rows.Count > 0) // Decimalvalue = myDataTable.Rows[0]["surfaceFieldValueDecimal"].ToString(); string Decimalvalue = value; txtDecimalBox.Text = Decimalvalue; lbl.Text = Decimalvalue; lblToSort.Text = Decimalvalue; } else { decimalParent.Attributes.Remove("class"); decimalParent.Attributes.Add("class", "input-group noShow"); lblParent.Attributes.Remove("class"); lblParent.Attributes.Add("class", "input-group"); string tempDec = String.Empty; List unique = txtDecimalBox.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { tempDec = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { tempDec = String.Empty; } decimal valueDecimal = 0; decimal.TryParse(tempDec, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; lbl.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); lblToSort.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); } } } else { if (editMode) { txtDecimalBox.RemoveCssClass("noShow"); string Decimalvalue = string.Empty; if (myDataTable.Rows.Count > 0) Decimalvalue = myDataTable.Rows[0]["surfaceFieldValueDecimal"].ToString(); txtDecimalBox.Text = Decimalvalue; lbl.Text = Decimalvalue; lblToSort.Text = Decimalvalue; } else { txtDecimalBox.AddCssClass("noShow"); decimal valueDecimal = 0; decimal.TryParse(txtDecimalBox.Text, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; lbl.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); lblToSort.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); } } } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist //CVH 2017-04-05 Enable wants reason on grid HtmlGenericControl ddlParent = (HtmlGenericControl)repeaterItem.FindControl("div" + field.surfaceFieldName); DropDownList ddl = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); TextBox txtddlReason = (TextBox)repeaterItem.FindControl("reason" + field.surfaceFieldName); TextBox txtSelectedDdl = (TextBox)repeaterItem.FindControl("sel" + field.surfaceFieldName); if (ddl != null && ddlParent != null && txtSelectedDdl != null) { if (editMode) { string tmpValDdl = string.Empty; string lookvalueDdl = string.Empty; if (myDataTable.Rows.Count > 0) tmpValDdl = myDataTable.Rows[0]["surfaceFieldLookupID"].ToString(); List uniqueDdl = tmpValDdl.Split(',').Reverse().Distinct().ToList(); if (uniqueDdl.Count > 0) { lookvalueDdl = uniqueDdl[0].Replace(",,,,", "").Replace(",,,,,", ""); } if (ddl.Items.FindByValue(lookvalueDdl) != null) { ddl.ClearSelection(); ddl.Items.FindByValue(lookvalueDdl).Selected = true; if (txtddlReason != null) { if (fieldData.surfaceFieldValueChar != String.Empty) { string tmpReason = fieldData.surfaceFieldValueChar; string reason = string.Empty; List uniqueReason = tmpReason.Split(',').Reverse().Distinct().ToList(); if (uniqueReason.Count > 0) { reason = uniqueReason[0].Replace(",,,,", "").Replace(",,,,,", ""); } txtddlReason.Enabled = true; txtddlReason.Text = reason; } else { txtddlReason.Enabled = false; txtddlReason.Text = String.Empty; } } } ddlParent.Attributes.Remove("class"); } else { ddlParent.Attributes.Add("class", "noShow"); int lookupId = 0; int.TryParse(ddl.SelectedValue, out lookupId); //CVH 2017-04-10 If the "selected" lookupId is the same as the saved lookupId, rather use value in hidden label. The selected value is not accurate. if (lookupId <= 0 || lookupId == fieldData.surfaceFieldLookupID) { string tempLook = String.Empty; List unique = txtSelectedDdl.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { tempLook = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { tempLook = String.Empty; } int.TryParse(tempLook, out lookupId); } if (lookupId > 0) { fieldData.surfaceFieldLookupID = lookupId; if (txtddlReason != null && txtddlReason.Text != String.Empty) { List uniqueReason = txtddlReason.Text.Split(',').Reverse().Distinct().ToList(); if (uniqueReason.Count > 0) { fieldData.surfaceFieldValueChar = uniqueReason[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { fieldData.surfaceFieldValueChar = String.Empty; } lbl.Text = txtddlReason.Text; lblToSort.Text = txtddlReason.Text; } else { lbl.Text = (ddl.Items.FindByValue(lookupId.ToString()) != null ? ddl.Items.FindByValue(lookupId.ToString()).Text : String.Empty); lblToSort.Text = (ddl.Items.FindByValue(lookupId.ToString()) != null ? ddl.Items.FindByValue(lookupId.ToString()).Text : String.Empty); fieldData.surfaceFieldValueChar = String.Empty; } } else { fieldData.surfaceFieldLookupID = 0; lbl.Text = String.Empty; lblToSort.Text = String.Empty; fieldData.surfaceFieldValueChar = String.Empty; } } } break; #endregion #region MultiPicklist case pNums.FieldType.MultiPicklist: ListBox listBox = (ListBox)repeaterItem.FindControl(field.surfaceFieldName); if (listBox != null) { //only setting listbox value, don't think we need to set labels too, it's already bound on repeater if (editMode) { string selectedItem = lbl.Text; listBox.ClearSelection(); foreach (string item in selectedItem.Split(';')) { foreach (ListItem lst in listBox.Items) { if (lst.Text.Trim() == item.Trim()) lst.Selected = true; } } //listBox.RemoveCssClass("noShow"); listBox.Visible = true; } else { //listBox.AddCssClass("noShow"); listBox.Visible = false; } } break; #endregion #region Date case pNums.FieldType.Date: //date HtmlGenericControl dvdt = (HtmlGenericControl)repeaterItem.FindControl("dvdt" + field.surfaceFieldName); TextBox txtDate = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtDate != null) { string format = ""; if (field.surfaceDateTypeId == pNums.SurfaceDateType.Year.GetHashCode()) { format = "yyyy"; } else if (field.surfaceDateTypeId == pNums.SurfaceDateType.MonthYear.GetHashCode()) { format = "MMMM yyyy"; } else { format = "dd/MM/yyyy"; } //txtDate.Visible = editMode; if (editMode) { dvdt.Attributes.Remove("class"); dvdt.Attributes.Add("class", "input-group date "); txtDate.RemoveCssClass("noShow"); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myGridDatePicker", "SetDatePicker();", true); string datevalue = string.Empty; if (field.defaultToCurrent) datevalue = DateTime.Now.ToString(format); else if (field.defaultValue != "") datevalue = field.defaultValue; else datevalue = ""; if (myDataTable.Rows.Count > 0 && myDataTable.Rows[0]["surfaceFieldValueDate"].ToString() != String.Empty) datevalue = Convert.ToDateTime(myDataTable.Rows[0]["surfaceFieldValueDate"].ToString()).ToString(format); txtDate.Text = datevalue; lbl.Text = datevalue; lblToSort.Text = datevalue; } else { dvdt.Attributes.Remove("class"); dvdt.Attributes.Add("class", "input-group date noShow"); txtDate.AddCssClass("noShow"); if (txtDate.Text != String.Empty) { List unique = txtDate.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { if (field.surfaceDateTypeId == pNums.SurfaceDateType.Year.GetHashCode()) fieldData.surfaceFieldValueDate = utils.formatStringToDate(unique[0].Replace(",,,,", "").Replace(",,,,,", "") + "/01/01"); else fieldData.surfaceFieldValueDate = utils.formatStringToDate(unique[0].Replace(",,,,", "").Replace(",,,,,", "")); } lbl.Text = fieldData.surfaceFieldValueDate.ToString(format); lblToSort.Text = fieldData.surfaceFieldValueDate.ToString(format); } } } break; #endregion #region Checkbox case pNums.FieldType.Checkbox: //checkbox if (repeaterItem.FindControl(field.surfaceFieldName).GetType().Name == "CheckBox") { CheckBox chkBox = (CheckBox)repeaterItem.FindControl(field.surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox CheckBox lblchk = (CheckBox)repeaterItem.FindControl("lblchk" + field.surfaceFieldName); if (chkBox != null && lblchk != null) { chkBox.Visible = editMode; if (editMode) { lblchk.AddCssClass("noShow"); chkBox.RemoveCssClass("noShow"); bool boolvalue = false; if (myDataTable.Rows.Count > 0) boolvalue = Convert.ToBoolean(myDataTable.Rows[0]["surfaceFieldValueBool"].ToString()); chkBox.Checked = boolvalue; lblchk.Checked = boolvalue; if (boolvalue == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } else { lblchk.RemoveCssClass("noShow"); chkBox.AddCssClass("noShow"); fieldData.surfaceFieldValueBool = chkBox.Checked; lblchk.Checked = chkBox.Checked; if (fieldData.surfaceFieldValueBool == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } } } else if (repeaterItem.FindControl(field.surfaceFieldName).GetType().Name == "HtmlInputCheckBox") { HtmlInputCheckBox chkBox = (HtmlInputCheckBox)repeaterItem.FindControl(field.surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox HtmlInputCheckBox lblchk = (HtmlInputCheckBox)repeaterItem.FindControl("lblchk" + field.surfaceFieldName); if (chkBox != null && lblchk != null) { chkBox.Visible = editMode; if (editMode) { lblchk.Attributes.Add("class", "noShow"); chkBox.Attributes.Remove("class"); bool boolvalue = false; if (myDataTable.Rows.Count > 0) boolvalue = Convert.ToBoolean(myDataTable.Rows[0]["surfaceFieldValueBool"].ToString()); chkBox.Checked = boolvalue; lblchk.Checked = boolvalue; if (boolvalue == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } else { lblchk.Attributes.Remove("class"); chkBox.Attributes.Add("class", "noShow"); fieldData.surfaceFieldValueBool = chkBox.Checked; lblchk.Checked = chkBox.Checked; if (fieldData.surfaceFieldValueBool == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } } } break; #endregion #region Grid case pNums.FieldType.Grid: //grid //no action - no data is saved in grid field type break; #endregion #region Placeholder /* CVH 2016-01-26 Add field type placeholder */ case pNums.FieldType.Placeholder: //no action break; #endregion #region Caption //JasR 2016-01-27 Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtCaption != null) { //txtTextbox.Visible = editMode; if (editMode) { txtCaption.RemoveCssClass("noShow"); txtCaption.Enabled = !field.isReadOnly; string tmpVal = string.Empty; string value = string.Empty; if (myDataTable.Rows.Count > 0) tmpVal = myDataTable.Rows[0]["surfaceFieldValueChar"].ToString(); List unique = tmpVal.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { value = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } txtCaption.Text = value; lbl.Text = value; lblToSort.Text = value; } else { txtCaption.AddCssClass("noShow"); List unique = txtCaption.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { fieldData.surfaceFieldValueChar = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { fieldData.surfaceFieldValueChar = String.Empty; } lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } } //HtmlTextArea textArea = (HtmlTextArea)repeaterItem.FindControl(field.surfaceFieldName); //if (textArea != null) //{ // //textArea.Visible = editMode; // if (editMode) // { // textArea.Attributes["class"] = textArea.Attributes["class"].Replace("noShow", ""); // string value = string.Empty; // if (myDataTable.Rows.Count > 0) // value = myDataTable.Rows[0]["surfaceFieldValueChar"].ToString(); // textArea.Value = value; // lbl.Text = value; // lblToSort.Text = value; // } // else // { // textArea.Attributes.Add("class", "noShow"); // fieldData.surfaceFieldValueChar =textArea.Value; // lbl.Text = fieldData.surfaceFieldValueChar; // lblToSort.Text = fieldData.surfaceFieldValueChar; // } //} break; #endregion #region RadioButtonList case pNums.FieldType.RadioButtonList: //radiobuttonlist //CVH 2017-04-05 Enable radiobuttonlist on grid, built as dropdown HtmlGenericControl rblParent = (HtmlGenericControl)repeaterItem.FindControl("div" + field.surfaceFieldName); DropDownList rblddl = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); TextBox txtReason = (TextBox)repeaterItem.FindControl("reason" + field.surfaceFieldName); TextBox txtSelected = (TextBox)repeaterItem.FindControl("sel" + field.surfaceFieldName); if (rblddl != null && rblParent != null && txtSelected != null) { if (editMode) { string tmpVal = string.Empty; string lookvalue = string.Empty; if (myDataTable.Rows.Count > 0) tmpVal = myDataTable.Rows[0]["surfaceFieldLookupID"].ToString(); List unique = tmpVal.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { lookvalue = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } if (rblddl.Items.FindByValue(lookvalue) != null) { rblddl.ClearSelection(); rblddl.Items.FindByValue(lookvalue).Selected = true; if (txtReason != null) { if (fieldData.surfaceFieldValueChar != String.Empty) { string tmpReason = fieldData.surfaceFieldValueChar; string reason = string.Empty; List uniqueReason = tmpReason.Split(',').Reverse().Distinct().ToList(); if (uniqueReason.Count > 0) { reason = uniqueReason[0].Replace(",,,,", "").Replace(",,,,,", ""); } txtReason.Enabled = true; txtReason.Text = reason; } else { txtReason.Enabled = false; txtReason.Text = String.Empty; } } } txtSelected.Text = lookvalue; rblParent.Attributes.Remove("class"); } else { rblParent.Attributes.Add("class", "noShow"); int lookupId = 0; int.TryParse(rblddl.SelectedValue, out lookupId); //CVH 2017-04-10 If the "selected" lookupId is the same as the saved lookupId, rather use the lookup in the hidden label. The selected item isn't accurate. if (lookupId <= 0 || lookupId == fieldData.surfaceFieldLookupID) { string tempLook = String.Empty; List unique = txtSelected.Text.Split(',').Reverse().Distinct().ToList(); if (unique.Count > 0) { tempLook = unique[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { tempLook = String.Empty; } int.TryParse(tempLook, out lookupId); } if (lookupId > 0) { fieldData.surfaceFieldLookupID = lookupId; if (txtReason != null && txtReason.Text != String.Empty) { List uniqueReason = txtReason.Text.Split(',').Reverse().Distinct().ToList(); if (uniqueReason.Count > 0) { fieldData.surfaceFieldValueChar = uniqueReason[0].Replace(",,,,", "").Replace(",,,,,", ""); } else { fieldData.surfaceFieldValueChar = String.Empty; } lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } else { lbl.Text = (rblddl.Items.FindByValue(lookupId.ToString()) != null ? rblddl.Items.FindByValue(lookupId.ToString()).Text : String.Empty); lblToSort.Text = (rblddl.Items.FindByValue(lookupId.ToString()) != null ? rblddl.Items.FindByValue(lookupId.ToString()).Text : String.Empty); fieldData.surfaceFieldValueChar = String.Empty; } } else { fieldData.surfaceFieldLookupID = 0; lbl.Text = String.Empty; lblToSort.Text = String.Empty; fieldData.surfaceFieldValueChar = String.Empty; } } } break; #endregion } } surfaceData.Add(fieldData); break; } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save for Grid Edit Type = Batch /// /// /// AUTHOR: Charlene van Heerden /// DATE WRITTEN: 2 February 2016 /// GR 2017-04-28 - rework with LinQ /// Performance upgrade /// private void SaveSurfaceGrid(Repeater rptEdit, int surfaceId, bool isChildSurface, int parentSurfaceItemId = 0) { try { DataTable surfaceFieldTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString(), "sequence"); DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId", surfaceId.ToString()); var fieldTableEnum = surfaceFieldTable.AsEnumerable(); var fieldTableDataEnum = surfaceFieldDataTable.AsEnumerable(); //change edit + delete column headings HtmlTableCell thEdit = (HtmlTableCell)rptEdit.Controls[0].Controls[0].FindControl("thEdit"); HtmlTableCell thDelete = (HtmlTableCell)rptEdit.Controls[0].Controls[0].FindControl("thDelete"); if (thEdit != null) thEdit.InnerText = "Edit"; if (thDelete != null) thDelete.InnerText = "Delete"; int currentParentSurfaceItemId = 0; int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //CVH 2017-05-02 SBF Get Total Monthly Income Post Interview calculated values DataTable dtSTUD1PostInterview = new DataTable(); if (handler.ReturnSetup().code == "STUD-1" && isChildSurface && base.SurfaceApp != null && base.SurfaceApp.name.Contains("PrimaryCaregivers") && parentSurfaceItemId != 0) { List list = new List(); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "surfaceItemId"; par2.paramObject = parentSurfaceItemId; list.Add(par2); dtSTUD1PostInterview = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_STUD1_CalculateTotalMonthlyIncomePostInterview", list); } oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction lookupFieldAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) { if (act.actionType == (int)pNums.ActionType.Calculation) { if (act.action == "Divide") divideAction = act; else if (act.action == "Lookup") lookupAction = act; else if (act.action == "Lookup Field") lookupFieldAction = act; } else if (act.actionType == (int)pNums.ActionType.Aggregation) { if (act.action == "Sum") aggrSumAction = act; } if (divideAction.recId > 0 && lookupAction.recId > 0 && aggrSumAction.recId > 0) { break; } } foreach (RepeaterItem repeaterItem in rptEdit.Items) { string STUD1_TypeOfIncome = String.Empty; decimal STUD1_PreInterview = 0m; if (repeaterItem.ItemIndex == 0) { //CVH 2017-03-21 Check for null & check if child surface - linked surface batch edit //CVH 2017-03-30 Don't check base.IsChildSurface, it's no longer correct. Use bool parameter instead if (repeaterItem.FindControl("hfParentSurfaceItemId") != null && isChildSurface) { HiddenField hfParentSurfaceItemId = (HiddenField)repeaterItem.FindControl("hfParentSurfaceItemId"); if (hfParentSurfaceItemId.Value != "") currentParentSurfaceItemId = Convert.ToInt32(hfParentSurfaceItemId.Value); } } LinkButton lnkEdit = null, lnkSaveRow = null, lnkRemove = null, lnkCancel = null, lnkView = null; lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); lnkSaveRow = (LinkButton)repeaterItem.FindControl("lnkSaveRow"); lnkRemove = (LinkButton)repeaterItem.FindControl("lnkRemove"); lnkCancel = (LinkButton)repeaterItem.FindControl("lnkCancel"); lnkView = (LinkButton)repeaterItem.FindControl("lnkView"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //CVH 2017-03-21 Only when child surface if (currentParentSurfaceItemId == 0 && isChildSurface) { //create new item oSurfaceItem childItem = new oSurfaceItem(); childItem.createdBy = userId; childItem.dateCreated = DateTime.Now; childItem.isActive = true; childItem.isDeleted = false; childItem.isWizardCompleted = false; childItem.lastTabCompleted = 0; childItem.surfaceId = surfaceId; itemId = xData.SaveTyped("recId", typeof(oSurfaceItem), childItem); } if (lnkEdit != null) lnkEdit.RemoveCssClass("noShow"); if (lnkSaveRow != null) lnkSaveRow.AddCssClass("noShow"); if (lnkRemove != null) lnkRemove.RemoveCssClass("noShow"); if (lnkCancel != null) lnkCancel.AddCssClass("noShow"); if (lnkView != null) lnkView.RemoveCssClass("noShow"); ArrayList fieldDataListNew = new ArrayList(); ArrayList fieldDataListUpdate = new ArrayList(); var gridFieldData = from grdFields in fieldTableEnum where (grdFields.Field("isGrid").Equals(true) && grdFields.Field("isActive").Equals(true) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.HeaderGroup) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Attachment) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Button) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Composite) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Content) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Control) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Debtors) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Grid) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Label) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Mediswitch) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Note) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Placeholder) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RelationalField) && !grdFields.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Sales)) || grdFields.Field("surfaceFieldName").Equals("ParentSurfaceItemId") select grdFields; foreach (DataRow fieldRow in gridFieldData.ToList()) { int _surfaceFieldTypeId = int.Parse(fieldRow["surfaceFieldTypeId"].ToString()); int _recId = int.Parse(fieldRow["recId"].ToString()); int _surfaceDateTypeId = 0; int.TryParse(fieldRow["surfaceDateTypeId"].ToString(), out _surfaceDateTypeId); string _surfaceFieldName = fieldRow["surfaceFieldName"].ToString(); string _surfaceFieldDisplay = fieldRow["surfaceFieldDisplay"].ToString(); int _actionType = 0; int.TryParse(fieldRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(fieldRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(fieldRow["actionSource"].ToString(), out _actionSource); string _actionValue = fieldRow["actionValue"].ToString(); oSurfaceFieldData fieldData = new oSurfaceFieldData(); //CVH 2017-03-21 Only when child surface if (currentParentSurfaceItemId == 0 && isChildSurface) { fieldData = new oSurfaceFieldData(); fieldData.surfaceId = surfaceId; fieldData.surfaceFieldID = _recId; fieldData.surfaceItemId = itemId; } else { var itemData = from items in fieldTableDataEnum where items.Field("surfaceItemId").Equals(itemId) && items.Field("surfaceFieldID").Equals(_recId) select items; //CVH 2017-05-11 If it is a valid item, but no data, need to create new data object, new field added after item has been created if (itemData.Count() == 0 && itemId <= 0) continue; else if (itemData.Count() == 0) { fieldData = new oSurfaceFieldData(); fieldData.surfaceId = surfaceId; fieldData.surfaceFieldID = _recId; fieldData.surfaceItemId = itemId; } else { foreach (DataRow itemRow in itemData.ToList()) { fieldData.recId = int.Parse(itemRow["recId"].ToString()); fieldData.surfaceFieldID = _recId; fieldData.surfaceItemId = itemId; fieldData.surfaceId = surfaceId; DateTime fieldDate; DateTime.TryParse(itemRow["surfaceFieldValueDate"].ToString(), out fieldDate); fieldData.surfaceFieldValueDate = fieldDate; DateTime fieldDateT; DateTime.TryParse(itemRow["surfaceFieldValueTime"].ToString(), out fieldDateT); fieldData.surfaceFieldValueTime = fieldDateT; fieldData.surfaceFieldValueChar = itemRow["surfaceFieldValueChar"].ToString(); decimal decVal = 0; decimal.TryParse(itemRow["surfaceFieldValueDecimal"].ToString(), out decVal); fieldData.surfaceFieldValueDecimal = decVal; int numVal = 0; int.TryParse(itemRow["surfaceFieldValueNum"].ToString(), out numVal); fieldData.surfaceFieldValueNum = numVal; int lookVal = 0; int.TryParse(itemRow["surfaceFieldLookupID"].ToString(), out lookVal); fieldData.surfaceFieldLookupID = lookVal; bool valBool = false; bool.TryParse(itemRow["surfaceFieldValueBool"].ToString(), out valBool); fieldData.surfaceFieldValueBool = valBool; } } } Label lblToSort = (Label)repeaterItem.FindControl("lblToSort" + _surfaceFieldName); Label lbl = (Label)repeaterItem.FindControl("lbl" + _surfaceFieldName); pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), _surfaceFieldTypeId); if (lbl != null) { lbl.RemoveCssClass("noShow"); } switch (typ) { #region Text case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtTextbox != null) { txtTextbox.AddCssClass("noShow"); if (_actionType == (int)pNums.ActionType.Calculation && _action == lookupFieldAction.recId) { List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = _recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = itemId; listLookup.Add(look2); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) { txtTextbox.Text = dtValue.Rows[0][0].ToString(); fieldData.surfaceFieldValueChar = txtTextbox.Text; } else { txtTextbox.Text = ""; fieldData.surfaceFieldValueChar = ""; } } else { fieldData.surfaceFieldValueChar = txtTextbox.Text; if (handler.ReturnSetup().code == "STUD-1" && isChildSurface && base.SurfaceApp != null && base.SurfaceApp.name.Contains("PrimaryCaregivers") && parentSurfaceItemId != 0 && _surfaceFieldDisplay == "Type of Income") { STUD1_TypeOfIncome = fieldData.surfaceFieldValueChar; } } lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } break; #endregion #region Number case pNums.FieldType.Number: //number if (_surfaceFieldName == "ParentSurfaceItemId") { fieldData.surfaceFieldValueNum = parentSurfaceItemId; } else { TextBox txtNumberBox = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtNumberBox != null) { txtNumberBox.AddCssClass("noShow"); int valueNum = 0; int.TryParse(txtNumberBox.Text, out valueNum); fieldData.surfaceFieldValueNum = valueNum; lbl.Text = fieldData.surfaceFieldValueNum.ToString(); lblToSort.Text = fieldData.surfaceFieldValueNum.ToString(); } } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtDecimalBox != null) { //CVH 2017-05-02 SBF Total Monthly Income Post Interview calculation if (handler.ReturnSetup().code == "STUD-1" && isChildSurface && base.SurfaceApp != null && base.SurfaceApp.name.Contains("PrimaryCaregivers") && parentSurfaceItemId != 0 && _surfaceFieldDisplay.Contains("Post Interview")) { if (STUD1_TypeOfIncome != String.Empty && dtSTUD1PostInterview.Rows.Count > 0 && dtSTUD1PostInterview.Columns[STUD1_TypeOfIncome] != null) { //assuming Type of Income field is processed before the Post Interview field decimal valueDecimal = 0; decimal.TryParse(dtSTUD1PostInterview.Rows[0][STUD1_TypeOfIncome].ToString(), out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; } else { fieldData.surfaceFieldValueDecimal = STUD1_PreInterview; } } else { decimal valueDecimal = 0; decimal.TryParse(txtDecimalBox.Text, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; } txtDecimalBox.AddCssClass("noShow"); lbl.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); lblToSort.Text = utils.returnFormattedDecimal(Convert.ToString(fieldData.surfaceFieldValueDecimal)); //CVH 2017-05-02 SBF Total Monthly Income Post Interview calculation if (handler.ReturnSetup().code == "STUD-1" && isChildSurface && base.SurfaceApp != null && base.SurfaceApp.name.Contains("PrimaryCaregivers") && parentSurfaceItemId != 0 && _surfaceFieldDisplay.Contains("Pre-Interview")) { STUD1_PreInterview = fieldData.surfaceFieldValueDecimal; } } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)repeaterItem.FindControl(_surfaceFieldName); if (ddDropdownlist != null) { ddDropdownlist.AddCssClass("noShow"); int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); if (lookupId > 0) fieldData.surfaceFieldLookupID = lookupId; lbl.Text = ddDropdownlist.SelectedItem.Text; lblToSort.Text = ddDropdownlist.SelectedItem.Text; } break; #endregion #region MultiPicklist case pNums.FieldType.MultiPicklist: //multi picklist ListBox listBox = (ListBox)repeaterItem.FindControl(_surfaceFieldName); if (listBox != null) { string lbSelectedValues = string.Empty; string lbSelectedText = string.Empty; foreach (ListItem item in listBox.Items) { if (item.Selected) { if (lbSelectedValues == String.Empty) { lbSelectedValues = item.Value.ToString(); lbSelectedText = item.Text.ToString(); } else { lbSelectedValues += "," + item.Value; lbSelectedText += "; " + item.Text.ToString(); } } } //listBox.AddCssClass("noShow"); listBox.Visible = false; fieldData.surfaceFieldValueChar = lbSelectedValues; lbl.Text = lbSelectedText; lblToSort.Text = lbSelectedText; } break; #endregion #region Date case pNums.FieldType.Date: //date TextBox txtDate = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtDate != null) { txtDate.AddCssClass("noShow"); if (txtDate.Text != String.Empty) { if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text + "/01/01"); else fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text); lbl.Text = fieldData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); lblToSort.Text = fieldData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); } } break; #endregion #region Checkbox case pNums.FieldType.Checkbox: //checkbox if (repeaterItem.FindControl(_surfaceFieldName).GetType().Name == "CheckBox") { CheckBox chkBox = (CheckBox)repeaterItem.FindControl(_surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox CheckBox lblchk = (CheckBox)repeaterItem.FindControl("lblchk" + _surfaceFieldName); if (chkBox != null && lblchk != null) { chkBox.AddCssClass("noShow"); lblchk.RemoveCssClass("noShow"); fieldData.surfaceFieldValueBool = chkBox.Checked; lblchk.Checked = chkBox.Checked; if (fieldData.surfaceFieldValueBool == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } } else if (repeaterItem.FindControl(_surfaceFieldName).GetType().Name == "HtmlInputCheckBox") { HtmlInputCheckBox chkBox = (HtmlInputCheckBox)repeaterItem.FindControl(_surfaceFieldName); //CVH 2016-11-10 No edit label for field type checkbox has been changed to a read only checkbox HtmlInputCheckBox lblchk = (HtmlInputCheckBox)repeaterItem.FindControl("lblchk" + _surfaceFieldName); if (chkBox != null && lblchk != null) { chkBox.Attributes.Add("class", "noShow"); lblchk.Attributes.Remove("class"); fieldData.surfaceFieldValueBool = chkBox.Checked; lblchk.Checked = chkBox.Checked; if (fieldData.surfaceFieldValueBool == true) lblToSort.Text = "Yes"; else lblToSort.Text = "No"; } } break; #endregion #region Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtCaption != null) { txtCaption.AddCssClass("noShow"); fieldData.surfaceFieldValueChar = txtCaption.Text; lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } break; #endregion #region FormulaField case pNums.FieldType.FormulaField: fieldData.surfaceFieldValueChar = ""; TextBox txtFieldBox = (TextBox)repeaterItem.FindControl(_surfaceFieldName); if (txtFieldBox != null) { //CVH 2017-02-07 Divide Calculation Formula need to calculate and save it on form save if (_actionType == (int)pNums.ActionType.Calculation && _action == divideAction.recId) { decimal? source1 = null; decimal? source2 = null; //if first source field is decimal, format it as a decimal, otherwise format as int bool divDecimal = false; int src2FieldId = 0; int.TryParse(_actionValue, out src2FieldId); decimal divideTemp = 0; var sfData = from sflds in fieldTableEnum where sflds.Field("recId").Equals(_actionSource) || (sflds.Field("recId").Equals(src2FieldId) && src2FieldId > 0) select sflds; foreach (DataRow srcFRow in sfData.ToList()) { int _srcFieldRecId = int.Parse(srcFRow["recId"].ToString()); int _srcFieldTypeId = int.Parse(srcFRow["surfaceFieldTypeId"].ToString()); string _srcFieldName = srcFRow["surfaceFieldName"].ToString(); if (_srcFieldRecId == _actionSource) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), _srcFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)repeaterItem.FindControl(_srcFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source1 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)repeaterItem.FindControl(_srcFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source1 = divideTemp; } break; } if (_srcFieldTypeId == (int)pNums.FieldType.Decimal) divDecimal = true; } else if (_srcFieldRecId == src2FieldId) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), _srcFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)repeaterItem.FindControl(_srcFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source2 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)repeaterItem.FindControl(_srcFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source2 = divideTemp; } break; } } } if (source1 != null && source2 != null && source2 != 0) { if (divDecimal) fieldData.surfaceFieldValueChar = utils.returnFormattedDecimal((source1 / source2).ToString()); else fieldData.surfaceFieldValueChar = Decimal.Round((source1.Value / source2.Value), 0).ToString(); } else { fieldData.surfaceFieldValueChar = ""; } } //CVH 2017-02-13 Lookup Calculation Formula else if (_actionType == (int)pNums.ActionType.Calculation && _action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; var srcfData = from sflds in fieldTableEnum where sflds.Field("recId").Equals(_actionSource) select sflds; foreach (DataRow srcFRow in srcfData.ToList()) { string _srcFieldName = srcFRow["surfaceFieldName"].ToString(); TextBox txtSrc = (TextBox)repeaterItem.FindControl(_srcFieldName); if (txtSrc != null) { conversionSuccess = decimal.TryParse(txtSrc.Text, out sourceValue); } break; } if (conversionSuccess) { fieldData.surfaceFieldValueChar = CalculateLookup(fieldRow, sourceValue); } } //CVH 2017-02-24 New action type Aggregation Sum else if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) fieldData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, itemId); } else { decimal valueDecimal = 0; if (decimal.TryParse(txtFieldBox.Text, out valueDecimal)) { fieldData.surfaceFieldValueDecimal = valueDecimal; } else //assume textbox { fieldData.surfaceFieldValueChar = txtFieldBox.Text; } if (_actionType == (int)pNums.ActionType.GenerateCode) { Session["surfaceCodeUsed"] = txtFieldBox.Text; } } } break; #endregion #region RadioButtonList //CVH 2017 - 04 - 05 Enable radiobuttonlist on grid, built as dropdown case pNums.FieldType.RadioButtonList: //radiobuttonlist HtmlGenericControl rblParent = (HtmlGenericControl)repeaterItem.FindControl("div" + _surfaceFieldName); DropDownList rblddl = (DropDownList)repeaterItem.FindControl(_surfaceFieldName); TextBox txtReason = (TextBox)repeaterItem.FindControl("reason" + _surfaceFieldName); if (rblddl != null && rblParent != null) { rblParent.Attributes.Add("class", "noShow"); int lookupId = 0; int.TryParse(rblddl.SelectedValue, out lookupId); if (lookupId > 0) fieldData.surfaceFieldLookupID = lookupId; if (txtReason != null && txtReason.Enabled) { lbl.Text = txtReason.Text; lblToSort.Text = txtReason.Text; fieldData.surfaceFieldValueChar = txtReason.Text; } else { lbl.Text = rblddl.SelectedItem.Text; lblToSort.Text = rblddl.SelectedItem.Text; fieldData.surfaceFieldValueChar = String.Empty; } } break; #endregion } if (fieldData.recId == 0) { fieldDataListNew.Add(fieldData); //xData.SaveTyped("recId", typeof(oSurfaceFieldData), fieldData); } else { fieldDataListUpdate.Add(fieldData); //xData.UpdateTyped("recId", fieldData.recId.ToString(), typeof(oSurfaceFieldData), fieldData); } } if (fieldDataListNew.Count > 0) xData.SaveTypedCollection("recId", typeof(oSurfaceFieldData), fieldDataListNew); if (fieldDataListUpdate.Count > 0) xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), fieldDataListUpdate); //save to query table xData.SaveSurfaceItemToQueryTable(surfaceId, itemId); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Save Row /// /// /// private void SaveSurfaceRow(ref oSurfaceItem _surfaceItem, ref ArrayList surfaceData, RepeaterItem rptItem) { try { //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); LinkButton lnkEdit = (LinkButton)rptItem.FindControl("lnkEdit"); LinkButton lnkSaveRow = (LinkButton)rptItem.FindControl("lnkSaveRow"); if (int.Parse((lnkEdit).CommandArgument) == _surfaceItem.recId) { SetRowMode(rptItem, _surfaceItem, false, ref surfaceData); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private bool SaveChildSurfaceData(int parentSurfaceItemId, bool isClosing, int childSurfaceId = 0) { bool success = true; try { if (base.SurfaceApp != null) { foreach (oSurfaceField gridField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid)) { Panel pnl = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId + "_" + gridField.surfaceFieldName); if (pnl != null) { oSurface childSurface = new oSurface(); foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", gridField.relationalSurface)) { //surfaceId = surf.recId; childSurface = surf; break; } if ((childSurface.recId > 0 && childSurfaceId == 0) || (childSurface.recId == childSurfaceId)) { //get grid options oSurfaceGridOptions gridOpts = new oSurfaceGridOptions(); foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { gridOpts = opt; break; } //CVH 2017-02-23 Only save child grid data if the field is not set read only //CVH 2017-04-21 If read only, just refresh data, need to update label values if (gridField.isReadOnly) { //loop through repeater items and re-insert into query table ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", childSurface.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); if (fieldTabs.Count > 1 && gridOpts.isTabbed) { foreach (oSurfaceField tabPanel in fieldTabs) { int tabId = tabPanel.recId; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { foreach (RepeaterItem repeaterItem in rpt.Items) { LinkButton lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //update query table xData.SaveSurfaceItemToQueryTable(childSurface.recId, itemId); } } } } else { int tabId = 0; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { foreach (RepeaterItem repeaterItem in rpt.Items) { LinkButton lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //update query table xData.SaveSurfaceItemToQueryTable(childSurface.recId, itemId); } } } } else { if (gridOpts.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", childSurface.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); if (fieldTabs.Count > 1 && gridOpts.isTabbed) { foreach (oSurfaceField tabPanel in fieldTabs) { int tabId = tabPanel.recId; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { SaveSurfaceGrid(rpt, childSurface.recId, true, parentSurfaceItemId); } } } else { int tabId = 0; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { SaveSurfaceGrid(rpt, childSurface.recId, true, parentSurfaceItemId); } } } } //CVH 2017-04-21 Moving out of if, always need to rebind child grids if not closing, need to update labels. if (!isClosing) //Bind child Grid BindChildGrid(childSurface); } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return success; } /// /// Used for Wizard save, don't need to save all child surfaces linked to surface, only those linked to current tab /// /// /// /// /// private bool SaveChildSurfaceDataSpecificTab(int parentSurfaceItemId, bool isClosing, string tabName) { bool success = true; try { if (base.SurfaceApp != null) { foreach (oSurfaceField tab in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,surfaceFieldName", base.SurfaceApp.recId + ",1," + tabName)) { foreach (oSurfaceField group in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,parentId", base.SurfaceApp.recId + ",2," + tab.recId)) { foreach (oSurfaceField gridField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId,parentId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid + "," + group.recId)) { Panel pnl = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId + "_" + gridField.surfaceFieldName); if (pnl != null) { oSurface childSurface = new oSurface(); foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", gridField.relationalSurface)) { //surfaceId = surf.recId; childSurface = surf; break; } if (childSurface.recId > 0) { //get grid options oSurfaceGridOptions gridOpts = new oSurfaceGridOptions(); foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { gridOpts = opt; break; } //CVH 2017-02-23 Only save child grid data if the field is not set read only //CVH 2017-04-21 If read only, just refresh data, need to update label values if (gridField.isReadOnly) { //loop through repeater items and re-insert into query table ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", childSurface.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); if (fieldTabs.Count > 1 && gridOpts.isTabbed) { foreach (oSurfaceField tabPanel in fieldTabs) { int tabId = tabPanel.recId; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { foreach (RepeaterItem repeaterItem in rpt.Items) { LinkButton lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //update query table xData.SaveSurfaceItemToQueryTable(childSurface.recId, itemId); } } } } else { int tabId = 0; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { foreach (RepeaterItem repeaterItem in rpt.Items) { LinkButton lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //update query table xData.SaveSurfaceItemToQueryTable(childSurface.recId, itemId); } } } } else { if (gridOpts.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", childSurface.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); if (fieldTabs.Count > 1 && gridOpts.isTabbed) { foreach (oSurfaceField tabPanel in fieldTabs) { int tabId = tabPanel.recId; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { SaveSurfaceGrid(rpt, childSurface.recId, true, parentSurfaceItemId); } } } else { int tabId = 0; //get repeater Repeater rpt = (Repeater)pnl.FindControl("rpt" + childSurface.name + "Child" + tabId + gridField.surfaceFieldName); if (rpt != null && rpt.Controls.Count > 0 && rpt.Controls[0].Controls.Count > 0) { SaveSurfaceGrid(rpt, childSurface.recId, true, parentSurfaceItemId); } } } } //CVH 2017-04-21 Moving out of if, always need to rebind child grids if not closing, need to update labels. if (!isClosing) //Bind child Grid BindChildGrid(childSurface); } } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return success; } /// /// Global Save method to cater for all scenarios /// /// private bool PerformSave(bool finish, bool draft, bool isClosing) { //CVH 2017-01-11 Add ref param indicating whether or not child surfaces saved successfully bool createParentSurfaceItem = false; //if true this surface is grid on parent surface and a parent surface item has been created to link child to bool result = false; oSurfaceItem item = new oSurfaceItem(); oUser user = new oUser(); ArrayList surfaceDataList = new ArrayList(); try { if (utils.verifySession("user")) user = (oUser)Session["user"]; if (base.SurfaceApp != null) { oSurface surfaceApp = base.SurfaceApp; if ((base.SurfaceAppItem != null && base.SurfaceAppItem.recId > 0) && !base.IsClone)//update { item = base.SurfaceAppItem; item.dateUpdated = DateTime.Now; item.updatedBy = user.recId; item.isActive = !draft; item.isDeleted = false; //item.lastTabCompleted = 0; //GR 2017-06-12 Handle saving for custom apps bool saved = false; if (base.SurfaceApp.isPublished) { saved = SaveSurfaceFormCustom(ref item, ref createParentSurfaceItem); } else { saved = SaveSurfaceForm(ref item, ref surfaceDataList, ref createParentSurfaceItem); } if (saved) { if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { if (surfaceDataList.Count > 0) xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; result = true; lblResult.Text = "your item was updated successfully."; /* CVH 2016-04-20 Add new note of type "Surface Item Changed" */ if (finish) { if (!utils.verifySession("newItem") || Session["newItem"].ToString() != "saved") { //CVH 2016-11-17 Set the Notes button field name, used when linking notes to surface string fieldName = ""; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Note + ",1")) { fieldName = field.surfaceFieldName; break; } oNote note = new oNote(); note.moduleId = (int)pNums.Module.Surface; note.typeId = (int)pNums.NoteType.SurfaceItemChanged; note.entityId = base.SurfaceAppItemId; note.title = "Surface Item Details Edited"; note.caption = "The surface item details were edited."; note.dateSaved = DateTime.Now; note.userIdSaved = user.recId; note.isActive = true; note.fieldName = fieldName; note.recId = xData.SaveTyped("recId", typeof(oNote), note); } else utils.disposeSession("newItem"); } } } } else//save { item.surfaceId = surfaceApp.recId; item.isActive = !draft; item.isDeleted = false; item.dateCreated = DateTime.Now; item.createdBy = user.recId; //GR 2017-06-12 Handle saving for custom apps bool saved = false; if (base.SurfaceApp.isPublished) { //save item first for object and table item.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), item); //refresh controls with item id RefreshControls(item); saved = SaveSurfaceFormCustom(ref item, ref createParentSurfaceItem); } else { saved = SaveSurfaceForm(ref item, ref surfaceDataList, ref createParentSurfaceItem); } if (saved) { if (!base.SurfaceApp.isPublished) item.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), item); if (item.recId > 0) { if (!base.SurfaceApp.isPublished)//refresh controls with item id RefreshControls(item); if (surfaceDataList.Count > 0) { foreach (oSurfaceFieldData data in surfaceDataList) { data.surfaceItemId = item.recId; } xData.SaveTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); } result = true; base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; lblResult.Text = "your item was created successfully."; //JR Move image path to id folder if (utils.verifySession("SurfaceItemImagesNotLinked")) { string currentPath = string.Empty, newPath = string.Empty, fileName = string.Empty, surfaceFieldId = string.Empty; foreach (string imagepath in Session["SurfaceItemImagesNotLinked"].ToString().Split(';')) { currentPath = imagepath.Split('|')[0]; fileName = imagepath.Split('|')[1]; surfaceFieldId = imagepath.Split('|')[2]; newPath = currentPath.Substring(0, currentPath.LastIndexOf("\\") - 1) + item.recId.ToString() + "\\"; //utils.ResizeImageMaxWidth(currentPath, newPath, fileName, true, true, 800); utils.validateFolder(newPath); File.Move(currentPath + fileName, newPath + fileName); foreach (oSurfaceFieldData dataItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceItemId,surfaceFieldID", item.recId.ToString() + "," + surfaceFieldId)) { dataItem.surfaceFieldValueChar = item.recId.ToString() + "/" + fileName; xData.UpdateTyped("recId", dataItem.recId.ToString(), typeof(oSurfaceFieldData), dataItem); } } utils.disposeSession("SurfaceItemImagesNotLinked"); } /* CVH 2016-10-18 If MedicalDiagnosisPatient items have been saved with 0 surfaceItemId, update records now */ if (utils.verifySession("PatientDiagnosisItemsNotLinked")) { ArrayList pdList = (ArrayList)Session["PatientDiagnosisItemsNotLinked"]; foreach (oMedicalPatientDiagnosis pd in pdList) { pd.surfaceItemId = item.recId; xData.UpdateTyped("recId", pd.recId.ToString(), typeof(oMedicalPatientDiagnosis), pd); } } /* CVH 2016-10-18 If MedicalPatientProcedureBooking items have been saved with 0 surfaceItemId, update records now */ if (utils.verifySession("PatientBookingItemsNotLinked")) { ArrayList bookingList = (ArrayList)Session["PatientBookingItemsNotLinked"]; foreach (oMedicalPatientProcedureBooking booking in bookingList) { booking.surfaceItemId = item.recId; xData.UpdateTyped("recId", booking.recId.ToString(), typeof(oMedicalPatientProcedureBooking), booking); } } //CVH 2016-11-17 Set the Notes button field name, used when linking notes to surface string fieldName = ""; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Note + ",1")) { fieldName = field.surfaceFieldName; break; } /* CVH 2016-04-20 Add new note of type "Surface Item Created" */ oNote note = new oNote(); note.moduleId = (int)pNums.Module.Surface; note.typeId = (int)pNums.NoteType.SurfaceItemCreated; note.entityId = base.SurfaceAppItemId; note.title = "Surface Item Created"; note.caption = "A new surface item was created."; note.dateSaved = DateTime.Now; note.userIdSaved = user.recId; note.isActive = true; note.fieldName = fieldName; note.recId = xData.SaveTyped("recId", typeof(oNote), note); //set session to indicate that changed record shouldn't be saved on next Finish click Session["newItem"] = "saved"; /* CVH 2016-07-22 Surface as grid field on parent surface. Parent item has been created, bubble event to save data on parent item */ if (createParentSurfaceItem && base.ParentSurfaceItemId > 0) { CommandEventArgs args = new CommandEventArgs("SaveParentSurfaceItem", base.ParentSurfaceItemId); RaiseBubbleEvent(null, args); } } } //CVH 2016-10-18 Dispose session, whether successful save or not utils.disposeSession("PatientDiagnosisItemsNotLinked"); utils.disposeSession("PatientBookingItemsNotLinked"); } /* CVH 2016-10-21 If ImageMap items have been saved with 0 surfaceItemId, update records now */ if (utils.verifySession("ImageMapItemsNotLinked")) { ArrayList imgList = (ArrayList)Session["ImageMapItemsNotLinked"]; foreach (oImageMap img in imgList) { img.surfaceItemId = item.recId; img.isActive = true; xData.UpdateTyped("recId", img.recId.ToString(), typeof(oImageMap), img); } } utils.disposeSession("ImageMapItemsNotLinked"); /* JR 2016-12-14 If MedicalPatientComaplaint items have been saved with 0 surfaceItemId, update records now */ if (utils.verifySession("PatientComplaintItemsNotLinked")) { ArrayList pcList = (ArrayList)Session["PatientComplaintItemsNotLinked"]; foreach (oMedicalPatientComplaints pc in pcList) { pc.surfaceItemId = item.recId; xData.UpdateTyped("recId", pc.recId.ToString(), typeof(oMedicalPatientComplaints), pc); } } utils.disposeSession("PatientComplaintItemsNotLinked"); //CVH 2016-10-21 Check for custom action on surface save if (result && base.SurfaceApp.surfaceActionId > 0) { foreach (oSurfaceAction action in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", base.SurfaceApp.surfaceActionId.ToString())) { if (action.action == "Surface Save") { string redirect = xSurfaceCustomAction.SurfaceSave(base.SurfaceApp, base.SurfaceAppItem, user.recId, ConfigurationManager.AppSettings["WebAddy"], ConfigurationManager.AppSettings["admin"], ConfigurationManager.AppSettings["from"]); if (redirect != String.Empty) Session["SaveSurfaceActionRedirect"] = redirect; } } } //JR 2017-02-10 Update SurfaceItemCodes if (utils.verifySession("surfaceCodeUsed")) { foreach (oSurfaceItemCode code in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItemCode), "userId,status", user.recId.ToString() + ",Active")) { int iLastUsed = code.lastUsed; int.TryParse(Session["surfaceCodeUsed"].ToString().Substring(1), out iLastUsed); code.lastUsed = iLastUsed; xData.UpdateTyped("recId", code.recId.ToString(), typeof(oSurfaceItemCode), code); } } SetPatientType("PatientType_PatientType_PatientType"); //CVH 2017-01-11 Save child surface data, only when proper save, not save draft if (result && !draft) { //CVH 2017-05-03 Need to copy item to query table before and after updating child grids, everything needs to be refreshed both ways (Total Monthly Income and linked surface Extramural labels) //save to query table if (!base.SurfaceApp.isPublished) xData.SaveSurfaceItemToQueryTable(item.surfaceId, item.recId); //CVH 2017-06-27 When saving in a wizard, only save child surfaces on current tab. Only enabling for SBF, might cause problems elsewhere, need to test per instance string currentTab = base.ActiveTabPanel; if (currentTab.Length > 0 && currentTab.LastIndexOf("_f") > 0) currentTab = currentTab.Substring(currentTab.LastIndexOf("_f") + 2); else currentTab = String.Empty; if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.isWizzard && pnlWizzardButtons.Visible && !pnlFormButtons.Visible && currentTab != String.Empty) SaveChildSurfaceDataSpecificTab(item.recId, isClosing, currentTab); else SaveChildSurfaceData(item.recId, isClosing); //update grid fields that rely on child data (aggregation sum) UpdateSurfaceActionFields(item); if (!base.SurfaceApp.isPublished)//save to query table xData.SaveSurfaceItemToQueryTable(item.surfaceId, item.recId, true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return result; } private bool PerformBulkUpdate(oSurfaceItem item, ArrayList bulkFields) { bool result = false; try { oUser user = handler.ReturnUser(); item.dateUpdated = DateTime.Now; item.updatedBy = user.recId; item.isActive = true; item.isDeleted = false; ArrayList surfaceDataList = new ArrayList(); if (SaveBulkUpdate(item, bulkFields, ref surfaceDataList)) { if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); //save to query table xData.SaveSurfaceItemToQueryTable(item.surfaceId, item.recId); result = true; string fieldName = ""; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + pNums.FieldType.Note.GetHashCode() + ",1")) { fieldName = field.surfaceFieldName; break; } oNote note = new oNote(); note.moduleId = pNums.Module.Surface.GetHashCode(); note.typeId = pNums.NoteType.SurfaceItemChanged.GetHashCode(); note.entityId = item.recId; note.title = "Surface Item Details Edited"; note.caption = "The surface item details were edited."; note.dateSaved = DateTime.Now; note.userIdSaved = user.recId; note.isActive = true; note.fieldName = fieldName; note.recId = xData.SaveTyped("recId", typeof(oNote), note); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return result; } private void ClearBulkUpdate(ArrayList bulkFields) { try { foreach (oSurfaceField bulkField in bulkFields) { if (bulkField.surfaceFieldTypeId != pNums.FieldType.Tab.GetHashCode() && bulkField.surfaceFieldTypeId != pNums.FieldType.Group.GetHashCode()) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), bulkField.surfaceFieldTypeId); switch (typ) { #region Number case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtNumberBox != null) { txtNumberBox.Text = ""; } break; #endregion #region Decimal case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtDecimalBox != null) { txtDecimalBox.Text = ""; } break; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (ddDropdownlist != null) { ddDropdownlist.ClearSelection(); } break; #endregion #region Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (txtCaption != null) { txtCaption.Text = ""; } break; #endregion } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Calculate age from a comntrol /// /// /// private void CalculateAge(string sourceID, string destinationID) { oAge age = new oAge(); TextBox sourceTextBox = (TextBox)pnlSurfaceForm.FindControl(sourceID); TextBox destinationTextBox = (TextBox)pnlSurfaceForm.FindControl(destinationID); if (sourceTextBox != null && sourceTextBox.Text != String.Empty && destinationTextBox != null) { age = utils.FormatAge(utils.formatStringToDate(sourceTextBox.Text), DateTime.Now); destinationTextBox.Text = age.years.ToString(); } } private string CalculateLookup(oSurfaceField lookupField, decimal sourceValue) { //assuming the source field and Bottom and Top fields numberic types, using decimals string value = ""; try { int lookupSurfaceId = 0; int.TryParse(lookupField.actionValue, out lookupSurfaceId); if (lookupSurfaceId <= 0) return value; DataTable dtLookup = xData.GetSurfaceDataAll(lookupSurfaceId, true); //rename columns for easer processing foreach (DataColumn col in dtLookup.Columns) { if (col.ColumnName.EndsWith("_Bottom")) col.ColumnName = "Bottom"; else if (col.ColumnName.EndsWith("_Top")) col.ColumnName = "Top"; else if (col.ColumnName.EndsWith("_Lookup")) col.ColumnName = "Lookup"; } if (dtLookup.Columns["Bottom"] == null || dtLookup.Columns["Top"] == null || dtLookup.Columns["Lookup"] == null) return value; dtLookup.DefaultView.Sort = "Bottom"; int counter = 0; foreach (DataRow row in dtLookup.Rows) { //bottom can be invalid when counter is 0, top can be invalid when counter is number of rows decimal bottom = 0m; if (!decimal.TryParse(row["Bottom"].ToString(), out bottom) && counter != 0) continue; decimal top = 0m; if (!decimal.TryParse(row["Top"].ToString(), out top) && counter != (dtLookup.Rows.Count - 1)) continue; if (counter == 0) { if (sourceValue <= top) { value = row["Lookup"].ToString(); break; } } else if (counter == dtLookup.Rows.Count - 1) { if (sourceValue >= bottom) { value = row["Lookup"].ToString(); break; } } else { if (sourceValue >= bottom && sourceValue <= top) { value = row["Lookup"].ToString(); break; } } counter++; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return value; } private string CalculateLookup(DataRow lookupFieldRow, decimal sourceValue) { //assuming the source field and Bottom and Top fields numberic types, using decimals string value = ""; try { int lookupSurfaceId = 0; int.TryParse(lookupFieldRow["actionValue"].ToString(), out lookupSurfaceId); if (lookupSurfaceId <= 0) return value; DataTable dtLookup = xData.GetSurfaceDataAll(lookupSurfaceId, true); //rename columns for easer processing foreach (DataColumn col in dtLookup.Columns) { if (col.ColumnName.EndsWith("_Bottom")) col.ColumnName = "Bottom"; else if (col.ColumnName.EndsWith("_Top")) col.ColumnName = "Top"; else if (col.ColumnName.EndsWith("_Lookup")) col.ColumnName = "Lookup"; } if (dtLookup.Columns["Bottom"] == null || dtLookup.Columns["Top"] == null || dtLookup.Columns["Lookup"] == null) return value; dtLookup.DefaultView.Sort = "Bottom"; int counter = 0; foreach (DataRow row in dtLookup.Rows) { //bottom can be invalid when counter is 0, top can be invalid when counter is number of rows decimal bottom = 0m; if (!decimal.TryParse(row["Bottom"].ToString(), out bottom) && counter != 0) continue; decimal top = 0m; if (!decimal.TryParse(row["Top"].ToString(), out top) && counter != (dtLookup.Rows.Count - 1)) continue; if (counter == 0) { if (sourceValue <= top) { value = row["Lookup"].ToString(); break; } } else if (counter == dtLookup.Rows.Count - 1) { if (sourceValue >= bottom) { value = row["Lookup"].ToString(); break; } } else { if (sourceValue >= bottom && sourceValue <= top) { value = row["Lookup"].ToString(); break; } } counter++; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return value; } private void SetPatientType(string sourceID) { try { DropDownList ddlSource = (DropDownList)pnlSurfaceForm.FindControl(sourceID); if (ddlSource != null) { if (ddlSource.SelectedItem.Text.Contains("Adult")) Session["PatientType"] = (int)pNums.PatientType.Adult; else Session["PatientType"] = (int)pNums.PatientType.Paediatric; SetCustomVisible(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Based on the Room Type for TPS, use the customCode field to get the room count value /// /// private void SetRoomTypeCountTextField(DropDownList list) { string recID = list.SelectedValue.ToString(); DataTable dtData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookup), "recId", recID); if (dtData.TableIsValid()) // Check if the table contains data { string customCode = String.IsNullOrWhiteSpace(dtData.Rows[0]["CustomCode"].ToString()) ? "1" : dtData.Rows[0]["CustomCode"].ToString(); switch (list.ID) { #region Bedrooms_Bedrooms_BedroomTypes case "Bedrooms_Bedrooms_BedroomTypes": TextBox txtBedroomCount = (TextBox)pnlSurfaceForm.FindControl("Bedrooms_Bedrooms_Count"); if (!(txtBedroomCount == null)) txtBedroomCount.Text = customCode; break; #endregion #region PropertySetup_Bathrooms_BathroomTypes //case "PropertySetup_Bathrooms_BathroomTypes": // TextBox txtBathroomCount = (TextBox)pnlSurfaceForm.FindControl("PropertySetup_PropertySetupGroup_Count"); // if (!(txtBathroomCount == null)) // txtBathroomCount.Text = customCode; // break; case "Bathrooms_Bathrooms_BathroomTypes": TextBox txtBathroomCount = (TextBox)pnlSurfaceForm.FindControl("PropertySetup_PropertySetupGroup_Count"); if (!(txtBathroomCount == null)) txtBathroomCount.Text = customCode; break; #endregion #region ReceptionRooms_ReceptionRooms_ReceptionRoomTypes case "ReceptionRooms_ReceptionRooms_ReceptionRoomTypes": TextBox txtReceptionRoomCount = (TextBox)pnlSurfaceForm.FindControl("ReceptionRooms_ReceptionsRooms_Count"); if (!(txtReceptionRoomCount == null)) txtReceptionRoomCount.Text = customCode; break; #endregion #region Garages_Garages_Garages case "Garages_Garages_Garages": TextBox txtGarageCount = (TextBox)pnlSurfaceForm.FindControl("Garages_Garages_Count"); if (!(txtGarageCount == null)) txtGarageCount.Text = customCode; break; #endregion #region OtherRooms_OtherRooms_OtherRoomTypes case "OtherRooms_OtherRooms_OtherRoomTypes": TextBox txtOtherRoomCount = (TextBox)pnlSurfaceForm.FindControl("OtherRooms_OtherRooms_Count"); if (!(txtOtherRoomCount == null)) txtOtherRoomCount.Text = customCode; break; #endregion default: break; } } } /// /// Calculate birthday from a Id Number /// /// /// private void CalculatebirthdayFromID(string sourceID, string destinationID) { oAge age = new oAge(); TextBox sourceTextBox = (TextBox)pnlSurfaceForm.FindControl(sourceID); TextBox destinationTextBox = (TextBox)pnlSurfaceForm.FindControl(destinationID); if (sourceTextBox != null && destinationTextBox != null) { destinationTextBox.Text = utils.FormatBirthdayFromID(sourceTextBox.Text).ToString("dd/MM/yyyy"); } } /// /// Method to retain the selected tab open /// /// private void KeepSelectedGridTab(Repeater repeater) { if (base.SurfaceApp != null) { if (MainGridOptions.isTabbed) { int tabId = int.Parse(repeater.ID.Replace("rpt", "")); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); int tabCounter = 0; foreach (oSurfaceField tab in fieldTabs) { tabCounter++; if (tab.recId == tabId) { string script = "$('#gSurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ClickGridTab", script, true); break; } } } } } /// /// Method to Build User Control /// /// private static void BuildControl(oSurface surface) { foreach (oModule moduleItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", ((int)pNums.Module.Surface).ToString())) { surfaceHandler.BuildSurfaceAppTemplate(surface, controlPath + moduleItem.control, surfacePath, true); } } private void NewItem() { oSurface surfaceApp = base.SurfaceApp; base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.ActiveTabPanel = String.Empty; oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surfaceApp.recId; bool exitEarly = false; //JR 2017-0-27 check if any conditions are stopping the form to populate if (handler.ReturnSetup().code == "STUD-1") { foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId,actionType", item.surfaceId + ",1," + ((int)pNums.FieldType.FormulaField).ToString() + "," + ((int)pNums.ActionType.GenerateCode).ToString())) { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; List sicParams = new List(); oDynamicParam sicParam = new oDynamicParam(); sicParam.paramDisplayName = "userId"; sicParam.paramObject = userId; sicParams.Add(sicParam); DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); if (nextCodeTable.Rows.Count == 0) { //no number, so warn and close Label lblModCleanTitle = (Label)FindControl("lblModCleanTitle"); Literal litModCleanBody = (Literal)FindControl("litModCleanBody"); if (lblModCleanTitle != null && litModCleanBody != null) { lblModCleanTitle.Text = "All Exam Numbers used"; StringBuilder sb = new StringBuilder(); sb.AppendLine("Please note that there are no more Exam Numbers available to your user profile. Please contact Merle or Zaakirah to re-issue Exam Numbers to your profile."); litModCleanBody.Text = sb.ToString(); } exitEarly = true; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showModClean", "$('#modClean" + base.SurfaceApp.name + "').modal();", true); } } } if (!exitEarly) { //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(item, true); } else { PopulateSurfaceForm(item, true); } TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } } private void SetCustomVisible() { try { if (utils.verifySession("PatientType")) { bool isAdult = Convert.ToInt32(Session["PatientType"].ToString()) == (int)pNums.PatientType.Adult; bool isPaediatric = Convert.ToInt32(Session["PatientType"].ToString()) == (int)pNums.PatientType.Paediatric; pNums.PatientType patientType = (pNums.PatientType)Convert.ToInt32(Session["PatientType"].ToString()); //find all controls to hide if certain patient type Control divControl; divControl = FindControl("srtPatientInformation_PatientDetails_IDPassportNumber"); if (divControl != null) divControl.Visible = isAdult; //divControl = FindControl("srtPatientInformation_PatientDetails_MobileNumber"); //if (divControl != null) // divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_TelephoneH"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_TelephoneW"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_EmailAddress"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_NumberofChildren"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_AgesofChildren"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_EmployerName"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_Occupation"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PatientDetails_Age"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PatientDetails_BirthHeightcm"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PatientDetails_BirthWeightkg"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PatientDetails_CurrentHeightcm"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PatientDetails_CurrentWeightkg"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PatientDetails_Placeholder"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("divfPatientInformation_MotherDetails"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("divfPatientInformation_FatherDetails"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("divfPatientInformation_SpouseDetailsifapplicable"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PersonResponsibleforAccountPayment_CopyFromPatient"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PersonResponsibleforAccountPayment_CopyFromSpouse"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_PersonResponsibleforAccountPayment_CopyFromMother"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_PersonResponsibleforAccountPayment_CopyFromFather"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_EmergencyContact_CopyFromSpouse"); if (divControl != null) divControl.Visible = isAdult; divControl = FindControl("srtPatientInformation_EmergencyContact_CopyFromMother"); if (divControl != null) divControl.Visible = isPaediatric; divControl = FindControl("srtPatientInformation_EmergencyContact_CopyFromFather"); if (divControl != null) divControl.Visible = isPaediatric; if (FindControl("upPatientInformation_PatientDetails") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_PatientDetails"); up.Update(); } if (FindControl("upPatientInformation_SpouseDetailsifapplicable") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_SpouseDetailsifapplicable"); up.Update(); } if (FindControl("upPatientInformation_FatherDetails") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_FatherDetails"); up.Update(); } if (FindControl("upPatientInformation_MotherDetails") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_MotherDetails"); up.Update(); } if (FindControl("upPatientInformation_PersonResponsibleforAccountPayment") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_PersonResponsibleforAccountPayment"); up.Update(); } if (FindControl("upPatientInformation_EmergencyContact") != null) { UpdatePanel up = (UpdatePanel)FindControl("upPatientInformation_EmergencyContact"); up.Update(); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void BindCompareDropdowns(oSurface surface, string parentSurface = "") { try { oSurfaceField filterField = null; foreach (oSurfaceField surfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isFilter,isComparable", surface.recId.ToString() + ",1,1", "sequence")) { filterField = surfaceField; break; } if (filterField != null) { for (int i = 1; i <= surface.columnCount; i++) { DropDownList ddlCompare = null; DataView dv = null; if (parentSurface != "") { if (pnlSurfaceCompare.FindControl("ddlCompare_" + i.ToString() + "__" + surface.recId.ToString() + "__" + parentSurface) != null) ddlCompare = (DropDownList)pnlSurfaceCompare.FindControl("ddlCompare_" + i.ToString() + "__" + surface.recId.ToString() + "__" + parentSurface); } else { if (pnlSurfaceCompare.FindControl("ddlCompare_" + i.ToString() + "__" + surface.recId.ToString()) != null) ddlCompare = (DropDownList)pnlSurfaceCompare.FindControl("ddlCompare_" + i.ToString() + "__" + surface.recId.ToString()); } if (base.IsChildSurface) { DataTable surfaceData = new DataTable(); surfaceData = xData.GetChildSurfaceQueryData(base.SurfaceApp.recId, base.ParentSurfaceItemId, 0); dv = surfaceData.DefaultView; ddlCompare.DataSource = surfaceData; ddlCompare.DataValueField = "itemID"; ddlCompare.DataTextField = filterField.surfaceFieldName; dv = surfaceData.DefaultView; dv.Sort = filterField.surfaceFieldName + " DESC"; if (filterField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { surfaceData.Columns.Add("dateField", typeof(DateTime), filterField.surfaceFieldName); ddlCompare.DataTextField = "dateField"; ddlCompare.DataTextFormatString = "{0:dd/MM/yyyy}"; dv.Sort = filterField.surfaceFieldName + " DESC"; } } else if (parentSurface != "") { if (base.SurfaceAppItem != null) { DataTable surfaceData = new DataTable(); surfaceData = xData.GetChildSurfaceQueryData(surface.recId, base.SurfaceAppItem.recId, 0); dv = surfaceData.DefaultView; ddlCompare.DataValueField = "itemID"; ddlCompare.DataTextField = filterField.surfaceFieldName; if (filterField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { surfaceData.Columns.Add("dateField", typeof(DateTime), filterField.surfaceFieldName); ddlCompare.DataTextField = "dateField"; ddlCompare.DataTextFormatString = "{0:dd/MM/yyyy}"; dv.Sort = filterField.surfaceFieldName + " DESC"; } ddlCompare.DataSource = dv; } } else { DataTable filterList = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID", surface.recId.ToString() + "," + filterField.recId.ToString()); dv = filterList.DefaultView; ddlCompare.DataValueField = "surfaceItemId"; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), filterField.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Date: ddlCompare.DataTextField = "surfaceFieldValueDate"; ddlCompare.DataTextFormatString = "{0:dd/MM/yyyy}"; dv.Sort = "surfaceFieldValueDate DESC"; break; case pNums.FieldType.Text: ddlCompare.DataTextField = "surfaceFieldValueChar"; dv.Sort = "surfaceFieldValueChar"; break; default: break; } ddlCompare.DataSource = dv; } ddlCompare.DataBind(); if (i > 3 && ddlCompare.Items.Count > 3) { ddlCompare.SelectedIndex = 3; ddlCompare_SelectedIndexChanged(ddlCompare, EventArgs.Empty); } else if (i > 2 && ddlCompare.Items.Count > 2) { ddlCompare.SelectedIndex = 2; ddlCompare_SelectedIndexChanged(ddlCompare, EventArgs.Empty); } else if (i > 1 && ddlCompare.Items.Count > 1) { ddlCompare.SelectedIndex = 1; ddlCompare_SelectedIndexChanged(ddlCompare, EventArgs.Empty); } else { ddlCompare_SelectedIndexChanged(ddlCompare, EventArgs.Empty); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Set the last tab used /// private void SetLastTabUsed(ArrayList fieldTabs) { int lastTabUsed = 0; try { int lastWizardTab = 0; int currentWizardTab = 0; int totalWizardTabs = 0; foreach (oSurfaceField tab in fieldTabs) { if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) totalWizardTabs++; } //CVH 2016-11-01 Determine index of last wizard tab for (int i = 0; i < fieldTabs.Count; i++) { oSurfaceField tabLast = (oSurfaceField)fieldTabs[i]; if (!tabLast.isHiddenFromWizzard && ((User.userType >= tabLast.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || User.mimicUserType >= tabLast.accessLevel && User.userType == (int)pNums.UserType.CustomUser)) lastWizardTab = i + 1; //tabCounter is not 0 index } if (base.SurfaceAppItem != null) { lastTabUsed = base.SurfaceAppItem.lastTabCompleted; } int tabCounter = 0; foreach (oSurfaceField tab in fieldTabs)//setup validation group on first next button { tabCounter++; //Label lblHiddenTabIndex = (Label)pnlSurfaceForm.FindControl("lblHiddenTabIndex" + base.SurfaceApp.name); //CVH 2017-03-28 Use cookies to store index, not hidden label //if (HttpContext.Current.Response.Cookies["fsurfaceTabs" + base.SurfaceApp.name] == null) // HttpContext.Current.Response.Cookies.Add(new HttpCookie("fsurfaceTabs" + base.SurfaceApp.name)); //HttpCookie tabCookie = HttpContext.Current.Response.Cookies["fsurfaceTabs" + base.SurfaceApp.name]; //CVH 2016-11-01 Sending all tabs to method, check here for hidden, after counter has been increased //CVH 2016-12-15 Find surface specific label if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) { currentWizardTab++; if (lastTabUsed > 0) { HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (tabCounter == 1 && tab.recId != lastTabUsed)//hide first tab { //lets set this to hidden now myTab.Attributes.Add("style", "display: none"); } else if (tab.recId == lastTabUsed) { btnPrevious.Visible = true; btnCancelWizzard.Visible = false; myTab.Attributes.Remove("style"); //set to active tab panel base.ActiveTabPanel = myTab.ClientID; //tabCookie.Value = (tabCounter - 1).ToString(); HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; //GR 2017-05-07 set hidden tab index for inital page load if (!Page.IsPostBack) { hfTabIndex.Value = (tabCounter - 1).ToString(); } else hfTabIndex.Value = ""; //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickLastTabUsedTrigger", script, true); if (pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName) != null) { Label myLabel = (Label)pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName); if (!myLabel.Text.Contains("(Step ")) myLabel.Text = myLabel.Text + " (Step " + currentWizardTab.ToString() + " of " + totalWizardTabs.ToString() + ")"; } if (tabCounter == lastWizardTab) { btnFinish.Visible = true; btnFinish.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); btnNext.Visible = false; } else { btnFinish.Visible = false; btnNext.Visible = true; btnNext.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); } break; } else { //hide myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); } } else { HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (myTab != null) { if (currentWizardTab == 1) { //CVH 2016-11-01 Cater for scenarios where first tab is not part of wizard myTab.Attributes.Remove("style"); //set to active tab panel base.ActiveTabPanel = myTab.ClientID; //tabCookie.Value = (tabCounter - 1).ToString(); HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; //GR 2017-05-07 set hidden tab index for inital page load if (!Page.IsPostBack) { hfTabIndex.Value = (tabCounter - 1).ToString(); } else hfTabIndex.Value = ""; //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickLastTabUsedTrigger", script, true); if (pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName) != null) { Label myLabel = (Label)pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName); if (!myLabel.Text.Contains("(Step ")) myLabel.Text = myLabel.Text + " (Step " + currentWizardTab.ToString() + " of " + totalWizardTabs.ToString() + ")"; } if (tabCounter == lastWizardTab) { btnFinish.Visible = true; btnFinish.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); btnNext.Visible = false; } else { btnFinish.Visible = false; btnNext.Visible = true; btnNext.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); } } else { //hide myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); } } //CVH 2017-03-02 Loop through all tabs and set not visible after last tab used has been found //break; } } else { //CVH 2016-11-01 Cater for scenarios where first tab is not part of wizard. hide tab HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (myTab != null) myTab.Attributes.Add("style", "display: none"); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Determines the current Active Tab, to be used in MaintainActiveTab, when clicking Save to keep the current active tab and not reset to first tab. /// Only enabling for SBF for now. /// /// private void SetActiveTab(ArrayList fieldTabs) { try { foreach (oSurfaceField tab in fieldTabs) { HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (myTab == null) continue; string temp = myTab.ClientID; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Keep the active tab valid /// private void MaintainActiveTab(ArrayList fieldTabs, bool isView = false) { int tabCounter = 0; bool activeSet = false; string prefix = isView ? "v" : "f"; oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } foreach (oSurfaceField tab in fieldTabs) { tabCounter++; HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); if (myTab == null) continue; if ((usr.userType >= tab.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= tab.accessLevel && usr.userType == (int)pNums.UserType.CustomUser)) { //CVH 2016-11-01 Sending all tabs to method, check here for hidden from wizard, after counter has been incremented if (base.SurfaceApp.isWizzard && !tab.isHiddenFromWizzard) { //HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); //if (myTab == null) // continue; if (!tab.isHiddenFromForm || (isView && !tab.isHiddenFromView)) { if ((base.ActiveTabPanel == null || base.ActiveTabPanel == String.Empty) && !activeSet) { activeSet = true; myTab.Attributes.Remove("style"); //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; string script = "setCurrentTab(" + (tabCounter - 1) + ",'fsurfaceTabs" + base.SurfaceApp.name + "')"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickDefaultTrigger", script, true); btnPrevious.Visible = false; btnCancelWizzard.Visible = true; } else if (myTab.ClientID == base.ActiveTabPanel) { //set to visible myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show')"; //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickActiveTab", script, true); //CVH 2016-11-30 string script = "setCurrentTab(" + (tabCounter - 1) + ",'fsurfaceTabs" + base.SurfaceApp.name + "');"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setCurrentTab1", script, true); } //else //{ // //hide // myTab.Attributes.Remove("style"); // myTab.Attributes.Remove("class"); // myTab.Attributes.Add("class", "tb-item"); // myTab.Attributes.Add("style", "display: none"); //} } //else //{ // //hide // myTab.Attributes.Remove("style"); // myTab.Attributes.Remove("class"); // myTab.Attributes.Add("class", "tb-item"); // myTab.Attributes.Add("style", "display: none"); //} } else if (!base.SurfaceApp.isWizzard || (base.SurfaceAppItem != null && base.SurfaceAppItem.isWizardCompleted)) { //HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); //if (myTab == null) // continue; if ((base.ActiveTabPanel == null || base.ActiveTabPanel == String.Empty) && (!tab.isHiddenFromForm || (isView && !tab.isHiddenFromView)) && !activeSet) { activeSet = true; myTab.Attributes.Remove("style"); string script = "$('#" + prefix + "surfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickDefaultTrigger", script, true); //GR 2017-05-07 set hidden tab index for inital page load HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; if (!Page.IsPostBack) { hfTabIndex.Value = (tabCounter - 1).ToString(); } else hfTabIndex.Value = ""; } else if (myTab.ClientID == base.ActiveTabPanel) { string script = "$('#" + prefix + "surfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickActiveTab", script, true); //GR 2017-05-07 set hidden tab index for inital page load HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; if (!Page.IsPostBack) { hfTabIndex.Value = (tabCounter - 1).ToString(); } else hfTabIndex.Value = ""; } } else { //hide myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); } } else { //HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); //if (myTab == null) // continue; //hide myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); } } } /// /// Method to Set the next tab /// private void SetNextTab(ArrayList fieldTabs) { try { int lastWizardTab = 0; int tabCounter = 0; bool activeFound = false; //CVH 2016-11-01 Determine index of last wizard tab for (int i = 0; i < fieldTabs.Count; i++) { oSurfaceField tabLast = (oSurfaceField)fieldTabs[i]; if (!tabLast.isHiddenFromWizzard && ((User.userType >= tabLast.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tabLast.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) lastWizardTab = i + 1; //tabCounter is not 0 index } int currentWizardTab = 0; int totalWizardTabs = 0; foreach (oSurfaceField tab in fieldTabs) { if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) totalWizardTabs++; } foreach (oSurfaceField tab in fieldTabs) { tabCounter++; HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser)))//included in wizzard { if (myTab != null) { currentWizardTab++; if (activeFound) { btnPrevious.Visible = true; btnCancelWizzard.Visible = false; myTab.Attributes.Remove("style"); base.ActiveTabPanel = myTab.ClientID; //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; string script = "setCurrentTab(" + (tabCounter - 1) + ",'fsurfaceTabs" + base.SurfaceApp.name + "')"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickNextTabTrigger", script, true); if (tabCounter == lastWizardTab) { btnFinish.Visible = true; if (base.SurfaceApp.isDisableRequired && base.SurfaceAppItem.recId > 0) { btnFinish.ValidationGroup = "none"; } else { btnFinish.ValidationGroup = myTab.ID.Replace("li_", ""); } //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); btnNext.Visible = false; } else { btnFinish.Visible = false; btnNext.Visible = true; if (base.SurfaceApp.isDisableRequired && base.SurfaceAppItem.recId > 0) { btnNext.ValidationGroup = "none"; } else { btnNext.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); } } if (pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName) != null) { Label myLabel = (Label)pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName); if (!myLabel.Text.Contains("(Step ")) myLabel.Text = myLabel.Text + " (Step " + currentWizardTab.ToString() + " of " + totalWizardTabs.ToString() + ")"; } //save last tab used in wizard base.SurfaceAppItem.lastTabCompleted = tab.recId; xData.UpdateTyped("recId", base.SurfaceAppItem.recId.ToString(), typeof(oSurfaceItem), base.SurfaceAppItem); //GR 07/05/2017 - This is a horrible hack - needs attention //if (handler.ReturnSetup().code == "GLOB-1") // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefreshNext", "forcePostBack('" + myTab.ClientID + "');", true); break; } else { //if (myTab.Attributes["style"] == null || myTab.Attributes["style"].Length == 0)//found visible tab if (base.ActiveTabPanel == myTab.ClientID)//use activetabpanel to determine where you are { //lets set this to hidden now //myTab.Attributes.Add("style", "display: none"); myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); activeFound = true; } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Set the previous tab /// private void SetPreviousTab(ArrayList fieldTabs) { try { int firstWizardTab = fieldTabs.Count; //CVH 2016-11-01 Determine index of last wizard tab for (int i = fieldTabs.Count - 1; i >= 0; i--) { oSurfaceField tabFirst = (oSurfaceField)fieldTabs[i]; if (!tabFirst.isHiddenFromWizzard && ((User.userType >= tabFirst.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tabFirst.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) firstWizardTab = i; //tabCounter is 0 index } int currentWizardTab = 0; int totalWizardTabs = 0; foreach (oSurfaceField tab in fieldTabs) { if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) totalWizardTabs++; } currentWizardTab = totalWizardTabs + 1; int tabCounter = fieldTabs.Count; bool activeFound = false; fieldTabs.Reverse();//reverse the order to go backwards foreach (oSurfaceField tab in fieldTabs) { tabCounter--; if (!tab.isHiddenFromWizzard && ((User.userType >= tab.accessLevel && User.userType != (int)pNums.UserType.CustomUser) || (User.mimicUserType >= tab.accessLevel && User.userType == (int)pNums.UserType.CustomUser))) { HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (myTab != null) { currentWizardTab--; if (activeFound) { myTab.Attributes.Remove("style"); //string script = "$('#fsurfaceTabs li:eq(" + (tabCounter) + ") a').tab('show');"; string script = "setCurrentTab(" + (tabCounter) + ",'fsurfaceTabs" + base.SurfaceApp.name + "')"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickPreviousTabTrigger", script, true); btnFinish.Visible = false; btnNext.Visible = true; base.ActiveTabPanel = myTab.ClientID; if (tabCounter == firstWizardTab) { btnCancelWizzard.Visible = true; btnPrevious.Visible = false; } else { btnCancelWizzard.Visible = false; btnPrevious.Visible = true; } btnNext.ValidationGroup = myTab.ID.Replace("li_", ""); //valSumSurface.ValidationGroup = myTab.ID.Replace("li_", ""); if (pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName) != null) { Label myLabel = (Label)pnlSurfaceForm.FindControl("lbl_f" + tab.surfaceFieldName); if (!myLabel.Text.Contains("(Step ")) myLabel.Text = myLabel.Text + " (Step " + currentWizardTab.ToString() + " of " + totalWizardTabs.ToString() + ")"; } //GR 07/05/2017 - This is a horrible hack - needs attention //if (handler.ReturnSetup().code == "GLOB-1") // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefreshPrevious", "forcePostBack('" + myTab.ClientID + "');", true); break; } else { if (base.ActiveTabPanel == myTab.ClientID)//use activetabpanel to determine where you are //if (myTab.Attributes["style"] == null || myTab.Attributes["style"].Length == 0)//found visible tab { //lets set this to hidden now //myTab.Attributes.Add("style", "display: none"); myTab.Attributes.Remove("style"); myTab.Attributes.Remove("class"); myTab.Attributes.Add("class", "tb-item"); myTab.Attributes.Add("style", "display: none"); activeFound = true; } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Set the last tab used /// private void SetTabsVisible(ArrayList fieldTabs, bool isView = false) { try { oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; //CVH 2016-10-26 TSP Hardcode tab security for now oSetup setup = handler.ReturnSetup(); string prefix = isView ? "v" : "f"; //int tabCounter = 0; int currentWizardTab = 0; int totalWizardTabs = 0; foreach (oSurfaceField tab in fieldTabs) { if (!tab.isHiddenFromWizzard) totalWizardTabs++; } foreach (oSurfaceField tab in fieldTabs)//setup validation group on first next button { HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); if (myTab == null) continue; if (setup.code == "SHOU-1" || setup.code == "GLOB-1") { //only show wizard tabs to website user. only power and up can see additional tabs if (tab.isHiddenFromWizzard) { if ((usr.userType >= (int)pNums.UserType.PowerUser && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= (int)pNums.UserType.PowerUser && usr.userType == (int)pNums.UserType.CustomUser)) { myTab.Attributes.Remove("style"); } else { if (!myTab.Attributes.ToString().Contains("style")) myTab.Attributes.Add("style", "display: none"); } } else { //CVH 2017-01-10 Also check access level of tab if ((!tab.isHiddenFromForm || (isView && !tab.isHiddenFromView)) && ((usr.userType >= tab.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= tab.accessLevel && usr.userType == (int)pNums.UserType.CustomUser))) { myTab.Attributes.Remove("style"); //set currentWizardTab++; //if (pnlSurfaceForm.FindControl("lbl_" + prefix + tab.surfaceFieldName) != null) //{ // Label myLabel = (Label)pnlSurfaceForm.FindControl("lbl_" + prefix + tab.surfaceFieldName); // if (!myLabel.Text.Contains("(Step ")) // myLabel.Text = myLabel.Text + " (Step " + currentWizardTab.ToString() + " of " + totalWizardTabs.ToString() + ")"; //} } else { if (!myTab.Attributes.ToString().Contains("style")) myTab.Attributes.Add("style", "display: none"); } } } else { //CVH 2017-01-10 Also check access level of tab if ((!tab.isHiddenFromForm || (isView && !tab.isHiddenFromView)) && ((usr.userType >= tab.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= tab.accessLevel && usr.userType == (int)pNums.UserType.CustomUser))) { myTab.Attributes.Remove("style"); } else { if (!myTab.Attributes.ToString().Contains("style")) myTab.Attributes.Add("style", "display: none"); } } //myTab.Attributes.Remove("class"); //myTab.Attributes.Add("class", "tb-item"); //if (tabCounter == 1) //{ // string script = "$('#fsurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show')"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickVisibleTrigger", script, true); //} } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void SetTabsVisibleNoWizard(ArrayList fieldTabs, bool isPageLoad) { try { //CVH left right nav buttons only built on form, not on view string prefix = "f"; int activeTabIndex = 0; string firstTab = ""; oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } //get last visible tab index int lastVisible = -1; foreach (oSurfaceField tab in fieldTabs) { if ((usr.userType >= tab.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= tab.accessLevel && usr.userType == (int)pNums.UserType.CustomUser)) lastVisible++; } int tabCounter = -1; int i = -1; foreach (oSurfaceField tab in fieldTabs) { i++; HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_" + prefix + tab.surfaceFieldName); HtmlGenericControl lblHidden = (HtmlGenericControl)pnlSurfaceForm.FindControl(prefix + tab.surfaceFieldName + "Hidden" + tab.recId); HtmlAnchor btnLeft = (HtmlAnchor)pnlSurfaceForm.FindControl("btn" + tab.surfaceFieldName + "Left"); HtmlAnchor btnRight = (HtmlAnchor)pnlSurfaceForm.FindControl("btn" + tab.surfaceFieldName + "Right"); if (myTab == null || lblHidden == null || btnLeft == null || btnRight == null) continue; if ((usr.userType >= tab.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= tab.accessLevel && usr.userType == (int)pNums.UserType.CustomUser)) { myTab.Visible = true; } else { myTab.Visible = false; continue; } if (firstTab == "" && !isPageLoad) firstTab = "." + prefix + tab.surfaceFieldName + "Hidden" + tab.recId; //check if tab is active if (myTab.Attributes["class"].Contains("active")) activeTabIndex = i; //if tab is visible, increase counter and set navigation properties tabCounter++; lblHidden.InnerText = tabCounter.ToString(); if (tabCounter == 0) { btnLeft.Visible = false; btnRight.Visible = true; } else if (tabCounter == lastVisible) { btnLeft.Visible = true; btnRight.Visible = false; } else { btnLeft.Visible = true; btnRight.Visible = true; } } //CVH 2016-12-15 Get surface specific label //Label lblHiddenTabIndex = (Label)pnlSurfaceForm.FindControl("lblHiddenTabIndex" + base.SurfaceApp.name); ////set tab index, when MaintainActiveTab is called, it will set the correct index //if (lblHiddenTabIndex != null && !isPageLoad) // lblHiddenTabIndex.Text = activeTabIndex.ToString(); //if (firstTab != "") //{ // string script = "setCurrentTabNoWizard('" + firstTab + "','fsurfaceTabs" + base.SurfaceApp.name + "')"; // if (Page.IsPostBack) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setCurrentNoWizardTab", script, true); //} } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void SetToggleViewActionVisibilityCheckboxList(CheckBox chkBox) { //get field name from parent control string parent = string.Empty; if (chkBox.Parent.ID != null) parent = chkBox.Parent.ID; else parent = chkBox.Parent.Parent.ID; ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", parent); if (list != null && list.Count > 0) { oSurfaceField field = (oSurfaceField)list[0]; string actionId = ""; foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "actionType,action", ((int)pNums.ActionType.ToggleView).ToString() + ",Visible")) { actionId = act.recId.ToString(); } foreach (oSurfaceField fieldToAction in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,actionType,action,actionSource", base.SurfaceApp.recId + "," + ((int)pNums.ActionType.ToggleView).ToString() + "," + actionId + "," + field.recId)) { if (chkBox.Text == fieldToAction.actionValue) { Control div = (Control)pnlSurfaceForm.FindControl("divToggleView" + fieldToAction.surfaceFieldName); if (div != null) div.Visible = chkBox.Checked; if (!chkBox.Checked) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), fieldToAction.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Date: case pNums.FieldType.Caption: TextBox txt = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txt.Text = ""; break; case pNums.FieldType.Picklist: DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); ddl.ClearSelection(); break; case pNums.FieldType.MultiPicklist: ListBox lb = (ListBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); lb.ClearSelection(); break; case pNums.FieldType.Checkbox: CheckBox chk = (CheckBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); chk.Checked = false; break; case pNums.FieldType.RadioButtonList: RadioButtonList rbl = (RadioButtonList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); rbl.ClearSelection(); break; case pNums.FieldType.Address: bool found = false; int itemNoClr = 0; do { found = false; itemNoClr++; TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName + itemNoClr); if (txtAddress != null) { txtAddress.Text = ""; found = true; } } while (found && itemNoClr < 50); break; case pNums.FieldType.CheckboxList: //CVH 2017-02-27 When alternateview, checkboxlist is built differently if (fieldToAction.alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxList != null) { checkboxList.SelectedIndex = -1; } } else { //CVH START 20170317 Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxPanel != null) { //CVH 2016-10-11 Clear checked items foreach (Control ctrlClear in checkboxPanel.Controls) { if (ctrlClear.GetType() == typeof(CheckBox)) { CheckBox chkClear = (CheckBox)ctrlClear; chkClear.Checked = false; TextBox txtClear = (TextBox)ctrlClear.Parent.FindControl(chkClear.ID + "Text"); if (txtClear != null) { txtClear.Text = ""; txtClear.Enabled = false; } } } } //CVH END 20170317 } break; case pNums.FieldType.Grid: //no action, not sure if need to clear grid?? copy from master etc. break; } } } } upSurface.Update(); } } private void SetToggleViewActionVisibilityRadioButtonList(RadioButtonList rbl) { //get field name from parent control ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", rbl.ID); if (list != null && list.Count > 0) { oSurfaceField field = (oSurfaceField)list[0]; string actionId = ""; foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "actionType,action", ((int)pNums.ActionType.ToggleView).ToString() + ",Visible")) { actionId = act.recId.ToString(); } foreach (oSurfaceField fieldToAction in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,actionType,action,actionSource", base.SurfaceApp.recId + "," + ((int)pNums.ActionType.ToggleView).ToString() + "," + actionId + "," + field.recId)) { Control div = (Control)pnlSurfaceForm.FindControl("divToggleView" + fieldToAction.surfaceFieldName); if (div != null) { if (rbl.SelectedItem != null && rbl.SelectedItem.Text.Replace(" ", "").Replace(" ", "") == fieldToAction.actionValue) { div.Visible = true; } else { div.Visible = false; //clear the fields when no longer visible, otherwise value is saved pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), fieldToAction.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Date: case pNums.FieldType.Caption: TextBox txt = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txt.Text = ""; break; case pNums.FieldType.Picklist: DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); ddl.ClearSelection(); break; case pNums.FieldType.MultiPicklist: ListBox lb = (ListBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); lb.ClearSelection(); break; case pNums.FieldType.Checkbox: CheckBox chk = (CheckBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); chk.Checked = false; break; case pNums.FieldType.RadioButtonList: RadioButtonList rblist = (RadioButtonList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); rblist.ClearSelection(); break; case pNums.FieldType.Address: bool found = false; int itemNoClr = 0; do { found = false; itemNoClr++; TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName + itemNoClr); if (txtAddress != null) { txtAddress.Text = ""; found = true; } } while (found && itemNoClr < 50); break; case pNums.FieldType.CheckboxList: //CVH 2017-02-27 When alternateview, checkboxlist is built differently if (fieldToAction.alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxList != null) { checkboxList.SelectedIndex = -1; } } else { //CVH START 20170317 Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxPanel != null) { //CVH 2016-10-11 Clear checked items foreach (Control ctrlClear in checkboxPanel.Controls) { if (ctrlClear.GetType() == typeof(CheckBox)) { CheckBox chkClear = (CheckBox)ctrlClear; chkClear.Checked = false; TextBox txtClear = (TextBox)ctrlClear.Parent.FindControl(chkClear.ID + "Text"); if (txtClear != null) { txtClear.Text = ""; txtClear.Enabled = false; } } } } //CVH END 20170317 } break; case pNums.FieldType.Grid: //no action, not sure if needed to clear grid?? copy from master etc. break; } } } } upSurface.Update(); } } private void SetToggleViewActionVisibilityPicklist(DropDownList ddl) { //get field name from parent control ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", ddl.ID); if (list != null && list.Count > 0) { oSurfaceField field = (oSurfaceField)list[0]; string actionId = ""; foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "actionType,action", ((int)pNums.ActionType.ToggleView).ToString() + ",Visible")) { actionId = act.recId.ToString(); } foreach (oSurfaceField fieldToAction in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,actionType,action,actionSource", base.SurfaceApp.recId + "," + ((int)pNums.ActionType.ToggleView).ToString() + "," + actionId + "," + field.recId)) { Control div = (Control)pnlSurfaceForm.FindControl("divToggleView" + fieldToAction.surfaceFieldName); if (div != null) { string valueToMatch = ""; foreach (var val in fieldToAction.actionValue.Split(';')) { valueToMatch += "|" + val + "|"; } if (ddl.SelectedItem != null && valueToMatch.Contains("|" + ddl.SelectedItem.Text.Replace(" ", "").Replace(" ", "") + "|")) { div.Visible = true; } else { div.Visible = false; //clear the fields when no longer visible, otherwise value is saved pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), fieldToAction.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Date: case pNums.FieldType.Caption: TextBox txt = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txt.Text = ""; break; case pNums.FieldType.Picklist: DropDownList ddlToAction = (DropDownList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); ddlToAction.ClearSelection(); break; case pNums.FieldType.MultiPicklist: ListBox lbToAction = (ListBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); lbToAction.ClearSelection(); break; case pNums.FieldType.Checkbox: CheckBox chk = (CheckBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); chk.Checked = false; break; case pNums.FieldType.RadioButtonList: RadioButtonList rblist = (RadioButtonList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); rblist.ClearSelection(); break; case pNums.FieldType.Address: bool found = false; int itemNoClr = 0; do { found = false; itemNoClr++; TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName + itemNoClr); if (txtAddress != null) { txtAddress.Text = ""; found = true; } } while (found && itemNoClr < 50); break; case pNums.FieldType.CheckboxList: //CVH 2017-02-27 When alternateview, checkboxlist is built differently if (fieldToAction.alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxList != null) { checkboxList.SelectedIndex = -1; } } else { //CVH START 20170317 Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); if (checkboxPanel != null) { //CVH 2016-10-11 Clear checked items foreach (Control ctrlClear in checkboxPanel.Controls) { if (ctrlClear.GetType() == typeof(CheckBox)) { CheckBox chkClear = (CheckBox)ctrlClear; chkClear.Checked = false; TextBox txtClear = (TextBox)ctrlClear.Parent.FindControl(chkClear.ID + "Text"); if (txtClear != null) { txtClear.Text = ""; txtClear.Enabled = false; } } } } //CVH END 20170317 } break; case pNums.FieldType.Grid: //no action, not sure if needed to clear grid?? copy from master etc. break; } } } } upSurface.Update(); } } private bool SaveBubbleData(oSurfaceItem surfaceItem) { ArrayList surfaceData = new ArrayList(); //new data to save //first fetch the field and data records ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceItem.surfaceId + "", "sequence"); DataTable surfaceFieldData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", surfaceItem.surfaceId + "," + surfaceItem.recId, "recId"); DataTable myDataTable = new DataTable(); myDataTable = surfaceFieldData.Clone(); //CVH 2017-02-07 Determine Divide Action to be used in formula field oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction lookupFieldAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); foreach (oSurfaceAction act in xData.GetTypedCollection("recId", typeof(oSurfaceAction))) { if (act.actionType == (int)pNums.ActionType.Calculation) { if (act.action == "Divide") divideAction = act; else if (act.action == "Lookup") lookupAction = act; else if (act.action == "Lookup Field") lookupFieldAction = act; } else if (act.actionType == (int)pNums.ActionType.Aggregation) { if (act.action == "Sum") aggrSumAction = act; } } //TSP string firstName = "", surname = "", email = "", patientNumber = "", contactNumber = "", registrationDate = ""; foreach (oSurfaceField field in surfaceFields) { oSurfaceFieldData fieldData = new oSurfaceFieldData(); myDataTable.Clear(); //get the data for this field ID var v = from enVal in surfaceFieldData.AsEnumerable() where (enVal.Field("surfaceFieldID") == field.recId) select enVal; v.CopyToDataTable(myDataTable, LoadOption.OverwriteChanges); foreach (oSurfaceFieldData fd in utils.ConvertDataTableToList(myDataTable, typeof(oSurfaceFieldData))) { fieldData = fd; break; } fieldData.surfaceFieldID = field.recId; fieldData.surfaceId = surfaceItem.surfaceId; fieldData.surfaceItemId = surfaceItem.recId; if (field.surfaceFieldTypeId != (int)pNums.FieldType.Tab && field.surfaceFieldTypeId != (int)pNums.FieldType.Group && field.isActive) { pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtTextbox != null) { if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupFieldAction.recId) { List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = field.recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = surfaceItem.recId; listLookup.Add(look2); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) { txtTextbox.Text = dtValue.Rows[0][0].ToString(); fieldData.surfaceFieldValueChar = txtTextbox.Text; } else { txtTextbox.Text = ""; fieldData.surfaceFieldValueChar = ""; } } else { if (field.isUnique)//check for unique { string textToCheck = txtTextbox.Text; if (IsDuplicate(fieldData.surfaceItemId, field, textToCheck)) return false; } fieldData.surfaceFieldValueChar = txtTextbox.Text; //TSP - JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_FirstNames") firstName = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_Surname") surname = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_EmailAddress") email = txtTextbox.Text; if (field.surfaceFieldName == "PatientInformation_PatientDetails_MobileNumber") contactNumber = txtTextbox.Text; } } break; case pNums.FieldType.Number: //number TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtNumberBox != null) { if (field.surfaceFieldName != "ParentSurfaceItemId") { //CVH 2017-02-24 New action type Aggregation Sum if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, surfaceItem.recId); int intTemp = 0; if (!int.TryParse(Math.Truncate(decFormula).ToString(), out intTemp)) intTemp = 0; fieldData.surfaceFieldValueNum = intTemp; } } else { if (field.isUnique)//check for unique { string textToCheck = txtNumberBox.Text; if (IsDuplicate(fieldData.surfaceItemId, field, textToCheck, true)) return false; } int valueNum = 0; int.TryParse(txtNumberBox.Text, out valueNum); fieldData.surfaceFieldValueNum = valueNum; if (field.isControlled && valueNum > Convert.ToInt32(field.controlledValue)) { int nextNumber = 0; int.TryParse(field.controlledValue, out nextNumber); nextNumber++; field.controlledValue = nextNumber.ToString(); xData.UpdateTyped("recId", field.recId.ToString(), typeof(oSurfaceField), field); } //TSP - JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_PatientNumber") patientNumber = valueNum.ToString(); } } else if (field.surfaceFieldName == "ParentSurfaceItemId") { fieldData.surfaceFieldValueNum = base.ParentSurfaceItemId; } } break; case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtDecimalBox != null) { //CVH 2017-02-24 New action type Aggregation Sum if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) { fieldData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, surfaceItem.recId); } } else //CVH 2017-02-07 Divide Calculation Formula need to calculate and save it on form save if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) { decimal? source1 = null; decimal? source2 = null; //need to do calculation based on two source fields foreach (oSurfaceField sourceField in surfaceFields) { int src2FieldId = 0; int.TryParse(field.actionValue, out src2FieldId); decimal divideTemp = 0; if (sourceField.recId == field.actionSource) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source1 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source1 = divideTemp; } break; } } else if (src2FieldId > 0 && sourceField.recId == src2FieldId) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source2 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source2 = divideTemp; } break; } } } if (source1 != null && source2 != null && source2 != 0) fieldData.surfaceFieldValueDecimal = (source1.Value / source2.Value); else fieldData.surfaceFieldValueDecimal = 0; } else { decimal valueDecimal = 0; decimal.TryParse(txtDecimalBox.Text, out valueDecimal); fieldData.surfaceFieldValueDecimal = valueDecimal; } } break; case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { if (field.relationalObject.Length > 0 && field.relationalObject != "0")//module picklist { if (field.relationalObject == "oSurface" && ddDropdownlist.SelectedItem != null) fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedItem.Text; else fieldData.surfaceFieldValueChar = ddDropdownlist.SelectedValue.ToString(); } else { int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); fieldData.surfaceFieldLookupID = lookupId; TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); if (txtReason != null) fieldData.surfaceFieldValueChar = txtReason.Text; } } break; case pNums.FieldType.MultiPicklist: ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (listBox != null) { string lbSelectedValues = string.Empty; foreach (ListItem item in listBox.Items) { if (item.Selected) { if (lbSelectedValues == String.Empty) lbSelectedValues = item.Value.ToString(); else lbSelectedValues += "," + item.Value; } } fieldData.surfaceFieldValueChar = lbSelectedValues; } break; case pNums.FieldType.Date: //date TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtDate != null) { if (txtDate.Text != String.Empty) fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text); //TSP JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_RegistrationDate") registrationDate = txtDate.Text; } break; case pNums.FieldType.Checkbox: //checkbox CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (chkBox != null) { //TSP JasR 2016-01-10 ReDo without hardcoding if (field.surfaceFieldName == "PatientInformation_PatientDetails_EmailSent") { mailSent = chkBox.Checked; chkBox.Checked = true; } fieldData.surfaceFieldValueBool = chkBox.Checked; } break; case pNums.FieldType.Grid: //grid //no action - no data saved, it shows user control of grid surface app break; case pNums.FieldType.RadioButtonList: //radiobuttonlist //HtmlGenericControl radiodiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName); RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(field.surfaceFieldName); //DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (radioButtonList != null) { //RadioButton rb = radiodiv.Controls.OfType() // .FirstOrDefault(r => r.Checked); int rbSelectedID = 0; int.TryParse(radioButtonList.SelectedValue, out rbSelectedID); fieldData.surfaceFieldLookupID = rbSelectedID; TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + field.surfaceFieldName); if (txtReason != null) fieldData.surfaceFieldValueChar = txtReason.Text; } break; case pNums.FieldType.Placeholder: //no action break; //JasR 2016-01-27 Caption case pNums.FieldType.Caption: TextBox txtCaption = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtCaption != null) { fieldData.surfaceFieldValueChar = txtCaption.Text; } break; //JR Bas-Pro-4 case pNums.FieldType.FormulaField: TextBox txtFieldBox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtFieldBox != null) { //CVH 2017-02-07 Divide Calculation Formula need to calculate and save it on form save if (field.actionType == (int)pNums.ActionType.Calculation && field.action == divideAction.recId) { decimal? source1 = null; decimal? source2 = null; //need to do calculation based on two source fields foreach (oSurfaceField sourceField in surfaceFields) { int src2FieldId = 0; int.TryParse(field.actionValue, out src2FieldId); decimal divideTemp = 0; if (sourceField.recId == field.actionSource) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source1 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source1 = divideTemp; } break; } } else if (src2FieldId > 0 && sourceField.recId == src2FieldId) { switch ((pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId)) { case pNums.FieldType.Text: TextBox txtDivideTextbox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideTextbox != null) { if (decimal.TryParse(txtDivideTextbox.Text, out divideTemp)) source2 = divideTemp; } break; case pNums.FieldType.Number: case pNums.FieldType.Decimal: TextBox txtDivideBox = (TextBox)pnlSurfaceForm.FindControl(sourceField.surfaceFieldName); if (txtDivideBox != null) { if (decimal.TryParse(txtDivideBox.Text, out divideTemp)) source2 = divideTemp; } break; } } } if (source1 != null && source2 != null && source2 != 0) txtFieldBox.Text = utils.returnFormattedDecimal((source1 / source2).ToString()); else txtFieldBox.Text = ""; } //CVH 2017-02-13 Lookup Calculation Formula else if (field.actionType == (int)pNums.ActionType.Calculation && field.action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; //get source field foreach (oSurfaceField srcField in surfaceFields) { if (srcField.recId == field.actionSource) { TextBox txtSrc = (TextBox)pnlSurfaceForm.FindControl(srcField.surfaceFieldName); if (txtSrc != null) { conversionSuccess = decimal.TryParse(txtSrc.Text, out sourceValue); } break; } } if (conversionSuccess) { fieldData.surfaceFieldValueChar = CalculateLookup(field, sourceValue); } } //CVH 2017-02-24 New action type Aggregation Sum else if (field.actionType == (int)pNums.ActionType.Aggregation && field.action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(field.actionValue, out actionSurfaceId)) fieldData.surfaceFieldValueDecimal = xData.GetSurfaceAggregationSum(actionSurfaceId, field.actionSource, surfaceItem.recId); } else { decimal valueDecimal = 0; if (decimal.TryParse(txtFieldBox.Text, out valueDecimal)) { fieldData.surfaceFieldValueDecimal = valueDecimal; } else //assume textbox { fieldData.surfaceFieldValueChar = txtFieldBox.Text; } } } break; case pNums.FieldType.Address: TextBox txtAddress1 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "1"); TextBox txtAddress2 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "2"); TextBox txtAddress3 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "3"); TextBox txtAddress4 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "4"); TextBox txtAddress5 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "5"); TextBox txtAddress6 = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName + "6"); string addressFull = string.Empty; if (txtAddress1 != null) addressFull += "~1~" + txtAddress1.Text + "~|~"; else addressFull += "~|~"; if (txtAddress2 != null) addressFull += "~2~" + txtAddress2.Text + "~|~"; else addressFull += "~|~"; if (txtAddress3 != null) addressFull += "~3~" + txtAddress3.Text + "~|~"; else addressFull += "~|~"; if (txtAddress4 != null) addressFull += "~4~" + txtAddress4.Text + "~|~"; else addressFull += "~|~"; if (txtAddress5 != null) { /* CVH 2016-08-15 Default Country field to South Africa for now */ if (txtAddress5.Text == String.Empty) addressFull += "~5~South Africa~|~"; else addressFull += "~5~" + txtAddress5.Text + "~|~"; } else { addressFull += "~|~"; } if (txtAddress6 != null) addressFull += "~6~" + txtAddress6.Text; //remove the last "~|~" if line 4 is empty if (addressFull.Substring(addressFull.Length - 4).Equals("~|~") && addressFull.Length > 4) addressFull = addressFull.Substring(0, addressFull.Length - 4); fieldData.surfaceFieldValueChar = addressFull; break; case pNums.FieldType.CheckboxList: //checkboxlist /* CVH 2016-09-27 Cater for wants reason. alternateView does not use wantsReason */ if (field.alternateView) { CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (checkboxList != null) { string checkedValues = ""; foreach (ListItem item in checkboxList.Items) { if (item.Selected) { checkedValues += item.Value.ToString() + "~R~~|~"; } } fieldData.surfaceFieldValueChar = checkedValues; } } else { Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (checkboxPanel != null) { string checkedValues = ""; foreach (Control ctrl in checkboxPanel.Controls) { if (ctrl.GetType() == typeof(CheckBox)) { CheckBox chk = (CheckBox)ctrl; if (chk.Checked) { string chkVal = ""; string chkReason = ""; if (chk.ID.LastIndexOf("_") > 0) { chkVal = chk.ID.Substring(chk.ID.LastIndexOf("_") + 1); //get reason TextBox txt = (TextBox)chk.Parent.FindControl(chk.ID + "Text"); if (txt != null) chkReason += txt.Text; } checkedValues += chkVal + "~R~" + chkReason + "~|~"; } else { checkedValues += "~R~~|~"; } } } fieldData.surfaceFieldValueChar = checkedValues; } } break; case pNums.FieldType.Control: //CVH 2017-06-09 Reload controls, otherwise they stay initialized with surfaceItemId = 0, and will create new surface item for each control field on that surface form oSurfaceFieldData controlData = new oSurfaceFieldData(); controlData.surfaceId = surfaceItem.surfaceId; controlData.surfaceItemId = surfaceItem.recId; controlData.surfaceFieldID = field.recId; ArrayList ctrlList = new ArrayList(); ctrlList.Add(controlData); SetSurfaceControlState(surfaceItem, ctrlList, field); break; } } surfaceData.Add(fieldData); } int userId = 0; if (utils.verifySession("user")) { oUser user = (oUser)Session["user"]; if (user.userType == (int)pNums.UserType.WebsiteUser && !mailSent) { mailSent = SendRegistrationEmail(firstName, surname, email, patientNumber, contactNumber, registrationDate); } userId = user.recId; } foreach (oSurfaceFieldData data in surfaceData) { data.surfaceItemId = surfaceItem.recId; } xData.SaveTypedCollection("recId", typeof(oSurfaceFieldData), surfaceData); xData.SaveSurfaceItemToQueryTable(surfaceItem.surfaceId, surfaceItem.recId); return true; } /// /// Persist the Placeholder /// private void PersistChildApp() { try { if (base.ChildAppItem != null && base.IsChildSurface) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", base.ChildAppItem.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".ascx"))) { BuildControl(gridSurface); } ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + ".ascx"); uc.ID = gridSurface.name + base.ChildAppItem.recId; uc.SurfaceApp = gridSurface; uc.ParentSurfaceItemId = base.SurfaceAppItemId; uc.ParentSurfaceId = base.SurfaceApp.recId; uc.SurfaceAppItem = base.ChildAppItem; uc.SurfaceAppItemId = base.ChildAppItem.recId; uc.IsClone = base.ChildIsClone; uc.IsChildSurface = true; Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); if (pnlSurfaceFieldModal != null) pnlSurfaceFieldModal.Visible = false; string sub = String.Empty; if (base.IsChildSurface) { sub = "Sub"; uc.IsSubChildSurface = true; } PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; if (plcChildApp != null) { plcChildApp.Controls.Clear(); plcChildApp.Controls.Add(uc); lblChildAppTitle.Text = gridSurface.surface; uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, true); //BindChildGrid(base.SurfaceApp.recId); upChildApp.Update(); BindChildGrid(gridSurface); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Persuist Child Edit if Inline Editing in child /// /// private void PersistChildEdit(int itemId) { if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), opt.surfaceGridEditTypeId); switch (editType) { case pNums.SurfaceGridEditType.Form: foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".ascx"))) { BuildControl(gridSurface); } //GR 2017-03-12 setup surface parcel for jquery load **** //oSurfaceControlParcel parcel = new oSurfaceControlParcel(); ////string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; //parcel.ControlPath = surfacePath + gridSurface.name + ".ascx"; //parcel.ID = gridSurface.name + 0; //parcel.SurfaceApp = gridSurface; //parcel.SurfaceAppItem = item; //parcel.SurfaceAppItemId = item.recId; //parcel.ParentSurfaceItemId = base.SurfaceAppItemId; //parcel.ParentSurfaceId = base.SurfaceApp.recId; //parcel.IsChildSurface = true; //string sub = String.Empty; //if (base.IsChildSurface) //{ // sub = "Sub"; // parcel.IsSubChildSurface = true; //} //parcel.IsView = false; //parcel.IsNew = false; //LoadSurfaceControl(parcel); //Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; //UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; //base.ChildAppItem = item; //base.ChildIsView = false; //base.ChildIsNew = false; //upChildApp.Update(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //GR 2017-03-12 setup surface parcel for jquery load END **** ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + ".ascx"); uc.ID = gridSurface.name + item.recId; uc.SurfaceApp = gridSurface; uc.ParentSurfaceItemId = base.SurfaceAppItemId; uc.ParentSurfaceId = base.SurfaceApp.recId; uc.SurfaceAppItem = item; uc.SurfaceAppItemId = item.recId; uc.IsChildSurface = true; Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); if (pnlSurfaceFieldModal != null) pnlSurfaceFieldModal.Visible = false; string sub = String.Empty; if (base.IsChildSurface) { sub = "Sub"; uc.IsSubChildSurface = true; } PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; if (plcChildApp != null) { plcChildApp.Controls.Clear(); plcChildApp.Controls.Add(uc); lblChildAppTitle.Text = gridSurface.surface; base.ChildAppItem = item; base.ChildIsView = false; base.ChildIsNew = false; uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew); upChildApp.Update(); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); } break; } } } } } /// /// used for repeater aggregates /// /// /// /// protected string getTotalFor(string field, string formatString) { decimal value = 0; SurfaceGridTotals.TryGetValue(field, out value); return value.ToString(formatString); } protected string getAverageFor(string field, string formatString) { decimal value = 0; SurfaceGridAverages.TryGetValue(field, out value); return value.ToString(formatString); } private void sumDataTable(DataTable dt) { try { //CVH 2017-03-01 Otherwise division by 0 if (dt.Rows.Count > 0) { List totalsKeyList = new List(SurfaceGridTotals.Keys); for (int i = 0; i < dt.Rows.Count; ++i) { foreach (string key in totalsKeyList) { if (dt.Columns.Contains(key) && dt.Rows[i][key].ToString() != "") SurfaceGridTotals[key] += Convert.ToDecimal(dt.Rows[i][key].ToString()); } } List averagesKeyList = new List(SurfaceGridAverages.Keys); foreach (string key in averagesKeyList) { SurfaceGridAverages[key] = (SurfaceGridTotals[key]) / (dt.Rows.Count); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Pro-5 /// /// /// private string FindNoteCustomValue(string customValue) { // DS - 23 June 2017 - unComment for now switch (customValue) { case "Landlords": DropDownList ddlCurrentLandlord = (DropDownList)pnlSurfaceForm.FindControl("Landlord_LandlordDetails_Landlord"); string landlordID = (ddlCurrentLandlord == null) ? "" : ddlCurrentLandlord.SelectedValue; customValue = $"{customValue}_{landlordID}"; break; case "Tenants": DropDownList ddlCurrentTenant = (DropDownList)pnlSurfaceForm.FindControl("Tenant_CurrentTenant_Tenant"); string tenantID = (ddlCurrentTenant == null) ? "" : ddlCurrentTenant.SelectedValue; customValue = $"{customValue}_{tenantID}"; break; case "LeaseManagement": int ipropID = base.SurfaceAppItem.recId; customValue = $"{customValue}_{ipropID}"; break; default: break; } return customValue; } #endregion #region custom methods /// /// Populate the surface form for custom controls /// General field rules still get applied /// However data is populated from the object /// NB** May require some additonal custom tweaking to suit your custom app needs /// GR 2017-06-12 /// Custom SurfaceApp Upgrade ability /// private void PopulateSurfaceFormCustom(oSurfaceItem _surfaceItem, bool isNew) { bool wizardcompleted = false; try { bool blnSaveClicked = false; // TPS - We need to ensure that dropdown lists without events don't re-bind and clear the selection of pick lists still to be saved if (ViewState["saveClicked"] != null) blnSaveClicked = (bool)ViewState["saveClicked"]; if (!blnSaveClicked) // Do not allow the re-bind of the surface form in the middle of saving { //fetch the fields to define the rules on from from fields DataTable surfaceFieldsTable = MainFieldTable; var fieldTableEnum = surfaceFieldsTable.AsEnumerable(); oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } oSetup setup = handler.ReturnSetup(); oSurfaceAction divideAction = new oSurfaceAction(); oSurfaceAction lookupAction = new oSurfaceAction(); oSurfaceAction aggrSumAction = new oSurfaceAction(); oSurfaceAction fieldAggrSumAction = new oSurfaceAction(); oSurfaceAction fieldAggrDiffAction = new oSurfaceAction(); oSurfaceAction fieldAggrDistinctionAction = new oSurfaceAction(); oSurfaceAction fieldAggrPassedAction = new oSurfaceAction(); oSurfaceAction fieldAggrFailedAction = new oSurfaceAction(); foreach (DataRow actRow in xData.GetTypedTable("recId", typeof(oSurfaceAction)).Rows) { if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.Calculation) { if (actRow["action"].ToString() == "Divide") { divideAction.action = actRow["action"].ToString(); divideAction.actionType = int.Parse(actRow["actionType"].ToString()); divideAction.isActive = bool.Parse(actRow["isActive"].ToString()); divideAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Lookup") { lookupAction.action = actRow["action"].ToString(); lookupAction.actionType = int.Parse(actRow["actionType"].ToString()); lookupAction.isActive = bool.Parse(actRow["isActive"].ToString()); lookupAction.recId = int.Parse(actRow["recId"].ToString()); } } else if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.Aggregation) { if (actRow["action"].ToString() == "Sum") { aggrSumAction.action = actRow["action"].ToString(); aggrSumAction.actionType = int.Parse(actRow["actionType"].ToString()); aggrSumAction.isActive = bool.Parse(actRow["isActive"].ToString()); aggrSumAction.recId = int.Parse(actRow["recId"].ToString()); } } else if (int.Parse(actRow["actionType"].ToString()) == (int)pNums.ActionType.FieldAggregation) { if (actRow["action"].ToString() == "Sum") { fieldAggrSumAction.action = actRow["action"].ToString(); fieldAggrSumAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrSumAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrSumAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Difference") { fieldAggrDiffAction.action = actRow["action"].ToString(); fieldAggrDiffAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrDiffAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrDiffAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Distinction Count") { fieldAggrDistinctionAction.action = actRow["action"].ToString(); fieldAggrDistinctionAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrDistinctionAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrDistinctionAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Failed Count") { fieldAggrFailedAction.action = actRow["action"].ToString(); fieldAggrFailedAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrFailedAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrFailedAction.recId = int.Parse(actRow["recId"].ToString()); } else if (actRow["action"].ToString() == "Passed Count") { fieldAggrPassedAction.action = actRow["action"].ToString(); fieldAggrPassedAction.actionType = int.Parse(actRow["actionType"].ToString()); fieldAggrPassedAction.isActive = bool.Parse(actRow["isActive"].ToString()); fieldAggrPassedAction.recId = int.Parse(actRow["recId"].ToString()); } } } //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default string groupIdsWithData = ""; #region Header Groups and Groups var groupHeadData = from groupHeads in surfaceFieldsTable.AsEnumerable() where groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.HeaderGroup) || groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groupHeads; foreach (DataRow groupHeadRow in groupHeadData.ToList()) { string _surfaceFieldName = groupHeadRow["surfaceFieldName"].ToString(); int _surfaceFieldTypeId = int.Parse(groupHeadRow["surfaceFieldTypeId"].ToString()); int _accessLevel = 0; int.TryParse(groupHeadRow["accessLevel"].ToString(), out _accessLevel); Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + _surfaceFieldName); bool isHidden = false; bool.TryParse(groupHeadRow["isHidden"].ToString(), out isHidden); if (groupControl != null & !isHidden) { groupControl.Visible = usr.userType >= _accessLevel; } } #endregion #region Label Fields var labelData = from labels in fieldTableEnum where labels.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Label) select labels; foreach (DataRow LabelRow in labelData.ToList()) { //setup field values bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(LabelRow["isControlled"].ToString(), out _isControlled); bool.TryParse(LabelRow["isReadOnly"].ToString(), out _isReadOnly); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _surfaceId = int.Parse(LabelRow["surfaceId"].ToString()); string _surfaceFieldName = LabelRow["surfaceFieldName"].ToString(); string _surfaceFieldDisplay = LabelRow["surfaceFieldDisplay"].ToString(); string _controlText = LabelRow["controlText"].ToString(); if (_controlText != String.Empty) _surfaceFieldDisplay = _controlText; string _relationalSurface = LabelRow["relationalSurface"].ToString(); string _relationalValues = LabelRow["relationalValues"].ToString(); string _relationalFields = LabelRow["relationalFields"].ToString(); bool _defaultToCurrent = false; bool.TryParse(LabelRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(LabelRow["isComparable"].ToString(), out _isComparable); int _surfaceDateTypeId = 0; int.TryParse(LabelRow["surfaceDateTypeId"].ToString(), out _surfaceDateTypeId); int _actionType = 0; int.TryParse(LabelRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(LabelRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(LabelRow["actionSource"].ToString(), out _actionSource); string _actionValue = LabelRow["actionValue"].ToString(); int _recId = int.Parse(LabelRow["recId"].ToString()); string itemId = _surfaceItem.recId.ToString(); if (_isReadOnly)//hide labels on new { Control divControl; divControl = FindControl("srt" + _surfaceFieldName); if (divControl != null) divControl.Visible = false; } else { bool isImage = false; string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; if (_relationalSurface == "user") { foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = user.userDisplay; } } else if (_relationalSurface == "date") { if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1901, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; } } else if (_relationalSurface == "static") { sourceFieldLabel = _surfaceFieldDisplay; sourceFieldValue = _relationalValues; } else { if (itemId != "0") { //just read from char //NB** done in generated code section } else //item doesn't exist, so will have to read label values from source { #region read label from source /* CVH 2017-05-19 Cater for linked surface labels in Form Edit mode */ if (base.SurfaceApp.isLinkedSurface && _relationalSurface != base.SurfaceApp.recId.ToString()) { sourceFieldLabel = _surfaceFieldDisplay; //NB** done in generated code section } else { //jas bool isLabelFromChild = false; if (_relationalSurface != _surfaceItem.surfaceId.ToString()) { foreach (oSurfaceField relSurfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", _relationalFields)) { foreach (oSurfaceField relParentSurfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", relSurfaceField.surfaceId.ToString() + ",parentSurfaceItemId")) { foreach (oSurfaceFieldData parentFieldData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceFieldValueNum", relParentSurfaceField.surfaceId.ToString() + "," + relParentSurfaceField.recId.ToString() + "," + _surfaceItem.recId.ToString())) { isLabelFromChild = true; itemId = parentFieldData.surfaceItemId.ToString(); } } } } //CVH 2017-01-17 Just checking ParentSurfaceItemId>0 not accurate, need to check if the label field surface is the current surface first, otherwise it will always try to find the parent field if it is a child surface, even if the label is pointing to a field on the same surface if (!isLabelFromChild && _relationalSurface != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) itemId = base.ParentSurfaceItemId.ToString(); foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", _relationalSurface.ToString() + "," + _relationalFields.ToString())) { sourceFieldLabel = sourceField.surfaceFieldDisplay; foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", _relationalSurface.ToString() + "," + _relationalFields.ToString() + "," + itemId)) { pNums.FieldType sourceType = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), sourceField.surfaceFieldTypeId); switch (sourceType) { case pNums.FieldType.Text: case pNums.FieldType.Caption: case pNums.FieldType.Address: case pNums.FieldType.MultiPicklist: sourceFieldValue = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Number: sourceFieldValue = sourceData.surfaceFieldValueNum.ToString(); break; case pNums.FieldType.Decimal: sourceFieldValue = sourceData.surfaceFieldValueDecimal.ToString(); break; case pNums.FieldType.Date: string format = "dd/MM/yyyy"; if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) format = "MMMM yyyy"; else if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) format = "yyyy"; sourceFieldValue = sourceData.surfaceFieldValueDate.ToString(format); break; case pNums.FieldType.Picklist: case pNums.FieldType.RadioButtonList: sourceFieldValue = ""; foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) { sourceFieldValue = look.display; break; } break; case pNums.FieldType.Checkbox: sourceFieldValue = sourceData.surfaceFieldValueBool == true ? "Yes" : "No"; break; case pNums.FieldType.FormulaField: sourceFieldValue = ""; //CVH 2017-02-13 New action Lookup need to recalc on load if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action == lookupAction.recId) { decimal lookupSrcValue = 0m; bool conversionSuccess = false; var sourceFieldData = from srcFields in fieldTableEnum where srcFields.Field("recId").Equals(sourceField.actionSource) select srcFields; foreach (DataRow lookupSourceFieldRow in sourceFieldData.ToList()) { int _recIdL = int.Parse(lookupSourceFieldRow["recId"].ToString()); int _surfaceFieldTypeId = int.Parse(lookupSourceFieldRow["surfaceFieldTypeId"].ToString()); //NB ** Custom dev would be required here string _surfaceFieldValueChar = ""; //srcDataRow["surfaceFieldValueChar"].ToString(); int _surfaceFieldValueNum = 0; //int.Parse(srcDataRow["surfaceFieldValueNum"].ToString()); decimal _surfaceFieldValueDecimal = 0M; //decimal.Parse(srcDataRow["surfaceFieldValueDecimal"].ToString()); if (_surfaceFieldTypeId == (int)pNums.FieldType.Number) conversionSuccess = decimal.TryParse(_surfaceFieldValueNum.ToString(), out lookupSrcValue); else if (_surfaceFieldTypeId == (int)pNums.FieldType.Decimal) { conversionSuccess = true; lookupSrcValue = _surfaceFieldValueDecimal; } else conversionSuccess = decimal.TryParse(_surfaceFieldValueChar, out lookupSrcValue); } if (conversionSuccess) { sourceFieldValue = CalculateLookup(LabelRow, lookupSrcValue); } } //CVH 2017-02-07 New action Divide is saved in Char else if (sourceField.actionType == (int)pNums.ActionType.Calculation && sourceField.action != divideAction.recId) { sourceFieldValue = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", sourceField.action.ToString())) { if (act.action == "Age") { //need to calculate age, it isn't always saved in the age field //get age source (date of birth) data DateTime? dob = null; foreach (oSurfaceFieldData dobData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", sourceField.surfaceId + "," + sourceData.surfaceItemId + "," + sourceField.actionSource)) { dob = dobData.surfaceFieldValueDate; break; } if (dob != null) { oAge age = utils.FormatAge(Convert.ToDateTime(dob), DateTime.Now); sourceFieldValue = age.years.ToString(); } } break; } } //CVH 2017-02-24 New action type Aggregation Sum else if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); sourceFieldValue = utils.returnFormattedDecimal(decFormula.ToString()); } } else { sourceFieldValue = sourceData.surfaceFieldValueChar; } break; case pNums.FieldType.CheckboxList: sourceFieldValue = ""; //split string to get lookup IDs foreach (string temp in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { string lookupId = ""; if (temp.IndexOf("~R~") >= 0) { lookupId = temp.Substring(0, temp.IndexOf("~R~")); } else { lookupId = temp; } //get lookup foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", lookupId)) { if (sourceFieldValue == String.Empty) sourceFieldValue = look.display; else sourceFieldValue += ", " + look.display; break; } } break; case pNums.FieldType.Image: HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "Div"); if (imageLabelDiv != null) { string imageUrl = "/images/placeholder.png"; imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } if (imageLabelDiv != null) { string imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } isImage = true; break; case pNums.FieldType.Attachment: HtmlGenericControl attachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "LabelfAttachments"); int intItemIdAt = 0; int.TryParse(itemId, out intItemIdAt); if (attachDiv != null && intItemIdAt > 0) BindAttachments(intItemIdAt, attachDiv, sourceField.surfaceFieldName); break; case pNums.FieldType.Note: HtmlGenericControl notesDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "LabelfNotes"); int intItemIdN = 0; int.TryParse(itemId, out intItemIdN); if (notesDiv != null && intItemIdN > 0) BindNotes(intItemIdN, notesDiv); break; } } } } #endregion } } Label lblLabel = (Label)pnlSurfaceForm.FindControl("lbl" + _surfaceFieldName + "Label"); if (lblLabel != null) { // Dirk Strauss - 11 May 2017 - Display Field Text was not being applied to labels. if (!(String.IsNullOrEmpty(_surfaceFieldDisplay))) lblLabel.Text = _surfaceFieldDisplay; else lblLabel.Text = sourceFieldLabel; } if (!isImage) { Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + _surfaceFieldName + "Value"); if (lblValue != null) { lblValue.Text = sourceFieldValue; } } } //CVH 2016-12-12 Don't expand collapsed group just for label groupIdsWithData += ""; } #endregion #region Formula Fields var ffData = from fflds in fieldTableEnum where fflds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.FormulaField) select fflds; foreach (DataRow ffRow in ffData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool _required = false; bool _isCloneable = false; bool.TryParse(ffRow["isControlled"].ToString(), out _isControlled); bool.TryParse(ffRow["isReadOnly"].ToString(), out _isReadOnly); bool.TryParse(ffRow["required"].ToString(), out _required); bool.TryParse(ffRow["isCloneable"].ToString(), out _isCloneable); bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; int _recId = int.Parse(ffRow["recId"].ToString()); int _parentId = int.Parse(ffRow["parentId"].ToString()); int _surfaceId = int.Parse(ffRow["surfaceId"].ToString()); string _surfaceFieldName = ffRow["surfaceFieldName"].ToString(); string _controlledValue = ffRow["controlledValue"].ToString(); int _actionType = 0; int.TryParse(ffRow["actionType"].ToString(), out _actionType); int _action = 0; int.TryParse(ffRow["action"].ToString(), out _action); int _actionSource = 0; int.TryParse(ffRow["actionSource"].ToString(), out _actionSource); string _actionValue = ffRow["actionValue"].ToString(); TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtFormulaBox != null) { txtFormulaBox.Text = ""; //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate if (_actionType == (int)pNums.ActionType.Calculation && _action == lookupAction.recId) { decimal sourceValue = 0m; bool conversionSuccess = false; var sfData = from sflds in fieldTableEnum where sflds.Field("recId").Equals(_actionSource) select sflds; foreach (DataRow srcFRow in sfData.ToList()) { int _srcRecId = int.Parse(srcFRow["recId"].ToString()); int _srcFieldTypeId = int.Parse(srcFRow["surfaceFieldTypeId"].ToString()); //NB ** Custom dev would be required here int _srcDataFieldNum = 0; //int.TryParse(srcFDataRow["surfaceFieldValueNum"].ToString(), out _srcDataFieldNum); decimal _srcDataFieldDecimal = 0; //decimal.TryParse(srcFDataRow["surfaceFieldValueDecimal"].ToString(), out _srcDataFieldDecimal); string _srcDataFieldChar = "";//srcFDataRow["surfaceFieldValueChar"].ToString(); //catering for field types char, number, decimal if (_srcFieldTypeId == (int)pNums.FieldType.Number) conversionSuccess = decimal.TryParse(_srcDataFieldNum.ToString(), out sourceValue); else if (_srcFieldTypeId == (int)pNums.FieldType.Decimal) { conversionSuccess = true; sourceValue = _srcDataFieldDecimal; } else conversionSuccess = decimal.TryParse(_srcDataFieldChar, out sourceValue); } if (conversionSuccess) { txtFormulaBox.Text = CalculateLookup(ffRow, sourceValue); } } //CVH 2017-02-24 New action type Aggregation Sum else if (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) { int actionSurfaceId = 0; if (int.TryParse(_actionValue, out actionSurfaceId)) { decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, _actionSource, _surfaceItem.recId); txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } } //CVH 2017-05-12 Only clone when cloneable else if (!base.IsClone || (base.IsClone && _isCloneable)) { //NB** done in generated code section } if (_actionType == (int)pNums.ActionType.GenerateCode && txtFormulaBox.Text == "") { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; List sicParams = new List(); oDynamicParam sicParam = new oDynamicParam(); sicParam.paramDisplayName = "userId"; sicParam.paramObject = userId; sicParams.Add(sicParam); DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); if (nextCodeTable.Rows.Count > 0) { txtFormulaBox.Text = nextCodeTable.Rows[0].Field(0); if (txtFormulaBox.Text == "-1") txtFormulaBox.Text = ""; } else { txtFormulaBox.Text = ""; } } if (_actionType == (int)pNums.ActionType.FieldAggregation) { decimal decFormula = xData.GetSurfaceFieldAggregationSum(_surfaceItem.recId, _actionValue); txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); } //txtFormulaBox.Enabled = enabled; //CVH 2017-02-07 Divide Calculation Formula field is always read only //JR same with field aggregation if ((_actionType == (int)pNums.ActionType.Calculation && (_action == divideAction.recId || _action == lookupAction.recId)) || (_actionType == (int)pNums.ActionType.Aggregation && _action == aggrSumAction.recId) || _actionType == (int)pNums.ActionType.FieldAggregation) txtFormulaBox.Enabled = false; else txtFormulaBox.Enabled = enabled; //CVH 2016-12-12 Group default collapse if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + _parentId + "|")) groupIdsWithData += "|" + _parentId + "|"; } } #endregion #region Auto Generated Populate Code //-- {PopulateFormCustomValues} --// #endregion #region Relational Fields var relData = from relFlds in fieldTableEnum where relFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RelationalField) select relFlds; foreach (DataRow relFldRow in relData.ToList()) { string _relationalFields = relFldRow["relationalFields"].ToString(); foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", _relationalFields)) { if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) { SetSurfaceControlState(_surfaceItem, relFldRow, relatedField); } } } #endregion #region Controls var cntrlData = from ctrlFlds in fieldTableEnum where ctrlFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Control) select ctrlFlds; foreach (DataRow ctrlRow in cntrlData.ToList()) { SetSurfaceControlState(_surfaceItem, ctrlRow); } #endregion #region Grid Fields //get grid field data var gridData = from grids in fieldTableEnum where grids.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Grid) select grids; foreach (DataRow gridRow in gridData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(gridRow["isControlled"].ToString(), out _isControlled); bool.TryParse(gridRow["isReadOnly"].ToString(), out _isReadOnly); int _surfaceId = int.Parse(gridRow["surfaceId"].ToString()); string _surfaceFieldName = gridRow["surfaceFieldName"].ToString(); string _relationalSurface = gridRow["relationalSurface"].ToString(); string _relationalValues = gridRow["relationalValues"].ToString(); bool _defaultToCurrent = false; bool.TryParse(gridRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(gridRow["isComparable"].ToString(), out _isComparable); /* CVH 2016-01-20 */ bool enabled = !_isReadOnly && !_isControlled; //CVH 2017-05-11 Only check WizardCompleted if this is a wizard surface, otherwise it enables when it shouldn't if ((isNew || base.IsClone || (base.SurfaceApp.isWizzard && !_surfaceItem.isWizardCompleted)) && !_isControlled)//if controlled value, should always be readonly enabled = true; #region Grid //find the div and bind all repeaters inside it HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + _surfaceFieldName); Panel panelGridHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + _surfaceId.ToString() + "_" + _surfaceFieldName); Panel panelCompareHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + _surfaceId.ToString() + "_" + _surfaceFieldName); Panel panelFormHolder = null; if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + _surfaceId.ToString() + "_" + _surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + _surfaceId.ToString() + "_" + _surfaceFieldName); if (divGridHolder != null) { DataTable childData = new DataTable(); int surfaceId = 0; oSurface childSurface = new oSurface(); bool isChildPublished = false; foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", _relationalSurface)) { surfaceId = surf.recId; childSurface = surf; isChildPublished = surf.isPublished; break; } if (surfaceId > 0) { int rowLimit = 0; int.TryParse(_relationalValues, out rowLimit); //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data if (_isControlled) { childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); } else { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, base.SurfaceAppItemId, usr.recId, rowLimit); else childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); if ((childData.Rows.Count == 0 && _defaultToCurrent) || (base.SurfaceAppItemId == 0 && _defaultToCurrent && childData.Rows.Count > 0)) { DataTable masterDataItems = new DataTable(); int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //get child surface fields ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); if (childData.Rows.Count == 0) { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, 0, usr.recId, 0); else childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); } } } if (panelGridHolder != null) { Repeater repeater = null; //foreach (Control rpt in divGridHolder.Controls) foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { repeater = (Repeater)rpt; SetAggregates(childData, surfaceId); repeater.DataSource = childData; repeater.DataBind(); utils.disposeSession("childButtons"); } } if (_isComparable && panelCompareHolder != null) { BindCompareDropdowns(childSurface, _surfaceFieldName); panelCompareHolder.Visible = true; panelGridHolder.Visible = false; } //CVH 2017-02-23 Only put in edit mode when field is not Read Only else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !_isReadOnly && !_isControlled) { //CVH 2016-12-20 Child grid default edit mode foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); RepeaterItem childRptItem = repeater.Items[0]; EditChild(editChildItemId, childRptItem); } break; } } } } } #endregion } #endregion BindSurfaceAttachments(_surfaceItem.recId, false); BindSurfaceNotes(_surfaceItem.recId, false); #region Group Fields //CVH 2016-12-12 Expand/Collapse groups depending on data loaded string expandGroups = ""; var groupData = from groups in fieldTableEnum where groups.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groups; foreach (DataRow groupRow in groupData.ToList()) { bool _isControlled = false; bool.TryParse(groupRow["isControlled"].ToString(), out _isControlled); int _recId = int.Parse(groupRow["recId"].ToString()); string _surfaceFieldName = groupRow["surfaceFieldName"].ToString(); if (_isControlled && groupIdsWithData.Contains("|" + _recId + "|")) { if (expandGroups == String.Empty) expandGroups = "tog" + _surfaceFieldName; else expandGroups += ",tog" + _surfaceFieldName; } } ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; #endregion //CVH 2017-01-10 Only register script when not page load, otherwise javascript error method not defined that breaks other javascript if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroupsPopulate", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); //handle last if (base.SurfaceApp.isWizzard) { //GR added check now to see if wizard completed if (base.SurfaceAppItem != null) { wizardcompleted = base.SurfaceAppItem.isWizardCompleted; } if (!wizardcompleted && (usr.userType == (int)pNums.UserType.WebsiteUser)) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Check inside method for hidden from wizard, don't exclude from list, otherwise it won't cater for wizard tabs that are not in sequence (when wizard tabs are 1 and 5. 2,3 and 4 are hidden) //remove count check, handle in calling method, need to still see Cancel and Finish buttons, can't show form buttons until wizard has been completed (Finish has been clicked) var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; if (tabData.Count() > 0) { ArrayList fieldTabs1 = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); pnlWizzardButtons.Visible = true; pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; SetLastTabUsed(fieldTabs1); } } else { var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; ArrayList fieldTabs2 = new ArrayList(); if (tabData.Count() > 0) { fieldTabs2 = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 MaintainActiveTab(fieldTabs2); SetTabsVisible(fieldTabs2); } //CVH 2017-01-11 Only show first non wizard when editing an item, not when creating new one if (usr.userType >= (int)pNums.UserType.PowerUser && base.SurfaceApp.isWizzard && base.SurfaceAppItem != null && base.SurfaceAppItem.recId != 0) { int tabIndex = 0; foreach (oSurfaceField tab in fieldTabs2) { tabIndex++; //CVH 2017-05-05 User should have access to the tab, otherwise shouldn't increase counter.... //if (tab.isHiddenFromWizzard && User.userType < tab.accessLevel) if (tab.isHiddenFromWizzard && User.userType >= tab.accessLevel) break; } if (tabIndex > 0) { //string script = "$('#fsurfaceTabs li:eq(" + (tabIndex - 1) + ") a').tab('show');"; //string script = "setCurrentTab(" + (tabIndex - 1) + ")"; HiddenField hfTabIndex = Page.Master.FindControl("hfTabIndex") as HiddenField; //GR 2017-03-18 set hidden tab index for inital page load if (!Page.IsPostBack) { hfTabIndex.Value = (tabIndex - 1).ToString(); } else hfTabIndex.Value = ""; } } pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) var tabData = from tabs in fieldTableEnum where tabs.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Tab) && tabs.Field("isActive").Equals(true) && tabs.Field("parentId").Equals(0) orderby tabs.Field("sequence") select tabs; if (tabData.Count() > 0) { ArrayList fieldTabs = utils.ConvertDataTableToList(tabData.CopyToDataTable(), typeof(oSurfaceField)); SetTabsVisibleNoWizard(fieldTabs, false); } } SetCustomVisible(); PerformCustomPopulateAddOn(); upSurface.Update(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface form /// private bool SaveSurfaceFormCustom(ref oSurfaceItem _surfaceItem, ref bool createParentSurfaceItem) { bool result = false; try { //handle any custom save add on code PerformCustomSaveAddOn(_surfaceItem); oUser user = handler.ReturnUser(); #region Auto Generated Save Code //-- {SaveFormCustomValues} --// #endregion #region controls ArrayList controlFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", _surfaceItem.surfaceId + "," + (int)pNums.FieldType.Control + ",1", "sequence"); foreach (oSurfaceField surfCtl in controlFields) { oSurfaceFieldData fieldData = new oSurfaceFieldData(); fieldData.surfaceFieldID = surfCtl.recId; fieldData.surfaceId = _surfaceItem.surfaceId; fieldData.surfaceItemId = _surfaceItem.recId; string controlType = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", surfCtl.controlledValue)) { controlType = module.module; controlName = module.objectName + surfCtl.surfaceFieldName; } switch (controlType) { case "BodyMap": string itemId = fieldData.surfaceItemId.ToString(); string fieldId = fieldData.surfaceFieldID.ToString(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "formSaveClick", "formSaveClick(" + itemId + "," + fieldId + ");", true); break; default: //find module Control and call saveControlData() dynamic moduleControl = this.FindControl(controlName); if (moduleControl != null) { moduleControl.SaveControlData(ref fieldData); } break; } } #endregion if (base.SurfaceApp.linkUser) { if (user.userType == (int)pNums.UserType.WebsiteUser) _surfaceItem.userLink = user.recId; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return result; } /// /// Additional custom populate add on /// private void PerformCustomPopulateAddOn() { try { oSetup _setup = handler.ReturnSetup(); if (_setup.code == "STUD-1")//handle custom saving methods for STUD-1 { //handle custom sum action for profiles if (base.SurfaceApp.name == "Profiles") { btnSaveBack.Text = "Profile Save"; } else if (base.SurfaceApp.name.StartsWith("Device")) { btnSaveDropdown.Attributes.Add("disabled", "disabled"); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Additional custom save add on methods /// GR - 2017-04-06 /// /// private bool PerformCustomSaveAddOn(oSurfaceItem _surfaceItem) { bool result = false; try { oSetup _setup = handler.ReturnSetup(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return result; } /// /// Reset Controls for new item /// private void ResetControls() { try { DataTable surfaceFieldsTable = MainFieldTable; var fieldTableEnum = surfaceFieldsTable.AsEnumerable(); #region Label Fields var labelData = from labels in fieldTableEnum where labels.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Label) select labels; foreach (DataRow LabelRow in labelData.ToList()) { string _surfaceFieldName = LabelRow["surfaceFieldName"].ToString(); Label lblValue = (Label)pnlSurfaceForm.FindControl("lbl" + _surfaceFieldName + "Value"); if (lblValue != null) { lblValue.Text = String.Empty; } } #endregion #region TextBoxes var textData = from textboxes in fieldTableEnum where textboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Text) select textboxes; foreach (DataRow textRow in textData.ToList()) { string _surfaceFieldName = textRow["surfaceFieldName"].ToString(); TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtTextbox != null) { txtTextbox.Text = ""; } } #endregion #region Numbers var numData = from numboxes in fieldTableEnum where numboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Number) select numboxes; foreach (DataRow numRow in numData.ToList()) { bool _isControlled = false; bool.TryParse(numRow["isControlled"].ToString(), out _isControlled); string _surfaceFieldName = numRow["surfaceFieldName"].ToString(); TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtNumberBox != null) { if (_isControlled) { int nextNumber = 0; int.TryParse(txtNumberBox.Text, out nextNumber); nextNumber++; txtNumberBox.Enabled = false; txtNumberBox.Text = nextNumber.ToString(); } else txtNumberBox.Text = ""; } } #endregion #region Decimals var decData = from decboxes in fieldTableEnum where decboxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Decimal) select decboxes; foreach (DataRow decRow in decData.ToList()) { string _surfaceFieldName = decRow["surfaceFieldName"].ToString(); TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtDecimalBox != null) { txtDecimalBox.Text = ""; } } #endregion #region Picklists var pickData = from piclists in fieldTableEnum where piclists.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Picklist) select piclists; foreach (DataRow pickRow in pickData.ToList()) { bool _isCustomSource = false; bool.TryParse(pickRow["isCustomSource"].ToString(), out _isCustomSource); string _surfaceFieldName = pickRow["surfaceFieldName"].ToString(); // Pro-Pro-20 - Dirk Strauss - 16 May 2017 string _surfaceFieldDisplay = pickRow["surfaceFieldDisplay"].ToString(); DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(_surfaceFieldName); TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + _surfaceFieldName); //CVH 2017-03-01 First off clear reason if (txtPicklistReason != null) txtPicklistReason.Text = ""; if (ddDropdownlist != null) { if (ddDropdownlist.Items.FindByValue("0") != null) ddDropdownlist.SelectedValue = "0"; else if (ddDropdownlist.Items.FindByValue("") != null) ddDropdownlist.SelectedValue = ""; } } #endregion #region Multi Picklists var mpickData = from mpiclists in fieldTableEnum where mpiclists.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.MultiPicklist) select mpiclists; foreach (DataRow pickRow in mpickData.ToList()) { string _surfaceFieldName = pickRow["surfaceFieldName"].ToString(); ListBox listBox = (ListBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (listBox != null) { listBox.ClearSelection(); } } #endregion #region Dates var dateData = from dates in fieldTableEnum where dates.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Date) select dates; foreach (DataRow dtRow in dateData.ToList()) { string _surfaceFieldName = dtRow["surfaceFieldName"].ToString(); bool _defaultToCurrent = bool.Parse(dtRow["defaultToCurrent"].ToString()); string _defaultValue = dtRow["defaultValue"].ToString(); int _surfaceDateTypeId = 0; int.TryParse(dtRow["surfaceDateTypeId"].ToString(), out _surfaceDateTypeId); TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (txtDate != null) { string format = "dd/MM/yyyy"; if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.MonthYear) format = "MMMM yyyy"; else if (_surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) format = "yyyy"; if (_defaultToCurrent) txtDate.Text = DateTime.Now.ToString(format); else if (_defaultValue != "") txtDate.Text = _defaultValue; else txtDate.Text = ""; } } #endregion #region Checkboxes var boxData = from boxes in fieldTableEnum where boxes.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Checkbox) select boxes; foreach (DataRow bxRow in boxData.ToList()) { string _surfaceFieldName = bxRow["surfaceFieldName"].ToString(); CheckBox chkBox = (CheckBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (chkBox != null) { chkBox.Checked = false; } } #endregion #region Radiobutton Lists var radioData = from radios in fieldTableEnum where radios.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RadioButtonList) select radios; foreach (DataRow radRow in radioData.ToList()) { string _surfaceFieldName = radRow["surfaceFieldName"].ToString(); RadioButtonList radioButtonList = (RadioButtonList)pnlSurfaceForm.FindControl(_surfaceFieldName); TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + _surfaceFieldName); RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + _surfaceFieldName); if (radioButtonList != null) { radioButtonList.SelectedIndex = -1; if (txtReason != null) { //always disable reason if no data selected txtReason.Text = ""; txtReason.Enabled = false; } } } #endregion #region Captions var captData = from caps in fieldTableEnum where caps.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Caption) select caps; foreach (DataRow capRow in captData.ToList()) { string _surfaceFieldName = capRow["surfaceFieldName"].ToString(); TextBox textArea = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName); if (textArea != null) { textArea.Text = ""; } } #endregion #region Address Fields var addrData = from addrFlds in fieldTableEnum where addrFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Address) select addrFlds; foreach (DataRow addrRow in addrData.ToList()) { string _surfaceFieldName = addrRow["surfaceFieldName"].ToString(); bool found = false; int itemNoClr = 0; do { found = false; itemNoClr++; TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(_surfaceFieldName + itemNoClr); if (txtAddress != null) { txtAddress.Text = ""; found = true; } } while (found && itemNoClr < 50); } #endregion #region CheckboxLists var cblData = from checkblsts in fieldTableEnum where checkblsts.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.CheckboxList) select checkblsts; foreach (DataRow chklstRow in cblData.ToList()) { string _surfaceFieldName = chklstRow["surfaceFieldName"].ToString(); Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(_surfaceFieldName); if (checkboxPanel != null) { //CVH 2016-10-11 Clear checked items foreach (Control lblClear in checkboxPanel.Controls) { if (lblClear != null && lblClear.Controls.Count > 0) { Control ctrlClear = lblClear.Controls[0]; if (ctrlClear.GetType() == typeof(CheckBox)) { CheckBox chkClear = (CheckBox)ctrlClear; chkClear.Checked = false; TextBox txtClear = (TextBox)lblClear.FindControl(chkClear.ID + "Text"); if (txtClear != null) { txtClear.Text = ""; txtClear.Enabled = false; } } } } } } #endregion #region Images var imgData = from imgFlds in fieldTableEnum where imgFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Image) select imgFlds; foreach (DataRow imgFldRow in imgData.ToList()) { string _surfaceFieldName = imgFldRow["surfaceFieldName"].ToString(); HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(_surfaceFieldName + "Div"); if (imageDiv != null) { string imageUrl = "/images/placeholder.png"; imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } } #endregion } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Refresh Controls /// /// private void RefreshControls(oSurfaceItem _item) { try { //fetch the fields to define the rules on from from fields DataTable surfaceFieldsTable = MainFieldTable; var fieldTableEnum = surfaceFieldsTable.AsEnumerable(); #region Controls var cntrlData = from ctrlFlds in fieldTableEnum where ctrlFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Control) select ctrlFlds; foreach (DataRow ctrlRow in cntrlData.ToList()) { SetSurfaceControlState(_item, ctrlRow); } #endregion } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events /// /// Page initiliazie event to dynamicall load user controls - grid surface apps /// /// /// protected void Page_Init(object sender, EventArgs e) { if (base.SurfaceApp != null) { if (base.SurfaceAppItem == null) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceFormGridSurfaceApps(); PopulateSurfaceFormContentType(item); } } } /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { bool wizardcompleted = false; try { if (!Page.IsPostBack) { //CVH 2017-05-16 Clear surface save action session utils.disposeSession("SaveSurfaceActionRedirect"); if (utils.verifySession("SurfaceControlParcel")) { oSurfaceControlParcel parcel = (oSurfaceControlParcel)Session["SurfaceControlParcel"]; //set values from parcel base.SurfaceApp = parcel.SurfaceApp; base.SurfaceAppItem = parcel.SurfaceAppItem; base.SurfaceAppItemId = parcel.SurfaceAppItem.recId; base.ParentSurfaceItemId = parcel.ParentSurfaceItemId; base.ParentSurfaceId = parcel.ParentSurfaceId; base.ChildParentSurfaceId = parcel.ChildParentSurfaceId; base.ChildParentSurfaceItemId = parcel.ChildParentSurfaceItemId; base.IsChildSurface = parcel.IsChildSurface; base.IsSubChildSurface = parcel.IsSubChildSurface; base.IsClone = parcel.IsClone; utils.disposeSession("SurfaceControlParcel"); } else { Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); return; } } else { //Persist apps //PersistChildApp(); } ScriptManager scriptM = ScriptManager.GetCurrent(this.Page); Button btnReport = pnlSurfaceForm.FindControl("ApplicantInformation_ApplicantInformation_SBFCandidateReport") as Button; if (btnReport != null) { btnReport.Click += surfaceButton_Click; scriptM.RegisterPostBackControl(btnReport); } //CVH 2017-01-17 Remove global oUser, get from handler oUser user = handler.ReturnUser(); if (base.SurfaceApp != null) { //GR added to show the wizzard buttons at bottom or standard form buttons if (base.SurfaceApp.isWizzard) { //CVH 2017-01-09 If it is a wizard, but the wizard buttons have been disabled, set the save button to custom javascript validation method ValidateSurfaceWizardTabs, to validate all the tabs oSetup setup = handler.ReturnSetup(); ArrayList fieldTabs = new ArrayList(); //GR added check now to see if wizard completed if (base.SurfaceAppItem != null) { wizardcompleted = base.SurfaceAppItem.isWizardCompleted; } if (!wizardcompleted && (user.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId,isHiddenFromWizzard", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab + ",0", "sequence"); if (fieldTabs.Count > 1)//check if there are more than one tab else act as a form anyway { pnlWizzardButtons.Visible = true; pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; } else { // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) if (setup.code == "SHOU-1" && user.userType < (int)pNums.UserType.PowerUser) { pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = true; pnlWizzardButtons.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; btnSaveSingle.ValidationGroup = ""; btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } } else { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetTabsVisible(fieldTabs); if (setup.code == "SHOU-1" && user.userType < (int)pNums.UserType.PowerUser) { pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = true; pnlWizzardButtons.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; btnSaveSingle.ValidationGroup = ""; btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetTabsVisibleNoWizard(fieldTabs, true); } if (!Page.IsPostBack) { pnlSurfaceForm.Enabled = true; btnNew.Enabled = true; //CVH 2017-05-11 Need to differentiate between edit and new, otherwise Read Only doesn't work -> (base.SurfaceAppItem.recId == 0) if (base.SurfaceAppItem != null) { //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { btnSaveDraft.Visible = false; PopulateSurfaceFormCustom(base.SurfaceAppItem, (base.SurfaceAppItem.recId == 0)); } else { PopulateSurfaceForm(base.SurfaceAppItem, (base.SurfaceAppItem.recId == 0)); } } oSurface surface = base.SurfaceApp; //JR 2017-04-20 regiser postback to sbf report button ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page); UpdatePanel upApplicantInfo_ApplicantInformation = (UpdatePanel)FindControl("upApplicantInfo_ApplicantInformation"); if (upApplicantInfo_ApplicantInformation != null) { Button btn = upApplicantInfo_ApplicantInformation.FindControl("ApplicantInfo_ApplicantInformation_SBFCanididateReport") as Button; if (btn != null) { btn.Click += surfaceButton_Click; scriptMan.RegisterPostBackControl(btn); } } //CVH 2017-06-30 Disable inline edit for all users if (1 == 0) //if ((user.userType > (int)pNums.UserType.PowerUser && user.userType != (int)pNums.UserType.CustomUser) // || (user.mimicUserType > (int)pNums.UserType.PowerUser && user.userType == (int)pNums.UserType.CustomUser)) { //surface field handling BindFieldTypes(); BindSequence(); BindLookupCategories(); BindSurfaceApps(); BindContent(); BindComposite(); BindActionTypes(); //show edit/add/remove buttons for inline edit CheckBox chkToggleLayout = (CheckBox)pnlSurfaceForm.FindControl("chkToggleLayout"); if (chkToggleLayout != null) chkToggleLayout.Visible = true; if (utils.verifySession("Inline")) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surface.recId; foreach (oSurfaceItem itm in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", Session["Inline"].ToString())) { item = itm; break; } EnableInlineButtons(true); chkToggleLayout.Checked = true; utils.disposeSession("Inline"); if (utils.verifySession("ChildInline")) { int itemId = 0; int.TryParse(Session["ChildInline"].ToString(), out itemId); if (itemId > 0) { PersistChildEdit(itemId); } utils.disposeSession("ChildInline"); } } else { EnableInlineButtons(false); chkToggleLayout.Checked = false; } } else { chkToggleLayout.Visible = false; EnableInlineButtons(false); pnlParentSurfaceOptions.Visible = false; } } else { //CVH 2016-12-13 Add check for isWizard if (!wizardcompleted && this.SurfaceApp.isWizzard) { if (base.ActiveTabPanel != null && base.ActiveTabPanel != String.Empty) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Send all tabs to method, handle hidden tabs there. Otherwise not handled correctly when surface tabs are not in sequence ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); MaintainActiveTab(fieldTabs); } } } if (base.SurfaceAppGridEditTypeId <= 0) { int editTypeId = 1; editTypeId = MainGridOptions.surfaceGridEditTypeId; base.SurfaceAppGridEditTypeId = editTypeId; } upSurface.Update(); } else { //Go To Grid oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Surface Item /// /// /// protected void btnNew_Click(object sender, EventArgs e) { try { if (base.SurfaceApp != null) { NewItem(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bulk Update /// /// /// protected void btnBulkUpdate_Click(object sender, EventArgs e) { TogglePanels("pnlSurfaceGrid"); lblBulkUpdateResult.Text = ""; pnlBulkUpdateResult.Visible = false; upBulkUpdate.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('#modBulkUpdate').modal('show');", true); } protected void btnSaveBulkUpdate_Click(object sender, EventArgs e) { try { if (pnlBulkUpdate.Controls.Count <= 0) { TogglePanels("pnlSurfaceGrid"); pnlBulkUpdateResult.Visible = true; lblBulkUpdateResult.Text = "No fields to update."; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');$('#modBulkUpdate').modal('show');", true); return; } bool result = false; bool anyChecked = false; ArrayList bulkFields = null; pnlBulkUpdateResult.Visible = true; if (!anyChecked) lblBulkUpdateResult.Text = "No items have been selected."; else if (result) { ClearBulkUpdate(bulkFields); lblBulkUpdateResult.Text = "All selected items have been updated successfully."; } else lblBulkUpdateResult.Text = "Bulk update failed."; upBulkUpdate.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');$('#modBulkUpdate').modal('show');", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Surface Item /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { EditSurface(itemId, rptItem); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clone Surface Item /// /// /// protected void lnkClone_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { CloneSurface(itemId); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Open User Link Modal /// /// /// protected void lnkUserLink_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { Session["userLinkItemId"] = itemId; IControlBase userLink = (IControlBase)this.FindControl("userLink"); userLink.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalUserLink", "$('#modUserLinks" + base.SurfaceApp.name + "').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Open User Link Modal /// /// /// protected void lnkUserLinkChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { Session["userLinkItemId"] = itemId; IControlBase userLink = (IControlBase)this.FindControl("userLink"); userLink.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalUserLink", "$('#modUserLinks" + base.SurfaceApp.name + "').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit click from View /// /// /// protected void btnViewEdit_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; base.ActiveTabPanel = String.Empty; //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(item, false); } else { PopulateSurfaceForm(item, false); } //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); SetPatientType("PatientType_PatientType_PatientType"); //JasR 2016-01-20 Set wizard buttons if (base.SurfaceApp.isWizzard) { btnFinish.Visible = false; btnNext.Visible = true; } TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } } } upSurface.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Surface Item /// /// /// protected void lnkView_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; base.ActiveTabPanel = String.Empty; base.SurfaceApp.isWizzard = false; oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=view", false); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove a surface item /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { /* CVH 2016-09-19 Don't delete surface items, set item isDeleted = true */ int itemId = int.Parse(((LinkButton)sender).CommandArgument); /* CVH 2016-07-22 Delete all child data items linking to current parent item id */ foreach (oSurfaceField parentSurfaceItemIdField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", "ParentSurfaceItemId")) { foreach (oSurfaceFieldData childItemId in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceFieldID,surfaceFieldValueNum", parentSurfaceItemIdField.recId + "," + itemId.ToString())) { foreach (oSurfaceItem childItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childItemId.surfaceItemId.ToString())) { childItem.isDeleted = true; if (xData.UpdateTyped("recId", childItem.recId.ToString(), typeof(oSurfaceItem), childItem)) xData.DeleteSurfaceItemFromQueryTable(childItem.surfaceId, childItem.recId); } } } foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item.isDeleted = true; if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.DeleteSurfaceItemFromQueryTable(item.surfaceId, item.recId); xData.DeletePublishedSurfaceItem(item.surfaceId, item.recId); pnlResult.Visible = true; lblResult.Text = "the selected item was deleted successfully."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } break; } //} } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void ddlCompare_SelectedIndexChanged(object sender, EventArgs e) { try { DropDownList list = (DropDownList)sender; int columnNumber = Convert.ToInt32(list.ID.Substring(list.ID.IndexOf('_') + 1, 1)); string listSurfaceItemId = list.SelectedValue; //surfaceItemId string surfaceField = ""; if (list.ID.Length - list.ID.Replace("__", "").Length > 2) { surfaceField = list.ID.Substring(list.ID.LastIndexOf("__") + 2); } foreach (oSurfaceItem surfaceItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", listSurfaceItemId)) { PopulateSurfaceCompareView(surfaceItem, columnNumber, surfaceField); break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface App Item /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { // TPS - Pro-4 ViewState["saveClicked"] = true; Control btn = (Control)sender; if (btn == null) return; if (PerformSave(false, btn.ID == "btnSaveDraft" ? true : false, btn.ID == "btnSaveBack" ? true : false)) { pnlResult.Visible = true; /* CVH 2016-07-25 Default action after save go back to grid. Otherwise automatic load for new item */ /* CVH 2016-08-30 Button text = Save and default action to remain in edit mode */ if (btn.ID == "btnSaveBack" || btn.ID == "btnSaveDraft") { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // //CVH 2017-03-22 Copy from 2017-03-14 Removing this, causing problems with tabs. When clicking Save and Back on child modal where parent is wizard, it switches to first wizard tab (not current where child modal is situated) // //PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // //if (plcChildApp != null) // // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } break; } //} } //CVH 2017-05-16 If surface action to redirect, add itemId to session and redirect else if (utils.verifySession("SaveSurfaceActionRedirect")) { Session["SaveSurfaceActionItemId"] = base.SurfaceAppItemId; Response.Redirect(Session["SaveSurfaceActionRedirect"].ToString(), false); } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } else if (btn.ID == "btnSaveAndNew") { string script = "setCurrentTab(" + 0 + ",'fsurfaceTabs" + base.SurfaceApp.name + "')"; if (Page.IsPostBack) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "clickResetTrigger", script, true); //if (base.IsSubChildSurface) //{ // //force a post back for child grids ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); //} //CVH 2017-05-16 If surface action to redirect, add itemId to session and redirect if (utils.verifySession("SaveSurfaceActionRedirect")) { Session["SaveSurfaceActionItemId"] = base.SurfaceAppItemId; Response.Redirect(Session["SaveSurfaceActionRedirect"].ToString(), false); } else { //CVH 2017-10-05 Clear this flag otherwise it doesn't load the form for a new item correctly ViewState["saveClicked"] = false; ResetControls(); base.Entity = null; NewItem(); } } else if (btn.ID == "btnSaveNext") { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNextTab", "ActivateNextTab();", true); } else { //CVH 2017-05-16 If surface action to redirect, add itemId to session and redirect if (utils.verifySession("SaveSurfaceActionRedirect")) { Session["SaveSurfaceActionItemId"] = base.SurfaceAppItemId; Response.Redirect(Session["SaveSurfaceActionRedirect"].ToString(), false); } else { //if (base.IsSubChildSurface) //{ // //force a post back for child grids // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); //} /* CVH 2016-08-30 Keep modal open if this is child surface */ if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //CVH 2017-05-25 This causes the first tab to become active after save. It should stay on current tab. //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); //MaintainActiveTab(fieldTabs); //SetTabsVisible(fieldTabs); //upSurface.Update(); } } //CVH 2016-09-23 If shown in modal on sales control, need to reload sales contacts list if (handler.GetRoutedData("canvas-title") == "sales") { CommandEventArgs args = new CommandEventArgs("ReloadContacts", ""); RaiseBubbleEvent(null, args); } } utils.disposeSession("SaveSurfaceActionRedirect"); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } finally { // TPS - Handle save logic to not re-bind controls before save // Reset/Clear the view state ViewState["saveClicked"] = false; } } /// /// Item Data Bound /// /// /// protected void rptSurfaceGrid_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { oUser user = handler.ReturnUser(); if (e.Item.ItemType == ListItemType.Header) { if (e.Item.FindControl("thUserLink") != null) { HtmlTableCell thUserLink = (HtmlTableCell)e.Item.FindControl("thUserLink"); thUserLink.Visible = base.SurfaceApp.linkUser && user.userType == (int)pNums.UserType.AdminUser; } foreach (oSurfaceField field in MainFieldTable.Select("surfaceFieldTypeId=" + (int)pNums.FieldType.Debtors + "") .AsEnumerable() .Cast()) { if (e.Item.FindControl("th" + field.surfaceFieldName) != null) { HtmlTableCell thDebtors = (HtmlTableCell)e.Item.FindControl("th" + field.surfaceFieldName); thDebtors.Visible = ((user.userType >= field.accessLevel && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= field.accessLevel && user.userType == (int)pNums.UserType.CustomUser)); } } if (e.Item.FindControl("thStatus") != null) { HtmlTableCell thStatus = (HtmlTableCell)e.Item.FindControl("thStatus"); thStatus.Visible = MainGridOptions.showWizardStatus; } if (e.Item.FindControl("thEdit") != null) { HtmlTableCell thEdit = (HtmlTableCell)e.Item.FindControl("thEdit"); thEdit.Visible = MainGridOptions.allowEdit && ((user.userType >= MainGridOptions.editAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thView") != null) { HtmlTableCell thView = (HtmlTableCell)e.Item.FindControl("thView"); thView.Visible = MainGridOptions.allowView && ((user.userType >= MainGridOptions.viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thRemove") != null) { HtmlTableCell thRemove = (HtmlTableCell)e.Item.FindControl("thRemove"); thRemove.Visible = MainGridOptions.allowRemove && ((user.userType >= MainGridOptions.removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thClone") != null) { HtmlTableCell thClone = (HtmlTableCell)e.Item.FindControl("thClone"); thClone.Visible = MainGridOptions.allowClone && ((user.userType >= MainGridOptions.cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } } if (e.Item.ItemType == ListItemType.Footer) { if (e.Item.FindControl("tfUserLink") != null) { HtmlTableCell tfUserLink = (HtmlTableCell)e.Item.FindControl("tfUserLink"); tfUserLink.Visible = base.SurfaceApp.linkUser && user.userType == (int)pNums.UserType.AdminUser; } foreach (oSurfaceField field in MainFieldTable.Select("surfaceFieldTypeId=" + (int)pNums.FieldType.Debtors + "") .AsEnumerable() .Cast()) { if (e.Item.FindControl("tf" + field.surfaceFieldName) != null) { HtmlTableCell tfDebtors = (HtmlTableCell)e.Item.FindControl("tf" + field.surfaceFieldName); tfDebtors.Visible = ((user.userType >= field.accessLevel && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= field.accessLevel && user.userType == (int)pNums.UserType.CustomUser)); } } if (e.Item.FindControl("tfStatus") != null) { HtmlTableCell tfStatus = (HtmlTableCell)e.Item.FindControl("tfStatus"); tfStatus.Visible = MainGridOptions.showWizardStatus; } if (e.Item.FindControl("tfEdit") != null) { HtmlTableCell tfEdit = (HtmlTableCell)e.Item.FindControl("tfEdit"); tfEdit.Visible = MainGridOptions.allowEdit && ((user.userType >= MainGridOptions.editAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfView") != null) { HtmlTableCell tfView = (HtmlTableCell)e.Item.FindControl("tfView"); tfView.Visible = MainGridOptions.allowView && ((user.userType >= MainGridOptions.viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfRemove") != null) { HtmlTableCell tfRemove = (HtmlTableCell)e.Item.FindControl("tfRemove"); tfRemove.Visible = MainGridOptions.allowRemove && ((user.userType >= MainGridOptions.removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfClone") != null) { HtmlTableCell tfClone = (HtmlTableCell)e.Item.FindControl("tfClone"); tfClone.Visible = MainGridOptions.allowClone && ((user.userType >= MainGridOptions.cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= MainGridOptions.cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { if (base.SurfaceApp.linkUser && e.Item.FindControl("lnkUserLink") != null) { HtmlTableCell tdUserControl = (HtmlTableCell)e.Item.FindControl("tdUserLink"); tdUserControl.Visible = user.userType == (int)pNums.UserType.AdminUser; LinkButton lnkUserLink = (LinkButton)e.Item.FindControl("lnkUserLink"); int surfaceItemId = Convert.ToInt32(lnkUserLink.CommandArgument.ToString()); foreach (oSurfaceItem surfaceItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceItemId.ToString(), "", "pal_")) { bool userLinked = false; lnkUserLink.Attributes.Remove("title"); foreach (ovUserShared userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", surfaceItem.userLink.ToString())) { userLinked = true; lnkUserLink.Attributes.Add("title", userItem.email); } if (!userLinked) { lnkUserLink.Attributes.Add("title", "no link found"); lnkUserLink.CssClass = "fa fa-users palette-remove"; } } } //add any custom logic here } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Repeater Item Created /// /// /// protected void rptSurfaceGrid_ItemCreated(object sender, RepeaterItemEventArgs e) { ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page); LinkButton btn = e.Item.FindControl("ApplicantInformation_ApplicantInformation_SBFCandidateReport") as LinkButton; if (btn != null) { btn.Click += surfaceButton_Click; scriptMan.RegisterPostBackControl(btn); } } protected void rptSurfaceGrid_PreRender(object sender, EventArgs e) { //Repeater rep = (Repeater)sender; //if (rep.Items.Count == 0) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(true);", true); //else // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(false);", true); } /// /// Save Row click /// /// /// protected void lnkSaveRow_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; //CVH 2017-02-09 Get Parent.Parent, Parent is td RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; oSurfaceItem item = new oSurfaceItem(); ArrayList surfaceDataList = new ArrayList(); if (base.SurfaceApp != null) { /* CVH 2016-02-02 Enable batch editing */ if (base.SurfaceAppGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { SaveSurfaceGrid((Repeater)rptItem.Parent, base.SurfaceApp.recId, false); } else { oSurface surfaceApp = base.SurfaceApp; if (base.SurfaceAppItem != null)//update { item = base.SurfaceAppItem; SaveSurfaceRow(ref item, ref surfaceDataList, rptItem); if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); //save to query table xData.SaveSurfaceItemToQueryTable(item.surfaceId, item.recId); base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; ToggleRowEdit(item.recId, item, false, rptItem); } } } if (rptItem.Parent != null && rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel Event for the row /// /// /// protected void lnkCancel_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent; oSurfaceItem item = new oSurfaceItem(); ArrayList surfaceDataList = new ArrayList(); if (base.SurfaceApp != null) { oSurface surfaceApp = base.SurfaceApp; if (base.SurfaceAppItem != null)//update { item = base.SurfaceAppItem; ToggleRowEdit(item.recId, item, false, rptItem); } } if (rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface textbox text changed event /// /// /// protected void surfaceTextBox_TextChanged(object sender, EventArgs e) { TextBox txtBox = (TextBox)sender; //actions foreach (oSurfaceField surfaceFieldSource in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", txtBox.ID)) { foreach (oSurfaceField surfaceFieldToChange in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "actionSource", surfaceFieldSource.recId.ToString())) { string controlIdToChange = surfaceFieldToChange.surfaceFieldName; string action = surfaceFieldToChange.action.ToString(); string output = string.Empty; foreach (oSurfaceAction actionItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", action)) { switch (actionItem.action) { case "VAT": oSetup setup = handler.ReturnSetup(); if (setup.vatRegistered) { decimal input = Convert.ToDecimal(txtBox.Text); output = utils.CalculateVAT(setup.vatRate, input).ToString("N2"); } break; case "Age": switch (surfaceFieldSource.surfaceFieldTypeId) { case 7: //Date of Birth output = utils.CalculateAge(DateTime.Parse(txtBox.Text), null).ToString(); break; default: //Assume IDnumber output = utils.CalculateAge(null, txtBox.Text).ToString(); break; } break; case "Gender": output = utils.formatGenderFromID(txtBox.Text).ToString(); break; default: break; } } TextBox tbToChange = (TextBox)FindControl(controlIdToChange); tbToChange.Text = output; } } //Custom per surface app switch (txtBox.ID) { case "": break; default: break; } } /// /// event for all surface picklist index changed event /// /// /// protected void surfaceDropDownList_SelectedIndexChanged(object sender, EventArgs e) { //Custom per surface app try { if (sender is DropDownList) { DropDownList list = (DropDownList)sender; string listId = list.ID; string display = list.SelectedItem.Text.ToString(); //CVH 2017-05-12 Populate Device Management User labels from selected picklist if (handler.ReturnSetup().code == "STUD-1" && (base.SurfaceApp.name == "DeviceManagement" || base.SurfaceApp.name.StartsWith("Mentorship")) && listId.EndsWith("Email")) { int itemId = 0; int.TryParse(list.SelectedItem.Value, out itemId); if (itemId == 0) { //clear textboxes foreach (Control prt in list.Parent.Parent.Controls) { if (prt is TextBox && prt.ID.EndsWith("ItemId")) { TextBox txtItemId = (TextBox)prt; txtItemId.Text = ""; } else { foreach (Control ctrl in prt.Controls) { if (ctrl is TextBox && ctrl.ID.Contains("Profiles")) { TextBox txt = (TextBox)ctrl; txt.Text = ""; } } } } } else { foreach (oSurface profilesSurf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", "Profiles")) { DataTable dtProfileItem = xData.GetSurfaceItemData(profilesSurf.recId, itemId); if (dtProfileItem != null && dtProfileItem.Rows.Count > 0) { foreach (Control prt in list.Parent.Parent.Controls) { if (prt is TextBox && prt.ID.EndsWith("ItemId")) { TextBox txtItemId = (TextBox)prt; if (dtProfileItem.Rows[0]["itemID"] != null) { txtItemId.Text = dtProfileItem.Rows[0]["itemID"].ToString(); } } else { foreach (Control ctrl in prt.Controls) { if (ctrl is TextBox && ctrl.ID.Contains("Profiles")) { TextBox txt = (TextBox)ctrl; if (txt.ID.EndsWith("ItemId") && dtProfileItem.Rows[0]["itemID"] != null) { txt.Text = dtProfileItem.Rows[0]["itemID"].ToString(); } else { string colNameEnd = "_" + txt.ID.Substring(txt.ID.LastIndexOf("_") + 1).Replace("Profiles", ""); foreach (DataColumn col in dtProfileItem.Columns) { //if (colNameEnd == "_Surname") //{ // if (col.ColumnName.EndsWith(colNameEnd) && col.ColumnName.StartsWith("PartA")) // txt.Text = dtProfileItem.Rows[0][col].ToString(); //} //else if (col.ColumnName.EndsWith(colNameEnd)) txt.Text = dtProfileItem.Rows[0][col].ToString(); } } } } } } } } } } else if (handler.ReturnSetup().code == "STUD-1" && base.SurfaceApp.name == "Profiles" && listId.EndsWith("_School")) { int itemId = 0; int.TryParse(list.SelectedItem.Value, out itemId); oUser user = new oUser(); if (utils.verifySession("user")) user = (oUser)Session["user"]; string dean = ""; if (itemId > 0) { string school = list.SelectedItem.Text; foreach (oSurface schoolSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "surface", "School Setup")) { DataTable dtSchool = xData.GetSurfaceQueryDataPaged(schoolSurface.recId, 0, 100, "", "", user.recId); DataColumn colSchool = null; DataColumn colDean = null; foreach (DataColumn col in dtSchool.Columns) { if (col.ColumnName.EndsWith("School")) colSchool = col; else if (col.ColumnName.EndsWith("Dean")) colDean = col; } if (colSchool != null && colDean != null) { foreach (DataRow row in dtSchool.Rows) { if (row[colSchool].ToString() == school) { dean = row[colDean].ToString(); } } } } } foreach (Control prt in list.Parent.Parent.Parent.Controls) { if (prt.ID != null && prt.ID.EndsWith("_ProfilesDean")) { foreach (Control pctrl in prt.Controls) { foreach (Control ctrl in pctrl.Controls) { if (ctrl is TextBox && ctrl.ID.Contains("Profiles") && ctrl.ID.Contains("Dean")) { TextBox txt = (TextBox)ctrl; txt.Text = dean; } } } } } } else if (list.Parent.FindControl("reason" + listId) != null) { TextBox txtReason = (TextBox)list.Parent.FindControl("reason" + listId); RequiredFieldValidator rfvReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + listId); string itemId = list.SelectedItem.Value; if (txtReason != null && itemId == "0") { txtReason.Enabled = false; txtReason.Text = ""; } else { foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", itemId)) { if (lookupItem.wantsReason) { txtReason.Enabled = true; if (rfvReason != null) rfvReason.ControlToValidate = txtReason.ID; txtReason.Focus(); } else { txtReason.Enabled = false; txtReason.Text = ""; } } } } if (list.ID == "PatientType_PatientType_PatientType") SetPatientType("PatientType_PatientType_PatientType"); //CVH 2017-01-18 Set toggle view controls visible/not visible depending on picklist selected value SetToggleViewActionVisibilityPicklist(list); //CVH 2017-07-04 Check if any fields has this field set as it's source value for the surface action Lookup Field if (list.SelectedItem.Value != "0" && display != "") { foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", list.ID)) { foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "actionType,action,actionSource", pNums.ActionType.Calculation.GetHashCode() + ",19," + sourceField.recId)) { List listLookup = new List(); oDynamicParam look1 = new oDynamicParam(); look1.paramDisplayName = "surfaceFieldId"; look1.paramObject = field.recId; listLookup.Add(look1); oDynamicParam look2 = new oDynamicParam(); look2.paramDisplayName = "surfaceItemId"; look2.paramObject = 0; listLookup.Add(look2); oDynamicParam look3 = new oDynamicParam(); look3.paramDisplayName = "unsavedItemValueToMatch"; look3.paramObject = display; listLookup.Add(look3); DataTable dtValue = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetSurfaceActionLookupFieldValue", listLookup); if (dtValue != null && dtValue.Rows.Count > 0) { string value = dtValue.Rows[0][0].ToString(); TextBox txtTextbox = (TextBox)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (txtTextbox != null) txtTextbox.Text = value; } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface checkbox checked changed event /// /// /// protected void surfaceCheckbox_OnCheckedChanged(object sender, EventArgs e) { //Custom per surface app try { CheckBox chkBox = (CheckBox)sender; if (chkBox.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryonDuty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divvPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = chkBox.Checked; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface checkbox checked changed event /// /// /// protected void surfaceCheckboxList_OnCheckedChanged(object sender, EventArgs e) { //Custom per surface app try { //if (sender is HtmlGenericControl) //{ // foreach (Control control in ((HtmlGenericControl)sender).Controls) // { // if (control is CheckBox) // { // CheckBox chkBox = (CheckBox)control; // //CVH 2016-09-27 If field is part of checkboxlist and picklist item wants reason, enable/disable textbox // //try to find textbox for wants reason // TextBox txt = (TextBox)chkBox.Parent.FindControl(chkBox.ID + "Text"); // if (txt != null) // { // txt.Enabled = chkBox.Checked; // if (!txt.Enabled) // txt.Text = ""; // } // //CVH 2016-10-10 Check if there are fields with Toggle View action types linking to this field, and then if selected item equals the action value // SetToggleViewActionVisibilityCheckboxList(chkBox); // } // } //} if (sender is CheckBox) { CheckBox chkBox = (CheckBox)sender; //CVH 2016-09-27 If field is part of checkboxlist and picklist item wants reason, enable/disable textbox //try to find textbox for wants reason TextBox txt = (TextBox)chkBox.Parent.FindControl(chkBox.ID + "Text"); if (txt != null) { txt.Enabled = chkBox.Checked; if (!txt.Enabled) txt.Text = ""; } //CVH 2016-10-10 Check if there are fields with Toggle View action types linking to this field, and then if selected item equals the action value SetToggleViewActionVisibilityCheckboxList(chkBox); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface radioButtonList index changed event /// /// /// protected void surfaceRadioButtonList_SelectedIndexChanged(object sender, EventArgs e) { //Custom per surface app try { RadioButtonList list = (RadioButtonList)sender; string listId = list.ID; string display = list.SelectedItem.Text.ToString(); TextBox txtReason = (TextBox)list.Parent.FindControl("reason" + listId); RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + listId); string itemId = list.SelectedItem.Value; foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", itemId)) { if (lookupItem.wantsReason) { txtReason.Enabled = true; if (rfvPicklistReason != null) { rfvPicklistReason.ControlToValidate = txtReason.ID; rfvPicklistReason.Enabled = true; } txtReason.Focus(); } else { txtReason.Text = ""; txtReason.Enabled = false; if (rfvPicklistReason != null) rfvPicklistReason.Enabled = false; } //IOD stuff if (listId.ToLower() == "patientinformation_personresponsibleforaccountpaymentmainmemberofmedicalaid_injuryonduty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = display == "Yes"; UpdatePanel iodPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); if (iodPanel != null) iodPanel.Update(); if (display == "Yes") { DropDownList ddMedScheme = (DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MedicalAidIfapplicable_MedicalAidSchemeName"); if (ddMedScheme != null) ddMedScheme.SelectedValue = ddMedScheme.Items.FindByText("Workmans Compensation Accident").Value; } Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); if (MedGroup != null) MedGroup.Visible = display == "No"; UpdatePanel medPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); if (medPanel != null) medPanel.Update(); } } //CVH 2016-10-11 Toggle View Action SetToggleViewActionVisibilityRadioButtonList(list); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface button clicks /// /// /// protected void surfaceButton_Click(object sender, EventArgs e) { //The body of this method is custom per surface app if (sender is LinkButton) { LinkButton btn = (LinkButton)sender; string btnID = btn.ID; switch (btnID) { case "ApplicantInformation_ApplicantInformation_SBFCandidateReport": int surfaceId = base.SurfaceApp.recId; int surfaceAppItemId = base.SurfaceAppItemId; if (base.SurfaceApp.name != "Profiles") { DataTable surfaceItemData = xData.GetSurfaceQueryItemData(surfaceId, surfaceAppItemId); DataRow surfaceItemRow = surfaceItemData.Rows[0]; surfaceAppItemId = Convert.ToInt32(surfaceItemRow["ParentSurfaceItemId"].ToString()); foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceAppItemId.ToString())) { surfaceId = item.surfaceId; } } string reportBody = xSurfaceCustomMethod.GenerateSBFProfileReport(surfaceId, surfaceAppItemId); string reportFile = "SBF_" + base.SurfaceAppItemId + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".pdf"; string reportPath = HttpContext.Current.Server.MapPath("~/upload/documents/"); utils.validateFolder(reportPath); if (utils.ConvertHTMLToPDFFile(reportBody, reportPath + reportFile, true, "", "", false)) { Response.Clear(); //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + reportFile); Response.TransmitFile(reportPath + reportFile); Response.Flush(); Response.SuppressContent = true; ApplicationInstance.CompleteRequest(); } break; default: break; } } else if (sender is Button) { Button btn = (Button)sender; string btnID = btn.ID; switch (btnID) { //GWC Status Button case "PatientProfile_PatientStatus": if (btn.Text == "Status: Pending") { oMedicalPatientVisitLog visitLog = new oMedicalPatientVisitLog(); visitLog.signInDate = DateTime.Now; visitLog.surfaceItemId = base.SurfaceAppItemId; //GR 2017-05-15 first clear any existing not signed out for this patient foreach (oMedicalPatientVisitLog vLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) { vLog.signOutDate = DateTime.Now; xData.UpdateTyped("recId", vLog.recId.ToString(), typeof(oMedicalPatientVisitLog), vLog); } xData.SaveTyped("recId", typeof(oMedicalPatientVisitLog), visitLog); btn.AddCssClass("btn-success"); btn.RemoveCssClass("btn-warning"); btn.RemoveCssClass("btn-danger"); btn.Text = "Status: In Progress"; } else { //sign out all entries for this patient foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) { visitLog.signOutDate = DateTime.Now; xData.UpdateTyped("recId", visitLog.recId.ToString(), typeof(oMedicalPatientVisitLog), visitLog); } btn.AddCssClass("btn-warning"); btn.RemoveCssClass("btn-success"); btn.RemoveCssClass("btn-danger"); btn.Text = "Status: Pending"; } break; //GWC Copy Buttons #region gwc - patient to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromPatient": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress1")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress1")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress2")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress2")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress3")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress3")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress4")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress4")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress5")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress5")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress6")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress6")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress1")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress1")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress2")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress2")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress3")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress3")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress4")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress4")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress5")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress5")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress6")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress6")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Occupation")).Text; break; #endregion #region gwc - spouce to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Occupation")).Text; break; #endregion #region gwc - mother to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromMother": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Occupation")).Text; break; #endregion #region gwc - father to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromFather": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Occupation")).Text; break; #endregion #region gwc - father to emergency case "PatientInformation_EmergencyContact_CopyFromFather": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Father"; break; #endregion #region gwc - mother to emergency case "PatientInformation_EmergencyContact_CopyFromMother": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Mother"; break; #endregion #region gwc - spouse to emergency case "PatientInformation_EmergencyContact_CopyFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Spouce"; break; #endregion //TSP Copy Buttons #region TSP Copy Buttons case "PatientInformation_SpouseDetailsIfapplicable_CopyPatientAddress": ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_ResidentialAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_PostalAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Text; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PatientDetails")).Update(); break; case "PatientInformation_PatientDetails_CopyResidentialToPostal": ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Text; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PatientDetails")).Update(); break; case "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_CopyAllFromPatient": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_DateofBirth")).Text; ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Gender")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Gender")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_ResidentialAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_PostalAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Text; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid")).Update(); break; case "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_CopyAllFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_DateofBirth")).Text; ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Gender")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Gender")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_ResidentialAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_ResidentialAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_PostalAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_PostalAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_EmployerName")).Text; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_SpouseDetailsIfapplicable")).Update(); break; #endregion //End of TSP Copy Buttons case "ApplicantInformation_ApplicantInformation_SBFCandidateReport": int surfaceId = base.SurfaceApp.recId; int surfaceAppItemId = base.SurfaceAppItemId; if (base.SurfaceApp.name != "Profiles") { DataTable surfaceItemData = xData.GetSurfaceQueryItemData(surfaceId, surfaceAppItemId); DataRow surfaceItemRow = surfaceItemData.Rows[0]; surfaceAppItemId = Convert.ToInt32(surfaceItemRow["ParentSurfaceItemId"].ToString()); foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceAppItemId.ToString())) { surfaceId = item.surfaceId; } } string reportBody = xSurfaceCustomMethod.GenerateSBFProfileReport(surfaceId, surfaceAppItemId); string reportFile = "SBF_" + base.SurfaceAppItemId + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm") + ".pdf"; string reportPath = HttpContext.Current.Server.MapPath("~/upload/documents/"); utils.validateFolder(reportPath); if (utils.ConvertHTMLToPDFFile(reportBody, reportPath + reportFile, true, "", "", false)) { Response.Clear(); //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + reportFile); Response.TransmitFile(reportPath + reportFile); Response.Flush(); Response.SuppressContent = true; ApplicationInstance.CompleteRequest(); } break; default: break; } } } /// /// event for all surface image edit clicks /// /// /// protected void surfaceImageEdit_Click(object sender, EventArgs e) { if (sender is LinkButton) { LinkButton lbSurfaceImageEdit = (LinkButton)sender; Session["surfaceImageItemId"] = lbSurfaceImageEdit.Attributes["data-id"]; Session["surfaceImageFieldId"] = lbSurfaceImageEdit.Attributes["data-fieldId"]; } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modImageUpload", "$('#modImageUpload').modal();", true); } /// /// event for all surface action button clicks /// /// /// /// protected void surfaceActionButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; string btnID = btn.ID; string surfaceFieldName = btnID.Substring(3); foreach (oSurfaceField surfaceFieldDest in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", surfaceFieldName)) { string action = ((oSurfaceAction)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", surfaceFieldDest.action.ToString())[0]).action; if (action == "Copy") { string controlIdDest = surfaceFieldDest.surfaceFieldName; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), surfaceFieldDest.surfaceFieldTypeId); oSurfaceField sourceField = (oSurfaceField)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", surfaceFieldDest.actionSource.ToString())[0]; if (sourceField.surfaceId != surfaceFieldDest.surfaceId && base.IsChildSurface) { //assume parent oSurfaceFieldData sourceData = (oSurfaceFieldData)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceItemId,surfaceFieldId", base.ParentSurfaceItemId.ToString() + "," + sourceField.recId.ToString())[0]; switch (typ) { case pNums.FieldType.Text: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Number: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueNum.ToString(); break; case pNums.FieldType.Decimal: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); break; case pNums.FieldType.Date: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); break; case pNums.FieldType.Caption: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Address: int itemNo = 0; foreach (string addressLine in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { itemNo++; if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(controlIdDest + itemNo + "dd"); if (ddSuburb != null) { if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) ddSuburb.SelectedValue = addressLine.Substring(3); } } else { TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + itemNo); if (txtAddress != null && addressLine.Substring(1, 1) == itemNo.ToString()) { txtAddress.Text = addressLine.Substring(3); } } } break; default: break; } } else { string controlIdSource = ((oSurfaceField)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", surfaceFieldDest.actionSource.ToString())[0]).surfaceFieldName; switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Date: case pNums.FieldType.Caption: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = ((TextBox)pnlSurfaceForm.FindControl(controlIdSource)).Text; break; case pNums.FieldType.Address: TextBox txtAddress1Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "1"); TextBox txtAddress1Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "1"); if (txtAddress1Dest != null && txtAddress1Src != null) txtAddress1Dest.Text = txtAddress1Src.Text; if (handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburbSrc = (DropDownList)pnlSurfaceForm.FindControl(controlIdSource + "2dd"); DropDownList ddSuburbDest = (DropDownList)pnlSurfaceForm.FindControl(controlIdDest + "2dd"); if (ddSuburbDest != null && ddSuburbSrc != null) ddSuburbDest.SelectedIndex = ddSuburbSrc.SelectedIndex; } else { TextBox txtAddress2Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "2"); TextBox txtAddress2Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "2"); if (txtAddress2Dest != null && txtAddress2Src != null) txtAddress2Dest.Text = txtAddress2Src.Text; } TextBox txtAddress3Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "3"); TextBox txtAddress3Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "3"); if (txtAddress3Dest != null && txtAddress3Src != null) txtAddress3Dest.Text = txtAddress3Src.Text; TextBox txtAddress4Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "4"); TextBox txtAddress4Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "4"); if (txtAddress4Dest != null && txtAddress4Src != null) txtAddress4Dest.Text = txtAddress4Src.Text; TextBox txtAddress5Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "5"); TextBox txtAddress5Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "5"); if (txtAddress5Dest != null && txtAddress5Src != null) txtAddress5Dest.Text = txtAddress5Src.Text; TextBox txtAddress6Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "6"); TextBox txtAddress6Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "6"); if (txtAddress6Dest != null && txtAddress6Src != null) txtAddress6Dest.Text = txtAddress6Src.Text; break; default: break; } } } } } /// /// Finish Saving /// /// /// protected void btnFinish_Click(object sender, EventArgs e) { try { /* CVH 2016-09-01 Wizard no save as draft function for now */ if (PerformSave(true, false, true)) { //update wizard to completed base.SurfaceAppItem.isWizardCompleted = true; base.SurfaceAppItem.lastTabCompleted = 0; xData.UpdateTyped("recId", base.SurfaceAppItem.recId.ToString(), typeof(oSurfaceItem), base.SurfaceAppItem); if (utils.verifySession("user")) { oUser user = (oUser)Session["user"]; oSetup setup = handler.ReturnSetup(); if ((user.userType >= (int)pNums.UserType.PowerUser || handler.ReturnSetup().code == "GLOB-1") && user.userType != (int)pNums.UserType.CustomUser) { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; base.ActiveTabPanel = String.Empty; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } break; } //} } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = false; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } else if (user.userType == (int)pNums.UserType.WebsiteUser && setup.code != "SHOU-1") //CVH 2016-12-01 If TSP, log out user and show modal { if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } break; } //} } else { ////GR 21/12/2016 close modal if child on save //if (base.IsChildSurface) //{ // string sub = String.Empty; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); // if (base.IsSubChildSurface) // { sub = "Sub"; } // else // { base.ChildAppItem = null; } // //RemoveSurfaceControl(sub); // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); //} //else //{ oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); //} } } else { //log out user utils.disposeSession("user"); //display notification ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myRegModal", "$('#modCompleteReg').modal();", true); } } if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Next click /// /// /// protected void btnNext_Click(object sender, EventArgs e) { try { SetPatientType("PatientType_PatientType_PatientType"); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 /* CVH 2016-09-01 Wizard no save as draft function for now */ ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,isReadonly,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0,0," + (int)pNums.FieldType.Tab, "sequence"); //CVH 2017-05-25 Clicking Next, isClosing = false if (PerformSave(false, false, false)) { //CVH 2016-11-01 Send all tabs to method, check for hidden there, otherwise not handled correctly when wizard tab is after hidden tabs SetNextTab(fieldTabs); SetCustomVisible(); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } else { MaintainActiveTab(fieldTabs); } upSurface.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Previous click /// /// /// protected void btnPrevious_Click(object sender, EventArgs e) { try { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Send all tabs to method, check for hidden there, otherwise not handled correctly when wizard tab is after hidden tab ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetPreviousTab(fieldTabs); upSurface.Update(); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel wizzard button click /// /// /// protected void btnCancelWizzard_Click(object sender, EventArgs e) { try { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; base.ActiveTabPanel = String.Empty; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } break; } //} } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// MSV method /// /// /// protected void btnMediswitch_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modMediSwitchMSV", "$('#modMediSwitchMSV" + base.SurfaceApp.name + "').modal();", true); } /// /// Debtors method /// /// /// protected void btnDebtors_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } //CVH 2016-11-17 Set the Debtors button field name, used when linking notes to surface //JR 2017-05-05 Should use id string fieldName = ""; int fieldId = 0; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Note + ",1")) { fieldName = field.surfaceFieldName; fieldId = field.recId; break; } Session["noteSurfaceFieldName"] = fieldId; Session["account"] = xDebtors.SetAccountItem(itemId, base.SurfaceApp.recId, usr); Session["loadType"] = "Redirected"; //redirect to debtors Response.Redirect("/pages/enquiry", false); } } protected void btnComposite_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); string profilePage = string.Empty; foreach (oSurfaceField surfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", ((LinkButton)sender).ID)) { foreach (oCanvas canvas in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "recId", surfaceField.contentId.ToString())) { profilePage = canvas.name; } } Session["surfaceItemId"] = itemId; //redirect to composite if (profilePage != string.Empty) Response.Redirect("/pages/" + profilePage, false); } } /// /// Close button method /// /// /// protected void btnClose_Click(object sender, EventArgs e) { try { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Called from grid field child surface to save surface data on parent /// /// /// /// protected override bool OnBubbleEvent(object source, EventArgs args) { try { CommandEventArgs e = (CommandEventArgs)args; if (e.CommandName == "SaveParentSurfaceItem") { int surfaceItemId = int.Parse(e.CommandArgument.ToString()); ArrayList itemList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceItemId.ToString()); if (itemList == null || itemList.Count <= 0) return false; oSurfaceItem surfaceItem = (oSurfaceItem)itemList[0]; SaveBubbleData(surfaceItem); base.SurfaceAppItem = surfaceItem; base.SurfaceAppItemId = surfaceItem.recId; //CVH 2016-11-17 Set the Notes button field name, used when linking notes to surface string fieldName = ""; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Note + ",1")) { fieldName = field.surfaceFieldName; break; } /* CVH 2016-04-20 Add new note of type "Surface Item Created" */ oNote note = new oNote(); note.moduleId = (int)pNums.Module.Surface; note.typeId = (int)pNums.NoteType.SurfaceItemCreated; note.entityId = base.SurfaceAppItemId; note.title = "Surface Item Created"; note.caption = "A new surface item was created."; note.dateSaved = DateTime.Now; note.userIdSaved = surfaceItem.createdBy; note.isActive = true; note.fieldName = fieldName; note.recId = xData.SaveTyped("recId", typeof(oNote), note); //set session to indicate that changed record shouldn't be saved on next Finish click Session["newItem"] = "saved"; } return true; } catch (Exception) { return false; } } /// /// /// /// /// protected void btnSales_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { if (((LinkButton)sender).CommandArgument != "") { int itemId = int.Parse(((LinkButton)sender).CommandArgument); Session["sales"] = xSales.SetSalesContact(itemId); //redirect to debtors Response.Redirect("/pages/sales", false); } } } protected void chkToggleLayout_CheckedChanged(object sender, EventArgs e) { CheckBox chkToggleLayout = (CheckBox)sender; if (chkToggleLayout != null) EnableInlineButtons(chkToggleLayout.Checked); upSurface.Update(); } protected void lnkGridView_Click(object sender, EventArgs e) { //Go To Grid //TO DO } protected void lnkCompareView_Click(object sender, EventArgs e) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = base.SurfaceAppItem; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=view", false); } //protected void RadioButton_FixAutoPostBack_OnPreRender(object sender, EventArgs e) //{ // RadioButton radioButton = (RadioButton)sender; // HtmlGenericControl label = (HtmlGenericControl)radioButton.Parent; // // Set onclick handler of the parent label to be the same as the radio button. // // This fixes issues caused by bootstrap javascript which adds labels. // label.Attributes.Add("onclick", // "javascript:setTimeout('__doPostBack(\\'" + // radioButton.UniqueID + "\\',\\'\\')', 0)"); //} protected void CheckBox_FixAutoPostBack_OnPreRender(object sender, EventArgs e) { CheckBox checkBox = (CheckBox)sender; Panel label = (Panel)checkBox.Parent; // Set onclick handler of the parent label to be the same as the radio button. // This fixes issues caused by bootstrap javascript which adds labels. label.Attributes.Add("onclick", "javascript:setTimeout('__doPostBack(\\'" + checkBox.UniqueID + "\\',\\'\\')', 0)"); } /// /// refresh current form /// /// /// protected void lnkRefresh_Click(object sender, EventArgs e) { //GR 2017-06-12 - handling of custom controls if (base.SurfaceApp.isPublished) { PopulateSurfaceFormCustom(base.SurfaceAppItem, false); } else { PopulateSurfaceForm(base.SurfaceAppItem, false); } TogglePanels("pnlSurfaceForm"); } #endregion #region child grid repeater events /// /// Item Data Bound /// /// /// protected void rptSurfaceChildGrid_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { Repeater childRepeater = (Repeater)sender; HiddenField hfChildSurfaceId = (HiddenField)childRepeater.Controls[0].Controls[0].FindControl("hfChildSurfaceId"); oUser user = handler.ReturnUser(); if (e.Item.ItemType == ListItemType.Header) { DataTable buttonFieldTable = new DataTable(); if (utils.verifySession("childButtons")) { buttonFieldTable = (DataTable)Session["childButtons"]; } else { buttonFieldTable = xData.GetTypedByCriteriaSpecificTable("redId", typeof(oSurfaceGridOptions), "surfaceId", hfChildSurfaceId.Value.ToString()); Session["childButtons"] = buttonFieldTable; } if (buttonFieldTable.Rows.Count > 0) { foreach (DataRow btnRow in buttonFieldTable.Rows) { int editAccessType = 0; int.TryParse(btnRow["editAccessType"].ToString(), out editAccessType); int viewAccessType = 0; int.TryParse(btnRow["viewAccessType"].ToString(), out viewAccessType); int removeAccessType = 0; int.TryParse(btnRow["removeAccessType"].ToString(), out removeAccessType); int cloneAccessType = 0; int.TryParse(btnRow["cloneAccessType"].ToString(), out cloneAccessType); bool showWizardStatus = false; bool.TryParse(btnRow["showWizardStatus"].ToString(), out showWizardStatus); bool allowEdit = false; bool.TryParse(btnRow["allowEdit"].ToString(), out allowEdit); bool allowView = false; bool.TryParse(btnRow["allowView"].ToString(), out allowView); bool allowRemove = false; bool.TryParse(btnRow["allowRemove"].ToString(), out allowRemove); bool allowClone = false; bool.TryParse(btnRow["allowClone"].ToString(), out allowClone); if (e.Item.FindControl("thStatus") != null) { HtmlTableCell thStatus = (HtmlTableCell)e.Item.FindControl("thStatus"); thStatus.Visible = showWizardStatus; } if (e.Item.FindControl("thEdit") != null) { HtmlTableCell thEdit = (HtmlTableCell)e.Item.FindControl("thEdit"); thEdit.Visible = allowEdit && ((user.userType >= editAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thView") != null) { HtmlTableCell thView = (HtmlTableCell)e.Item.FindControl("thView"); thView.Visible = allowView && ((user.userType >= viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thRemove") != null) { HtmlTableCell thRemove = (HtmlTableCell)e.Item.FindControl("thRemove"); thRemove.Visible = allowRemove && ((user.userType >= removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thClone") != null) { HtmlTableCell thClone = (HtmlTableCell)e.Item.FindControl("thClone"); thClone.Visible = allowClone && ((user.userType >= cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } break; } } } if (e.Item.ItemType == ListItemType.Footer) { DataTable buttonFieldTable = new DataTable(); if (utils.verifySession("childButtons")) { buttonFieldTable = (DataTable)Session["childButtons"]; } else { buttonFieldTable = xData.GetTypedByCriteriaSpecificTable("redId", typeof(oSurfaceGridOptions), "surfaceId", hfChildSurfaceId.Value.ToString()); Session["childButtons"] = buttonFieldTable; } if (buttonFieldTable.Rows.Count > 0) { foreach (DataRow btnRow in buttonFieldTable.Rows) { int editAccessType = 0; int.TryParse(btnRow["editAccessType"].ToString(), out editAccessType); int viewAccessType = 0; int.TryParse(btnRow["viewAccessType"].ToString(), out viewAccessType); int removeAccessType = 0; int.TryParse(btnRow["removeAccessType"].ToString(), out removeAccessType); int cloneAccessType = 0; int.TryParse(btnRow["cloneAccessType"].ToString(), out cloneAccessType); bool showWizardStatus = false; bool.TryParse(btnRow["showWizardStatus"].ToString(), out showWizardStatus); bool allowEdit = false; bool.TryParse(btnRow["allowEdit"].ToString(), out allowEdit); bool allowView = false; bool.TryParse(btnRow["allowView"].ToString(), out allowView); bool allowRemove = false; bool.TryParse(btnRow["allowRemove"].ToString(), out allowRemove); bool allowClone = false; bool.TryParse(btnRow["allowClone"].ToString(), out allowClone); if (e.Item.FindControl("tfStatus") != null) { HtmlTableCell tfStatus = (HtmlTableCell)e.Item.FindControl("tfStatus"); tfStatus.Visible = showWizardStatus; } if (e.Item.FindControl("tfEdit") != null) { HtmlTableCell tfEdit = (HtmlTableCell)e.Item.FindControl("tfEdit"); tfEdit.Visible = allowEdit && ((user.userType >= editAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfView") != null) { HtmlTableCell tfView = (HtmlTableCell)e.Item.FindControl("tfView"); tfView.Visible = allowView && ((user.userType >= viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfRemove") != null) { HtmlTableCell tfRemove = (HtmlTableCell)e.Item.FindControl("tfRemove"); tfRemove.Visible = allowRemove && ((user.userType >= removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfClone") != null) { HtmlTableCell tfClone = (HtmlTableCell)e.Item.FindControl("tfClone"); tfClone.Visible = allowClone && ((user.userType >= cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } break; } } } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //add any custom logic here } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void rptSurfaceChildGrid_PreRender(object sender, EventArgs e) { //Repeater rep = (Repeater)sender; //if (rep.Items.Count == 0) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(true);", true); //else // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(false);", true); } /// /// Hide child compare view and show child grid view /// /// /// protected void btnGridViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton btnGridView = (LinkButton)sender; string panelGridVal = btnGridView.ID.Replace("btnGridViewChild_", "pnlSurfaceGrid_"); string panelCompareVal = btnGridView.ID.Replace("btnGridViewChild_", "pnlSurfaceCompare_"); if (pnlSurfaceForm.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelGridVal)).Visible = true; if (pnlSurfaceForm.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelCompareVal)).Visible = false; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Hide child grid view and show child compare view /// /// /// protected void btnCompareViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton btnCompareView = (LinkButton)sender; string panelGridVal = btnCompareView.ID.Replace("btnCompareViewChild_", "pnlSurfaceGrid_"); string panelCompareVal = btnCompareView.ID.Replace("btnCompareViewChild_", "pnlSurfaceCompare_"); if (pnlSurfaceForm.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelGridVal)).Visible = false; if (pnlSurfaceForm.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelCompareVal)).Visible = true; //have : btnGridViewChild_1011_XRays_XRays_XRays //get : pnlSurfaceGrid_1011_XRays_XRays_XRays and put invisible //get : pnlSurfaceCompare_1011_XRays_XRays_XRays and put visible } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Surface Item /// /// /// protected void btnNewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { if (base.SurfaceApp.isPublished)//we can call to save with published its not heavy lifting to save PerformSave(false, false, true); int surfaceId = 0; LinkButton newChild = (LinkButton)sender; //CVH 2017-01-11 Find the full string that needs to be replaced e.g. "btnNewChild_Form", not just "Form", otherwise it processes incorrectly when the surface name contains "Form", like "Application Form" for SBF string childVal; if (newChild.ID.Contains("btnNewChild_Compare")) childVal = newChild.ID.Replace("btnNewChild_Compare", ""); else if (newChild.ID.Contains("btnNewChild_Form")) childVal = newChild.ID.Replace("btnNewChild_Form", ""); else childVal = newChild.ID.Replace("btnNewChild_", ""); childVal = childVal.Remove(childVal.IndexOf("_")); int.TryParse(childVal, out surfaceId); if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false, true)) return; } if (surfaceId > 0) { bool isBatchEdit = false; foreach (oSurfaceGridOptions gridOption in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", surfaceId.ToString())) { isBatchEdit = gridOption.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch; } if (isBatchEdit) { foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", surfaceId.ToString())) { string childSurface = newChild.ID.Replace("btnNewChild_" + surfaceId.ToString() + "_", ""); int tabId = 0; string repeaterId = "rpt" + surf.name + "Child" + tabId.ToString() + childSurface; if (pnlSurfaceForm.FindControl(repeaterId) != null && pnlSurfaceForm.FindControl(repeaterId) is Repeater) { oSurfaceItem childItem = new oSurfaceItem(); childItem.createdBy = User.recId; childItem.dateCreated = DateTime.Now; childItem.isActive = true; childItem.isDeleted = false; childItem.isWizardCompleted = false; childItem.lastTabCompleted = 0; childItem.surfaceId = surfaceId; int itemId = xData.SaveTyped("recId", typeof(oSurfaceItem), childItem); DataTable surfaceFieldTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString(), "sequence"); DataTable surfaceFieldDataTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldData), "surfaceId", surfaceId.ToString()); var fieldTableEnum = surfaceFieldTable.AsEnumerable(); var fieldTableDataEnum = surfaceFieldDataTable.AsEnumerable(); var gridFieldData = from grdFields in fieldTableEnum where grdFields.Field("surfaceFieldName").Equals("ParentSurfaceItemId") select grdFields; foreach (DataRow fieldRow in gridFieldData.ToList()) { oSurfaceFieldData fieldData = new oSurfaceFieldData(); fieldData.surfaceId = surfaceId; fieldData.surfaceItemId = itemId; fieldData.surfaceFieldValueNum = base.SurfaceAppItemId; fieldData.surfaceFieldID = int.Parse(fieldRow["recId"].ToString()); xData.SaveTyped("recId", typeof(oSurfaceFieldData), fieldData); } xData.SaveSurfaceItemToQueryTable(surfaceId, itemId); SaveChildSurfaceData(base.SurfaceAppItemId, false, surfaceId); } } } else { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", surfaceId.ToString())) { //load the surface app control oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surfaceId; if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + "_form.ascx"))) { BuildControl(gridSurface); } #region oldCode //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = false; // base.ChildIsNew = true; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control #endregion oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); // } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Surface Item /// /// /// protected void lnkViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + "_view.ascx"))) { BuildControl(gridSurface); } //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = true; // base.ChildIsNew = false; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=view", false); // } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Child item from compare /// /// /// protected void lnkEditCompareChild_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkEdit", "ddlCompare"); if (pnlSurfaceForm.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditChild(listSurfaceItemId); } } /// /// Edit Surface Item /// /// /// protected void lnkEditCompare_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkEdit", "ddlCompare"); if (pnlSurfaceForm.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditSurface(listSurfaceItemId, null); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clone Compare Surface Item /// /// /// protected void lnkCloneCompare_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkClone", "ddlCompare"); if (pnlSurfaceForm.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId CloneSurface(listSurfaceItemId); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clone Child item from compare /// /// /// protected void lnkCloneCompareChild_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkClone", "ddlCompare"); if (pnlSurfaceForm.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceForm.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditChild(listSurfaceItemId, null, true); } } /// /// Edit Surface Item /// /// /// protected void lnkEditChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { //CVH 2017-02-01 //RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent; RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent.Parent; EditChild(itemId, rptItem); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Child Item /// /// /// private void EditChild(int itemId, RepeaterItem rptItem = null, bool isClone = false) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), opt.surfaceGridEditTypeId); switch (editType) { case pNums.SurfaceGridEditType.Form: foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + "_form.ascx"))) { BuildControl(gridSurface); } //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = false; // base.ChildIsNew = false; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); //} } break; case pNums.SurfaceGridEditType.Row: if (rptItem != null) { ToggleRowEdit(itemId, item, true, rptItem); //if (rptItem.Parent.GetType() == typeof(Repeater)) //{ KeepSelectedGridTab((Repeater)rptItem.Parent); } } break; /* CVH 2016-02-02 Batch edit mode */ case pNums.SurfaceGridEditType.Batch: if (rptItem != null) { ToggleGridEdit(true, (Repeater)rptItem.Parent, itemId, item.surfaceId); } break; } } } } /// /// Clone Surface Item /// /// /// protected void lnkCloneChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent; EditChild(itemId, rptItem, true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove a surface item /// /// /// protected void lnkRemoveChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { /* CVH 2016-09-19 Don't delete surface items, set item isDeleted = true */ int itemId = int.Parse(((LinkButton)sender).CommandArgument); foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item.isDeleted = true; if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.DeleteSurfaceItemFromQueryTable(item.surfaceId, item.recId); xData.DeletePublishedSurfaceItem(item.surfaceId, item.recId); foreach (oSurface childSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //Bind Child Grid BindChildGrid(childSurface); } pnlResult.Visible = true; lblResult.Text = "the selected item was deleted successfully."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Row click /// /// /// protected void lnkSaveRowChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; oSurfaceItem item = new oSurfaceItem(); int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem surfItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item = surfItem; break; } foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { if (opt.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { SaveSurfaceGrid((Repeater)rptItem.Parent, item.surfaceId, true); } else { ArrayList surfaceDataList = new ArrayList(); SaveSurfaceRow(ref item, ref surfaceDataList, rptItem); if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); //save to query table xData.SaveSurfaceItemToQueryTable(item.surfaceId, item.recId); ToggleRowEdit(item.recId, item, false, rptItem); } } foreach (oSurface childSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //Bind child Grid BindChildGrid(childSurface); } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel Event for the row /// /// /// protected void lnkCancelChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { oSurfaceItem item = new oSurfaceItem(); int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem surfItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item = surfItem; break; } foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { if (opt.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { foreach (oSurface childSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //Bind Child Grid BindChildGrid(childSurface); } } else { LinkButton lnkButton = (LinkButton)sender; //CVH 2017-04-05 RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; ArrayList surfaceDataList = new ArrayList(); if (item.recId > 0) { ToggleRowEdit(item.recId, item, false, rptItem); } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region note and file handling /// /// Notes event from the grid /// /// /// protected void btnNotes_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { //setup notes oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); int itemId = 0, fieldId = 0; string lnkNote = "lnkNote_"; if (sender.GetType() == typeof(LinkButton)) { int.TryParse(((LinkButton)sender).CommandArgument, out itemId); int.TryParse(((LinkButton)sender).ID.Substring(lnkNote.Length), out fieldId); } if (itemId == 0) { if (base.SurfaceAppItemId > 0) itemId = base.SurfaceAppItemId; } if (controlFieldData.surfaceFieldID == 0) //set default values if populating blank form { controlFieldData.surfaceFieldID = fieldId; controlFieldData.surfaceItemId = itemId; controlFieldData.surfaceId = base.SurfaceApp.recId; } if (itemId > 0) { dynamic moduleControl = this.FindControl("notes"); if (moduleControl != null) { moduleControl.ReloadControl(controlFieldData); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNotesModal", "$('#modNotes" + base.SurfaceApp.name + "').modal();", true); } //Session["noteModuleId"] = (int)pNums.Module.Surface; //Session["noteEntityId"] = itemId; //Session["fieldNameNote"] = fieldName; //IControlBase notes = (IControlBase)this.FindControl("notes"); //notes.ReloadControl(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNotesModal", "$('#modNotes" + base.SurfaceApp.name + "').modal();", true); } } } /// /// Atatchments event from Grid /// /// /// protected void btnAttachments_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { //setup attachments int itemId = 0; string fieldName = String.Empty; if (sender.GetType() == typeof(LinkButton)) { int.TryParse(((LinkButton)sender).CommandArgument, out itemId); fieldName = ((LinkButton)sender).ID; } if (itemId == 0) { if (base.SurfaceAppItemId > 0) itemId = base.SurfaceAppItemId; } if (itemId > 0) { Session["moduleId"] = (int)pNums.Module.Surface; Session["entityId"] = itemId; Session["fieldNameFile"] = fieldName; IControlBase files = (IControlBase)this.FindControl("files"); files.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalFiles", "$('#modFiles" + base.SurfaceApp.name + "').modal();", true); } } } /// /// Bind surface notes /// /// private void BindSurfaceNotes(int itemId, bool isView) { try { ArrayList noteFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Note, "sequence"); foreach (oSurfaceField field in noteFields) { if (!isView) { HtmlGenericControl genericNoteDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "fNotes"); if (genericNoteDiv != null) BindNotes(itemId, genericNoteDiv); } else { HtmlGenericControl genericNoteDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "vNotes"); if (genericNoteDiv != null) BindNotes(itemId, genericNoteDiv); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind surface notes /// /// private void BindSurfaceAttachments(int itemId, bool isView) { try { ArrayList attchmentFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Attachment, "sequence"); foreach (oSurfaceField field in attchmentFields) { if (!isView) { HtmlGenericControl genericAttachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "fAttachments"); if (genericAttachDiv != null) BindAttachments(itemId, genericAttachDiv, field.surfaceFieldName); } else { HtmlGenericControl genericAttachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "vAttachments"); if (genericAttachDiv != null) BindAttachments(itemId, genericAttachDiv, field.surfaceFieldName); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Get file type image /// /// /// private string GetFileTypeImage(string fileLocation) { string imgSrc = "/images/doc.png"; try { //string uri = String.Empty; //if (fileLocation.Contains("http")) // uri = fileLocation; //else // uri = Server.MapPath("~" + fileLocation); System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(fileLocation); if (icon != null) { System.Drawing.Image img = icon.ToBitmap(); byte[] byteArray = new byte[0]; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); } string base64 = Convert.ToBase64String(byteArray); imgSrc = String.Format("data:image/png;base64,{0}", base64); } } catch { //do nothing if it fails } return imgSrc; } /// /// Bind Attachments /// /// /// private void BindAttachments(int itemId, HtmlGenericControl parentControl, string fieldName) { try { oSetup _setup = handler.ReturnSetup(); System.Text.StringBuilder formbuilder = new System.Text.StringBuilder(); //CVH 2017-01-17 Calling this method for attachment as Label also // fieldName = parentControl.ID.Replace("LabelfAttachments", ""); //else // fieldName = parentControl.ID.Replace("fAttachments", "").Replace("vAttachments", ""); //CVH 2017-05-29 Arraylist always blank, datatable works fine //ArrayList files = xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId,fieldName", (int)pNums.Module.Surface + "," + itemId.ToString() + "," + fieldName, "dateSaved DESC"); DataTable dtFiles = xData.GetDynamicByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId,fieldName", (int)pNums.Module.Surface + "," + itemId.ToString() + "," + fieldName, "dateSaved DESC"); if (dtFiles != null && dtFiles.Rows.Count > 0) { formbuilder.AppendLine("
"); //get all attachments linked to this event foreach (DataRow row in dtFiles.Rows) { string user = ""; foreach (ovUserShared usr in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", row["userIdSaved"].ToString())) { user = usr.name; break; } string details = "(" + user + " - " + utils.fixDate(row["dateSaved"].ToString()) + ")"; string fileLocation = ""; string pathLocation = ""; string hyperlink = ""; if (row["typeId"].ToString() == pNums.AttachmentType.Document.GetHashCode().ToString()) { fileLocation = Server.MapPath("~/upload/" + row["folderName"].ToString() + "/file/" + row["fileName"].ToString()); pathLocation = row["sourcePath"].ToString() + "/upload/" + row["folderName"].ToString() + "/file/" + row["fileName"].ToString(); if (!File.Exists(fileLocation)) { fileLocation = fileLocation.Replace("/file", ""); pathLocation = pathLocation.Replace("/file", ""); } hyperlink = "" + row["display"].ToString() + " "; //hyperlink = ""; //hyperlink = ""; //hyperlink = ""; //hyperlink = ""; } else { fileLocation = Server.MapPath("~/upload/" + row["folderName"].ToString() + "/image/" + row["fileName"].ToString()); pathLocation = row["sourcePath"].ToString() + "/upload/" + row["folderName"].ToString() + "/image/" + row["fileName"].ToString(); hyperlink = "" + row["display"].ToString() + ""; } formbuilder.AppendLine(hyperlink); } //formbuilder.AppendLine(""); formbuilder.AppendLine("
"); } //RadMediaPlayer med1 = (RadMediaPlayer)parentControl.FindControl("RadMediaPlayer1"); //if (med1 != null) //{ // MediaPlayerVideoFile vid = new MediaPlayerVideoFile(); // vid.Title = "Test"; // vid.Sources.Add(new MediaPlayerSource() { Path = "/upload/surface/20017/file/20017_ibchdakbi.mp4", MimeType= "video/mp4" }); // //ConfigureMediaPlayer(vid); // med1.Sources.Clear(); // med1.StartTime = 0; // med1.Muted = false; // med1.AutoPlay = false; // med1.Title = vid.Title; // //med1.Poster = file.Title == "AppBuilder" ? "images/appBuilderPoster.png" : ""; // foreach (MediaPlayerSource source in vid.Sources) // { // med1.Sources.Add(source); // source.Path = source.Path; // source.MimeType = source.MimeType; // } //} parentControl.InnerHtml = formbuilder.ToString(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Notes /// /// /// private void BindNotes(int itemId, HtmlGenericControl parentControl) { try { parentControl.InnerHtml = ""; ArrayList surfNotes = new ArrayList(); //CVH 2017-01-17 Calling this method for attachment as Label also string fieldName = ""; if (parentControl.ID.IndexOf("LabelfNotes") > 0) fieldName = parentControl.ID.Replace("LabelfNotes", ""); else fieldName = parentControl.ID.Replace("fNotes", "").Replace("vNotes", ""); //get list of all notes linked to this history item foreach (oNote note in xData.GetTypedByCriteriaSpecific("recId", typeof(oNote), "moduleId,entityId,typeId", (int)pNums.Module.Surface + "," + itemId.ToString() + "," + (int)pNums.NoteType.General, "")) { surfNotes.Add(note); } //order notes by date if (surfNotes == null || surfNotes.Count <= 0) return; var notes = surfNotes.OfType().OrderByDescending(n => n.dateSaved).ToArray(); System.Text.StringBuilder formBuilder = new System.Text.StringBuilder(); bool firstNote = true; //loop through notes, get attachment linked to note, and add to form foreach (oNote noteAdd in notes) { //start of group formBuilder.Append("
"); //heading formBuilder.AppendLine("
"); formBuilder.AppendLine(noteAdd.title); formBuilder.AppendLine(""); formBuilder.AppendLine(""); formBuilder.AppendLine(""); formBuilder.AppendLine("
"); //end of heading //toggle panel if (firstNote) { formBuilder.AppendLine("
"); firstNote = false; } else { formBuilder.AppendLine("
"); } //build body of formBuilder.AppendLine("
"); //build horizontal form formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); //row formBuilder.AppendLine("
"); if (noteAdd.customValue != string.Empty) { formBuilder.AppendLine("
"); foreach (oNoteType noteType in xData.GetTypedByCriteriaSpecific("recId", typeof(oNoteType), "recId", noteAdd.typeId.ToString())) { formBuilder.AppendLine("" + noteType.customItem + ": "); } formBuilder.AppendLine(noteAdd.customValue + "
"); } formBuilder.AppendLine("
" + noteAdd.caption + "
"); //get all attachments linked to note ArrayList files = xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId", (int)pNums.Module.Notes + "," + noteAdd.recId.ToString(), ""); if (files.Count > 0) { formBuilder.AppendLine("
"); foreach (oAttachment att in files) { string user = ""; foreach (ovUserShared usr in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", att.userIdSaved.ToString())) { user = usr.name; break; } string details = "(" + user + " - " + utils.fixDate(att.dateSaved) + ")"; string fileLocation = ""; string pathLocation = ""; string hyperlink = ""; if (att.typeId == (int)pNums.AttachmentType.Document) { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/file/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/file/" + att.fileName; if (!File.Exists(fileLocation)) { fileLocation = fileLocation.Replace("/file", ""); pathLocation = pathLocation.Replace("/file", ""); } hyperlink = "" + att.display + ""; } else { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/image/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/image/" + att.fileName; hyperlink = "" + att.display + ""; } formBuilder.AppendLine(hyperlink); } formBuilder.AppendLine("
"); } formBuilder.AppendLine("
"); //end of row //end of horizontal formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); //end of body formBuilder.AppendLine("
"); //end toggle panel formBuilder.AppendLine("
"); //end of group } parentControl.InnerHtml = formBuilder.ToString(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Attachments /// /// /// protected void btnfAddFile_Click(object sender, EventArgs e) { string fieldName = ((LinkButton)sender).ID; hfFieldNameFile.Value = fieldName; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", "$('#modAddFile" + base.SurfaceApp.name + "').on('shown', function () {$(\"#scrtop" + base.SurfaceApp.name + "\").scrollTop(0);});", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModal", "$('#modAddFile" + base.SurfaceApp.name + "').modal();", true); upAddFile.Update(); } /// /// Add notes /// /// /// protected void btnfAddNotes_Click(object sender, EventArgs e) { lblNoteTypeCustom.Text = string.Empty; divNoteCustom.Visible = false; radNewNote.Content = ""; string fieldName = ((LinkButton)sender).ID; hfFieldNameNote.Value = fieldName; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", "$('#modAddNote" + base.SurfaceApp.name + "').on('shown', function () {$(\"#scrtop" + base.SurfaceApp.name + "\").scrollTop(0);});", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModal", "$('#modAddNote" + base.SurfaceApp.name + "').modal();", true); upAddNote.Update(); } /// /// File Uploaded /// /// /// protected void radUpload_FileUploaded(object sender, FileUploadedEventArgs e) { oAttachment Attachment = new oAttachment(); try { oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userAlert", "alert('No user login detected. Operation aborted.');", true); return; } if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false, false)) return; } int itemId = base.SurfaceAppItemId; Attachment.entityId = itemId; Attachment.fieldName = hfFieldNameFile.Value; Attachment.moduleId = (int)pNums.Module.Surface; Attachment.isActive = true; Attachment.typeId = e.File.ContentType.StartsWith("image") ? (int)pNums.AttachmentType.Image : (int)pNums.AttachmentType.Document; string surfFolderName = "surface/"; surfFolderName += itemId.ToString(); Attachment.folderName = surfFolderName; /* CVH 2016-04-15 Add date and user */ int userId = usr.recId; if (Attachment.recId > 0) { Attachment.userIdUpdated = userId; Attachment.dateUpdated = System.DateTime.Now; } else { Attachment.userIdSaved = userId; Attachment.dateSaved = System.DateTime.Now; } Attachment.display = e.File.FileName.Remove(e.File.FileName.LastIndexOf(".")); Attachment.fileName = Attachment.entityId + "_" + utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string imagePath = Server.MapPath("~/upload/" + Attachment.folderName + "/image/"); string thumbPath = Server.MapPath("~/upload/" + Attachment.folderName + "/thumb/"); string tempPath = Server.MapPath("~/upload/" + Attachment.folderName + "/temp/"); string filePath = Server.MapPath("~/upload/" + Attachment.folderName + "/file/"); utils.validateFolder(imagePath); utils.validateFolder(thumbPath); utils.validateFolder(tempPath); utils.validateFolder(filePath); Attachment.sourcePath = ConfigurationManager.AppSettings["WebAddy"]; if (Attachment.typeId == (int)pNums.AttachmentType.Image) { //upload file e.File.SaveAs(tempPath + Attachment.fileName); //resize and crop for thumbnail utils.ResizeCropImagePrecise(tempPath + Attachment.fileName, thumbPath, Attachment.fileName, 383, 264, false); //resize image for a larger size utils.ResizeImage(tempPath + Attachment.fileName, imagePath, Attachment.fileName, 400, true, true); } else { //upload file e.File.SaveAs(filePath + Attachment.fileName); } if (Attachment.recId > 0) { xData.UpdateTyped("recId", Attachment.recId.ToString(), typeof(oAttachment), Attachment); utils.disposeSession("Attachment"); } else { Attachment.recId = xData.SaveTyped("recId", typeof(oAttachment), Attachment); if (Attachment.recId > 0) { } } } catch (Exception ex) { exception.HandleException("Attachments:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } /// /// Close File Modal /// /// /// protected void btnCloseFileModal_Click(object sender, EventArgs e) { //to do find all controls that are notes / attachments and bind if (base.SurfaceAppItemId != 0) { //BindSurfaceNotes(base.SurfaceAppItemId); BindSurfaceAttachments(base.SurfaceAppItemId, false); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceFileRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); } //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalClose", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } /// /// File Notes uploaded /// /// /// protected void radUploadNotes_FileUploaded(object sender, FileUploadedEventArgs e) { oAttachment Attachment = new oAttachment(); try { oUser user = new oUser(); if (utils.verifySession("user")) user = (oUser)Session["user"]; else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userAlert", "alert('No user login detected. Operation aborted.');", true); return; } oNote note = new oNote(); if (ViewState["newNote"] == null) { if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false, false)) return; } int itemId = base.SurfaceAppItemId; //save new note to link attachment to note.caption = radNewNote.Content; note.dateSaved = System.DateTime.Now; note.entityId = itemId; note.fieldName = hfFieldNameNote.Value; note.isActive = true; note.moduleId = (int)pNums.Module.Surface; note.title = user.name + " (" + utils.fixDate(System.DateTime.Now) + ")"; note.typeId = (int)pNums.NoteType.General; note.userIdSaved = user.recId; // Pro-5 if (ddNoteCustom.SelectedItem != null) note.customValue = FindNoteCustomValue(ddNoteCustom.SelectedItem.Text); note.recId = xData.SaveTyped("recId", typeof(oNote), note); ViewState["newNote"] = note; } else { note = (oNote)ViewState["newNote"]; } Attachment.entityId = note.recId; Attachment.fieldName = hfFieldNameNote.Value; Attachment.moduleId = (int)pNums.Module.Notes; Attachment.isActive = true; Attachment.typeId = e.File.ContentType.StartsWith("image") ? (int)pNums.AttachmentType.Image : (int)pNums.AttachmentType.Document; string taskFolderName = "surface/"; taskFolderName += this.SurfaceAppItem.recId.ToString(); Attachment.folderName = taskFolderName; /* CVH 2016-04-15 Add date and user */ int userId = user.recId; if (Attachment.recId > 0) { Attachment.userIdUpdated = userId; Attachment.dateUpdated = System.DateTime.Now; } else { Attachment.userIdSaved = userId; Attachment.dateSaved = System.DateTime.Now; } Attachment.display = e.File.FileName.Remove(e.File.FileName.LastIndexOf(".")); Attachment.fileName = Attachment.entityId + "_" + utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string imagePath = Server.MapPath("~/upload/" + Attachment.folderName + "/image/"); string thumbPath = Server.MapPath("~/upload/" + Attachment.folderName + "/thumb/"); string tempPath = Server.MapPath("~/upload/" + Attachment.folderName + "/temp/"); string filePath = Server.MapPath("~/upload/" + Attachment.folderName + "/file/"); utils.validateFolder(imagePath); utils.validateFolder(thumbPath); utils.validateFolder(tempPath); utils.validateFolder(filePath); Attachment.sourcePath = ConfigurationManager.AppSettings["WebAddy"]; if (Attachment.typeId == (int)pNums.AttachmentType.Image) { //upload file e.File.SaveAs(tempPath + Attachment.fileName); //resize and compress utils.ResizeImage(tempPath + Attachment.fileName, imagePath, Attachment.fileName, 400, true); //resize and crop utils.ResizeCropImagePrecise(imagePath + Attachment.fileName, thumbPath, Attachment.fileName, 383, 264, false); } else { //upload file e.File.SaveAs(filePath + Attachment.fileName); } if (Attachment.recId > 0) { xData.UpdateTyped("recId", Attachment.recId.ToString(), typeof(oAttachment), Attachment); utils.disposeSession("Attachment"); } else { Attachment.recId = xData.SaveTyped("recId", typeof(oAttachment), Attachment); if (Attachment.recId > 0) { } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } /// /// Cancel Click /// /// /// protected void btnCancelNote_Click(object sender, EventArgs e) { //to do find all controls that are notes / attachments and bind if (base.SurfaceAppItemId != 0) { BindSurfaceNotes(base.SurfaceAppItemId, false); //BindSurfaceAttachments(base.SurfaceAppItemId); } //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalClose", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } /// /// Save the surface note /// /// /// protected void btnSaveNote_Click(object sender, EventArgs e) { try { oUser user = new oUser(); if (utils.verifySession("user")) { user = (oUser)Session["user"]; } else { Response.Redirect("/home", false); return; //throw new Exception("Logged on user could not be determined."); } //if viewstate is null, no attachment has been linked to this note, and the note hasn't been saved yet, save it now if (ViewState["newNote"] == null) { if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false, false)) return; } int itemId = base.SurfaceAppItemId; oNote note = new oNote(); note.caption = radNewNote.Content; note.dateSaved = System.DateTime.Now; note.entityId = itemId; note.isActive = true; note.moduleId = (int)pNums.Module.Surface; note.title = user.name + " (" + utils.fixDate(System.DateTime.Now) + ")"; note.fieldName = hfFieldNameNote.Value; note.typeId = (int)pNums.NoteType.General; note.userIdSaved = user.recId; note.recId = xData.SaveTyped("recId", typeof(oNote), note); } else ViewState["newNote"] = null; BindSurfaceNotes(base.SurfaceAppItemId, false); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceFileRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); //BindSurfaceAttachments(base.SurfaceAppItemId,pnlSurfaceView.Visible); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalSave", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } catch (Exception ex) { exception.HandleException("Attachments:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } #endregion #region surface field methods /// /// Enable inline buttons /// private void EnableInlineButtons(bool show = false) { try { if (base.SurfaceApp != null) { btnNewField.Visible = show; btnManagePicklists.Visible = show; btnGrid.Visible = show; //lblPipe.Visible = show; lblPipe1.Visible = show; lblPipe2.Visible = show; btnLookCat.Visible = show; //lblPipe3.Visible = true; //btnSavePositions.Visible = true; ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", base.SurfaceApp.recId + ",1", "sequence", "pal_"); foreach (oSurfaceField field in surfaceFields) { LinkButton lnkEdit = (LinkButton)pnlSurfaceForm.FindControl("lnkInEd" + field.surfaceFieldName); if (lnkEdit != null) lnkEdit.Visible = show; LinkButton lnkAdd = (LinkButton)pnlSurfaceForm.FindControl("lnkInAd" + field.surfaceFieldName); if (lnkAdd != null) lnkAdd.Visible = show; LinkButton lnkRemove = (LinkButton)pnlSurfaceForm.FindControl("lnkInDel" + field.surfaceFieldName); if (lnkRemove != null) lnkRemove.Visible = show; HtmlAnchor anchor = (HtmlAnchor)pnlSurfaceForm.FindControl("lnkInMove" + field.surfaceFieldName); if (anchor != null) anchor.Visible = show; Panel panelInline = (Panel)pnlSurfaceForm.FindControl("pnlInline" + field.surfaceFieldName); if (panelInline != null) panelInline.Visible = show; } Session["InlineApp"] = base.SurfaceApp; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save field positions /// private void SaveFieldPositions() { try { if (base.SurfaceApp != null) { int surfaceId = base.SurfaceApp.recId; //first save navs int tabCounter = 0; int groupcounter = 0; int controlCounter = 0; ArrayList surfaceFieldList = new ArrayList(); //enumerate through each control foreach (Control ctl in pnlSurfaceForm.Controls) { if (ctl.ID != null) { ArrayList FieldList = new ArrayList(); string fieldName = String.Empty; int sequence = 0; if (ctl.ID.StartsWith("li_f"))//tab { tabCounter++; fieldName = ctl.ID.Replace("li_f", ""); sequence = tabCounter; } else if (ctl.ID.StartsWith("divf"))//group { groupcounter++; fieldName = ctl.ID.Replace("divf", ""); sequence = groupcounter; } else//control { if (!ctl.ID.StartsWith("val") && !ctl.ID.StartsWith("lnk") && !ctl.ID.StartsWith("up") && !ctl.ID.StartsWith("req") && !ctl.ID.StartsWith("pnl") && !ctl.ID.StartsWith("lbl")) { controlCounter++; fieldName = ctl.ID; sequence = controlCounter; } } if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //set new sequence field.sequence = sequence; //appedn to field list for update surfaceFieldList.Add(field); break; } } } } if (surfaceFieldList.Count > 0) { if (xData.UpdateTypedCollection("recId", typeof(oSurfaceField), surfaceFieldList)) { pnlResult.Visible = true; lblResult.Text = "Layout was saved successfully."; upSurface.Update(); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindFieldTypes() { try { DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldType), "isActive", "1", "recId"); ddFieldTypes.DataSource = typeData; ddFieldTypes.DataTextField = "surfaceFieldType"; ddFieldTypes.DataValueField = "recId"; ddFieldTypes.DataBind(); ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Parent Fields /// private void BindParentFields() { oSurface surface = new oSurface(); try { if (base.SurfaceApp != null) { surface = base.SurfaceApp; int fieldTypeId = 2;//default to group if (int.Parse(ddFieldTypes.SelectedValue) == (int)pNums.FieldType.Group) fieldTypeId = 1; DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", surface.recId + "," + fieldTypeId, "sequence"); ddParentFields.DataSource = typeData; ddParentFields.DataTextField = "surfaceFieldDisplay"; ddParentFields.DataValueField = "recId"; ddParentFields.DataBind(); //CVH 2017-02-14 Add subtab functionality. If selected field is Tab, allow it to be linked to a group parent ddParentFields.Items.Insert(0, new ListItem("None", "0")); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindLookupCategories() { try { DataTable lookData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookupCategory), "isActive", "1", "lookupCategory"); ddLookupCategory.DataSource = lookData; ddLookupCategory.DataValueField = "recId"; ddLookupCategory.DataTextField = "lookupCategory"; ddLookupCategory.DataBind(); ddLookupCategory.Items.Insert(0, new ListItem("select...", "0")); DataTable moduleLookupData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "isActive,isPicklist", "1,1", "module"); foreach (DataRow row in moduleLookupData.Rows) { ddModuleLookup.Items.Add(new ListItem(row["module"].ToString(), row["objectName"].ToString())); } ddModuleLookup.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Action Types /// private void BindActionTypes() { try { DataTable actionTypeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceActionType), "isActive", "1", "recId"); ddActionTypes.DataSource = actionTypeData; ddActionTypes.DataTextField = "actionType"; ddActionTypes.DataValueField = "recId"; ddActionTypes.DataBind(); ddActionTypes.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Actions from Action Type /// /// private void BindActions(string actionTypeId) { try { DataTable actionData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceAction), "isActive,actionType", "1," + actionTypeId, "recId"); ddActions.DataSource = actionData; ddActions.DataTextField = "action"; ddActions.DataValueField = "recId"; ddActions.DataBind(); ddActions.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Action Source from Action /// /// private void BindActionSource(string fieldTypeIds) { try { DataTable actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceFieldTypeId", "1,~()" + fieldTypeIds, "recId"); ddActionSource.DataSource = actionSourceData; ddActionSource.DataTextField = "surfaceFieldDisplay"; ddActionSource.DataValueField = "recId"; ddActionSource.DataBind(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Method to Bind the slide Order Drop down /// private void BindSequence() { try { for (int i = 0; i < 50; i++) { //append sequence item ddSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulateFieldFormValues(ref oSurfaceField _SurfaceField) { try { chkActiveField.Checked = _SurfaceField.isActive; chkGridActive.Checked = _SurfaceField.isGrid; chkFilter.Checked = _SurfaceField.isFilter; chkRequired.Checked = _SurfaceField.required; chkIsAutoPostback.Checked = _SurfaceField.isAutoPostback; chkHiddenField.Checked = _SurfaceField.isHidden; chkHiddenWizzard.Checked = _SurfaceField.isHiddenFromWizzard; chkReadOnlyField.Checked = _SurfaceField.isReadOnly; //JR Bas-Pro-3 chkUnique.Checked = _SurfaceField.isUnique; txtLength.Value = _SurfaceField.length.ToString(); txtDisplay.Value = _SurfaceField.surfaceFieldDisplay; txtPlaceholder.Value = _SurfaceField.placeholder; if (ddFieldTypes.Items.FindByValue(_SurfaceField.surfaceFieldTypeId.ToString()) != null) ddFieldTypes.SelectedValue = _SurfaceField.surfaceFieldTypeId.ToString(); BindParentFields(); if (_SurfaceField.sequence > 0) ddSequence.SelectedItem.Text = _SurfaceField.sequence.ToString(); if (ddLookupCategory.Items.FindByValue(_SurfaceField.lookupCategory.ToString()) != null) ddLookupCategory.SelectedValue = _SurfaceField.lookupCategory.ToString(); if (_SurfaceField.relationalObject.ToString().Length > 0 && ddModuleLookup.Items.FindByValue(_SurfaceField.relationalObject.ToString()) != null) ddModuleLookup.SelectedValue = _SurfaceField.relationalObject.ToString(); if (_SurfaceField.parentId > 0) ddParentFields.SelectedValue = _SurfaceField.parentId.ToString(); /* Rev 001 Select surface app if field is Grid Type * Charlene van Heerden * 7 January 2016 */ /* CVH 2016-01-22 RelField */ if (ddSurfaceApps.Items.FindByValue(_SurfaceField.relationalSurface) != null) { if (ddSurfaceApps.Items.FindByValue(_SurfaceField.relationalSurface) != null) ddSurfaceApps.SelectedValue = _SurfaceField.relationalSurface; BindSurfaceAppFields(_SurfaceField.relationalSurface); } else { ddSurfaceApps.SelectedValue = "0"; } /* CVH 2016-01-22 RelField */ if (ddSurfaceAppFields.Items.FindByValue(_SurfaceField.relationalFields) != null) ddSurfaceAppFields.SelectedValue = _SurfaceField.relationalFields; else ddSurfaceAppFields.SelectedValue = "0"; if (_SurfaceField.contentId != 0) { if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) ddContent.SelectedValue = _SurfaceField.contentId.ToString(); if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) ddComposite.SelectedValue = _SurfaceField.contentId.ToString(); } chkIsControlled.Checked = _SurfaceField.isControlled; if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; txtControlledValue.Value = _SurfaceField.controlledValue; txtControlText.Value = _SurfaceField.controlText; if (ddActionTypes.Items.FindByValue(_SurfaceField.actionType.ToString()) != null) { ddActionTypes.SelectedValue = _SurfaceField.actionType.ToString(); BindActions(_SurfaceField.action.ToString()); actionGroup.Visible = true; if (ddActions.Items.FindByValue(_SurfaceField.action.ToString()) != null) { ddActions.SelectedValue = _SurfaceField.action.ToString(); string action = ddActions.SelectedItem.Text; switch (action) { case "VAT": BindActionSource(pNums.FieldType.Decimal.ToString()); break; case "Age": BindActionSource(pNums.FieldType.Date.ToString() + "|" + ((int)pNums.FieldType.Text).ToString()); break; case "Gender": BindActionSource(pNums.FieldType.Text.ToString()); break; default: break; case "Copy": string destType = ddFieldTypes.SelectedValue; BindActionSource(destType); break; } actionSourceGroup.Visible = true; if (ddActionSource.Items.FindByValue(_SurfaceField.actionSource.ToString()) != null) { ddActionSource.SelectedValue = _SurfaceField.actionSource.ToString(); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// /// /// REVISION 001: When field type is grid, add surface app name as relationalSurface /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// private void SaveFieldFormValues(ref oSurfaceField _SurfaceField) { try { _SurfaceField.isActive = chkActiveField.Checked; _SurfaceField.isFilter = chkFilter.Checked; _SurfaceField.isGrid = chkGridActive.Checked; _SurfaceField.required = chkRequired.Checked; _SurfaceField.isAutoPostback = chkIsAutoPostback.Checked; _SurfaceField.isHidden = chkHiddenField.Checked; _SurfaceField.isHiddenFromWizzard = chkHiddenWizzard.Checked; _SurfaceField.isReadOnly = chkReadOnlyField.Checked; //JR Bas-Pro-3 _SurfaceField.isUnique = chkUnique.Checked; int length = 0; int.TryParse(txtLength.Value, out length); _SurfaceField.length = length; int parent = 0; int.TryParse(ddParentFields.SelectedValue, out parent); _SurfaceField.parentId = parent; int seq = 0; int.TryParse(ddSequence.SelectedItem.Text, out seq); _SurfaceField.sequence = seq; _SurfaceField.surfaceFieldDisplay = txtDisplay.Value; _SurfaceField.placeholder = txtPlaceholder.Value; int fieldType = 0; int.TryParse(ddFieldTypes.SelectedValue, out fieldType); _SurfaceField.surfaceFieldTypeId = fieldType; if (ddFieldTypes.SelectedValue != ((int)pNums.FieldType.Tab).ToString() && ddFieldTypes.SelectedValue != ((int)pNums.FieldType.HeaderGroup).ToString()) { if (ddFieldTypes.SelectedValue != ((int)pNums.FieldType.Group).ToString()) { int groupId = 0; string tabName = String.Empty; if (ddParentFields.SelectedValue != null) { groupId = int.Parse(ddParentFields.SelectedValue); foreach (oSurfaceField grp in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", groupId.ToString())) { foreach (oSurfaceField tab in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", grp.parentId.ToString())) { tabName = tab.surfaceFieldDisplay; } } } _SurfaceField.surfaceFieldName = utils.stripCharacters(tabName).Replace(" ", "") + "_" + utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } else { _SurfaceField.surfaceFieldName = utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } } else { _SurfaceField.surfaceFieldName = utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } _SurfaceField.lookupCategory = int.Parse(ddLookupCategory.SelectedValue); if (ddModuleLookup.SelectedIndex > 0) { _SurfaceField.relationalObject = ddModuleLookup.SelectedValue; } /* Rev 001 Add relationalSurface if Grid type selected * Charlene van Heerden * 10 December 2015 */ string relationalSurface = ""; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField) relationalSurface = ddSurfaceApps.SelectedValue; _SurfaceField.relationalSurface = relationalSurface; /* CVH 2016-01-22 RelField */ _SurfaceField.relationalFields = ddSurfaceAppFields.SelectedValue; /*JasR 2016-01-13*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) { int contentID = 0; int.TryParse(ddContent.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } /*JasR 2016-01-15*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { _SurfaceField.defaultToCurrent = chkDefaultCurrent.Checked; } /*JasR 2016-01-15*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Number) { _SurfaceField.isControlled = chkIsControlled.Checked; _SurfaceField.controlledValue = txtControlledValue.Value; } /*JasR 2016-01-16*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Button || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Checkbox || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Mediswitch) { _SurfaceField.controlText = txtControlText.Value; } if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) { int contentID = 0; int.TryParse(ddComposite.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } if (ddActionSource.SelectedValue != null && ddActionSource.SelectedValue != String.Empty) _SurfaceField.actionSource = Convert.ToInt32(ddActionSource.SelectedValue); if (ddActions.SelectedValue != null && ddActions.SelectedValue != String.Empty) _SurfaceField.action = Convert.ToInt32(ddActions.SelectedValue); if (ddActionTypes.SelectedValue != null && ddActionTypes.SelectedValue != String.Empty) _SurfaceField.actionType = Convert.ToInt32(ddActionTypes.SelectedValue); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Toggle Field Types /// /// /// REVISION 001: Add Grid field type /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// private void ToggleFieldTypes() { try { //set default views lookupGroup.Visible = false; moduleLookupGroup.Visible = false; validationGroup.Visible = true; lengthGroup.Visible = true; /* Rev 001 Hide Surface App * Charlene van Heerden * 10 December 2015 */ surfaceApp.Visible = false; /* CVH 2016-01-22 RelField */ surfaceAppFields.Visible = false; content.Visible = false; defaultDateCurrent.Visible = false; isControlled.Visible = false; controlledValue.Visible = false; controlText.Visible = false; isAutoPostback.Visible = false; parentGroup.Visible = true; //CVH 2017-02-14 Subtab. Get currently selected parent, then rebind parent dropdown, then reselect if list is the same (list depends on field type) string selectedParentId = "0"; if (ddParentFields.SelectedItem != null) selectedParentId = ddParentFields.SelectedItem.Value; BindParentFields(); if (ddParentFields.Items.FindByValue(selectedParentId) != null) ddParentFields.Items.FindByValue(selectedParentId).Selected = true; chkGridActive.Visible = true; chkFilter.Visible = true; chkHiddenField.Visible = true; chkHiddenWizzard.Visible = false; chkReadOnlyField.Visible = true; placeholderGroup.Visible = false; compositeGroup.Visible = false; //JR Bas-Pro-3 chkUnique.Visible = false; actionTypeGroup.Visible = true; if (ddActionTypes.SelectedIndex > 0) { actionGroup.Visible = true; if (ddActions.SelectedIndex > 0) { actionSourceGroup.Visible = true; } } //change views based on selected field type pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), int.Parse(ddFieldTypes.SelectedValue)); switch (typ) { case pNums.FieldType.Tab: //parentGroup.Visible = false; validationGroup.Visible = false; lengthGroup.Visible = false; chkGridActive.Visible = false; chkFilter.Visible = false; chkHiddenField.Visible = false; chkReadOnlyField.Visible = true; chkHiddenWizzard.Visible = true; actionTypeGroup.Visible = false; actionGroup.Visible = false; actionSourceGroup.Visible = false; break; case pNums.FieldType.Group: validationGroup.Visible = false; lengthGroup.Visible = false; chkGridActive.Visible = false; chkFilter.Visible = false; chkHiddenField.Visible = true; chkReadOnlyField.Visible = false; actionTypeGroup.Visible = false; actionGroup.Visible = false; actionSourceGroup.Visible = false; break; case pNums.FieldType.Text: isAutoPostback.Visible = true; placeholderGroup.Visible = true; //JR Bas-Pro-3 chkUnique.Visible = true; break; case pNums.FieldType.Number: isAutoPostback.Visible = true; isControlled.Visible = true; if (chkIsControlled.Checked) controlledValue.Visible = true; //JR Bas-Pro-3 chkUnique.Visible = true; break; case pNums.FieldType.Decimal: isAutoPostback.Visible = true; break; case pNums.FieldType.Picklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; break; case pNums.FieldType.MultiPicklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; break; case pNums.FieldType.Date: isAutoPostback.Visible = true; lengthGroup.Visible = false; defaultDateCurrent.Visible = true; break; case pNums.FieldType.Checkbox: lengthGroup.Visible = false; controlText.Visible = true; isAutoPostback.Visible = true; break; case pNums.FieldType.RadioButtonList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "RadioButtonList Category"; lengthGroup.Visible = false; break; case pNums.FieldType.Button: lengthGroup.Visible = false; controlText.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.Grid: lengthGroup.Visible = false; surfaceApp.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.Attachment: lengthGroup.Visible = false; break; case pNums.FieldType.RelationalField: lengthGroup.Visible = false; surfaceApp.Visible = true; surfaceAppFields.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.FormulaField: break; case pNums.FieldType.Content: content.Visible = true; lengthGroup.Visible = false; validationGroup.Visible = false; break; case pNums.FieldType.Placeholder: lengthGroup.Visible = false; break; //JasR 2016-01-27 case pNums.FieldType.Caption: isAutoPostback.Visible = false; placeholderGroup.Visible = true; break; case pNums.FieldType.Note: lengthGroup.Visible = false; break; case pNums.FieldType.Debtors: lengthGroup.Visible = false; break; case pNums.FieldType.Mediswitch: lengthGroup.Visible = false; controlText.Visible = true; break; case pNums.FieldType.Composite: lengthGroup.Visible = false; compositeGroup.Visible = true; break; case pNums.FieldType.CheckboxList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "CheckboxList Category"; lengthGroup.Visible = false; break; case pNums.FieldType.Sales: lengthGroup.Visible = false; break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Surface Apps /// private void BindSurfaceApps() { try { ArrayList surfaceApps = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "isActive", "1", "surface"); ddSurfaceApps.DataSource = surfaceApps; ddSurfaceApps.DataTextField = "surface"; ddSurfaceApps.DataValueField = "name"; ddSurfaceApps.DataBind(); ddSurfaceApps.Items.Insert(0, new ListItem("Select Surface", "0")); /* CVH 2016-01-22 Add 0 item */ ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Surface App Fields /// private void BindSurfaceAppFields(string surfaceName) { try { foreach (oSurface surface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", surfaceName)) { ArrayList surfaceAppFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", surface.recId + ",1"); ddSurfaceAppFields.DataSource = surfaceAppFields; ddSurfaceAppFields.DataTextField = "surfaceFieldDisplay"; ddSurfaceAppFields.DataValueField = "recId"; ddSurfaceAppFields.DataBind(); } ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("canvas:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Content Items /// private void BindContent() { try { ArrayList contentItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "isActive", "1", "title"); ddContent.DataSource = contentItems; ddContent.DataTextField = "title"; ddContent.DataValueField = "recId"; ddContent.DataBind(); ddContent.Items.Insert(0, new ListItem("Select Content", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Composite Items /// private void BindComposite() { try { ArrayList compositeItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oComposite), "", "", "composite"); ddComposite.DataSource = compositeItems; ddComposite.DataTextField = "composite"; ddComposite.DataValueField = "canvasId"; ddComposite.DataBind(); ddComposite.Items.Insert(0, new ListItem("Select Composite", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } #endregion #region surface field events /// /// Save Layout /// /// /// protected void btnSavePositions_Click(object sender, EventArgs e) { try { SaveFieldPositions(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnCloseField_Click(object sender, EventArgs e) { try { string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Picklist Modal /// /// /// protected void btnClosePicklist_Click(object sender, EventArgs e) { try { BindLookupCategories(); upSurfaceFields.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Categpry /// /// /// protected void btnCloseCategory_Click(object sender, EventArgs e) { try { BindLookupCategories(); upSurfaceFields.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myPicklistModal", "$('#modLoookups" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surfaceLookups", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Manage Picklists /// /// /// protected void btnManagePicklists_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myPicklistModal", "$('#modLoookups" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnLookCat_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myCatModal", "$('#modLookupCategories" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// manage Grid Options /// /// /// protected void btnGrid_Click(object sender, EventArgs e) { try { if (base.SurfaceApp != null) { Session["surface"] = base.SurfaceApp; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myGridOptionsModal", "$('#modGridOptions" + base.SurfaceApp.name + "').modal();", true); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Grid Options /// /// /// protected void btnCloseGridOptions_Click(object sender, EventArgs e) { try { upSurfaceFields.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add New Field /// /// /// protected void btnNewField_Click(object sender, EventArgs e) { oSurface Surface = new oSurface(); try { if (base.SurfaceApp != null) { Session["surfaceFieldId"] = 0; utils.disposeSession("surfaceField"); oSurfaceField SurfaceField = new oSurfaceField(); PopulateFieldFormValues(ref SurfaceField); upSurfaceFields.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewFieldScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewFieldScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); } else { Response.Redirect("/home", false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add New Field /// /// /// protected void btnNewGroupField_Click(object sender, EventArgs e) { oSurface Surface = new oSurface(); ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton) && base.SurfaceApp != null) { //get field name string fieldName = ((LinkButton)sender).ID.Replace("lnkInAd", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { Session["surfaceFieldId"] = 0; utils.disposeSession("surfaceField"); oSurfaceField SurfaceField = new oSurfaceField(); SurfaceField.surfaceFieldTypeId = (int)pNums.FieldType.Text; SurfaceField.parentId = field.recId; PopulateFieldFormValues(ref SurfaceField); upSurfaceFields.Update(); //show modal //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); break; } ToggleFieldTypes(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewGroupScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewGroupScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); } } if (base.SurfaceApp != null) { } else { Response.Redirect("/home", false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface field /// /// /// /// /// REVISION 001: Enable Grid field type. Confirm that surface app loading as Grid Field type is not the current surface app being created /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// protected void btnSaveSurfaceField_Click(object sender, EventArgs e) { oSurfaceField SurfaceField = new oSurfaceField(); oSurface surface = new oSurface(); try { if (base.SurfaceApp != null) { surface = base.SurfaceApp; if (utils.verifySession("surfaceField"))//update mode { SurfaceField = (oSurfaceField)Session["surfaceField"]; //save form values SaveFieldFormValues(ref SurfaceField); /* Rev 001 If field type is grid, verify that selected surface app is not same as current surface app * Charlene van Heerden * 10 December 2015 */ if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; } else { if (xData.UpdateTyped("recId", SurfaceField.recId.ToString(), typeof(oSurfaceField), SurfaceField)) { BuildControl(surface); //oSurfaceItem item = new oSurfaceItem(); //item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceForm(item, false); //TogglePanels("pnlSurfaceForm"); //if (this.SurfaceApp.isModal) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //upSurface.Update(); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your changes were updated successfully."; string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); ; } } } else { //save form values SaveFieldFormValues(ref SurfaceField); if (!xData.VerifyExists("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surface.recId + "," + SurfaceField.surfaceFieldName)) { /* Rev 001 If field type is grid, verify that selected surface app is not same as current surface app * Charlene van Heerden * 10 December 2015 */ if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; } else { SurfaceField.surfaceId = surface.recId; SurfaceField.recId = xData.SaveTyped("recId", typeof(oSurfaceField), SurfaceField); if (SurfaceField.recId > 0) { BuildControl(surface); //oSurfaceItem item = new oSurfaceItem(); //item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceForm(item, false); //TogglePanels("pnlSurfaceForm"); //if (this.SurfaceApp.isModal) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //upSurface.Update(); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your surface field was created successfully."; string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } } } else { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field with this name already exists on this surface app."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Field /// /// /// protected void lnkEditField_Click(object sender, EventArgs e) { oSurfaceField _SurfaceField = new oSurfaceField(); ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton) && base.SurfaceApp != null) { //get field name string fieldName = ((LinkButton)sender).ID.Replace("lnkInEd", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { Session["surfaceFieldId"] = field.recId; //assign object _SurfaceField = field; //populate page form PopulateFieldFormValues(ref _SurfaceField); Session["surfaceField"] = _SurfaceField; upSurfaceFields.Update(); break; } ToggleFieldTypes(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditFieldScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditFieldScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditField", "$('#modField" + base.SurfaceApp.name + ":first').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove field /// /// /// protected void lnkRemoveField_Click(object sender, EventArgs e) { ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // string fieldName = ((LinkButton)sender).ID.Replace("lnkInDel", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //Delete cat if (xData.DeleteTyped("recId", field.recId.ToString(), typeof(oSurfaceField))) { BuildControl(base.SurfaceApp); string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } break; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Field Type selection change /// /// /// protected void ddFieldTypes_SelectedIndexChanged(object sender, EventArgs e) { try { ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// PArent Fields Selection Changed /// /// /// protected void ddParentFields_SelectedIndexChanged(object sender, EventArgs e) { try { } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Check if number is controlled and then show controlled value /// /// /// protected void chkIsControlled_CheckedChanged(object sender, EventArgs e) { if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; } /// /// Load surface app fields /// /// /// protected void ddSurfaceApps_SelectedIndexChanged(object sender, EventArgs e) { /* CVH 2016-01-22 RelField */ try { DropDownList list = (DropDownList)sender; string value = list.SelectedValue.ToString(); //load surface fields drop down BindSurfaceAppFields(value); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Change Action Type /// /// /// protected void ddActionTypes_SelectedIndexChanged(object sender, EventArgs e) { BindActions(ddActionTypes.SelectedValue.ToString()); actionGroup.Visible = true; } /// /// Change Action /// /// /// protected void ddActions_SelectedIndexChanged(object sender, EventArgs e) { string action = ddActions.SelectedItem.Text; switch (action) { case "VAT": BindActionSource(pNums.FieldType.Decimal.ToString()); break; case "Age": BindActionSource(pNums.FieldType.Date.ToString() + "|" + ((int)pNums.FieldType.Text).ToString()); break; case "Gender": BindActionSource(pNums.FieldType.Text.ToString()); break; default: break; } actionSourceGroup.Visible = true; } #endregion #region properties public Dictionary SurfaceGridTotals { get { if (ViewState["totalsDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["totalsDictionary"]; } set { ViewState["totalsDictionary"] = value; } } public Dictionary SurfaceGridAverages { get { if (ViewState["averagesDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["averagesDictionary"]; } set { ViewState["averagesDictionary"] = value; } } public oSurfaceGridOptions MainGridOptions { get { if (ViewState["mainGridOptions"] == null) { oSurfaceGridOptions gridOptions = new oSurfaceGridOptions(); foreach (oSurfaceGridOptions gridOptionsItem in xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) { gridOptions = gridOptionsItem; } return gridOptions; } else return (oSurfaceGridOptions)ViewState["mainGridOptions"]; } set { ViewState["mainGridOptions"] = value; } } public ArrayList MainSurface { get { if (ViewState["mainSurface"] == null) return xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", base.SurfaceApp.recId.ToString()); else return (ArrayList)ViewState["mainSurface"]; } } public DataTable MainFieldTable { get { if (ViewState["mainFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.SurfaceApp.recId.ToString() + ",1", "sequence"); else return (DataTable)ViewState["mainFieldTable"]; } set { ViewState["mainFieldTable"] = value; } } public DataTable ChildFieldTable { get { if (ViewState["childFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.ParentSurfaceId + ",1", "sequence"); else return (DataTable)ViewState["childFieldTable"]; } set { ViewState["childFieldTable"] = value; } } public DataTable SuburbTable { get { if (ViewState["suburbTable"] == null) { DataTable dtSuburbs = new DataTable(); foreach (oSurfaceLookupCategory cat in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookupCategory), "lookupCategory,isActive", "Suburbs,1")) { dtSuburbs = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookup), "categoryId,isActive", cat.recId.ToString() + ",1"); } return dtSuburbs; } else return (DataTable)ViewState["suburbTable"]; } } public oUser User { get { return handler.ReturnUser(); } set { Session["user"] = value; } } #endregion }