-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptionDlg.cs
More file actions
186 lines (149 loc) · 6.32 KB
/
OptionDlg.cs
File metadata and controls
186 lines (149 loc) · 6.32 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
/*
Copyright (C) 2016 Marko Graf
*/
using System;
using System.IO;
using System.Windows.Forms;
using KeePass.Forms;
namespace KeeSAPLogon
{
public partial class OptionDlg : Form
{
private readonly MainForm m_form = null;
private readonly SAPLogonOpt m_config = null;
//---------------------------------------------------------------------------------------------------
// Class Constructors
//---------------------------------------------------------------------------------------------------
public OptionDlg(MainForm form, SAPLogonOpt config)
{
InitializeComponent();
this.tbDefaultLng.KeyPress += new KeyPressEventHandler(this.tbDefaultLng_KeyPress);
this.Text = Translatable.TitelOptionDlg;
this.Icon = IconExtractor.GetSettingsIcon();
this.btnFolderDlg.Image = IconExtractor.GetOpenFolderIcon().ToBitmap();
this.fbDlgGUIPath.RootFolder = Environment.SpecialFolder.ProgramFilesX86;
LoadOptions(config);
m_form = form;
m_config = config;
}
//---------------------------------------------------------------------------------------------------
// Class Destructor
//---------------------------------------------------------------------------------------------------
~OptionDlg()
{
this.tbDefaultLng.KeyPress -= new KeyPressEventHandler(this.tbDefaultLng_KeyPress);
}
//---------------------------------------------------------------------------------------------------
// Eventhandler
//---------------------------------------------------------------------------------------------------
private void OptionDlg_Shown(object sender, EventArgs e)
{
UpdatePathMsg();
}
private void tbDefaultLng_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsLetter(e.KeyChar))
{
//Further processing allowed by setting FALSE, that's what we want
e.Handled = false;
}
else
{
//No further processing allowed by setting TRUE, that's what we want
e.Handled = true;
}
}
private void tbSAPGUIPath_TextChanged(object sender, EventArgs e)
{
UpdatePathMsg();
}
private void btFolderDlg_Click(object sender, EventArgs e)
{
if (fbDlgGUIPath.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.tbSAPGUIPath.Text = fbDlgGUIPath.SelectedPath;
UpdatePathMsg();
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (!(this.cbSAPID.Checked || this.cbClient.Checked || this.cbLanguage.Checked || this.cbTransaction.Checked))
{
MessageBox.Show(Translatable.ErrorMsgDisplayOption, KeeSAPLogonExt.PlugInName + " settings error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!SAPLogonHandler.ValidateSAPGUIPath(this.tbSAPGUIPath.Text))
{
MessageBox.Show(Translatable.ErrorMsgSAPGUIPath, KeeSAPLogonExt.PlugInName + " settings error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
this.DialogResult = DialogResult.OK;
SaveOptions();
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
//---------------------------------------------------------------------------------------------------
// Private Methods
//---------------------------------------------------------------------------------------------------
private void UpdatePathMsg()
{
string msg = "";
if (!SAPLogonHandler.ValidateSAPGUIPath(this.tbSAPGUIPath.Text))
{
msg = Translatable.ValidationInfoNeg;
msg = msg.Replace("%EXE_NAME%", SAPLogonHandler.SAPGUIShortCutEXE);
this.tbPathValidInfo.Text = msg;
return;
}
if (m_config != null)
{
if (m_config.AutoDetected)
{
msg = Translatable.ValidationInfoAuto;
msg = msg.Replace("%EXE_NAME%", SAPLogonHandler.SAPGUIShortCutEXE);
this.tbPathValidInfo.Text = msg;
return;
}
}
if (SAPLogonHandler.ValidateSAPGUIPath(this.tbSAPGUIPath.Text))
{
msg = Translatable.ValidationInfoPos;
msg = msg.Replace("%EXE_NAME%", SAPLogonHandler.SAPGUIShortCutEXE);
this.tbPathValidInfo.Text = msg;
return;
}
}
private void LoadOptions(SAPLogonOpt config)
{
if (config != null)
{
this.cbSAPID.Checked = Convert.ToBoolean(config.DisSystemID);
this.cbClient.Checked = Convert.ToBoolean(config.DisClient);
this.cbLanguage.Checked = Convert.ToBoolean(config.DisLanguage);
this.cbTransaction.Checked = Convert.ToBoolean(config.DisTx);
this.tbDefaultLng.Text = config.DefaultLng;
this.tbDefaultTx.Text = config.DefaultTx;
this.tbSAPGUIPath.Text = config.SAPGUIPath;
}
}
private void SaveOptions()
{
if (m_config != null)
{
m_config.DisSystemID = this.cbSAPID.Checked;
m_config.DisClient = this.cbClient.Checked;
m_config.DisLanguage = this.cbLanguage.Checked;
m_config.DisTx = this.cbTransaction.Checked;
m_config.DefaultLng = this.tbDefaultLng.Text;
m_config.DefaultTx = this.tbDefaultTx.Text;
m_config.SAPGUIPath = this.tbSAPGUIPath.Text;
}
if (m_form != null)
{
m_form.RefreshEntriesList();
}
}
}
}