Skip to content

Commit 1cd3be0

Browse files
committed
🚀 프로젝트 완성
1 parent ab23c92 commit 1cd3be0

File tree

3 files changed

+249
-10
lines changed

3 files changed

+249
-10
lines changed

GunplaWinForm/Form1.Designer.cs

Lines changed: 166 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GunplaWinForm/Form1.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111

1212
namespace GunplaWinForm {
1313
public partial class Form1 : Form {
14+
15+
GunplaRepository db = new GunplaRepository();
16+
1417
public Form1() {
1518
InitializeComponent();
1619
}
1720

1821
private void button1_Click(object sender, EventArgs e) {
19-
GunplaRepository db = new GunplaRepository();
20-
2122
string error = db.Connect();
2223

2324
if (error != null)
@@ -29,5 +30,56 @@ private void button1_Click(object sender, EventArgs e) {
2930
gridMechanic.DataSource = data;
3031
gridMechanic.DataMember = "mechanic";
3132
}
33+
34+
private void OnAdd(object sender, EventArgs e) {
35+
if (textName.Text.ToString().Length == 0) {
36+
MessageBox.Show("Name을 입력해 주세요.");
37+
textName.Focus();
38+
return;
39+
}
40+
41+
if (textModel.Text.ToString().Length == 0) {
42+
MessageBox.Show("Model을 입력해 주세요.");
43+
textModel.Focus();
44+
return;
45+
}
46+
47+
if (textHeight.Text.ToString().Length == 0) {
48+
MessageBox.Show("Height를 입력해 주세요.");
49+
textHeight.Focus();
50+
return;
51+
}
52+
53+
double height = 0.0f;
54+
if (double.TryParse(textHeight.Text, out height) == false) {
55+
MessageBox.Show("Height를 double 타입으로 입력해 주세요.");
56+
textHeight.Focus();
57+
return;
58+
}
59+
60+
if (textWeight.Text.ToString().Length == 0) {
61+
MessageBox.Show("Weight를 입력해 주세요.");
62+
textWeight.Focus();
63+
return;
64+
}
65+
66+
double weight = 0.0f;
67+
if (double.TryParse(textWeight.Text, out weight) == false) {
68+
MessageBox.Show("Weight를 double 타입으로 입력해 주세요.");
69+
textWeight.Focus();
70+
return;
71+
}
72+
73+
db.Insert(
74+
textName.Text,
75+
textModel.Text,
76+
textManufacturer.Text,
77+
textArmor.Text,
78+
height,
79+
weight
80+
);
81+
82+
gridMechanic.DataSource = db.Mechanic();
83+
}
3284
}
3385
}

GunplaWinForm/GunplaRepository.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ class GunplaRepository {
1111
MySqlConnection dbc = null;
1212

1313
public string Connect() {
14-
string con = "server=52.79.110.60;user=root;database=gunpladb;port=52804;password=mysql1234";
14+
if (dbc != null)
15+
dbc.Close();
16+
17+
string con = "server=13.209.64.228;user=root;database=gunpladb;port=50513;password=mysql1234;charset='utf8'";
1518
dbc = new MySqlConnection(con);
1619
try {
1720
dbc.Open();
@@ -26,14 +29,37 @@ public void Close() {
2629
}
2730

2831
public DataSet Mechanic() {
29-
MySqlDataAdapter adapter;
32+
if (dbc.State != ConnectionState.Open)
33+
return null;
34+
3035
string query = "SELECT * FROM mechanic";
31-
adapter = new MySqlDataAdapter(query, dbc);
36+
MySqlDataAdapter adapter = new MySqlDataAdapter(query, dbc);
3237

3338
DataSet data = new DataSet();
3439
adapter.Fill(data, "mechanic");
3540

3641
return data;
3742
}
43+
44+
public string Insert(string name, string model, string manufacturer, string armor, double height, double weight) {
45+
try {
46+
string query = @"
47+
INSERT INTO mechanic (id, name, model, manufacturer, armor, height, weight) VALUES
48+
(null, @name, @model, @manufacturer, @armor, @height, @weight)
49+
";
50+
MySqlCommand cmd = new MySqlCommand(query, dbc);
51+
cmd.Parameters.AddWithValue("@name", name);
52+
cmd.Parameters.AddWithValue("@model", model);
53+
cmd.Parameters.AddWithValue("@manufacturer", manufacturer);
54+
cmd.Parameters.AddWithValue("@armor", armor);
55+
cmd.Parameters.AddWithValue("@height", height);
56+
cmd.Parameters.AddWithValue("@weight", weight);
57+
cmd.ExecuteNonQuery();
58+
return null;
59+
}
60+
catch (Exception ex) {
61+
return ex.ToString();
62+
}
63+
}
3864
}
3965
}

0 commit comments

Comments
 (0)