protected void rptCustomFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem) return;

            var currentField = (UserCustomField)e.Item.DataItem;

            var ph = (PlaceHolder)e.Item.FindControl("PlaceHolder");
            var id = (HiddenField)e.Item.FindControl("Id");
            var name = (HiddenField)e.Item.FindControl("Name");

            id.Value = currentField.Id.ToString();
            name.Value = currentField.Name;

            switch (currentField.FieldType)
            {
                case CustomFieldType.DropDownList:

                    var ddl = new DropDownList
                    {
                        ID = FIELD_VALUE_NAME,
                        DataSource = UserCustomFieldSelectionManager.GetByCustomFieldId(currentField.Id),
                        DataTextField = "Name",
                        DataValueField = "Value",
                        CssClass = "form-control"
                    };

                    ddl.DataBind();
                    ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty));
                    ddl.SelectedValue = currentField.Value;

                    ph.Controls.Add(ddl);

                    if (IsLocked)
                    {
                        ddl.Enabled = false;
                    }

                    break;
                case CustomFieldType.Date:

                    var fieldValue1 = new TextBox();
                    fieldValue1.Attributes.Add("bn-data-type", "date");
                    var cal = new CalendarExtender();

                    var img = new Image { ID = "calImage", CssClass = "icon", ImageUrl = "~/images/calendar.gif" };

                    cal.PopupButtonID = "calImage";
                    cal.TargetControlID = FIELD_VALUE_NAME;
                    cal.ID = "Calendar1";

                    fieldValue1.ID = "FieldValue";
                    fieldValue1.Width = 80;

                    ph.Controls.Add(fieldValue1);
                    ph.Controls.Add(img);
                    ph.Controls.Add(new LiteralControl("&nbsp"));

                    DateTime dt;
                    var dateTimeValue = currentField.Value;

                    if (DateTime.TryParse(dateTimeValue, out dt))
                    {
                        dateTimeValue = dt.ToShortDateString();
                    }

                    fieldValue1.Text = dateTimeValue;

                    ph.Controls.Add(cal);

                    if (IsLocked)
                    {
                        cal.Enabled = false;
                        fieldValue1.Enabled = false;
                        img.Visible = false;
                    }
                    break;
                case CustomFieldType.Text:

                    var fieldValue = new TextBox
                    {
                        ID = FIELD_VALUE_NAME,
                        Text = currentField.Value,
                        CssClass = "form-control"
                    };
                    fieldValue.Attributes.Add("bn-data-type", "text");

                    ph.Controls.Add(fieldValue);

                    if (currentField.Value.Trim().ToLower().StartsWith("http"))
                    {
                        var url = new HyperLink { Target = "_blank", NavigateUrl = currentField.Value, Text = " GOTO >>" };
                        ph.Controls.Add(url);
                    }

                    if (IsLocked)
                    {
                        fieldValue.Enabled = false;
                    }
                    break;
                case CustomFieldType.YesNo:

                    var chk = new CheckBox { ID = FIELD_VALUE_NAME };

                    if (!String.IsNullOrEmpty(currentField.Value))
                    {
                        chk.Checked = Boolean.Parse(currentField.Value);
                    }

                    ph.Controls.Add(new LiteralControl("<div class=\"checkbox\">"));
                    ph.Controls.Add(chk);
                    ph.Controls.Add(new LiteralControl("</div>"));

                    if (IsLocked)
                    {
                        chk.Enabled = false;
                    }

                    break;
                case CustomFieldType.RichText:

                    var editor = new HtmlEditor { ID = FIELD_VALUE_NAME };
                    editor.Attributes.Add("bn-data-type", "html");

                    ph.Controls.Add(editor);

                    editor.Text = currentField.Value;

                    break;
                case CustomFieldType.UserList:

                    ddl = new DropDownList
                    {
                        ID = FIELD_VALUE_NAME,
                        DataSource = UserManager.GetAllUsers(),
                        DataTextField = "DisplayName",
                        DataValueField = "UserName",
                        CssClass = "form-control"
                    };

                    ddl.DataBind();

                    ddl.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString(), string.Empty));
                    ddl.SelectedValue = currentField.Value;

                    ph.Controls.Add(ddl);

                    if (IsLocked)
                    {
                        ddl.Enabled = false;
                    }

                    break;
            }

            var lblFieldName = (Label)e.Item.FindControl("lblFieldName");
            lblFieldName.AssociatedControlID = FIELD_VALUE_NAME;
            lblFieldName.Text = currentField.Name;

            if (EnableValidation)
            {
                //if required dynamically add a required field validator
                if (currentField.Required && currentField.FieldType != CustomFieldType.YesNo)
                {
                    var valReq = new RequiredFieldValidator
                    {
                        ControlToValidate = FIELD_VALUE_NAME,
                        Text = string.Format(" ({0})", GetGlobalResourceObject("SharedResources", "Required")).ToLower(),
                        Display = ValidatorDisplay.Dynamic,
                        CssClass = "text-danger validation-error",
                        SetFocusOnError = true
                    };

                    if (currentField.FieldType == CustomFieldType.DropDownList)
                        valReq.InitialValue = string.Empty;

                    ph.Controls.Add(valReq);
                }

                //create data type check validator
                if (currentField.FieldType != CustomFieldType.YesNo)
                {
                    var valCompare = new CompareValidator
                    {
                        Type = currentField.DataType,
                        Text = String.Format("({0})", currentField.DataType),
                        Operator = ValidationCompareOperator.DataTypeCheck,
                        Display = ValidatorDisplay.Dynamic,
                        ControlToValidate = FIELD_VALUE_NAME
                    };
                    ph.Controls.Add(valCompare);
                }
            }
        }
Ejemplo n.º 2
0
        protected void rptCustomFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType != ListItemType.AlternatingItem)
            {
                return;
            }

            var currentField = (CustomField)e.Item.DataItem;

            var ph   = (PlaceHolder)e.Item.FindControl("PlaceHolder");
            var id   = (HiddenField)e.Item.FindControl("Id");
            var name = (HiddenField)e.Item.FindControl("Name");

            id.Value   = currentField.Id.ToString();
            name.Value = currentField.Name;

            switch (currentField.FieldType)
            {
            case CustomFieldType.DropDownList:

                var ddl = new DropDownList
                {
                    ID             = FIELD_VALUE_NAME,
                    DataSource     = CustomFieldSelectionManager.GetByCustomFieldId(currentField.Id),
                    DataTextField  = "Name",
                    DataValueField = "Value",
                    CssClass       = "form-control"
                };

                ddl.DataBind();
                ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty));
                ddl.SelectedValue = currentField.Value;

                ph.Controls.Add(ddl);

                if (IsLocked)
                {
                    ddl.Enabled = false;
                }

                break;

            case CustomFieldType.Date:

                var fieldValue1 = new TextBox();
                fieldValue1.Attributes.Add("bn-data-type", "date");
                var cal = new CalendarExtender();

                var img = new Image {
                    ID = "calImage", CssClass = "icon", ImageUrl = "~/images/calendar.gif"
                };

                cal.PopupButtonID   = "calImage";
                cal.TargetControlID = FIELD_VALUE_NAME;
                cal.ID = "Calendar1";

                fieldValue1.ID    = "FieldValue";
                fieldValue1.Width = 80;

                ph.Controls.Add(fieldValue1);
                ph.Controls.Add(img);
                ph.Controls.Add(new LiteralControl("&nbsp"));

                DateTime dt;
                var      dateTimeValue = currentField.Value;

                if (DateTime.TryParse(dateTimeValue, out dt))
                {
                    dateTimeValue = dt.ToShortDateString();
                }

                fieldValue1.Text = dateTimeValue;

                ph.Controls.Add(cal);

                if (IsLocked)
                {
                    cal.Enabled         = false;
                    fieldValue1.Enabled = false;
                    img.Visible         = false;
                }
                break;

            case CustomFieldType.Text:

                var fieldValue = new TextBox {
                    ID       = FIELD_VALUE_NAME, Text = currentField.Value,
                    CssClass = "form-control"
                };
                fieldValue.Attributes.Add("bn-data-type", "text");

                ph.Controls.Add(fieldValue);

                if (currentField.Value.Trim().ToLower().StartsWith("http"))
                {
                    var url = new HyperLink {
                        Target = "_blank", NavigateUrl = currentField.Value, Text = "&nbsp;GOTO >>"
                    };
                    ph.Controls.Add(url);
                }

                if (IsLocked)
                {
                    fieldValue.Enabled = false;
                }
                break;

            case CustomFieldType.YesNo:

                var chk = new CheckBox {
                    ID = FIELD_VALUE_NAME
                };

                if (!String.IsNullOrEmpty(currentField.Value))
                {
                    chk.Checked = Boolean.Parse(currentField.Value);
                }

                ph.Controls.Add(new LiteralControl("<div class=\"checkbox\">"));
                ph.Controls.Add(chk);
                ph.Controls.Add(new LiteralControl("</div>"));

                if (IsLocked)
                {
                    chk.Enabled = false;
                }

                break;

            case CustomFieldType.RichText:

                var editor = new HtmlEditor {
                    ID = FIELD_VALUE_NAME
                };
                editor.Attributes.Add("bn-data-type", "html");

                ph.Controls.Add(editor);

                editor.Text = currentField.Value;

                break;

            case CustomFieldType.UserList:

                ddl = new DropDownList
                {
                    ID             = FIELD_VALUE_NAME,
                    DataSource     = UserManager.GetUsersByProjectId(currentField.ProjectId),
                    DataTextField  = "DisplayName",
                    DataValueField = "UserName",
                    CssClass       = "form-control"
                };

                ddl.DataBind();

                ddl.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString(), string.Empty));
                ddl.SelectedValue = currentField.Value;

                ph.Controls.Add(ddl);

                if (IsLocked)
                {
                    ddl.Enabled = false;
                }

                break;
            }

            var lblFieldName = (Label)e.Item.FindControl("lblFieldName");

            lblFieldName.AssociatedControlID = FIELD_VALUE_NAME;
            lblFieldName.Text = currentField.Name;

            if (EnableValidation)
            {
                //if required dynamically add a required field validator
                if (currentField.Required && currentField.FieldType != CustomFieldType.YesNo)
                {
                    var valReq = new RequiredFieldValidator
                    {
                        ControlToValidate = FIELD_VALUE_NAME,
                        Text            = string.Format(" ({0})", GetGlobalResourceObject("SharedResources", "Required")).ToLower(),
                        Display         = ValidatorDisplay.Dynamic,
                        CssClass        = "text-danger validation-error",
                        SetFocusOnError = true
                    };

                    if (currentField.FieldType == CustomFieldType.DropDownList)
                    {
                        valReq.InitialValue = string.Empty;
                    }

                    ph.Controls.Add(valReq);
                }

                //create data type check validator
                if (currentField.FieldType != CustomFieldType.YesNo)
                {
                    var valCompare = new CompareValidator
                    {
                        Type              = currentField.DataType,
                        Text              = String.Format("({0})", currentField.DataType),
                        Operator          = ValidationCompareOperator.DataTypeCheck,
                        Display           = ValidatorDisplay.Dynamic,
                        ControlToValidate = FIELD_VALUE_NAME
                    };
                    ph.Controls.Add(valCompare);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// LSTs the custom fields item data bound.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.DataListItemEventArgs"/> instance containing the event data.</param>
        void lstCustomFieldsItemDataBound(object s, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                CustomField currentField = (CustomField)e.Item.DataItem;
                PlaceHolder ph = (PlaceHolder)e.Item.FindControl("PlaceHolder");

                switch (currentField.FieldType)
                {
                    case Common.CustomFieldType.DropDownList:
                        DropDownList ddl = new DropDownList();
                        ddl.ID = FIELD_VALUE_NAME;
                        ddl.DataSource = CustomFieldSelectionManager.GetByCustomFieldId(currentField.Id);
                        ddl.DataTextField = "Name";
                        ddl.DataValueField = "Value";
                        ddl.DataBind();
                        ddl.Items.Insert(0,new ListItem( "-- Select One --", string.Empty));
                        ddl.SelectedValue = currentField.Value;
                        ph.Controls.Add(ddl);
                        if (IsLocked)
                            ddl.Enabled = false;
                        break;
                    case Common.CustomFieldType.Date:
                        TextBox FieldValue1 = new TextBox();
                        AjaxControlToolkit.CalendarExtender cal = new AjaxControlToolkit.CalendarExtender();
                        Image img = new Image();
                        img.ID = "calImage";
                        img.CssClass = "icon";
                        img.ImageUrl = "~/images/calendar.gif";
                        cal.PopupButtonID = "calImage";
                        cal.TargetControlID = FIELD_VALUE_NAME;
                        cal.ID = "Calendar1";
                        FieldValue1.ID = "FieldValue";
                        FieldValue1.Width = 80;
                        ph.Controls.Add(FieldValue1);
                        ph.Controls.Add(img);
                        ph.Controls.Add(new LiteralControl("&nbsp"));
                        FieldValue1.Text = currentField.Value;
                        ph.Controls.Add(cal);
                        if (IsLocked)
                        {
                            cal.Enabled = false;
                            FieldValue1.Enabled = false;
                            img.Visible = false;
                        }
                        break;
                    case Common.CustomFieldType.Text:
                        var fieldValue = new TextBox {ID = FIELD_VALUE_NAME, Text = currentField.Value};
                        ph.Controls.Add(fieldValue);
                        if (IsLocked)
                            fieldValue.Enabled = false;
                        break;
                    case Common.CustomFieldType.YesNo:
                        var chk = new CheckBox {ID = FIELD_VALUE_NAME};
                        if (!String.IsNullOrEmpty(currentField.Value))
                            chk.Checked = Boolean.Parse(currentField.Value);
                        ph.Controls.Add(chk);
                        if (IsLocked)
                            chk.Enabled = false;
                        break;
                    case Common.CustomFieldType.RichText:
                        var editor = new HtmlEditor {ID = FIELD_VALUE_NAME};

                        ph.Controls.Add(editor);
                        editor.Text = currentField.Value;
                        //if (IsLocked)
                        //    editor.Enabled = false;
                        break;
                    case Common.CustomFieldType.UserList:
                        ddl = new DropDownList
                                  {
                                      ID = FIELD_VALUE_NAME,
                                      DataSource = UserManager.GetUsersByProjectId(currentField.ProjectId),
                                      DataTextField = "DisplayName",
                                      DataValueField = "UserName"
                                  };
                        ddl.DataBind();
                        ddl.Items.Insert(0, new ListItem("-- Select One --", string.Empty));
                        ddl.SelectedValue = currentField.Value;
                        ph.Controls.Add(ddl);
                        if (IsLocked)
                            ddl.Enabled = false;
                        break;
                }

                var lblFieldName = (Label)e.Item.FindControl("lblFieldName");
                lblFieldName.AssociatedControlID = FIELD_VALUE_NAME;
                lblFieldName.Text = string.Format("{0}:", currentField.Name);

                if (EnableValidation)
                {
                    //if required dynamically add a required field validator
                    if (currentField.Required && currentField.FieldType != Common.CustomFieldType.YesNo)
                    {
                        var valReq = new RequiredFieldValidator
                                         {
                                             ControlToValidate = FIELD_VALUE_NAME,
                                             Text = " (required)",
                                             Display = ValidatorDisplay.Dynamic
                                         };

                        if (currentField.FieldType == Common.CustomFieldType.DropDownList)
                            valReq.InitialValue = string.Empty;

                        ph.Controls.Add(valReq);
                    }

                    //create datatype check validator
                    if (currentField.FieldType != Common.CustomFieldType.YesNo)
                    {
                        var valCompare = new CompareValidator
                                             {
                                                 Type = currentField.DataType,
                                                 Text = String.Format("({0})", currentField.DataType),
                                                 Operator = ValidationCompareOperator.DataTypeCheck,
                                                 Display = ValidatorDisplay.Dynamic,
                                                 ControlToValidate = FIELD_VALUE_NAME
                                             };
                        ph.Controls.Add(valCompare);
                    }
                }

            }
        }