-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrmSetting.vb
More file actions
269 lines (224 loc) · 10.5 KB
/
Copy pathfrmSetting.vb
File metadata and controls
269 lines (224 loc) · 10.5 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
Imports System.IO
Imports System.Windows.Forms
Public Class frmSetting
Private iniHelper As IniHelper
Private ReadOnly iniFilePath As String = Path.Combine(Application.StartupPath, "sconfig.ini")
' Settings properties
Public Property GenerateDropStatements As Boolean = False
Public Property OverwriteExistingFiles As Boolean = True
Public Property OpenOutputFolderAfterOperation As Boolean = False ' New property
#Region "Form Events"
Private Sub frmSetting_Load(sender As Object, e As EventArgs) Handles MyBase.Load
InitializeForm()
LoadSettings()
End Sub
#End Region
#Region "Initialization"
Private Sub InitializeForm()
' Initialize INI helper
iniHelper = New IniHelper(iniFilePath)
' Set form properties
Me.Text = "RepoSQL Settings"
' Set default values
GenerateDropStatements = False
OverwriteExistingFiles = True
OpenOutputFolderAfterOperation = False ' Default to false
End Sub
#End Region
#Region "Settings Management"
''' <summary>
''' Load settings from sconfig.ini file
''' </summary>
Private Sub LoadSettings()
Try
' Load settings from INI file
GenerateDropStatements = iniHelper.ReadBoolean("GenerationSettings", "GenerateDropStatements", False)
OverwriteExistingFiles = iniHelper.ReadBoolean("GenerationSettings", "OverwriteExistingFiles", True)
OpenOutputFolderAfterOperation = iniHelper.ReadBoolean("GenerationSettings", "OpenOutputFolderAfterOperation", False)
' Update UI controls
chkGenerateDropStatements.Checked = GenerateDropStatements
chkOverwriteExistingFiles.Checked = OverwriteExistingFiles
chkOpenOutputFolder.Checked = OpenOutputFolderAfterOperation
Catch ex As Exception
UpdateButtonStatus(btnApply, "error", "Error loading settings")
End Try
End Sub
''' <summary>
''' Save settings to sconfig.ini file
''' </summary>
Private Sub SaveSettings()
Try
' Get values from UI controls
GenerateDropStatements = chkGenerateDropStatements.Checked
OverwriteExistingFiles = chkOverwriteExistingFiles.Checked
OpenOutputFolderAfterOperation = chkOpenOutputFolder.Checked
' Save to INI file
iniHelper.WriteBoolean("GenerationSettings", "GenerateDropStatements", GenerateDropStatements)
iniHelper.WriteBoolean("GenerationSettings", "OverwriteExistingFiles", OverwriteExistingFiles)
iniHelper.WriteBoolean("GenerationSettings", "OpenOutputFolderAfterOperation", OpenOutputFolderAfterOperation)
' Write timestamp
iniHelper.WriteValue("GenerationSettings", "LastUpdated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
Catch ex As Exception
UpdateButtonStatus(btnApply, "error", "Error saving settings")
End Try
End Sub
''' <summary>
''' Reset settings to default values
''' </summary>
Private Sub ResetSettings()
GenerateDropStatements = False
OverwriteExistingFiles = True
OpenOutputFolderAfterOperation = False
' Update UI controls
chkGenerateDropStatements.Checked = GenerateDropStatements
chkOverwriteExistingFiles.Checked = OverwriteExistingFiles
chkOpenOutputFolder.Checked = OpenOutputFolderAfterOperation
End Sub
''' <summary>
''' Update button status with visual feedback
''' </summary>
''' <param name="button">Button to update</param>
''' <param name="status">Status type (success, error, warning, info)</param>
''' <param name="message">Status message</param>
''' <param name="autoRevert">Whether to auto-revert after 3 seconds</param>
Private Sub UpdateButtonStatus(button As Button, status As String, message As String, Optional autoRevert As Boolean = True)
Dim originalText As String = button.Tag?.ToString() ' Store original text in Tag
If String.IsNullOrEmpty(originalText) Then
button.Tag = button.Text
originalText = button.Text
End If
Dim originalColor As Color = button.BackColor
Select Case status.ToLower()
Case "success"
button.BackColor = Color.FromArgb(40, 167, 69)
button.Text = "✓ " & message
Case "error"
button.BackColor = Color.FromArgb(220, 53, 69)
button.Text = "✗ " & message
Case "warning"
button.BackColor = Color.FromArgb(255, 193, 7)
button.ForeColor = Color.Black
button.Text = "⚠ " & message
Case "info"
button.BackColor = Color.FromArgb(0, 120, 215)
button.Text = "ℹ " & message
Case "loading"
button.BackColor = Color.FromArgb(108, 117, 125)
button.Text = "⏳ " & message
End Select
Application.DoEvents()
If autoRevert Then
' Auto-revert after 3 seconds using a Timer instead of Task.Delay
Dim revertTimer As New Timer()
revertTimer.Interval = 3000 ' 3 seconds
AddHandler revertTimer.Tick, Sub()
revertTimer.Stop()
revertTimer.Dispose()
If Not Me.IsDisposed AndAlso Me.IsHandleCreated Then
button.Text = originalText
button.BackColor = originalColor
button.ForeColor = Color.White
End If
End Sub
revertTimer.Start()
End If
End Sub
#End Region
#Region "Button Event Handlers"
Private Sub btnOK_Click(sender As Object, e As EventArgs) Handles btnOK.Click
SaveSettings()
UpdateButtonStatus(btnOK, "success", "Settings saved")
' Delay close to show status using Timer instead of Task.Delay
Dim closeTimer As New Timer()
closeTimer.Interval = 1000 ' 1 second
AddHandler closeTimer.Tick, Sub()
closeTimer.Stop()
closeTimer.Dispose()
If Not Me.IsDisposed AndAlso Me.IsHandleCreated Then
Me.DialogResult = DialogResult.OK
Me.Close()
End If
End Sub
closeTimer.Start()
End Sub
Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
Me.DialogResult = DialogResult.Cancel
Me.Close()
End Sub
Private Sub btnApply_Click(sender As Object, e As EventArgs) Handles btnApply.Click
SaveSettings()
UpdateButtonStatus(btnApply, "success", "Applied successfully")
End Sub
Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click
' Create custom confirmation dialog instead of MessageBox
Using confirmDialog As New Form()
confirmDialog.Text = "Reset Settings"
confirmDialog.Size = New Size(400, 200)
confirmDialog.StartPosition = FormStartPosition.CenterParent
confirmDialog.FormBorderStyle = FormBorderStyle.FixedDialog
confirmDialog.MaximizeBox = False
confirmDialog.MinimizeBox = False
confirmDialog.ShowIcon = False
Dim lblMessage As New Label()
lblMessage.Text = "Reset all settings to default values?"
lblMessage.Font = New Font("Segoe UI", 10)
lblMessage.Location = New Point(20, 30)
lblMessage.Size = New Size(360, 50)
lblMessage.TextAlign = ContentAlignment.MiddleCenter
Dim btnYes As New Button()
btnYes.Text = "Yes"
btnYes.Location = New Point(220, 100)
btnYes.Size = New Size(75, 30)
btnYes.BackColor = Color.FromArgb(40, 167, 69)
btnYes.ForeColor = Color.White
btnYes.FlatStyle = FlatStyle.Flat
btnYes.DialogResult = DialogResult.Yes
AddHandler btnYes.Click, Sub() confirmDialog.Close()
Dim btnNo As New Button()
btnNo.Text = "No"
btnNo.Location = New Point(305, 100)
btnNo.Size = New Size(75, 30)
btnNo.BackColor = Color.FromArgb(108, 117, 125)
btnNo.ForeColor = Color.White
btnNo.FlatStyle = FlatStyle.Flat
btnNo.DialogResult = DialogResult.No
AddHandler btnNo.Click, Sub() confirmDialog.Close()
confirmDialog.Controls.AddRange({lblMessage, btnYes, btnNo})
confirmDialog.AcceptButton = btnYes
confirmDialog.CancelButton = btnNo
If confirmDialog.ShowDialog(Me) = DialogResult.Yes Then
ResetSettings()
UpdateButtonStatus(btnReset, "success", "Settings reset")
End If
End Using
End Sub
#End Region
#Region "Public Methods"
''' <summary>
''' Get current settings from the form
''' </summary>
''' <returns>Dictionary containing current settings</returns>
Public Function GetCurrentSettings() As Dictionary(Of String, Object)
Dim settings As New Dictionary(Of String, Object)
settings("GenerateDropStatements") = chkGenerateDropStatements.Checked
settings("OverwriteExistingFiles") = chkOverwriteExistingFiles.Checked
settings("OpenOutputFolderAfterOperation") = chkOpenOutputFolder.Checked
Return settings
End Function
''' <summary>
''' Apply settings to the form
''' </summary>
''' <param name="settings">Dictionary containing settings to apply</param>
Public Sub ApplySettings(settings As Dictionary(Of String, Object))
If settings.ContainsKey("GenerateDropStatements") Then
chkGenerateDropStatements.Checked = CBool(settings("GenerateDropStatements"))
End If
If settings.ContainsKey("OverwriteExistingFiles") Then
chkOverwriteExistingFiles.Checked = CBool(settings("OverwriteExistingFiles"))
End If
If settings.ContainsKey("OpenOutputFolderAfterOperation") Then
chkOpenOutputFolder.Checked = CBool(settings("OpenOutputFolderAfterOperation"))
End If
End Sub
#End Region
End Class