Exemple #1
0
        public static void SetValueFieldsFromFormValues(this WebFormFieldResponse data, HttpRequestBase request)
        {
            if (data == null)
            {
                throw new ArgumentNullException("webFormFieldResponse");
            }
            if (request == null)
            {
                throw new ArgumentNullException("webFormFieldResponse");
            }

            if (data.WebFormField == null)
            {
                throw new ArgumentException("webFormFieldResponse.WebFormField is null. Be sure to set webFormFieldResponse.WebFormField object before calling this method", "webFormFieldResponse.WebFormField");
            }
            if (!Enum.IsDefined(typeof(GStoreValueDataType), data.DataType))
            {
                throw new ArgumentException("webFormFieldResponse.DataType value '" + data.DataType.ToString() + "' is invalid.  is null. Be sure to set this value on the webFormFieldResponse object before calling this method", "webFormFieldResponse.DataType");
            }

            data.Value1String = request.GetFormFieldValue1String(data.WebFormField);
            data.Value2String = request.GetFormFieldValue2String(data.WebFormField);

            switch (data.DataType)
            {
            case GStoreValueDataType.EmailAddress:
            //do nothing string value already set

            case GStoreValueDataType.Url:
            //do nothing string value already set

            case GStoreValueDataType.CheckboxYesNo:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    if (
                        data.Value1String.Trim().ToLower() == "1" ||
                        data.Value1String.Trim().ToLower() == "true" ||
                        data.Value1String.Trim().ToLower() == "t" ||
                        data.Value1String.Trim().ToLower() == "y" ||
                        data.Value1String.Trim().ToLower() == "yes" ||
                        data.Value1String.Trim().ToLower() == "checked" ||
                        data.Value1String.Trim().ToLower() == "check"
                        )
                    {
                        data.Value1Bool = true;
                    }
                    else
                    {
                        data.Value1Bool = false;
                    }
                }
                break;

            case GStoreValueDataType.Integer:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int result;
                    if (int.TryParse(data.Value1String, out result))
                    {
                        data.Value1Int = result;
                    }
                }
                break;

            case GStoreValueDataType.Decimal:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    decimal result;
                    if (decimal.TryParse(data.Value1String, out result))
                    {
                        data.Value1Decimal = result;
                    }
                }
                break;

            case GStoreValueDataType.IntegerRange:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int result1;
                    if (int.TryParse(data.Value1String, out result1))
                    {
                        data.Value1Int = result1;
                    }
                }
                if (!string.IsNullOrWhiteSpace(data.Value2String))
                {
                    int result2;
                    if (int.TryParse(data.Value2String, out result2))
                    {
                        data.Value2Int = result2;
                    }
                }
                break;

            case GStoreValueDataType.DecimalRange:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    decimal result1;
                    if (decimal.TryParse(data.Value1String, out result1))
                    {
                        data.Value1Decimal = result1;
                    }
                }
                if (!string.IsNullOrWhiteSpace(data.Value2String))
                {
                    decimal result2;
                    if (decimal.TryParse(data.Value2String, out result2))
                    {
                        data.Value2Decimal = result2;
                    }
                }
                break;

            case GStoreValueDataType.SingleLineText:
                //do nothing string value already set
                break;

            case GStoreValueDataType.MultiLineText:
                //do nothing string value already set
                break;

            case GStoreValueDataType.Html:
                //do nothing string value already set
                break;

            case GStoreValueDataType.ValueListItemDropdown:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int result;
                    if (int.TryParse(data.Value1String, out result))
                    {
                        if (result != 0)
                        {
                            data.Value1ValueListItemId   = result;
                            data.Value1ValueListItemName = data.WebFormField.GetValueListItemName(data.Value1String);
                        }
                    }
                }

                break;

            case GStoreValueDataType.ValueListItemRadio:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int result;
                    if (int.TryParse(data.Value1String, out result))
                    {
                        if (result != 0)
                        {
                            data.Value1ValueListItemId   = result;
                            data.Value1ValueListItemName = data.WebFormField.GetValueListItemName(data.Value1String);
                        }
                    }
                }
                break;

            case GStoreValueDataType.ValueListItemMultiCheckbox:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int      result;
                    string[] split = data.Value1String.Split(',');
                    foreach (string value in split)
                    {
                        if (!string.IsNullOrWhiteSpace(value))
                        {
                            if (int.TryParse(value.Trim(), out result))
                            {
                                if (result != 0)
                                {
                                    if (!string.IsNullOrEmpty(data.Value1ValueListItemIdList))
                                    {
                                        data.Value1ValueListItemIdList += ",";
                                    }
                                    if (!string.IsNullOrEmpty(data.Value1ValueListItemNameList))
                                    {
                                        data.Value1ValueListItemNameList += ",";
                                    }
                                    data.Value1ValueListItemIdList   += result;
                                    data.Value1ValueListItemNameList += data.WebFormField.GetValueListItemName(value);
                                }
                            }
                        }
                    }
                }
                break;

            case GStoreValueDataType.ExternalLinkToPage:
                //do nothing link url will be value 1, link text will be value 2
                break;

            case GStoreValueDataType.ExternalLinkToImage:
                //do nothing link url will be value 1, link text will be value 2
                break;

            case GStoreValueDataType.InternalLinkToPageById:
                if (!string.IsNullOrWhiteSpace(data.Value1String))
                {
                    int result;
                    if (int.TryParse(data.Value1String, out result))
                    {
                        if (result != 0)
                        {
                            data.Value1PageId = result;
                        }
                    }
                }
                break;

            case GStoreValueDataType.InternalLinkToPageByUrl:
                //do nothing route values will be value 1, link text will be value 2
                break;

            case GStoreValueDataType.InternalLinkToImageByUrl:
                //do nothing route values will be value 1, link text will be value 2
                break;

            default:
                break;
            }
        }