/
VariantPicklistMapControl.xaml.cs
103 lines (84 loc) · 2.97 KB
/
VariantPicklistMapControl.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace MultiTermTBXMapper.Menu
{
/// <summary>
/// Interaction logic for VariantPicklistMapControl.xaml
/// </summary>
public partial class VariantPicklistMapControl : UserControl
{
public Action<string[]> map;
public Action<bool> next;
private Dictionary<string, object[]> mapping = new Dictionary<string,object[]>();
public VariantPicklistMapControl()
{
InitializeComponent();
}
public void clear()
{
Methods.removeListBoxItems(ref lb_tbx_dcs);
Methods.removeListBoxItems(ref lb_user_picklists);
}
public void fillListBoxes(List<string> tbx_dcs, List<string> values)
{
foreach (string dc in tbx_dcs)
{
ListBoxItem item = new ListBoxItem();
item.Content = dc;
lb_tbx_dcs.Items.Add(item);
}
for (int i = 0; i < values.Count; i++)
{
ListBoxItem item = new ListBoxItem();
item.Content = values[i];
lb_user_picklists.Items.Add(item);
}
lb_user_picklists.SelectedIndex = 0;
}
private void lb_user_picklists_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count < 1)
{
return;
}
if (lb_user_picklists.SelectedItem != null)
{
string picklist_value = (e.AddedItems[0] as ListBoxItem).Content.ToString();
if (mapping.ContainsKey(picklist_value))
{
lb_tbx_dcs.SelectedIndex = (int) mapping[picklist_value][0];
}
else
{
lb_tbx_dcs.SelectedItem = lb_tbx_dcs.Items[0];
}
}
}
private void lb_tbx_dcs_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count < 1)
{
return;
}
string picklist_value = (lb_user_picklists.SelectedItem as ListBoxItem).Content.ToString();
string tbx_dc = (e.AddedItems[0] as ListBoxItem).Content.ToString();
int tbx_dc_index = lb_tbx_dcs.Items.IndexOf(e.AddedItems[0]);
string[] map_string = new string[2] { picklist_value, tbx_dc };
map?.Invoke(map_string);
if (mapping.ContainsKey(picklist_value))
{
mapping[picklist_value] = new object[2] { tbx_dc_index, tbx_dc };
}
else
{
mapping.Add(picklist_value, new object[2] { tbx_dc_index, tbx_dc });
}
}
private void btn_submit_Click(object sender, RoutedEventArgs e)
{
next(true);
}
}
}