using framework_business; using framework_library; 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.Text; using System.Threading.Tasks; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using Telerik.Web.UI; public partial class controls_surface_surface : 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 totalled - 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(); int startIndex = 0; int maxLength = 50; //foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) //{ if (MainGridOptions.pagingCount > 0) { maxLength = MainGridOptions.pagingCount; if (ddSurfaceEntries.Items.FindByValue(MainGridOptions.pagingCount.ToString()) != null) ddSurfaceEntries.SelectedValue = MainGridOptions.pagingCount.ToString(); } btnNew.Visible = user.userType >= MainGridOptions.addAccessType; //break; //} if (!base.IsChildSurface) { BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(false); } if (!isPersisting) { if (item.recId > 0 || isNew) { if (user.userType > (int)pNums.UserType.PowerUser) { //surface field handling BindFieldTypes(); BindSequence(); BindLookupCategories(); BindSurfaceApps(); BindContent(); BindComposite(); BindActionTypes(); //show edit/add/remove buttons for inline edit CheckBox chkToggleLayout = (CheckBox)pnlSurfaceForm.FindControl("chkToggleLayout"); if (chkToggleLayout != null) chkToggleLayout.Visible = true; pnlSurfaceFieldModal.Visible = true; } else { chkToggleLayout.Visible = false; EnableInlineButtons(false); pnlParentSurfaceOptions.Visible = false; } if (isView) { PopulateSurfaceView(item); TogglePanels("pnlSurfaceView"); } 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"); //if (isNew) // NewItem(); } } else { TogglePanels("pnlSurfaceGrid"); } } //int count = BindSurfaceGrid(startIndex, maxLength); //TogglePanels("pnlSurfaceGrid"); //if (base.IsChildSurface) //{ // /* CVH 2016-08-29 Only toggle to surface form if surface is not modal, otherwise modal pops up the whole time */ // if (count <= 0 && !this.SurfaceApp.isModal) // { // /*CVH 2016-10-20 Don't do this anymore. // * It causes a surface to go into form mode if it is a child and there are no records saved. // * (So it overrides the Default To Form setting not checked) // * This is problematic for TSP, when it needs to copy the master data for the child // */ // //oSurfaceItem item = new oSurfaceItem(); // //item.surfaceId = base.SurfaceApp.recId; // //base.SurfaceAppItemId = item.recId; // //PopulateSurfaceForm(item, true); // //TogglePanels("pnlSurfaceForm"); // //if (this.Parent.ID.StartsWith("plcv")) // //{ // // pnlSurfaceForm.Enabled = false; // // btnNew.Enabled = false; // //} // //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setLoadOptionsSwitches", "setLoadOptionsSwitches();", true); // } // else // { // if (base.SurfaceApp.isComparable) // { // BindCompareDropdowns(base.SurfaceApp); // lnkGridView.Visible = true; // TogglePanels("pnlSurfaceCompare"); // } // else if (base.RowLimit == 1 && base.SurfaceAppItem != null) // { // PopulateSurfaceView(base.SurfaceAppItem); // TogglePanels("pnlSurfaceView"); // } // else // TogglePanels("pnlSurfaceGrid"); // if (this.Parent.ID.StartsWith("plcv")) // { // pnlSurfaceGrid.Enabled = false; // btnNew.Enabled = false; // } // } //} } /// /// Overridible Save Control /// public override void SaveControl(bool finish, bool draft, bool closing) { // } #endregion #region methods /// /// Method to Bind the surface Grid /// private int BindSurfaceGrid(int startIndex, int maxRecords) { int recCount = 0; try { oUser user = handler.ReturnUser(); if (base.SurfaceApp != null) { oSurface surfaceApp = base.SurfaceApp; DataTable surfaceData = new DataTable(); #region ChildSurface if (base.IsChildSurface) { if (base.ParentSurfaceItemId != 0) { pnlSurfaceGridFilter.Visible = false; //foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", base.SurfaceApp.recId.ToString())) foreach (oSurface gridSurface in MainSurface) { ArrayList gridFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.ParentSurfaceId + ",1," + (int)pNums.FieldType.Grid, "sequence"); //foreach (oSurfaceField gridField in ChildFieldTable.Select("surfaceFieldTypeId=" + (int)pNums.FieldType.Grid + "").AsEnumerable().Cast()) foreach (oSurfaceField gridField in gridFields) { if (gridField.relationalSurface == gridSurface.name) { int rowLimit = 0; int.TryParse(gridField.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 (gridField.isControlled) { List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = base.SurfaceApp.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.ParentSurfaceItemId; list.Add(par2); oDynamicParam par3 = new oDynamicParam(); par3.paramDisplayName = "RowLimit"; par3.paramObject = rowLimit; list.Add(par3); surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceDataSummarized", list); } else { List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = base.SurfaceApp.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.ParentSurfaceItemId; list.Add(par2); oDynamicParam par3 = new oDynamicParam(); par3.paramDisplayName = "RowLimit"; par3.paramObject = rowLimit; list.Add(par3); surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); if (rowLimit > 0) { string limitDisplay = " (Last " + rowLimit.ToString() + ")"; if (!lblPanelHeading.Text.Contains(limitDisplay)) lblPanelHeading.Text = lblPanelHeading.Text + limitDisplay; if (base.RowLimit == 1 && surfaceData.Rows.Count == 1) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", surfaceData.Rows[0][0].ToString())) { base.SurfaceAppItem = item; break; } } } if (surfaceData.Rows.Count == 0 && gridField.defaultToCurrent) { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //get child surface fields //ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", gridSurface.recId.ToString()); //save copy of master data - JR nope just get it, save on save List paramList = new List(); par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = gridSurface.recId; paramList.Add(par1); par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = 0; paramList.Add(par2); // DataTable masterDataItems = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); //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 = gridSurface.recId; // copyItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), copyItem); // 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.ParentSurfaceItemId; // } // break; // } // } // copyData.recId = xData.SaveTyped("recId", typeof(oSurfaceFieldData), copyData); // } //} //get newly created data //paramList = new List(); //par1 = new oDynamicParam(); //par1.paramDisplayName = "SurfaceID"; //par1.paramObject = gridSurface.recId; //paramList.Add(par1); //par2 = new oDynamicParam(); //par2.paramDisplayName = "ParentSurfaceItemId"; //par2.paramObject = base.ParentSurfaceItemId; //paramList.Add(par2); //surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); } } break; } } } } } #endregion #region not ChildSurface else { //CVH 2017-01-31 Add filter string filter = BuildSurfaceGridFilter(); //userLink specifics int userLink = 0; if (utils.verifySession("user")) user = (oUser)Session["user"]; if (surfaceApp.linkUser && user.userType == (int)pNums.UserType.WebsiteUser) userLink = user.recId; int TotalRows = xData.GetSurfaceDataCount(surfaceApp.recId, userLink, filter); if ((TotalRows / maxRecords).ToString().Contains(".")) { lblPageCount.Text = (int.Parse((((TotalRows / maxRecords) + 1)).ToString().Substring(0, (((TotalRows / maxRecords) + 1)).ToString().IndexOf("."))) + 2).ToString(); } else { lblPageCount.Text = ((TotalRows / maxRecords) + 1).ToString(); } if (lblPageCount.Text == "1") { btnPageBack.Enabled = false; btnPageNext.Enabled = false; txbPageNumber.Disabled = true; } else { btnPageBack.Enabled = true; btnPageNext.Enabled = true; txbPageNumber.Disabled = false; } lblCount.Text = TotalRows.ToString(); int pageIndex = 1; if (txbPageNumber.Value != String.Empty) int.TryParse(txbPageNumber.Value, out pageIndex); if (pageIndex > int.Parse(lblPageCount.Text)) pageIndex = int.Parse(lblPageCount.Text); if (pageIndex > 0) startIndex = (pageIndex - 1) * maxRecords; else startIndex = 0 * maxRecords; //set the display fields if (pageIndex > 0) txbPageNumber.Value = (pageIndex).ToString(); else txbPageNumber.Value = "1"; //TO DO sort ordering //string orderBy = ddSortBy.SelectedValue; string searchVal = txbSearchSurface.Value; //fetch the paged data surfaceData = xData.GetSurfaceDataPaged(surfaceApp.recId, startIndex, maxRecords, "", searchVal, User.recId, userLink, filter, false); } #endregion if (surfaceData != null) recCount = surfaceData.Rows.Count; foreach (Control rpt in pnlSurfaceGrid.Controls) { if (rpt.GetType() == typeof(Repeater)) { Repeater repeater = (Repeater)rpt; //MainGridOptions = (oSurfaceGridOptions)xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())[0]; SetAggregates(surfaceData, surfaceApp.recId); repeater.DataSource = surfaceData; repeater.DataBind(); //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetVerticalheading", "rotateHeadCell('"+surfaceApp.recId.ToString()+"');", true); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return recCount; } /// /// 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(int surfaceId) { try { foreach (oSurface gridSurface 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) { UpdatePanel upGroup = null; foreach (oSurfaceField group in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", gridField.parentId.ToString())) { if (gridField.relationalSurface == gridSurface.name) { HtmlGenericControl divGridHolder = null; Panel panelGridHolder = null; Panel panelCompareHolder = null; Panel panelFormHolder = null; //CVH 2016-12-01 Find pnlSurfaceGrid_ for current surface, not child surfaceId, otherwise panel is null if (pnlSurfaceForm.Visible) { if (pnlSurfaceForm.FindControl("div" + gridField.surfaceFieldName) != null) divGridHolder = (HtmlGenericControl)pnlSurfaceForm.FindControl("div" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceGrid_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceForm_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("up" + group.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceForm.FindControl("up" + group.surfaceFieldName); } else { if (pnlSurfaceForm.FindControl("divv" + gridField.surfaceFieldName) != null) divGridHolder = (HtmlGenericControl)pnlSurfaceView.FindControl("divv" + gridField.surfaceFieldName); if (pnlSurfaceView.FindControl("pnlSurfaceGrid_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceGrid_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceCompare_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceCompare_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("pnlSurfaceForm_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceForm.FindControl("pnlSurfaceForm_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceForm.FindControl("upv" + group.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceForm.FindControl("upv" + group.surfaceFieldName); } if (divGridHolder != null) { DataTable childData = new DataTable(); int surfaceChildId = 0; oSurface childSurface = new oSurface(); foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", gridField.relationalSurface)) { surfaceChildId = surf.recId; childSurface = surf; break; } if (surfaceChildId > 0) { int rowLimit = 0; int.TryParse(gridField.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 (gridField.isControlled) { List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = surfaceChildId; 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 = surfaceChildId; 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 && gridField.defaultToCurrent) { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", gridSurface.recId.ToString()); //save copy of master data - JR nope - just get. save on save List paramList = new List(); par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = gridSurface.recId; paramList.Add(par1); par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = 0; paramList.Add(par2); //DataTable masterDataItems = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); //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 = gridSurface.recId; // copyItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), copyItem); // 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.ParentSurfaceItemId; // } // break; // } // } // copyData.recId = xData.SaveTyped("recId", typeof(oSurfaceFieldData), copyData); // } //} ////get newly created data //paramList = new List(); //par1 = new oDynamicParam(); //par1.paramDisplayName = "SurfaceID"; //par1.paramObject = gridSurface.recId; //paramList.Add(par1); //par2 = new oDynamicParam(); //par2.paramDisplayName = "ParentSurfaceItemId"; //par2.paramObject = base.ParentSurfaceItemId; //paramList.Add(par2); //childData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); } } 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, gridSurface.recId); repeater.DataSource = childData; repeater.DataBind(); } } //CVH 2017-02-23 Need to put grids in edit mode, need this here for child grids to stay in edit mode in wizard //CVH 2017-02-23 Only put in edit mode if field is not set Read Only if (gridField.isComparable && panelCompareHolder != null) { BindCompareDropdowns(childSurface, gridField.surfaceFieldName); panelCompareHolder.Visible = true; panelGridHolder.Visible = false; } else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !gridField.isReadOnly && !gridField.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 (gridField.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", gridSurface.recId.ToString() + "," + (int)pNums.FieldType.Group)) { if (pnlSurfaceForm.FindControl("upv" + surfaceId.ToString() + childFields.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceForm.FindControl("upv" + surfaceId.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); } } private string BuildSurfaceGridFilter() { string filter = ""; try { if (!divFilterColumns.Visible) return filter; StringBuilder filterBuilder = new StringBuilder(); foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isFilter", base.SurfaceApp.recId + ",1", "sequence")) { ListBox colFilter = (ListBox)divFilterColumns.FindControl("colFilter_" + field.surfaceFieldName); if (colFilter == null) continue; bool numeric = false; if (field.surfaceFieldTypeId == (int)pNums.FieldType.Number || field.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) numeric = true; int[] indices = colFilter.GetSelectedIndices(); string filterValues = ""; for (int i = 0; i < indices.Count(); i++) { string val = colFilter.Items[indices[i]].Value; if (val == "(blank)") val = ""; if (val != "" && field.surfaceFieldTypeId == (int)pNums.FieldType.Date && field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) val = val + "/01/01"; if (filterValues == String.Empty) filterValues = (numeric ? "" : "'") + val + (numeric ? "" : "'"); else filterValues += ", " + (numeric ? "" : "'") + val + (numeric ? "" : "'"); } if (filterValues != String.Empty) { //the first AND/WHERE is built on stored proc side if (filterBuilder.ToString() == String.Empty) filterBuilder.AppendLine(field.surfaceFieldName + " IN (" + filterValues + ") "); else filterBuilder.AppendLine(" AND " + field.surfaceFieldName + " IN (" + filterValues + ") "); } } filter = filterBuilder.ToString(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } return filter; } private void BindSurfaceGridColumnFilters(bool retainSelections) { bool showFilterGroup = false; try { if (base.SurfaceApp == null) return; //foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) //{ if (!MainGridOptions.allowFilter) return; //} //build filter string filter = ""; if (retainSelections) { filter = BuildSurfaceGridFilter(); } //userLink specifics int userLink = 0; oUser user = new oUser(); if (utils.verifySession("user")) user = (oUser)Session["user"]; if (base.SurfaceApp.linkUser && user.userType == (int)pNums.UserType.WebsiteUser) userLink = user.recId; //get total rows int TotalRows = xData.GetSurfaceDataCount(base.SurfaceApp.recId, userLink, filter); //get search value string searchVal = txbSearchSurface.Value; //get surface data DataTable dtSurfaceData = xData.GetSurfaceDataPaged(base.SurfaceApp.recId, 0, TotalRows, "", searchVal, User.recId, userLink, filter); //get Toggle View Visible action Id int visibleActionId = 0; foreach (oSurfaceAction act in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "actionType,action", (int)pNums.ActionType.ToggleView + ",Visible")) { visibleActionId = act.recId; } bool showColFilter = true; //get all filter fields ArrayList fields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isFilter", base.SurfaceApp.recId + ",1", "sequence"); foreach (oSurfaceField field in fields) { HtmlGenericControl divColFilter = (HtmlGenericControl)divFilterColumns.FindControl("divFilter_" + field.surfaceFieldName); ListBox colFilter = (ListBox)divFilterColumns.FindControl("colFilter_" + field.surfaceFieldName); if (colFilter == null || divColFilter == null) continue; //if field is toggle view, determine if the source field is a filter field if (field.actionType == (int)pNums.ActionType.ToggleView && field.action == visibleActionId) { showColFilter = false; //build value to match string valueToMatch = ""; foreach (var val in field.actionValue.Split(';')) { valueToMatch += "|" + val + "|"; } foreach (oSurfaceField toggleSource in fields) { if (toggleSource.recId == field.actionSource) { //get toggle source listbox, and determine if toggle value has been selected ListBox colSource = (ListBox)divFilterColumns.FindControl("colFilter_" + toggleSource.surfaceFieldName); if (colSource != null) { foreach (ListItem sourceItem in colSource.Items) { if (sourceItem.Selected && valueToMatch.Contains("|" + sourceItem.Value + "|")) { showColFilter = true; break; } } } break; } } } if (showColFilter) { divColFilter.Visible = true; divColFilter.Attributes.Remove("style"); } else { //clear filter and don't show colFilter.ClearSelection(); colFilter.Items.Clear(); divColFilter.Attributes.Add("style", "display: none"); continue; } //get list of selected items to reapply if selections need to be retained int[] indices = colFilter.GetSelectedIndices(); string[] selections = new string[indices.Count()]; //replace index with value, rebinding list so indices might change for (int i = 0; i < indices.Count(); i++) { selections[i] = colFilter.Items[indices[i]].Value; } DataTable dtFilter = dtSurfaceData.DefaultView.ToTable(true, field.surfaceFieldName); //replace spaces with   foreach (DataRow row in dtFilter.Rows) { if (row[0].ToString().Trim() == String.Empty) row[0] = "(blank)"; if (field.surfaceFieldTypeId == (int)pNums.FieldType.Date) { if (field.surfaceDateTypeId == (int)pNums.SurfaceDateType.Year) { DateTime dtYear = new DateTime(); if (DateTime.TryParse(row[0].ToString(), out dtYear)) row[0] = dtYear.Year.ToString(); } } } colFilter.DataSource = dtFilter; colFilter.DataTextField = field.surfaceFieldName; colFilter.DataValueField = field.surfaceFieldName; colFilter.DataBind(); showFilterGroup = true; if (retainSelections) { foreach (string selected in selections) { foreach (ListItem item in colFilter.Items) { if (item.Value == selected) item.Selected = true; } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } finally { if (showFilterGroup) divFilterColumns.Visible = true; else divFilterColumns.Visible = 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); } } /// /// Populate the surface form /// /// /// REVISION 001: Add functionality for field type Grid /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 14 December 2015 /// private void PopulateSurfaceView(oSurfaceItem _surfaceItem, bool isChild = false) { try { string prefix = ""; if (isChild) prefix = _surfaceItem.surfaceId.ToString(); //first fetch the field and data records DataTable surfaceFieldsTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", _surfaceItem.surfaceId + ",1", "sequence"); ArrayList surfaceFieldData = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId", _surfaceItem.surfaceId + "," + _surfaceItem.recId, "recId"); ArrayList surfaceFields = utils.ConvertDataTableToListParallel(surfaceFieldsTable, typeof(oSurfaceField)); /* CVH 2016-09-01 Set command argument for view edit button */ btnEdit.CommandArgument = _surfaceItem.recId.ToString(); oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; //foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) //{ btnEdit.Visible = usr.userType >= MainGridOptions.editAccessType; //} //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; } } //Parallel.ForEach(surfaceFields.Cast(), field => //{ foreach (oSurfaceField field in surfaceFields) { if (field.surfaceFieldTypeId == (int)pNums.FieldType.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) { Control groupControl = (Control)pnlSurfaceForm.FindControl("divv" + prefix + field.surfaceFieldName); if (groupControl != null) groupControl.Visible = usr.userType >= field.accessLevel; } 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: string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; bool isImage = false; 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") { sourceFieldLabel = field.surfaceFieldDisplay; sourceFieldValue = $"{(_surfaceItem.dateUpdated > new DateTime(1900, 1, 1) ? _surfaceItem.dateUpdated : _surfaceItem.dateCreated):g}"; } else { 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() + "," + _surfaceItem.recId.ToString())) { 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: 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: sourceFieldValue = sourceData.surfaceFieldValueDate.ToShortDateString(); break; case pNums.FieldType.Image: HtmlGenericControl imageLabelDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl("v" + prefix + field.surfaceFieldName + "Div"); if (imageLabelDiv != null) { string imageUrl = "/images/placeholder.png"; imageUrl = "/upload/surface/" + sourceData.surfaceFieldValueChar; imageLabelDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } isImage = true; break; case pNums.FieldType.Picklist: sourceFieldValue = ""; foreach (oSurfaceLookup look in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", sourceData.surfaceFieldLookupID.ToString())) { sourceFieldValue = look.display; break; } break; } } } } Label lblLabel = (Label)pnlSurfaceView.FindControl("lblv" + prefix + field.surfaceFieldName + "Label"); if (lblLabel != null) { lblLabel.Text = sourceFieldLabel; } if (!isImage) { Label lblValue = (Label)pnlSurfaceView.FindControl("lblv" + prefix + field.surfaceFieldName + "Value"); if (lblValue != null) { lblValue.Text = sourceFieldValue; } } break; #endregion #region Text case pNums.FieldType.Text://Textbox Label lbl = (Label)pnlSurfaceView.FindControl("lblv" + prefix + field.surfaceFieldName); if (lbl != null) { lbl.Text = ""; 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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(decFormula.ToString()); } } 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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())) { lblPicklist.Text = look.display; break; } break; } } } break; #endregion #region MultiPicklist case pNums.FieldType.MultiPicklist: //MultiPicklist Label lblMultiPicklist = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 Grid case pNums.FieldType.Grid: //grid //find the div and bind all repeaters inside it HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceView.FindControl("divv" + prefix + field.surfaceFieldName); HtmlGenericControl panelGridHolder = (HtmlGenericControl)pnlSurfaceView.FindControl("pnlSurfaceGrid_v" + prefix + field.surfaceId.ToString() + "_" + field.surfaceFieldName); if (divGridHolder != null && panelGridHolder != null) { DataTable childData = new DataTable(); int surfaceId = 0; foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) { surfaceId = surf.recId; break; } if (surfaceId > 0 && _surfaceItem.recId > 0) { int rowLimit = 0; int.TryParse(field.relationalValues, out rowLimit); 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 = _surfaceItem.recId; 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 = _surfaceItem.recId; 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); } //foreach (Control rpt in divGridHolder.Controls) foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { Repeater repeater = (Repeater)rpt; SetAggregates(childData, surfaceId); repeater.DataSource = childData; repeater.DataBind(); } } } } break; #endregion #region RadioButtonList case pNums.FieldType.RadioButtonList: //radiobuttonlist Label lblRadioButtonList = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 Placeholder case pNums.FieldType.Placeholder: //no action break; #endregion #region Caption case pNums.FieldType.Caption: HtmlTextArea lblCaption = (HtmlTextArea)pnlSurfaceView.FindControl("lblv" + prefix + field.surfaceFieldName); if (lblCaption != null) { lblCaption.Value = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { lblCaption.Value = data.surfaceFieldValueChar; break; } } } break; #endregion #region FormulaField case pNums.FieldType.FormulaField: Label lblFormula = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 = (Label)pnlSurfaceView.FindControl("lblv" + prefix + 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 = (Label)pnlSurfaceView.FindControl("lblv" + 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; // lblImage.Text = ""; // break; // } // } //} HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl("v" + prefix + field.surfaceFieldName + "Div"); if (imageDiv != null) { string imageUrl = "/images/placeholder.png"; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { if (data.surfaceFieldValueChar != "") imageUrl = "/upload/surface/" + data.surfaceFieldValueChar; break; } } imageDiv.Style.Add("background-image", "url(" + imageUrl + ")"); } break; #endregion #region Control case pNums.FieldType.Control: string controlType = string.Empty; string controlPath = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", field.controlledValue)) { controlType = module.module; controlPath = module.control; controlName = module.objectName + field.surfaceFieldName; } oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); if (surfaceFieldData != null && surfaceFieldData.Count > 0) { ArrayList fieldData = new ArrayList(surfaceFieldData.Cast() .Where(d => d.surfaceFieldID == field.recId) .ToList()); foreach (oSurfaceFieldData data in fieldData) { if (field.recId == data.surfaceFieldID) { controlFieldData = data; } } } if (controlFieldData.surfaceFieldID == 0) //set default values if populating blank form { controlFieldData.surfaceFieldID = field.recId; 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','1');", true); break; default: //find Control and call reloadControl() dynamic moduleControl = this.FindControl(controlName + "View"); if (moduleControl != null) { moduleControl.ReloadControl(controlFieldData, field.alternateView, true); } break; } break; #endregion #region Button case pNums.FieldType.Button: Button btn = (Button)pnlSurfaceForm.FindControl("btnv" + prefix + 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; } } } break; #endregion } } } //}); BindSurfaceAttachments(_surfaceItem.recId, true); BindSurfaceNotes(_surfaceItem.recId, true); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs1 = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); MaintainActiveTab(fieldTabs1, true); SetTabsVisible(fieldTabs1, true); } 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 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; } } 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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lbl = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lbl = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName); } if (lbl != null) { lbl.Text = ""; 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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblNum = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblNum = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblDecimal = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblDecimal = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblPicklist = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblPicklist = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblMultiPicklist = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblMultiPicklist = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblDate = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblDate = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCheckbox = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCheckbox = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblRadioButtonList = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblRadioButtonList = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCaption = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCaption = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblFormula = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblFormula = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblCheckboxList = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblCheckboxList = (Label)pnlSurfaceView.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 (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField) != null) lblImage = (Label)pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName + "__" + parentSurfaceField); } else { if (pnlSurfaceView.FindControl("lblC_" + colNum + field.surfaceFieldName) != null) lblImage = (Label)pnlSurfaceView.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; lblImage.Text = "
"; break; } } } break; #endregion } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } ///// ///// Populates the grid surface apps on the surface form during page initialization (otherwise viewstate is lost) ///// ///// //private void PopulateSurfaceFormGridSurfaceApps() //{ // try // { // ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence"); // foreach (oSurfaceField field in surfaceFields) // { // if (field.surfaceFieldTypeId == (int)pNums.FieldType.Grid) // { // PlaceHolder plc = (PlaceHolder)pnlSurfaceForm.FindControl(field.surfaceFieldName); // //form // if (plc != null && plc.ID != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //load the surface app control // plc.Controls.Clear(); // if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".ascx"))) // { BuildControl(gridSurface); } // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + ".ascx"); // uc.ID = gridSurface.name + field.recId; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; //0 if not yet saved // uc.ParentSurfaceId = base.SurfaceApp.recId; // int rowLimit = 0; // Int32.TryParse(field.relationalValues, out rowLimit); // uc.RowLimit = rowLimit; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // plc.Controls.Add(uc); // } // } // //view // PlaceHolder plcv = (PlaceHolder)pnlSurfaceForm.FindControl("plcv" + field.surfaceFieldName); // if (plcv != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //load the surface app control // plcv.Controls.Clear(); // if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".ascx"))) // { BuildControl(gridSurface); } // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + ".ascx"); // uc.ID = "v" + gridSurface.name + field.recId; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; //0 if not yet saved // uc.ParentSurfaceId = base.SurfaceApp.recId; // int rowLimit = 0; // Int32.TryParse(field.relationalValues, out rowLimit); // uc.RowLimit = rowLimit; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // plcv.Controls.Add(uc); // } // } // } // } // } // 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("lblv" + 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); } } 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(); if (gridField.isControlled) { //get newly created data List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = childSurface.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.SurfaceAppItem.recId; 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 { //get newly created data List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = childSurface.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.SurfaceAppItem.recId; 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); } 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(); } } //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); } } //CVH START 20170317 //CVH 2017-03-17 Reverting to pre-2017-03-13 /// /// Populate the surface form /// private void PopulateSurfaceForm(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)); //Parallel.ForEach(surfaceFields.Cast(), field => //{ 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 2017-04-12 Read-only not working */ //bool enabled = !field.isReadOnly && !field.isControlled; bool enabled = true; if (field.isReadOnly) enabled = false; else 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 surfaceFieldData) { 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)pnlSurfaceView.FindControl("lbl" + field.surfaceFieldName + "Label"); if (lblLabel != null) { lblLabel.Text = sourceFieldLabel; } if (!isImage) { Label lblValue = (Label)pnlSurfaceView.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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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: HtmlTextArea textArea = (HtmlTextArea)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (textArea != null) { textArea.Value = ""; foreach (oSurfaceFieldData data in surfaceFieldData) { if (field.recId == data.surfaceFieldID) { textArea.Value = data.surfaceFieldValueChar; break; } } textArea.Disabled = !enabled; //CVH 2016-12-12 Group default collapse if (textArea.Value != "" && !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 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) { 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 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) { txtFormulaBox.Text = data.surfaceFieldValueChar; } 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 surfaceFieldData) { 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 (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.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 surfaceFieldData) { 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 surfaceFieldData) { 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 surfaceFieldData) { 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; bool enabled = true; if (field.isReadOnly) enabled = false; else 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) + ")"; 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(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #region Graham BAK ///// ///// 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); // DataTable myFieldDataTable = surfaceFieldDataTable.Clone(); // //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)); // //Parallel.ForEach(surfaceFields.Cast(), field => // //{ // 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) // { // myFieldDataTable.Clear(); // var v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == field.recId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // //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: // sourceFieldValue = sourceData.surfaceFieldValueDate.ToShortDateString(); // 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) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == lookupSrcField.recId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (lookupSrcField.recId == (int)dataRow["surfaceFieldID"]) // { // //catering for field types char, number, decimal // if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueNum"].ToString(), out lookupSrcValue); // else if (lookupSrcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // lookupSrcValue = (decimal)dataRow["surfaceFieldValueDecimal"]; // } // else // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueChar"].ToString(), 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)pnlSurfaceView.FindControl("lbl" + field.surfaceFieldName + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceView.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 (DataRow dataRow in myFieldDataTable.Rows) // { // txtTextbox.Text = (string)dataRow["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 (DataRow dataRow in myFieldDataTable.Rows) // { // txtNumberBox.Text = dataRow["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 = ""; // //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 (DataRow dataRow in myFieldDataTable.Rows) // { // txtDecimalBox.Text = utils.returnFormattedDecimal(dataRow["surfaceFieldValueDecimal"].ToString()); // 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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (field.relationalObject.Length > 0 && field.relationalObject != "0") // { // if (ddDropdownlist.Items.FindByValue(dataRow["surfaceFieldValueChar"].ToString()) != null) // ddDropdownlist.SelectedValue = dataRow["surfaceFieldValueChar"].ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(dataRow["surfaceFieldLookupID"].ToString()) != null) // ddDropdownlist.SelectedValue = dataRow["surfaceFieldLookupID"].ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = (string)dataRow["surfaceFieldValueChar"]; // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", dataRow["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(); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // string valueIds = dataRow["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 (DataRow dataRow in myFieldDataTable.Rows) // { // txtDate.Text = ((DateTime)dataRow["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) && (DateTime)dataRow["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 ((DateTime)dataRow["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 (DataRow dataRow in myFieldDataTable.Rows) // { // chkBox.Checked = (bool)dataRow["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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == field.recId && enVal.Field("surfaceFieldLookupID") != 0) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (radioButtonList.Items.FindByValue(dataRow["surfaceFieldLookupID"].ToString()) != null) // radioButtonList.SelectedValue = dataRow["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 = dataRow["surfaceFieldValueChar"].ToString(); // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", dataRow["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: // HtmlTextArea textArea = (HtmlTextArea)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (textArea != null) // { // textArea.Value = ""; // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // textArea.Value = dataRow["surfaceFieldValueChar"].ToString(); // break; // } // textArea.Disabled = !enabled; // //CVH 2016-12-12 Group default collapse // if (textArea.Value != "" && !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) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)srcField.recId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //catering for field types char, number, decimal // if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueNum"].ToString(), out sourceValue); // else if (srcField.surfaceFieldTypeId == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // sourceValue = (decimal)dataRow["surfaceFieldValueDecimal"]; // } // else // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueChar"].ToString(), 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 // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == field.recId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //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 = dataRow["surfaceFieldValueChar"].ToString(); // } // else // { // if ((decimal)dataRow["surfaceFieldValueDecimal"] != 0) // txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(dataRow["surfaceFieldValueDecimal"])); // if (dataRow["surfaceFieldValueChar"].ToString() != string.Empty) // txtFormulaBox.Text = dataRow["surfaceFieldValueChar"].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); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // int itemNo = 0; // foreach (string addressLine in dataRow["surfaceFieldValueChar"].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 (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.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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == field.recId && enVal.Field("surfaceFieldValueChar") != "") // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //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 dataRow["surfaceFieldValueChar"].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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == field.recId && enVal.Field("surfaceFieldValueChar") != "") // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // foreach (string temp in dataRow["surfaceFieldValueChar"].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("|" + (int)field.parentId + "|")) // groupIdsWithData += "|" + (int)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, surfaceFieldDataTable, field, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // SetSurfaceControlState(_surfaceItem, surfaceFieldDataTable, 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 (DataRow dataRow in surfaceFieldDataTable.Rows) // { // if (field.recId == (int)dataRow["surfaceFieldID"]) // { // if ((string)dataRow["surfaceFieldValueChar"] != "") // { // imageUrl = "/upload/surface/" + dataRow["surfaceFieldValueChar"].ToString(); // //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) // { // 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) + ")"; // 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(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} #endregion #region Graham latest /// /// Populate the surface form /// //private void PopulateSurfaceForm(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); // DataTable myFieldDataTable = surfaceFieldDataTable.Clone(); // DataTable myFieldTable = surfaceFieldsTable.Clone(); // //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)); // //Parallel.ForEach(surfaceFields.Cast(), field => // //{ // 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 (DataRow fieldRow in surfaceFieldsTable.Rows) // { // myFieldDataTable.Clear(); // //if (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // //{ // var v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"]) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // //} // //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 ((int)fieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Grid) // continue; // if ((int)fieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Group || (int)fieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.HeaderGroup) // { // Control groupControl = (Control)pnlSurfaceForm.FindControl("divf" + fieldRow["surfaceFieldName"].ToString()); // 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") && // (fieldRow["surfaceFieldName"].ToString() == "PatientInformation_EmployerDetailsInjuryonDuty" || fieldRow["surfaceFieldName"].ToString() == "PatientInformation_MedicalAidIfapplicable")) // { // //do nothing // } // else if (setup.code == "GLOB-1" && // (int)fieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.HeaderGroup && // !_surfaceItem.isWizardCompleted) // { // groupControl.Visible = false; // } // else // { // if (fieldRow["accessLevel"] != DBNull.Value) // groupControl.Visible = usr.userType >= (int)fieldRow["accessLevel"]; // } // } // } // /* CVH 2016-01-20 */ // bool enabled = !(bool)fieldRow["isReadOnly"] && !(bool)fieldRow["isControlled"]; // if ((isNew || base.IsClone || !_surfaceItem.isWizardCompleted) && !(bool)fieldRow["isControlled"])//if controlled value, should always be readonly // enabled = true; // if ((int)fieldRow["surfaceFieldTypeId"] != (int)pNums.FieldType.Tab || (int)fieldRow["surfaceFieldTypeId"] != (int)pNums.FieldType.Group) // { // pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), (int)fieldRow["surfaceFieldTypeId"]); // switch (typ) // { // #region Label // case pNums.FieldType.Label: // if ((bool)fieldRow["isReadOnly"])//hide labels on new // { // Control divControl; // divControl = FindControl("srt" + fieldRow["surfaceFieldName"].ToString()); // if (divControl != null) // divControl.Visible = false; // } // else // { // bool isImage = false; // string sourceFieldLabel = string.Empty, sourceFieldValue = string.Empty; // if (fieldRow["relationalSurface"].ToString() == "user") // { // foreach (ovUserShared user in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", (_surfaceItem.updatedBy > 0 ? _surfaceItem.updatedBy : _surfaceItem.createdBy).ToString())) // { // sourceFieldLabel = fieldRow["surfaceFieldDisplay"].ToString(); // sourceFieldValue = user.userDisplay; // } // } // else if (fieldRow["relationalSurface"].ToString() == "date") // { // if (_surfaceItem.dateCreated > new DateTime(1901, 1, 1) || _surfaceItem.dateUpdated > new DateTime(1901, 1, 1)) // { // sourceFieldLabel = fieldRow["surfaceFieldDisplay"].ToString(); // 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 (fieldRow["relationalSurface"].ToString() != _surfaceItem.surfaceId.ToString() && base.ParentSurfaceItemId > 0) // itemId = base.ParentSurfaceItemId.ToString(); // foreach (oSurfaceField sourceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,recId", fieldRow["relationalSurface"].ToString() + "," + fieldRow["relationalFields"].ToString())) // { // sourceFieldLabel = sourceField.surfaceFieldDisplay; // foreach (oSurfaceFieldData sourceData in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID,surfaceItemId", fieldRow["relationalSurface"].ToString() + "," + fieldRow["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: // sourceFieldValue = sourceData.surfaceFieldValueDate.ToShortDateString(); // 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; // myFieldTable.Clear(); // v = from enVal in surfaceFieldsTable.AsEnumerable() // where (enVal.Field("recId") == sourceField.actionSource) // select enVal; // v.CopyToDataTable(myFieldTable, LoadOption.OverwriteChanges); // foreach (DataRow lookupSrcFieldRow in myFieldTable.Rows) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)lookupSrcFieldRow["recId"]) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //catering for field types char, number, decimal // if ((int)lookupSrcFieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueNum"].ToString(), out lookupSrcValue); // else if ((int)lookupSrcFieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // lookupSrcValue = (decimal)dataRow["surfaceFieldValueDecimal"]; // } // else // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueChar"].ToString(), out lookupSrcValue); // break; // } // } // if (conversionSuccess) // { // sourceFieldValue = CalculateLookup(fieldRow, 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 (sourceField.actionType == (int)pNums.ActionType.Aggregation && sourceField.action == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(sourceField.actionValue, out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, sourceField.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(fieldRow["surfaceFieldName"].ToString() + "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(fieldRow["surfaceFieldName"].ToString() + "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(fieldRow["surfaceFieldName"].ToString() + "LabelfNotes"); // int intItemIdN = 0; // int.TryParse(itemId, out intItemIdN); // if (notesDiv != null && intItemIdN > 0) // BindNotes(intItemIdN, notesDiv); // break; // } // } // } // } // Label lblLabel = (Label)pnlSurfaceView.FindControl("lbl" + fieldRow["surfaceFieldName"].ToString() + "Label"); // if (lblLabel != null) // { // lblLabel.Text = sourceFieldLabel; // } // if (!isImage) // { // Label lblValue = (Label)pnlSurfaceView.FindControl("lbl" + fieldRow["surfaceFieldName"].ToString() + "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(fieldRow["surfaceFieldName"].ToString()); // if (txtTextbox != null) // { // txtTextbox.Text = ""; // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // txtTextbox.Text = dataRow["surfaceFieldValueChar"].ToString(); // break; // } // /* CVH 2016-01-20 */ // txtTextbox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtTextbox.Text != "" && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // break; // #endregion // #region Number // case pNums.FieldType.Number: //number // TextBox txtNumberBox = (TextBox)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (txtNumberBox != null) // { // if ((bool)fieldRow["isControlled"]) // { // int nextNumber = 0; // int.TryParse(fieldRow["controlledValue"].ToString(), out nextNumber); // nextNumber++; // txtNumberBox.Enabled = false; // txtNumberBox.Text = nextNumber.ToString(); // } // else // txtNumberBox.Text = ""; // if (!base.IsClone || (base.IsClone && !(bool)fieldRow["isControlled"])) // { // //CVH 2017-02-28 New action type Aggregation Sum // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(fieldRow["actionValue"].ToString(), out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, (int)fieldRow["actionSource"], _surfaceItem.recId); // txtNumberBox.Text = Math.Floor(decFormula).ToString(); // } // } // else // { // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // txtNumberBox.Text = dataRow["surfaceFieldValueNum"].ToString(); // break; // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId) // txtNumberBox.Enabled = false; // else // txtNumberBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtNumberBox.Text != "" && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // break; // #endregion // #region Decimal // case pNums.FieldType.Decimal: //decimal // TextBox txtDecimalBox = (TextBox)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (txtDecimalBox != null) // { // txtDecimalBox.Text = "";//(string)fieldRow["surfaceFieldName"] // //if (setup.code == "STUD-1" && field.surfaceFieldDisplay.StartsWith("Portion of Total Monthly Income")) // if (setup.code == "STUD-1" && fieldRow["surfaceFieldDisplay"].ToString().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()); // } // else // { // //CVH 2017-02-28 New action type Aggregation Sum // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(fieldRow["actionValue"].ToString(), out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, (int)fieldRow["actionSource"], _surfaceItem.recId); // txtDecimalBox.Text = utils.returnFormattedDecimal(Convert.ToString(decFormula)); // } // } // else // { // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // txtDecimalBox.Text = utils.returnFormattedDecimal(dataRow["surfaceFieldValueNum"].ToString()); // break; // } // } // } // //CVH 2017-02-28 If Aggregation Sum action, always disable // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId) // txtDecimalBox.Enabled = false; // else // txtDecimalBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtDecimalBox.Text != "" && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + " | "; // } // break; // #endregion // #region Picklist // case pNums.FieldType.Picklist: //picklist // DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // TextBox txtPicklistReason = (TextBox)pnlSurfaceForm.FindControl("reason" + fieldRow["surfaceFieldName"].ToString()); // RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + fieldRow["surfaceFieldName"].ToString()); // //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 (fieldRow["relationalObject"].ToString().Length > 0 && fieldRow["relationalObject"].ToString() != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(fieldRow["relationalObject"].ToString()); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", fieldRow["relationalObject"].ToString()); // 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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (fieldRow["relationalObject"].ToString().Length > 0 && fieldRow["relationalObject"].ToString() != "0") // { // if (ddDropdownlist.Items.FindByValue(dataRow["surfaceFieldValueChar"].ToString()) != null) // ddDropdownlist.SelectedValue = dataRow["surfaceFieldValueChar"].ToString(); // } // else // { // if (ddDropdownlist.Items.FindByValue(dataRow["surfaceFieldLookupID"].ToString()) != null) // ddDropdownlist.SelectedValue = dataRow["surfaceFieldLookupID"].ToString(); // if (txtPicklistReason != null) // { // txtPicklistReason.Text = dataRow["surfaceFieldValueChar"].ToString(); // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", dataRow["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", fieldRow["lookupCategory"].ToString() + ",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 (fieldRow["surfaceFieldName"].ToString() == "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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["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(fieldRow["surfaceFieldName"].ToString()); // if (listBox != null) // { // if (fieldRow["relationalObject"].ToString().Length > 0 && fieldRow["relationalObject"].ToString() != "0") // { // Assembly asm = typeof(oModule).Assembly; // Type type = asm.GetType(fieldRow["relationalObject"].ToString()); // DataTable dtModule = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "objectName", fieldRow["relationalObject"].ToString()); // 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(); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // string valueIds = dataRow["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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // break; // #endregion // #region Date // case pNums.FieldType.Date: //date // TextBox txtDate = (TextBox)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (txtDate != null) // { // string format = "dd/MM/yyyy"; // if ((int)fieldRow["surfaceDateTypeId"] == (int)pNums.SurfaceDateType.MonthYear) // format = "MMMM yyyy"; // else if ((int)fieldRow["surfaceDateTypeId"] == (int)pNums.SurfaceDateType.Year) // format = "yyyy"; // if (fieldRow["defaultToCurrent"] != DBNull.Value && (bool)fieldRow["defaultToCurrent"]) // txtDate.Text = DateTime.Now.ToString(format); // else if (fieldRow["defaultValue"] != DBNull.Value && fieldRow["defaultValue"].ToString() != "") // txtDate.Text = fieldRow["defaultValue"].ToString(); // else // txtDate.Text = ""; // if (fieldRow["defaultToCurrent"] != DBNull.Value && !base.IsClone || (base.IsClone && !(bool)fieldRow["defaultToCurrent"])) // { // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // txtDate.Text = ((DateTime)dataRow["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) && (DateTime)dataRow["surfaceFieldValueDate"] != DateTime.Parse("1900/01/01") && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // //CVH 2016-12-21 Show empty textbox if date is min date // if ((DateTime)dataRow["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(fieldRow["surfaceFieldName"].ToString()); // if (chkBox != null) // { // chkBox.Checked = false; // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // chkBox.Checked = (bool)dataRow["surfaceFieldValueBool"]; // break; // } // /* CVH 2016-01-20 */ // chkBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (chkBox.Checked && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["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(fieldRow["surfaceFieldName"].ToString()); // TextBox txtReason = (TextBox)pnlSurfaceForm.FindControl("reason" + fieldRow["surfaceFieldName"].ToString()); // RequiredFieldValidator rfvRadioButtonListReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + fieldRow["surfaceFieldName"].ToString()); // 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", (int)fieldRow["lookupCategory"] + ",1"); // if (catWantsReason != null && catWantsReason.Count > 0) // txtReason.Visible = true; // else // txtReason.Visible = false; // } // if (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"] && enVal.Field("surfaceFieldLookupID") != 0) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (radioButtonList.Items.FindByValue(dataRow["surfaceFieldLookupID"].ToString()) != null) // radioButtonList.SelectedValue = dataRow["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 = dataRow["surfaceFieldValueChar"].ToString(); // foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", dataRow["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 ((bool)fieldRow["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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // break; // #endregion // #region Placeholder // case pNums.FieldType.Placeholder: // //no action // break; // #endregion // #region Caption // case pNums.FieldType.Caption: // HtmlTextArea textArea = (HtmlTextArea)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (textArea != null) // { // textArea.Value = ""; // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // textArea.Value = dataRow["surfaceFieldValueChar"].ToString(); // break; // } // textArea.Disabled = !enabled; // //CVH 2016-12-12 Group default collapse // if (textArea.Value != "" && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // break; // #endregion // #region FormulaField // case pNums.FieldType.FormulaField: //decimal // TextBox txtFormulaBox = (TextBox)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (txtFormulaBox != null) // { // txtFormulaBox.Text = ""; // //CVH 2017-02-13 Lookup Calculation Formula - redo calculation on populate // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Calculation && (int)fieldRow["action"] == lookupAction.recId) // { // decimal sourceValue = 0m; // bool conversionSuccess = false; // myFieldTable.Clear(); // v = from enVal in surfaceFieldsTable.AsEnumerable() // where (enVal.Field("recId") == (int)fieldRow["actionSource"]) // select enVal; // v.CopyToDataTable(myFieldTable, LoadOption.OverwriteChanges); // //get source field // foreach (DataRow srcFieldRow in myFieldTable.Rows) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)srcFieldRow["recId"]) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //catering for field types char, number, decimal // if ((int)srcFieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Number) // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueNum"].ToString(), out sourceValue); // else if ((int)srcFieldRow["surfaceFieldTypeId"] == (int)pNums.FieldType.Decimal) // { // conversionSuccess = true; // sourceValue = (decimal)dataRow["surfaceFieldValueDecimal"]; // } // else // conversionSuccess = decimal.TryParse(dataRow["surfaceFieldValueChar"].ToString(), out sourceValue); // break; // } // break; // } // if (conversionSuccess) // { // txtFormulaBox.Text = CalculateLookup(fieldRow, sourceValue); // } // } // //CVH 2017-02-24 New action type Aggregation Sum // else if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId) // { // int actionSurfaceId = 0; // if (int.TryParse(fieldRow["actionValue"].ToString(), out actionSurfaceId)) // { // decimal decFormula = xData.GetSurfaceAggregationSum(actionSurfaceId, (int)fieldRow["actionSource"], _surfaceItem.recId); // txtFormulaBox.Text = utils.returnFormattedDecimal(decFormula.ToString()); // } // } // else // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"]) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //CVH 2017-02-07 Divide Calculation Formula is saved in Char column // if ((int)fieldRow["actionType"] == (int)pNums.ActionType.Calculation && (int)fieldRow["action"] == divideAction.recId) // { // txtFormulaBox.Text = dataRow["surfaceFieldValueChar"].ToString(); // } // else // { // if ((decimal)dataRow["surfaceFieldValueDecimal"] != 0) // txtFormulaBox.Text = utils.returnFormattedDecimal(Convert.ToString(dataRow["surfaceFieldValueDecimal"])); // if (dataRow["surfaceFieldValueChar"].ToString() != string.Empty) // txtFormulaBox.Text = dataRow["surfaceFieldValueChar"].ToString(); // } // break; // } // } // if ((int)fieldRow["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 (((int)fieldRow["actionType"] == (int)pNums.ActionType.Calculation && ((int)fieldRow["action"] == divideAction.recId || (int)fieldRow["action"] == lookupAction.recId)) || // ((int)fieldRow["actionType"] == (int)pNums.ActionType.Aggregation && (int)fieldRow["action"] == aggrSumAction.recId)) // txtFormulaBox.Enabled = false; // else // txtFormulaBox.Enabled = enabled; // //CVH 2016-12-12 Group default collapse // if (txtFormulaBox.Text != "" && !groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["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(fieldRow["surfaceFieldName"].ToString() + 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(fieldRow["surfaceFieldName"].ToString() + 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 (DataRow dataRow in myFieldDataTable.Rows) // { // int itemNo = 0; // foreach (string addressLine in dataRow["surfaceFieldValueChar"].ToString().Split(new string[] { "~|~" }, StringSplitOptions.None)) // { // itemNo++; // if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") // { // DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString() + 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 (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) // ddSuburb.SelectedValue = addressLine.Substring(3); // } // } // else // { // TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString() + itemNo); // if (txtAddress != null && 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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // } // } // } // break; // #endregion // #region CheckboxList // case pNums.FieldType.CheckboxList: //checkboxlist // /* CVH 2016-09-27 Cater for Wants Reason. alternateView does not use wantsReason */ // if ((bool)fieldRow["alternateView"]) // { // CheckBoxList checkboxList = (CheckBoxList)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // if (checkboxList != null) // { // checkboxList.SelectedIndex = -1; // if (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"] && enVal.Field("surfaceFieldValueChar") != "") // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // //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 dataRow["surfaceFieldValueChar"].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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["parentId"] + "|"; // } // } // else // { // Panel checkboxPanel = (Panel)pnlSurfaceForm.FindControl(fieldRow["surfaceFieldName"].ToString()); // 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 (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"] && enVal.Field("surfaceFieldValueChar") != "") // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // foreach (string temp in dataRow["surfaceFieldValueChar"].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(fieldRow["surfaceFieldName"].ToString() + "_" + 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("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["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", fieldRow["relationalFields"].ToString())) // { // if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) // { // SetSurfaceControlState(_surfaceItem, surfaceFieldDataTable, fieldRow, relatedField); // } // } // break; // #endregion // #region Control // case pNums.FieldType.Control: // SetSurfaceControlState(_surfaceItem, surfaceFieldDataTable, fieldRow); // //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(fieldRow["surfaceFieldName"].ToString()); // if (btn != null) // { // if (fieldRow["surfaceFieldName"].ToString() == "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(fieldRow["surfaceFieldName"].ToString() + "Div"); // if (imageDiv != null) // { // string imageUrl = "/images/placeholder.png"; // myFieldDataTable.Clear(); // v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == (int)fieldRow["recId"]) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // if (dataRow["surfaceFieldValueChar"].ToString() != "") // { // imageUrl = "/upload/surface/" + dataRow["surfaceFieldValueChar"].ToString(); // //CVH 2016-12-12 Group default collapse // if (!groupIdsWithData.Contains("|" + (int)fieldRow["parentId"] + "|")) // groupIdsWithData += "|" + (int)fieldRow["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) // { // 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) + ")"; // 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(); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} #endregion #region Graham latest //private void SetSurfaceControlStateBAC(oSurfaceItem _surfaceItem, DataTable surfaceFieldDataTable, oSurfaceField field, oSurfaceField relatedField = null) //{ // string fieldName = field.surfaceFieldName; // string controlledValue = field.controlledValue; // bool altView = field.alternateView; // int fieldRecId = field.recId; // DataTable myFieldDataTable = surfaceFieldDataTable.Clone(); // 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; // } // DataRow controlFieldDataRow = myFieldDataTable.NewRow(); // if (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // var v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == fieldRecId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // controlFieldDataRow = dataRow; // } // } // if (controlFieldDataRow["surfaceFieldID"] != DBNull.Value && (int)controlFieldDataRow["surfaceFieldID"] == 0 || base.IsClone) //set default values if populating blank form // { // controlFieldDataRow["surfaceFieldID"] = fieldRecId; // controlFieldDataRow["surfaceItemId"] = _surfaceItem.recId; // controlFieldDataRow["surfaceId"] = _surfaceItem.surfaceId; // } // switch (controlType) // { // case "BodyMap": // string bodyPartList = controlFieldDataRow["surfaceFieldValueChar"].ToString(); // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); // break; // default: // //find Control and call reloadControl() // dynamic moduleControl = this.FindControl(controlName); // if (moduleControl != null) // { // myFieldDataTable.Clear(); // myFieldDataTable.Rows.Add(controlFieldDataRow); // moduleControl.ReloadControl(((oSurfaceFieldData)utils.ConvertDataTableToList(myFieldDataTable, typeof(oSurfaceFieldData))[0]), altView); // } // break; // } //} //private void SetSurfaceControlStateBAC(oSurfaceItem _surfaceItem, DataTable surfaceFieldDataTable, DataRow fieldRow, oSurfaceField relatedField = null) //{ // string fieldName = fieldRow["surfaceFieldName"].ToString(); // string controlledValue = fieldRow["controlledValue"].ToString(); // bool altView = (bool)fieldRow["alternateView"]; // int fieldRecId = (int)fieldRow["recId"]; // DataTable myFieldDataTable = surfaceFieldDataTable.Clone(); // 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; // } // DataRow controlFieldDataRow = myFieldDataTable.NewRow(); // if (surfaceFieldDataTable != null && surfaceFieldDataTable.Rows.Count > 0) // { // myFieldDataTable.Clear(); // var v = from enVal in surfaceFieldDataTable.AsEnumerable() // where (enVal.Field("surfaceFieldID") == fieldRecId) // select enVal; // v.CopyToDataTable(myFieldDataTable, LoadOption.OverwriteChanges); // foreach (DataRow dataRow in myFieldDataTable.Rows) // { // controlFieldDataRow = dataRow; // } // } // if (controlFieldDataRow["surfaceFieldID"] != DBNull.Value && (int)controlFieldDataRow["surfaceFieldID"] == 0 || base.IsClone) //set default values if populating blank form // { // controlFieldDataRow["surfaceFieldID"] = fieldRecId; // controlFieldDataRow["surfaceItemId"] = _surfaceItem.recId; // controlFieldDataRow["surfaceId"] = _surfaceItem.surfaceId; // } // switch (controlType) // { // case "BodyMap": // string bodyPartList = controlFieldDataRow["surfaceFieldValueChar"].ToString(); // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); // break; // default: // //find Control and call reloadControl() // dynamic moduleControl = this.FindControl(controlName); // if (moduleControl != null) // { // myFieldDataTable.Clear(); // myFieldDataTable.Rows.Add(controlFieldDataRow); // moduleControl.ReloadControl(((oSurfaceFieldData)utils.ConvertDataTableToList(myFieldDataTable, typeof(oSurfaceFieldData))[0]), altView); // } // break; // } //} #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; 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; default: //find Control and call reloadControl() dynamic moduleControl = this.FindControl(controlName); if (moduleControl != null) { moduleControl.ReloadControl(controlFieldData, altView); } break; } } //CVH END 20170317 /// /// 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); /* CVH 2016-07-22 Refresh child surfaces */ //foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence")) //{ // PlaceHolder plc = (PlaceHolder)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (plc != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //load the surface app control // ISurfaceBase uc = (ISurfaceBase)plc.FindControl(gridSurface.name + field.recId); // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.IsChildSurface = true; // int rowLimit = 0; // Int32.TryParse(field.relationalValues, out rowLimit); // uc.RowLimit = rowLimit; // uc.ReloadControl(); // } // } //} switch (editType) { case pNums.SurfaceGridEditType.Form: Session["surfaceAppItem"] = base.SurfaceAppItem; 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: 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.SurfaceAppItem = item; //base.SurfaceAppItemId = item.recId; //base.ActiveTabPanel = String.Empty; base.IsClone = true; pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), base.SurfaceAppGridEditTypeId); 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); } } /// /// Save Surface form /// private bool SaveSurfaceForm(ref oSurfaceItem _surfaceItem, ref ArrayList surfaceData, ref bool createParentSurfaceItem) { try { 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 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; } } //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.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) { //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; #endregion #region Picklist case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { //CVH 2016-10-21 Also check !="0", relationalObject saves as "0" if (field.relationalObject.Length > 0 && field.relationalObject != "0")//module picklist { 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; #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); 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: HtmlTextArea textArea = (HtmlTextArea)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (textArea != null) { fieldData.surfaceFieldValueChar = textArea.Value; } 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(); } 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); } } //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 && !mailSent) { 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 { 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: HtmlTextArea textArea = (HtmlTextArea)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (textArea != null) { fieldData.surfaceFieldValueChar = textArea.Value; } 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 "pnlSurfaceGrid": ToggleHeadingButtonVisibility(true, btnNew); ToggleHeadingButtonVisibility(true, btnBulkUpdate); ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceGrid.Visible = true; pnlSurfaceForm.Visible = false; pnlSurfaceView.Visible = false; pnlSurfaceCompare.Visible = false; lnkRefresh.Visible = false; lnkSave.Visible = false; lnkBack.Visible = false; break; case "pnlSurfaceForm": ToggleHeadingButtonVisibility(false, btnNew); ToggleHeadingButtonVisibility(false, btnBulkUpdate); ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceGrid.Visible = true; pnlSurfaceGrid.Visible = this.SurfaceApp.isModal ? true : false; pnlSurfaceForm.Visible = true; pnlSurfaceView.Visible = false; pnlSurfaceCompare.Visible = false; break; case "pnlSurfaceView": ToggleHeadingButtonVisibility(false, btnNew); ToggleHeadingButtonVisibility(false, btnBulkUpdate); if (base.SurfaceAppGridEditTypeId == (int)pNums.SurfaceGridEditType.Form && !base.SurfaceApp.isModal) ToggleHeadingButtonVisibility(true, btnEdit); else ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceView.Visible = true; pnlSurfaceGrid.Visible = this.SurfaceApp.isModal ? true : false; pnlSurfaceForm.Visible = false; pnlSurfaceCompare.Visible = false; break; case "pnlSurfaceCompare": ToggleHeadingButtonVisibility(true, btnNew); ToggleHeadingButtonVisibility(true, btnBulkUpdate); ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceView.Visible = false; pnlSurfaceGrid.Visible = false; pnlSurfaceForm.Visible = false; pnlSurfaceCompare.Visible = true; lnkRefresh.Visible = false; lnkSave.Visible = false; lnkBack.Visible = false; 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"); 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 DropDownList ddDropdownlist = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { if (editMode) { ddDropdownlist.SelectedItem.Text = lbl.Text; ddDropdownlist.RemoveCssClass("noShow"); } else { ddDropdownlist.AddCssClass("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: HtmlTextArea textArea = (HtmlTextArea)repeaterItem.FindControl(field.surfaceFieldName); if (textArea != null) { if (editMode) { textArea.Attributes["class"].Replace("noShow", ""); } else { textArea.Attributes.Add("class", "noShow"); } } break; case pNums.FieldType.RelationalField: if (lbl != null) lbl.RemoveCssClass("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"); 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"); } 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"); } /* 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) { case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtTextbox != null) { //txtTextbox.Visible = editMode; if (editMode) { txtTextbox.RemoveCssClass("noShow"); string value = string.Empty; if (myDataTable.Rows.Count > 0) value = myDataTable.Rows[0]["surfaceFieldValueChar"].ToString(); txtTextbox.Text = value; lbl.Text = value; lblToSort.Text = value; } else { txtTextbox.AddCssClass("noShow"); fieldData.surfaceFieldValueChar = txtTextbox.Text; lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } } break; 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; int.TryParse(txtNumberBox.Text, out valueNum); fieldData.surfaceFieldValueNum = valueNum; lbl.Text = fieldData.surfaceFieldValueNum.ToString(); lblToSort.Text = fieldData.surfaceFieldValueNum.ToString(); } } break; case pNums.FieldType.Decimal: //decimal TextBox txtDecimalBox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtDecimalBox != null) { //txtDecimalBox.Visible = editMode; 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; case pNums.FieldType.Picklist: //picklist DropDownList ddDropdownlist = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { //ddDropdownlist.Visible = editMode; if (editMode) { ddDropdownlist.RemoveCssClass("noShow"); string lookvalue = string.Empty; if (myDataTable.Rows.Count > 0) lookvalue = myDataTable.Rows[0]["surfaceFieldLookupID"].ToString(); if (ddDropdownlist.Items.FindByValue(lookvalue) != null) ddDropdownlist.SelectedValue = lookvalue; lbl.Text = ddDropdownlist.SelectedItem.Text; lblToSort.Text = ddDropdownlist.SelectedItem.Text; } else { ddDropdownlist.AddCssClass("noShow"); int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); fieldData.surfaceFieldLookupID = lookupId; lbl.Text = ddDropdownlist.SelectedItem.Text; lblToSort.Text = ddDropdownlist.SelectedItem.Text; } } break; 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; 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"); } } //txtDate.Visible = editMode; if (editMode) { txtDate.RemoveCssClass("noShow"); string datevalue = string.Empty; if (myDataTable.Rows.Count > 0) datevalue = Convert.ToDateTime(myDataTable.Rows[0]["surfaceFieldValueDate"].ToString()).ToString("dd/MM/yyyy"); txtDate.Text = datevalue; lbl.Text = datevalue; lblToSort.Text = datevalue; } else { txtDate.AddCssClass("noShow"); if (txtDate.Text != String.Empty) { fieldData.surfaceFieldValueDate = utils.formatStringToDate(txtDate.Text); lbl.Text = fieldData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); lblToSort.Text = fieldData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); } } } 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) { 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; case pNums.FieldType.Grid: //grid //no action - no data is saved in grid field type break; /* CVH 2016-01-26 Add field type placeholder */ case pNums.FieldType.Placeholder: //no action break; //JasR 2016-01-27 Caption case pNums.FieldType.Caption: HtmlTextArea textArea = (HtmlTextArea)repeaterItem.FindControl(field.surfaceFieldName); if (textArea != null) { //textArea.Visible = editMode; if (editMode) { 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; } } 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 /// private void SaveSurfaceGrid(Repeater rptEdit, int surfaceId, int parentSurfaceItemId = 0) { 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 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; foreach (RepeaterItem repeaterItem in rptEdit.Items) { if (repeaterItem.ItemIndex == 0) { HiddenField hfParentSurfaceItemId = (HiddenField)repeaterItem.FindControl("hfParentSurfaceItemId"); 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 && base.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(); 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" ) { oSurfaceFieldData fieldData; //CVH 2017-03-21 Only when child surface if (currentParentSurfaceItemId == 0 && base.IsChildSurface) { fieldData = new oSurfaceFieldData(); fieldData.surfaceId = surfaceId; fieldData.surfaceFieldID = field.recId; fieldData.surfaceItemId = itemId; } else { //get surface field data item to update, based on surfaceItemId and surfaceFieldId ArrayList dataList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceItemId,surfaceFieldID", surfaceId + "," + itemId + "," + field.recId); if (dataList == null || dataList.Count <= 0) continue; fieldData = (oSurfaceFieldData)dataList[0]; } 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); if (lbl != null) { lbl.RemoveCssClass("noShow"); } switch (typ) { #region Text case pNums.FieldType.Text://Textbox TextBox txtTextbox = (TextBox)repeaterItem.FindControl(field.surfaceFieldName); if (txtTextbox != null) { txtTextbox.AddCssClass("noShow"); fieldData.surfaceFieldValueChar = txtTextbox.Text; lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } break; #endregion #region Number case pNums.FieldType.Number: //number if (field.surfaceFieldName == "ParentSurfaceItemId") { fieldData.surfaceFieldValueNum = parentSurfaceItemId; } else { TextBox txtNumberBox = (TextBox)repeaterItem.FindControl(field.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(field.surfaceFieldName); if (txtDecimalBox != null) { 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 DropDownList ddDropdownlist = (DropDownList)repeaterItem.FindControl(field.surfaceFieldName); if (ddDropdownlist != null) { ddDropdownlist.AddCssClass("noShow"); int lookupId = 0; int.TryParse(ddDropdownlist.SelectedValue, out lookupId); 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(field.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(field.surfaceFieldName); if (txtDate != null) { txtDate.AddCssClass("noShow"); 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); 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(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.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(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.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: HtmlTextArea textArea = (HtmlTextArea)repeaterItem.FindControl(field.surfaceFieldName); if (textArea != null) { textArea.Attributes.Add("class", "noShow"); fieldData.surfaceFieldValueChar = textArea.Value; lbl.Text = fieldData.surfaceFieldValueChar; lblToSort.Text = fieldData.surfaceFieldValueChar; } 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); } } 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 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)) { //CVH 2017-02-23 Only save child grid data if the field is not set read only if (gridField.isReadOnly) continue; 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; } 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, 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, parentSurfaceItemId); } } //Bind child Grid BindChildGrid(childSurface.recId); } } } } } } 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) { //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 (user.userType != (int)pNums.UserType.WebsiteUser && ddUserLink.SelectedValue == "0") //{ // lblResult.Text = "Error: Please select the relevant user"; // pnlResult.Visible = true; // return false; //} 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; if (SaveSurfaceForm(ref item, ref surfaceDataList, ref createParentSurfaceItem)) { if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(false); 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; //item.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), item); if (SaveSurfaceForm(ref item, ref surfaceDataList, ref createParentSurfaceItem)) { //xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item); item.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), item); if (item.recId > 0) { foreach (oSurfaceFieldData data in surfaceDataList) { data.surfaceItemId = item.recId; } xData.SaveTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); result = true; int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(false); 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") xSurfaceCustomAction.SurfaceSave(base.SurfaceApp, base.SurfaceAppItem, user.recId, ConfigurationManager.AppSettings["WebAddy"], ConfigurationManager.AppSettings["admin"], ConfigurationManager.AppSettings["from"]); } } //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) { SaveChildSurfaceData(item.recId); } } } 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); 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: HtmlTextArea textArea = (HtmlTextArea)pnlBulkUpdate.FindControl("bulk_" + bulkField.surfaceFieldName); if (textArea != null) { textArea.Value = ""; } 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); } } /// /// 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) { //ArrayList gridOptions = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString()); //foreach (oSurfaceGridOptions opt in gridOptions) //{ 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; #region old code /////* CVH 2016-07-22 Refresh child surfaces */ //foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence")) //{ // PlaceHolder plc = (PlaceHolder)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (plc != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //CVH 2016-10-19 If copy master data to child, save new parent surface item and parent surface data, save copy of master for child surface // int parentSurfaceItemId = 0; // if (field.defaultToCurrent) // { // //save current surface item // 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.SurfaceApp.recId; // parentItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), parentItem); // SaveBubbleData(parentItem); // parentSurfaceItemId = parentItem.recId; // //get child surface fields // ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", gridSurface.recId.ToString()); // //save copy of master data // List paramList = new List(); // oDynamicParam par1 = new oDynamicParam(); // par1.paramDisplayName = "SurfaceID"; // par1.paramObject = gridSurface.recId; // paramList.Add(par1); // oDynamicParam par2 = new oDynamicParam(); // par2.paramDisplayName = "ParentSurfaceItemId"; // par2.paramObject = 0; // paramList.Add(par2); // DataTable masterDataItems = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", paramList); // 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 = gridSurface.recId; // copyItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), copyItem); // 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 = parentSurfaceItemId; // } // break; // } // } // copyData.recId = xData.SaveTyped("recId", typeof(oSurfaceFieldData), copyData); // } // } // base.SurfaceAppItem = parentItem; // base.SurfaceAppItemId = parentItem.recId; // /* 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 = userId; // note.isActive = true; // 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"; // } // ////load the surface app control // //ISurfaceBase uc = (ISurfaceBase)plc.FindControl(gridSurface.name + field.recId); // //uc.ParentSurfaceItemId = parentSurfaceItemId; // //uc.ParentSurfaceId = base.SurfaceApp.recId; // //uc.IsChildSurface = true; // //uc.ReloadControl(); // } // } //} #endregion 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) { 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; 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(); List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = base.SurfaceApp.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.ParentSurfaceItemId; list.Add(par2); surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); ddlCompare.DataSource = surfaceData; 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}"; } } else if (parentSurface != "") { if (base.SurfaceAppItem != null) { DataTable surfaceData = new DataTable(); List list = new List(); oDynamicParam par1 = new oDynamicParam(); par1.paramDisplayName = "SurfaceID"; par1.paramObject = surface.recId; list.Add(par1); oDynamicParam par2 = new oDynamicParam(); par2.paramDisplayName = "ParentSurfaceItemId"; par2.paramObject = base.SurfaceAppItem.recId; list.Add(par2); surfaceData = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sp_GetChildSurfaceData", list); ddlCompare.DataSource = surfaceData; 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}"; } } } else { ArrayList filterList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceId,surfaceFieldID", surface.recId.ToString() + "," + filterField.recId.ToString()); ddlCompare.DataSource = filterList; 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}"; break; case pNums.FieldType.Text: ddlCompare.DataTextField = "surfaceFieldValueChar"; break; default: break; } } 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) 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) 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) { 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(); //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(); //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); } } /// /// 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) { //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) + ");"; 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); } 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); } } 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) 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) totalWizardTabs++; } foreach (oSurfaceField tab in fieldTabs) { tabCounter++; HtmlGenericControl myTab = (HtmlGenericControl)pnlSurfaceForm.FindControl("li_f" + tab.surfaceFieldName); if (!tab.isHiddenFromWizzard && User.userType >= tab.accessLevel)//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; 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_", ""); } 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); 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"); 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) firstWizardTab = i; //tabCounter is 0 index } int currentWizardTab = 0; int totalWizardTabs = 0; foreach (oSurfaceField tab in fieldTabs) { if (!tab.isHiddenFromWizzard && User.userType >= tab.accessLevel) 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) { 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() + ")"; } 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"); 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) { 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)) { 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)) { 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) 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"); 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) { myTab.Visible = true; } else { myTab.Visible = false; continue; } if (firstTab == "" && !isPageLoad) firstTab = "." + prefix + tab.surfaceFieldName + "Hidden"; //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: 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.Caption: HtmlTextArea txtCaption = (HtmlTextArea)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txtCaption.Value = ""; 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: 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.Caption: HtmlTextArea txtCaption = (HtmlTextArea)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txtCaption.Value = ""; 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: 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.Caption: HtmlTextArea txtCaption = (HtmlTextArea)pnlSurfaceForm.FindControl(fieldToAction.surfaceFieldName); txtCaption.Value = ""; 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 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; } } //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.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 { 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: HtmlTextArea textArea = (HtmlTextArea)pnlSurfaceForm.FindControl(field.surfaceFieldName); if (textArea != null) { fieldData.surfaceFieldValueChar = textArea.Value; } 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; } } 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); return true; } /// /// Persist the Placeholder /// private void PersistChildApp() { try { if (base.ChildAppItem != null) { 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); } //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 = base.ChildAppItem; //parcel.SurfaceAppItemId = base.ChildAppItem.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 = base.ChildIsView; //parcel.IsNew = base.ChildIsNew; //parcel.IsClone = base.ChildIsClone; //LoadSurfaceControl(parcel); //Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; //UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; //upChildApp.Update(); //BindChildGrid(base.ChildAppItem.surfaceId); 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(base.ChildAppItem.surfaceId); } } } } 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)) SurfaceGridTotals[key] += Convert.ToDecimal(dt.Rows[i][key]); } } 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); } } ///// ///// Load Surface control with Jquery ///// //private void LoadSurfaceControl(oSurfaceControlParcel _controlParcel) //{ // try // { // Session["SurfaceControlParcel"] = _controlParcel; // if (_controlParcel.IsSubChildSurface) // { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "loadjQuerySurfaceControlSub", "loadSurfaceControlSub('" + _controlParcel.ControlPath + "');", true); } // else // { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "loadjQuerySurfaceControl", "loadSurfaceControl('" + _controlParcel.ControlPath + "');", true); } // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} ///// ///// Remove Surface control with Jquery ///// //private void RemoveSurfaceControl(string sub) //{ // try // { // if (sub != String.Empty) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "removeSurfaceControlSub", "removeSurfaceControlSub();", true); // else // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "removeSurfaceControl", "removeSurfaceControl();", true); // } // catch (Exception ex) // { // exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} #endregion #region events /// /// Page initiliazie event to dynamicall load user controls - grid surface apps /// /// /// protected void Page_Init(object sender, EventArgs e) { if (base.SurfaceApp != null) { if (base.SurfaceAppItem == null) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceFormGridSurfaceApps(); PopulateSurfaceFormContentType(item); } //CVH 2016-12-20 Rebind child grids that are in edit mode by default, otherwise it loses it's checkboxes //RebindChildGridBatchEdit(); } } /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { bool wizardcompleted = false; try { //CVH 2017-01-17 Remove global oUser, get from handler oUser user = handler.ReturnUser(); //Persist apps PersistChildApp(); if (base.SurfaceApp != null) { //GR added to show the wizzard buttons at bottom or standard form buttons if (base.SurfaceApp.isWizzard) { //CVH 2017-01-09 If it is a wizard, but the wizard buttons have been disabled, set the save button to custom javascript validation method ValidateSurfaceWizardTabs, to validate all the tabs oSetup setup = handler.ReturnSetup(); ArrayList fieldTabs = new ArrayList(); //GR added check now to see if wizard completed if (base.SurfaceAppItem != null) { wizardcompleted = base.SurfaceAppItem.isWizardCompleted; } if (!wizardcompleted && (user.userType == (int)pNums.UserType.WebsiteUser || setup.code == "GLOB-1")) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId,isHiddenFromWizzard", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab + ",0", "sequence"); if (fieldTabs.Count > 1)//check if there are more than one tab else act as a form anyway { pnlWizzardButtons.Visible = true; pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; } else { // if (setup.code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser) if (setup.code == "SHOU-1" && user.userType < (int)pNums.UserType.PowerUser) { pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = true; pnlWizzardButtons.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; btnSaveSingle.ValidationGroup = ""; btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } } else { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetTabsVisible(fieldTabs); if (setup.code == "SHOU-1" && user.userType < (int)pNums.UserType.PowerUser) { pnlFormButtons.Visible = false; pnlFormButtonsSingleItem.Visible = true; pnlWizzardButtons.Visible = false; lnkSave.Visible = false; lnkRefresh.Visible = false; lnkBack.Visible = false; btnSaveSingle.ValidationGroup = ""; btnSaveSingle.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; btnSave.ValidationGroup = ""; btnSaveAndNew.ValidationGroup = ""; btnSaveBack.ValidationGroup = ""; btnSave.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveAndNew.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; btnSaveBack.OnClientClick = "javascript:return ValidateSurfaceWizardTabs();"; } } } else { pnlFormButtons.Visible = true; pnlFormButtonsSingleItem.Visible = false; pnlWizzardButtons.Visible = false; lnkSave.Visible = true; lnkRefresh.Visible = true; lnkBack.Visible = true; //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-12-12 Set tab access, and set navigation button properties (previous + next) ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetTabsVisibleNoWizard(fieldTabs, true); } if (!Page.IsPostBack) { pnlSurfaceForm.Enabled = true; pnlSurfaceGrid.Enabled = true; btnNew.Enabled = true; base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; base.ActiveTabPanel = String.Empty; int startIndex = 0; int maxLength = 50; //foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) //{ if (MainGridOptions.pagingCount > 0) { maxLength = MainGridOptions.pagingCount; if (ddSurfaceEntries.Items.FindByValue(MainGridOptions.pagingCount.ToString()) != null) ddSurfaceEntries.SelectedValue = MainGridOptions.pagingCount.ToString(); } btnNew.Visible = user.userType >= MainGridOptions.addAccessType; //break; //} BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(false); oSurface surface = base.SurfaceApp; bool viewSingle = false; if (utils.verifySession("surfaceItemId")) { foreach (oSurfaceItem userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", Session["surfaceItemId"].ToString())) { base.SurfaceAppItem = userItem; base.SurfaceAppItemId = userItem.recId; viewSingle = true; break; } utils.disposeSession("surfaceItemId"); } if (surface.isDefaultToForm) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surface.recId; bool userLinks = false; //GR Added the ability to pickup the individual surface item related to user if (user.userType == (int)pNums.UserType.WebsiteUser) { //JR is userLink contains data, then go to grid if (xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "surfaceId,isActive,isDeleted,userLink", surface.recId + ",1,0," + user.recId, "dateCreated Desc").Count > 0) { TogglePanels("pnlSurfaceGrid"); userLinks = true; } else { //GR Added custom to prevent a back button to grid for website users btnCancel.Enabled = false; btnNew.Visible = false; btnCancelWizzard.Enabled = false; //foreach (oSurfaceItem userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "surfaceId,isActive,createdBy", surface.recId + ",1," + user.recId, "dateCreated Desc")) foreach (oSurfaceItem userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "surfaceId,isActive,userLink", surface.recId + ",1," + user.recId, "dateCreated Desc")) { base.SurfaceAppItem = userItem; base.SurfaceAppItemId = userItem.recId; item = userItem; break; } } } if (!userLinks) { TogglePanels("pnlSurfaceForm"); PopulateSurfaceForm(item, true); //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"); } } /* CVH 2016-09-09 Add ELSE, otherwise Default to Form doesn't work. NB for TSP */ else if (surface.isComparable) { BindCompareDropdowns(surface); lnkGridView.Visible = true; TogglePanels("pnlSurfaceCompare"); } else if ((base.RowLimit == 1 || viewSingle) && base.SurfaceAppItem != null) { PopulateSurfaceView(base.SurfaceAppItem); TogglePanels("pnlSurfaceView"); } else { TogglePanels("pnlSurfaceGrid"); } if (user.userType > (int)pNums.UserType.PowerUser) { //surface field handling BindFieldTypes(); BindSequence(); BindLookupCategories(); BindSurfaceApps(); BindContent(); BindComposite(); BindActionTypes(); //show edit/add/remove buttons for inline edit CheckBox chkToggleLayout = (CheckBox)pnlSurfaceForm.FindControl("chkToggleLayout"); if (chkToggleLayout != null) chkToggleLayout.Visible = true; if (utils.verifySession("Inline")) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surface.recId; foreach (oSurfaceItem itm in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", Session["Inline"].ToString())) { item = itm; break; } base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; PopulateSurfaceForm(item, true); TogglePanels("pnlSurfaceForm"); EnableInlineButtons(true); chkToggleLayout.Checked = true; utils.disposeSession("Inline"); if (utils.verifySession("ChildInline")) { int itemId = 0; int.TryParse(Session["ChildInline"].ToString(), out itemId); if (itemId > 0) { PersistChildEdit(itemId); } utils.disposeSession("ChildInline"); } } } else { chkToggleLayout.Visible = false; EnableInlineButtons(false); pnlParentSurfaceOptions.Visible = false; } //GR 08/03/2017 setup child controls //ArrayList ChildAppNames = new ArrayList(); //ArrayList ChildApps = new ArrayList(); ////fetch child names //ChildAppNames = xData.GetTypedByCriteriaDistinct("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Grid, "relationalSurface", "relationalSurface"); //foreach (oSurfaceField grdField in ChildAppNames) //{ // string userControlName = "surfaceChildControl_" + grdField.relationalSurface; // ISurfaceBase ucChild = (ISurfaceBase)this.FindControl(userControlName); // if (ucChild != null) // { // foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "isActive,name", "1," + grdField.relationalSurface)) // { // ucChild.SurfaceApp = surf; // } // } //} if (utils.verifySession("referItem")) { int itemId = int.Parse(Session["referItem"].ToString()); EditSurface(itemId, null); utils.disposeSession("referItem"); } } else { //CVH 2016-12-13 Add check for isWizard if (!wizardcompleted && this.SurfaceApp.isWizzard) { if (base.ActiveTabPanel != null && base.ActiveTabPanel != String.Empty) { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Send all tabs to method, handle hidden tabs there. Otherwise not handled correctly when surface tabs are not in sequence ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); MaintainActiveTab(fieldTabs); } } //CVH 2016-12-13 Expand collapsed groups on postback //string expandGroups = ""; //if (ViewState["ExpandSurfaceGroupAccordianIds"] != null && ViewState["ExpandSurfaceGroupAccordianIds"].ToString() != "") // expandGroups = ViewState["ExpandSurfaceGroupAccordianIds"].ToString(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "expandGroups", "ExpandSurfaceGroupAccordian('" + expandGroups + "');", true); } if (base.SurfaceAppGridEditTypeId <= 0) { int editTypeId = 1; //foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) //{ editTypeId = MainGridOptions.surfaceGridEditTypeId; //break; //} base.SurfaceAppGridEditTypeId = editTypeId; } } //else //{ // Response.Redirect("/home", false); //} } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Selected index changed eventfor entires per page /// /// /// protected void ddSurfaceEntries_SelectedIndexChanged(object sender, EventArgs e) { int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); } /// /// Next /// /// /// protected void btnPageNext_Click(object sender, EventArgs e) { int totalRecords = 0; int.TryParse(lblCount.Text, out totalRecords); int pageIndex = 0; int.TryParse(txbPageNumber.Value, out pageIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); if (totalRecords > 0) { if (pageIndex > 1) { if ((pageIndex - 1) < totalRecords / maxLength) { txbPageNumber.Value = (pageIndex + 1).ToString(); BindSurfaceGrid(pageIndex, maxLength); } } else { if (pageIndex < totalRecords / maxLength) { txbPageNumber.Value = (pageIndex + 1).ToString(); BindSurfaceGrid(pageIndex, maxLength); } } } } /// /// Back /// /// /// protected void btnPageBack_Click(object sender, EventArgs e) { int pageIndex = 0; int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); int.TryParse(txbPageNumber.Value, out pageIndex); if (pageIndex > 1) { txbPageNumber.Value = (pageIndex - 1).ToString(); BindSurfaceGrid(pageIndex, maxLength); } } /// /// Search Surface Button /// /// /// protected void btnSearch_Click(object sender, EventArgs e) { int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(true); } /// /// Refresh Filters Button /// /// /// protected void lnkRefreshFilterSurfaceGrid_Click(object sender, EventArgs e) { try { BindSurfaceGridColumnFilters(true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clear Filters Button /// /// /// protected void lnkRemoveFilterSurfaceGrid_Click(object sender, EventArgs e) { try { BindSurfaceGridColumnFilters(false); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Filter Grid Button /// /// /// protected void lnkFilterSurfaceGrid_Click(object sender, EventArgs e) { try { int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Surface Item /// /// /// protected void btnNew_Click(object sender, EventArgs e) { try { if (base.SurfaceApp != null) { NewItem(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bulk Update /// /// /// protected void btnBulkUpdate_Click(object sender, EventArgs e) { TogglePanels("pnlSurfaceGrid"); lblBulkUpdateResult.Text = ""; pnlBulkUpdateResult.Visible = false; upBulkUpdate.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('#modBulkUpdate').modal('show');", true); } protected void btnSaveBulkUpdate_Click(object sender, EventArgs e) { try { if (pnlBulkUpdate.Controls.Count <= 0) { TogglePanels("pnlSurfaceGrid"); pnlBulkUpdateResult.Visible = true; lblBulkUpdateResult.Text = "No fields to update."; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');$('#modBulkUpdate').modal('show');", true); return; } bool result = false; bool anyChecked = false; ArrayList bulkFields = null; //find repeater and all selected items foreach (Control rpt in pnlSurfaceGrid.Controls) { if (rpt.GetType() == typeof(Repeater)) { Repeater repeater = (Repeater)rpt; foreach (RepeaterItem rptItem in repeater.Items) { CheckBox chk = (CheckBox)rptItem.FindControl("chkBulkUpdate"); if (chk != null && chk.Checked) { anyChecked = true; LinkButton lnkEdit = (LinkButton)rptItem.FindControl("lnkEdit"); if (lnkEdit != null) { int itemId = int.Parse(lnkEdit.CommandArgument); if (itemId > 0) { foreach (oSurfaceItem surfaceItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { if (bulkFields == null) bulkFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,enableBulkUpdate", surfaceItem.surfaceId + ",1,1", "sequence"); result = PerformBulkUpdate(surfaceItem, bulkFields); break; } } } } if (anyChecked && !result) break; } } } pnlBulkUpdateResult.Visible = true; if (!anyChecked) lblBulkUpdateResult.Text = "No items have been selected."; else if (result) { ClearBulkUpdate(bulkFields); lblBulkUpdateResult.Text = "All selected items have been updated successfully."; } else lblBulkUpdateResult.Text = "Bulk update failed."; upBulkUpdate.Update(); int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(true); TogglePanels("pnlSurfaceGrid"); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showBulkUpdateModal", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');$('#modBulkUpdate').modal('show');", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Surface Item /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { EditSurface(itemId, rptItem); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Surface Item /// /// /// protected void lnkEditCompare_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkEdit", "ddlCompare"); if (pnlSurfaceView.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceView.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditSurface(listSurfaceItemId, null); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clone Surface Item /// /// /// protected void lnkClone_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { CloneSurface(itemId); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Clone Compare Surface Item /// /// /// protected void lnkCloneCompare_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkClone", "ddlCompare"); if (pnlSurfaceView.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceView.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId CloneSurface(listSurfaceItemId); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Open User Link Modal /// /// /// protected void lnkUserLink_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { Session["userLinkItemId"] = itemId; IControlBase userLink = (IControlBase)this.FindControl("userLink"); userLink.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalUserLink", "$('#modUserLinks" + base.SurfaceApp.name + "').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Open User Link Modal /// /// /// protected void lnkUserLinkChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { Session["userLinkItemId"] = itemId; IControlBase userLink = (IControlBase)this.FindControl("userLink"); userLink.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalUserLink", "$('#modUserLinks" + base.SurfaceApp.name + "').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit click from View /// /// /// protected void btnViewEdit_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; base.ActiveTabPanel = String.Empty; ///* CVH 2016-07-22 Refresh child surfaces */ //foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence")) //{ // PlaceHolder plc = (PlaceHolder)pnlSurfaceForm.FindControl(field.surfaceFieldName); // if (plc != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //load the surface app control // ISurfaceBase uc = (ISurfaceBase)plc.FindControl(gridSurface.name + field.recId); // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.IsChildSurface = true; // int rowLimit = 0; // Int32.TryParse(field.relationalValues, out rowLimit); // uc.RowLimit = rowLimit; // uc.ReloadControl(); // } // } //} PopulateSurfaceForm(item, false); //custom to calculate age if these fields exsit CalculateAge("PatientInformation_PatientDetails_DateofBirth", "PatientInformation_PatientDetails_Age"); //STUD-1 age calc CalculateAge("Application_PartADETAILSOFAPPLICANT_DateofBirth", "ApplicantInfo_ApplicantInformation_Age"); SetPatientType("PatientType_PatientType_PatientType"); //JasR 2016-01-20 Set wizard buttons if (base.SurfaceApp.isWizzard) { btnFinish.Visible = false; btnNext.Visible = true; } TogglePanels("pnlSurfaceForm"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } } } upSurface.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Surface Item /// /// /// protected void lnkView_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; base.ActiveTabPanel = String.Empty; base.SurfaceApp.isWizzard = false; /* CVH 2016-07-22 Refresh child surfaces */ //foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Grid, "sequence")) //{ // PlaceHolder plc = (PlaceHolder)pnlSurfaceForm.FindControl("plcv" + field.surfaceFieldName); // if (plc != null) // { // foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) // { // //load the surface app control // ISurfaceBase uc = (ISurfaceBase)plc.FindControl("v" + gridSurface.name + field.recId); // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.IsChildSurface = true; // int rowLimit = 0; // Int32.TryParse(field.relationalValues, out rowLimit); // uc.RowLimit = rowLimit; // uc.ReloadControl(); // } // } //} PopulateSurfaceView(item); TogglePanels("pnlSurfaceView"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceViewModal", "$('#modSurfaceView" + base.SurfaceApp.name + "').modal();", true); } dynamic enquiry = this.FindControl("enquiryUC"); if (enquiry != null) { oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } //CVH 2016-11-17 Set the Note 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; } Session["noteSurfaceFieldName"] = fieldName; Session["account"] = xDebtors.SetAccountItem(itemId, base.SurfaceApp.recId, usr); Session["loadType"] = "Embedded"; enquiry.ReloadControl(); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove a surface item /// /// /// protected void lnkRemove_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { /* CVH 2016-09-19 Don't delete surface items, set item isDeleted = true */ int itemId = int.Parse(((LinkButton)sender).CommandArgument); /* CVH 2016-07-22 Delete all child data items linking to current parent item id */ foreach (oSurfaceField parentSurfaceItemIdField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", "ParentSurfaceItemId")) { foreach (oSurfaceFieldData childItemId in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceFieldID,surfaceFieldValueNum", parentSurfaceItemIdField.recId + "," + itemId.ToString())) { foreach (oSurfaceItem childItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", childItemId.surfaceItemId.ToString())) { childItem.isDeleted = true; xData.UpdateTyped("recId", childItem.recId.ToString(), typeof(oSurfaceItem), childItem); } //if (xData.DeleteTyped("surfaceItemId", childItem.surfaceItemId.ToString(), typeof(oSurfaceFieldData))) //{ //if (xData.DeleteTyped("recId", childItem.surfaceItemId.ToString(), typeof(oSurfaceItem))) //{ //} //} } } foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item.isDeleted = true; if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(true); pnlResult.Visible = true; lblResult.Text = "the selected item was deleted successfully."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; if (base.IsSubChildSurface) { sub = "Sub"; } else { base.ChildAppItem = null; } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); //RemoveSurfaceControl(sub); PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; if (plcChildApp != null) plcChildApp.Controls.Clear(); } else { if (base.SurfaceApp.isComparable) { BindCompareDropdowns(base.SurfaceApp); lnkGridView.Visible = true; TogglePanels("pnlSurfaceCompare"); } else { TogglePanels("pnlSurfaceGrid"); } if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); upSurface.Update(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bulk Update select all checkbox check /// /// /// protected void chkBulkUpdateAll_OnCheckedChanged(object sender, EventArgs e) { try { CheckBox chkBulkUpdateAll = (CheckBox)sender; if (chkBulkUpdateAll != null) { foreach (Control rpt in pnlSurfaceGrid.Controls) { if (rpt.GetType() == typeof(Repeater)) { Repeater repeater = (Repeater)rpt; foreach (RepeaterItem item in repeater.Items) { CheckBox chk = (CheckBox)item.FindControl("chkBulkUpdate"); if (chk != null) chk.Checked = chkBulkUpdateAll.Checked; } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface App Item /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { Control btn = (Control)sender; if (btn == null) return; if (PerformSave(false, btn.ID == "btnSaveDraft" ? true : false)) { pnlResult.Visible = true; /* CVH 2016-07-25 Default action after save go back to grid. Otherwise automatic load for new item */ /* CVH 2016-08-30 Button text = Save and default action to remain in edit mode */ if (btn.ID == "btnSaveBack" || btn.ID == "btnSaveDraft") { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { //force a post back for child grids ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); string sub = String.Empty; if (base.IsSubChildSurface) { sub = "Sub"; } else { base.ChildAppItem = null; } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); //RemoveSurfaceControl(sub); //CVH 2017-03-14 Removing this, causing problems with tabs. When clicking Save and Back on child modal where parent is wizard, it switches to first wizard tab (not current where child modal is situated) //PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; //if (plcChildApp != null) // plcChildApp.Controls.Clear(); } else { TogglePanels("pnlSurfaceGrid"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } } else if (btn.ID == "btnSaveAndNew") { if (base.IsChildSurface) { //force a post back for child grids ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); } NewItem(); } else if (btn.ID == "btnSaveNext") { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNextTab", "ActivateNextTab();", true); } else { if (base.IsChildSurface) { //force a post back for child grids ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); upSurface.Update(); } /* CVH 2016-08-30 Keep modal open if this is child surface */ if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); MaintainActiveTab(fieldTabs); SetTabsVisible(fieldTabs); } //CVH 2016-09-23 If shown in modal on sales control, need to reload sales contacts list if (handler.GetRoutedData("canvas-title") == "sales") { CommandEventArgs args = new CommandEventArgs("ReloadContacts", ""); RaiseBubbleEvent(null, args); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Item Data Bound /// /// /// protected void rptSurfaceGrid_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { oUser user = handler.ReturnUser(); if (e.Item.ItemType == ListItemType.Header) { if (e.Item.FindControl("thUserLink") != null) { HtmlTableCell thUserLink = (HtmlTableCell)e.Item.FindControl("thUserLink"); thUserLink.Visible = base.SurfaceApp.linkUser && user.userType >= (int)pNums.UserType.AdminUser; } foreach (oSurfaceField field in MainFieldTable.Select("surfaceFieldTypeId=" + (int)pNums.FieldType.Debtors + "") .AsEnumerable() .Cast()) { if (e.Item.FindControl("th" + field.surfaceFieldName) != null) { HtmlTableCell thDebtors = (HtmlTableCell)e.Item.FindControl("th" + field.surfaceFieldName); thDebtors.Visible = user.userType >= field.accessLevel; } } if (e.Item.FindControl("thStatus") != null) { HtmlTableCell thStatus = (HtmlTableCell)e.Item.FindControl("thStatus"); thStatus.Visible = MainGridOptions.showWizardStatus; } if (e.Item.FindControl("thEdit") != null) { HtmlTableCell thEdit = (HtmlTableCell)e.Item.FindControl("thEdit"); thEdit.Visible = MainGridOptions.allowEdit && user.userType >= MainGridOptions.editAccessType; } if (e.Item.FindControl("thView") != null) { HtmlTableCell thView = (HtmlTableCell)e.Item.FindControl("thView"); thView.Visible = MainGridOptions.allowView && user.userType >= MainGridOptions.viewAccessType; } if (e.Item.FindControl("thRemove") != null) { HtmlTableCell thRemove = (HtmlTableCell)e.Item.FindControl("thRemove"); thRemove.Visible = MainGridOptions.allowRemove && user.userType >= MainGridOptions.removeAccessType; } if (e.Item.FindControl("thClone") != null) { HtmlTableCell thClone = (HtmlTableCell)e.Item.FindControl("thClone"); thClone.Visible = MainGridOptions.allowClone && user.userType >= MainGridOptions.cloneAccessType; } } if (e.Item.ItemType == ListItemType.Footer) { if (e.Item.FindControl("tfUserLink") != null) { HtmlTableCell tfUserLink = (HtmlTableCell)e.Item.FindControl("tfUserLink"); tfUserLink.Visible = base.SurfaceApp.linkUser && user.userType >= (int)pNums.UserType.AdminUser; } foreach (oSurfaceField field in MainFieldTable.Select("surfaceFieldTypeId=" + (int)pNums.FieldType.Debtors + "") .AsEnumerable() .Cast()) { if (e.Item.FindControl("tf" + field.surfaceFieldName) != null) { HtmlTableCell tfDebtors = (HtmlTableCell)e.Item.FindControl("tf" + field.surfaceFieldName); tfDebtors.Visible = user.userType >= field.accessLevel; } } if (e.Item.FindControl("tfStatus") != null) { HtmlTableCell tfStatus = (HtmlTableCell)e.Item.FindControl("tfStatus"); tfStatus.Visible = MainGridOptions.showWizardStatus; } if (e.Item.FindControl("tfEdit") != null) { HtmlTableCell tfEdit = (HtmlTableCell)e.Item.FindControl("tfEdit"); tfEdit.Visible = MainGridOptions.allowEdit && user.userType >= MainGridOptions.editAccessType; } if (e.Item.FindControl("tfView") != null) { HtmlTableCell tfView = (HtmlTableCell)e.Item.FindControl("tfView"); tfView.Visible = MainGridOptions.allowView && user.userType >= MainGridOptions.viewAccessType; } if (e.Item.FindControl("tfRemove") != null) { HtmlTableCell tfRemove = (HtmlTableCell)e.Item.FindControl("tfRemove"); tfRemove.Visible = MainGridOptions.allowRemove && user.userType >= MainGridOptions.removeAccessType; } if (e.Item.FindControl("tfClone") != null) { HtmlTableCell tfClone = (HtmlTableCell)e.Item.FindControl("tfClone"); tfClone.Visible = MainGridOptions.allowClone && user.userType >= MainGridOptions.cloneAccessType; } } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { if (base.SurfaceApp.linkUser && e.Item.FindControl("lnkUserLink") != null) { HtmlTableCell tdUserControl = (HtmlTableCell)e.Item.FindControl("tdUserLink"); tdUserControl.Visible = user.userType >= (int)pNums.UserType.AdminUser; LinkButton lnkUserLink = (LinkButton)e.Item.FindControl("lnkUserLink"); int surfaceItemId = Convert.ToInt32(lnkUserLink.CommandArgument.ToString()); foreach (oSurfaceItem surfaceItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceItemId.ToString(), "", "pal_")) { bool userLinked = false; lnkUserLink.Attributes.Remove("title"); foreach (ovUserShared userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", surfaceItem.userLink.ToString())) { userLinked = true; lnkUserLink.Attributes.Add("title", userItem.email); } if (!userLinked) { lnkUserLink.Attributes.Add("title", "no link found"); lnkUserLink.CssClass = "fa fa-users palette-remove"; } } } //add any custom logic here } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Repeater Item Created /// /// /// protected void rptSurfaceGrid_ItemCreated(object sender, RepeaterItemEventArgs e) { ScriptManager scriptMan = ScriptManager.GetCurrent(this.Page); LinkButton btn = e.Item.FindControl("ApplicantInfo_ApplicantInformation_SBFCanididateReport") as LinkButton; if (btn != null) { btn.Click += surfaceButton_Click; scriptMan.RegisterAsyncPostBackControl(btn); } } protected void rptSurfaceGrid_PreRender(object sender, EventArgs e) { //Repeater rep = (Repeater)sender; //if (rep.Items.Count == 0) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(true);", true); //else // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(false);", true); } /// /// Save Row click /// /// /// protected void lnkSaveRow_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; //CVH 2017-02-09 Get Parent.Parent, Parent is td RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; oSurfaceItem item = new oSurfaceItem(); ArrayList surfaceDataList = new ArrayList(); if (base.SurfaceApp != null) { /* CVH 2016-02-02 Enable batch editing */ if (base.SurfaceAppGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { SaveSurfaceGrid((Repeater)rptItem.Parent, base.SurfaceApp.recId); } else { oSurface surfaceApp = base.SurfaceApp; if (base.SurfaceAppItem != null)//update { item = base.SurfaceAppItem; SaveSurfaceRow(ref item, ref surfaceDataList, rptItem); if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); base.SurfaceAppItem = item; base.SurfaceAppItemId = item.recId; ToggleRowEdit(item.recId, item, false, rptItem); } } } if (rptItem.Parent != null && rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); BindSurfaceGridColumnFilters(true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel Event for the row /// /// /// protected void lnkCancel_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { /* CVH 2016-02-02 Enable batch editing */ if (base.SurfaceAppGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); } else { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent; oSurfaceItem item = new oSurfaceItem(); ArrayList surfaceDataList = new ArrayList(); if (base.SurfaceApp != null) { oSurface surfaceApp = base.SurfaceApp; if (base.SurfaceAppItem != null)//update { item = base.SurfaceAppItem; ToggleRowEdit(item.recId, item, false, rptItem); } } if (rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void ddlCompare_SelectedIndexChanged(object sender, EventArgs e) { try { DropDownList list = (DropDownList)sender; int columnNumber = Convert.ToInt32(list.ID.Substring(list.ID.IndexOf('_') + 1, 1)); string listSurfaceItemId = list.SelectedValue; //surfaceItemId string surfaceField = ""; if (list.ID.Length - list.ID.Replace("__", "").Length > 2) { surfaceField = list.ID.Substring(list.ID.LastIndexOf("__") + 2); } foreach (oSurfaceItem surfaceItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", listSurfaceItemId)) { PopulateSurfaceCompareView(surfaceItem, columnNumber, surfaceField); break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface textbox text changed event /// /// /// protected void surfaceTextBox_TextChanged(object sender, EventArgs e) { TextBox txtBox = (TextBox)sender; //actions foreach (oSurfaceField surfaceFieldSource in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", txtBox.ID)) { foreach (oSurfaceField surfaceFieldToChange in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "actionSource", surfaceFieldSource.recId.ToString())) { string controlIdToChange = surfaceFieldToChange.surfaceFieldName; string action = surfaceFieldToChange.action.ToString(); string output = string.Empty; foreach (oSurfaceAction actionItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", action)) { switch (actionItem.action) { case "VAT": oSetup setup = handler.ReturnSetup(); if (setup.vatRegistered) { decimal input = Convert.ToDecimal(txtBox.Text); output = utils.CalculateVAT(setup.vatRate, input).ToString("N2"); } break; case "Age": switch (surfaceFieldSource.surfaceFieldTypeId) { case 7: //Date of Birth output = utils.CalculateAge(DateTime.Parse(txtBox.Text), null).ToString(); break; default: //Assume IDnumber output = utils.CalculateAge(null, txtBox.Text).ToString(); break; } break; case "Gender": output = utils.formatGenderFromID(txtBox.Text).ToString(); break; default: break; } } TextBox tbToChange = (TextBox)FindControl(controlIdToChange); tbToChange.Text = output; } } //Custom per surface app switch (txtBox.ID) { case "": break; default: break; } } /// /// event for all surface picklist index changed event /// /// /// protected void surfaceDropDownList_SelectedIndexChanged(object sender, EventArgs e) { //Custom per surface app try { if (sender is DropDownList) { DropDownList list = (DropDownList)sender; string listId = list.ID; string display = list.SelectedItem.Text.ToString(); if (list.Parent.FindControl("reason" + listId) != null) { TextBox txtReason = (TextBox)list.Parent.FindControl("reason" + listId); RequiredFieldValidator rfvReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + listId); string itemId = list.SelectedItem.Value; if (txtReason != null && itemId == "0") { txtReason.Enabled = false; txtReason.Text = ""; } else { foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", itemId)) { if (lookupItem.wantsReason) { txtReason.Enabled = true; if (rfvReason != null) rfvReason.ControlToValidate = txtReason.ID; txtReason.Focus(); } else { txtReason.Enabled = false; txtReason.Text = ""; } } } } if (list.ID == "PatientType_PatientType_PatientType") SetPatientType("PatientType_PatientType_PatientType"); //CVH 2017-01-18 Set toggle view controls visible/not visible depending on picklist selected value SetToggleViewActionVisibilityPicklist(list); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface checkbox checked changed event /// /// /// protected void surfaceCheckbox_OnCheckedChanged(object sender, EventArgs e) { //Custom per surface app try { CheckBox chkBox = (CheckBox)sender; if (chkBox.ID == "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_InjuryonDuty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divvPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = chkBox.Checked; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface checkbox checked changed event /// /// /// protected void surfaceCheckboxList_OnCheckedChanged(object sender, EventArgs e) { //Custom per surface app try { //if (sender is HtmlGenericControl) //{ // foreach (Control control in ((HtmlGenericControl)sender).Controls) // { // if (control is CheckBox) // { // CheckBox chkBox = (CheckBox)control; // //CVH 2016-09-27 If field is part of checkboxlist and picklist item wants reason, enable/disable textbox // //try to find textbox for wants reason // TextBox txt = (TextBox)chkBox.Parent.FindControl(chkBox.ID + "Text"); // if (txt != null) // { // txt.Enabled = chkBox.Checked; // if (!txt.Enabled) // txt.Text = ""; // } // //CVH 2016-10-10 Check if there are fields with Toggle View action types linking to this field, and then if selected item equals the action value // SetToggleViewActionVisibilityCheckboxList(chkBox); // } // } //} if (sender is CheckBox) { CheckBox chkBox = (CheckBox)sender; //CVH 2016-09-27 If field is part of checkboxlist and picklist item wants reason, enable/disable textbox //try to find textbox for wants reason TextBox txt = (TextBox)chkBox.Parent.FindControl(chkBox.ID + "Text"); if (txt != null) { txt.Enabled = chkBox.Checked; if (!txt.Enabled) txt.Text = ""; } //CVH 2016-10-10 Check if there are fields with Toggle View action types linking to this field, and then if selected item equals the action value SetToggleViewActionVisibilityCheckboxList(chkBox); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface radioButtonList index changed event /// /// /// protected void surfaceRadioButtonList_SelectedIndexChanged(object sender, EventArgs e) { //Custom per surface app try { RadioButtonList list = (RadioButtonList)sender; string listId = list.ID; string display = list.SelectedItem.Text.ToString(); TextBox txtReason = (TextBox)list.Parent.FindControl("reason" + listId); RequiredFieldValidator rfvPicklistReason = (RequiredFieldValidator)pnlSurfaceForm.FindControl("req" + listId); string itemId = list.SelectedItem.Value; foreach (oSurfaceLookup lookupItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "recId", itemId)) { if (lookupItem.wantsReason) { txtReason.Enabled = true; if (rfvPicklistReason != null) { rfvPicklistReason.ControlToValidate = txtReason.ID; rfvPicklistReason.Enabled = true; } txtReason.Focus(); } else { txtReason.Text = ""; txtReason.Enabled = false; if (rfvPicklistReason != null) rfvPicklistReason.Enabled = false; } //IOD stuff if (listId.ToLower() == "patientinformation_personresponsibleforaccountpaymentmainmemberofmedicalaid_injuryonduty") { Control IODGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_EmployerDetailsInjuryonDuty"); if (IODGroup != null) IODGroup.Visible = display == "Yes"; UpdatePanel iodPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_EmployerDetailsInjuryonDuty"); if (iodPanel != null) iodPanel.Update(); if (display == "Yes") { DropDownList ddMedScheme = (DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MedicalAidIfapplicable_MedicalAidSchemeName"); if (ddMedScheme != null) ddMedScheme.SelectedValue = ddMedScheme.Items.FindByText("Workmans Compensation Accident").Value; } Control MedGroup = (Control)pnlSurfaceForm.FindControl("divfPatientInformation_MedicalAidIfapplicable"); if (MedGroup != null) MedGroup.Visible = display == "No"; UpdatePanel medPanel = (UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_MedicalAidIfapplicable"); if (medPanel != null) medPanel.Update(); } } //CVH 2016-10-11 Toggle View Action SetToggleViewActionVisibilityRadioButtonList(list); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// event for all surface button clicks /// /// /// protected void surfaceButton_Click(object sender, EventArgs e) { //The body of this method is custom per surface app Button btn = (Button)sender; string btnID = btn.ID; switch (btnID) { //GWC Status Button case "PatientProfile_PatientStatus": if (btn.Text == "Status: Pending") { oMedicalPatientVisitLog visitLog = new oMedicalPatientVisitLog(); visitLog.signInDate = DateTime.Now; visitLog.surfaceItemId = base.SurfaceAppItemId; xData.SaveTyped("recId", typeof(oMedicalPatientVisitLog), visitLog); btn.AddCssClass("btn-success"); btn.RemoveCssClass("btn-warning"); btn.RemoveCssClass("btn-danger"); btn.Text = "Status: In Progress"; } else { foreach (oMedicalPatientVisitLog visitLog in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientVisitLog), "surfaceItemId", base.SurfaceAppItemId.ToString(), "signInDate DESC")) { visitLog.signOutDate = DateTime.Now; xData.UpdateTyped("recId", visitLog.recId.ToString(), typeof(oMedicalPatientVisitLog), visitLog); break; } btn.AddCssClass("btn-warning"); btn.RemoveCssClass("btn-success"); btn.RemoveCssClass("btn-danger"); btn.Text = "Status: Pending"; } break; //GWC Copy Buttons #region gwc - patient to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromPatient": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress1")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress1")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress2")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress2")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress3")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress3")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress4")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress4")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress5")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress5")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PostalAddress6")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress6")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress1")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress1")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress2")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress2")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress3")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress3")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress4")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress4")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress5")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress5")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_PhysicalAddress6")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PhysicalAddress6")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Occupation")).Text; break; #endregion #region gwc - spouce to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Occupation")).Text; break; #endregion #region gwc - mother to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromMother": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Occupation")).Text; break; #endregion #region gwc - father to account case "PatientInformation_PersonResponsibleforAccountPayment_CopyFromFather": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_DateofBirth")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_EmailAddress")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_EmployerName")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPayment_Occupation")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Occupation")).Text; break; #endregion #region gwc - father to emergency case "PatientInformation_EmergencyContact_CopyFromFather": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_FatherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Father"; break; #endregion #region gwc - mother to emergency case "PatientInformation_EmergencyContact_CopyFromMother": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_MotherDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Mother"; break; #endregion #region gwc - spouse to emergency case "PatientInformation_EmergencyContact_CopyFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsifapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_EmergencyContact_Relationship")).Text = "Spouce"; break; #endregion //TSP Copy Buttons case "PatientInformation_SpouseDetailsIfapplicable_CopyPatientAddress": ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_ResidentialAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Value; ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_PostalAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Value; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PatientDetails")).Update(); break; case "PatientInformation_PatientDetails_CopyResidentialToPostal": ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Value; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PatientDetails")).Update(); break; case "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_CopyAllFromPatient": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_DateofBirth")).Text; ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Gender")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_Gender")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_EmailAddress")).Text; ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_ResidentialAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_ResidentialAddress")).Value; ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_PostalAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PatientDetails_PostalAddress")).Value; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid")).Update(); break; case "PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_CopyAllFromSpouse": ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Title")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Title")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Surname")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Surname")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_FirstNames")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_FirstNames")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_IDPassportNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_IDPassportNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_DateofBirth")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_DateofBirth")).Text; ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_Gender")).SelectedIndex = ((DropDownList)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_Gender")).SelectedIndex; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_MobileNumber")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_MobileNumber")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneH")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_TelephoneH")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_TelephoneW")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_TelephoneW")).Text; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmailAddress")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_EmailAddress")).Text; ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_ResidentialAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_ResidentialAddress")).Value; ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_PostalAddress")).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_PostalAddress")).Value; ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_PersonResponsibleforAccountPaymentMainMemberofMedicalAid_EmployerName")).Text = ((TextBox)pnlSurfaceForm.FindControl("PatientInformation_SpouseDetailsIfapplicable_EmployerName")).Text; ((UpdatePanel)pnlSurfaceForm.FindControl("upPatientInformation_SpouseDetailsIfapplicable")).Update(); break; //End of TSP Copy Buttons default: break; } } /// /// event for all surface image edit clicks /// /// /// protected void surfaceImageEdit_Click(object sender, EventArgs e) { if (sender is LinkButton) { LinkButton lbSurfaceImageEdit = (LinkButton)sender; Session["surfaceImageItemId"] = lbSurfaceImageEdit.Attributes["data-id"]; Session["surfaceImageFieldId"] = lbSurfaceImageEdit.Attributes["data-fieldId"]; } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modImageUpload", "$('#modImageUpload').modal();", true); } /// /// event for all surface action button clicks /// /// /// /// protected void surfaceActionButton_Click(object sender, EventArgs e) { Button btn = (Button)sender; string btnID = btn.ID; string surfaceFieldName = btnID.Substring(3); foreach (oSurfaceField surfaceFieldDest in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", surfaceFieldName)) { string action = ((oSurfaceAction)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceAction), "recId", surfaceFieldDest.action.ToString())[0]).action; if (action == "Copy") { string controlIdDest = surfaceFieldDest.surfaceFieldName; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), surfaceFieldDest.surfaceFieldTypeId); oSurfaceField sourceField = (oSurfaceField)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", surfaceFieldDest.actionSource.ToString())[0]; if (sourceField.surfaceId != surfaceFieldDest.surfaceId && base.IsChildSurface) { //assume parent oSurfaceFieldData sourceData = (oSurfaceFieldData)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceItemId,surfaceFieldId", base.ParentSurfaceItemId.ToString() + "," + sourceField.recId.ToString())[0]; switch (typ) { case pNums.FieldType.Text: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Number: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueNum.ToString(); break; case pNums.FieldType.Decimal: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = utils.returnFormattedDecimal(Convert.ToString(sourceData.surfaceFieldValueDecimal)); break; case pNums.FieldType.Date: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = sourceData.surfaceFieldValueDate.ToString("dd/MM/yyyy"); break; case pNums.FieldType.Caption: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((HtmlTextArea)pnlSurfaceForm.FindControl(controlIdDest)).Value = sourceData.surfaceFieldValueChar; break; case pNums.FieldType.Address: int itemNo = 0; foreach (string addressLine in sourceData.surfaceFieldValueChar.Split(new string[] { "~|~" }, StringSplitOptions.None)) { itemNo++; if (itemNo == 2 && handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburb = (DropDownList)pnlSurfaceForm.FindControl(controlIdDest + itemNo + "dd"); if (ddSuburb != null) { if (ddSuburb.Items.FindByValue(addressLine.Substring(3)) != null) ddSuburb.SelectedValue = addressLine.Substring(3); } } else { TextBox txtAddress = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + itemNo); if (txtAddress != null && addressLine.Substring(1, 1) == itemNo.ToString()) { txtAddress.Text = addressLine.Substring(3); } } } break; default: break; } } else { string controlIdSource = ((oSurfaceField)xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", surfaceFieldDest.actionSource.ToString())[0]).surfaceFieldName; switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Date: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((TextBox)pnlSurfaceForm.FindControl(controlIdDest)).Text = ((TextBox)pnlSurfaceForm.FindControl(controlIdSource)).Text; break; case pNums.FieldType.Caption: if (pnlSurfaceForm.FindControl(controlIdDest) != null && pnlSurfaceForm.FindControl(controlIdDest) != null) ((HtmlTextArea)pnlSurfaceForm.FindControl(controlIdDest)).Value = ((HtmlTextArea)pnlSurfaceForm.FindControl(controlIdSource)).Value; break; case pNums.FieldType.Address: TextBox txtAddress1Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "1"); TextBox txtAddress1Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "1"); if (txtAddress1Dest != null && txtAddress1Src != null) txtAddress1Dest.Text = txtAddress1Src.Text; if (handler.ReturnSetup().code == "STUD-1") { DropDownList ddSuburbSrc = (DropDownList)pnlSurfaceForm.FindControl(controlIdSource + "2dd"); DropDownList ddSuburbDest = (DropDownList)pnlSurfaceForm.FindControl(controlIdDest + "2dd"); if (ddSuburbDest != null && ddSuburbSrc != null) ddSuburbDest.SelectedIndex = ddSuburbSrc.SelectedIndex; } else { TextBox txtAddress2Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "2"); TextBox txtAddress2Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "2"); if (txtAddress2Dest != null && txtAddress2Src != null) txtAddress2Dest.Text = txtAddress2Src.Text; } TextBox txtAddress3Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "3"); TextBox txtAddress3Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "3"); if (txtAddress3Dest != null && txtAddress3Src != null) txtAddress3Dest.Text = txtAddress3Src.Text; TextBox txtAddress4Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "4"); TextBox txtAddress4Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "4"); if (txtAddress4Dest != null && txtAddress4Src != null) txtAddress4Dest.Text = txtAddress4Src.Text; TextBox txtAddress5Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "5"); TextBox txtAddress5Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "5"); if (txtAddress5Dest != null && txtAddress5Src != null) txtAddress5Dest.Text = txtAddress5Src.Text; TextBox txtAddress6Src = (TextBox)pnlSurfaceForm.FindControl(controlIdSource + "6"); TextBox txtAddress6Dest = (TextBox)pnlSurfaceForm.FindControl(controlIdDest + "6"); if (txtAddress6Dest != null && txtAddress6Src != null) txtAddress6Dest.Text = txtAddress6Src.Text; break; default: break; } } } } } /// /// Finish Saving /// /// /// protected void btnFinish_Click(object sender, EventArgs e) { try { /* CVH 2016-09-01 Wizard no save as draft function for now */ if (PerformSave(true, false)) { //update wizard to completed base.SurfaceAppItem.isWizardCompleted = true; base.SurfaceAppItem.lastTabCompleted = 0; xData.UpdateTyped("recId", base.SurfaceAppItem.recId.ToString(), typeof(oSurfaceItem), base.SurfaceAppItem); if (utils.verifySession("user")) { oUser user = (oUser)Session["user"]; oSetup setup = handler.ReturnSetup(); if (user.userType >= (int)pNums.UserType.PowerUser || handler.ReturnSetup().code == "GLOB-1") { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; base.ActiveTabPanel = String.Empty; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); string sub = String.Empty; if (base.IsSubChildSurface) { sub = "Sub"; } else { base.ChildAppItem = null; } //RemoveSurfaceControl(sub); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); } else { TogglePanels("pnlSurfaceGrid"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } } else if (user.userType == (int)pNums.UserType.WebsiteUser && setup.code != "SHOU-1") //CVH 2016-12-01 If TSP, log out user and show modal { //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); if (base.IsSubChildSurface) { sub = "Sub"; } else { base.ChildAppItem = null; } //RemoveSurfaceControl(sub); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); } else { TogglePanels("pnlSurfaceGrid"); //TogglePanels("pnlSurfaceForm"); } } else { //log out user utils.disposeSession("user"); //display notification ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myRegModal", "$('#modCompleteReg').modal();", true); } } if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Next click /// /// /// protected void btnNext_Click(object sender, EventArgs e) { try { SetPatientType("PatientType_PatientType_PatientType"); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 /* CVH 2016-09-01 Wizard no save as draft function for now */ ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,isReadonly,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0,0," + (int)pNums.FieldType.Tab, "sequence"); if (PerformSave(false, false)) { //CVH 2016-11-01 Send all tabs to method, check for hidden there, otherwise not handled correctly when wizard tab is after hidden tabs SetNextTab(fieldTabs); SetCustomVisible(); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } else { MaintainActiveTab(fieldTabs); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Previous click /// /// /// protected void btnPrevious_Click(object sender, EventArgs e) { try { //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 //CVH 2016-11-01 Send all tabs to method, check for hidden there, otherwise not handled correctly when wizard tab is after hidden tab ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); SetPreviousTab(fieldTabs); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel wizzard button click /// /// /// protected void btnCancelWizzard_Click(object sender, EventArgs e) { try { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; base.ActiveTabPanel = String.Empty; //GR 21/12/2016 close modal if child on save if (base.IsChildSurface) { string sub = String.Empty; if (base.IsSubChildSurface) sub = "Sub"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; if (plcChildApp != null) plcChildApp.Controls.Clear(); } else { TogglePanels("pnlSurfaceGrid"); if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// MSV method /// /// /// protected void btnMediswitch_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modMediSwitchMSV", "$('#modMediSwitchMSV" + base.SurfaceApp.name + "').modal();", true); } /// /// Debtors method /// /// /// protected void btnDebtors_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } //CVH 2016-11-17 Set the Debtors button field name, used when linking notes to surface 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; } Session["noteSurfaceFieldName"] = fieldName; Session["account"] = xDebtors.SetAccountItem(itemId, base.SurfaceApp.recId, usr); Session["loadType"] = "Redirected"; //redirect to debtors Response.Redirect("/pages/enquiry", false); } } protected void btnComposite_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); string profilePage = string.Empty; foreach (oSurfaceField surfaceField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceFieldName", ((LinkButton)sender).ID)) { foreach (oCanvas canvas in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "recId", surfaceField.contentId.ToString())) { profilePage = canvas.name; } } Session["surfaceItemId"] = itemId; //redirect to composite if (profilePage != string.Empty) Response.Redirect("/pages/" + profilePage, false); } } /// /// Close button method /// /// /// protected void btnClose_Click(object sender, EventArgs e) { try { Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Called from grid field child surface to save surface data on parent /// /// /// /// protected override bool OnBubbleEvent(object source, EventArgs args) { try { CommandEventArgs e = (CommandEventArgs)args; if (e.CommandName == "SaveParentSurfaceItem") { int surfaceItemId = int.Parse(e.CommandArgument.ToString()); ArrayList itemList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", surfaceItemId.ToString()); if (itemList == null || itemList.Count <= 0) return false; oSurfaceItem surfaceItem = (oSurfaceItem)itemList[0]; SaveBubbleData(surfaceItem); int startIndex = 0; int.TryParse(txbPageNumber.Value, out startIndex); int maxLength = int.Parse(ddSurfaceEntries.SelectedValue); BindSurfaceGrid(startIndex, maxLength); base.SurfaceAppItem = surfaceItem; base.SurfaceAppItemId = surfaceItem.recId; //CVH 2016-11-17 Set the Notes button field name, used when linking notes to surface string fieldName = ""; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", base.SurfaceApp.recId + "," + (int)pNums.FieldType.Note + ",1")) { fieldName = field.surfaceFieldName; break; } /* CVH 2016-04-20 Add new note of type "Surface Item Created" */ oNote note = new oNote(); note.moduleId = (int)pNums.Module.Surface; note.typeId = (int)pNums.NoteType.SurfaceItemCreated; note.entityId = base.SurfaceAppItemId; note.title = "Surface Item Created"; note.caption = "A new surface item was created."; note.dateSaved = DateTime.Now; note.userIdSaved = surfaceItem.createdBy; note.isActive = true; note.fieldName = fieldName; note.recId = xData.SaveTyped("recId", typeof(oNote), note); //set session to indicate that changed record shouldn't be saved on next Finish click Session["newItem"] = "saved"; } return true; } catch (Exception) { return false; } } /// /// /// /// /// protected void btnSales_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { if (((LinkButton)sender).CommandArgument != "") { int itemId = int.Parse(((LinkButton)sender).CommandArgument); Session["sales"] = xSales.SetSalesContact(itemId); //redirect to debtors Response.Redirect("/pages/sales", false); } } } protected void chkToggleLayout_CheckedChanged(object sender, EventArgs e) { CheckBox chkToggleLayout = (CheckBox)sender; if (chkToggleLayout != null) EnableInlineButtons(chkToggleLayout.Checked); upSurface.Update(); } protected void lnkGridView_Click(object sender, EventArgs e) { TogglePanels("pnlSurfaceGrid"); lnkCompareView.Visible = true; lnkGridView.Visible = false; if (this.SurfaceApp.isModal) ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "hideSurfaceModal", "CloseAllModals();", true); } protected void lnkCompareView_Click(object sender, EventArgs e) { TogglePanels("pnlSurfaceCompare"); lnkCompareView.Visible = false; lnkGridView.Visible = true; if (base.SurfaceApp != null) { BindCompareDropdowns(base.SurfaceApp); } } //protected void RadioButton_FixAutoPostBack_OnPreRender(object sender, EventArgs e) //{ // RadioButton radioButton = (RadioButton)sender; // HtmlGenericControl label = (HtmlGenericControl)radioButton.Parent; // // Set onclick handler of the parent label to be the same as the radio button. // // This fixes issues caused by bootstrap javascript which adds labels. // label.Attributes.Add("onclick", // "javascript:setTimeout('__doPostBack(\\'" + // radioButton.UniqueID + "\\',\\'\\')', 0)"); //} protected void CheckBox_FixAutoPostBack_OnPreRender(object sender, EventArgs e) { CheckBox checkBox = (CheckBox)sender; Panel label = (Panel)checkBox.Parent; // Set onclick handler of the parent label to be the same as the radio button. // This fixes issues caused by bootstrap javascript which adds labels. label.Attributes.Add("onclick", "javascript:setTimeout('__doPostBack(\\'" + checkBox.UniqueID + "\\',\\'\\')', 0)"); } /// /// refresh current form /// /// /// protected void lnkRefresh_Click(object sender, EventArgs e) { PopulateSurfaceForm(base.SurfaceAppItem, false); TogglePanels("pnlSurfaceForm"); } #endregion #region child grid repeater events /// /// Item Data Bound /// /// /// protected void rptSurfaceChildGrid_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { Repeater childRepeater = (Repeater)sender; HiddenField hfChildSurfaceId = (HiddenField)childRepeater.Controls[0].Controls[0].FindControl("hfChildSurfaceId"); oUser user = handler.ReturnUser(); if (e.Item.ItemType == ListItemType.Header) { ArrayList buttonFields = xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", hfChildSurfaceId.Value.ToString()); oSurfaceGridOptions childGridOptions = (oSurfaceGridOptions)buttonFields[0]; if (e.Item.FindControl("thStatus") != null) { HtmlTableCell thStatus = (HtmlTableCell)e.Item.FindControl("thStatus"); thStatus.Visible = childGridOptions.showWizardStatus; } if (e.Item.FindControl("thEdit") != null) { HtmlTableCell thEdit = (HtmlTableCell)e.Item.FindControl("thEdit"); thEdit.Visible = childGridOptions.allowEdit && user.userType >= childGridOptions.editAccessType; } if (e.Item.FindControl("thView") != null) { HtmlTableCell thView = (HtmlTableCell)e.Item.FindControl("thView"); thView.Visible = childGridOptions.allowView && user.userType >= childGridOptions.viewAccessType; } if (e.Item.FindControl("thRemove") != null) { HtmlTableCell thRemove = (HtmlTableCell)e.Item.FindControl("thRemove"); thRemove.Visible = childGridOptions.allowRemove && user.userType >= childGridOptions.removeAccessType; } if (e.Item.FindControl("thClone") != null) { HtmlTableCell thClone = (HtmlTableCell)e.Item.FindControl("thClone"); thClone.Visible = childGridOptions.allowClone && user.userType >= childGridOptions.cloneAccessType; } } if (e.Item.ItemType == ListItemType.Footer) { ArrayList buttonFields = xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", hfChildSurfaceId.Value.ToString()); oSurfaceGridOptions childGridOptions = (oSurfaceGridOptions)buttonFields[0]; if (e.Item.FindControl("tfStatus") != null) { HtmlTableCell tfStatus = (HtmlTableCell)e.Item.FindControl("tfStatus"); tfStatus.Visible = childGridOptions.showWizardStatus; } if (e.Item.FindControl("tfEdit") != null) { HtmlTableCell tfEdit = (HtmlTableCell)e.Item.FindControl("tfEdit"); tfEdit.Visible = childGridOptions.allowEdit && user.userType >= childGridOptions.editAccessType; } if (e.Item.FindControl("tfView") != null) { HtmlTableCell tfView = (HtmlTableCell)e.Item.FindControl("tfView"); tfView.Visible = childGridOptions.allowView && user.userType >= childGridOptions.viewAccessType; } if (e.Item.FindControl("tfRemove") != null) { HtmlTableCell tfRemove = (HtmlTableCell)e.Item.FindControl("tfRemove"); tfRemove.Visible = childGridOptions.allowRemove && user.userType >= childGridOptions.removeAccessType; } if (e.Item.FindControl("tfClone") != null) { HtmlTableCell tfClone = (HtmlTableCell)e.Item.FindControl("tfClone"); tfClone.Visible = childGridOptions.allowClone && user.userType >= childGridOptions.cloneAccessType; } } if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //add any custom logic here } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void rptSurfaceChildGrid_PreRender(object sender, EventArgs e) { //Repeater rep = (Repeater)sender; //if (rep.Items.Count == 0) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(true);", true); //else // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "setNoSurfaceRecords", "setNoSurfaceRecords(false);", true); } /// /// Hide child compare view and show child grid view /// /// /// protected void btnGridViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton btnGridView = (LinkButton)sender; string panelGridVal = btnGridView.ID.Replace("btnGridViewChild_", "pnlSurfaceGrid_"); string panelCompareVal = btnGridView.ID.Replace("btnGridViewChild_", "pnlSurfaceCompare_"); if (pnlSurfaceForm.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelGridVal)).Visible = true; if (pnlSurfaceForm.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelCompareVal)).Visible = false; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Hide child grid view and show child compare view /// /// /// protected void btnCompareViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton btnCompareView = (LinkButton)sender; string panelGridVal = btnCompareView.ID.Replace("btnCompareViewChild_", "pnlSurfaceGrid_"); string panelCompareVal = btnCompareView.ID.Replace("btnCompareViewChild_", "pnlSurfaceCompare_"); if (pnlSurfaceForm.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelGridVal)).Visible = false; if (pnlSurfaceForm.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceForm.FindControl(panelCompareVal)).Visible = true; //have : btnGridViewChild_1011_XRays_XRays_XRays //get : pnlSurfaceGrid_1011_XRays_XRays_XRays and put invisible //get : pnlSurfaceCompare_1011_XRays_XRays_XRays and put visible } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Surface Item /// /// /// protected void btnNewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int surfaceId = 0; LinkButton newChild = (LinkButton)sender; //CVH 2017-01-11 Find the full string that needs to be replaced e.g. "btnNewChild_Form", not just "Form", otherwise it processes incorrectly when the surface name contains "Form", like "Application Form" for SBF string childVal; if (newChild.ID.Contains("btnNewChild_Compare")) childVal = newChild.ID.Replace("btnNewChild_Compare", ""); else if (newChild.ID.Contains("btnNewChild_Form")) childVal = newChild.ID.Replace("btnNewChild_Form", ""); else childVal = newChild.ID.Replace("btnNewChild_", ""); childVal = childVal.Remove(childVal.IndexOf("_")); int.TryParse(childVal, out surfaceId); if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false)) return; } if (surfaceId > 0) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", surfaceId.ToString())) { //load the surface app control oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surfaceId; if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".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 = true; //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 = true; //upChildApp.Update(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppNew", "$('#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 + 0; uc.SurfaceApp = gridSurface; uc.ParentSurfaceItemId = base.SurfaceAppItemId; uc.ParentSurfaceId = base.SurfaceApp.recId; uc.SurfaceAppItem = item; uc.SurfaceAppItemId = item.recId; uc.IsChildSurface = true; Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); if (pnlSurfaceFieldModal != null) pnlSurfaceFieldModal.Visible = false; string sub = String.Empty; 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 = true; uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew); upChildApp.Update(); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Surface Item /// /// /// protected void lnkViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".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 = true; //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 = true; //base.ChildIsNew = false; //upChildApp.Update(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppView", "$('#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 = true; 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); } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Child item from compare /// /// /// protected void lnkEditCompareChild_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkEdit", "ddlCompare"); if (pnlSurfaceView.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceView.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditChild(listSurfaceItemId); } } /// /// Edit Surface Item /// /// /// protected void lnkEditChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { //CVH 2017-02-01 //RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent; RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent.Parent; EditChild(itemId, rptItem); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Child Item /// /// /// private void EditChild(int itemId, RepeaterItem rptItem = null, bool isClone = false) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { pNums.SurfaceGridEditType editType = (pNums.SurfaceGridEditType)Enum.ToObject(typeof(pNums.SurfaceGridEditType), opt.surfaceGridEditTypeId); switch (editType) { case pNums.SurfaceGridEditType.Form: foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + ".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.IsClone = isClone; 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; base.ChildIsClone = isClone; uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); upChildApp.Update(); } ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').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; } } } } /// /// Clone Child item from compare /// /// /// protected void lnkCloneCompareChild_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkClone", "ddlCompare"); if (pnlSurfaceView.FindControl(ddlID) != null) { DropDownList ddl = (DropDownList)pnlSurfaceView.FindControl(ddlID); int listSurfaceItemId = Convert.ToInt32(ddl.SelectedValue); //surfaceItemId EditChild(listSurfaceItemId, null, true); } } /// /// Clone Surface Item /// /// /// protected void lnkCloneChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { RepeaterItem rptItem = (RepeaterItem)((LinkButton)sender).Parent; EditChild(itemId, rptItem, true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove a surface item /// /// /// protected void lnkRemoveChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { /* CVH 2016-09-19 Don't delete surface items, set item isDeleted = true */ int itemId = int.Parse(((LinkButton)sender).CommandArgument); foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item.isDeleted = true; if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { //Bind Child Grid BindChildGrid(item.surfaceId); pnlResult.Visible = true; lblResult.Text = "the selected item was deleted successfully."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Row click /// /// /// protected void lnkSaveRowChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent.Parent; oSurfaceItem item = new oSurfaceItem(); int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem surfItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item = surfItem; break; } foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { if (opt.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { SaveSurfaceGrid((Repeater)rptItem.Parent, item.surfaceId); } else { ArrayList surfaceDataList = new ArrayList(); SaveSurfaceRow(ref item, ref surfaceDataList, rptItem); if (xData.UpdateTyped("recId", item.recId.ToString(), typeof(oSurfaceItem), item)) { xData.UpdateTypedCollection("recId", typeof(oSurfaceFieldData), surfaceDataList); ToggleRowEdit(item.recId, item, false, rptItem); } } //Bind child Grid BindChildGrid(item.surfaceId); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel Event for the row /// /// /// protected void lnkCancelChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { oSurfaceItem item = new oSurfaceItem(); int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem surfItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { item = surfItem; break; } foreach (oSurfaceGridOptions opt in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", item.surfaceId.ToString())) { if (opt.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { //Bind Child Grid BindChildGrid(item.surfaceId); } else { LinkButton lnkButton = (LinkButton)sender; RepeaterItem rptItem = (RepeaterItem)lnkButton.Parent; ArrayList surfaceDataList = new ArrayList(); if (item.recId > 0) { ToggleRowEdit(item.recId, item, false, rptItem); } } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region note and file handling /// /// Notes event from the grid /// /// /// protected void btnNotes_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { //setup notes oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); int itemId = 0, fieldId = 0; string lnkNote = "lnkNote_"; if (sender.GetType() == typeof(LinkButton)) { int.TryParse(((LinkButton)sender).CommandArgument, out itemId); int.TryParse(((LinkButton)sender).ID.Substring(lnkNote.Length), out fieldId); } if (itemId == 0) { if (base.SurfaceAppItemId > 0) itemId = base.SurfaceAppItemId; } if (controlFieldData.surfaceFieldID == 0) //set default values if populating blank form { controlFieldData.surfaceFieldID = fieldId; controlFieldData.surfaceItemId = itemId; controlFieldData.surfaceId = base.SurfaceApp.recId; } if (itemId > 0) { dynamic moduleControl = this.FindControl("notes"); if (moduleControl != null) { moduleControl.ReloadControl(controlFieldData); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNotesModal", "$('#modNotes" + base.SurfaceApp.name + "').modal();", true); } //Session["noteModuleId"] = (int)pNums.Module.Surface; //Session["noteEntityId"] = itemId; //Session["fieldNameNote"] = fieldName; //IControlBase notes = (IControlBase)this.FindControl("notes"); //notes.ReloadControl(); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNotesModal", "$('#modNotes" + base.SurfaceApp.name + "').modal();", true); } } } /// /// Atatchments event from Grid /// /// /// protected void btnAttachments_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { //setup attachments int itemId = 0; string fieldName = String.Empty; if (sender.GetType() == typeof(LinkButton)) { int.TryParse(((LinkButton)sender).CommandArgument, out itemId); fieldName = ((LinkButton)sender).ID; } if (itemId == 0) { if (base.SurfaceAppItemId > 0) itemId = base.SurfaceAppItemId; } if (itemId > 0) { Session["moduleId"] = (int)pNums.Module.Surface; Session["entityId"] = itemId; Session["fieldNameFile"] = fieldName; IControlBase files = (IControlBase)this.FindControl("files"); files.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myModalFiles", "$('#modFiles" + base.SurfaceApp.name + "').modal();", true); } } } /// /// Bind surface notes /// /// private void BindSurfaceNotes(int itemId, bool isView) { try { ArrayList noteFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Note, "sequence"); foreach (oSurfaceField field in noteFields) { if (!isView) { HtmlGenericControl genericNoteDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "fNotes"); if (genericNoteDiv != null) BindNotes(itemId, genericNoteDiv); } else { HtmlGenericControl genericNoteDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "vNotes"); if (genericNoteDiv != null) BindNotes(itemId, genericNoteDiv); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind surface notes /// /// private void BindSurfaceAttachments(int itemId, bool isView) { try { ArrayList attchmentFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", base.SurfaceApp.recId + ",1," + (int)pNums.FieldType.Attachment, "sequence"); foreach (oSurfaceField field in attchmentFields) { if (!isView) { HtmlGenericControl genericAttachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "fAttachments"); if (genericAttachDiv != null) BindAttachments(itemId, genericAttachDiv, field.surfaceFieldName); } else { HtmlGenericControl genericAttachDiv = (HtmlGenericControl)pnlSurfaceForm.FindControl(field.surfaceFieldName + "vAttachments"); if (genericAttachDiv != null) BindAttachments(itemId, genericAttachDiv, field.surfaceFieldName); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Get file type image /// /// /// private string GetFileTypeImage(string fileLocation) { string imgSrc = "/images/doc.png"; try { //string uri = String.Empty; //if (fileLocation.Contains("http")) // uri = fileLocation; //else // uri = Server.MapPath("~" + fileLocation); System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(fileLocation); if (icon != null) { System.Drawing.Image img = icon.ToBitmap(); byte[] byteArray = new byte[0]; using (System.IO.MemoryStream stream = new System.IO.MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); } string base64 = Convert.ToBase64String(byteArray); imgSrc = String.Format("data:image/png;base64,{0}", base64); } } catch { //do nothing if it fails } return imgSrc; } /// /// Bind Attachments /// /// /// private void BindAttachments(int itemId, HtmlGenericControl parentControl, string fieldName) { try { oSetup _setup = handler.ReturnSetup(); System.Text.StringBuilder formbuilder = new System.Text.StringBuilder(); //CVH 2017-01-17 Calling this method for attachment as Label also // fieldName = parentControl.ID.Replace("LabelfAttachments", ""); //else // fieldName = parentControl.ID.Replace("fAttachments", "").Replace("vAttachments", ""); ArrayList files = xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId,fieldName", (int)pNums.Module.Surface + "," + itemId.ToString() + "," + fieldName, "dateSaved DESC"); if (files.Count > 0) { formbuilder.AppendLine("
"); //get all attachments linked to this event foreach (oAttachment att in files) { string user = ""; foreach (ovUserShared usr in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", att.userIdSaved.ToString())) { user = usr.name; break; } string details = "(" + user + " - " + utils.fixDate(att.dateSaved) + ")"; string fileLocation = ""; string pathLocation = ""; string hyperlink = ""; if (att.typeId == (int)pNums.AttachmentType.Document) { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/file/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/file/" + att.fileName; if (!File.Exists(fileLocation)) { fileLocation = fileLocation.Replace("/file", ""); pathLocation = pathLocation.Replace("/file", ""); } hyperlink = "" + att.display + ""; } else { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/image/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/image/" + att.fileName; hyperlink = "" + att.display + ""; } formbuilder.AppendLine(hyperlink); } formbuilder.AppendLine("
"); } parentControl.InnerHtml = formbuilder.ToString(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Notes /// /// /// private void BindNotes(int itemId, HtmlGenericControl parentControl) { try { parentControl.InnerHtml = ""; ArrayList surfNotes = new ArrayList(); //CVH 2017-01-17 Calling this method for attachment as Label also string fieldName = ""; if (parentControl.ID.IndexOf("LabelfNotes") > 0) fieldName = parentControl.ID.Replace("LabelfNotes", ""); else fieldName = parentControl.ID.Replace("fNotes", "").Replace("vNotes", ""); //get list of all notes linked to this history item foreach (oNote note in xData.GetTypedByCriteriaSpecific("recId", typeof(oNote), "moduleId,entityId,typeId", (int)pNums.Module.Surface + "," + itemId.ToString() + "," + (int)pNums.NoteType.General, "")) { surfNotes.Add(note); } //order notes by date if (surfNotes == null || surfNotes.Count <= 0) return; var notes = surfNotes.OfType().OrderByDescending(n => n.dateSaved).ToArray(); System.Text.StringBuilder formBuilder = new System.Text.StringBuilder(); bool firstNote = true; //loop through notes, get attachment linked to note, and add to form foreach (oNote noteAdd in notes) { //start of group formBuilder.Append("
"); //heading formBuilder.AppendLine("
"); formBuilder.AppendLine(noteAdd.title); formBuilder.AppendLine(""); formBuilder.AppendLine(""); formBuilder.AppendLine(""); formBuilder.AppendLine("
"); //end of heading //toggle panel if (firstNote) { formBuilder.AppendLine("
"); firstNote = false; } else { formBuilder.AppendLine("
"); } //build body of formBuilder.AppendLine("
"); //build horizontal form formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); //row formBuilder.AppendLine("
"); if (noteAdd.customValue != string.Empty) { formBuilder.AppendLine("
"); foreach (oNoteType noteType in xData.GetTypedByCriteriaSpecific("recId", typeof(oNoteType), "recId", noteAdd.typeId.ToString())) { formBuilder.AppendLine("" + noteType.customItem + ": "); } formBuilder.AppendLine(noteAdd.customValue + "
"); } formBuilder.AppendLine("
" + noteAdd.caption + "
"); //get all attachments linked to note ArrayList files = xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId", (int)pNums.Module.Notes + "," + noteAdd.recId.ToString(), ""); if (files.Count > 0) { formBuilder.AppendLine("
"); foreach (oAttachment att in files) { string user = ""; foreach (ovUserShared usr in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", att.userIdSaved.ToString())) { user = usr.name; break; } string details = "(" + user + " - " + utils.fixDate(att.dateSaved) + ")"; string fileLocation = ""; string pathLocation = ""; string hyperlink = ""; if (att.typeId == (int)pNums.AttachmentType.Document) { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/file/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/file/" + att.fileName; if (!File.Exists(fileLocation)) { fileLocation = fileLocation.Replace("/file", ""); pathLocation = pathLocation.Replace("/file", ""); } hyperlink = "" + att.display + ""; } else { fileLocation = Server.MapPath("~/upload/" + att.folderName + "/image/" + att.fileName); pathLocation = att.sourcePath + "/upload/" + att.folderName + "/image/" + att.fileName; hyperlink = "" + att.display + ""; } formBuilder.AppendLine(hyperlink); } formBuilder.AppendLine("
"); } formBuilder.AppendLine("
"); //end of row //end of horizontal formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); formBuilder.AppendLine("
"); //end of body formBuilder.AppendLine("
"); //end toggle panel formBuilder.AppendLine("
"); //end of group } parentControl.InnerHtml = formBuilder.ToString(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Attachments /// /// /// protected void btnfAddFile_Click(object sender, EventArgs e) { string fieldName = ((LinkButton)sender).ID; hfFieldNameFile.Value = fieldName; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", "$('#modAddFile" + base.SurfaceApp.name + "').on('shown', function () {$(\"#scrtop" + base.SurfaceApp.name + "\").scrollTop(0);});", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModal", "$('#modAddFile" + base.SurfaceApp.name + "').modal();", true); upAddFile.Update(); } /// /// Add notes /// /// /// protected void btnfAddNotes_Click(object sender, EventArgs e) { lblNoteTypeCustom.Text = string.Empty; divNoteCustom.Visible = false; radNewNote.Content = ""; string fieldName = ((LinkButton)sender).ID; hfFieldNameNote.Value = fieldName; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalScroll", "$('#modAddNote" + base.SurfaceApp.name + "').on('shown', function () {$(\"#scrtop" + base.SurfaceApp.name + "\").scrollTop(0);});", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModal", "$('#modAddNote" + base.SurfaceApp.name + "').modal();", true); upAddNote.Update(); } /// /// File Uploaded /// /// /// protected void radUpload_FileUploaded(object sender, FileUploadedEventArgs e) { oAttachment Attachment = new oAttachment(); try { oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userAlert", "alert('No user login detected. Operation aborted.');", true); return; } if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false)) return; } int itemId = base.SurfaceAppItemId; Attachment.entityId = itemId; Attachment.fieldName = hfFieldNameFile.Value; Attachment.moduleId = (int)pNums.Module.Surface; Attachment.isActive = true; Attachment.typeId = e.File.ContentType.StartsWith("image") ? (int)pNums.AttachmentType.Image : (int)pNums.AttachmentType.Document; string surfFolderName = "surface/"; surfFolderName += itemId.ToString(); Attachment.folderName = surfFolderName; /* CVH 2016-04-15 Add date and user */ int userId = usr.recId; if (Attachment.recId > 0) { Attachment.userIdUpdated = userId; Attachment.dateUpdated = System.DateTime.Now; } else { Attachment.userIdSaved = userId; Attachment.dateSaved = System.DateTime.Now; } Attachment.display = e.File.FileName.Remove(e.File.FileName.LastIndexOf(".")); Attachment.fileName = Attachment.entityId + "_" + utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string imagePath = Server.MapPath("~/upload/" + Attachment.folderName + "/image/"); string thumbPath = Server.MapPath("~/upload/" + Attachment.folderName + "/thumb/"); string tempPath = Server.MapPath("~/upload/" + Attachment.folderName + "/temp/"); string filePath = Server.MapPath("~/upload/" + Attachment.folderName + "/file/"); utils.validateFolder(imagePath); utils.validateFolder(thumbPath); utils.validateFolder(tempPath); utils.validateFolder(filePath); Attachment.sourcePath = ConfigurationManager.AppSettings["WebAddy"]; if (Attachment.typeId == (int)pNums.AttachmentType.Image) { //upload file e.File.SaveAs(tempPath + Attachment.fileName); //resize and crop for thumbnail utils.ResizeCropImagePrecise(tempPath + Attachment.fileName, thumbPath, Attachment.fileName, 383, 264, false); //resize image for a larger size utils.ResizeImage(tempPath + Attachment.fileName, imagePath, Attachment.fileName, 400, true, true); } else { //upload file e.File.SaveAs(filePath + Attachment.fileName); } if (Attachment.recId > 0) { xData.UpdateTyped("recId", Attachment.recId.ToString(), typeof(oAttachment), Attachment); utils.disposeSession("Attachment"); } else { Attachment.recId = xData.SaveTyped("recId", typeof(oAttachment), Attachment); if (Attachment.recId > 0) { } } } catch (Exception ex) { exception.HandleException("Attachments:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } /// /// Close File Modal /// /// /// protected void btnCloseFileModal_Click(object sender, EventArgs e) { //to do find all controls that are notes / attachments and bind if (base.SurfaceAppItemId != 0) { //BindSurfaceNotes(base.SurfaceAppItemId); BindSurfaceAttachments(base.SurfaceAppItemId, pnlSurfaceView.Visible); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceFileRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); } //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfFileModalClose", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } /// /// File Notes uploaded /// /// /// protected void radUploadNotes_FileUploaded(object sender, FileUploadedEventArgs e) { oAttachment Attachment = new oAttachment(); try { oUser user = new oUser(); if (utils.verifySession("user")) user = (oUser)Session["user"]; else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userAlert", "alert('No user login detected. Operation aborted.');", true); return; } oNote note = new oNote(); if (ViewState["newNote"] == null) { if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false)) return; } int itemId = base.SurfaceAppItemId; //save new note to link attachment to note.caption = radNewNote.Content; note.dateSaved = System.DateTime.Now; note.entityId = itemId; note.fieldName = hfFieldNameNote.Value; note.isActive = true; note.moduleId = (int)pNums.Module.Surface; note.title = user.name + " (" + utils.fixDate(System.DateTime.Now) + ")"; note.typeId = (int)pNums.NoteType.General; note.userIdSaved = user.recId; if (ddNoteCustom.SelectedItem != null) note.customValue = ddNoteCustom.SelectedItem.Text; note.recId = xData.SaveTyped("recId", typeof(oNote), note); ViewState["newNote"] = note; } else { note = (oNote)ViewState["newNote"]; } Attachment.entityId = note.recId; Attachment.fieldName = hfFieldNameNote.Value; Attachment.moduleId = (int)pNums.Module.Notes; Attachment.isActive = true; Attachment.typeId = e.File.ContentType.StartsWith("image") ? (int)pNums.AttachmentType.Image : (int)pNums.AttachmentType.Document; string taskFolderName = "surface/"; taskFolderName += this.SurfaceAppItem.recId.ToString(); Attachment.folderName = taskFolderName; /* CVH 2016-04-15 Add date and user */ int userId = user.recId; if (Attachment.recId > 0) { Attachment.userIdUpdated = userId; Attachment.dateUpdated = System.DateTime.Now; } else { Attachment.userIdSaved = userId; Attachment.dateSaved = System.DateTime.Now; } Attachment.display = e.File.FileName.Remove(e.File.FileName.LastIndexOf(".")); Attachment.fileName = Attachment.entityId + "_" + utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string imagePath = Server.MapPath("~/upload/" + Attachment.folderName + "/image/"); string thumbPath = Server.MapPath("~/upload/" + Attachment.folderName + "/thumb/"); string tempPath = Server.MapPath("~/upload/" + Attachment.folderName + "/temp/"); string filePath = Server.MapPath("~/upload/" + Attachment.folderName + "/file/"); utils.validateFolder(imagePath); utils.validateFolder(thumbPath); utils.validateFolder(tempPath); utils.validateFolder(filePath); Attachment.sourcePath = ConfigurationManager.AppSettings["WebAddy"]; if (Attachment.typeId == (int)pNums.AttachmentType.Image) { //upload file e.File.SaveAs(tempPath + Attachment.fileName); //resize and compress utils.ResizeImage(tempPath + Attachment.fileName, imagePath, Attachment.fileName, 400, true); //resize and crop utils.ResizeCropImagePrecise(imagePath + Attachment.fileName, thumbPath, Attachment.fileName, 383, 264, false); } else { //upload file e.File.SaveAs(filePath + Attachment.fileName); } if (Attachment.recId > 0) { xData.UpdateTyped("recId", Attachment.recId.ToString(), typeof(oAttachment), Attachment); utils.disposeSession("Attachment"); } else { Attachment.recId = xData.SaveTyped("recId", typeof(oAttachment), Attachment); if (Attachment.recId > 0) { } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } /// /// Cancel Click /// /// /// protected void btnCancelNote_Click(object sender, EventArgs e) { //to do find all controls that are notes / attachments and bind if (base.SurfaceAppItemId != 0) { BindSurfaceNotes(base.SurfaceAppItemId, pnlSurfaceView.Visible); //BindSurfaceAttachments(base.SurfaceAppItemId); } //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalClose", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } /// /// Save the surface note /// /// /// protected void btnSaveNote_Click(object sender, EventArgs e) { try { oUser user = new oUser(); if (utils.verifySession("user")) { user = (oUser)Session["user"]; } else { Response.Redirect("/home", false); return; //throw new Exception("Logged on user could not be determined."); } //if viewstate is null, no attachment has been linked to this note, and the note hasn't been saved yet, save it now if (ViewState["newNote"] == null) { if (base.SurfaceAppItemId == 0) { if (!PerformSave(false, false)) return; } int itemId = base.SurfaceAppItemId; oNote note = new oNote(); note.caption = radNewNote.Content; note.dateSaved = System.DateTime.Now; note.entityId = itemId; note.isActive = true; note.moduleId = (int)pNums.Module.Surface; note.title = user.name + " (" + utils.fixDate(System.DateTime.Now) + ")"; note.fieldName = hfFieldNameNote.Value; note.typeId = (int)pNums.NoteType.General; note.userIdSaved = user.recId; note.recId = xData.SaveTyped("recId", typeof(oNote), note); } else ViewState["newNote"] = null; BindSurfaceNotes(base.SurfaceAppItemId, pnlSurfaceView.Visible); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceFileRefresh", "forcePostBack('" + pnlSurfaceForm.ClientID + "');", true); //BindSurfaceAttachments(base.SurfaceAppItemId,pnlSurfaceView.Visible); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myfNoteModalSave", "$('.modal-backdrop').remove(); $('body').removeClass('modal-open');", true); } catch (Exception ex) { exception.HandleException("Attachments:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } #endregion #region surface field methods /// /// Enable inline buttons /// private void EnableInlineButtons(bool show = true) { try { if (base.SurfaceApp != null) { btnNewField.Visible = show; btnManagePicklists.Visible = show; btnGrid.Visible = show; //lblPipe.Visible = show; lblPipe1.Visible = show; lblPipe2.Visible = show; btnLookCat.Visible = show; //lblPipe3.Visible = true; //btnSavePositions.Visible = true; ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", base.SurfaceApp.recId + ",1", "sequence", "pal_"); foreach (oSurfaceField field in surfaceFields) { LinkButton lnkEdit = (LinkButton)pnlSurfaceForm.FindControl("lnkInEd" + field.surfaceFieldName); if (lnkEdit != null) lnkEdit.Visible = show; LinkButton lnkAdd = (LinkButton)pnlSurfaceForm.FindControl("lnkInAd" + field.surfaceFieldName); if (lnkAdd != null) lnkAdd.Visible = show; LinkButton lnkRemove = (LinkButton)pnlSurfaceForm.FindControl("lnkInDel" + field.surfaceFieldName); if (lnkRemove != null) lnkRemove.Visible = show; HtmlAnchor anchor = (HtmlAnchor)pnlSurfaceForm.FindControl("lnkInMove" + field.surfaceFieldName); if (anchor != null) anchor.Visible = show; Panel panelInline = (Panel)pnlSurfaceForm.FindControl("pnlInline" + field.surfaceFieldName); if (panelInline != null) panelInline.Visible = show; } Session["InlineApp"] = base.SurfaceApp; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save field positions /// private void SaveFieldPositions() { try { if (base.SurfaceApp != null) { int surfaceId = base.SurfaceApp.recId; //first save navs int tabCounter = 0; int groupcounter = 0; int controlCounter = 0; ArrayList surfaceFieldList = new ArrayList(); //enumerate through each control foreach (Control ctl in pnlSurfaceForm.Controls) { if (ctl.ID != null) { ArrayList FieldList = new ArrayList(); string fieldName = String.Empty; int sequence = 0; if (ctl.ID.StartsWith("li_f"))//tab { tabCounter++; fieldName = ctl.ID.Replace("li_f", ""); sequence = tabCounter; } else if (ctl.ID.StartsWith("divf"))//group { groupcounter++; fieldName = ctl.ID.Replace("divf", ""); sequence = groupcounter; } else//control { if (!ctl.ID.StartsWith("val") && !ctl.ID.StartsWith("lnk") && !ctl.ID.StartsWith("up") && !ctl.ID.StartsWith("req") && !ctl.ID.StartsWith("pnl") && !ctl.ID.StartsWith("lbl")) { controlCounter++; fieldName = ctl.ID; sequence = controlCounter; } } if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //set new sequence field.sequence = sequence; //appedn to field list for update surfaceFieldList.Add(field); break; } } } } if (surfaceFieldList.Count > 0) { if (xData.UpdateTypedCollection("recId", typeof(oSurfaceField), surfaceFieldList)) { pnlResult.Visible = true; lblResult.Text = "Layout was saved successfully."; upSurface.Update(); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindFieldTypes() { try { DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldType), "isActive", "1", "recId"); ddFieldTypes.DataSource = typeData; ddFieldTypes.DataTextField = "surfaceFieldType"; ddFieldTypes.DataValueField = "recId"; ddFieldTypes.DataBind(); ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Parent Fields /// private void BindParentFields() { oSurface surface = new oSurface(); try { if (base.SurfaceApp != null) { surface = base.SurfaceApp; int fieldTypeId = 2;//default to group if (int.Parse(ddFieldTypes.SelectedValue) == (int)pNums.FieldType.Group) fieldTypeId = 1; DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", surface.recId + "," + fieldTypeId, "sequence"); ddParentFields.DataSource = typeData; ddParentFields.DataTextField = "surfaceFieldDisplay"; ddParentFields.DataValueField = "recId"; ddParentFields.DataBind(); //CVH 2017-02-14 Add subtab functionality. If selected field is Tab, allow it to be linked to a group parent ddParentFields.Items.Insert(0, new ListItem("None", "0")); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindLookupCategories() { try { DataTable lookData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookupCategory), "isActive", "1", "lookupCategory"); ddLookupCategory.DataSource = lookData; ddLookupCategory.DataValueField = "recId"; ddLookupCategory.DataTextField = "lookupCategory"; ddLookupCategory.DataBind(); ddLookupCategory.Items.Insert(0, new ListItem("select...", "0")); DataTable moduleLookupData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "isActive,isPicklist", "1,1", "module"); foreach (DataRow row in moduleLookupData.Rows) { ddModuleLookup.Items.Add(new ListItem(row["module"].ToString(), row["objectName"].ToString())); } ddModuleLookup.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Action Types /// private void BindActionTypes() { try { DataTable actionTypeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceActionType), "isActive", "1", "recId"); ddActionTypes.DataSource = actionTypeData; ddActionTypes.DataTextField = "actionType"; ddActionTypes.DataValueField = "recId"; ddActionTypes.DataBind(); ddActionTypes.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Actions from Action Type /// /// private void BindActions(string actionTypeId) { try { DataTable actionData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceAction), "isActive,actionType", "1," + actionTypeId, "recId"); ddActions.DataSource = actionData; ddActions.DataTextField = "action"; ddActions.DataValueField = "recId"; ddActions.DataBind(); ddActions.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Action Source from Action /// /// private void BindActionSource(string fieldTypeIds) { try { DataTable actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceFieldTypeId", "1,~()" + fieldTypeIds, "recId"); ddActionSource.DataSource = actionSourceData; ddActionSource.DataTextField = "surfaceFieldDisplay"; ddActionSource.DataValueField = "recId"; ddActionSource.DataBind(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Method to Bind the slide Order Drop down /// private void BindSequence() { try { for (int i = 0; i < 50; i++) { //append sequence item ddSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulateFieldFormValues(ref oSurfaceField _SurfaceField) { try { chkActiveField.Checked = _SurfaceField.isActive; chkGridActive.Checked = _SurfaceField.isGrid; chkFilter.Checked = _SurfaceField.isFilter; chkRequired.Checked = _SurfaceField.required; chkIsAutoPostback.Checked = _SurfaceField.isAutoPostback; chkHiddenField.Checked = _SurfaceField.isHidden; chkHiddenWizzard.Checked = _SurfaceField.isHiddenFromWizzard; chkReadOnlyField.Checked = _SurfaceField.isReadOnly; //JR Bas-Pro-3 chkUnique.Checked = _SurfaceField.isUnique; txtLength.Value = _SurfaceField.length.ToString(); txtDisplay.Value = _SurfaceField.surfaceFieldDisplay; txtPlaceholder.Value = _SurfaceField.placeholder; if (ddFieldTypes.Items.FindByValue(_SurfaceField.surfaceFieldTypeId.ToString()) != null) ddFieldTypes.SelectedValue = _SurfaceField.surfaceFieldTypeId.ToString(); BindParentFields(); if (_SurfaceField.sequence > 0) ddSequence.SelectedItem.Text = _SurfaceField.sequence.ToString(); if (ddLookupCategory.Items.FindByValue(_SurfaceField.lookupCategory.ToString()) != null) ddLookupCategory.SelectedValue = _SurfaceField.lookupCategory.ToString(); if (_SurfaceField.relationalObject.ToString().Length > 0 && ddModuleLookup.Items.FindByValue(_SurfaceField.relationalObject.ToString()) != null) ddModuleLookup.SelectedValue = _SurfaceField.relationalObject.ToString(); if (_SurfaceField.parentId > 0) ddParentFields.SelectedValue = _SurfaceField.parentId.ToString(); /* Rev 001 Select surface app if field is Grid Type * Charlene van Heerden * 7 January 2016 */ /* CVH 2016-01-22 RelField */ if (ddSurfaceApps.Items.FindByValue(_SurfaceField.relationalSurface) != null) { if (ddSurfaceApps.Items.FindByValue(_SurfaceField.relationalSurface) != null) ddSurfaceApps.SelectedValue = _SurfaceField.relationalSurface; BindSurfaceAppFields(_SurfaceField.relationalSurface); } else { ddSurfaceApps.SelectedValue = "0"; } /* CVH 2016-01-22 RelField */ if (ddSurfaceAppFields.Items.FindByValue(_SurfaceField.relationalFields) != null) ddSurfaceAppFields.SelectedValue = _SurfaceField.relationalFields; else ddSurfaceAppFields.SelectedValue = "0"; if (_SurfaceField.contentId != 0) { if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) ddContent.SelectedValue = _SurfaceField.contentId.ToString(); if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) ddComposite.SelectedValue = _SurfaceField.contentId.ToString(); } chkIsControlled.Checked = _SurfaceField.isControlled; if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; txtControlledValue.Value = _SurfaceField.controlledValue; txtControlText.Value = _SurfaceField.controlText; if (ddActionTypes.Items.FindByValue(_SurfaceField.actionType.ToString()) != null) { ddActionTypes.SelectedValue = _SurfaceField.actionType.ToString(); BindActions(_SurfaceField.action.ToString()); actionGroup.Visible = true; if (ddActions.Items.FindByValue(_SurfaceField.action.ToString()) != null) { ddActions.SelectedValue = _SurfaceField.action.ToString(); string action = ddActions.SelectedItem.Text; switch (action) { case "VAT": BindActionSource(pNums.FieldType.Decimal.ToString()); break; case "Age": BindActionSource(pNums.FieldType.Date.ToString() + "|" + ((int)pNums.FieldType.Text).ToString()); break; case "Gender": BindActionSource(pNums.FieldType.Text.ToString()); break; default: break; case "Copy": string destType = ddFieldTypes.SelectedValue; BindActionSource(destType); break; } actionSourceGroup.Visible = true; if (ddActionSource.Items.FindByValue(_SurfaceField.actionSource.ToString()) != null) { ddActionSource.SelectedValue = _SurfaceField.actionSource.ToString(); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// /// /// REVISION 001: When field type is grid, add surface app name as relationalSurface /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// private void SaveFieldFormValues(ref oSurfaceField _SurfaceField) { try { _SurfaceField.isActive = chkActiveField.Checked; _SurfaceField.isFilter = chkFilter.Checked; _SurfaceField.isGrid = chkGridActive.Checked; _SurfaceField.required = chkRequired.Checked; _SurfaceField.isAutoPostback = chkIsAutoPostback.Checked; _SurfaceField.isHidden = chkHiddenField.Checked; _SurfaceField.isHiddenFromWizzard = chkHiddenWizzard.Checked; _SurfaceField.isReadOnly = chkReadOnlyField.Checked; //JR Bas-Pro-3 _SurfaceField.isUnique = chkUnique.Checked; int length = 0; int.TryParse(txtLength.Value, out length); _SurfaceField.length = length; int parent = 0; int.TryParse(ddParentFields.SelectedValue, out parent); _SurfaceField.parentId = parent; int seq = 0; int.TryParse(ddSequence.SelectedItem.Text, out seq); _SurfaceField.sequence = seq; _SurfaceField.surfaceFieldDisplay = txtDisplay.Value; _SurfaceField.placeholder = txtPlaceholder.Value; int fieldType = 0; int.TryParse(ddFieldTypes.SelectedValue, out fieldType); _SurfaceField.surfaceFieldTypeId = fieldType; if (ddFieldTypes.SelectedValue != ((int)pNums.FieldType.Tab).ToString() && ddFieldTypes.SelectedValue != ((int)pNums.FieldType.HeaderGroup).ToString()) { if (ddFieldTypes.SelectedValue != ((int)pNums.FieldType.Group).ToString()) { int groupId = 0; string tabName = String.Empty; if (ddParentFields.SelectedValue != null) { groupId = int.Parse(ddParentFields.SelectedValue); foreach (oSurfaceField grp in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", groupId.ToString())) { foreach (oSurfaceField tab in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", grp.parentId.ToString())) { tabName = tab.surfaceFieldDisplay; } } } _SurfaceField.surfaceFieldName = utils.stripCharacters(tabName).Replace(" ", "") + "_" + utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } else { _SurfaceField.surfaceFieldName = utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } } else { _SurfaceField.surfaceFieldName = utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } _SurfaceField.lookupCategory = int.Parse(ddLookupCategory.SelectedValue); if (ddModuleLookup.SelectedIndex > 0) { _SurfaceField.relationalObject = ddModuleLookup.SelectedValue; } /* Rev 001 Add relationalSurface if Grid type selected * Charlene van Heerden * 10 December 2015 */ string relationalSurface = ""; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField) relationalSurface = ddSurfaceApps.SelectedValue; _SurfaceField.relationalSurface = relationalSurface; /* CVH 2016-01-22 RelField */ _SurfaceField.relationalFields = ddSurfaceAppFields.SelectedValue; /*JasR 2016-01-13*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) { int contentID = 0; int.TryParse(ddContent.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } /*JasR 2016-01-15*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { _SurfaceField.defaultToCurrent = chkDefaultCurrent.Checked; } /*JasR 2016-01-15*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Number) { _SurfaceField.isControlled = chkIsControlled.Checked; _SurfaceField.controlledValue = txtControlledValue.Value; } /*JasR 2016-01-16*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Button || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Checkbox || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Mediswitch) { _SurfaceField.controlText = txtControlText.Value; } if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) { int contentID = 0; int.TryParse(ddComposite.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } if (ddActionSource.SelectedValue != null && ddActionSource.SelectedValue != String.Empty) _SurfaceField.actionSource = Convert.ToInt32(ddActionSource.SelectedValue); if (ddActions.SelectedValue != null && ddActions.SelectedValue != String.Empty) _SurfaceField.action = Convert.ToInt32(ddActions.SelectedValue); if (ddActionTypes.SelectedValue != null && ddActionTypes.SelectedValue != String.Empty) _SurfaceField.actionType = Convert.ToInt32(ddActionTypes.SelectedValue); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Toggle Field Types /// /// /// REVISION 001: Add Grid field type /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// private void ToggleFieldTypes() { try { //set default views lookupGroup.Visible = false; moduleLookupGroup.Visible = false; validationGroup.Visible = true; lengthGroup.Visible = true; /* Rev 001 Hide Surface App * Charlene van Heerden * 10 December 2015 */ surfaceApp.Visible = false; /* CVH 2016-01-22 RelField */ surfaceAppFields.Visible = false; content.Visible = false; defaultDateCurrent.Visible = false; isControlled.Visible = false; controlledValue.Visible = false; controlText.Visible = false; isAutoPostback.Visible = false; parentGroup.Visible = true; //CVH 2017-02-14 Subtab. Get currently selected parent, then rebind parent dropdown, then reselect if list is the same (list depends on field type) string selectedParentId = "0"; if (ddParentFields.SelectedItem != null) selectedParentId = ddParentFields.SelectedItem.Value; BindParentFields(); if (ddParentFields.Items.FindByValue(selectedParentId) != null) ddParentFields.Items.FindByValue(selectedParentId).Selected = true; chkGridActive.Visible = true; chkFilter.Visible = true; chkHiddenField.Visible = true; chkHiddenWizzard.Visible = false; chkReadOnlyField.Visible = true; placeholderGroup.Visible = false; compositeGroup.Visible = false; //JR Bas-Pro-3 chkUnique.Visible = false; actionTypeGroup.Visible = true; if (ddActionTypes.SelectedIndex > 0) { actionGroup.Visible = true; if (ddActions.SelectedIndex > 0) { actionSourceGroup.Visible = true; } } //change views based on selected field type pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), int.Parse(ddFieldTypes.SelectedValue)); switch (typ) { case pNums.FieldType.Tab: //parentGroup.Visible = false; validationGroup.Visible = false; lengthGroup.Visible = false; chkGridActive.Visible = false; chkFilter.Visible = false; chkHiddenField.Visible = false; chkReadOnlyField.Visible = true; chkHiddenWizzard.Visible = true; actionTypeGroup.Visible = false; actionGroup.Visible = false; actionSourceGroup.Visible = false; break; case pNums.FieldType.Group: validationGroup.Visible = false; lengthGroup.Visible = false; chkGridActive.Visible = false; chkFilter.Visible = false; chkHiddenField.Visible = true; chkReadOnlyField.Visible = false; actionTypeGroup.Visible = false; actionGroup.Visible = false; actionSourceGroup.Visible = false; break; case pNums.FieldType.Text: isAutoPostback.Visible = true; placeholderGroup.Visible = true; //JR Bas-Pro-3 chkUnique.Visible = true; break; case pNums.FieldType.Number: isAutoPostback.Visible = true; isControlled.Visible = true; if (chkIsControlled.Checked) controlledValue.Visible = true; //JR Bas-Pro-3 chkUnique.Visible = true; break; case pNums.FieldType.Decimal: isAutoPostback.Visible = true; break; case pNums.FieldType.Picklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; break; case pNums.FieldType.MultiPicklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; break; case pNums.FieldType.Date: isAutoPostback.Visible = true; lengthGroup.Visible = false; defaultDateCurrent.Visible = true; break; case pNums.FieldType.Checkbox: lengthGroup.Visible = false; controlText.Visible = true; isAutoPostback.Visible = true; break; case pNums.FieldType.RadioButtonList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "RadioButtonList Category"; lengthGroup.Visible = false; break; case pNums.FieldType.Button: lengthGroup.Visible = false; controlText.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.Grid: lengthGroup.Visible = false; surfaceApp.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.Attachment: lengthGroup.Visible = false; break; case pNums.FieldType.RelationalField: lengthGroup.Visible = false; surfaceApp.Visible = true; surfaceAppFields.Visible = true; validationGroup.Visible = false; break; case pNums.FieldType.FormulaField: break; case pNums.FieldType.Content: content.Visible = true; lengthGroup.Visible = false; validationGroup.Visible = false; break; case pNums.FieldType.Placeholder: lengthGroup.Visible = false; break; //JasR 2016-01-27 case pNums.FieldType.Caption: isAutoPostback.Visible = false; placeholderGroup.Visible = true; break; case pNums.FieldType.Note: lengthGroup.Visible = false; break; case pNums.FieldType.Debtors: lengthGroup.Visible = false; break; case pNums.FieldType.Mediswitch: lengthGroup.Visible = false; controlText.Visible = true; break; case pNums.FieldType.Composite: lengthGroup.Visible = false; compositeGroup.Visible = true; break; case pNums.FieldType.CheckboxList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "CheckboxList Category"; lengthGroup.Visible = false; break; case pNums.FieldType.Sales: lengthGroup.Visible = false; break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Surface Apps /// private void BindSurfaceApps() { try { ArrayList surfaceApps = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "isActive", "1", "surface"); ddSurfaceApps.DataSource = surfaceApps; ddSurfaceApps.DataTextField = "surface"; ddSurfaceApps.DataValueField = "name"; ddSurfaceApps.DataBind(); ddSurfaceApps.Items.Insert(0, new ListItem("Select Surface", "0")); /* CVH 2016-01-22 Add 0 item */ ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Surface App Fields /// private void BindSurfaceAppFields(string surfaceName) { try { foreach (oSurface surface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", surfaceName)) { ArrayList surfaceAppFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive", surface.recId + ",1"); ddSurfaceAppFields.DataSource = surfaceAppFields; ddSurfaceAppFields.DataTextField = "surfaceFieldDisplay"; ddSurfaceAppFields.DataValueField = "recId"; ddSurfaceAppFields.DataBind(); } ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("canvas:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Content Items /// private void BindContent() { try { ArrayList contentItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "isActive", "1", "title"); ddContent.DataSource = contentItems; ddContent.DataTextField = "title"; ddContent.DataValueField = "recId"; ddContent.DataBind(); ddContent.Items.Insert(0, new ListItem("Select Content", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Composite Items /// private void BindComposite() { try { ArrayList compositeItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oComposite), "", "", "composite"); ddComposite.DataSource = compositeItems; ddComposite.DataTextField = "composite"; ddComposite.DataValueField = "canvasId"; ddComposite.DataBind(); ddComposite.Items.Insert(0, new ListItem("Select Composite", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } #endregion #region surface field events /// /// Save Layout /// /// /// protected void btnSavePositions_Click(object sender, EventArgs e) { try { SaveFieldPositions(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnCloseField_Click(object sender, EventArgs e) { try { string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Picklist Modal /// /// /// protected void btnClosePicklist_Click(object sender, EventArgs e) { try { BindLookupCategories(); upSurfaceFields.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Categpry /// /// /// protected void btnCloseCategory_Click(object sender, EventArgs e) { try { BindLookupCategories(); surfaceLookups1.ReloadControl(); upSurfaceFields.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myPicklistModal", "$('#modLoookups" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surfaceLookups", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Manage Picklists /// /// /// protected void btnManagePicklists_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myPicklistModal", "$('#modLoookups" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnLookCat_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myCatModal", "$('#modLookupCategories" + base.SurfaceApp.name + "').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// manage Grid Options /// /// /// protected void btnGrid_Click(object sender, EventArgs e) { try { if (base.SurfaceApp != null) { Session["surface"] = base.SurfaceApp; surfaceGrids1.ReloadControl(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myGridOptionsModal", "$('#modGridOptions" + base.SurfaceApp.name + "').modal();", true); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Grid Options /// /// /// protected void btnCloseGridOptions_Click(object sender, EventArgs e) { try { upSurfaceFields.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add New Field /// /// /// protected void btnNewField_Click(object sender, EventArgs e) { oSurface Surface = new oSurface(); try { if (base.SurfaceApp != null) { Session["surfaceFieldId"] = 0; utils.disposeSession("surfaceField"); oSurfaceField SurfaceField = new oSurfaceField(); PopulateFieldFormValues(ref SurfaceField); upSurfaceFields.Update(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewFieldScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewFieldScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); } else { Response.Redirect("/home", false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add New Field /// /// /// protected void btnNewGroupField_Click(object sender, EventArgs e) { oSurface Surface = new oSurface(); ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton) && base.SurfaceApp != null) { //get field name string fieldName = ((LinkButton)sender).ID.Replace("lnkInAd", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { Session["surfaceFieldId"] = 0; utils.disposeSession("surfaceField"); oSurfaceField SurfaceField = new oSurfaceField(); SurfaceField.surfaceFieldTypeId = (int)pNums.FieldType.Text; SurfaceField.parentId = field.recId; PopulateFieldFormValues(ref SurfaceField); upSurfaceFields.Update(); //show modal //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); break; } ToggleFieldTypes(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewGroupScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myNewGroupScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditField", "$('#modField" + base.SurfaceApp.name + "').modal();", true); } } if (base.SurfaceApp != null) { } else { Response.Redirect("/home", false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Surface field /// /// /// /// /// REVISION 001: Enable Grid field type. Confirm that surface app loading as Grid Field type is not the current surface app being created /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// protected void btnSaveSurfaceField_Click(object sender, EventArgs e) { oSurfaceField SurfaceField = new oSurfaceField(); oSurface surface = new oSurface(); try { if (base.SurfaceApp != null) { surface = base.SurfaceApp; if (utils.verifySession("surfaceField"))//update mode { SurfaceField = (oSurfaceField)Session["surfaceField"]; //save form values SaveFieldFormValues(ref SurfaceField); /* Rev 001 If field type is grid, verify that selected surface app is not same as current surface app * Charlene van Heerden * 10 December 2015 */ if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; } else { if (xData.UpdateTyped("recId", SurfaceField.recId.ToString(), typeof(oSurfaceField), SurfaceField)) { BuildControl(surface); //oSurfaceItem item = new oSurfaceItem(); //item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceForm(item, false); //TogglePanels("pnlSurfaceForm"); //if (this.SurfaceApp.isModal) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //upSurface.Update(); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your changes were updated successfully."; string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); ; } } } else { //save form values SaveFieldFormValues(ref SurfaceField); if (!xData.VerifyExists("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surface.recId + "," + SurfaceField.surfaceFieldName)) { /* Rev 001 If field type is grid, verify that selected surface app is not same as current surface app * Charlene van Heerden * 10 December 2015 */ if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; } else { SurfaceField.surfaceId = surface.recId; SurfaceField.recId = xData.SaveTyped("recId", typeof(oSurfaceField), SurfaceField); if (SurfaceField.recId > 0) { BuildControl(surface); //oSurfaceItem item = new oSurfaceItem(); //item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceForm(item, false); //TogglePanels("pnlSurfaceForm"); //if (this.SurfaceApp.isModal) // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showSurfaceFormModal", "$('#modSurfaceForm" + base.SurfaceApp.name + "').modal();", true); //upSurface.Update(); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your surface field was created successfully."; string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } } } else { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field with this name already exists on this surface app."; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Field /// /// /// protected void lnkEditField_Click(object sender, EventArgs e) { oSurfaceField _SurfaceField = new oSurfaceField(); ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton) && base.SurfaceApp != null) { //get field name string fieldName = ((LinkButton)sender).ID.Replace("lnkInEd", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { Session["surfaceFieldId"] = field.recId; //assign object _SurfaceField = field; //populate page form PopulateFieldFormValues(ref _SurfaceField); Session["surfaceField"] = _SurfaceField; upSurfaceFields.Update(); break; } ToggleFieldTypes(); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditFieldScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditFieldScrollSub", " $(\"#modChildAppSub\").scrollTop(0);", true); //show modal ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditField", "$('#modField" + base.SurfaceApp.name + ":first').modal();", true); } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove field /// /// /// protected void lnkRemoveField_Click(object sender, EventArgs e) { ArrayList FieldList = new ArrayList(); try { if (sender.GetType() == typeof(LinkButton)) { // string fieldName = ((LinkButton)sender).ID.Replace("lnkInDel", ""); int surfaceId = base.SurfaceApp.recId; if (surfaceId > 0 && fieldName != String.Empty) { //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfaceId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //Delete cat if (xData.DeleteTyped("recId", field.recId.ToString(), typeof(oSurfaceField))) { BuildControl(base.SurfaceApp); string page = handler.GetRoutedData("canvas-title"); if (base.IsChildSurface) { Session["Inline"] = base.ParentSurfaceItemId; Session["childInline"] = base.SurfaceAppItemId; } else Session["Inline"] = base.SurfaceAppItemId; Response.Redirect("/pages/" + page, false); } break; } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Field Type selection change /// /// /// protected void ddFieldTypes_SelectedIndexChanged(object sender, EventArgs e) { try { ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// PArent Fields Selection Changed /// /// /// protected void ddParentFields_SelectedIndexChanged(object sender, EventArgs e) { try { } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Check if number is controlled and then show controlled value /// /// /// protected void chkIsControlled_CheckedChanged(object sender, EventArgs e) { if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; } /// /// Load surface app fields /// /// /// protected void ddSurfaceApps_SelectedIndexChanged(object sender, EventArgs e) { /* CVH 2016-01-22 RelField */ try { DropDownList list = (DropDownList)sender; string value = list.SelectedValue.ToString(); //load surface fields drop down BindSurfaceAppFields(value); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Change Action Type /// /// /// protected void ddActionTypes_SelectedIndexChanged(object sender, EventArgs e) { BindActions(ddActionTypes.SelectedValue.ToString()); actionGroup.Visible = true; } /// /// Change Action /// /// /// protected void ddActions_SelectedIndexChanged(object sender, EventArgs e) { string action = ddActions.SelectedItem.Text; switch (action) { case "VAT": BindActionSource(pNums.FieldType.Decimal.ToString()); break; case "Age": BindActionSource(pNums.FieldType.Date.ToString() + "|" + ((int)pNums.FieldType.Text).ToString()); break; case "Gender": BindActionSource(pNums.FieldType.Text.ToString()); break; default: break; } actionSourceGroup.Visible = true; } #endregion #region properties public Dictionary SurfaceGridTotals { get { if (ViewState["totalsDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["totalsDictionary"]; } set { ViewState["totalsDictionary"] = value; } } public Dictionary SurfaceGridAverages { get { if (ViewState["averagesDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["averagesDictionary"]; } set { ViewState["averagesDictionary"] = value; } } public oSurfaceGridOptions MainGridOptions { get { if (ViewState["mainGridOptions"] == null) { oSurfaceGridOptions gridOptions = new oSurfaceGridOptions(); foreach (oSurfaceGridOptions gridOptionsItem in xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) { gridOptions = gridOptionsItem; } return gridOptions; } else return (oSurfaceGridOptions)ViewState["mainGridOptions"]; } set { ViewState["mainGridOptions"] = value; } } public ArrayList MainSurface { get { if (ViewState["mainSurface"] == null) return xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", base.SurfaceApp.recId.ToString()); else return (ArrayList)ViewState["mainSurface"]; } } public DataTable MainFieldTable { get { if (ViewState["mainFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.SurfaceApp.recId.ToString() + ",0", "surfaceId"); else return (DataTable)ViewState["mainFieldTable"]; } set { ViewState["mainFieldTable"] = value; } } public DataTable ChildFieldTable { get { if (ViewState["childFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.ParentSurfaceId + ",1", "sequence"); else return (DataTable)ViewState["childFieldTable"]; } set { ViewState["childFieldTable"] = value; } } public DataTable SuburbTable { get { if (ViewState["suburbTable"] == null) { DataTable dtSuburbs = new DataTable(); foreach (oSurfaceLookupCategory cat in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookupCategory), "lookupCategory,isActive", "Suburbs,1")) { dtSuburbs = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookup), "categoryId,isActive", cat.recId.ToString() + ",1"); } return dtSuburbs; } else return (DataTable)ViewState["suburbTable"]; } } public oUser User { get { return handler.ReturnUser(); } set { Session["user"] = value; } } #endregion }