/// <summary> /// Handles the UpdateCommand event of the grdSelectionValues control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdSelectionValues_Update(object source, DataGridCommandEventArgs e) { lblError.Text = String.Empty; if (ListItemType.EditItem == e.Item.ItemType) { var selectionName = (TextBox)e.Item.FindControl("txtEditSelectionName"); var txtValue = (TextBox)e.Item.FindControl("txtEditSelectionValue"); if (selectionName != null && txtValue != null) { var customFieldSelectionId = (int)((DataGrid)source).DataKeys[e.Item.ItemIndex]; CustomFieldSelection cfs = CustomFieldSelectionManager.GetById(customFieldSelectionId); cfs.Name = selectionName.Text.Trim(); cfs.Value = txtValue.Text.Trim(); CustomFieldSelectionManager.SaveOrUpdate(cfs); lblError.Text = String.Empty; foreach (DataGridItem item in grdCustomFields.Items) { var grdSelectionValues = (DataGrid)item.FindControl("grdSelectionValues"); if (null == grdSelectionValues) { continue; } grdSelectionValues.ShowFooter = true; grdSelectionValues.EditItemIndex = -1; BindCustomFieldSelections(); } } ViewState["EditingSubGrid"] = null; BindCustomFields(); } }
/// <summary> /// Handles the ItemCommand event of the grdSelectionValues control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param> protected void grdSelectionValues_ItemCommand(object source, DataGridCommandEventArgs e) { CustomFieldSelection cfs; var itemIndex = e.Item.ItemIndex; int itemId; var grid = source as DataGrid; switch (e.CommandName) { case "up": //move row up if (itemIndex == 0) { return; } itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = CustomFieldSelectionManager.GetById(itemId); cfs.SortOrder -= 1; CustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "down": //move row down if (itemIndex == grid.Items.Count - 1) { return; } itemId = Convert.ToInt32(grid.DataKeys[itemIndex]); cfs = CustomFieldSelectionManager.GetById(itemId); cfs.SortOrder += 1; CustomFieldSelectionManager.SaveOrUpdate(cfs); break; case "add": if (Page.IsValid) { var txtAddSelectionName = (TextBox)e.Item.FindControl("txtAddSelectionName"); var txtAddSelectionValue = (TextBox)e.Item.FindControl("txtAddSelectionValue"); cfs = new CustomFieldSelection { CustomFieldId = Convert.ToInt32(e.CommandArgument), Name = txtAddSelectionName.Text.Trim(), Value = txtAddSelectionValue.Text.Trim() }; CustomFieldSelectionManager.SaveOrUpdate(cfs); } break; } BindCustomFieldSelections(); }
protected void btnDeleteSelectionValue_Click(object sender, ImageClickEventArgs e) { var btn = sender as ImageButton; if (btn == null) { return; } var id = btn.CommandArgument.To <int>(); if (!CustomFieldSelectionManager.Delete(id)) { lblError.Text = LoggingManager.GetErrorMessageResource("DeleteCustomFieldError"); } else { BindCustomFields(); } }
/// <summary> /// When the user changes the selected field type, show the corresponding list /// of possible values. /// </summary> /// <param name="s">The s.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void dropFieldSelectedIndexChanged(Object s, EventArgs e) { dropValue.Items.Clear(); dropValue.Visible = false; txtValue.Visible = false; DateValue.Visible = false; switch (dropField.SelectedValue) { case "IssueId": case "IssueTitle": case "IssueDescription": case "IssueVotes": case "IssueProgress": case "IssueEstimation": case "TimeLogged": txtValue.Visible = true; break; case "IssuePriorityId": dropValue.Visible = true; dropValue.DataSource = PriorityManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueTypeId": dropValue.Visible = true; dropValue.DataSource = IssueTypeManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueMilestoneId": dropValue.Visible = true; dropValue.DataSource = MilestoneManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueAffectedMilestoneId": dropValue.Visible = true; dropValue.DataSource = MilestoneManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueResolutionId": dropValue.Visible = true; dropValue.DataSource = ResolutionManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueCategoryId": dropValue.Visible = true; var objCats = new CategoryTree(); dropValue.DataSource = objCats.GetCategoryTreeByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueStatusId": dropValue.Visible = true; dropValue.DataSource = StatusManager.GetByProjectId(ProjectId); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Id"; break; case "IssueAssignedUserId": dropValue.Visible = true; dropValue.DataSource = UserManager.GetUsersByProjectId(ProjectId); dropValue.DataTextField = "DisplayName"; dropValue.DataValueField = "Id"; break; case "IssueOwnerUserId": dropValue.Visible = true; txtValue.Visible = false; dropValue.DataSource = UserManager.GetUsersByProjectId(ProjectId); dropValue.DataTextField = "DisplayName"; dropValue.DataValueField = "Id"; break; case "IssueCreatorUserId": dropValue.Visible = true; dropValue.DataSource = UserManager.GetUsersByProjectId(ProjectId); dropValue.DataTextField = "DisplayName"; dropValue.DataValueField = "Id"; break; case "DateCreatedAsDate": case "LastUpdateAsDate": case "IssueDueDate": DateValue.Visible = true; break; case "CustomFieldName": dropValue.Visible = false; txtValue.Visible = true; //show the text value field. Not needed. CustomFieldSelected = true; if (CustomFieldManager.GetByProjectId(ProjectId).Count > 0) { dropField.DataSource = CustomFieldManager.GetByProjectId(ProjectId); dropField.DataTextField = "Name"; dropField.DataValueField = "Name"; dropField.DataBind(); // bind to the new data source. dropField.Items.Add(GetGlobalResourceObject("SharedResources", "DropDown_ResetFields").ToString()); dropField.Items.Insert(0, new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectCustomField").ToString(), "0")); } break; default: if (dropField.SelectedItem.Text.Equals(GetGlobalResourceObject("SharedResources", "DropDown_SelectCustomField").ToString())) { return; } // The user decides to reset the fields if (dropField.SelectedItem.Text.Equals(GetGlobalResourceObject("SharedResources", "DropDown_ResetFields").ToString())) { dropField.DataSource = null; dropField.DataSource = RequiredFieldManager.GetRequiredFields(); dropField.DataTextField = "Name"; dropField.DataValueField = "Value"; dropField.DataBind(); } //RW Once the list is populated with any varying type of name, //we just default to this case, because we know it is not a standard field. else { //check the type of this custom field and load the appropriate values. var cf = CustomFieldManager.GetByProjectId(ProjectId).Find(c => c.Name == dropField.SelectedValue); if (cf == null) { return; } CustomFieldSelected = true; CustomFieldId = cf.Id; CustomFieldDataType = cf.DataType; switch (cf.FieldType) { case CustomFieldType.DropDownList: dropValue.Visible = true; dropValue.DataSource = CustomFieldSelectionManager.GetByCustomFieldId(cf.Id); dropValue.DataTextField = "Name"; dropValue.DataValueField = "Value"; break; case CustomFieldType.Date: DateValue.Visible = true; break; case CustomFieldType.YesNo: dropValue.Visible = true; dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "DropDown_SelectOne").ToString())); dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "Yes").ToString(), Boolean.TrueString)); dropValue.Items.Add(new ListItem(GetGlobalResourceObject("SharedResources", "No").ToString(), Boolean.FalseString)); break; default: txtValue.Visible = true; break; } } break; } try { dropValue.DataBind(); } catch { } }
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(" ")); 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.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); } } }
/// <summary> /// Gets the custom field selections. /// </summary> /// <param name="customFieldId">The custom field id.</param> /// <returns></returns> private static List <CustomFieldSelection> GetCustomFieldSelections(int customFieldId) { return(CustomFieldSelectionManager.GetByCustomFieldId(customFieldId)); }