미니프로젝트 - 콘솔 오라클
1. 주소록 조회
2. 주소록 추가
3. 주소록 수정
4. 주소록 삭제
메뉴 : _______
|
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
|
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyContacts
{
class Program
{
static void Main(string[] args)
{
// 오라클 연결 문자열
string strConn = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=xe)));User Id=hr;Password=hr;";
// 오라클 연결
OracleConnection conn = new OracleConnection(strConn);
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
do
{
int CONTACTS_ID = 0;
string name = "";
string hp = "";
string hometown = "";
Console.Clear();
Console.Write("1. 주소록 조회\n\n2. 주소록 추가\n\n3. 주소록 수정\n\n4. 주소록 삭제\n\n\n메뉴: ");
int num = int.Parse(Console.ReadLine());
switch (num)
{
case 1:
//cmd.CommandText = "Create Table SEUNGSU_CONTACTS (CONTACTS_ID number(4) PRIMARY KEY,NAME varchar2(20),HP varchar2(20),HOMETOWN varchar2(20))";
//cmd.ExecuteNonQuery();
//Console.WriteLine("테이블이 생성되었습니다.\n\n");
//Console.WriteLine("-------------------------------");
//break;
cmd.CommandText = "SELECT * FROM SEUNGSU_CONTACTS";
OracleDataReader rdr2 = cmd.ExecuteReader();
Console.WriteLine("\nID\t 이름\t 번호\t 고향\n");
while (rdr2.Read())
{
int id = rdr2.GetInt32(0); // int나 number로 받을 때
name = rdr2["NAME"] as string;
hp = rdr2["HP"] as string;
hometown = rdr2["HOMETOWN"] as string;
Console.WriteLine($"{id}\t:{name}\t:{hp}\t:{hometown}\n");
}
Console.WriteLine("\n\n");
Console.ReadLine();
break;
case 2:
cmd.CommandText = "SELECT ROWNUM FROM SEUNGSU_CONTACTS ORDER BY ROWNUM DESC";
OracleDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
CONTACTS_ID = rdr.GetInt32(0);
break;
}
//Console.WriteLine(CONTACTS_ID);
Console.Write("\n이름을 입력해 주세요: ");
name = Console.ReadLine();
Console.Write("\n전화번호를 입력해 주세요: ");
hp = Console.ReadLine();
Console.Write("\n고향을 입력해 주세요: ");
hometown = Console.ReadLine();
cmd.CommandText = "INSERT INTO SEUNGSU_CONTACTS VALUES (" + (CONTACTS_ID + 1) + ", '" + name + "', '" + hp + "', '" + hometown + "')";
cmd.ExecuteNonQuery();
Console.WriteLine("\n주소록이 정상적으로 추가되었습니다.\n\n");
Console.ReadLine();
break;
case 3:
Console.Write("\n수정하고 싶은 이름을 입력하세요: ");
string tempname = Console.ReadLine();
Console.WriteLine("\n1. 이름 수정\n\n2. 전화번호 수정\n\n3. 고향 수정\n\n4. 모두 수정\n");
int num2 = int.Parse(Console.ReadLine());
switch(num2)
{
case 1:
Console.Write("\n이름을 입력해주세요: ");
string editedname = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET NAME = '" + editedname + "' WHERE NAME='" + tempname + "'";
cmd.ExecuteNonQuery();
Console.WriteLine("\n이름이 정상적으로 수정되었습니다.\n\n");
break;
case 2:
Console.Write("\n전화번호를 입력해주세요: ");
string editedhp = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET HP = '" + editedhp + "' WHERE NAME='" + tempname + "'";
cmd.ExecuteNonQuery();
Console.WriteLine("\n전화번호가 정상적으로 수정되었습니다.\n\n");
break;
case 3:
Console.Write("\n고향을 입력해주세요: ");
string editedhometown = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET HOMETOWN = '" + editedhometown + "' WHERE NAME='" + tempname + "'";
cmd.ExecuteNonQuery();
Console.WriteLine("\n고향이 정상적으로 수정되었습니다.\n\n");
break;
case 4:
Console.Write("\n이름을 입력해주세요: ");
editedname = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET NAME = '" + editedname + "' WHERE NAME='" + tempname + "'";
cmd.ExecuteNonQuery();
Console.Write("\n전화번호를 입력해주세요: ");
editedhp = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET HP = '" + editedhp + "' WHERE NAME='" + editedname + "'";
cmd.ExecuteNonQuery();
Console.Write("\n고향을 입력해주세요: ");
editedhometown = Console.ReadLine();
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET HOMETOWN = '" + editedhometown + "' WHERE NAME='" + editedname + "'";
cmd.ExecuteNonQuery();
Console.WriteLine("\n이름, 전화번호, 고향이 정상적으로 수정되었습니다.\n\n");
break;
default:
Console.WriteLine("\n잘못 입력하셨습니다.");
break;
}
cmd.CommandText = "UPDATE SEUNGSU_CONTACTS SET NAME = '"+ name +"' WHERE NAME='"+ tempname +"'";
Console.ReadLine();
break;
case 4:
Console.Write("\n삭제하고 싶은 이름을 입력해주세요: ");
string tobedeleted = Console.ReadLine();
cmd.CommandText = "DELETE FROM SEUNGSU_CONTACTS WHERE NAME = '"+ tobedeleted +"'";
cmd.ExecuteNonQuery();
Console.WriteLine("\n주소록이 정상적으로 삭제되었습니다.");
Console.ReadLine();
break;
default:
Console.WriteLine("\n잘못 입력하셨습니다.종료합니다.\n");
conn.Close();
return;
}
} while (true);
}
}
}
|
cs |
WinFrom
.NET UI 라이브러리
WinForm(Windows Form) : 익히기 쉽고 높은 생산성 제공
WPF(Windows Presentation Foundation) : 세련된 UI와 화려한 효과를 제공하나, 학습곡선이 가파름.
WYSIWYG 방식의 GUI 프로그램 개발
WinForm 윈도우 띄우기
SimpleWindow01.csproj
xml
|
1
2
3
4
5
6
7
8
9
10
|
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net4.7.2</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<DisableWinExeOutPutInference>true</DisableWinExeOutPutInference>
</PropertyGroup>
</Project>
|
cs |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
using System;
using System.Windows.Forms;
namespace SimpleWindow01
{
class Program : Form
{
static void Main(string[] args)
{
//Console.WriteLine("Hello World!");
Program myWin = new Program();
Application.Run(myWin);
}
}
}
|
cs |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
using System;
using System.Windows.Forms;
namespace SimpleWindow01
{
class MyWindowsForm : Form
{
}
class Program
{
static void Main(string[] args)
{
MyWindowsForm myWin = new MyWindowsForm();
Application.Run(myWin);
}
}
}
|
cs |
new 하지않고 .해서 쓰는 메소드를 static 메소드
|
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
|
using System;
using System.Windows.Forms;
namespace SimpleWindow01
{
class MyForm : Form
{
}
class Program
{
static void Main(string[] args)
{
MyForm form = new MyForm();
form.Click += new EventHandler(
(sender, eventArgs) =>
{
Application.Exit();
}
);
Application.Run(form);
}
}
}
|
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
|
using System;
using System.Windows.Forms;
namespace UsingApplication
{
class MyForm : Form
{
}
class Program
{
static void Main(string[] args)
{
MyForm form = new MyForm();
// 이벤트 추가
form.Click += new EventHandler(
(sender, eventArgs) =>
{
Console.WriteLine("윈도우를 닫습니다.");
Application.Exit();
}
);
Console.WriteLine("윈도우 애플리케이션이 시작됩니다.");
Application.Run(form);
}
}
}
|
cs |
메시지 필터링(Message Filtering)
윈도우 메시지의 생성 및 처리 예
- 하드웨어(마우스나 키보드)로부터 인터럽트 발생
- 해당 인터럽트는 윈도우에 의해 윈도우 메시지 생성
- 윈도우 메시지를 응용 프로그램에게 전송
응용 프로그램은 해당 메시지를 처리
메시지 필터는 관심 있는 메시지를 정제
Application 클래스가 메시지 필터 제공
Application.AddMessageFilter() 메소드를 이용하여 응용프로그램에 메시지 필터 설치
메시지 필터는 다음과 같이 IMessageFilter 인터페이스 상속
709페이지 표 별 5개
메시지 구조체
HWnd - 메시지 번호 - 운영체제가 만들어줌
Msg - 메시지 이름(ID) - 내가 만듦
LParam - 기본 메시지 값
WParam - 키보드와 마우스, 조이스틱 등의 값
Result - 메시지 응답에 윈도우가 반환하는 값
|
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
|
using System;
using System.Windows.Forms;
namespace MessageFilter
{
class MessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
/* 0x0F : WM_PAINT 다시 그려라
* 0x200 : WM_MOUSEMOVE
* 0x113 : WM_TIMER
* 0x201 : WM_LBUTTONDOWN
*/
if (m.Msg == 0x0F || m.Msg == 0xA0 || m.Msg == 0x200 || m.Msg == 0x113)
return false;
Console.WriteLine($"{m.ToString()} : {m.Msg}");
if (m.Msg == 0x201)
Application.Exit();
return false;
}
}
class Program : Form
{
static void Main(string[] args)
{
Application.AddMessageFilter(new MessageFilter());
Application.Run(new Program());
}
}
}
|
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
|
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;
namespace WinFormsApp002
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void txt1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int num1 = int.Parse(txt1.Text);
int num2 = int.Parse(txt2.Text);
int num3 = int.Parse(txt3.Text);
int num4 = int.Parse(txt4.Text);
int num5 = int.Parse(txt5.Text);
int num6 = int.Parse(txt6.Text);
int num7 = int.Parse(txt7.Text);
int num8 = int.Parse(txt8.Text);
int result = num1 + num2;
int result2 = num1 - num2;
int result3 = num1 * num2;
float result4 = (float)num1 / num2;
txtResult.Text = result.ToString();
txtResult2.Text = result2.ToString();
txtResult3.Text = result3.ToString();
txtResult4.Text = result4.ToString();
}
private void txt3_TextChanged(object sender, EventArgs e)
{
}
private void textBox5_TextChanged(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void label12_Click(object sender, EventArgs e)
{
}
}
}
|
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
|
using System;
using System.Windows.Forms;
namespace FormEvent
{
class MainApp : Form
{
// 멤버변수
// 생성자 - 인자가 있는 생성자
public MainApp(string title)
{
this.Text = title;
this.MouseDown += new MouseEventHandler(MyMouseHandler);
}
// 이벤트 처리 핸들러
public void MyMouseHandler(Object sender, MouseEventArgs e)
{
Console.WriteLine($"Sender : {(Form)sender}.Text");
Console.WriteLine($"X:{e.X}, Y:{e.Y}");
Console.WriteLine($"Button:{e.Button}, Click:{e.Clicks}");
} // 메인 함수
static void Main(string[] args)
{
Application.Run(new MainApp("마우스 이벤트 테스트-1"));
}
}
}
|
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
|
using System;
using System.Windows.Forms;
namespace FormSize
{
class MainApp : Form
{
static void Main(string[] args)
{
MainApp form = new MainApp();
form.Width = 300;
form.Height = 200;
form.MouseDown += new MouseEventHandler(form_MouseDown);
Application.Run(form);
}
static void form_MouseDown(Object sender, MouseEventArgs e)
{
Form form = (Form)sender;
int oldWidth = form.Width;
int oldHeight = form.Height;
// 왼쪽 마우스 버튼 눌렀을 때
if(e.Button == MouseButtons.Left)
{
form.Width = oldHeight;
form.Height = oldWidth;
}
else if(e.Button == MouseButtons.Right)
{
if(oldHeight < oldWidth)
{
form.Width = oldHeight;
form.Height = oldWidth;
}
}
Console.WriteLine("윈도우의 크기가 변경되었습니다.");
Console.WriteLine($"{form.Width} : {form.Height}");
}
}
}
|
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
|
using System;
using System.Drawing;
using System.Windows.Forms;
namespace FormBackground
{
class MainApp : Form
{
Random rand;
public MainApp()
{
rand = new Random(); // 랜덤 객체를 생성해야 랜덤을 사용할 수 있다.
this.MouseWheel += new MouseEventHandler(MainApp_MouseWheel);
this.MouseDown += new MouseEventHandler(MainApp_MouseDown);
}
void MainApp_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Color oldColor = this.BackColor;
this.BackColor = Color.FromArgb(rand.Next(0, 255), rand.Next(0, 255), rand.Next(0, 255));
}
else if (e.Button == MouseButtons.Right)
{
// 에러처리
if (this.BackgroundImage != null)
{
this.BackgroundImage = null;
return;
}
string file = "cat.png";
if (System.IO.File.Exists(file) == false)
MessageBox.Show("이미지 파일이 없습니다.");
else
this.BackgroundImage = Image.FromFile(file);
}
}
void MainApp_MouseWheel(object sender, MouseEventArgs e)
{
this.Opacity = this.Opacity + (e.Delta > 0 ? 0.1 : -0.1);
Console.WriteLine(this.Opacity);
}
static void Main(string[] args)
{
Application.Run(new MainApp());
}
}
}
|
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
|
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;
namespace UsingControls
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
var Fonts = FontFamily.Families;
foreach (FontFamily font in Fonts)
cboFont.Items.Add(font.Name);
}
public void ChangeFont()
{
if (cboFont.SelectedIndex < 0) // 선택X 아무동작X
return;
FontStyle style = FontStyle.Regular;
if (checkBold.Checked)
style |= FontStyle.Bold;
if (checkItalic.Checked)
style |= FontStyle.Italic;
txtSampleText.Font = new Font((string)cboFont.SelectedItem, 10, style);
}
private void cboFont_SelectedIndexChanged(object sender, EventArgs e)
{
ChangeFont();
}
private void checkBold_CheckedChanged(object sender, EventArgs e)
{
ChangeFont();
}
private void checkItalic_CheckedChanged(object sender, EventArgs e)
{
ChangeFont();
}
}
}
|
cs |
'C#' 카테고리의 다른 글
| 스마트팩토리 5주 22일차 C# 16일차 ~ 25일차 C# 19일차 미니프로젝트 초밥 공정 시스템 (0) | 2021.06.01 |
|---|---|
| 스마트팩토리 5주 21일차 C# 15일차 (0) | 2021.05.25 |
| 스마트팩토리 4주 19일차 C# 13일차 (0) | 2021.05.21 |
| 스마트팩토리 4주 18일차 C# 12일차 (0) | 2021.05.20 |
| 스마트팩토리 4주 17일차 C# 11일차 (0) | 2021.05.19 |




최근댓글