Repository navigation
Expand file tree
/
Copy pathOffice365AuthenticationConfigurationControl.cs
More file actions
109 lines (95 loc) · 4.66 KB
/
Copy pathOffice365AuthenticationConfigurationControl.cs
File metadata and controls
109 lines (95 loc) · 4.66 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
using CRMPluginUtils;
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MicrosoftDynamicsCRMPlugin
{
public partial class Office365AuthenticationConfigurationControl : PluginConfigurationPartControl
{
private ConfigurationManager configurationManager = new ConfigurationManager("3CXCRMUser.ini");
private const string locationNorthAmericaText = "North America";
private const string locationNorthAmerica2Text = "North America 2";
private const string locationEMEAText = "EMEA";
private const string locationAPACText = "APAC";
private const string locationOceaniaText = "Oceania";
private const string locationJapanText = "Japan";
private const string locationSouthAmericaText = "South America";
private const string locationIndiaText = "India";
private const string locationCanadaText = "Canada";
private int getLocationIndex(string location)
{
if (location == locationNorthAmericaText) return 0;
if (location == locationNorthAmerica2Text) return 1;
if (location == locationEMEAText) return 2;
if (location == locationAPACText) return 3;
if (location == locationOceaniaText) return 4;
if (location == locationJapanText) return 5;
if (location == locationSouthAmericaText) return 6;
if (location == locationIndiaText) return 7;
if (location == locationCanadaText) return 8;
return 0;
}
private void loadLabelsFromResources()
{
lblUserName.Text = LocalizedResourceManager.GetString("DotNetScript", "Office365AuthenticationConfigurationControl.lblUserName.Text");
lblPassword.Text = LocalizedResourceManager.GetString("DotNetScript", "Office365AuthenticationConfigurationControl.lblPassword.Text");
lblLocation.Text = LocalizedResourceManager.GetString("DotNetScript", "Office365AuthenticationConfigurationControl.lblLocation.Text");
comboLocation.Items.AddRange(new string[] { locationNorthAmericaText, locationNorthAmerica2Text, locationEMEAText, locationAPACText, locationOceaniaText, locationJapanText, locationSouthAmericaText, locationIndiaText, locationCanadaText });
int maxWidth = Math.Max(lblUserName.Width, Math.Max(lblPassword.Width, lblLocation.Width));
txtUserName.Location = new Point(6 + lblUserName.Location.X + maxWidth, txtUserName.Location.Y);
txtUserName.Size = new Size(Width - txtUserName.Location.X - 6, txtUserName.Height);
txtPassword.Location = new Point(6 + lblPassword.Location.X + maxWidth, txtPassword.Location.Y);
txtPassword.Size = new Size(Width - txtPassword.Location.X - 6, txtPassword.Height);
comboLocation.Location = new Point(6 + lblLocation.Location.X + maxWidth, comboLocation.Location.Y);
comboLocation.Size = new Size(Width - comboLocation.Location.X - 6, comboLocation.Height);
}
private void loadInitialValues()
{
try
{
disableNotifications();
txtUserName.Text = configurationManager.GetValue("Microsoft Dynamics Plug-in", "UserName", "");
txtPassword.Text = configurationManager.GetCryptedValue("Microsoft Dynamics Plug-in", "Password", "");
string location = configurationManager.GetValue("Microsoft Dynamics Plug-in", "WindowsLiveLocation", locationNorthAmericaText);
comboLocation.SelectedIndex = getLocationIndex(location);
}
catch (Exception exc)
{
MessageBox.Show(String.Format(LocalizedResourceManager.GetString("DotNetScript", "Office365AuthenticationConfigurationControl.Error.LoadingConfiguration"), ErrorHelper.GetErrorDescription(exc)), "3CX Microsoft Dynamics CRM Plug-in", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
enableNotifications();
}
}
public Office365AuthenticationConfigurationControl()
{
InitializeComponent();
loadLabelsFromResources();
loadInitialValues();
}
public override void LoadConfiguration()
{
loadInitialValues();
}
public override void Save()
{
configurationManager.SetValue("Microsoft Dynamics Plug-in", "UserName", txtUserName.Text);
configurationManager.SetCryptedValue("Microsoft Dynamics Plug-in", "Password", txtPassword.Text);
configurationManager.SetValue("Microsoft Dynamics Plug-in", "WindowsLiveLocation", comboLocation.SelectedItem.ToString());
}
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 comboLocation_SelectedIndexChanged(object sender, EventArgs e)
{
notifyControlChanged();
}
}
}