using framework_business; using framework_library; using System; using System.Collections; using System.Data; using System.Data.SqlClient; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Reflection; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.Web.UI; public partial class controls_admin_surfaceField : System.Web.UI.UserControl { private const string controlPath = "~/controls/"; private const string surfacePath = "~/controls/surface/"; private const string tempPath = "~/upload/temp/"; #region Events /// /// Reload Control /// public void ReloadControl(bool isNew, oSurfaceField _field, bool isPersisting = false) { try { pnlResultSurfaceField.Visible = false; LoadControls(isPersisting); if (_field.recId > 0) { EditField(_field); } else if (isNew) { if (_field.parentId > 0) NewField(_field); else NewField(); } } catch (Exception ex) { exception.HandleException("surface fields:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Save Control /// public bool SaveControlData() { bool result = false; oSurfaceField SurfaceField = new oSurfaceField(); oSurface surface = new oSurface(); try { if (utils.verifySession("surface")) { surface = (oSurface)Session["surface"]; if (utils.verifySession("surfaceField"))//update mode { SurfaceField = (oSurfaceField)Session["surfaceField"]; //save form values SaveFieldFormValues(ref SurfaceField); /* Rev 001 If field type is grid, verify that selected surface app is not same as current surface app * Charlene van Heerden * 10 December 2015 */ if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } //not sure why it's here - JR 2017/02/08 //else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) //{ // pnlResultSurfaceField.Visible = true; // lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; //} else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Control && SurfaceField.controlledValue == pNums.Module.ImageMap.GetHashCode().ToString() && SurfaceField.placeholder == String.Empty) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please upload an image."; } else { if (xData.UpdateTyped("recId", SurfaceField.recId.ToString(), typeof(oSurfaceField), SurfaceField)) { BuildControl(surface); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your changes were updated successfully."; result = true; } } } else { //save form values SaveFieldFormValues(ref SurfaceField); //CVH 2017-03-02 Max field name length allowed 128, otherwise causes problems in stored procs QUOTENAME (max 128 char allowed) if (SurfaceField.surfaceFieldName.Length > 128) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The total surface field name cannot exceed 128 characters. Please choose a shorter Name, use Display Text to display a longer value."; } else if (SurfaceField.parentId == 0 && SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Tab && SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.HeaderGroup) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Parent cannot be \"None\"."; } else if (!xData.VerifyExists("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surface.recId + "," + SurfaceField.surfaceFieldName)) { if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid && surface.name == SurfaceField.relationalSurface) { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "The surface app " + surface.name + " cannot be added as a grid field to the surface app " + surface.name + "."; } else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && SurfaceField.relationalFields == "0") { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "Please select a Surface Field."; } //not sure why it's here - JR 2017/02/08 //else if (SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField && surface.name == SurfaceField.relationalSurface) //{ // pnlResultSurfaceField.Visible = true; // lblResultSurfaceField.Text = "A surface field cannot relate to a field on the same surface app."; //} else { SurfaceField.surfaceId = surface.recId; SurfaceField.recId = xData.SaveTyped("recId", typeof(oSurfaceField), SurfaceField); if (SurfaceField.recId > 0) { BuildControl(surface); Session["surfaceFieldId"] = SurfaceField.recId; Session["surfaceField"] = SurfaceField; pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "your surface field was created successfully."; result = true; } } } else { pnlResultSurfaceField.Visible = true; lblResultSurfaceField.Text = "A surface field with this name already exists on this surface app."; } } //GR 2017-08-04 Save Surface Signature configuration if (SurfaceField.recId > 0 && SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Control && SurfaceField.controlledValue == pNums.Module.SurfaceSignature.GetHashCode().ToString()) { oSurfaceSignatureConfig conf = new oSurfaceSignatureConfig(); foreach (oSurfaceSignatureConfig c in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceSignatureConfig), "fieldId", SurfaceField.recId.ToString())) { conf = c; break; } conf.includePhoto = chkSigIncludePhoto.Checked; conf.labelText = txtSigLabelText.Value; conf.disclaimer = txtSigDisclaimerText.Value; conf.fieldId = SurfaceField.recId; //hardcoded these values for now for a default state of the feature conf.editRoles = "0"; conf.allowPhotoEdit = chkSigAllowPhotoEdit.Checked; conf.allowSignatureEdit = chkSigAllowSignatureEdit.Checked; if (conf.recId > 0) xData.UpdateTyped("recId", conf.recId.ToString(), typeof(oSurfaceSignatureConfig), conf); else xData.SaveTyped("recId", typeof(oSurfaceSignatureConfig), conf); } //GR 2017-10-27 Save Surface Drawing configuration if (SurfaceField.recId > 0 && SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Control && SurfaceField.controlledValue == pNums.Module.SurfaceDrawing.GetHashCode().ToString()) { oSurfaceDrawingConfig confDrw = new oSurfaceDrawingConfig(); foreach (oSurfaceDrawingConfig conf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceDrawingConfig), "fieldId", SurfaceField.recId.ToString(), "")) { confDrw = conf; break; } confDrw.fieldId = SurfaceField.recId; if (confDrw.recId > 0) xData.UpdateTyped("recId", confDrw.recId.ToString(), typeof(oSurfaceDrawingConfig), confDrw); else xData.SaveTyped("recId", typeof(oSurfaceDrawingConfig), confDrw); } if (result) { PopulateFieldFormValues(ref SurfaceField); } } } catch (Exception ex) { exception.HandleException("surface fields:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } return result; } /// /// Page Load /// /// /// protected void Page_Load(object sender, EventArgs e) { try { if (!Page.IsPostBack) { LoadControls(false); } } catch (Exception ex) { exception.HandleException("surface fields", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #region surface field events /// /// Manage Picklists /// /// /// protected void btnManagePicklists_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myPicklistModal", "$('#modLoookups').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Field Type selection change /// /// /// protected void ddFieldTypes_SelectedIndexChanged(object sender, EventArgs e) { try { ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Check if number is controlled and then show controlled value /// /// /// protected void chkIsControlled_CheckedChanged(object sender, EventArgs e) { if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; } /// /// Load surface app fields /// /// /// protected void ddSurfaceApps_SelectedIndexChanged(object sender, EventArgs e) { /* CVH 2016-01-22 RelField */ try { DropDownList list = (DropDownList)sender; string value = list.SelectedValue.ToString(); //load surface fields drop down BindSurfaceAppFields(value); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Change Action Type /// /// /// protected void ddActionTypes_SelectedIndexChanged(object sender, EventArgs e) { string actionType = ddActionTypes.SelectedValue.ToString(); BindActions(actionType); ClearActionControls(); //CVH 2017-06-30 Cleanup - Do these on Action select /* if (actionType == pNums.ActionType.Button.GetHashCode().ToString()) lblActionValue.InnerText = "Copy Button Text"; else lblActionValue.InnerHtml = "Value use delimiter ;"; lookupCalcSurfaceGroup.Visible = false; fieldAggregationGroup.Visible = false; actionValueGroup.Visible = (actionType == pNums.ActionType.ToggleView.GetHashCode().ToString()); aggregationSurfaceGroup.Visible = (actionType == ((int)pNums.ActionType.Aggregation).ToString()); if (actionType == ((int)pNums.ActionType.FieldAggregation).ToString()) { fieldAggregationGroup.Visible = true; BindFieldAggregationList(); } stylingTextColourGroup.Visible = false; txtActionValue.Text = ""; */ } protected void ddModuleLookup_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddModuleLookup.SelectedItem != null && ddModuleLookup.SelectedItem.Text == "Surface") { moduleSurfaceGroup.Visible = true; ddModuleSurfaceField.ClearSelection(); ddModuleSurfaceField.Items.Clear(); ddModuleSurface.ClearSelection(); ddModuleSurface.Items.Clear(); BindModuleSurface(); } else moduleSurfaceGroup.Visible = false; } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } protected void ddModuleSurface_SelectedIndexChanged(object sender, EventArgs e) { try { ddModuleSurfaceField.ClearSelection(); ddModuleSurfaceField.Items.Clear(); if (ddModuleSurface.SelectedItem != null) { BindModuleSurfaceFields(int.Parse(ddModuleSurface.SelectedItem.Value)); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } protected void ddLookupCalcSurface_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddActions.SelectedItem != null && ddActions.SelectedItem.Text == "Lookup Field" && ddLookupCalcSurface.SelectedItem.Value != "") { BindLookupCalcSurfaceFields(ddLookupCalcSurface.SelectedItem.Value); lookupCalcSurfaceFieldGroup.Visible = true; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Change Action /// /// /// protected void ddActions_SelectedIndexChanged(object sender, EventArgs e) { try { oSurfaceField field = new oSurfaceField(); if (utils.verifySession("surfaceField")) field = (oSurfaceField)Session["surfaceField"]; if (field.surfaceId == 0 && utils.verifySession("surfaceId")) field.surfaceId = int.Parse(Session["surfaceId"].ToString()); int actionType = 0; if (ddActionTypes.SelectedItem != null) actionType = int.Parse(ddActionTypes.SelectedItem.Value); string action = ""; if (ddActions.SelectedItem != null && ddActions.SelectedItem.Value != "0") action = ddActions.SelectedItem.Text; ToggleAction(field.surfaceId, actionType, action, field.actionSource, field.actionValue); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } protected void btnMapFields_Click(object sender, EventArgs e) { try { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "modMapFields", "$('#modMapFields').modal();", true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void ddControls_SelectedIndexChanged(object sender, EventArgs e) { try { ToggleControlDisplay(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void ddLabelSurface_SelectedIndexChanged(object sender, EventArgs e) { if (ddLabelSurface.SelectedValue != "user" && ddLabelSurface.SelectedValue != "date" && ddLabelSurface.SelectedValue != "static") { BindLabelSourceFields(ddLabelSurface.SelectedValue); labelSourceGroup.Visible = true; labelStaticGroup.Visible = false; } if (ddLabelSurface.SelectedValue == "static") { labelSourceGroup.Visible = false; labelStaticGroup.Visible = true; } } /// /// Aggregation Surface drop down selection changed /// /// /// protected void ddAggregationSurface_SelectedIndexChanged(object sender, EventArgs e) { try { if (sender is DropDownList) { DropDownList dd = (DropDownList)sender; if (dd != null) { if (dd.SelectedItem != null) { //BindLabelSourceFields(dd.SelectedItem.Value); //labelSourceGroup.Visible = true; BindActionSource(pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString(), int.Parse(dd.SelectedItem.Value)); } } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Custom Source Checked changed event /// /// /// protected void chkUseCustomSource_CheckedChanged(object sender, EventArgs e) { try { ToggleCustomSource(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Custom Source Selcted Index changed event /// /// /// protected void ddCustomSource_SelectedIndexChanged(object sender, EventArgs e) { try { BindCustomSourceFields(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// File Uploaded event /// /// /// protected void fuDrawingPlaceholder_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e) { try { if (!utils.verifySession("surfaceField")) { if (!SaveControlData()) { return; } } if (utils.verifySession("surfaceField")) { oSurfaceField _surfField = (oSurfaceField)Session["surfaceField"]; string drawingConfigFolder = "surface/drawingConfig/"; drawingConfigFolder += _surfField.recId; string randomFileName = utils.RandomString(5, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string filePath = Server.MapPath("~/upload/" + drawingConfigFolder + "/"); utils.validateFolder(filePath); //save to file system with new image name e.File.SaveAs(filePath + randomFileName); oSurfaceDrawingConfig drawCfg = new oSurfaceDrawingConfig(); foreach (oSurfaceDrawingConfig conf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceDrawingConfig), "fieldId", _surfField.recId.ToString(), "")) { drawCfg = conf; break; } System.Drawing.Image plcIMG = System.Drawing.Image.FromFile(filePath + randomFileName); drawCfg.placeholder = drawingConfigFolder + "/" + randomFileName; if (plcIMG.Width > 800)//resize image { plcIMG.Dispose(); utils.ResizeImage(filePath + randomFileName, filePath, "res_" + randomFileName, 800, true, true); plcIMG = System.Drawing.Image.FromFile(filePath + "res_" + randomFileName); drawCfg.placeholder = drawingConfigFolder + "/" + "res_" + randomFileName; } drawCfg.placeHolderH = plcIMG.Height.ToString(); drawCfg.placeHolderW = plcIMG.Width.ToString(); ; drawCfg.fieldId = _surfField.recId; plcIMG.Dispose(); if (drawCfg.recId > 0)//update { xData.UpdateTyped("recId", drawCfg.recId.ToString(), typeof(oSurfaceDrawingConfig), drawCfg); } else { drawCfg.recId = xData.SaveTyped("recId", typeof(oSurfaceDrawingConfig), drawCfg); } } } catch (Exception ex) { exception.HandleException("surfaceSignature:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #endregion #region Methods /// /// Method to Build User Control /// /// private static void BuildControl(oSurface surface) { foreach (oModule moduleItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", pNums.Module.Surface.GetHashCode().ToString())) { surfaceHandler.BuildSurfaceAppTemplate(surface, controlPath + moduleItem.control, surfacePath, true); } } /// /// Load Controls /// private void LoadControls(bool isPersisting) { try { if (!isPersisting) { BindFieldTypes(); BindSurfaceDateTypes(); BindControls(); BindSequence(); BindSurfaceApps(); BindContent(); BindComposite(); BindActionTypes(); BindLabelSourceSurface(); BindAggregationSurface(); BindAccessLevel(); BindValidationTypes(); BindCustomSourceTables(); } BindLookupCategories(); } catch (Exception ex) { exception.HandleException("surface fields", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Edit Field /// /// private void EditField(oSurfaceField _SurfaceField) { try { Session["surfaceFieldId"] = _SurfaceField.recId; Session["surfaceField"] = _SurfaceField; ToggleFieldStatePublished(false); //ToggleFieldTypes(); //populate page form PopulateFieldFormValues(ref _SurfaceField); ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// New Field /// private void NewField(oSurfaceField _field = null) { try { Session["surfaceFieldId"] = 0; utils.disposeSession("surfaceField"); oSurfaceField SurfaceField = new oSurfaceField(); if (_field != null) SurfaceField = _field; PopulateFieldFormValues(ref SurfaceField); ToggleFieldTypes(); ToggleFieldStatePublished(true); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void BindModuleSurface() { oSurface surf = new oSurface(); if (utils.verifySession("surface")) surf = (oSurface)Session["surface"]; ArrayList surfaces = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "isActive", "1", "surface"); for (int i = surfaces.Count - 1; i >= 0; i--) { if (((oSurface)surfaces[i]).recId == surf.recId) { surfaces.RemoveAt(i); break; } } ddModuleSurface.DataSource = surfaces; ddModuleSurface.DataTextField = "surface"; ddModuleSurface.DataValueField = "recId"; ddModuleSurface.DataBind(); ddModuleSurface.Items.Insert(0, new ListItem("select...", "0")); } private void BindModuleSurfaceFields(int surfaceId) { ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", surfaceId + "," + pNums.FieldType.Text.GetHashCode() + ",1"); ddModuleSurfaceField.DataSource = surfaceFields; ddModuleSurfaceField.DataTextField = "surfaceFieldDisplay"; ddModuleSurfaceField.DataValueField = "recId"; ddModuleSurfaceField.DataBind(); ddModuleSurfaceField.Items.Insert(0, new ListItem("select...", "0")); } /// /// Bind Field Types /// private void BindFieldTypes() { try { DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldType), "isActive", "1", "recId"); ddFieldTypes.DataSource = typeData; ddFieldTypes.DataTextField = "surfaceFieldType"; ddFieldTypes.DataValueField = "recId"; ddFieldTypes.DataBind(); ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Toggle Field Types /// /// /// REVISION 001: Add Grid field type /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 10 December 2015 /// private void ToggleFieldTypes() { try { //set default views lookupGroup.Visible = false; moduleLookupGroup.Visible = false; validationGroup.Visible = true; lengthGroup.Visible = true; controlSizeGroup.Visible = true; labelSizeGroup.Visible = true; surfaceApp.Visible = false; surfaceAppFields.Visible = false; content.Visible = false; defaultDataCurrent.Visible = false; isControlled.Visible = false; divConfidentialNotes.Visible = false; controlledValue.Visible = false; controlText.Visible = true; isAutoPostback.Visible = false; parentGroup.Visible = true; //CVH 2017-02-14 Subtab. Get currently selected parent, then rebind parent dropdown, then reselect if list is the same (list depends on field type) string selectedParentId = "0"; if (ddParentFields.SelectedItem != null) selectedParentId = ddParentFields.SelectedItem.Value; BindParentFields(); if (ddParentFields.Items.FindByValue(selectedParentId) != null) ddParentFields.Items.FindByValue(selectedParentId).Selected = true; divGridActive.Visible = true; divIsGrouped.Visible = true; divFilter.Visible = true; divComparable.Visible = true; divHiddenField.Visible = true; divHiddenWizzard.Visible = false; divHiddenView.Visible = false; divHiddenForm.Visible = false; divReadOnlyField.Visible = true; divIsCloneable.Visible = true; //GR 2017-07-04 custom source options customSourceOpt.Visible = false; customSourceLookup.Visible = false; customSourceFieldDisplay.Visible = false; customSourceFieldValue.Visible = false; customSourceWhere.Visible = false; customSourceOrderBy.Visible = false; //GR 2017-08-04 Signature Config pnlSurfaceSignatureConfig.Visible = false; //GR 2017-10-27 Drawing Config pnlDrawingConfiguration.Visible = false; divAlternateView.Visible = false; divNewLine.Visible = true; divBottomBorder.Visible = true; divFullBorder.Visible = true; placeholderGroup.Visible = false; compositeGroup.Visible = false; //JR Bas-Pro-3 divUnique.Visible = false; mapFieldsGroup.Visible = false; controlsGroup.Visible = false; controlsImageMapGroup.Visible = false; dateTypeGroup.Visible = false; labelSurfaceGroup.Visible = false; labelSourceGroup.Visible = false; rowLimitGroup.Visible = false; lblMaxLength.Text = "Max Length"; divLabelHidden.Visible = true; divGroupDefaultCollapsed.Visible = false; validationTypeGroup.Visible = false; //CVH 2017-02-16 Enable for picklists and caption for now. Adding Number and Decimal. divBulkUpdate.Visible = false; divCurrency.Visible = false; //CVH 2017-02-28 Summary grid - summarizes child grid values into this parent grid divSummaryGrid.Visible = false; pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), int.Parse(ddFieldTypes.SelectedValue)); //CVH 2017-02-28 Set action properties for all field types (will clear it for non action typed) SetActionProperties((int)typ); //change views based on selected field type switch (typ) { case pNums.FieldType.Tab: //CVH 2017-02-14 Subtab. Show parent group //parentGroup.Visible = false; validationGroup.Visible = false; lengthGroup.Visible = false; controlSizeGroup.Visible = false; labelSizeGroup.Visible = false; divGridActive.Visible = false; divIsGrouped.Visible = false; divFilter.Visible = false; divComparable.Visible = false; divHiddenField.Visible = false; divReadOnlyField.Visible = true; divHiddenWizzard.Visible = true; divHiddenView.Visible = true; divHiddenForm.Visible = true; divLabelHidden.Visible = false; divNewLine.Visible = false; divBottomBorder.Visible = false; divFullBorder.Visible = false; isAutoPostback.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Group: validationGroup.Visible = false; lengthGroup.Visible = false; controlSizeGroup.Visible = false; labelSizeGroup.Visible = false; divGridActive.Visible = false; divIsGrouped.Visible = false; divLabelHidden.Visible = false; divFilter.Visible = false; divComparable.Visible = false; divHiddenField.Visible = true; divReadOnlyField.Visible = false; divNewLine.Visible = false; divBottomBorder.Visible = false; divFullBorder.Visible = false; divGroupDefaultCollapsed.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.HeaderGroup: parentGroup.Visible = false; validationGroup.Visible = false; lengthGroup.Visible = false; controlSizeGroup.Visible = false; labelSizeGroup.Visible = false; divGridActive.Visible = false; divIsGrouped.Visible = false; divFilter.Visible = false; divLabelHidden.Visible = false; divComparable.Visible = false; divHiddenField.Visible = true; divReadOnlyField.Visible = false; divIsCloneable.Visible = false; break; case pNums.FieldType.Text: isAutoPostback.Visible = true; placeholderGroup.Visible = true; //JR Bas-Pro-3 divUnique.Visible = true; validationTypeGroup.Visible = true; break; case pNums.FieldType.Number: isAutoPostback.Visible = true; isControlled.Visible = true; if (chkIsControlled.Checked) controlledValue.Visible = true; //JR Bas-Pro-3 divUnique.Visible = true; divCurrency.Visible = true; divBulkUpdate.Visible = true; break; case pNums.FieldType.Decimal: isAutoPostback.Visible = true; divCurrency.Visible = true; divBulkUpdate.Visible = true; break; case pNums.FieldType.Picklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; divBulkUpdate.Visible = true; customSourceOpt.Visible = true; break; case pNums.FieldType.MultiPicklist: lookupGroup.Visible = true; moduleLookupGroup.Visible = true; divAlternateView.Visible = true; lblLookupCat.Text = "Picklist Category"; lengthGroup.Visible = false; isAutoPostback.Visible = true; break; case pNums.FieldType.Date: isAutoPostback.Visible = true; lengthGroup.Visible = false; /* CVH 2016-10-19 Using Default Current checkbox for Grid Default data to master data */ lblDefaultCurrent.Text = "Default"; chkDefaultCurrent.Text = "Current"; defaultDataCurrent.Visible = true; dateTypeGroup.Visible = true; break; case pNums.FieldType.Checkbox: lengthGroup.Visible = false; controlText.Visible = true; isAutoPostback.Visible = true; break; case pNums.FieldType.RadioButtonList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "RadioButtonList Category"; lengthGroup.Visible = false; divAlternateView.Visible = true; customSourceOpt.Visible = true; break; case pNums.FieldType.Button: lengthGroup.Visible = false; controlText.Visible = true; validationGroup.Visible = false; divIsCloneable.Visible = false; break; case pNums.FieldType.Grid: lengthGroup.Visible = false; surfaceApp.Visible = true; validationGroup.Visible = false; /* CVH 2016-10-19 Using Default Current checkbox for Grid Default data to master data */ lblDefaultCurrent.Text = "Default Data"; chkDefaultCurrent.Text = "Copy from master"; dtDefaultDate.Visible = false; defaultDataCurrent.Visible = true; rowLimitGroup.Visible = true; divSummaryGrid.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Attachment: lengthGroup.Visible = false; divIsCloneable.Visible = false; break; case pNums.FieldType.RelationalField: lengthGroup.Visible = false; surfaceApp.Visible = true; surfaceAppFields.Visible = true; validationGroup.Visible = false; divAlternateView.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.FormulaField: break; case pNums.FieldType.Content: content.Visible = true; lengthGroup.Visible = false; validationGroup.Visible = false; break; case pNums.FieldType.Placeholder: lengthGroup.Visible = false; divIsCloneable.Visible = false; break; //JasR 2016-01-27 case pNums.FieldType.Caption: isAutoPostback.Visible = false; placeholderGroup.Visible = true; divBulkUpdate.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Note: lengthGroup.Visible = false; divIsCloneable.Visible = false; break; case pNums.FieldType.Debtors: lengthGroup.Visible = false; mapFieldsGroup.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Mediswitch: lengthGroup.Visible = false; controlText.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Composite: lengthGroup.Visible = false; compositeGroup.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Address: break; case pNums.FieldType.CheckboxList: isAutoPostback.Visible = true; lookupGroup.Visible = true; lblLookupCat.Text = "CheckboxList Category"; lengthGroup.Visible = false; divAlternateView.Visible = true; break; case pNums.FieldType.Sales: lengthGroup.Visible = false; mapFieldsGroup.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Control: divAlternateView.Visible = true; divIsCloneable.Visible = false; controlsGroup.Visible = true; ToggleControlDisplay(); break; case pNums.FieldType.Label: validationGroup.Visible = false; labelSurfaceGroup.Visible = true; labelSourceGroup.Visible = true; divIsCloneable.Visible = false; break; case pNums.FieldType.Image: lblMaxLength.Text = "Max Height"; break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// set action properties /// private void SetActionProperties(int fieldType) { //CVH 2017-06-30 Cleanup. oSurfaceField field = new oSurfaceField(); if (utils.verifySession("surfaceField")) { field = (oSurfaceField)Session["surfaceField"]; } if (field.surfaceId == 0 && utils.verifySession("surfaceId")) field.surfaceId = int.Parse(Session["surfaceId"].ToString()); field.surfaceFieldTypeId = fieldType; //clear all action values //action type actionTypeGroup.Visible = false; ddActionTypes.ClearSelection(); //action actionGroup.Visible = false; ddActions.ClearSelection(); ddActions.Items.Clear(); ClearActionControls(); pNums.FieldType typ = (pNums.FieldType)Enum.ToObject(typeof(pNums.FieldType), field.surfaceFieldTypeId); switch (typ) { case pNums.FieldType.Text: case pNums.FieldType.Number: case pNums.FieldType.Decimal: case pNums.FieldType.Picklist: case pNums.FieldType.MultiPicklist: case pNums.FieldType.Date: case pNums.FieldType.Checkbox: case pNums.FieldType.RadioButtonList: case pNums.FieldType.Grid: case pNums.FieldType.Attachment: case pNums.FieldType.FormulaField: case pNums.FieldType.Caption: case pNums.FieldType.Address: case pNums.FieldType.CheckboxList: actionTypeGroup.Visible = true; if (ddActionTypes.Items.FindByValue(field.actionType.ToString()) != null) { ddActionTypes.SelectedValue = field.actionType.ToString(); BindActions(field.actionType.ToString()); string action = ""; if (ddActions.Items.FindByValue(field.action.ToString()) != null) { ddActions.SelectedValue = field.action.ToString(); if (ddActions.SelectedItem.Value != "0") action = ddActions.SelectedItem.Text; } ToggleAction(field.surfaceId, field.actionType, action, field.actionSource, field.actionValue); } break; } /* actionValueGroup.Visible = false; actionSourceGroup2.Visible = false; actionTypeGroup.Visible = true; if (ddActionTypes.SelectedIndex > 0) { if (ddActionTypes.SelectedValue == pNums.ActionType.ToggleView.GetHashCode().ToString()) actionValueGroup.Visible = true; else if (ddActionTypes.SelectedValue == pNums.ActionType.Button.GetHashCode().ToString()) { actionValueGroup.Visible = true; lblActionValue.InnerText = "Copy Button Text"; } actionGroup.Visible = true; if (ddActions.SelectedIndex > 0) { if (ddActionTypes.SelectedValue == pNums.ActionType.GenerateCode.GetHashCode().ToString() || ddActionTypes.SelectedValue == pNums.ActionType.Styling.GetHashCode().ToString()) actionSourceGroup.Visible = false; else actionSourceGroup.Visible = true; if (ddActions.SelectedItem.Text == "Ranking" || ddActions.SelectedItem.Text == "Divide") actionSourceGroup2.Visible = true; } }*/ } /// /// Clear Action Controls /// private void ClearActionControls() { //action source actionSourceGroup.Visible = false; ddActionSource.ClearSelection(); ddActionSource.Items.Clear(); //action source 2 actionSourceGroup2.Visible = false; ddActionSource2.ClearSelection(); ddActionSource2.Items.Clear(); //action value actionValueGroup.Visible = false; txtActionValue.Text = ""; //field aggregation fieldAggregationGroup.Visible = false; lstFieldAggregation.ClearSelection(); lstFieldAggregation.Items.Clear(); //styling text stylingTextColourGroup.Visible = false; txtStylingTextColourValue.Text = ""; //aggregation aggregationSurfaceGroup.Visible = false; ddAggregationSurface.ClearSelection(); ddAggregationSurface.Items.Clear(); //lookup calc lookupCalcSurfaceGroup.Visible = false; ddLookupCalcSurface.ClearSelection(); ddLookupCalcSurface.Items.Clear(); //lookup calc field lookupCalcSurfaceFieldGroup.Visible = false; ddLookupCalcSurfaceField.ClearSelection(); ddLookupCalcSurfaceField.Items.Clear(); } /// /// Replaces SetActionFieldValues /// private void ToggleAction(int surfaceId, int actionType, string action, int actionSource, string actionValue) { try { ClearActionControls(); if (actionType == pNums.ActionType.Button.GetHashCode()) lblActionValue.InnerText = "Copy Button Text"; else lblActionValue.InnerHtml = "Value use delimiter ;"; lblddActionSource2.Text = "Divide By"; switch (action) { case "VAT": BindActionSource(pNums.FieldType.Decimal.GetHashCode().ToString()); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); break; case "Age": BindActionSource(pNums.FieldType.Date.GetHashCode().ToString() + "|" + pNums.FieldType.Text.GetHashCode().ToString()); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); break; case "Gender": BindActionSource(pNums.FieldType.Text.GetHashCode().ToString()); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); break; case "Copy": string destType = ddFieldTypes.SelectedValue; BindActionSource(destType); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); txtActionValue.Text = actionValue; actionValueGroup.Visible = true; break; case "Visible": //CVH 2016-10-10 Only catering for fieldtype Checkboxlist and RadioButtonList //CVH 2017-01-18 Add toggle view for picklist //CVH 2017-02-15 Add toggle view for grid BindActionSource(pNums.FieldType.CheckboxList.GetHashCode().ToString() + "|" + pNums.FieldType.RadioButtonList.GetHashCode().ToString() + "|" + pNums.FieldType.Picklist.GetHashCode().ToString() + "|" + pNums.FieldType.Grid.GetHashCode(), surfaceId); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); txtActionValue.Text = actionValue; actionValueGroup.Visible = true; break; case "Divide": BindActionSource(pNums.FieldType.Text.GetHashCode().ToString() + "|" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString(), surfaceId, true); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); actionSourceGroup2.Visible = true; if (ddActionSource2.Items.FindByValue(actionValue) != null) ddActionSource2.Items.FindByValue(actionValue).Selected = true; break; case "Lookup": BindActionSource(pNums.FieldType.Text.GetHashCode().ToString() + "|" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString() + "|" + pNums.FieldType.FormulaField.GetHashCode().ToString(), surfaceId); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); BindLookupCalcSurface(); lookupCalcSurfaceGroup.Visible = true; if (ddLookupCalcSurface.Items.FindByValue(actionValue) != null) ddLookupCalcSurface.Items.FindByValue(actionValue).Selected = true; break; case "Lookup Field": BindActionSource(pNums.FieldType.Text.GetHashCode().ToString() + "|" + pNums.FieldType.Picklist.GetHashCode().ToString() + "|" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString() + "|" + pNums.FieldType.FormulaField.GetHashCode().ToString(), surfaceId); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); BindLookupCalcSurface(); lookupCalcSurfaceGroup.Visible = true; if (actionValue != "") { foreach (oSurfaceField lookupField in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", actionValue)) { if (ddLookupCalcSurface.Items.FindByValue(lookupField.surfaceId.ToString()) != null) { ddLookupCalcSurface.Items.FindByValue(lookupField.surfaceId.ToString()).Selected = true; BindLookupCalcSurfaceFields(lookupField.surfaceId.ToString()); lookupCalcSurfaceFieldGroup.Visible = true; if (ddLookupCalcSurfaceField.Items.FindByValue(lookupField.recId.ToString()) != null) ddLookupCalcSurfaceField.Items.FindByValue(lookupField.recId.ToString()).Selected = true; } } } break; case "Sum": //Aggregation Sum (could be a Calculation Sum later) if (actionType == (int)pNums.ActionType.Aggregation) { actionSourceGroup.Visible = false; actionSourceGroup2.Visible = false; BindAggregationSurface(); aggregationSurfaceGroup.Visible = true; if (ddAggregationSurface.Items.FindByValue(actionValue) != null) { ddAggregationSurface.Items.FindByValue(actionValue).Selected = true; BindActionSource(pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString(), int.Parse(actionValue)); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.Items.FindByValue(actionSource.ToString()).Selected = true; } } else if (actionType == (int)pNums.ActionType.FieldAggregation) { fieldAggregationGroup.Visible = true; BindFieldAggregationList(); foreach (string fields in actionValue.Split('|')) { if (lstFieldAggregation.Items.FindByValue(fields) != null) { lstFieldAggregation.Items.FindByValue(fields).Selected = true; } } } break; case "Text Colour": stylingTextColourGroup.Visible = true; ddStylingTextColourRule.ClearSelection(); txtStylingTextColourValue.Text = ""; ddStylingTextColourColour.ClearSelection(); if (actionValue != String.Empty) { // Rule|Value|Colour eg "<|60|Red" int styleCount = 0; foreach (string style in actionValue.Split('|')) { if (styleCount == 0) { if (style == "<" && ddStylingTextColourRule.Items.FindByValue("Less Than") != null) ddStylingTextColourRule.Items.FindByValue("Less Than").Selected = true; } else if (styleCount == 1) { txtStylingTextColourValue.Text = style; } else if (styleCount == 2) { if (ddStylingTextColourColour.Items.FindByValue(style) != null) ddStylingTextColourColour.Items.FindByValue(style).Selected = true; } styleCount++; } } break; case "Average": if (actionType == (int)pNums.ActionType.FieldAggregation) { fieldAggregationGroup.Visible = true; BindFieldAggregationList(); foreach (string fields in actionValue.Split('|')) { if (lstFieldAggregation.Items.FindByValue(fields) != null) { lstFieldAggregation.Items.FindByValue(fields).Selected = true; } } } break; case "Ranking": BindActionSource(pNums.FieldType.FormulaField.GetHashCode().ToString() + "|" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString(), surfaceId); if (ddActionSource.Items.FindByValue(actionSource.ToString()) != null) ddActionSource.SelectedValue = actionSource.ToString(); DataTable actionSourceData = new DataTable(); if (surfaceId == 0) actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive", "1", "recId"); else actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceId", "1," + surfaceId.ToString(), "recId"); ddActionSource2.DataSource = actionSourceData; ddActionSource2.DataTextField = "surfaceFieldName"; ddActionSource2.DataValueField = "recId"; ddActionSource2.DataBind(); if (ddActionSource2.Items.FindByValue(actionValue) != null) ddActionSource2.Items.FindByValue(actionValue).Selected = true; lblddActionSource2.Text = "Group By"; actionSourceGroup2.Visible = true; break; case "Distinction Count": case "Failed Count": case "Passed Count": if (actionType == (int)pNums.ActionType.FieldAggregation) { fieldAggregationGroup.Visible = true; BindFieldAggregationList(); foreach (string fields in actionValue.Split('|')) { if (lstFieldAggregation.Items.FindByValue(fields) != null) { lstFieldAggregation.Items.FindByValue(fields).Selected = true; } } } break; case "Difference": if (actionType == (int)pNums.ActionType.FieldAggregation) { fieldAggregationGroup.Visible = true; BindFieldAggregationList(); foreach (string fields in actionValue.Split('|')) { if (lstFieldAggregation.Items.FindByValue(fields) != null) { lstFieldAggregation.Items.FindByValue(fields).Selected = true; } } } break; default: break; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Field Aggregation List /// private void BindFieldAggregationList() { try { if (utils.verifySession("surface")) { oSurface surface = (oSurface)Session["surface"]; DataTable FieldTable = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", surface.recId.ToString() + ",~()4|5|14", "surfaceFieldName"); lstFieldAggregation.DataSource = FieldTable; lstFieldAggregation.DataTextField = "surfaceFieldName"; lstFieldAggregation.DataValueField = "recId"; lstFieldAggregation.DataBind(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Populate Form Values /// /// private void PopulateFieldFormValues(ref oSurfaceField _SurfaceField) { try { chkActiveField.Checked = _SurfaceField.isActive; chkGridActive.Checked = _SurfaceField.isGrid; chkIsGrouped.Checked = _SurfaceField.isGrouped; chkFilter.Checked = _SurfaceField.isFilter; chkRequired.Checked = _SurfaceField.required; chkIsAutoPostback.Checked = _SurfaceField.isAutoPostback; chkDefaultCurrent.Checked = _SurfaceField.defaultToCurrent; dtDefaultDate.Text = _SurfaceField.defaultValue; chkHiddenField.Checked = _SurfaceField.isHidden; chkHiddenWizzard.Checked = _SurfaceField.isHiddenFromWizzard; chkHiddenView.Checked = _SurfaceField.isHiddenFromView; chkHiddenForm.Checked = _SurfaceField.isHiddenFromForm; chkReadOnlyField.Checked = _SurfaceField.isReadOnly; //JR Bas-Pro-3 chkUnique.Checked = _SurfaceField.isUnique; chkComparable.Checked = _SurfaceField.isComparable; chkAlternateView.Checked = _SurfaceField.alternateView; chkLabelHidden.Checked = _SurfaceField.isLabelHidden; //CVH 2016-12-12 chkGroupDefaultCollapsed.Checked = false; if (_SurfaceField.surfaceFieldTypeId == pNums.FieldType.Group.GetHashCode()) chkGroupDefaultCollapsed.Checked = _SurfaceField.isControlled; chkNewLine.Checked = _SurfaceField.isOnNewLine; chkBottomBorder.Checked = _SurfaceField.hasBottomBorder; chkFullBorder.Checked = _SurfaceField.hasFullBorder; txtLength.Value = _SurfaceField.length.ToString(); txtDisplay.Value = _SurfaceField.surfaceFieldDisplay; txtPlaceholder.Value = _SurfaceField.placeholder; txtRowLimit.Value = _SurfaceField.relationalValues; if (ddFieldTypes.Items.FindByValue(_SurfaceField.surfaceFieldTypeId.ToString()) != null) ddFieldTypes.SelectedValue = _SurfaceField.surfaceFieldTypeId.ToString(); BindParentFields(); if (ddParentFields.Items.FindByValue(_SurfaceField.parentId.ToString()) != null) ddParentFields.Items.FindByValue(_SurfaceField.parentId.ToString()).Selected = true; if (_SurfaceField.sequence > 0) ddSequence.SelectedItem.Text = _SurfaceField.sequence.ToString(); if (_SurfaceField.gridSequence > 0) ddGridSequence.SelectedItem.Text = _SurfaceField.gridSequence.ToString(); if (_SurfaceField.accessLevel > 0 && ddAccessLevel.Items.FindByValue(_SurfaceField.accessLevel.ToString()) != null) ddAccessLevel.SelectedValue = _SurfaceField.accessLevel.ToString(); ddLookupCategory.SelectedValue = _SurfaceField.lookupCategory.ToString(); ddModuleLookup.ClearSelection(); moduleSurfaceGroup.Visible = false; if (_SurfaceField.relationalObject.ToString().Length > 0 && ddModuleLookup.Items.FindByValue(_SurfaceField.relationalObject.ToString()) != null) { ddModuleLookup.SelectedValue = _SurfaceField.relationalObject.ToString(); if (ddModuleLookup.SelectedItem.Text == "Surface") { moduleSurfaceGroup.Visible = true; ddModuleSurface.ClearSelection(); ddModuleSurface.Items.Clear(); BindModuleSurface(); if (_SurfaceField.relationalFields != String.Empty) { int modSurfField = 0; if (int.TryParse(_SurfaceField.relationalFields, out modSurfField)) { foreach (oSurfaceField fld in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", modSurfField.ToString())) { if (ddModuleSurface.Items.FindByValue(fld.surfaceId.ToString()) != null) { ddModuleSurface.Items.FindByValue(fld.surfaceId.ToString()).Selected = true; ddModuleSurfaceField.ClearSelection(); ddModuleSurfaceField.Items.Clear(); BindModuleSurfaceFields(fld.surfaceId); if (ddModuleSurfaceField.Items.FindByValue(fld.recId.ToString()) != null) ddModuleSurfaceField.Items.FindByValue(fld.recId.ToString()).Selected = true; } break; } } } } } if (_SurfaceField.relationalSurface.ToString().Length > 0 && ddLabelSurface.Items.FindByValue(_SurfaceField.relationalSurface.ToString()) != null) { ddLabelSurface.SelectedValue = _SurfaceField.relationalSurface.ToString(); if (ddLabelSurface.SelectedValue != "user" && ddLabelSurface.SelectedValue != "date" && ddLabelSurface.SelectedValue != "static") { BindLabelSourceFields(ddLabelSurface.SelectedValue); labelSourceGroup.Visible = true; labelStaticGroup.Visible = false; } if (ddLabelSurface.SelectedValue == "static") { labelSourceGroup.Visible = false; labelStaticGroup.Visible = true; txtStaticLabel.Text = _SurfaceField.relationalValues; } } if (_SurfaceField.relationalSurface.ToString().Length > 0 && ddLabelSurface.Items.FindByValue(_SurfaceField.relationalSurface.ToString()) != null && _SurfaceField.relationalFields.ToString().Length > 0 && ddLabelSource.Items.FindByValue(_SurfaceField.relationalFields.ToString()) != null) ddLabelSource.SelectedValue = _SurfaceField.relationalFields.ToString(); ddFieldSize.SelectedValue = "6"; if (_SurfaceField.surfaceFieldSize > 0 && ddFieldSize.Items.FindByValue(_SurfaceField.surfaceFieldSize.ToString()) != null) ddFieldSize.SelectedValue = _SurfaceField.surfaceFieldSize.ToString(); ddLabelSize.SelectedValue = "4"; if (_SurfaceField.labelSize > 0 && ddLabelSize.Items.FindByValue(_SurfaceField.labelSize.ToString()) != null) ddLabelSize.SelectedValue = _SurfaceField.labelSize.ToString(); /* CVH 2016-01-22 RelField */ if (ddSurfaceApps.Items.FindByValue(_SurfaceField.relationalSurface) != null) { ddSurfaceApps.SelectedValue = _SurfaceField.relationalSurface; BindSurfaceAppFields(_SurfaceField.relationalSurface); } else { ddSurfaceApps.SelectedValue = "0"; } /* CVH 2016-01-22 RelField */ if (ddSurfaceAppFields.Items.FindByValue(_SurfaceField.relationalFields) != null) ddSurfaceAppFields.SelectedValue = _SurfaceField.relationalFields; else ddSurfaceAppFields.SelectedValue = "0"; if (_SurfaceField.contentId != 0) { if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) ddContent.SelectedValue = _SurfaceField.contentId.ToString(); if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) ddComposite.SelectedValue = _SurfaceField.contentId.ToString(); } chkIsControlled.Checked = _SurfaceField.isControlled; if (chkIsControlled.Checked) { controlledValue.Visible = true; } else controlledValue.Visible = false; txtControlledValue.Value = _SurfaceField.controlledValue; txtControlText.Value = _SurfaceField.controlText; actionTypeGroup.Visible = false; actionGroup.Visible = false; actionSourceGroup.Visible = false; actionValueGroup.Visible = false; actionSourceGroup2.Visible = false; lookupCalcSurfaceGroup.Visible = false; lookupCalcSurfaceFieldGroup.Visible = false; stylingTextColourGroup.Visible = false; //CVH 2017-06-30 Cleanup - Action properties are set in SetActinProperties called from ToggleFieldType (always called after Populate is called) //if (//_SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Attachment && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Button && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Composite && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Content && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Debtors && // //_SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Grid && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Group && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.HeaderGroup && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Image && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Mediswitch && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Note && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Placeholder && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.RelationalField && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Tab && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Sales && // _SurfaceField.surfaceFieldTypeId != (int)pNums.FieldType.Control) //{ // SetActionFieldValues(_SurfaceField); //} mapFieldsGroup.Visible = false; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Sales || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Debtors) mapFieldsGroup.Visible = true; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Control) { controlsGroup.Visible = true; if (ddControls.Items.FindByValue(_SurfaceField.controlledValue) != null) { ddControls.SelectedValue = _SurfaceField.controlledValue; ToggleControlDisplay(); //CVH 2017-05-23 Surface Notes - Confidential if (_SurfaceField.controlledValue == pNums.Module.SurfaceNotes.GetHashCode().ToString()) { chkIsConfidential.Checked = _SurfaceField.isControlled; chkIsControlled.Checked = false; isControlled.Visible = false; } } else { ddControls.SelectedValue = "0"; } //GR 2017-08-04 Included Configration options for Surface Signature if (int.Parse(ddControls.SelectedValue) == (int)pNums.Module.SurfaceSignature) { foreach (oSurfaceSignatureConfig conf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceSignatureConfig), "fieldId", _SurfaceField.recId.ToString())) { txtSigLabelText.Value = conf.labelText; txtSigDisclaimerText.Value = conf.disclaimer; chkSigIncludePhoto.Checked = conf.includePhoto; chkSigAllowPhotoEdit.Checked = conf.allowPhotoEdit; chkSigAllowSignatureEdit.Checked = conf.allowSignatureEdit; break; } } //GR 2017-10-27 Included Configration options for Surface Drawing if (int.Parse(ddControls.SelectedValue) == (int)pNums.Module.SurfaceDrawing) { foreach (oSurfaceDrawingConfig conf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceDrawingConfig), "fieldId", _SurfaceField.recId.ToString(), "")) { imgDrawing.ImageUrl = "~/upload/" + conf.placeholder; break; } } } if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { dateTypeGroup.Visible = true; if (ddSurfaceDateType.Items.FindByValue(_SurfaceField.surfaceDateTypeId.ToString()) != null) ddSurfaceDateType.SelectedValue = _SurfaceField.surfaceDateTypeId.ToString(); else ddSurfaceDateType.SelectedIndex = 0; } if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Text) { if (ddlValidationType.Items.FindByValue(_SurfaceField.validationType.ToString()) != null) ddlValidationType.SelectedValue = _SurfaceField.validationType.ToString(); } else ddlValidationType.SelectedValue = "0"; chkBulkUpdate.Checked = _SurfaceField.enableBulkUpdate; chkCurrency.Checked = _SurfaceField.isCurrency; chkVerticalHeader.Checked = _SurfaceField.isVerticalHeader; chkSummaryGrid.Checked = false; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid) chkSummaryGrid.Checked = _SurfaceField.isControlled; chkIsCloneable.Checked = _SurfaceField.isCloneable; //GR 2017-07-04 Custom source chkUseCustomSource.Checked = _SurfaceField.isCustomSource; ToggleCustomSource(); if (_SurfaceField.isCustomSource) { ddCustomSource.SelectedValue = _SurfaceField.relationalObject; BindCustomSourceFields(); String[] fields = _SurfaceField.relationalFields.Split(char.Parse(",")); foreach (string fld in fields) { foreach (ListItem item in lstRelationalFieldDisplay.Items) { if (item.Value == fld) { item.Selected = true; break; } } } if (ddRelationalFieldValue.Items.FindByValue(_SurfaceField.relationalValues.ToString()) != null) ddRelationalFieldValue.SelectedValue = _SurfaceField.relationalValues; txtRelationalOrderBy.Text = _SurfaceField.relationalOrderBy; txtRelationalWhere.Text = _SurfaceField.relationalWhere; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind fields for selected custom source table /// private void BindCustomSourceFields() { SqlCommand command = new SqlCommand(); try { ArrayList fields = new ArrayList(); if (ddCustomSource.SelectedValue != "") { command = dataTier.CommandMethods.BeginSQLCommand(); fields = constructor.GetTableFields(ddCustomSource.SelectedValue, ref command); lstRelationalFieldDisplay.DataTextField = "fieldName"; lstRelationalFieldDisplay.DataValueField = "fieldName"; ddRelationalFieldValue.DataTextField = "fieldName"; ddRelationalFieldValue.DataValueField = "fieldName"; } lstRelationalFieldDisplay.DataSource = fields; lstRelationalFieldDisplay.DataBind(); ddRelationalFieldValue.DataSource = fields; ddRelationalFieldValue.DataBind(); ddRelationalFieldValue.Items.Insert(0, new ListItem("select", "")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } finally { dataTier.CommandMethods.CompleteSQLCommand(ref command); } } /// /// Toggle Field State for Published Apps /// /// private void ToggleFieldStatePublished(bool isNew) { oSurface _surface = new oSurface(); bool _enable = true; if (utils.verifySession("surface")) { _surface = (oSurface)Session["surface"]; } if (_surface.isPublished && !Debugger.IsAttached)//check if published and not debugging { _enable = isNew; } txtDisplay.Disabled = !_enable; ddFieldTypes.Enabled = _enable; ddParentFields.Enabled = _enable; ddControls.Enabled = _enable; ddSurfaceDateType.Enabled = _enable; ddLabelSurface.Enabled = _enable; ddLabelSource.Enabled = _enable; txtStaticLabel.Enabled = _enable; ddLookupCategory.Enabled = _enable; btnManagePicklists.Enabled = _enable; ddModuleLookup.Enabled = _enable; ddModuleSurface.Enabled = _enable; ddModuleSurfaceField.Enabled = _enable; chkUseCustomSource.Enabled = _enable; ddCustomSource.Enabled = _enable; lstRelationalFieldDisplay.Enabled = _enable; ddRelationalFieldValue.Enabled = _enable; txtRelationalWhere.Enabled = _enable; txtRelationalOrderBy.Enabled = _enable; ddComposite.Enabled = _enable; chkIsControlled.Enabled = _enable; txtControlledValue.Disabled = !_enable; txtLength.Disabled = !_enable; chkActiveField.Enabled = _enable; //chkHiddenField.Enabled = _enable; chkComparable.Enabled = _enable; chkCurrency.Enabled = _enable; chkSummaryGrid.Enabled = _enable; } /// /// Upload Image Map Control Image /// /// private void UploadImageMapControlImage(ref oSurfaceField _field) { try { if (radImageMapUpload.UploadedFiles.Count > 0) { foreach (UploadedFile file in radImageMapUpload.UploadedFiles) { _field.placeholder = file.FileName; string fileName = _field.placeholder; string uploadPath = Server.MapPath("~/upload/image/"); utils.validateFolder(uploadPath); //upload file file.SaveAs(uploadPath + fileName); } } } catch (Exception ex) { exception.HandleException("Promotions:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Form Values /// /// private void SaveFieldFormValues(ref oSurfaceField _SurfaceField) { try { _SurfaceField.isActive = chkActiveField.Checked; _SurfaceField.isFilter = chkFilter.Checked; _SurfaceField.isGrid = chkGridActive.Checked; _SurfaceField.isGrouped = chkIsGrouped.Checked; _SurfaceField.required = chkRequired.Checked; _SurfaceField.isAutoPostback = chkIsAutoPostback.Checked; _SurfaceField.isHidden = chkHiddenField.Checked; _SurfaceField.isHiddenFromWizzard = chkHiddenWizzard.Checked; _SurfaceField.isHiddenFromView = chkHiddenView.Checked; _SurfaceField.isHiddenFromForm = chkHiddenForm.Checked; _SurfaceField.isReadOnly = chkReadOnlyField.Checked; //JR Bas-Pro-3 _SurfaceField.isUnique = chkUnique.Checked; _SurfaceField.isComparable = chkComparable.Checked; _SurfaceField.alternateView = chkAlternateView.Checked; _SurfaceField.isLabelHidden = chkLabelHidden.Checked; _SurfaceField.isOnNewLine = chkNewLine.Checked; _SurfaceField.hasBottomBorder = chkBottomBorder.Checked; _SurfaceField.hasFullBorder = chkFullBorder.Checked; int length = 0; int.TryParse(txtLength.Value, out length); _SurfaceField.length = length; int accessType = 0; int.TryParse(ddAccessLevel.SelectedValue, out accessType); _SurfaceField.accessLevel = accessType; int parent = 0; int.TryParse(ddParentFields.SelectedValue, out parent); _SurfaceField.parentId = parent; int seq = 0; int.TryParse(ddSequence.SelectedItem.Text, out seq); _SurfaceField.sequence = seq; int gSeq = 0; int.TryParse(ddGridSequence.SelectedItem.Text, out gSeq); _SurfaceField.gridSequence = gSeq; _SurfaceField.surfaceFieldDisplay = txtDisplay.Value; _SurfaceField.placeholder = txtPlaceholder.Value; int fieldType = 0; int.TryParse(ddFieldTypes.SelectedValue, out fieldType); _SurfaceField.surfaceFieldTypeId = fieldType; //GR 2017-07-05 reset custom source if not selected as these properties may be used if (!chkUseCustomSource.Checked) { _SurfaceField.relationalObject = String.Empty; _SurfaceField.relationalFields = String.Empty; _SurfaceField.relationalValues = String.Empty; _SurfaceField.relationalOrderBy = String.Empty; _SurfaceField.relationalWhere = String.Empty; } if (ddFieldTypes.SelectedValue != pNums.FieldType.Tab.GetHashCode().ToString()) { if (ddFieldTypes.SelectedValue != pNums.FieldType.Group.GetHashCode().ToString() && ddFieldTypes.SelectedValue != pNums.FieldType.HeaderGroup.GetHashCode().ToString()) { int groupId = 0; string tabName = String.Empty; if (ddParentFields.SelectedValue != null) { groupId = int.Parse(ddParentFields.SelectedValue); foreach (oSurfaceField grp in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", groupId.ToString())) { if (grp.surfaceFieldTypeId != (int)pNums.FieldType.HeaderGroup) foreach (oSurfaceField tab in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", grp.parentId.ToString())) { tabName = utils.stripCharacters(tab.surfaceFieldDisplay).Replace(" ", "") + "_"; } } } bool updateFieldName = true; if (_SurfaceField.recId > 0)//update mode { oSurface surface = new oSurface(); if (utils.verifySession("surface")) { surface = (oSurface)Session["surface"]; if (surface.isPublished && !Debugger.IsAttached)//is published and not debugging so dont change field name updateFieldName = false; } } if (updateFieldName) { _SurfaceField.surfaceFieldName = tabName + utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } } else { _SurfaceField.surfaceFieldName = utils.stripCharacters(ddParentFields.SelectedItem.Text).Replace(" ", "") + "_" + utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } } else { //CVH 2017-02-14 Subtab. No change, will save subtab with just tab name, will ID it by parentId <> 0 _SurfaceField.surfaceFieldName = utils.stripCharacters(txtDisplay.Value).Replace(" ", ""); } _SurfaceField.lookupCategory = int.Parse(ddLookupCategory.SelectedValue); if (ddModuleLookup.SelectedIndex > 0) { _SurfaceField.relationalObject = ddModuleLookup.SelectedValue; if (ddModuleLookup.SelectedItem.Text == "Surface" && moduleSurfaceGroup.Visible && ddModuleSurfaceField.SelectedItem != null) { _SurfaceField.relationalFields = ddModuleSurfaceField.SelectedItem.Value; } } string relationalSurface = ""; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField) { relationalSurface = ddSurfaceApps.SelectedValue; /* CVH 2016-07-21 Link grid surface app to parent surface by adding hidden field to grid surface */ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid) { SaveGridFieldSurfaceLink(relationalSurface); /* CVH 2016-10-19 Allow option to copy data from master data (where parent Id = 0) */ _SurfaceField.defaultToCurrent = chkDefaultCurrent.Checked; _SurfaceField.relationalValues = txtRowLimit.Value; } } _SurfaceField.relationalSurface = relationalSurface; _SurfaceField.surfaceFieldSize = Convert.ToInt32(ddFieldSize.SelectedValue); _SurfaceField.labelSize = Convert.ToInt32(ddLabelSize.SelectedValue); /* CVH 2016-01-22 RelField */ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.RelationalField) _SurfaceField.relationalFields = ddSurfaceAppFields.SelectedValue; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Label) { _SurfaceField.relationalSurface = ddLabelSurface.SelectedValue; _SurfaceField.relationalFields = ddLabelSource.SelectedValue; _SurfaceField.relationalValues = txtStaticLabel.Text; } /*JasR 2016-01-13*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Content) { int contentID = 0; int.TryParse(ddContent.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } /*JasR 2016-01-15*/ if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Date) { _SurfaceField.defaultToCurrent = chkDefaultCurrent.Checked; if (ddSurfaceDateType.SelectedItem != null) _SurfaceField.surfaceDateTypeId = int.Parse(ddSurfaceDateType.SelectedValue); _SurfaceField.defaultValue = dtDefaultDate.Text; } /*JasR 2016-01-15*/ _SurfaceField.isControlled = false; _SurfaceField.controlledValue = ""; if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Number) { _SurfaceField.isControlled = chkIsControlled.Checked; _SurfaceField.controlledValue = txtControlledValue.Value; } else if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Group) { _SurfaceField.isControlled = chkGroupDefaultCollapsed.Checked; } //CVH 2017-02-28 Using isControlled to indicate that grid is summarized values of a child grid else if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Grid) { if (divSummaryGrid.Visible) _SurfaceField.isControlled = chkSummaryGrid.Checked; } //CVH 2017-02-28 Moved this here, to keep all isControlled values together, in case we overriding it unintentionally else if (_SurfaceField.actionType == pNums.ActionType.GenerateCode.GetHashCode()) { _SurfaceField.isControlled = true; } if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Control) { int controlID = 0; int.TryParse(ddControls.SelectedValue, out controlID); _SurfaceField.controlledValue = controlID.ToString(); if (controlID == pNums.Module.ImageMap.GetHashCode()) { UploadImageMapControlImage(ref _SurfaceField); } else if (controlID == pNums.Module.SurfaceNotes.GetHashCode()) { _SurfaceField.isControlled = chkIsConfidential.Checked; } } /*JasR 2016-01-16*/ //if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Button || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Checkbox || _SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Mediswitch) //{ _SurfaceField.controlText = txtControlText.Value; //} if (_SurfaceField.surfaceFieldTypeId == (int)pNums.FieldType.Composite) { int contentID = 0; int.TryParse(ddComposite.SelectedValue, out contentID); _SurfaceField.contentId = contentID; } //CVH 2016-11-14 Only save action values when the div is visible, otherwise it saves values incorrectly if (actionSourceGroup.Visible && ddActionSource.SelectedValue != null && ddActionSource.SelectedValue != "") _SurfaceField.actionSource = Convert.ToInt32(ddActionSource.SelectedValue); else _SurfaceField.actionSource = 0; if (actionGroup.Visible && ddActions.SelectedValue != null && ddActions.SelectedValue != "") _SurfaceField.action = Convert.ToInt32(ddActions.SelectedValue); else _SurfaceField.action = 0; if (actionTypeGroup.Visible && ddActionTypes.SelectedValue != null && ddActionTypes.SelectedValue != "") { _SurfaceField.actionType = Convert.ToInt32(ddActionTypes.SelectedValue); _SurfaceField.actionValue = ""; if (actionValueGroup.Visible && (_SurfaceField.actionType == pNums.ActionType.ToggleView.GetHashCode() || _SurfaceField.actionType == pNums.ActionType.Button.GetHashCode())) { _SurfaceField.actionValue = txtActionValue.Text; } else if (lookupCalcSurfaceGroup.Visible && ddLookupCalcSurface.SelectedItem != null && _SurfaceField.actionType == pNums.ActionType.Calculation.GetHashCode()) { if (lookupCalcSurfaceFieldGroup.Visible && ddLookupCalcSurfaceField.SelectedItem != null) _SurfaceField.actionValue = ddLookupCalcSurfaceField.SelectedItem.Value.ToString(); else _SurfaceField.actionValue = ddLookupCalcSurface.SelectedItem.Value.ToString(); } else if (actionSourceGroup2.Visible && ddActionSource2.SelectedItem != null && _SurfaceField.actionType == pNums.ActionType.Calculation.GetHashCode()) { _SurfaceField.actionValue = ddActionSource2.SelectedItem.Value; } //CVH 2017-02-21 Aggregation Sum if (_SurfaceField.actionType == (int)pNums.ActionType.Aggregation && ddAggregationSurface.SelectedItem != null) { _SurfaceField.actionValue = ddAggregationSurface.SelectedItem.Value; } //CVH 2017-03-16 Styling Text Colour else if (_SurfaceField.actionType == (int)pNums.ActionType.Styling && stylingTextColourGroup.Visible) { // Rule|Value|Colour eg "<|60|Red" string stylingRule = ""; if (ddStylingTextColourRule.SelectedItem != null) { if (ddStylingTextColourRule.SelectedItem.Value == "Less Than") stylingRule = "<"; } string stylingValue = txtStylingTextColourValue.Text; string stylingColour = ""; if (ddStylingTextColourColour.SelectedItem != null) stylingColour = ddStylingTextColourColour.SelectedItem.Value; _SurfaceField.actionValue = stylingRule + "|" + stylingValue + "|" + stylingColour; } else if (_SurfaceField.actionType == (int)pNums.ActionType.FieldAggregation && lstFieldAggregation.SelectedItem != null) { string actionValue = ""; foreach (ListItem item in lstFieldAggregation.Items.GetSelectedItems()) { if (item.Selected) actionValue += item.Value.ToString() + "|"; } _SurfaceField.actionValue = actionValue; } } else { _SurfaceField.actionType = 0; _SurfaceField.actionValue = ""; } _SurfaceField.validationType = Convert.ToInt32(ddlValidationType.SelectedValue); _SurfaceField.enableBulkUpdate = false; if (divBulkUpdate.Visible) _SurfaceField.enableBulkUpdate = chkBulkUpdate.Checked; _SurfaceField.isCurrency = false; if (divCurrency.Visible) _SurfaceField.isCurrency = chkCurrency.Checked; _SurfaceField.isVerticalHeader = chkVerticalHeader.Checked; _SurfaceField.isCloneable = false; if (divIsCloneable.Visible) _SurfaceField.isCloneable = chkIsCloneable.Checked; //GR 2017-07-04 Custom source _SurfaceField.isCustomSource = chkUseCustomSource.Checked; if (_SurfaceField.isCustomSource) { _SurfaceField.relationalObject = ddCustomSource.SelectedValue; var fields = lstRelationalFieldDisplay.Items.GetSelectedItems(); _SurfaceField.relationalFields = String.Join(",", fields.Select(x => x.Value).ToArray()); _SurfaceField.relationalValues = ddRelationalFieldValue.SelectedValue; _SurfaceField.relationalOrderBy = txtRelationalOrderBy.Text; _SurfaceField.relationalWhere = txtRelationalWhere.Text; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Saves new surface field in Grid Surface app, hidden, links to parent (current) surface app /// private void SaveGridFieldSurfaceLink(string gridSurfaceName) { //check if there is existing field ArrayList linkSurface = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", gridSurfaceName); if (linkSurface == null || linkSurface.Count <= 0) throw new Exception("Grid field linked surface could not be determined."); oSurface gridSurface = (oSurface)linkSurface[0]; ArrayList linkFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldDisplay", gridSurface.recId + ",ParentSurfaceItemId"); if (linkFields != null && linkFields.Count > 0) return; if (utils.verifySession("surface")) { oSurface surface = (oSurface)Session["surface"]; //get first visible group field on grid surface to link hidden field to ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", gridSurface.recId + ",1," + pNums.FieldType.Group.GetHashCode(), "sequence"); if (list == null || list.Count <= 0) throw new Exception("Group surface field for grid surface could not be determined."); oSurfaceField gridGroupField = (oSurfaceField)list[0]; oSurfaceField field = new oSurfaceField(); field.defaultToCurrent = false; field.isActive = true; field.isAutoPostback = false; field.isControlled = false; field.isFilter = false; field.isGrid = false; field.isHidden = true; field.isReadOnly = true; field.length = 0; field.lookupCategory = 0; field.parentId = gridGroupField.recId; field.relationalSurface = surface.name; field.sequence = 0; field.surfaceFieldDisplay = "ParentSurfaceItemId"; field.surfaceFieldName = "ParentSurfaceItemId"; field.surfaceFieldTypeId = pNums.FieldType.Number.GetHashCode(); field.surfaceId = gridGroupField.surfaceId; field.recId = xData.SaveTyped("recId", typeof(oSurfaceField), field); } else throw new Exception("Grid field parent surface could not be determined."); } /// /// Bind Composite Items /// private void BindComposite() { try { ArrayList compositeItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oComposite), "", "", "composite"); ddComposite.DataSource = compositeItems; ddComposite.DataTextField = "composite"; ddComposite.DataValueField = "canvasId"; ddComposite.DataBind(); ddComposite.Items.Insert(0, new ListItem("Select Composite", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// toggle Custom source /// private void ToggleCustomSource() { try { if (chkUseCustomSource.Checked) { lookupGroup.Visible = false; moduleLookupGroup.Visible = false; customSourceOpt.Visible = true; customSourceLookup.Visible = true; customSourceFieldDisplay.Visible = true; customSourceFieldValue.Visible = true; customSourceWhere.Visible = true; customSourceOrderBy.Visible = true; } else { lookupGroup.Visible = true; moduleLookupGroup.Visible = true; customSourceLookup.Visible = false; customSourceFieldDisplay.Visible = false; customSourceFieldValue.Visible = false; customSourceWhere.Visible = false; customSourceOrderBy.Visible = false; } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind fields for selected custom source table /// private void BindCustomSourceTables() { SqlCommand command = new SqlCommand(); try { DataTable dtTables = constructor.GetTables().Tables[0]; ddCustomSource.DataSource = dtTables; ddCustomSource.DataValueField = "tableName"; ddCustomSource.DataTextField = "tableName"; ddCustomSource.DataBind(); ddCustomSource.Items.Insert(0, new ListItem("select source", "")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } finally { dataTier.CommandMethods.CompleteSQLCommand(ref command); } } /// /// Bind Surface App Fields /// private void BindSurfaceAppFields(string surfaceName) { try { foreach (oSurface surface in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", surfaceName)) { ArrayList surfaceAppFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,isActive,surfaceFieldTypeId", surface.recId + ",1,~>2"); ddSurfaceAppFields.DataSource = surfaceAppFields; ddSurfaceAppFields.DataTextField = "surfaceFieldDisplay"; ddSurfaceAppFields.DataValueField = "recId"; ddSurfaceAppFields.DataBind(); } ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("canvas:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Surface Apps /// private void BindSurfaceApps() { try { ArrayList surfaceApps = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "isActive", "1", "surface"); ddSurfaceApps.DataSource = surfaceApps; ddSurfaceApps.DataTextField = "surface"; ddSurfaceApps.DataValueField = "name"; ddSurfaceApps.DataBind(); ddSurfaceApps.Items.Insert(0, new ListItem("Select Surface", "0")); /* CVH 2016-01-22 Add 0 item */ ddSurfaceAppFields.Items.Insert(0, new ListItem("Select Surface Field", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Bind Content Items /// private void BindContent() { try { ArrayList contentItems = xData.GetTypedByCriteriaSpecific("recId", typeof(oContent), "isActive", "1", "title"); ddContent.DataSource = contentItems; ddContent.DataTextField = "title"; ddContent.DataValueField = "recId"; ddContent.DataBind(); ddContent.Items.Insert(0, new ListItem("Select Content", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Toggle display for certain control selections /// private void ToggleControlDisplay() { try { //default views controlsImageMapGroup.Visible = false; divConfidentialNotes.Visible = false; pnlSurfaceSignatureConfig.Visible = false; pnlDrawingConfiguration.Visible = false; if (ddControls.SelectedValue != null && ddControls.SelectedValue != String.Empty) { pNums.Module mod = (pNums.Module)Enum.ToObject(typeof(pNums.Module), int.Parse(ddControls.SelectedValue)); switch (mod) { case pNums.Module.ImageMap: controlsImageMapGroup.Visible = true; break; case pNums.Module.SurfaceNotes: divConfidentialNotes.Visible = true; break; case pNums.Module.SurfaceSignature: pnlSurfaceSignatureConfig.Visible = true; break; case pNums.Module.SurfaceDrawing: pnlDrawingConfiguration.Visible = true; break; } } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindSurfaceDateTypes() { try { DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceDateType), "isActive", "1", "recId"); ddSurfaceDateType.DataSource = typeData; ddSurfaceDateType.DataTextField = "surfaceDateType"; ddSurfaceDateType.DataValueField = "recId"; ddSurfaceDateType.DataBind(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Controls /// private void BindControls() { try { DataTable controlData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "isActive,isSurfaceField", "1,1", "recId"); ddControls.DataSource = controlData; ddControls.DataTextField = "module"; ddControls.DataValueField = "recId"; ddControls.DataBind(); //ToggleFieldTypes(); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Parent Fields /// private void BindParentFields() { oSurface surface = new oSurface(); try { if (utils.verifySession("surface")) { surface = (oSurface)Session["surface"]; string fieldTypeIds = "2|16";//default to group/headergroup if (int.Parse(ddFieldTypes.SelectedValue) == pNums.FieldType.Group.GetHashCode() || int.Parse(ddFieldTypes.SelectedValue) == pNums.FieldType.HeaderGroup.GetHashCode()) fieldTypeIds = "1"; else if (int.Parse(ddFieldTypes.SelectedValue) == pNums.FieldType.Tab.GetHashCode()) fieldTypeIds = "2"; DataTable typeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId", surface.recId + ",~()" + fieldTypeIds, "sequence"); ddParentFields.DataSource = typeData; ddParentFields.DataTextField = "surfaceFieldDisplay"; ddParentFields.DataValueField = "recId"; ddParentFields.DataBind(); //CVH 2017-02-14 Add subtab functionality. If selected field is Tab, allow it to be linked to a group parent ddParentFields.Items.Insert(0, new ListItem("None", "0")); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Field Types /// private void BindLookupCategories() { try { DataTable lookData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceLookupCategory), "isActive", "1", "lookupCategory"); ddLookupCategory.DataSource = lookData; ddLookupCategory.DataValueField = "recId"; ddLookupCategory.DataTextField = "lookupCategory"; ddLookupCategory.DataBind(); ddLookupCategory.Items.Insert(0, new ListItem("select...", "0")); DataTable moduleLookupData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oModule), "isActive,isPicklist", "1,1", "module"); foreach (DataRow row in moduleLookupData.Rows) { ddModuleLookup.Items.Add(new ListItem(row["module"].ToString(), row["objectName"].ToString())); } ddModuleLookup.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Bind Aggregation action Surface /// private void BindAggregationSurface() { try { DataTable dt = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurface), "isActive", "1", "recId"); ddAggregationSurface.DataSource = dt; ddAggregationSurface.DataTextField = "surface"; ddAggregationSurface.DataValueField = "recId"; ddAggregationSurface.DataBind(); ddAggregationSurface.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Label Source Surface /// private void BindLabelSourceSurface() { try { DataTable labelSourceSurfaceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurface), "isActive", "1", "recId"); ddLabelSurface.DataSource = labelSourceSurfaceData; ddLabelSurface.DataTextField = "surface"; ddLabelSurface.DataValueField = "recId"; ddLabelSurface.DataBind(); ddLabelSurface.Items.Insert(0, new ListItem("select...", "0")); ddLabelSurface.Items.Add(new ListItem("Logged User", "user")); ddLabelSurface.Items.Add(new ListItem("Logged Date", "date")); ddLabelSurface.Items.Add(new ListItem("Static Label", "static")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Label Source Fields /// /// private void BindLabelSourceFields(string surfaceId) { try { string fieldTypes = pNums.FieldType.Text.GetHashCode().ToString() + "|" + pNums.FieldType.Number.GetHashCode().ToString() + "|" + pNums.FieldType.Decimal.GetHashCode().ToString() + "|" + pNums.FieldType.Picklist.GetHashCode().ToString() + "|" + pNums.FieldType.Date.GetHashCode().ToString() + "|" + pNums.FieldType.Checkbox.GetHashCode().ToString() + "|" + pNums.FieldType.RadioButtonList.GetHashCode().ToString() + "|" + pNums.FieldType.Attachment.GetHashCode().ToString() + "|" + pNums.FieldType.FormulaField.GetHashCode().ToString() + "|" + pNums.FieldType.Image.GetHashCode().ToString() + "|" + pNums.FieldType.Caption.GetHashCode().ToString() + "|" + pNums.FieldType.Note.GetHashCode().ToString() + "|" + pNums.FieldType.Address.GetHashCode().ToString() + "|" + pNums.FieldType.CheckboxList.GetHashCode().ToString() + "|" + pNums.FieldType.MultiPicklist.GetHashCode().ToString(); DataTable labelSourceFieldData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceId,surfaceFieldTypeId", "1," + surfaceId + ",~()" + fieldTypes + "", "recId"); labelSourceFieldData.Columns.Add("NameWithDisplay", typeof(string), "surfaceFieldDisplay + ' (' + surfaceFieldName+')'"); ddLabelSource.DataSource = labelSourceFieldData; ddLabelSource.DataTextField = "NameWithDisplay"; ddLabelSource.DataValueField = "recId"; ddLabelSource.DataBind(); ddLabelSource.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// bind validation types /// private void BindValidationTypes() { try { DataTable validationTypeSource = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceFieldValidationType), "isActive", "1", "recId"); ddlValidationType.DataSource = validationTypeSource; ddlValidationType.DataTextField = "validationType"; ddlValidationType.DataValueField = "recId"; ddlValidationType.DataBind(); ddlValidationType.Items.Insert(0, new ListItem("none", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Action Types /// private void BindActionTypes() { try { DataTable actionTypeData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceActionType), "isActive", "1", "recId"); ddActionTypes.DataSource = actionTypeData; ddActionTypes.DataTextField = "actionType"; ddActionTypes.DataValueField = "recId"; ddActionTypes.DataBind(); ddActionTypes.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Actions from Action Type /// /// private void BindActions(string actionTypeId) { try { ddActions.ClearSelection(); ddActions.Items.Clear(); ddActions.SelectedValue = null; DataTable actionData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceAction), "isActive,actionType", "1," + actionTypeId, "recId"); ddActions.DataSource = actionData; ddActions.DataTextField = "action"; ddActions.DataValueField = "recId"; ddActions.DataBind(); ddActions.Items.Insert(0, new ListItem("select...", "0")); if (ddActions.Items.Count > 1) actionGroup.Visible = true; } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } /// /// Bind Action Source from Action /// /// private void BindActionSource(string fieldTypeIds, int surfaceId = 0, bool bindActionSource2 = false) { try { DataTable actionSourceData = new DataTable(); if (surfaceId == 0) actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceFieldTypeId", "1,~()" + fieldTypeIds, "recId"); else actionSourceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurfaceField), "isActive,surfaceId,surfaceFieldTypeId", "1," + surfaceId + ",~()" + fieldTypeIds, "recId"); ddActionSource.DataSource = actionSourceData; ddActionSource.DataTextField = "surfaceFieldName"; ddActionSource.DataValueField = "recId"; ddActionSource.DataBind(); //CVH 2017-07-03 Show group even if dropdown is empty, otherwise it looks buggy //if (ddActionSource.Items.Count > 0) actionSourceGroup.Visible = true; if (bindActionSource2) { //CVH 2017-02-06 Bind second source dropdown with same result (for new calculation action Divide, will only show it if Divide selected as actino) ddActionSource2.DataSource = actionSourceData; ddActionSource2.DataTextField = "surfaceFieldName"; ddActionSource2.DataValueField = "recId"; ddActionSource2.DataBind(); } } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } private void BindLookupCalcSurface() { try { DataTable lookupSurfaceData = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oSurface), "isActive", "1", "recId"); ddLookupCalcSurface.DataSource = lookupSurfaceData; ddLookupCalcSurface.DataTextField = "surface"; ddLookupCalcSurface.DataValueField = "recId"; ddLookupCalcSurface.DataBind(); ddLookupCalcSurface.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["admin"]); Response.Redirect("/error", false); } } private void BindLookupCalcSurfaceFields(string surfaceId) { try { string fieldTypes = pNums.FieldType.Text.GetHashCode().ToString() + "|" + pNums.FieldType.Label.GetHashCode().ToString(); ArrayList surfaceFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldTypeId,isActive", surfaceId + ",~()" + fieldTypes + ",1"); ddLookupCalcSurfaceField.DataSource = surfaceFields; ddLookupCalcSurfaceField.DataTextField = "surfaceFieldDisplay"; ddLookupCalcSurfaceField.DataValueField = "recId"; ddLookupCalcSurfaceField.DataBind(); ddLookupCalcSurfaceField.Items.Insert(0, new ListItem("select...", "0")); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Method to Bind the slide Order Drop down /// private void BindSequence() { try { for (int i = 0; i < 100; i++) { //append sequence item ddSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); ddGridSequence.Items.Add(new ListItem(i.ToString(), i.ToString())); } } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } /// /// Method to Bind Access Level /// private void BindAccessLevel() { try { DataTable dtUserType = xData.GetTypedByCriteriaSpecificTable("recId", typeof(oUserType), "isActive,userType", "1,~<>Custom User", "sequence"); ddAccessLevel.DataSource = dtUserType; ddAccessLevel.DataTextField = "userType"; ddAccessLevel.DataValueField = "recId"; ddAccessLevel.DataBind(); } catch (Exception ex) { exception.HandleException("Content:", MethodBase.GetCurrentMethod().Name, ex, 0); Response.Redirect("/error", false); } } #endregion }