Exemple #1
0
        private void SaveCustomField()
        {
            CustomFields customFields = new CustomFields(LoginSession.LoginUser);

            CustomField customField = null;

            if (_customFieldID < 0)
            {
                customField                = customFields.AddNewCustomField();
                customField.AuxID          = _auxID;
                customField.RefType        = _refType;
                customField.OrganizationID = _organizationID;
                customField.Position       = customFields.GetMaxPosition(_organizationID, _refType, _auxID) + 1;
            }
            else
            {
                customFields.LoadByCustomFieldID(_customFieldID);
                customField = customFields[0];
            }

            customField.Description = textDescription.Text;
            customField.FieldType   = (CustomFieldType)cmbType.SelectedIndex;
            customField.ListValues  = textList.Text;
            customField.Name        = textName.Text;
            customFields.Save();
        }
Exemple #2
0
    public override bool Save()
    {
        if (textName.Text.Trim() == "")
        {
            _manager.Alert("Please give the custom field a name.");
            return(false);
        }

        string apiFieldName = GetApiFieldName();

        if (apiFieldName == "")
        {
            _manager.Alert("Please give the custom field an API field name.");
            return(false);
        }

        if (FieldExists(apiFieldName))
        {
            return(false);
        }


        int?catID = Request["CatID"] == null ? null : (int?)int.Parse(Request["CatID"]);

        CustomFields fields = new CustomFields(UserSession.LoginUser);
        CustomField  field;

        if (_customFieldID < 0)
        {
            field = fields.AddNewCustomField();
            field.OrganizationID        = UserSession.LoginUser.OrganizationID;
            field.RefType               = _refType;
            field.AuxID                 = _auxID;
            field.CustomFieldCategoryID = catID;
            field.Position              = fields.GetMaxPosition(UserSession.LoginUser.OrganizationID, _refType, _auxID) + 1;
        }
        else
        {
            fields.LoadByCustomFieldID(_customFieldID);
            if (fields.IsEmpty)
            {
                return(false);
            }
            field = fields[0];
        }

        field.Description         = textDescription.Text;
        field.Name                = textName.Text;
        field.ApiFieldName        = apiFieldName;
        field.FieldType           = GetSelectedFieldType();
        field.ParentCustomFieldID = GetSelectedParentCustomFieldID();
        field.ParentCustomValue   = GetSelectedParentCustomValue();
        field.ParentProductID     = GetSelectedParentProductID();
        field.IsVisibleOnPortal   = cbIsVisibleOnPortal.Checked;
        field.IsFirstIndexSelect  = cbFirstSelect.Checked;
        field.IsRequired          = cbIsRequired.Checked;
        field.IsRequiredToClose   = cbIsRequiredToClose.Checked;
        field.Mask                = textMask.Text;

        string list = textList.Text.Replace("\n", "|");

        if (list != "")
        {
            string[] items = list.Split('|');

            CommaDelimitedStringCollection collection = new CommaDelimitedStringCollection();

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < items.Length; i++)
            {
                builder.Append(items[i].Trim());
                if (i < items.Length - 1)
                {
                    builder.Append("|");
                }
            }

            field.ListValues = builder.ToString();
        }
        else
        {
            field.ListValues = list;
        }
        field.Collection.Save();

        ActionLogs.AddActionLog(UserSession.LoginUser, ActionLogType.Update, ReferenceType.CustomFields, field.CustomFieldID, string.Format(
                                    "{0} updated custom field \"{1}\" ({2})",
                                    Users.GetUserFullName(UserSession.LoginUser, UserSession.LoginUser.UserID), field.Name, field.CustomFieldID));

        return(true);
    }