cf. LibreOffice : MS Office를 열어 볼 수 있는 오픈 소스 툴
cf. 3rd-party component
- Telerik
- devexpress
- jetbrains
1) Chart 컨트롤 사용(p.550 / 실무170)
윈폼에는 다양한 차트를 만들 수 있는 Chart 컨트롤이 제공된다.
- ChartArea : 차트가 그려지는 영역, 하나의 차트 객체는 하나 이상의 ChartArea(차트 영역)을 가질 수 있다.
- Series : 차트 영역에 표시되는 데이터, 하나의 차트 영역에 두 개 이상의 시리즈가 있을 수 있다. 차트의 종류를 지정할 수 있으며 차트 영역이 두 개 이상이라면 시리즈별로 어떤 차트 영역에 그려질지 지정할 수 있다.
- Legends : 범레, 시리즈마다 범례를 가질 수 있다.
- Titles : 차트 컨트롤 상단에 표시되는 제목이다.
ex)
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Using Chart Control";
//10명의 학생 랜덤점수 생성 및 차트 바인딩
Random rand = new Random();
chart1.Titles.Add("중간고사 성적");
for (int i = 0; i < 10; i++)
{
int val = rand.Next(10, 100);
chart1.Series["Score"].Points.Add(val);
}
chart1.Series["Score"].LegendText = "수학";
chart1.Series["Score"].ChartType = SeriesChartType.Column;
}
private void button1_Click(object sender, EventArgs e)
{
chart1.Series["Score"].Points.Clear();
MessageBox.Show("데이터를 지웠습니다.", "처리",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
cf. NuGet을 이용한 참조 추가
2) 윈폼 - DB 연동
유저 아이디 등록을 위한 테이블 생성
USE BookRentalshopDB
GO
CREATE TABLE userTbl (
id int IDENTITY(1,1) NOT NULL PRIMARY KEY,
userID varchar(12) NOT NULL,
password varchar(max) NOT NULL,
lastLoginDt datetime NULL,
loginIpAddr varchar(30) NULL
)
GO
로그인 동작 구현중
//MainForm
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 MetroFramework.Forms;
namespace BookRentalShop20
{
public partial class MainForm : MetroForm
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
LoginForm loginForm = new LoginForm();
loginForm.ShowDialog();
}
}
}
// LoginForm
using MetroFramework.Forms;
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 MetroFramework.Forms;
using MetroFramework;
using System.Data.SqlClient;
using System.Diagnostics;
namespace BookRentalShop20
{
public partial class LoginForm : MetroForm
{
string strConnString = "Data Source=192.168.0.10;Initial Catalog=BookRentalshopDB;Persist Security Info=True;User ID=sa;Password=p@ssw0rd!";
public LoginForm()
{
InitializeComponent();
}
/// <summary>
/// 취소버튼 클릭이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnCancel_Click(object sender, EventArgs e)
{
//Application.Exit();// 정확하게 메모리 해제가 안되는 경우가 있음
Environment.Exit(0);// 0(FLASE): 에러가 없이 정상종료 // 1(TRUE) : 에러가 있어 종료가 안됨
}
/// <summary>
/// 로그인 처리버튼 클릭이벤트
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BtnOK_Click(object sender, EventArgs e)
{
LoginProcess();
}
private void TxtUserID_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == (char)13) // 엔터
{
TxtPassWord.Focus();
}
}
private void TxtPassWord_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)13) // 엔터
{
LoginProcess();
}
}
private void LoginProcess()
{
//if(TxtUserID.Text == null || TxtUserID.Text == "" || TxtPassWord.Text == null || TxtPassWord.Text == "")
if(string.IsNullOrEmpty(TxtUserID.Text) || string.IsNullOrEmpty(TxtPassWord.Text) )
{
MetroMessageBox.Show(this, "아이디/패스워드를 입력하세요!", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
string strUserId = string.Empty;
using (SqlConnection conn = new SqlConnection(strConnString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT userID FROM userTbl"
+ " WHERE userID = @userID"
+ " AND password = @password";
// DB 해킹(SQL Injection)을 방지하기 위해 변수를 사용하여 접속
SqlParameter parmUserID = new SqlParameter("@userID", SqlDbType.VarChar, 12);
parmUserID.Value = TxtUserID.Text;
cmd.Parameters.Add(parmUserID);
SqlParameter parmPassword = new SqlParameter("@password", SqlDbType.VarChar, 20);
parmPassword.Value = TxtPassWord.Text;
cmd.Parameters.Add(parmPassword);
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
strUserId = reader["userID"].ToString();
MetroMessageBox.Show(this, "접속성공", "로그인");
Debug.WriteLine("On the Debug");
}
}
}
}
cf. SDI(Single Document Interface), MDI(Multiple Document Interface)
SDI : 3개의 클래스가 연결되어 있으며 메인프레임, 뷰, 도큐먼트가 있다.
- 메인프레임 : 뷰를 감싸 안으면서 메뉴의 이벤트를 얻음
- 뷰 윈도우 : 실제 화면 처리 담당
- 도큐먼트(Document) : View와 쌍으로 움직이며, 데이터를 저장하는 기능을 가진 클래스
ex) 메모장, ...
MDI : SDI와 달리 여러 개의 도큐먼트를 가지고 있는 형태, SDI형태의 프로그램을 여러 개 모아놓은 것
- 메인프레임 : SDI와 달리 독립적으로 설정, 여러 개의 자식 프레임을 가짐
- 자식 프레임 : 하나의 템플릿으로 구성
- 뷰 윈도우 : 화면을 출력하는 클래스
- 도큐먼트(Document) : View와 쌍으로 움직이며, 데이터를 저장하는 기능을 가진 클래스
ex) 워드, 한글, ...
cf. SQL Injection
SQL Injection이란 악의적인 사용자가 보안상의 취약점을 이용하여, 임의의 SQL 문을 주입하고 실행하게 하여 데이터베이스가 비정상적인 동작을 하도록 조작하는 행위
'스마트팩토리 > C# 데스크톱 앱(윈폼),WPF' 카테고리의 다른 글
[정리] 윈폼 - DB 연동 (최종본) (0) | 2020.06.20 |
---|---|
5. 윈폼 - DB연동 (0) | 2020.06.19 |
3. 메뉴, 마우스, 입력 포커스, 키보드, 리스트 뷰, 트리 뷰, 프로그레스 바, 타이머, 그래픽 (0) | 2020.06.17 |
2. 컨트롤, 대화상자 (0) | 2020.06.16 |
1. 제네릭, 예외 처리 구문, 윈폼 (0) | 2020.06.15 |