-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.cs
204 lines (168 loc) · 6.48 KB
/
Form2.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
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
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.Diagnostics;
using MySql.Data.MySqlClient;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Globalization;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
namespace 로그인
{
public partial class Form2 : Form
{
Form1 f1;
MainForm mf;
string myConnection = "datasource=localhost;port=3306;username=root;password=password;sslMode=none"; // mysql 정보
private string Form2_value;
public string passvalue // mainForm eventName 가져오기
{
get { return this.Form2_value; }
set { this.Form2_value = value; }
}
public Form2(MainForm mainform)
{
InitializeComponent();
mf = mainform;
dateTimePicker2.Value = DateTime.Now;
}
public Form2(Form1 frm)
{
InitializeComponent();
f1 = frm;
dateTimePicker2.Value = DateTime.Now;
}
public Form2()
{
InitializeComponent();
dateTimePicker2.Value = DateTime.Now;
}
void Cal()//달력에 날짜를 선택하면 양력 음력 날짜가 다 나오도록 설정
{
KoreanLunisolarCalendar klc = new KoreanLunisolarCalendar();
bool bExistLeap = false;
DateTime dt = (DateTime)monthCalendar2.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_ayng2.Text = tmpDt.ToString(Year + "-" + Month + "-" + day);
textBox_um2.Text = tmpDt.ToString(InYear + "-" + InMonth + "-" + Inday);
}
private void btnOK2_Click(object sender, EventArgs e) //수정버튼
{
dateTimePicker2.Value = DateTime.Now;
DateTime oldDate = (DateTime)monthCalendar2.SelectionRange.Start;
if (MessageBox.Show(txtEvent2.Text + "\n" + textBox_ayng2.Text, "수정하시겠습니까?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
string Query = "update login.event set eventName = '" + this.txtEvent2.Text + "', startDay = '" + this.dateTimePicker2.Text + "', endDay = '" + this.textBox_ayng2.Text + "', day = '" + this.txtDay2.Text + "', ID= '" + f1.textBox_ID.Text + "' where eventName = '" + passvalue + "';"; //ID = '" + f1.textBox_ID + "',
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase = new MySqlCommand(Query, myConn);
MySqlDataReader myReader;
try
{
myConn.Open();
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("수정되었습니다.");
this.Hide();
new MainForm(f1).Show();
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConn.Close();
}
}
}
private void btnToDayON2_Click(object sender, EventArgs e) //날짜계산
{
DateTime oldDate = (DateTime)monthCalendar2.SelectionRange.Start;
DateTime newDate = dateTimePicker2.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;
txtDay2.Text = b.ToString();
}
else
{
int a = Days - 1;
txtDay2.Text = a.ToString();
}
}
else if (Days > 0)
txtDay2.Text = Days.ToString("+0;-#");
}
private void monthCalendar2_DateChanged(object sender, DateRangeEventArgs e)
{
Cal();
}
private void button_back_Click(object sender, EventArgs e) //뒤로가기
{
this.Hide();
new MainForm(f1).Show();
}
private void Form2_Load(object sender, EventArgs e)
{
mf = new MainForm();
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlCommand selectCommand = new MySqlCommand("select eventName from login.event where eventName = '" + passvalue + "'", myConn);
try
{
myConn.Open();
String event_name = (String)selectCommand.ExecuteScalar();
txtEvent2.Text = event_name;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConn.Close();
}
}
}
}