-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsert.cs
174 lines (144 loc) · 5.65 KB
/
Insert.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
using MySql.Data.MySqlClient;
namespace 로그인
{
public partial class Insert : Form
{
Form1 f1;
MainForm mf;
string constring = "datasource = localhost;port=3306;username=root;password=password";
public Insert(MainForm mainform)
{
InitializeComponent();
mf = mainform;
}
public Insert(Form1 frm)
{
InitializeComponent();
dateTimePicker1.Value = DateTime.Now;
this.f1 = frm;
}
void Cal()//달력에 날짜를 선택하면 양력 음력 날짜가 다 나오도록 설정
{
KoreanLunisolarCalendar klc = new KoreanLunisolarCalendar();
bool bExistLeap = false;
DateTime dt = (DateTime)monthCalendar1.SelectionRange.Start;
string year = dt.ToString("yyyy");
string month = dt.ToString("MM");
string day = dt.ToString("dd");
int Year = Convert.ToInt32(year);
int Month = Convert.ToInt32(month);
int Day = Convert.ToInt32(day);
DateTime tmpDt = new DateTime(Year, Month, Day);
int InYear = klc.GetYear(tmpDt);
int InMonth = klc.GetMonth(tmpDt);
int Inday = klc.GetDayOfMonth(tmpDt);
if (klc.GetMonthsInYear(InYear) > 12)
{
bExistLeap = klc.IsLeapMonth(InYear, InMonth);
int intLeap_mm = klc.GetLeapMonth(InYear);
if (InMonth >= intLeap_mm)
{
InMonth--;
}
}
textBox_ayng.Text = tmpDt.ToString(Year + "-" + Month + "-" + day);
textBox_um.Text = tmpDt.ToString(InYear + "-" + InMonth + "-" + Inday);
}
private void btnOK_Click(object sender, EventArgs e) //저장 버튼
{
DateTime oldDate = (DateTime)monthCalendar1.SelectionRange.Start;
if (MessageBox.Show(txtEvent.Text + "\n" + textBox_ayng.Text, "등록하시겠습니까?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string Query = "select eventName from login.event where eventName = '" + this.txtEvent.Text + "'and ID = '" + f1.textBox_ID.Text + "'";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
try
{
MySqlDataReader myReader;
conDataBase.Open();
String eName = (String)cmdDataBase.ExecuteScalar();
if (eName == this.txtEvent.Text)
{
MessageBox.Show("중복되는 이벤트명이 있습니다.");
}
else
{
cmdDataBase.CommandText = "insert into login.event (eventName,startDay,endDay,day,ID) value ('" + this.txtEvent.Text + "','" + this.dateTimePicker1.Text + "','" + this.textBox_ayng.Text + "','" + this.txtDay.Text + "','" + f1.textBox_ID.Text + "')";
myReader = cmdDataBase.ExecuteReader();
while (myReader.Read())
{
}
this.Hide();
new MainForm(f1).Show();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
Cal();
}
private void btnToDayON_Click(object sender, EventArgs e)
{
DateTime oldDate = (DateTime)monthCalendar1.SelectionRange.Start;
DateTime newDate = dateTimePicker1.Value;
TimeSpan ts = newDate - oldDate;
string day = newDate.ToString("dd");
int Day = Convert.ToInt32(day);
string day2 = oldDate.ToString("dd");
int Day2 = Convert.ToInt32(day2);
string month = newDate.ToString("MM");
int Month = Convert.ToInt32(month);
string month2 = oldDate.ToString("MM");
int Month2 = Convert.ToInt32(month2);
string year = newDate.ToString("yy");
int Year = Convert.ToInt32(year);
string year2 = oldDate.ToString("yy");
int Year2 = Convert.ToInt32(year2);
int Days = ts.Days;
if (Days <= 0)
{
if (Day == Day2 && Month == Month2 && year == year2)
{
int b = Day - Day2;
txtDay.Text = b.ToString();
}
else
{
int a = Days - 1;
txtDay.Text = a.ToString();
}
}
else if (Days > 0)
txtDay.Text = Days.ToString("+0;-#");
}
private void button_back_Click(object sender, EventArgs e)
{
new MainForm(f1).Show();
this.Hide();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
private void Insert_Load(object sender, EventArgs e)
{
}
private void textBox_ayng_TextChanged(object sender, EventArgs e)
{
}
}
}