Repository navigation
Expand file tree
/
Copy pathDynamicsPluginConfigurationControl.cs
More file actions
294 lines (246 loc) · 15.4 KB
/
Copy pathDynamicsPluginConfigurationControl.cs
File metadata and controls
294 lines (246 loc) · 15.4 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
using CRMPluginUtils;
using MicrosoftDynamicsCRMPlugin.Properties;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace MicrosoftDynamicsCRMPlugin
{
public partial class DynamicsPluginConfigurationControl : PluginConfigurationControl
{
private ConfigurationManager configurationManager = new ConfigurationManager("3CXCRMUser.ini");
private const string onPremiseText = "OnPremise";
private const string ifdText = "IFD";
private const string office365Text = "Office365";
private string contactsText = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.Contacts.Text");
private string leadsText = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.Leads.Text");
private string accountsText = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.Accounts.Text");
private OnPremiseAuthenticationConfigurationControl onPremiseAuthenticationConfigurationControl = new OnPremiseAuthenticationConfigurationControl();
private IFDAuthenticationConfigurationControl ifdAuthenticationConfigurationControl = new IFDAuthenticationConfigurationControl();
private Office365AuthenticationConfigurationControl office365AuthenticationConfigurationControl = new Office365AuthenticationConfigurationControl();
private void loadLabelsFromResources()
{
grpBoxLoginInformation.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.grpBoxLoginInformation.Text");
lblOrganization.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.lblOrganization.Text");
lblAuthenticationMethod.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.lblAuthenticationMethod.Text");
comboAuthenticationMethod.Items.AddRange(new string[] { onPremiseText, ifdText, office365Text });
authenticationControlPanel.Controls.AddRange(new Control[] { onPremiseAuthenticationConfigurationControl,
ifdAuthenticationConfigurationControl ,
office365AuthenticationConfigurationControl});
onPremiseAuthenticationConfigurationControl.Dock = DockStyle.Fill;
onPremiseAuthenticationConfigurationControl.Visible = false;
onPremiseAuthenticationConfigurationControl.Changed += new ChangedHandler(notifyControlChanged);
ifdAuthenticationConfigurationControl.Dock = DockStyle.Fill;
ifdAuthenticationConfigurationControl.Visible = false;
ifdAuthenticationConfigurationControl.Changed += new ChangedHandler(notifyControlChanged);
office365AuthenticationConfigurationControl.Dock = DockStyle.Fill;
office365AuthenticationConfigurationControl.Visible = false;
office365AuthenticationConfigurationControl.Changed += new ChangedHandler(notifyControlChanged);
grpBoxContactLookup.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.grpBoxContactLookup.Text");
chkLookupContacts.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.chkLookupContacts.Text");
chkLookupLeads.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.chkLookupLeads.Text");
chkLookupAccounts.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.chkLookupAccounts.Text");
lblLookupOrder.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.lblLookupOrder.Text");
chkBoxUseDefaultBrowser.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.chkBoxUseDefaultBrowser.Text");
lblSelectBrowser.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.lblSelectBrowser.Text");
selectBrowserButton.Text = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.selectBrowserButton.Text");
selectBrowserDialog.Title = LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.selectBrowserDialog.Title");
int maxWidth = Math.Max(lblOrganization.Width, lblAuthenticationMethod.Width);
txtOrganization.Location = new Point(6 + lblOrganization.Location.X + maxWidth, txtOrganization.Location.Y);
txtOrganization.Size = new Size(grpBoxLoginInformation.Width - txtOrganization.Location.X - 6, txtOrganization.Height);
comboAuthenticationMethod.Location = new Point(6 + lblAuthenticationMethod.Location.X + maxWidth, comboAuthenticationMethod.Location.Y);
comboAuthenticationMethod.Size = new Size(grpBoxLoginInformation.Width - comboAuthenticationMethod.Location.X - 6, comboAuthenticationMethod.Height);
}
private void loadInitialValues()
{
try
{
disableNotifications();
txtOrganization.Text = configurationManager.GetValue("Microsoft Dynamics Plug-in", "Organization", "");
string authenticationMethod = configurationManager.GetValue("Microsoft Dynamics Plug-in", "AuthenticationMethod", ifdText);
comboAuthenticationMethod.SelectedIndex = authenticationMethod == office365Text ? 2 : (authenticationMethod == ifdText ? 1 : 0);
int lookupContactsOrder = Convert.ToInt32(configurationManager.GetValue("Microsoft Dynamics Plug-in", "LookupContactsOrder", "0"));
int lookupLeadsOrder = Convert.ToInt32(configurationManager.GetValue("Microsoft Dynamics Plug-in", "LookupLeadsOrder", "1"));
int lookupAccountsOrder = Convert.ToInt32(configurationManager.GetValue("Microsoft Dynamics Plug-in", "LookupAccountsOrder", "-1"));
for (int index = 0; index < 3; ++index)
addLookupOrderItem(index, lookupContactsOrder, lookupLeadsOrder, lookupAccountsOrder);
if (lookupOrderListBox.Items.Count == 0)
{
moveDownButton.Enabled = false;
moveUpButton.Enabled = false;
}
else
lookupOrderListBox.SelectedIndex = 0;
chkOpenNewCase.Checked = configurationManager.GetValue("Microsoft Dynamics Plug-in", "OpenCaseNotContact", "False") == "True";
chkOpenPhoneCall.Checked = configurationManager.GetValue("Microsoft Dynamics Plug-in", "OpenPhoneCall", "False") == "True";
chkBoxUseDefaultBrowser.Checked = configurationManager.GetValue("Microsoft Dynamics Plug-in", "UseDefaultBrowser", "True") == "True";
txtBrowser.Text = configurationManager.GetValue("Microsoft Dynamics Plug-in", "CustomBrowser", "");
}
catch (Exception exc)
{
MessageBox.Show(String.Format(LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.Error.LoadingConfiguration"), ErrorHelper.GetErrorDescription(exc)), "3CX Microsoft Dynamics CRM Plug-in", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
enableNotifications();
}
}
private void addLookupOrderItem(int index, int lookupContactsOrder, int lookupLeadsOrder, int lookupAccountsOrder)
{
if (lookupContactsOrder == index)
chkLookupContacts.Checked = true;
else if (lookupLeadsOrder == index)
chkLookupLeads.Checked = true;
else if (lookupAccountsOrder == index)
chkLookupAccounts.Checked = true;
}
public DynamicsPluginConfigurationControl()
{
InitializeComponent();
loadLabelsFromResources();
loadInitialValues();
}
public override Image GetPluginIcon()
{
return Resources.Dynamics_CRM;
}
public override string GetPluginName()
{
return "Microsoft Dynamics CRM";
}
public override void LoadConfiguration()
{
onPremiseAuthenticationConfigurationControl.LoadConfiguration();
ifdAuthenticationConfigurationControl.LoadConfiguration();
office365AuthenticationConfigurationControl.LoadConfiguration();
loadInitialValues();
}
public override void Save()
{
if (!chkBoxUseDefaultBrowser.Checked && (String.IsNullOrEmpty(txtBrowser.Text) || !File.Exists(txtBrowser.Text)))
throw new ApplicationException(String.Format(LocalizedResourceManager.GetString("DotNetScript", "DynamicsPluginConfigurationControl.Error.InvalidCustomBrowser"), txtBrowser.Text));
switch (comboAuthenticationMethod.SelectedIndex)
{
case 0: onPremiseAuthenticationConfigurationControl.Save(); break;
case 1: ifdAuthenticationConfigurationControl.Save(); break;
case 2: office365AuthenticationConfigurationControl.Save(); break;
}
configurationManager.SetValue("Microsoft Dynamics Plug-in", "Organization", txtOrganization.Text);
configurationManager.SetValue("Microsoft Dynamics Plug-in", "AuthenticationMethod", comboAuthenticationMethod.SelectedItem.ToString());
// Initially set every item to -1 (disabled), then enable them in order, as specified in lookupOrderListBox
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupContactsOrder", "-1");
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupLeadsOrder", "-1");
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupAccountsOrder", "-1");
for (int index = 0; index < lookupOrderListBox.Items.Count; ++index)
{
if (lookupOrderListBox.Items[index].ToString() == contactsText)
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupContactsOrder", index.ToString());
else if (lookupOrderListBox.Items[index].ToString() == leadsText)
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupLeadsOrder", index.ToString());
else if (lookupOrderListBox.Items[index].ToString() == accountsText)
configurationManager.SetValue("Microsoft Dynamics Plug-in", "LookupAccountsOrder", index.ToString());
}
configurationManager.SetValue("Microsoft Dynamics Plug-in", "OpenCaseNotContact", chkOpenNewCase.Checked ? "True" : "False");
configurationManager.SetValue("Microsoft Dynamics Plug-in", "OpenPhoneCall", chkOpenPhoneCall.Checked ? "True" : "False");
configurationManager.SetValue("Microsoft Dynamics Plug-in", "UseDefaultBrowser", chkBoxUseDefaultBrowser.Checked ? "True" : "False");
configurationManager.SetValue("Microsoft Dynamics Plug-in", "CustomBrowser", txtBrowser.Text);
}
private void comboAuthenticationMethod_SelectedIndexChanged(object sender, EventArgs e)
{
onPremiseAuthenticationConfigurationControl.Visible = false;
ifdAuthenticationConfigurationControl.Visible = false;
office365AuthenticationConfigurationControl.Visible = false;
switch (comboAuthenticationMethod.SelectedIndex)
{
case 0: onPremiseAuthenticationConfigurationControl.Visible = true; break;
case 1: ifdAuthenticationConfigurationControl.Visible = true; break;
case 2: office365AuthenticationConfigurationControl.Visible = true; break;
}
notifyControlChanged();
}
private void textBox_GotFocus(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;
textBox.SelectAll();
}
private void textBox_TextChanged(object sender, EventArgs e)
{
notifyControlChanged();
}
private void maskedTextBox_GotFocus(object sender, EventArgs e)
{
MaskedTextBox textBox = sender as MaskedTextBox;
textBox.SelectAll();
}
private void maskedTextBox_TextChanged(object sender, EventArgs e)
{
notifyControlChanged();
}
private void chkLookupContacts_CheckedChanged(object sender, EventArgs e)
{
if (chkLookupContacts.Checked)
lookupOrderListBox.Items.Add(contactsText);
else
lookupOrderListBox.Items.Remove(contactsText);
notifyControlChanged();
}
private void chkLookupLeads_CheckedChanged(object sender, EventArgs e)
{
if (chkLookupLeads.Checked)
lookupOrderListBox.Items.Add(leadsText);
else
lookupOrderListBox.Items.Remove(leadsText);
notifyControlChanged();
}
private void chkLookupAccounts_CheckedChanged(object sender, EventArgs e)
{
if (chkLookupAccounts.Checked)
lookupOrderListBox.Items.Add(accountsText);
else
lookupOrderListBox.Items.Remove(accountsText);
notifyControlChanged();
}
private void lookupOrderListBox_SelectedIndexChanged(object sender, EventArgs e)
{
moveDownButton.Enabled = lookupOrderListBox.SelectedIndex >= 0 && lookupOrderListBox.SelectedIndex < lookupOrderListBox.Items.Count - 1;
moveUpButton.Enabled = lookupOrderListBox.SelectedIndex > 0;
}
private void moveUpButton_Click(object sender, EventArgs e)
{
string selectedItem = lookupOrderListBox.SelectedItem.ToString();
int selectedIndex = lookupOrderListBox.SelectedIndex;
lookupOrderListBox.Items.RemoveAt(selectedIndex);
lookupOrderListBox.Items.Insert(selectedIndex - 1, selectedItem);
lookupOrderListBox.SelectedIndex = selectedIndex - 1;
notifyControlChanged();
}
private void moveDownButton_Click(object sender, EventArgs e)
{
string selectedItem = lookupOrderListBox.SelectedItem.ToString();
int selectedIndex = lookupOrderListBox.SelectedIndex;
lookupOrderListBox.Items.RemoveAt(selectedIndex);
lookupOrderListBox.Items.Insert(selectedIndex + 1, selectedItem);
lookupOrderListBox.SelectedIndex = selectedIndex + 1;
notifyControlChanged();
}
private void chkBoxUseDefaultBrowser_CheckedChanged(object sender, EventArgs e)
{
txtBrowser.Enabled = !chkBoxUseDefaultBrowser.Checked;
selectBrowserButton.Enabled = !chkBoxUseDefaultBrowser.Checked;
notifyControlChanged();
}
private void chkOpenPhoneCall_CheckedChanged(object sender, EventArgs e)
{
notifyControlChanged();
}
private void chkOpenNewCase_CheckedChanged(object sender, EventArgs e)
{
notifyControlChanged();
}
private void selectBrowserButton_Click(object sender, EventArgs e)
{
if (selectBrowserDialog.ShowDialog() == DialogResult.OK)
txtBrowser.Text = selectBrowserDialog.FileName;
}
}
}