/// <summary> /// Loads DataRow for BasicForm with data from FormFieldInfo settings and optionally with form control's default values. /// </summary> /// <param name="loadDefaultValues">Indicates if data container should be initialized with form control's default data</param> private DataRowContainer GetData(bool loadDefaultValues) { DataRowContainer result = new DataRowContainer(FormInfo.GetDataRow(loadDefaultValues)); if (loadDefaultValues) { // Load default values for visible properties (values of hidden form control properties shouldn't be stored in form definition) FormInfo.LoadDefaultValues(result, FormResolveTypeEnum.None, true); } if (Settings != null) { // Load settings of the existing field foreach (string columnName in Settings.Keys) { if (result.ContainsColumn(columnName)) { object value = Settings[columnName]; var settingField = FormInfo.GetFormField(columnName); if (!String.IsNullOrEmpty(Convert.ToString(value)) && IsDataTypeValid(value, settingField)) { result[columnName] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, settingField.DataType, value, SystemContext.EnglishCulture); } } } } return(result); }
protected void btnSetParameter_Click(object sender, EventArgs e) { var selected = GetSelected(hdnParamSelected.Value); if (selected != null) { string paramName = hdnParam.Value.ToLowerCSafe(); var param = selected.Parameters[paramName]; if (param != null) { if (formElem.ValidateData()) { // Load value from the form control var ctrl = formElem.FieldControls[paramName]; if (ctrl != null) { var dataType = ctrl.FieldInfo.DataType; bool nullForDefaultValue = !DataTypeManager.IsNumber(TypeEnum.Field, dataType); // If value is not a number and it is default value of its data type (e.g. Guid.Empty for Guid), convert it to null object convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value, null, nullForDefaultValue); // Convert values to EN culture string value = ValidationHelper.GetString(convertedValue, String.Empty, CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName) && !String.IsNullOrEmpty(value)) { displayName = value; param.ApplyValueTypeConversion = true; } param.Value = value; param.Text = displayName; param.ValueType = dataType; } pnlModalProperty.Visible = false; pnlFooter.Visible = false; } else { pnlModalProperty.Visible = true; pnlFooter.Visible = true; mdlDialog.Visible = true; mdlDialog.Show(); } } } }
/// <summary> /// Loads the from definition from selected parameter into a BasicForm control. /// </summary> /// <param name="actual">If true, data from actual hiddens are loaded</param> private void LoadFormDefinition(bool actual) { MacroRuleTree selected = GetSelected((actual ? hdnParamSelected.Value : hdnLastSelected.Value)); if (selected != null) { string paramName = (actual ? hdnParam.Value.ToLowerCSafe() : hdnLastParam.Value.ToLowerCSafe()); MacroRuleParameter param = selected.Parameters[paramName]; if (param != null) { FormInfo fi = new FormInfo(selected.RuleParameters); FormFieldInfo ffi = fi.GetFormField(paramName); if (ffi != null) { fi = new FormInfo(); fi.AddFormItem(ffi); // Add fake DisplayName field FormFieldInfo displayName = new FormFieldInfo(); displayName.Visible = false; displayName.Name = "DisplayName"; displayName.DataType = FieldDataType.Text; fi.AddFormItem(displayName); DataRow row = fi.GetDataRow().Table.NewRow(); if (ffi.AllowEmpty && String.IsNullOrEmpty(param.Value)) { if (!DataTypeManager.IsString(TypeEnum.Field, ffi.DataType)) { row[paramName] = DBNull.Value; } } else { // Convert to a proper type var val = DataTypeManager.ConvertToSystemType(TypeEnum.Field, ffi.DataType, param.Value, CultureHelper.EnglishCulture); if (val != null) { row[paramName] = val; } } formElem.DataRow = row; formElem.FormInformation = fi; formElem.ReloadData(); } } } }
/// <summary> /// Saves merge changes. /// </summary> private void SaveChanges() { mParentContact.ContactFirstName = cmbContactFirstName.Text.Trim(); mParentContact.ContactMiddleName = cmbContactMiddleName.Text.Trim(); mParentContact.ContactLastName = cmbContactLastName.Text.Trim(); mParentContact.ContactSalutation = cmbContactSalutation.Text.Trim(); mParentContact.ContactTitleBefore = cmbContactTitleBefore.Text.Trim(); mParentContact.ContactTitleAfter = cmbContactTitleAfter.Text.Trim(); mParentContact.ContactCompanyName = cmbContactCompanyName.Text.Trim(); mParentContact.ContactJobTitle = cmbContactJobTitle.Text.Trim(); mParentContact.ContactAddress1 = cmbContactAddress1.Text.Trim(); mParentContact.ContactAddress2 = cmbContactAddress2.Text.Trim(); mParentContact.ContactCity = cmbContactCity.Text.Trim(); mParentContact.ContactZIP = cmbContactZIP.Text.Trim(); mParentContact.ContactStateID = countrySelector.StateID; mParentContact.ContactCountryID = countrySelector.CountryID; mParentContact.ContactMobilePhone = cmbContactMobilePhone.Text.Trim(); mParentContact.ContactHomePhone = cmbContactHomePhone.Text.Trim(); mParentContact.ContactBusinessPhone = cmbContactBusinessPhone.Text.Trim(); mParentContact.ContactEmail = cmbContactEmail.Text.Trim(); mParentContact.ContactWebSite = cmbContactWebSite.Text.Trim(); mParentContact.ContactBirthday = ValidationHelper.GetDateTime(calendarControl.Value, DateTimeHelper.ZERO_TIME); mParentContact.ContactGender = genderSelector.Gender; mParentContact.ContactStatusID = ValidationHelper.GetInteger(contactStatusSelector.Value, 0); mParentContact.ContactCampaign = (string)cCampaign.Value; mParentContact.ContactNotes = (string)htmlNotes.Value; mParentContact.ContactOwnerUserID = MembershipContext.AuthenticatedUser.UserID; mParentContact.ContactMonitored = chkContactMonitored.Checked; // Save cusotm fields foreach (string key in mCustomFields.Keys) { // Get value from object value = ((object[])mCustomFields[key])[0]; var datatype = (string)((object[])mCustomFields[key])[1]; string text = ((TextBox)value).Text; if (!String.IsNullOrEmpty(text)) { // Convert the value to a proper type var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, datatype, text); // Set the parent value mParentContact.SetValue(key, convertedValue); } } ContactInfoProvider.SetContactInfo(mParentContact, false); }
protected void btnSetParameter_Click(object sender, EventArgs e) { var selected = GetSelected(hdnParamSelected.Value); if (selected != null) { string paramName = hdnParam.Value.ToLowerInvariant(); var param = selected.Parameters[paramName]; if (param != null) { if (formElem.ValidateData()) { // Load value from the form control var ctrl = formElem.FieldControls[paramName]; if (ctrl != null) { var dataType = ctrl.FieldInfo.DataType; var useNullInsteadOfDefaultValue = UseNullInsteadOfDefaultValue(dataType); object convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value, null, useNullInsteadOfDefaultValue); // Convert values to EN culture string value = ValidationHelper.GetString(convertedValue, String.Empty, CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName) && !String.IsNullOrEmpty(value)) { displayName = value; param.ApplyValueTypeConversion = true; } param.Value = value; param.Text = displayName; param.ValueType = dataType; } pnlModalProperty.Visible = false; pnlFooter.Visible = false; } else { ShowParameterDialog(); } } } }
/// <summary> /// Loads DataRow container for BasicForm with widget properties. /// </summary> private DataRowContainer GetWidgetProperties() { var result = new DataRowContainer(widgetTypeFormInfo.GetDataRow()); foreach (var property in widgetInstance.Properties) { if (property.Value == null) { continue; } var formField = widgetTypeFormInfo.GetFormField(property.Name); if (formField == null) { continue; } result[property.Name] = DataTypeManager.ConvertToSystemType(TypeEnum.Field, formField.DataType, property.Value, CultureHelper.EnglishCulture); } return(result); }
/// <summary> /// Saves merge changes. /// </summary> private void SaveChanges() { mParentAccount.AccountName = cmbAccountName.Text.Trim(); mParentAccount.AccountAddress1 = cmbAccountAddress1.Text.Trim(); mParentAccount.AccountAddress2 = cmbAccountAddress2.Text.Trim(); mParentAccount.AccountCity = cmbAccountCity.Text.Trim(); mParentAccount.AccountZIP = cmbAccountZIP.Text.Trim(); mParentAccount.AccountStateID = countrySelector.StateID; mParentAccount.AccountCountryID = countrySelector.CountryID; mParentAccount.AccountWebSite = cmbAccountWebSite.Text.Trim(); mParentAccount.AccountPhone = cmbAccountPhone.Text.Trim(); mParentAccount.AccountEmail = cmbAccountEmail.Text.Trim(); mParentAccount.AccountFax = cmbAccountFax.Text.Trim(); mParentAccount.AccountStatusID = accountStatusSelector.AccountStatusID; mParentAccount.AccountNotes = (string)htmlNotes.Value; mParentAccount.AccountOwnerUserID = MembershipContext.AuthenticatedUser.UserID; mParentAccount.AccountSubsidiaryOfID = accountSelector.AccountID; // Save cusotm fields foreach (string key in mCustomFields.Keys) { // Get value from object value = ((object[])mCustomFields[key])[0]; var datatype = (string)((object[])mCustomFields[key])[1]; string text = ((TextBox)value).Text; if (!String.IsNullOrEmpty(text)) { // Convert the value to a proper type var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, datatype, text); // Set the parent value mParentAccount.SetValue(key, convertedValue); } } AccountInfoProvider.SetAccountInfo(mParentAccount); }
/// <summary> /// Creates new <see cref="FieldMacroRule"/> object based on inputs. /// </summary> private FieldMacroRule CreateMacroRule() { if (!IsValid()) { return(null); } MacroRuleTree main = null; FieldMacroRule fmr = null; MacroRuleInfo mri = MacroRuleInfoProvider.GetMacroRuleInfo(mSelectedRuleName); if (mri != null) { main = new MacroRuleTree(); MacroRuleTree childern = new MacroRuleTree() { RuleText = mri.MacroRuleText, RuleName = mri.MacroRuleName, RuleCondition = mri.MacroRuleCondition, Parent = main }; main.Children.Add(childern); foreach (string paramName in formProperties.Fields) { // Load value from the form control FormEngineUserControl ctrl = formProperties.FieldControls[paramName]; if (ctrl != null) { // Convert value to EN culture var dataType = ctrl.FieldInfo.DataType; var convertedValue = DataTypeManager.ConvertToSystemType(TypeEnum.Field, dataType, ctrl.Value); string value = ValidationHelper.GetString(convertedValue, "", CultureHelper.EnglishCulture); string displayName = ctrl.ValueDisplayName; if (String.IsNullOrEmpty(displayName)) { displayName = value; } MacroRuleParameter param = new MacroRuleParameter { Value = value, Text = displayName, ValueType = dataType }; childern.Parameters.Add(paramName, param); } } string macroRule = string.Format("Rule(\"{0}\", \"{1}\")", MacroElement.EscapeSpecialChars(main.GetCondition()), MacroElement.EscapeSpecialChars(main.GetXML())); if (!MacroSecurityProcessor.IsSimpleMacro(macroRule)) { // Sign complex macros macroRule = MacroSecurityProcessor.AddMacroSecurityParams(macroRule, MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser)); } fmr = new FieldMacroRule(); fmr.MacroRule = string.Format("{{%{0}%}}", macroRule); fmr.ErrorMessage = txtErrorMsg.Text; } return(fmr); }