-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingForm.cs
More file actions
77 lines (75 loc) · 3.18 KB
/
Copy pathSettingForm.cs
File metadata and controls
77 lines (75 loc) · 3.18 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
using System;
using System.Configuration;
using System.Text;
using System.Windows.Forms;
namespace HomeWorkSQL
{
public partial class SettingForm : Form
{
public SettingForm()
{
InitializeComponent();
ServerTextBox.Text = ConfigurationManager.AppSettings["Server"];
DataBaseTextBox.Text = ConfigurationManager.AppSettings["Database"];
UIDTextBox.Text = ConfigurationManager.AppSettings["Uid"];
PassWordTextBox.Text = ConfigurationManager.AppSettings["Password"];
}
private void Save_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(ServerTextBox.Text) && !string.IsNullOrEmpty(DataBaseTextBox.Text)
&& !string.IsNullOrEmpty(UIDTextBox.Text) && !string.IsNullOrEmpty(PassWordTextBox.Text))
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["Server"].Value = ServerTextBox.Text;
config.AppSettings.Settings["Database"].Value = DataBaseTextBox.Text;
config.AppSettings.Settings["UID"].Value = UIDTextBox.Text;
config.AppSettings.Settings["Password"].Value = PassWordTextBox.Text;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
MessageBox.Show("값이 App.config에 저장되었습니다.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
string errorMessage = ConfigEmptyCheck(string.IsNullOrEmpty(ServerTextBox.Text),
string.IsNullOrEmpty(DataBaseTextBox.Text)
, string.IsNullOrEmpty(UIDTextBox.Text), string.IsNullOrEmpty(PassWordTextBox.Text));
MessageBox.Show(errorMessage + " \nFill in the Blank","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
private string ConfigEmptyCheck(bool ServerEmpty, bool DataBaseEmpty, bool UIDEmpty, bool PasswordEmpty)
{
StringBuilder emptyFields = new StringBuilder();
if (ServerEmpty)
{
if (emptyFields.Length > 0)
emptyFields.Append(", ");
emptyFields.Append("Server");
}
if (DataBaseEmpty)
{
if (emptyFields.Length > 0)
emptyFields.Append(", ");
emptyFields.Append("Database");
}
if (UIDEmpty)
{
if (emptyFields.Length > 0)
emptyFields.Append(", ");
emptyFields.Append("UID");
}
if (PasswordEmpty)
{
if (emptyFields.Length > 0)
emptyFields.Append(", ");
emptyFields.Append("Password");
}
emptyFields.Append(" is Empty");
return emptyFields.Length > 0 ? emptyFields.ToString() : null;
}
private void Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}