我目前正在使用 AT Web 服务 API ( https://webservices5.autotask.net/ATServices/1.5/atws.asmx ) 为 AutoTask 实现编写一些代码。要执行任何操作,您基本上需要首先在 AT 中查询所有选项列表值。这是相当直截了当的,但是我在弄清楚如何分离所有“SubIssueTypes”以便它们可以轻松地链接到它们的父值“IssueType”时遇到了一些麻烦。
我一直将每个 PickList 放入一个字典中,并使该字典成为应用程序中 ComboBoxes 的源。这很好用,除了我不确定做 SubIssueTypes 的最佳方法是什么。每个 IssueType 都有多个链接到它的 SubIssueTypes,但是 AT 已将所有 SubIssueTypes 放在同一个 PickList 中。
如何将所有 SubIssueTypes 放入他们自己的 ComboBox 中,仅显示“pValue.parentValue”与当前选择的 IssueType 值匹配的值?
public static Dictionary<string, Resource> ResourcesById = new Dictionary<string, Resource>();
public static Dictionary<string, Account> AccountsById = new Dictionary<string, Account>();
public static Dictionary<string, string> ResourcesIdByName = new Dictionary<string, string>();
public static Dictionary<string, string> AccountsIdByName = new Dictionary<string, string>();
public static Dictionary<string, string> AccountsNameById = new Dictionary<string, string>();
public static Dictionary<string, string> StatusIdByName = new Dictionary<string, string>();
public static Dictionary<string, string> StatusNameById = new Dictionary<string, string>();
public static Dictionary<string, string> IssueType = new Dictionary<string, string>();
public static Dictionary<string, string> SubIssueType = new Dictionary<string, string>();
public static Dictionary<string, Tuple<string, string>> SubIssueLabel = new Dictionary<string, Tuple<string, string>>();
public static Dictionary<Tuple<string, string>, string> SubIssueValue = new Dictionary<Tuple<string, string>, string>();
public static Dictionary<string, string> Priority = new Dictionary<string, string>();
public static Dictionary<string, string> Source = new Dictionary<string, string>();
public static Dictionary<string, string> ServiceLevelAgreement = new Dictionary<string, string>();
public static Dictionary<string, string> TicketType = new Dictionary<string, string>();
public static Dictionary<string, string> QueueNameById = new Dictionary<string, string>();
public static Dictionary<string, string> QueueIdByName = new Dictionary<string, string>();
public static Dictionary<string, string> AssignedResourceRole = new Dictionary<string, string>();
public static Dictionary<string, string> AssignedResource = new Dictionary<string, string>();
public static Dictionary<string, string> AllocationCode = new Dictionary<string, string>();
public static Dictionary<string, string> ResourcesNameById = new Dictionary<string, string>();
public static void Preload()
{
var client = new SoapClient().Admin();
AutotaskIntegrations ati = new AutotaskIntegrations();
Field[] fieldInfo = client.GetFieldInfo(ati, "Ticket");
foreach (var item in fieldInfo)
{
if (item.IsPickList)
{
foreach (var pValue in item.PicklistValues)
{
switch (item.Name)
{
case "Status":
StatusIdByName.Add(pValue.Label, pValue.Value);
StatusNameById.Add(pValue.Value, pValue.Label);
break;
case "IssueType":
IssueType.Add(pValue.Label, pValue.Value);
break;
case "SubIssueType":
SubIssueLabel.Add(pValue.Label, new Tuple<string, string>(pValue.parentValue, pValue.Value));
SubIssueValue.Add(new Tuple<string, string>(pValue.parentValue, pValue.Value), pValue.Label);
break;
case "Priority":
Priority.Add(pValue.Label, pValue.Value);
break;
case "Source":
Source.Add(pValue.Label, pValue.Value);
break;
case "ServiceLevelAgreementID":
ServiceLevelAgreement.Add(pValue.Label, pValue.Value);
break;
case "TicketType":
TicketType.Add(pValue.Label, pValue.Value);
break;
case "QueueID":
QueueNameById.Add(pValue.Value, pValue.Label);
QueueIdByName.Add(pValue.Label, pValue.Value);
break;
case "AllocationCodeID":
AllocationCode.Add(pValue.Label, pValue.Value);
break;
case "AssignedResourceID":
AssignedResource.Add(pValue.Label, pValue.Value);
break;
case "AssignedResourceRoleID":
AssignedResourceRole.Add(pValue.Label, pValue.Value);
break;
}
}
}
}
}
现在,对于大多数 PickList -> Dictionaries,我可以简单地将源指定为字典。
private void FillCombos()
{
AutoTaskData.Preload();
AutoTaskData.ResourcesIdByName.Add("", "clear");
ResourceBox.ItemsSource = AutoTaskData.ResourcesIdByName;
AutoTaskData.QueueIdByName.Add("", "clear");
QueueBox.ItemsSource = AutoTaskData.QueueIdByName;
AutoTaskData.StatusIdByName.Add("", "clear");
StatusBox.ItemsSource = AutoTaskData.StatusIdByName;
}
XAML:
<ComboBox x:Name="QueueBox" SelectedValuePath="Value" DisplayMemberPath="Key" SelectionChanged="QueueBox_SelectionChanged" />
<TextBlock Margin="5,10,10,0">Resource</TextBlock>
<ComboBox x:Name="ResourceBox" SelectedValuePath="Value" DisplayMemberPath="Key" SelectionChanged="ResourceBox_SelectionChanged" />
<TextBlock Margin="5,10,10,0">Status</TextBlock>
<ComboBox x:Name="StatusBox" SelectedValuePath="Value" DisplayMemberPath="Key" />
不过,这显然不适用于 SubIssueType,因为它们都在一个字典中,如果选择了与其“pValue.ParentValue”变量(或者换句话说字典键的第一个元组)匹配的 IssueType,我只希望显示值或价值)。也许元组不是要走的路,但是我不确定最好的实现是什么。