-
Notifications
You must be signed in to change notification settings - Fork 0
/
Add_Content.xaml.cs
108 lines (101 loc) · 3.88 KB
/
Add_Content.xaml.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using MySql.Data;
using MySql.Data.Common;
using MySql.Data.MySqlClient;
namespace Hoooon22_Program
{
/// <summary>
/// Add_Content.xaml에 대한 상호 작용 논리
/// </summary>
public partial class Add_Content : Window
{
Finance finance1; // 동기화를 위한
MySqlConnection conn;
string dbTable = "finace_content_tb"; // 접근할 테이블 설정
string dbInfo()
{
string dbServer = "localhost";
string dbDatabase = "hpdb";
string dbUid = "root";
string dbPwd = "password";
string dbSslMode = "none";
string Conn = "Server=" + dbServer + ";"
+ "Database=" + dbDatabase + ";"
+ "Uid=" + dbUid + ";"
+ "Pwd=" + dbPwd + ";"
+ "SslMode=" + dbSslMode;
return Conn;
}
public Add_Content()
{
InitializeComponent();
}
public Add_Content(Finance finance)
{
InitializeComponent();
finance1 = finance;
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
try
{
using (conn = new MySqlConnection(dbInfo()))
{
conn.Open();
if (conn.State == ConnectionState.Open) // System.Data
{
MessageBox.Show("서버에 연결");
}
// MySql DB Table 생성 (없으면)
string create_sql = "Create table if not exists " + dbTable + " ("
+ "id int NOT NULL AUTO_INCREMENT PRIMARY KEY,"
+ "date Date NOT NULL,"
+ "title Varchar(45) NOT NULL,"
+ "amount int NOT NULL,"
+ "source Varchar(45) NOT NULL,"
+ "remarks Varchar(45)"
+ ");";
MySqlCommand create_cmd = new MySqlCommand(create_sql, conn);
create_cmd.ExecuteNonQuery();
//MessageBox.Show("테이블 생성 성공");
// MySql DB Table 값 입력
string insert_sql = "";
if (Remarks.ToString() != "")
{
insert_sql = "insert into " + dbTable
+ "(date, title, amount, source, remarks)"
+ " values "
+ "(\'" + Date.Text + "\', \'" + Title.Text + "\', " + Amount.Text + ", \'" + Source.Text + "\', \'" + Remarks.Text + "\');";
}
else
{
insert_sql = "insert into " + dbTable
+ "(date, title, amount, source)"
+ " values "
+ "(\'" + Date.Text + "\', \'" + Title.Text + "\', " + Amount.Text + ", \'" + Source.Text + "\');";
}
MySqlCommand insert_cmd = new MySqlCommand(insert_sql, conn);
insert_cmd.ExecuteNonQuery();
MessageBox.Show("입력 성공!");
conn.Close(); // 연결 종료
finance1.Finance_Reloaded();
Close(); // 윈도우 종료
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
}
}