0

我目前正在使用 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,我只希望显示值或价值)。也许元组不是要走的路,但是我不确定最好的实现是什么。

4

2 回答 2

0

我相信我找到了一种方法来做到这一点。我不知道这是否是最好的方法,但它似乎有效。

我将字典更改为“预加载”区域中的元组列表。

public static List<Tuple<string,string,string>> Subs = new List<Tuple<string, 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":

                            Subs.Add(new Tuple<string, string, string>(pValue.parentValue, pValue.Label, pValue.Value));
                            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;
                    }
                }
            }
        }
}

然后,我创建了一个 CurrentSub 字典,用于保存当前选定的 IssueType 的所有 SubIssueType。每次 IssueType 更改都会清除字典。

private Dictionary<string, string> CurrentSub = new Dictionary<string, string>(); 

在“工单详细信息”控件中,我使用以下内容填充 ComboBoxes(最初和在 IssueType 更改时)。

public partial class TicketDetailControl : UserControl
{

    private Ticket info = null;

    public TicketDetailControl()
    {
        InitializeComponent();
    }

    public Ticket Info
    {
        get { return info; }
        set
        {
            info = value;

            Description.Text = info.Description.ToString();

            Status.ItemsSource = AutoTaskData.StatusIdByName;
            Status.SelectedValue = info.Status.ToString();

            Queue.ItemsSource = AutoTaskData.QueueIdByName;
            Queue.SelectedValue = info.QueueID.ToString();

            IssueType.ItemsSource = AutoTaskData.IssueType;
            IssueType.SelectedValue = info.IssueType.ToString();

            CurrentSub.Clear();
            SubIssueType.ItemsSource = null;
            foreach (var item in AutoTaskData.Subs.Where(item => item.Item1 == (string)IssueType.SelectedValue))
            {
                CurrentSub.Add(item.Item2, item.Item3);
            }

            SubIssueType.ItemsSource = CurrentSub;
            SubIssueType.SelectedValue = info.SubIssueType.ToString();





        }

    }

    private Dictionary<string, string> CurrentSub = new Dictionary<string, string>(); 

    private void IssueType_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        CurrentSub.Clear();
        SubIssueType.ItemsSource = null;

        foreach (var item in AutoTaskData.Subs.Where(item => item.Item1 == (string) IssueType.SelectedValue))
        {
            CurrentSub.Add(item.Item2, item.Item3);
        }

        SubIssueType.ItemsSource = CurrentSub;


    }
}
于 2015-04-15T02:31:23.217 回答
0

Tom,

We merge the IssueTypes and SubIssueTypes into a single set of values. Here's how we do it.

Let's assume we have 2 IssueTypes:

  • Hardware (id=1)
  • Software (id=2)

And 4 SubIssueTypes:

  • Repair (id=1, Parent=1 Hardware)
  • Upgrade (id=2, Parent=1 Hardware)
  • Bug (id=3, Parent=2 Software)
  • Enhancement (id=4, Parent=2 Software)

For this set of options, we combine it into 1 set of options:

  • Hardware (id=-1)
  • Hardware / Repair (id=1)
  • Hardware / Upgrade (id=2)
  • Software (id=-2)
  • Software / Bug (id=3)
  • Software / Enhancement (id=4)

Notice that the items in my list that represent an IssueType with no SubIssueType are negative numbers. The others are positive.

When the user submits a value of -1, we know it's for IssueType id=1. When they submit a value of 3, we do a lookup for SubIssueType id=3 to find that its parent id=2.

Not sure if this will help you in your project, but it's worked well for us.

Hope this helps,

Travis

于 2015-04-15T05:06:19.703 回答