示例#1
0
        private string GetFieldHtml(Field field, FormEntry entry)
        {
            StringBuilder builder = new StringBuilder();
            string fieldValue = string.Empty;
            if (entry != null)
            {
                Data data = entry.GetFieldData(field);
                if (data != null)
                {
                    fieldValue = entry.GetFieldData(field).Value as string;
                }
            }

            if (field.FieldType == FieldType.MultiLine)
            {
                builder.Append(@"<textarea style=""width:600px;""");
            }
            else if (field.FieldType == FieldType.Html)
            {
                builder.Append(@"<textarea style=""width:600px;"" rows='8'");
            }
            else
            {
                builder.Append("<input type=\"text\"");

                if (field.FieldType == FieldType.String || field.FieldType == FieldType.Url)
                {
                    builder.Append(@" style=""width:600px;""");
                }
                else if (field.FieldType == FieldType.DateTime)
                {
                    builder.Append(@" style=""width:100px;""");
                }
                else
                {
                    builder.Append(@" style=""width:300px;""");
                }

            }

            builder.AppendFormat(@" id=""{0}{1}"" ", IdPrefix, field.Name);

            if (field.FieldType == FieldType.MultiLine ||
                field.FieldType == FieldType.Html)
            {
                builder.AppendFormat(">{0}</textarea>", fieldValue);
            }
            else
            {

                string validate = GetValidateString(field);
                if (!string.IsNullOrEmpty(validate))
                {
                    builder.Append(validate);
                }

                builder.AppendFormat(@"value=""{0}""", fieldValue);
                builder.Append("/>");
            }

            return builder.ToString();
        }
示例#2
0
        public void Add(FormEntry response)
        {
            #region argument checking

            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            if (!response.IsValid())
            {
                throw new InvalidOperationException("response is invalid");
            }

            #endregion

            //get the corresponding form
            Form form = FormsPlugin.Instance.Read(response.Form);

            if (form == null)
            {
                // response without form cannot be saved.
                throw new MessageException(FormsErrorCodes.NoFormFoundWithTheName, ResourceManager.GetMessage(FormMessages.FormNotFound));
            }

            // check to see that the input supplied adhere the rules of the form.
            foreach (Field field in form.Fields)
            {
                Data data = response.GetFieldData(field);

                if (field.IsRequired)
                {
                    // if the field value is required it must not be null
                    // and incase of string, must not be empty.
                    if ((data == null||data.Value == null) ||
                        (field.FieldType == FieldType.String && string.IsNullOrEmpty(data.Value.ToString())))
                    {
                        throw new MessageException(FormsErrorCodes.NotAllRequiredFieldsSupplied,
                            ResourceManager.GetMessage(FormMessages.NotAllFieldsSupplied));
                    }
                }

                bool fieldTypeMatch = true;

                if (data != null && data.Value != null)
                {
                    fieldTypeMatch = IsFieldTypeMatch(field, data.Value);
                }

                if (!fieldTypeMatch)
                {
                    //field's value does not match with the defined type.
                    throw new MessageException(FormsErrorCodes.FieldValueDoesnotMatchWithFieldType,
                        ResourceManager.GetMessage(FormMessages.FieldValueDoesnotMatchWithFieldType));
                }
            }

            // save the data
            try
            {
                // add the form
                PluginStore.Instance.Save(this, response);
            }
            catch (MessageException me)
            {
                if (me.ErrorNumber == PluginErrorCodes.IdAlreadyInUse)
                {
                    // throw with a new message
                    throw new MessageException(me.ErrorNumber, ResourceManager.GetMessage(FormMessages.ResponseIdInUse));
                }

                throw;
            }
        }