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.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using Telerik.Web.UI; public partial class controls_surface_surface_view : 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(); if (!isPersisting) { if (item.recId > 0) { if (base.SurfaceApp.isPublished) { PopulateSurfaceViewCustom(item); } else { PopulateSurfaceView(item); } TogglePanels("pnlSurfaceView"); } } } /// /// Overridible Save Control /// public override void SaveControl(bool finish, bool draft, bool closing) { } #endregion #region methods /// /// Set Aggreagete Data /// /// private void SetAggregates(DataTable surfaceData, int surfaceId) { try { Dictionary localTotals = SurfaceGridTotals; Dictionary localAverages = SurfaceGridAverages; foreach (oSurfaceGridOptions gridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", surfaceId.ToString())) { if (gridOptions.showAggregate) { foreach (oSurfaceGridAggregate agg in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridAggregate), "surfaceId", surfaceId.ToString())) { foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", agg.surfaceFieldId.ToString())) { if (localTotals.ContainsKey(field.surfaceFieldName)) localTotals.Remove(field.surfaceFieldName); localTotals.Add(field.surfaceFieldName, 0); if (localAverages.ContainsKey(field.surfaceFieldName)) localAverages.Remove(field.surfaceFieldName); localAverages.Add(field.surfaceFieldName, 0); } } } } SurfaceGridTotals = localTotals; SurfaceGridAverages = localAverages; //CVH 2017-03-22 Moving, otherwise keys = 0 sumDataTable(surfaceData); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Child Grid /// /// private void BindChildGrid(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 (pnlSurfaceView.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 (pnlSurfaceView.FindControl("pnlSurfaceCompare_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceCompare_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceView.FindControl("pnlSurfaceForm_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceForm_v" + base.SurfaceApp.recId.ToString() + "_" + gridField.surfaceFieldName); if (pnlSurfaceView.FindControl("upv" + group.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceView.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); } } 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 (pnlSurfaceView.FindControl("upv" + surfaceId.ToString() + childFields.surfaceFieldName) != null) upGroup = (UpdatePanel)pnlSurfaceView.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); } } /// /// 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; myTab = (HtmlGenericControl)pnlSurfaceView.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"]; btnEdit.Visible = (usr.userType >= MainGridOptions.editAccessType && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= MainGridOptions.editAccessType && usr.userType == (int)pNums.UserType.CustomUser); //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.Group || field.surfaceFieldTypeId == (int)pNums.FieldType.HeaderGroup) { Control groupControl = (Control)pnlSurfaceView.FindControl("divv" + prefix + field.surfaceFieldName); if (groupControl != null) groupControl.Visible = (usr.userType >= field.accessLevel && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= field.accessLevel && usr.userType == (int)pNums.UserType.CustomUser); } 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)pnlSurfaceView.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) { if (field.relationalObject.Length > 0 && field.relationalObject != "0") { lblPicklist.Text = data.surfaceFieldValueChar; } else { 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); Panel panelGridHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceGrid_v0_" + field.surfaceFieldName); if (divGridHolder != null && panelGridHolder != null) { DataTable childData = new DataTable(); int surfaceId = 0; bool isChildPublished = false; foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", field.relationalSurface)) { surfaceId = surf.recId; isChildPublished = surf.isPublished; 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 { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, _surfaceItem.recId, usr.recId, rowLimit); else childData = xData.GetChildSurfaceQueryData(surfaceId, _surfaceItem.recId, rowLimit); } //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: HtmlGenericControl imageDiv = (HtmlGenericControl)pnlSurfaceView.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)pnlSurfaceView.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); } 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 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 //view labels Label lblvContent = (Label)pnlSurfaceView.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 SetSurfaceControlState(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 + "View"; } 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 SetSurfaceControlState(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 + "View"; } 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 SetSurfaceControlState(oSurfaceItem _surfaceItem, DataRow fieldRow, oSurfaceField relatedField = null) { string fieldName = fieldRow["surfaceFieldName"].ToString(); string controlledValue = fieldRow["controlledValue"].ToString(); bool isControlled = false; bool.TryParse(fieldRow["isControlled"].ToString(), out isControlled); bool altView = false; bool.TryParse(fieldRow["alternateView"].ToString(), out altView); int fieldRecId = int.Parse(fieldRow["recId"].ToString()); if (relatedField != null) { controlledValue = relatedField.controlledValue; fieldRecId = relatedField.recId; } string controlType = string.Empty; string controlPath = string.Empty; string controlName = string.Empty; foreach (oModule module in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", controlledValue)) { controlType = module.module; controlPath = module.control; controlName = module.objectName + fieldName + "View"; } oSurfaceFieldData controlFieldData = new oSurfaceFieldData(); controlFieldData.surfaceFieldID = fieldRecId; controlFieldData.surfaceItemId = _surfaceItem.recId; controlFieldData.surfaceId = _surfaceItem.surfaceId; switch (controlType) { case "BodyMap": string bodyPartList = controlFieldData.surfaceFieldValueChar; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetupBodyParts", "SetupBodyParts('" + bodyPartList + "','1');", true); break; case "Surface Notes": dynamic surfaceControl = this.FindControl(controlName); if (surfaceControl != null) { surfaceControl.Confidential = isControlled; surfaceControl.ReloadControl(controlFieldData, altView); } break; default: dynamic noteControl = this.FindControl(controlName); if (noteControl != null) { noteControl.ReloadControl(controlFieldData, altView); } break; } } /// /// 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); oSurfaceControlParcel parcel = new oSurfaceControlParcel(); if (base.SurfaceApp.isPublished) { //go to surface form control parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); } else { switch (editType) { case pNums.SurfaceGridEditType.Form: //go to surface form control parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; case pNums.SurfaceGridEditType.Row: if (rptItem != null) { ToggleRowEdit(itemId, item, true, rptItem); if (rptItem.Parent.GetType() == typeof(Repeater)) { KeepSelectedGridTab((Repeater)rptItem.Parent); } } break; /* CVH 2016-02-02 Batch edit mode */ case pNums.SurfaceGridEditType.Batch: if (rptItem != null) { ToggleGridEdit(true, (Repeater)rptItem.Parent, itemId, item.surfaceId); } break; default: //go to surface form control parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); break; } } break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } 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 "pnlSurfaceView": ToggleHeadingButtonVisibility(false, btnNew); if ((base.SurfaceAppGridEditTypeId == 0 || base.SurfaceAppGridEditTypeId == (int)pNums.SurfaceGridEditType.Form) && !base.SurfaceApp.isModal) ToggleHeadingButtonVisibility(true, btnEdit); else ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceView.Visible = true; pnlSurfaceCompare.Visible = false; break; case "pnlSurfaceCompare": ToggleHeadingButtonVisibility(true, btnNew); ToggleHeadingButtonVisibility(false, btnEdit); pnlSurfaceView.Visible = false; pnlSurfaceCompare.Visible = true; lnkRefresh.Visible = false; lnkBack.Visible = false; break; } upHeading.Update(); } /// /// 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) { //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) { //CVH 2017-03-21 Check for null & check if child surface - linked surface batch edit if (repeaterItem.FindControl("hfParentSurfaceItemId") != null && base.IsChildSurface) { HiddenField hfParentSurfaceItemId = (HiddenField)repeaterItem.FindControl("hfParentSurfaceItemId"); if (hfParentSurfaceItemId.Value != "") currentParentSurfaceItemId = Convert.ToInt32(hfParentSurfaceItemId.Value); } } LinkButton lnkEdit = null, lnkSaveRow = null, lnkRemove = null, lnkCancel = null, lnkView = null; lnkEdit = (LinkButton)repeaterItem.FindControl("lnkEdit"); lnkSaveRow = (LinkButton)repeaterItem.FindControl("lnkSaveRow"); lnkRemove = (LinkButton)repeaterItem.FindControl("lnkRemove"); lnkCancel = (LinkButton)repeaterItem.FindControl("lnkCancel"); lnkView = (LinkButton)repeaterItem.FindControl("lnkView"); if (lnkEdit == null) continue; int itemId = int.Parse(lnkEdit.CommandArgument); //CVH 2017-03-21 Only when child surface if (currentParentSurfaceItemId == 0 && 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)pnlSurfaceView.FindControl("pnlSurfaceGrid_v" + 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; } 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; } /// /// Method to retain the selected tab open /// /// private void KeepSelectedGridTab(Repeater repeater) { if (base.SurfaceApp != null) { if (MainGridOptions.isTabbed) { int tabId = int.Parse(repeater.ID.Replace("rpt", "")); //CVH 2017-02-14 Subtabs. Only retrieve primary tabs where parentId = 0 ArrayList fieldTabs = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,parentId,surfaceFieldTypeId", base.SurfaceApp.recId + ",1,0," + (int)pNums.FieldType.Tab, "sequence"); int tabCounter = 0; foreach (oSurfaceField tab in fieldTabs) { tabCounter++; if (tab.recId == tabId) { string script = "$('#gSurfaceTabs li:eq(" + (tabCounter - 1) + ") a').tab('show');"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "ClickGridTab", script, true); break; } } } } } /// /// Method to Build User Control /// /// private static void BuildControl(oSurface surface) { foreach (oModule moduleItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", ((int)pNums.Module.Surface).ToString())) { surfaceHandler.BuildSurfaceAppTemplate(surface, controlPath + moduleItem.control, surfacePath, true); } } private void NewItem() { oSurface surfaceApp = base.SurfaceApp; base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.ActiveTabPanel = String.Empty; oSurfaceItem item = new oSurfaceItem(); item.surfaceId = surfaceApp.recId; bool exitEarly = false; //JR 2017-0-27 check if any conditions are stopping the form to populate if (handler.ReturnSetup().code == "STUD-1") { foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId,actionType", item.surfaceId + ",1," + ((int)pNums.FieldType.FormulaField).ToString() + "," + ((int)pNums.ActionType.GenerateCode).ToString())) { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; List sicParams = new List(); oDynamicParam sicParam = new oDynamicParam(); sicParam.paramDisplayName = "userId"; sicParam.paramObject = userId; sicParams.Add(sicParam); DataTable nextCodeTable = xData.GetTypedTableByProc("recId", typeof(oSurfaceItemCode), "sp_GetNextSurfaceItemCodeByUserId", sicParams); if (nextCodeTable.Rows.Count == 0) { //no number, so warn and close Label lblModCleanTitle = (Label)FindControl("lblModCleanTitle"); Literal litModCleanBody = (Literal)FindControl("litModCleanBody"); if (lblModCleanTitle != null && litModCleanBody != null) { lblModCleanTitle.Text = "All Exam Numbers used"; StringBuilder sb = new StringBuilder(); sb.AppendLine("Please note that there are no more Exam Numbers available to your user profile. Please contact Merle or Zaakirah to re-issue Exam Numbers to your profile."); litModCleanBody.Text = sb.ToString(); } exitEarly = true; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "showModClean", "$('#modClean" + base.SurfaceApp.name + "').modal();", true); } } } if (!exitEarly) { //go to Form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); } } 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); } } /// /// 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); } 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); } 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); } } #endregion #region custom methods /// /// Populate the surface form /// /// /// REVISION 001: Add functionality for field type Grid /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 14 December 2015 /// private void PopulateSurfaceViewCustom(oSurfaceItem _surfaceItem, bool isChild = false) { try { string prefix = ""; if (isChild) prefix = _surfaceItem.surfaceId.ToString(); //fetch the fields to define the rules on from from fields DataTable surfaceFieldsTable = MainFieldTable; var fieldTableEnum = surfaceFieldsTable.AsEnumerable(); btnEdit.CommandArgument = _surfaceItem.recId.ToString(); oUser usr = handler.ReturnUser(); oSetup setup = handler.ReturnSetup(); btnEdit.Visible = (usr.userType >= MainGridOptions.editAccessType && usr.userType != (int)pNums.UserType.CustomUser) || (usr.mimicUserType >= MainGridOptions.editAccessType && usr.userType == (int)pNums.UserType.CustomUser); //CVH 2016-12-12 Build a list of parentId's where data has been entered, used when a group is set collapsed by default string groupIdsWithData = ""; #region Header Groups and Groups var groupHeadData = from groupHeads in surfaceFieldsTable.AsEnumerable() where groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.HeaderGroup) || groupHeads.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groupHeads; foreach (DataRow groupHeadRow in groupHeadData.ToList()) { string _surfaceFieldName = groupHeadRow["surfaceFieldName"].ToString(); int _surfaceFieldTypeId = int.Parse(groupHeadRow["surfaceFieldTypeId"].ToString()); int _accessLevel = 0; int.TryParse(groupHeadRow["accessLevel"].ToString(), out _accessLevel); Control groupControl = (Control)pnlSurfaceView.FindControl("divv" + prefix + _surfaceFieldName); bool isHidden = false; bool.TryParse(groupHeadRow["isHidden"].ToString(), out isHidden); if (groupControl != null & !isHidden) { groupControl.Visible = usr.userType >= _accessLevel; } } #endregion #region Auto Generated Populate Code //-- {PopulateViewCustomValues} --// #endregion #region Relational Fields var relData = from relFlds in fieldTableEnum where relFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.RelationalField) select relFlds; foreach (DataRow relFldRow in relData.ToList()) { string _relationalFields = relFldRow["relationalFields"].ToString(); foreach (oSurfaceField relatedField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", _relationalFields)) { if (relatedField.surfaceFieldTypeId == (int)pNums.FieldType.Control) { SetSurfaceControlState(_surfaceItem, relFldRow, relatedField); } } } #endregion #region Controls var cntrlData = from ctrlFlds in fieldTableEnum where ctrlFlds.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Control) select ctrlFlds; foreach (DataRow ctrlRow in cntrlData.ToList()) { SetSurfaceControlState(_surfaceItem, ctrlRow); } #endregion #region Grid Fields //get grid field data var gridData = from grids in fieldTableEnum where grids.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Grid) select grids; foreach (DataRow gridRow in gridData.ToList()) { bool _isControlled = false; bool _isReadOnly = false; bool.TryParse(gridRow["isControlled"].ToString(), out _isControlled); bool.TryParse(gridRow["isReadOnly"].ToString(), out _isReadOnly); int _surfaceId = int.Parse(gridRow["surfaceId"].ToString()); string _surfaceFieldName = gridRow["surfaceFieldName"].ToString(); string _relationalSurface = gridRow["relationalSurface"].ToString(); string _relationalValues = gridRow["relationalValues"].ToString(); bool _defaultToCurrent = false; bool.TryParse(gridRow["defaultToCurrent"].ToString(), out _defaultToCurrent); bool _isComparable = false; bool.TryParse(gridRow["isComparable"].ToString(), out _isComparable); #region Grid //find the div and bind all repeaters inside it HtmlGenericControl divGridHolder = (HtmlGenericControl)pnlSurfaceView.FindControl("divv" + _surfaceFieldName); Panel panelGridHolder = null; if (pnlSurfaceView.FindControl("pnlSurfaceGrid_v0_" + _surfaceFieldName) != null) panelGridHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceGrid_v0_" + _surfaceFieldName); Panel panelCompareHolder = null; if (pnlSurfaceView.FindControl("pnlSurfaceCompare_v0_" + _surfaceFieldName) != null) panelCompareHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceCompare_v0_" + _surfaceFieldName); Panel panelFormHolder = null; if (pnlSurfaceView.FindControl("pnlSurfaceForm_v0_" + _surfaceFieldName) != null) panelFormHolder = (Panel)pnlSurfaceView.FindControl("pnlSurfaceView_v0_" + _surfaceFieldName); if (divGridHolder != null) { DataTable childData = new DataTable(); int surfaceId = 0; oSurface childSurface = new oSurface(); bool isChildPublished = false; foreach (oSurface surf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", _relationalSurface)) { surfaceId = surf.recId; childSurface = surf; isChildPublished = surf.isPublished; break; } if (surfaceId > 0) { int rowLimit = 0; int.TryParse(_relationalValues, out rowLimit); //CVH 2017-02-28 If this is a summarized grid, ignore the copy from master setting, the stored proc will return the summarized data if (_isControlled) { childData = xData.GetChildSurfaceQueryDataSummarized(surfaceId, base.SurfaceAppItemId, rowLimit); } else { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, base.SurfaceAppItemId, usr.recId, rowLimit); else childData = xData.GetChildSurfaceQueryData(surfaceId, base.SurfaceAppItemId, rowLimit); if ((childData.Rows.Count == 0 && _defaultToCurrent) || (base.SurfaceAppItemId == 0 && _defaultToCurrent && childData.Rows.Count > 0)) { DataTable masterDataItems = new DataTable(); int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //get child surface fields ArrayList childFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId", surfaceId.ToString()); if (childData.Rows.Count == 0) { if (isChildPublished) childData = xData.GetChildPublishedSurfaceData(surfaceId, 0, usr.recId, 0); else childData = xData.GetChildSurfaceQueryData(surfaceId, 0, 0); } } } if (panelGridHolder != null) { Repeater repeater = null; //foreach (Control rpt in divGridHolder.Controls) foreach (Control rpt in panelGridHolder.Controls) { if (rpt.GetType() == typeof(Repeater)) { repeater = (Repeater)rpt; SetAggregates(childData, surfaceId); repeater.DataSource = childData; repeater.DataBind(); utils.disposeSession("childButtons"); } } if (_isComparable && panelCompareHolder != null) { BindCompareDropdowns(childSurface, _surfaceFieldName); panelCompareHolder.Visible = true; panelGridHolder.Visible = false; } //CVH 2017-02-23 Only put in edit mode when field is not Read Only else if (repeater != null && repeater.Items.Count > 0 && childData.Rows.Count > 0 && childData.Columns["itemId"] != null && !_isReadOnly && !_isControlled) { //CVH 2016-12-20 Child grid default edit mode foreach (oSurfaceGridOptions childGridOptions in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceGridOptions), "surfaceId", childSurface.recId.ToString())) { //CVH 2017-01-12 Only put into edit mode if edit is allowed (grid options not always cleared) if (childGridOptions.allowEdit && childGridOptions.surfaceGridEditTypeId == (int)pNums.SurfaceGridEditType.Batch) { int editChildItemId = int.Parse(childData.Rows[0]["itemId"].ToString()); RepeaterItem childRptItem = repeater.Items[0]; EditChild(editChildItemId, childRptItem); } break; } } } } } #endregion } #endregion BindSurfaceAttachments(_surfaceItem.recId, false); BindSurfaceNotes(_surfaceItem.recId, false); #region Group Fields //CVH 2016-12-12 Expand/Collapse groups depending on data loaded string expandGroups = ""; var groupData = from groups in fieldTableEnum where groups.Field("surfaceFieldTypeId").Equals((int)pNums.FieldType.Group) select groups; foreach (DataRow groupRow in groupData.ToList()) { bool _isControlled = false; bool.TryParse(groupRow["isControlled"].ToString(), out _isControlled); int _recId = int.Parse(groupRow["recId"].ToString()); string _surfaceFieldName = groupRow["surfaceFieldName"].ToString(); if (_isControlled && groupIdsWithData.Contains("|" + _recId + "|")) { if (expandGroups == String.Empty) expandGroups = "tog" + _surfaceFieldName; else expandGroups += ",tog" + _surfaceFieldName; } } ViewState["ExpandSurfaceGroupAccordianIds"] = expandGroups; #endregion SetCustomVisible(); upSurface.Update(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events /// /// Page initiliazie event to dynamicall load user controls - grid surface apps /// /// /// protected void Page_Init(object sender, EventArgs e) { if (base.SurfaceApp != null) { if (base.SurfaceAppItem == null) { oSurfaceItem item = new oSurfaceItem(); item.surfaceId = base.SurfaceApp.recId; //PopulateSurfaceFormGridSurfaceApps(); PopulateSurfaceFormContentType(item); } } } /// /// Page Load Event /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { if (utils.verifySession("SurfaceControlParcel")) { oSurfaceControlParcel parcel = (oSurfaceControlParcel)Session["SurfaceControlParcel"]; //set values from parcel base.SurfaceApp = parcel.SurfaceApp; base.SurfaceAppItem = parcel.SurfaceAppItem; base.SurfaceAppItemId = parcel.SurfaceAppItem.recId; base.ParentSurfaceItemId = parcel.ParentSurfaceItemId; base.ParentSurfaceId = parcel.ParentSurfaceId; base.ChildParentSurfaceId = parcel.ChildParentSurfaceId; base.ChildParentSurfaceItemId = parcel.ChildParentSurfaceItemId; base.IsChildSurface = parcel.IsChildSurface; base.IsSubChildSurface = parcel.IsSubChildSurface; base.IsClone = parcel.IsClone; this.IsFromView = parcel.IsView; utils.disposeSession("SurfaceControlParcel"); } else { Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); return; } btnNew.Enabled = true; if (base.SurfaceAppItem != null) { if (base.SurfaceApp.isPublished) { PopulateSurfaceViewCustom(base.SurfaceAppItem); } else { PopulateSurfaceView(base.SurfaceAppItem); } TogglePanels("pnlSurfaceView"); } else { //Go To Grid oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } //else //{ // //Persist apps // PersistChildApp(); //} } 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); } } /// /// 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); } } /// /// 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 && base.SurfaceApp != null) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("rcId", typeof(oSurfaceItem), "recId", itemId.ToString())) { //CVH 2017-10-04 Cater for editing a CHILD item in view mode oSurfaceControlParcel parcel = new oSurfaceControlParcel(); if (base.IsChildSurface) Session["childAppName"] = base.SurfaceApp.name; //Go to surface form control parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = item; parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; if (base.IsChildSurface) Session["childAppName"] = base.SurfaceApp.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); } } } upSurface.Update(); } 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); } } } 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)) { } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Cancel /// /// /// protected void btnCancel_Click(object sender, EventArgs e) { try { base.SurfaceAppItem = null; base.SurfaceAppItemId = 0; base.SurfaceAppGridEditTypeId = 0; if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; parcel.IsView = this.IsFromView; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; parcel.IsView = this.IsFromView; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=" + (this.IsFromView ? "view" : "form"), false); break; } break; } //} } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// 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); } } } } 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) { } 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); } } /// /// 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; if (base.IsChildSurface) { string sub = String.Empty; //if (base.IsSubChildSurface) //{ // sub = "Sub"; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildClose", "$('#modChildApp" + sub + "').modal('toggle');", true); // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // if (plcChildApp != null) // plcChildApp.Controls.Clear(); //} //else //{ //get parent surface and item and canvas foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", base.ParentSurfaceItemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsSubChildSurface) { //get the child's parent parcel.ParentSurfaceId = base.ChildParentSurfaceId; parcel.ParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } else { parcel.ParentSurfaceId = 0; parcel.ParentSurfaceItemId = 0; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = false; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); break; } break; } //} } else { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// MSV method /// /// /// protected void btnMediswitch_Click(object sender, EventArgs e) { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modMediSwitchMSV", "$('#modMediSwitchMSV" + base.SurfaceApp.name + "').modal();", true); } /// /// Debtors method /// /// /// protected void btnDebtors_Click(object sender, EventArgs e) { if (base.SurfaceApp != null) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; } //CVH 2016-11-17 Set the Debtors button field name, used when linking notes to surface 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 { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.ChildParentSurfaceId = base.ChildParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ChildParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsSubChildSurface = base.IsSubChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } catch (Exception ex) { exception.HandleException("Master:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// /// /// /// 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 lnkGridView_Click(object sender, EventArgs e) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = base.SurfaceApp; parcel.SurfaceAppItem = new oSurfaceItem(); parcel.ParentSurfaceId = base.ParentSurfaceId; parcel.ParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = base.IsChildSurface; parcel.IsClone = base.IsClone; Session["SurfaceControlParcel"] = parcel; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0], false); } protected void lnkCompareView_Click(object sender, EventArgs e) { TogglePanels("pnlSurfaceCompare"); lnkCompareView.Visible = false; lnkGridView.Visible = true; if (base.SurfaceApp != null) { BindCompareDropdowns(base.SurfaceApp); } } /// /// 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); } } 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) { if (base.SurfaceApp.isPublished) { PopulateSurfaceViewCustom(base.SurfaceAppItem); } else { PopulateSurfaceView(base.SurfaceAppItem, false); } TogglePanels("pnlSurfaceView"); } /// /// 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; default: break; } } #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 && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thView") != null) { HtmlTableCell thView = (HtmlTableCell)e.Item.FindControl("thView"); thView.Visible = childGridOptions.allowView && ((user.userType >= childGridOptions.viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thRemove") != null) { HtmlTableCell thRemove = (HtmlTableCell)e.Item.FindControl("thRemove"); thRemove.Visible = childGridOptions.allowRemove && ((user.userType >= childGridOptions.removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("thClone") != null) { HtmlTableCell thClone = (HtmlTableCell)e.Item.FindControl("thClone"); thClone.Visible = childGridOptions.allowClone && ((user.userType >= childGridOptions.cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } } 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 && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.editAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfView") != null) { HtmlTableCell tfView = (HtmlTableCell)e.Item.FindControl("tfView"); tfView.Visible = childGridOptions.allowView && ((user.userType >= childGridOptions.viewAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.viewAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfRemove") != null) { HtmlTableCell tfRemove = (HtmlTableCell)e.Item.FindControl("tfRemove"); tfRemove.Visible = childGridOptions.allowRemove && ((user.userType >= childGridOptions.removeAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.removeAccessType && user.userType == (int)pNums.UserType.CustomUser)); } if (e.Item.FindControl("tfClone") != null) { HtmlTableCell tfClone = (HtmlTableCell)e.Item.FindControl("tfClone"); tfClone.Visible = childGridOptions.allowClone && ((user.userType >= childGridOptions.cloneAccessType && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType >= childGridOptions.cloneAccessType && user.userType == (int)pNums.UserType.CustomUser)); } } 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); } /// /// 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); } } /// /// 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_v", "pnlSurfaceGrid_v"); string panelCompareVal = btnGridView.ID.Replace("btnGridViewChild_v", "pnlSurfaceCompare_v"); if (pnlSurfaceView.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceView.FindControl(panelGridVal)).Visible = true; if (pnlSurfaceView.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceView.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_v", "pnlSurfaceGrid_v"); string panelCompareVal = btnCompareView.ID.Replace("btnCompareViewChild_v", "pnlSurfaceCompare_v"); if (pnlSurfaceView.FindControl(panelGridVal) != null) ((Panel)pnlSurfaceView.FindControl(panelGridVal)).Visible = false; if (pnlSurfaceView.FindControl(panelCompareVal) != null) ((Panel)pnlSurfaceView.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 (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 + "_form.ascx"))) { BuildControl(gridSurface); } //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = false; // base.ChildIsNew = true; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); //} } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Add Surface Item /// /// /// protected void lnkViewChild_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { int itemId = int.Parse(((LinkButton)sender).CommandArgument); if (itemId > 0) { foreach (oSurfaceItem item in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "recId", itemId.ToString())) { foreach (oSurface gridSurface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", item.surfaceId.ToString())) { //load the surface app control if (!File.Exists(Server.MapPath(surfacePath + gridSurface.name + "_view.ascx"))) { BuildControl(gridSurface); } //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = true; // base.ChildIsNew = false; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=view", false); //} } } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Child item from compare /// /// /// protected void lnkEditCompareChild_Click(object sender, EventArgs e) { LinkButton lnk = (LinkButton)sender; string ddlID = lnk.ID.Replace("lnkEdit", "ddlCompare"); if (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 + "_form.ascx"))) { BuildControl(gridSurface); } //if (base.IsChildSurface) //{ // ISurfaceBase uc = (ISurfaceBase)LoadControl(surfacePath + gridSurface.name + "_form.ascx"); // uc.ID = gridSurface.name + 0; // uc.SurfaceApp = gridSurface; // uc.ParentSurfaceItemId = base.SurfaceAppItemId; // uc.ParentSurfaceId = base.SurfaceApp.recId; // uc.SurfaceAppItem = item; // uc.SurfaceAppItemId = item.recId; // uc.IsChildSurface = true; // Panel pnlSurfaceFieldModal = (Panel)uc.FindControl("pnlSurfaceFieldModal"); // if (pnlSurfaceFieldModal != null) // pnlSurfaceFieldModal.Visible = false; // string sub = String.Empty; // sub = "Sub"; // uc.IsSubChildSurface = true; // PlaceHolder plcChildApp = this.Parent.FindControl("plcChildApp" + sub) as PlaceHolder; // Label lblChildAppTitle = this.Parent.FindControl("lblChildAppTitle" + sub) as Label; // UpdatePanel upChildApp = this.Parent.FindControl("upChildApp" + sub) as UpdatePanel; // if (plcChildApp != null) // { // plcChildApp.Controls.Clear(); // plcChildApp.Controls.Add(uc); // lblChildAppTitle.Text = gridSurface.surface; // base.ChildAppItem = item; // base.ChildIsView = false; // base.ChildIsNew = false; // base.ChildIsClone = false; // uc.ReloadControl(base.ChildAppItem, base.ChildIsView, base.ChildIsNew, false); // upChildApp.Update(); // } // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myChildAppEdit", "$('#modChildApp" + sub + "').modal();", true); //} //else //{ //Go to surface form control oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = gridSurface; parcel.SurfaceAppItem = item; if (base.IsChildSurface) { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = base.ParentSurfaceId; parcel.ChildParentSurfaceItemId = base.ParentSurfaceItemId; parcel.IsChildSurface = true; parcel.IsSubChildSurface = true; parcel.IsClone = false; } else { parcel.ParentSurfaceId = base.SurfaceApp.recId; parcel.ParentSurfaceItemId = base.SurfaceAppItemId; parcel.ChildParentSurfaceId = 0; parcel.ChildParentSurfaceItemId = 0; parcel.IsChildSurface = true; parcel.IsSubChildSurface = false; parcel.IsClone = false; } Session["SurfaceControlParcel"] = parcel; Session["childAppName"] = gridSurface.name; Response.Redirect(Request.Url.AbsoluteUri.Split('?')[0] + "?mode=form", false); //} } break; case pNums.SurfaceGridEditType.Row: if (rptItem != null) { ToggleRowEdit(itemId, item, true, rptItem); //if (rptItem.Parent.GetType() == typeof(Repeater)) //{ KeepSelectedGridTab((Repeater)rptItem.Parent); } } break; /* CVH 2016-02-02 Batch edit mode */ case pNums.SurfaceGridEditType.Batch: if (rptItem != null) { ToggleGridEdit(true, (Repeater)rptItem.Parent, itemId, item.surfaceId); } break; } } } } /// /// Clone 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); } } } } 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) { HtmlGenericControl genericNoteDiv = (HtmlGenericControl)pnlSurfaceView.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) { HtmlGenericControl genericAttachDiv = (HtmlGenericControl)pnlSurfaceView.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(), "myvFileModalScroll", " $(\"#modChildApp\").scrollTop(0);", true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myvFileModalScrollSub", " $(\"#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(), "myvFileModal", "$('#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) { 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('" + pnlSurfaceView.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) { 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, true); //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) { 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, true); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "forceFileRefresh", "forcePostBack('" + pnlSurfaceView.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 properties public Dictionary SurfaceGridTotals { get { if (ViewState["totalsDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["totalsDictionary"]; } set { ViewState["totalsDictionary"] = value; } } public Dictionary SurfaceGridAverages { get { if (ViewState["averagesDictionary"] == null) return new Dictionary(); else return (Dictionary)ViewState["averagesDictionary"]; } set { ViewState["averagesDictionary"] = value; } } public oSurfaceGridOptions MainGridOptions { get { if (ViewState["mainGridOptions"] == null) { oSurfaceGridOptions gridOptions = new oSurfaceGridOptions(); foreach (oSurfaceGridOptions gridOptionsItem in xData.GetTypedByCriteriaSpecific("redId", typeof(oSurfaceGridOptions), "surfaceId", base.SurfaceApp.recId.ToString())) { gridOptions = gridOptionsItem; } return gridOptions; } else return (oSurfaceGridOptions)ViewState["mainGridOptions"]; } set { ViewState["mainGridOptions"] = value; } } public ArrayList MainSurface { get { if (ViewState["mainSurface"] == null) return xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", base.SurfaceApp.recId.ToString()); else return (ArrayList)ViewState["mainSurface"]; } } public DataTable MainFieldTable { get { if (ViewState["mainFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.SurfaceApp.recId.ToString() + ",1", "sequence"); else return (DataTable)ViewState["mainFieldTable"]; } set { ViewState["mainFieldTable"] = value; } } public DataTable ChildFieldTable { get { if (ViewState["childFieldTable"] == null) return xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,isActive", base.ParentSurfaceId + ",1", "sequence"); else return (DataTable)ViewState["childFieldTable"]; } set { ViewState["childFieldTable"] = value; } } public DataTable SuburbTable { get { if (ViewState["suburbTable"] == null) { DataTable dtSuburbs = new DataTable(); foreach (oSurfaceLookupCategory cat in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookupCategory), "lookupCategory,isActive", "Suburbs,1")) { dtSuburbs = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookup), "categoryId,isActive", cat.recId.ToString() + ",1"); } return dtSuburbs; } else return (DataTable)ViewState["suburbTable"]; } } public oUser User { get { return handler.ReturnUser(); } set { Session["user"] = value; } } //CVH 2017-10-05 When click back, load View mode if opened from View private bool IsFromView { get { if (ViewState["isFromView"] == null || ViewState["isFromView"].ToString() == String.Empty) return false; else return bool.Parse(ViewState["isFromView"].ToString()); } set { ViewState["isFromView"] = value; } } #endregion }