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); 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") && (_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", "")); } } 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 //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 || 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); //repopulate PopulateSurfaceFormCustom(item, false); 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 (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); if (groupControl != null) { 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 (_isCustomSource) ddDropdownlist.SelectedValue = ""; else ddDropdownlist.SelectedValue = "0"; } } #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