public Dictionary <int, string> GetPickListItemsByPickListType(PickListType pickListType) { var pickListItems = new Dictionary <int, string>(); using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @" SELECT PLI.PickListItem_ID, PLI.Code FROM dbo.PickListItem AS PLI INNER JOIN dbo.PickList AS PL ON PLI.PickList_ID = PL.PickList_ID WHERE PL.Code = @pickListCode" ; command.CommandType = CommandType.Text; command.Parameters.Add(new SqlParameter("pickListCode", EnumUtility.CctCodeValueOf(pickListType))); using (var reader = command.ExecuteReader()) { while (reader.Read()) { pickListItems.Add(Convert.ToInt32(reader["PickListItem_ID"]), Convert.ToString(reader["Code"])); } } } } return(pickListItems); }
public void BindUser(User user, PickListType pickListType, String categoryName, TraitCategoryType traitCategory) { this.User = user; this.CategoryName = categoryName; this.TraitCategory = traitCategory; this.PickListType = pickListType; if (pickListType == Extensibility.PickListType.MultimediaType) { txt.IsReadOnly = true; } this.Service = new SupportService(user); txt.PreviewKeyDown += new KeyEventHandler(txt_PreviewKeyDown); }
public PickListControl(User user, PickListType type, string phraseCategory, TraitCategoryType traitCategory) { InitializeComponent(); BindUser(user, type, phraseCategory, traitCategory); GotFocus += new RoutedEventHandler(PickListControl_GotFocus); }
public static string ShowPickList(User user, PickListType type, string categoryName, TraitCategoryType traitCategory, string filter = null, Control owner = null, Control ownerAncestor = null) { Func<IEnumerable<string>> itemsFunc = null; Func<string, bool> addItemFunc = null; string caption = "Select a value"; var service = new SupportService(user); switch (type) { case PickListType.Phrase: int phraseCategoryID = service.GetPhraseCategoryId(categoryName, true); caption = String.Format("Values for '{0}'", categoryName); itemsFunc = () => service.GetPhrases(phraseCategoryID).ConvertAll((phrase) => phrase.PhraseText); addItemFunc = (newphrase) => { Phrase phrase = new Phrase(); phrase.PhraseID = -1; phrase.PhraseCatID = phraseCategoryID; phrase.PhraseText = newphrase; // Save the new phrase value... service.InsertPhrase(phrase); return true; }; break; case PickListType.DistinctTraitList: caption = String.Format("Values for '{0}'", categoryName); itemsFunc = () => service.GetTraitValues(categoryName, traitCategory.ToString()); break; case PickListType.DistinctList: break; case PickListType.Trait: caption = String.Format("Existing trait names for {0}", traitCategory.ToString()); itemsFunc = () => service.GetTraitNamesForCategory(traitCategory.ToString()); break; case PickListType.MultimediaType: caption = "Select a multimedia type..."; itemsFunc = () => { return service.GetMultimediaTypes().ConvertAll((mmtype) => mmtype.Name); }; break; case PickListType.RefLinkType: caption = "Reference Link types"; itemsFunc = () => { var list = service.GetRefLinkTypes(); SortedDictionary<string, string> filtered = new SortedDictionary<string, string>(); // Remove the duplicates...Something really dodgey is going on when inserting ref links, it looks like // duplicate ref link types are being created. foreach (string item in list) { filtered[item] = item; } return filtered.Keys; }; addItemFunc = (newval) => { service.InsertRefLinkType(newval, traitCategory.ToString()); return true; }; break; default: throw new Exception("Unhandled pick list type: " + type); } PickListWindow frm = new PickListWindow(user, caption, itemsFunc, addItemFunc, filter, owner, ownerAncestor); if (frm.ShowDialog().GetValueOrDefault(false)) { return frm.SelectedValue as string; }; return null; }
public static string ShowPickList(User user, PickListType type, string categoryName, TraitCategoryType traitCategory, string filter = null, Control owner = null, Control ownerAncestor = null) { Func <IEnumerable <string> > itemsFunc = null; Func <string, bool> addItemFunc = null; string caption = "Select a value"; var service = new SupportService(user); switch (type) { case PickListType.Phrase: int phraseCategoryID = service.GetPhraseCategoryId(categoryName, true); caption = String.Format("Values for '{0}'", categoryName); itemsFunc = () => service.GetPhrases(phraseCategoryID).ConvertAll((phrase) => phrase.PhraseText); addItemFunc = (newphrase) => { Phrase phrase = new Phrase(); phrase.PhraseID = -1; phrase.PhraseCatID = phraseCategoryID; phrase.PhraseText = newphrase; // Save the new phrase value... service.InsertPhrase(phrase); return(true); }; break; case PickListType.DistinctTraitList: caption = String.Format("Values for '{0}'", categoryName); itemsFunc = () => service.GetTraitValues(categoryName, traitCategory.ToString()); break; case PickListType.DistinctList: break; case PickListType.Trait: caption = String.Format("Existing trait names for {0}", traitCategory.ToString()); itemsFunc = () => service.GetTraitNamesForCategory(traitCategory.ToString()); break; case PickListType.MultimediaType: caption = "Select a multimedia type..."; itemsFunc = () => { return(service.GetMultimediaTypes().ConvertAll((mmtype) => mmtype.Name)); }; break; case PickListType.RefLinkType: caption = "Reference Link types"; itemsFunc = () => { var list = service.GetRefLinkTypes(); SortedDictionary <string, string> filtered = new SortedDictionary <string, string>(); // Remove the duplicates...Something really dodgey is going on when inserting ref links, it looks like // duplicate ref link types are being created. foreach (string item in list) { filtered[item] = item; } return(filtered.Keys); }; addItemFunc = (newval) => { service.InsertRefLinkType(newval, traitCategory.ToString()); return(true); }; break; default: throw new Exception("Unhandled pick list type: " + type); } PickListWindow frm = new PickListWindow(user, caption, itemsFunc, addItemFunc, filter, owner, ownerAncestor); if (frm.ShowDialog().GetValueOrDefault(false)) { return(frm.SelectedValue as string); } ; return(null); }