동영상URL |
---|
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Windows.Forms;
namespace Form
{
class Class1 : System.Windows.Forms.Form
{
private Button buttonOne;
private TextBox textBoxOne;
private TextBox textBoxTwo;
private TextBox textBoxThree;
private ListBox listBox;
private GroupBox groupBox;
public Class1()
{
this.Text="Windows Form Example(홍길동)";
Init();
}
public void Init()
{
buttonOne=new Button();
buttonOne.Text="안녕하세요.";
buttonOne.Left=200;
buttonOne.Top=30;
buttonOne.Width=150;
buttonOne.Enabled=false;
buttonOne.Click+=new EventHandler(buttonOne_Click);
textBoxOne=new TextBox();
textBoxOne.Left=30;
textBoxOne.Top=30;
textBoxOne.Text="이름을 입력하시오";
textBoxOne.Width=150;
textBoxOne.TextChanged+=new EventHandler(textBoxOne_TextChanged);
textBoxTwo=new TextBox();
textBoxTwo.Left=30;
textBoxTwo.Top=90;
textBoxTwo.Text="나이를 입력하시오";
textBoxTwo.Width=150;
textBoxThree=new TextBox();
textBoxThree.Left=30;
textBoxThree.Top=150;
textBoxThree.Text="직업을 입력하시오";
textBoxThree.Width=150;
listBox=new ListBox();
listBox.Left=30;
listBox.Top=30;
listBox.Width=250;
listBox.Height=150;
groupBox=new GroupBox();
groupBox.Left=30;
groupBox.Top=170;
groupBox.Width=320;
groupBox.Height=200;
this.Width=400;
this.Height=400;
this.Controls.Add(buttonOne);
this.Controls.Add(textBoxOne);
this.Controls.Add(textBoxTwo);
this.Controls.Add(textBoxThree);
groupBox.Controls.Add(listBox);
this.Controls.Add(groupBox);
}
static void Main(string[] args)
{
System.Windows.Forms.Application.Run(new Class1());
}
private void buttonOne_Click(object sender, EventArgs e)
{
string msg=textBoxOne.Text+","+textBoxTwo.Text+","+textBoxThree.Text;
listBox.Items.Add(msg);
}
private void textBoxOne_TextChanged(object sender, EventArgs e)
{
buttonOne.Enabled=true;
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Chapter10_2
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.OpenFileDialog openFileDialog2;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
this.menuItem1.Text = "파일";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "열기";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "종료";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 375);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2});
this.statusBar1.Size = new System.Drawing.Size(520, 22);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "간단한 이미지뷰어입니다.";
//
// statusBarPanel1
//
this.statusBarPanel1.Text = "statusBarPanel1";
//
// statusBarPanel2
//
this.statusBarPanel2.Text = "statusBarPanel2";
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton3,
this.toolBarButton2});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(520, 41);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Text = "열기";
//
// toolBarButton3
//
this.toolBarButton3.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "전체화면";
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlText;
this.pictureBox1.Location = new System.Drawing.Point(0, 48);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(520, 328);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 2;
this.pictureBox1.TabStop = false;
this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(520, 397);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.statusBar1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void OpenFile()
{
if(DialogResult.OK==openFileDialog1.ShowDialog(this))
{
pictureBox1.Image=new Bitmap(openFileDialog1.FileName);
}
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button.Text=="열기")
OpenFile();
else if(e.Button.Text=="전체화면")
FullScreen();
}
private void FullScreen()
{
int Height,Width;
Height=SystemInformation.WorkingArea.Height;
Width=SystemInformation.WorkingArea.Width;
this.SetDesktopLocation(0,0);
this.SetClientSizeCore(Width,Height);
this.pictureBox1.Height=Height;
this.pictureBox1.Width=Width;
this.pictureBox1.SizeMode=PictureBoxSizeMode.StretchImage;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
OpenFile();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void pictureBox1_Click(object sender, System.EventArgs e)
{
FullScreen();
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Windows.Forms;
using System.Drawing;
namespace HelloWolrd
{
public class HandMadeClass:System.Windows.Forms.Form
{
//컴포넌트 추가
private System.Windows.Forms.Label lbHelloWorld;
private System.Windows.Forms.Button btnShowMsg;
private System.Windows.Forms.Button btnExit;
public HandMadeClass()
{
// 객체 생성
this.lbHelloWorld = new System.Windows.Forms.Label();
this.btnShowMsg = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
// 현재 클래스의 인스턴스를 의미
this.Text="Hello World";
// 라벨의 위치 설정
lbHelloWorld.Location = new System.Drawing.Point(10,10);
// 발벨의 텍스트 설정
lbHelloWorld.Text = "";
// AutoSize가 true면 라벨의 크기가 텍스트 크기에 따라 변경
lbHelloWorld.AutoSize = true;
// 버튼의 위치 설정
btnShowMsg.Location = new System.Drawing.Point(90,100);
// 버튼의 텍스트 설정
btnShowMsg.Text = "&Show Message";
// 버튼의 크기 설정
btnShowMsg.Size = new System.Drawing.Size(120,25);
// 버튼의 위치 설정
btnExit.Location = new System.Drawing.Point(180,210);
// 버튼의 텍스트 설정
btnExit.Text = "E&xit";
// 버튼의 그기 설정
btnExit.Size = new System.Drawing.Size(80,25);
// 이벤트 처리기 호출
btnExit.Click += new System.EventHandler(this.btnExit_Click);
btnShowMsg.Click += new System.EventHandler(this.btnShowMsg_Click);
// 폼에 컨포넌트를 추가
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnShowMsg);
this.Controls.Add(this.lbHelloWorld);
}
public static void Main()
{
// 어프리케이션을 실행
Application.Run(new HandMadeClass());
}
protected void btnExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
protected void btnShowMsg_Click(object sender, System.EventArgs e)
{
// 라벨의 텍스트에 "Hello World"라는 문자열을 삽입
lbHelloWorld.Text = "Hello Wolrd";
// 메시지 박스를 보여줌
MessageBox.Show("Hello World", "Button Click");
// 메시지 박스가 닫히면 라벨의 텍스트를 지움
lbHelloWorld.Text = "";
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 예제_2_Window_form_event_
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class UseIDE : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnShowMsg;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Label lbHelloWorld;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
public UseIDE()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.btnShowMsg = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.lbHelloWorld = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnShowMsg
//
this.btnShowMsg.Location = new System.Drawing.Point(90, 100);
this.btnShowMsg.Name = "btnShowMsg";
this.btnShowMsg.Size = new System.Drawing.Size(120, 25);
this.btnShowMsg.TabIndex = 0;
this.btnShowMsg.Text = "&Show Message";
this.btnShowMsg.Click += new System.EventHandler(this.btnShowMsg_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(180, 210);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(90, 25);
this.btnExit.TabIndex = 1;
this.btnExit.Text = "E&xit";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// lbHelloWorld
//
this.lbHelloWorld.AutoSize = true;
this.lbHelloWorld.Location = new System.Drawing.Point(10, 10);
this.lbHelloWorld.Name = "lbHelloWorld";
this.lbHelloWorld.Size = new System.Drawing.Size(0, 17);
this.lbHelloWorld.TabIndex = 2;
this.lbHelloWorld.Click += new System.EventHandler(this.lbHelloWorld_Click);
//
// UseIDE
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.lbHelloWorld);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnShowMsg);
this.Name = "UseIDE";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Hello World";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new UseIDE());
}
private void lbHelloWorld_Click(object sender, System.EventArgs e)
{
}
private void btnExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void btnShowMsg_Click(object sender, System.EventArgs e)
{
lbHelloWorld.Text = "Hello World";
MessageBox.Show("Hello World", "Button Click");
lbHelloWorld.Text = "";
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
namespace Stream
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
public FileStream fileStream;
public byte[] buffer;
public bool fileOpened;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.MenuItem menuItem7;
public string filePath;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
this.GetLocalDrives();
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.listBox2 = new System.Windows.Forms.ListBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem7,
this.menuItem5,
this.menuItem4});
this.menuItem1.Text = "파일";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "열기";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "저장";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 4;
this.menuItem4.Text = "종료";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "-";
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 467);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(656, 22);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "간단한 메모장입니다.";
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(216, 5);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(440, 300);
this.richTextBox1.TabIndex = 1;
this.richTextBox1.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.listBox2);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.listBox1);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(216, 472);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(8, 40);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(200, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 15);
this.label1.TabIndex = 1;
this.label1.Text = "드라이브";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 16);
this.label2.TabIndex = 2;
this.label2.Text = "디렉토리";
//
// listBox1
//
this.listBox1.HorizontalScrollbar = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(8, 80);
this.listBox1.Name = "listBox1";
this.listBox1.ScrollAlwaysVisible = true;
this.listBox1.Size = new System.Drawing.Size(200, 100);
this.listBox1.TabIndex = 3;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 184);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 16);
this.label3.TabIndex = 4;
this.label3.Text = "파일";
//
// listBox2
//
this.listBox2.HorizontalScrollbar = true;
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(8, 200);
this.listBox2.Name = "listBox2";
this.listBox2.ScrollAlwaysVisible = true;
this.listBox2.Size = new System.Drawing.Size(200, 268);
this.listBox2.TabIndex = 5;
this.listBox2.SelectedIndexChanged += new System.EventHandler(this.listBox2_SelectedIndexChanged);
//
// menuItem7
//
this.menuItem7.Index = 2;
this.menuItem7.Text = "새로저장";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(656, 489);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.statusBar1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
protected override void OnSizeChanged(EventArgs e)
{
this.richTextBox1.Height=this.Height-70;
this.richTextBox1.Width=this.Width;
base.OnSizeChanged (e);
}
private void GetLocalDrives()
{
//현재 컴퓨터의 드라이브를 구한다.
string[] drives=Environment.GetLogicalDrives();
for(int i=0;i<drives.Length;i++)
{
comboBox1.Items.Add(drives[i]);
}
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//드라이브 아이템을 선택할 경우
//디렉토리 정보를 표시한다.
try
{
string[] directory=
Directory.GetDirectories(comboBox1.SelectedItem.ToString());
for(int i=0;i<directory.Length;i++)
{
listBox1.Items.Add(directory[i]);
}
}
catch(System.IO.IOException io)
{
Console.WriteLine(io.ToString());
}
}
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//디렉토리 리스트박스를 클릭하면 해당 디렉토리를 보여주고
//파일 리스트박스에 파일을 표시한다.
try
{
string[] directory=null;
string[] file=null;
if(listBox1.SelectedItem !=null)
{
directory=Directory.GetDirectories(listBox1.SelectedItem.ToString());
file=Directory.GetFiles(listBox1.SelectedItem.ToString());
listBox1.Items.Clear();
for(int i=0;i<directory.Length;i++)
{
listBox1.Items.Add(directory[i]);
}
if(file != null)
{
listBox2.Items.Clear();
for(int i=0;i<file.Length;i++)
{
//파일 추가
listBox2.Items.Add(file[i]);
}
}
}
}
catch(System.IO.IOException io)
{
Console.WriteLine(io.ToString());
}
}
private void listBox2_SelectedIndexChanged(object sender, System.EventArgs e)
{
//파일 리스트박스를 클릭했을때
//TXT 파일만 읽어들인다.
try
{
if(IsText(listBox2.SelectedItem.ToString()))
{
//만약 txt파일이라면
fileOpened=true;
//파일이 열렸다는 것을 알리고
//파일을 읽어 버퍼에 데이타를 저장한다.
//그리고 리치텍스트박스에 한글로 인코딩해서 표시한다
fileStream=new FileStream(listBox2.SelectedItem.ToString(),FileMode.Open);
buffer=new byte[fileStream.Length];
fileStream.Read(buffer,0,(int)fileStream.Length);
this.richTextBox1.Text=Encoding.GetEncoding("euc-kr").GetString(buffer);
filePath=listBox2.SelectedItem.ToString();
fileStream.Close();
}
}
catch(System.IO.IOException io)
{
Console.WriteLine(io.ToString());
}
}
private bool IsText(string filename)
{
//확장자가 txt인지 확인한다.
string judge=filename.Substring(filename.Length-3);
if(judge == "txt")
return true;
return false;
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(DialogResult.OK == openFileDialog1.ShowDialog(this))
{
try
{
if(IsText(openFileDialog1.FileName))
{
//만약 txt파일이라면
fileOpened=true;
//파일이 열렸다는 것을 알리고
//파일을 읽어 버퍼에 데이타를 저장한다.
//그리고 리치텍스트박스에 한글로 인코딩해서 표시한다.
fileStream=new FileStream(openFileDialog1.FileName,FileMode.Open);
buffer=new byte[fileStream.Length];
fileStream.Read(buffer,0,(int)fileStream.Length);
this.richTextBox1.Text=Encoding.GetEncoding("euc-kr").GetString(buffer);
filePath=openFileDialog1.FileName;
fileStream.Close();
}
}
catch(System.IO.IOException io)
{
Console.WriteLine(io.ToString());
}
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
StreamWriter writer;
//여기서는 StreamWriter객체를 이용해서
//텍스트박스의 내용을 저장 한다.
if(fileOpened)
{
writer=new StreamWriter(filePath);
writer.Write(this.richTextBox1.Text);
writer.Close();
}
else
{
if(DialogResult.OK==saveFileDialog1.ShowDialog(this))
{
//파일 다이얼로그를 열어 저장할 위치와
//파일명을 받는다.
writer=new StreamWriter(saveFileDialog1.FileName);
writer.Write(this.richTextBox1.Text);
writer.Close();
}
}
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
StreamWriter writer;
if(DialogResult.OK==saveFileDialog1.ShowDialog(this))
{
//파일 다이얼로그를 열어 저장할 위치와
//파일명을 받는다.
writer=new StreamWriter(saveFileDialog1.FileName);
writer.Write(this.richTextBox1.Text);
writer.Close();
}
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace MediaPlayer
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private AxMediaPlayer.AxMediaPlayer axMediaPlayer1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
private int volume=100;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "Open";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "Exit";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton4,
this.toolBarButton5,
this.toolBarButton6});
this.toolBar1.DropDownArrows = true;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(368, 41);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.Text = "파일열기";
//
// toolBarButton2
//
this.toolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton3
//
this.toolBarButton3.Text = "전체화면";
//
// toolBarButton4
//
this.toolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton5
//
this.toolBarButton5.Text = "소리크게";
//
// toolBarButton6
//
this.toolBarButton6.Text = "소리작게";
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(8, 48);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(352, 424);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(368, 481);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.toolBar1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
if(DialogResult.OK==openFileDialog1.ShowDialog(this))
{
this.axMediaPlayer1.FileName=openFileDialog1.FileName;
this.axMediaPlayer1.Play();
}
}
protected override void OnClosing(CancelEventArgs e)
{
//미디어 플레이어의 자원이 아직 남아있다면
//자원을 해제한다.
if(this.axMediaPlayer1 != null)
this.axMediaPlayer1.Dispose();
base.OnClosing (e);
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
//툴바에서 파일열기를 누르면 파일다이얼로그를 불러온다.
if(e.Button.Text=="파일열기")
{
if(DialogResult.OK==openFileDialog1.ShowDialog(this))
{
this.axMediaPlayer1.FileName=openFileDialog1.FileName;
this.axMediaPlayer1.Play();
}
}
//전체화면 버튼을 누르면 실행한다.
else if(e.Button.Text=="전체화면")
if(this.axMediaPlayer1 !=null)
this.axMediaPlayer1.DisplaySize=MPDisplaySizeConstants.mpFullScreen;
else if(e.Button.Text=="소리크게")
this.axMediaPlayer1.Volume=volume+=10;
else if(e.Button.Text=="소리작게")
this.axMediaPlayer1.Volume=volume-=10;
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class FileTest
{
public static void Main()
{
Console.WriteLine("1. 프로그램 시작");
File.Copy("FileTest.cs","Output.txt",true);
Console.WriteLine("2. === Copied Successfully!!===");
bool exist = File.Exists("C:/C#Example/09/Output.txt");
Console.WriteLine("3. Output.txt존재여부:"+ exist);
DateTime dt = File.GetCreationTime("C:/C#Example/09/Output.txt");
Console.WriteLine("4. 파일 생성시간:"+ dt.ToString());
Console.WriteLine("5. 프로그램 끝");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class BinaryRWTest
{
public static void Main()
{
FileStream fs = new FileStream( "BinaryRWTest.dat", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
int[ ] data = new int[ ]{0,1,2,3,4};
Console.WriteLine("1. int형을 이진 데이터로 기록");
for (int i = 0;i<data.Length ;i++ )
{
bw.Write(data[i]);
}
bw.Close();
FileStream fs2 = new FileStream("BinaryRWTest.dat", FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs2);
Console.WriteLine("2. int형 형식으로 읽어 오기");
for (int i =0;i<data.Length ;i++ )
{
Console.Write(br.ReadInt32()+" \t");
}
br.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
using System.Net;
public class WebPageTest
{
public static void Main()
{
int length = 1024;
char[ ] buffer = new char[length];
WebRequest request = WebRequest.Create("http://ehan.co.kr");
WebResponse response = request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream(),
System.Text.Encoding.Default);
int count =0;
do
{
count = sr.Read(buffer,0,length);
Console.WriteLine(buffer,0,count);
}while(count>0);
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class FileTest2
{
public static void Main()
{
Console.WriteLine("1. 프로그램 시작");
Console.WriteLine("2. 파일스트림 생성 ");
FileStream fs = File.OpenRead("C:/C#Example/poet.txt");
StreamReader r = new StreamReader(fs,System.Text.Encoding.Default); //문자스트림 변환
r.BaseStream.Seek(0, SeekOrigin.Begin);
//커서의 위치를 첫 시작점에 위치시킨다.
Console.WriteLine("3. 파일 읽어와서 디스플레이하기");
while (r.Peek() > -1)
{
Console.WriteLine(r.ReadLine());
}
r.Close();
Console.WriteLine("4. 프로그램 끝");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class DirectoryTest
{
public static void Main()
{
Console.WriteLine("1. 프로그램 시작");
Directory.CreateDirectory("C:/C#Example/NewFolder");
//디렉터리 생성
if(Directory.Exists("C:/C#Example/NewFolder"))
{
//디렉터리 존재확인
Console.WriteLine("2. 해당 디렉터리가 존재합니다.");
}
else
{
Console.WriteLine("2. 해당 디렉터리가 존재하지 않습니다.");
}
Console.WriteLine("3. 디렉터리 내의 파일목록 출력");
string[ ] files = Directory.GetFiles("C:\\C#Example");
//디렉터리 내의 파일 목록 얻기
for(int i= 0; i<files.Length;i++)
{
Console.WriteLine(files[i]);
}
Console.WriteLine("4. 디렉터리 내의 서브디렉터리목록 출력");
string[ ] dirs = Directory.GetDirectories("C:\\C#Example");
//서브 디렉터리 목록 얻기
for(int i= 0; i<dirs.Length;i++)
{
Console.WriteLine("C:\\C#Example" + dirs[i]);
}
Console.WriteLine("5. 프로그램 끝");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class PathTest
{
public static void Main()
{
Console.WriteLine("1. 프로그램 시작");
char ps = Path.DirectorySeparatorChar;
Console.WriteLine("2. Path.DirectorySeparatorChar:"+ ps);
string path1 = @"C:\C#Example";
string path2 = @"Path";
Console.WriteLine("3. 디렉터리 결합:" + Path.Combine(path1, path2));
string str = Path.GetFileName(@"C:\C#Example\PathTest.cs");
Console.WriteLine("4. 파일이름얻기:" + str);
Console.WriteLine("5. 프로그램 끝");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class StreamTest
{
public static void Main()
{
int ch;
Stream st = Console.OpenStandardInput();
Console.WriteLine("CanRead:"+ st.CanRead);
Console.WriteLine("CanWrite :"+ st.CanWrite);
Console.WriteLine("끝내시려면 'S'를 입력해 주세요");
Console.Write("아무글이나 입력하시고 Enter를 쳐주세요?");
while((ch=st.ReadByte()) != -1)
{
if(ch == 83)
{ // S의 아스키코드는 83
Console.WriteLine("stop");
return;
}
Console.WriteLine((char)ch +":"+ ch);
}
} //main
} //class
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class FileStreamTest
{
public static void Main()
{
Console.WriteLine("1. 프로그램 시작");
String path = @"C:\C#Example\poet.txt";
Console.WriteLine("2. 파일에 데이터 기록");
FileStream fs = new FileStream(path, FileMode.Create);
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default);
sw.BaseStream.Seek(0, SeekOrigin.End);
sw.WriteLine ("-------------------------------");
sw.WriteLine(" 파일 내용!!!!!!!!!!! ");
sw.WriteLine ("-------------------------------");
sw.Flush();
sw.Close();
Console.WriteLine("3. 파일에 데이터 읽기");
FileStream fs2 = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader sr = new StreamReader(fs2,System.Text.Encoding.Default);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
while (sr.Peek() > -1)
{
Console.WriteLine(sr.ReadLine());
}
sr.Close();
Console.WriteLine("4. 프로그램 종료");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class BufferedStreamTest
{
public static void Main(string[ ] args)
{
FileStream fs = new FileStream(args[0],FileMode.OpenOrCreate, FileAccess.Read);
BufferedStream bin = new BufferedStream(fs);
FileStream fs2 = new FileStream(args[1],FileMode.Create, FileAccess.Write);
BufferedStream bout = new BufferedStream(fs2);
byte[ ] array = new byte[1024*4]; //BufferedStream의 기본 버퍼는 4096
Console.Write("Copy..Start Time: "+ DateTime.Now.TimeOfDay);
int count = 0;
do
{
count=bin.Read(array, 0, 4096);
bout.Write(array, 0, count);
}while(count>0);
Console.Write("\nCopy....End Time: "+DateTime.Now.TimeOfDay);
bout.Flush();
bin.Close();
bout.Close();
} //main
} //class
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class MemoryStreamTest
{
public static void Main()
{
byte[ ] values = new byte [ ] {0,1,2,3,4,5,6,7,8,9};
Console.WriteLine("1. 원본 배열에서 읽기");
foreach (byte b in values)
Console.Write(b+"\t");
Console.WriteLine("2. 메모리 스트림을 통해서 읽기");
MemoryStream ms = new MemoryStream (values);
int temp = 0;
while( (temp = ms.ReadByte())!=-1 )
{ //메모리 스트림읽기
Console.Write(temp+"\t");
}
Console.WriteLine("3. 메모리 스트림을 배열로 만들기");
byte[ ] result = ms.ToArray(); //메모리스트림을 배열로
foreach (byte b in result)
Console.Write(b +"\t");
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.IO;
public class StringRWTest
{
public static void Main()
{
int ch;
string str="ehan!";
StringReader sr=new StringReader(str);
StringWriter sw=new StringWriter();
while((ch=sr.Read())!=-1)
{
sw.Write((char)ch);
Console.WriteLine("read:["+(char)ch+"]"+",write:["+ sw.ToString() +"]");
}
Console.WriteLine("문자열 출력: "+sw.ToString());
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace Chapter13_1
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.GroupBox groupBox4;
private System.Windows.Forms.Panel panel4;
private Graphics gOne,gTwo,gThree,gFour;
private Thread threadOne;
private Thread threadTwo;
private Thread threadThree;
private Thread threadFour;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private Rectangle rec;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.panel2 = new System.Windows.Forms.Panel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.panel3 = new System.Windows.Forms.Panel();
this.groupBox4 = new System.Windows.Forms.GroupBox();
this.panel4 = new System.Windows.Forms.Panel();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Location = new System.Drawing.Point(8, 16);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(184, 144);
this.panel1.TabIndex = 0;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem7,
this.menuItem6});
this.menuItem1.Text = "그리기";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "사각형";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "원";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "채우기";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.panel1);
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 168);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.panel2);
this.groupBox2.Location = new System.Drawing.Point(208, 0);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(200, 168);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.White;
this.panel2.Location = new System.Drawing.Point(8, 16);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(184, 144);
this.panel2.TabIndex = 0;
//
// groupBox3
//
this.groupBox3.Controls.Add(this.panel3);
this.groupBox3.Location = new System.Drawing.Point(0, 176);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 168);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.White;
this.panel3.Location = new System.Drawing.Point(8, 16);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(184, 144);
this.panel3.TabIndex = 0;
//
// groupBox4
//
this.groupBox4.Controls.Add(this.panel4);
this.groupBox4.Location = new System.Drawing.Point(208, 176);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(200, 168);
this.groupBox4.TabIndex = 4;
this.groupBox4.TabStop = false;
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.White;
this.panel4.Location = new System.Drawing.Point(8, 16);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(184, 144);
this.panel4.TabIndex = 0;
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "반짝반짝";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem6
//
this.menuItem6.Index = 5;
this.menuItem6.Text = "종료";
//
// menuItem7
//
this.menuItem7.Index = 4;
this.menuItem7.Text = "-";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(408, 345);
this.Controls.Add(this.groupBox4);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
threadOne=new Thread(new ThreadStart(One));
threadOne.Start();
}
private void One()
{
gOne=panel1.CreateGraphics();
rec=new Rectangle(30,30,70,70);
while(true)
{
Thread.Sleep(1000);
gOne.DrawRectangle(Pens.Green,rec);
gOne.RotateTransform(1);
}
}
private void Two()
{
gTwo=panel2.CreateGraphics();
Rectangle r2=new Rectangle(30,30,70,70);
int red=0,green=0,blue=0;
while(true)
{
Thread.Sleep(100);
red+=1;
green+=10;
blue+=20;
if(red >255 || green >255 || blue>255)
{
red=0;green=0;blue=0;
}
SolidBrush brush=new SolidBrush(Color.FromArgb(red,green,blue));
gTwo.FillEllipse(brush,30,30,100,100);
}
}
protected override void OnClosing(CancelEventArgs e)
{
if(threadOne != null)
threadOne.Abort();
if(threadTwo != null)
threadTwo.Abort();
if(threadThree != null)
threadThree.Abort();
if(threadFour != null)
threadFour.Abort();
base.OnClosing (e);
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
threadTwo=new Thread(new ThreadStart(Two));
threadTwo.Start();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
threadThree=new Thread(new ThreadStart(Three));
threadThree.Start();
}
private void Three()
{
gThree=panel3.CreateGraphics();
int red=0,green=0,blue=0;
while(true)
{
Thread.Sleep(100);
red+=20;
green+=10;
blue+=1;
if(red >255 || green >255 || blue>255)
{
red=0;green=0;blue=0;
}
SolidBrush brush=new SolidBrush(Color.FromArgb(red,green,blue));
gThree.FillRectangle(brush,0,0,200,150);
}
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
threadFour=new Thread(new ThreadStart(Four));
threadFour.Start();
}
private void Four()
{
gFour=panel4.CreateGraphics();
while(true)
{
Thread.Sleep(10);
Brush brush=new SolidBrush(Color.Blue);
gFour.FillRectangle(brush,0,0,200,150);
gFour.Clear(Color.White);
}
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Text;
namespace Chapter13_2
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
private const int port=4567;
private Socket listenSocket;
private Socket clientSocket;
private Socket remoteSocket;
private IPEndPoint listenEP;
private IPEndPoint remoteEP;
private Thread listenThread;
private System.Windows.Forms.ListBox listBox1;
private Thread streamThread;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button4;
private Thread clientThread;
private bool isServer=true;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button4 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Location = new System.Drawing.Point(0, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 88);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "접속";
//
// button3
//
this.button3.Location = new System.Drawing.Point(152, 24);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(128, 24);
this.button3.TabIndex = 3;
this.button3.Text = "클라이언트";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 24);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(128, 24);
this.button2.TabIndex = 2;
this.button2.Text = "서버";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(152, 56);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 24);
this.button1.TabIndex = 1;
this.button1.Text = "접속";
this.button1.Visible = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Enabled = false;
this.textBox1.Location = new System.Drawing.Point(8, 56);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "127.0.0.1";
this.textBox1.Visible = false;
//
// listBox1
//
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(0, 104);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(288, 136);
this.listBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(0, 248);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(200, 21);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "";
//
// button4
//
this.button4.Location = new System.Drawing.Point(208, 248);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(80, 24);
this.button4.TabIndex = 3;
this.button4.Text = "보내기";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button4);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button3_Click(object sender, System.EventArgs e)
{
//클라이언트로 실행했을때
//소켓을 생성하고
//데이터를 받는 스레드를 생성한다.
this.textBox1.Visible=true;
this.button1.Visible=true;
try
{
remoteSocket=new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
remoteEP=new IPEndPoint(IPAddress.Loopback,port);
clientThread=new Thread(new ThreadStart(client));
}
catch(System.Net.Sockets.SocketException se)
{
Console.WriteLine(se.ToString());
}
}
private void button2_Click(object sender, System.EventArgs e)
{
//서버로 실행했을때
//소켓을 생성하고
//데이타를 받는 스레드를 생성,시작한다.
//클라이언트가 접속하기를 기다리는
//스레드도 생성,시작한다.
try
{
listenSocket=new Socket(AddressFamily.InterNetwork,
SocketType.Stream,ProtocolType.Tcp);
listenEP=new IPEndPoint(IPAddress.Any,port);
listenSocket.Bind(listenEP);
listenSocket.Listen(5);
listenThread=new Thread(new ThreadStart(listen));
listenThread.Start();
streamThread=new Thread(new ThreadStart(Stream));
streamThread.Start();
this.listBox1.Items.Add("Server Start");
}
catch(System.Net.Sockets.SocketException se)
{
Console.WriteLine(se.ToString());
}
}
private void listen()
{
//클라이언트를 기다린다.
while(true)
{
Thread.Sleep(100);
clientSocket=listenSocket.Accept();
this.listBox1.Items.Add("클라이언트 접속");
}
}
private void Stream()
{
//서버편 데이타를 받는 스레드 함수
//
byte[] buffer=new byte[512];
string temp=null;
while(true)
{
Thread.Sleep(100);
if(clientSocket !=null)
{
int rec=clientSocket.Receive(buffer);
temp=Encoding.Unicode.GetString(buffer,0,rec);
this.listBox1.Items.Add(temp);
}
}
}
private void button4_Click(object sender, System.EventArgs e)
{
//서버와 클라이언트 모두
//데이타를 보내는 함수로
//서버일때와 클라이언트일때 보내는 소켓이 다르다.
byte[] send=new byte[512];
if(isServer)
{
Encoding.Unicode.GetBytes(this.textBox2.Text,
0,this.textBox2.Text.Length,send,0);
clientSocket.Send(send);
}
else
{
Encoding.Unicode.GetBytes(this.textBox2.Text,
0,this.textBox2.Text.Length,send,0);
remoteSocket.Send(send);
}
this.textBox2.Text="";
}
protected override void OnClosing(CancelEventArgs e)
{
if(listenThread != null)
listenThread.Abort();
if(streamThread != null)
streamThread.Abort();
base.OnClosing (e);
}
private void button1_Click(object sender, System.EventArgs e)
{
//클라이언트로 접속 버튼을 누르면
//서버에 접속을하고
//데이타를 기다리는 스레드를 시작한다.
try
{
remoteSocket.Connect(remoteEP);
isServer=false;
clientThread.Start();
}
catch(System.Net.Sockets.SocketException se)
{
Console.WriteLine(se.ToString());
}
}
private void client()
{
//클라이언트가 서버로부터 데이타를
//수신대기하는 함수이다.
byte[] buffer=new byte[512];
string temp=null;
while(true)
{
Thread.Sleep(100);
if(remoteSocket !=null)
{
int rec=remoteSocket.Receive(buffer);
temp=Encoding.Unicode.GetString(buffer,0,rec);
this.listBox1.Items.Add(temp);
}
}
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
class SimpleThread
{
public void SimpleMethod()
{
Random RandomNumber = new Random();
for (int i=0;i<3;i++)
{
Console.WriteLine(i+" "+Thread.CurrentThread.Name);
Thread.Sleep(RandomNumber.Next(1,5)*1000);
}
Console.WriteLine("DONE! "+Thread.CurrentThread.Name);
}
}
class Exercise
{
public static void Main()
{
SimpleThread obj = new SimpleThread();
ThreadStart ts = new ThreadStart(obj.SimpleMethod);
Thread worker1 = new Thread(ts);
Thread worker2 = new Thread(ts);
worker1.Name = "Apple";
worker2.Name = "Orange";
worker1.Start();
worker2.Start();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class MainThreadTest
{
public static void Main ()
{
Thread th = Thread.CurrentThread;
Console.WriteLine("1. 현재 Thread HashCode:", th.GetHashCode());
Console.WriteLine("2. 스레드의 이름:"+ th.Name);
Console.WriteLine("3. 스레드의 CurrentCulture:"+ th.CurrentCulture);
Console.WriteLine("4. 스레드의 우선순위:"+ th.Priority);
Console.WriteLine("5. 스레드의 상태:"+ th.ThreadState);
Console.WriteLine("6. 스레드의 IsBackground:"+ th.IsBackground);
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class ThreadMonitorTest
{
public static void Main()
{
Top t1 = new Top();
Top t2 = new Top();
ThreadStart ts1 = new ThreadStart(t1.SayHello);
ThreadStart ts2 = new ThreadStart(t2.SayHello);
Thread thread1= new Thread(ts1);
Thread thread2= new Thread(ts2);
thread1.Start();
thread2.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private static object obj = new object();
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
Monitor.Enter(Top.obj); //동기화 진입점
try
{
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + count++);
Thread.Sleep(10);
if(count==5)
{
throw(new Exception());
}
}
}
catch(Exception e)
{
Console.WriteLine(e);
}
finally
{
Monitor.Exit(Top.obj); //동기화 종료점
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class ThreadMutexTest
{
public static void Main()
{
Top t1 = new Top();
Top t2 = new Top();
ThreadStart ts1 = new ThreadStart(t1.SayHello);
ThreadStart ts2 = new ThreadStart(t2.SayHello);
Thread thread1= new Thread(ts1);
Thread thread2= new Thread(ts2);
thread1.Start();
thread2.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private static Mutex mtx = new Mutex(false,"mutexsample");
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
mtx.WaitOne();
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + count++);
Thread.Sleep(10);
}
mtx.ReleaseMutex();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
class InterlockedTest
{
public static void Main()
{
Top s = new Top();
Thread t1=new Thread(new ThreadStart(s.SayHello));
Thread t2=new Thread(new ThreadStart(s.SayHello));
t1.Start();
t2.Start();
} //main
} //class
class Top
{
private int limit = 0;
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + limit);
Interlocked.Increment(ref limit);
//limit을 사용하는 순간에 동기화가 보장된다.
count++;
Thread.Sleep(10);
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class ReaderWriterLockTest
{
public static void Main()
{
Top t = new Top();
ThreadStart s= new ThreadStart(t.Writer);
ThreadStart r = new ThreadStart(t.Reader);
Thread t1 = new Thread(s);
Thread t2 = new Thread(r);
t1.Start();
t2.Start();
}
}
class Top
{
static ReaderWriterLock rw = new ReaderWriterLock();
public void Writer()
{
Console.Write("Writing:");
for(int i=0;i<20;++i)
{
rw.AcquireWriterLock(Timeout.Infinite);
Console.Write("w");
Thread.Sleep(20);
rw.ReleaseWriterLock();
}
Console.WriteLine();
}
public void Reader()
{
Console.Write("Reading:");
for(int i=0;i<20;++i)
{
rw.AcquireReaderLock(Timeout.Infinite);
Console.Write("r");
Thread.Sleep(20);
rw.ReleaseReaderLock();
}
Console.WriteLine();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class SimpleThreadTest
{
public static void Main()
{
Top t = new Top();
ThreadStart ts = new ThreadStart(t.SayHello);
Thread thread= new Thread(ts);
thread.Start();
Console.Write("Thread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private int limit = 0;
public void SayHello()
{
while(limit<10)
{
Console.WriteLine("Thread "+Thread.CurrentThread.GetHashCode() +":" + limit++);
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class SimpleThreadSleepTest
{
public static void Main()
{
Top t = new Top();
ThreadStart ts = new ThreadStart(t.SayHello);
Thread thread= new Thread(ts);
thread.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
} //main
} //class
public class Top
{
private int limit = 0;
public void SayHello()
{
while(limit<10)
{
Console.WriteLine(DateTime.Now.Second +":" + limit++);
Thread.Sleep(1000); //1초
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class SimpleThreadSuspendTest
{
public static void Main()
{
Top t = new Top();
ThreadStart ts = new ThreadStart(t.SayHello);
Thread thread= new Thread(ts);
thread.Start();
Console.Write("Thread "+Thread.CurrentThread.GetHashCode()+"메인 3초 Sleep 설정\n" );
Thread.Sleep(3000);
Console.Write("Thread "+Thread.CurrentThread.GetHashCode()+"메인 Sleep 해제\n" );
thread.Resume();
}
}
public class Top
{
private int limit = 0;
public void SayHello()
{
while(limit<10)
{
Console.WriteLine("Thread "+Thread.CurrentThread.GetHashCode() +":" + limit++);
if(limit==5)
Thread.CurrentThread.Suspend();
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
class SimpleThreadExitTest
{
public static void Main ()
{
Top t = new Top();
Thread thread = new Thread(new ThreadStart(t.SayHello));
thread.Start();
Thread.Sleep(300);
thread.Abort(); //0.3초 뒤 스레드가 강제 종료
}
}
class Top
{
public void SayHello()
{
int id = Thread.CurrentThread.GetHashCode();
try
{
Console.WriteLine("Thread "+id+ ": 작업시작" );
for (int i=0;i<10;i++)
{
Console.WriteLine("SayHello:"+ i);
Thread.Sleep(100);
}
Console.WriteLine("Thread "+id+ ": try 작업종료" );
}
catch(ThreadAbortException e)
{
Console.WriteLine("Thread "+id+ ": catch" );
Console.WriteLine(e);
}
finally
{
Console.WriteLine("Thread "+id+ ": finally" );
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class MultiThreadTest
{
public static void Main()
{
Top t1 = new Top();
Top t2 = new Top();
ThreadStart ts1 = new ThreadStart(t1.SayHello);
ThreadStart ts2 = new ThreadStart(t2.SayHello);
Thread thread1= new Thread(ts1);
Thread thread2= new Thread(ts2);
thread1.Start();
thread2.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private int limit = 0;
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + limit++);
count++;
Thread.Sleep(10);
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
class SimpleThreadPriorityTest
{
public static void Main ()
{
int nowId = Thread.CurrentThread.GetHashCode();
Console.WriteLine("-ID {0} Main Thread 작업시작-", nowId );
Top t1 = new Top();
Top t2 = new Top();
Thread thread1 = new Thread(new ThreadStart(t1.SayHello));
Thread thread2 = new Thread(new ThreadStart(t2.SayHello));
Thread.CurrentThread.Priority = ThreadPriority.Normal;
thread1.Priority = ThreadPriority.Lowest;
thread2.Priority = ThreadPriority.Highest;
thread1.Start();
thread2.Start();
Console.WriteLine("-ID {0} Main Thread 작업종료-", nowId);
}
}
public class Top
{
private int limit = 0;
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + limit++);
count++;
Thread.Sleep(1);
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class MultiThreadSyncTest
{
public static void Main()
{
Top t = new Top(); //하나의 객체 생성
ThreadStart ts1 = new ThreadStart(t.SayHello);
ThreadStart ts2 = new ThreadStart(t.SayHello);
Thread thread1= new Thread(ts1);
Thread thread2= new Thread(ts2);
thread1.Start();
thread2.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private int limit = 0; //공유자원
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
lock(this)
{
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + limit++);
count++;
Thread.Sleep(10);
}
} //lock
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Threading;
public class MultiThreadSyncStaticTest
{
public static void Main()
{
Top t1 = new Top();
Top t2 = new Top();
ThreadStart ts1 = new ThreadStart(t1.SayHello);
ThreadStart ts2 = new ThreadStart(t2.SayHello);
Thread thread1= new Thread(ts1);
Thread thread2= new Thread(ts2);
thread1.Start();
thread2.Start();
Console.Write("\nThread "+Thread.CurrentThread.GetHashCode()+ "메인 종료\n" );
}
}
public class Top
{
private static int limit = 0;
public void SayHello()
{
int hash = Thread.CurrentThread.GetHashCode();
int count =0;
lock(typeof(Top))
{
while(count<10)
{
Console.WriteLine("Thread "+ hash+":" + limit++);
count++;
Thread.Sleep(10);
}
} //lock
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace Chapter14_1
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button1;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox6;
private SqlCommand command1;
private SqlDataReader reader;
private string searchText=null;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Data.SqlClient.SqlCommand sqlCommand1;
private string searchItem=null;
public Form1()
{
//
// Windows Form 디자이너 지원에 필요합니다.
//
InitializeComponent();
//
// TODO: InitializeComponent를 호출한 다음 생성자 코드를 추가합니다.
//
//데이타 베이스에 접속한다.
sqlConnection1.Open();
#region 첫 번째 고객 데이터를 읽어온다
string comText="SELECT people.* FROM people";
command1=new SqlCommand(comText,sqlConnection1);
command1.ExecuteNonQuery();
reader=command1.ExecuteReader();
reader.Read();
this.textBox1.Text=reader.GetInt32(0).ToString();
this.textBox2.Text=reader.GetString(1);
this.textBox3.Text=reader.GetInt32(2).ToString();
this.textBox4.Text=reader.GetString(3);
this.textBox6.Text=reader.GetString(4);
#endregion
}
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form 디자이너에서 생성한 코드
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button2 = new System.Windows.Forms.Button();
this.textBox5 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.sqlCommand1 = new System.Data.SqlClient.SqlCommand();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=LEUC0M2RO5VQ1JU;packet size=4096;user id=kimhoon;integrated securi" +
"ty=SSPI;data source=LEUC0M2RO5VQ1JU;persist security info=False;initial catalog=" +
"Northwind";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.textBox6);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.textBox4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.textBox3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Location = new System.Drawing.Point(0, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(216, 224);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Customer";
//
// label4
//
this.label4.Location = new System.Drawing.Point(8, 128);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(40, 24);
this.label4.TabIndex = 7;
this.label4.Text = "Sex";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(88, 120);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(120, 21);
this.textBox4.TabIndex = 6;
this.textBox4.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 24);
this.label3.TabIndex = 5;
this.label3.Text = "Age";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(88, 88);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(120, 21);
this.textBox3.TabIndex = 4;
this.textBox3.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(8, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 24);
this.label2.TabIndex = 3;
this.label2.Text = "Name";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(88, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(120, 21);
this.textBox2.TabIndex = 2;
this.textBox2.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 24);
this.label1.TabIndex = 1;
this.label1.Text = "Number";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(120, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(88, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(120, 32);
this.button1.TabIndex = 1;
this.button1.Text = "다음고객";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button4);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.Controls.Add(this.textBox5);
this.groupBox2.Controls.Add(this.button2);
this.groupBox2.Controls.Add(this.comboBox1);
this.groupBox2.Location = new System.Drawing.Point(224, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(136, 224);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
//
// comboBox1
//
this.comboBox1.Items.AddRange(new object[] {
"ID",
"Name",
"Age",
"Sex",
"Phone"});
this.comboBox1.Location = new System.Drawing.Point(8, 120);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(120, 20);
this.comboBox1.TabIndex = 0;
this.comboBox1.Text = "항목선택";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 184);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(120, 32);
this.button2.TabIndex = 1;
this.button2.Text = "찾기";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(8, 152);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(120, 21);
this.textBox5.TabIndex = 2;
this.textBox5.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(8, 160);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 24);
this.label5.TabIndex = 9;
this.label5.Text = "Phone";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(88, 152);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(120, 21);
this.textBox6.TabIndex = 8;
this.textBox6.Text = "";
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 16);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(120, 32);
this.button3.TabIndex = 3;
this.button3.Text = "고객추가";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(8, 56);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(120, 32);
this.button4.TabIndex = 4;
this.button4.Text = "고객삭제";
//
// sqlCommand1
//
this.sqlCommand1.CommandText = "INSERT INTO people (ID, name, age) VALUES (8, \'hoony\', 22)";
this.sqlCommand1.Connection = this.sqlConnection1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(368, 237);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Console.WriteLine(reader.IsClosed);
if(reader.IsClosed)
{
reader=command1.ExecuteReader();
if(reader.Read())
{
this.textBox1.Text=reader.GetInt32(0).ToString();
this.textBox2.Text=reader.GetString(1);
this.textBox3.Text=reader.GetInt32(2).ToString();
this.textBox4.Text=reader.GetString(3);
this.textBox6.Text=reader.GetString(4);
}
else
{
MessageBox.Show(this,"여기가 끝입니다.");
}
}
else
{
if(reader.Read())
{
this.textBox1.Text=reader.GetInt32(0).ToString();
this.textBox2.Text=reader.GetString(1);
this.textBox3.Text=reader.GetInt32(2).ToString();
this.textBox4.Text=reader.GetString(3);
this.textBox6.Text=reader.GetString(4);
}
else
{
MessageBox.Show(this,"여기가 끝입니다.");
}
}
}
protected override void OnClosing(CancelEventArgs e)
{
if(reader != null)
reader.Close();
if(sqlConnection1 !=null)
sqlConnection1.Close();
base.OnClosing (e);
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.comboBox1.SelectedItem.ToString() == "ID")
searchItem="id=";
else if(this.comboBox1.SelectedItem.ToString() == "Name")
searchItem="name=";
else if(this.comboBox1.SelectedItem.ToString() == "Age")
searchItem="age=";
else if(this.comboBox1.SelectedItem.ToString() == "Sex")
searchItem="sex=";
else if(this.comboBox1.SelectedItem.ToString() == "Phone")
searchItem="phone=";
}
private void button2_Click(object sender, System.EventArgs e)
{
reader.Close();
//찾기에 해당하는 항목을 찾는다.
searchText="SELECT * FROM people WHERE "+searchItem+"'"+this.textBox5.Text+"'";
Console.WriteLine(searchText);
SqlCommand command2=new SqlCommand(searchText,sqlConnection1);
try
{
SqlDataReader searchReader=command2.ExecuteReader();
if(searchReader.Read())
{
this.textBox1.Text=searchReader.GetInt32(0).ToString();
this.textBox2.Text=searchReader.GetString(1);
this.textBox3.Text=searchReader.GetInt32(2).ToString();
this.textBox4.Text=searchReader.GetString(3);
this.textBox6.Text=searchReader.GetString(4);
}
else
{
MessageBox.Show(this,"해당하는 데이터가 없습니다.");
}
searchReader.Close();
}
catch(System.Data.SqlClient.SqlException se)
{
Console.WriteLine(se.ToString());
}
}
private void button3_Click(object sender, System.EventArgs e)
{
try
{
reader.Close();
string query ="INSERT INTO people (ID, name, age) VALUES ("
+Convert.ToInt32(this.textBox1.Text)+","+ "\'"+textBox2.Text+"\'"+","+Convert.ToInt32(this.textBox3.Text)+")";
SqlCommand comm = new SqlCommand(query, sqlConnection1);
comm.ExecuteNonQuery();
MessageBox.Show(this,"고객이 추가되었습니다.");
}
catch(System.Data.SqlClient.SqlException se)
{
Console.WriteLine(se.ToString());
}
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
class ConnectionTest
{
public static void Main(string[ ] args)
{
string strConn="server=localhost;database=NorthWind;user id=sa; password=1004";
SqlConnection conn = new SqlConnection(strConn);
conn.Open(); // Open Connection
Console.WriteLine("1. Database = " + conn.Database);
Console.WriteLine("2. DataSource = " + conn.DataSource);
Console.WriteLine("3. DataServerVersion = " + conn.ServerVersion);
Console.WriteLine("4. State = " + conn.State);
Console.WriteLine("5. WorkstationID = " + conn.WorkstationId);
conn.Close(); // Close Connection
Console.WriteLine("6. State = " + conn.State);
} //main
} //class
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class DataSetMergeTest
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
SqlDataAdapter adapter1 = new SqlDataAdapter();
SqlDataAdapter adapter2 = new SqlDataAdapter();
adapter1.SelectCommand = new SqlCommand("select * from Address", conn);
adapter2.SelectCommand = new SqlCommand("select LastName from Employees", conn);
DataSet ds1 = new DataSet();
DataSet ds2 = new DataSet();
adapter1.Fill(ds1, "DsAddress"); //DataSet에서 사용할 테이블의 이름을 설정한다.
adapter2.Fill(ds2, "DsEmployees"); //DataSet에서 사용할 테이블의 이름을 설정한다.
conn.Close();
ds1.Merge(ds2); //ds2를 ds1과 병합한다.
DataSet dsc = ds1.Copy(); //병합된 ds1의 복사본을 만든다.
DataTable table= dsc.Tables["DsAddress"];
DataRowCollection rows = table.Rows;
foreach (DataRow dr in rows)
{
for (int i = 0; i<table.Columns.Count; i++)
Console.Write("{0,15}",dr[i]);
Console.WriteLine();
}
table= dsc.Tables["DsEmployees"];
rows = table.Rows;
foreach (DataRow dr in rows)
{
for (int i = 0; i<table.Columns.Count; i++)
Console.Write("{0,15}",dr[i]);
Console.WriteLine();
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
public class RelationTest
{
public static void Main()
{
// DataSet 생성
DataSet ds = new DataSet ( "publication" ) ;
//DataTable 생성
DataTable publicTable = new DataTable("publics") ;
publicTable.Columns.Add ( new DataColumn("publicID",typeof (int)));
publicTable.Columns.Add ( new DataColumn ("Name", typeof ( string))) ;
//테이블에 제약조건 설정
publicTable.Constraints.Add (
new UniqueConstraint ( "PK_Publics" , publicTable.Columns[0] ) ) ;
//기본키 설정
publicTable.PrimaryKey = new DataColumn[ ] { publicTable.Columns[0] } ;
DataTable peopleTable = new DataTable("People" ) ;
peopleTable.Columns.Add (new DataColumn("PeopleID",typeof (int))) ;
peopleTable.Columns.Add ( new DataColumn("Name",typeof (string))) ;
peopleTable.Columns.Add ( new DataColumn ( "publicID" , typeof (int))) ;
peopleTable.Constraints.Add (
new UniqueConstraint ( "PK_People" , peopleTable.Columns[0] ) ) ;
peopleTable.PrimaryKey = new DataColumn[ ] { peopleTable.Columns[0] } ;
//DataSet 에 DataTable 추가
ds.Tables.Add (publicTable) ;
ds.Tables.Add (peopleTable) ;
// 관계 설정
ds.Relations.Add ( "Peoples",ds.Tables["publics"].Columns["publicID"],
ds.Tables["People"].Columns["publicID"]) ;
//DataTable에 자료 입력
DataRow publicRow = ds.Tables["publics"].NewRow() ;
publicRow["publicID"] = 1 ;
publicRow["Name"] = "Seoul" ;
ds.Tables["publics"].Rows.Add ( publicRow ) ;
DataRow peopleRow = ds.Tables["People"].NewRow ( ) ;
peopleRow["PeopleID" ] = 1 ;
peopleRow["Name"] = "Namil Park" ;
peopleRow["publicID"] = 1 ;
ds.Tables["People"].Rows.Add ( peopleRow ) ;
peopleRow = ds.Tables["People"].NewRow ( ) ;
peopleRow["PeopleID" ] = 2 ;
peopleRow["Name"] = "JiSun" ;
peopleRow["publicID"] = 1 ;
ds.Tables["People"].Rows.Add ( peopleRow ) ;
peopleRow = ds.Tables["People"].NewRow ( ) ;
peopleRow["PeopleID" ] = 3 ;
peopleRow["Name"] = "Kate" ;
peopleRow["publicID"] = 1 ;
ds.Tables["People"].Rows.Add ( peopleRow ) ;
// 테이블간의 관계를 이용하여 데이터 출력
foreach ( DataRow publisher in ds.Tables["publics"].Rows )
{
DataRow[ ] subRelay = publisher.GetChildRows("Peoples") ;
int peopleCount = subRelay.Length ;
Console.WriteLine ( " {0} 출신 : {1} 명" , publisher["Name"] , peopleCount ) ;
foreach ( DataRow thePeople in subRelay )
Console.WriteLine ( "성명: {0}" , thePeople["Name"]);
}
foreach ( DataRow people in ds.Tables["People"].Rows)
{
DataRow[ ] parents = people.GetParentRows ( "Peoples" ) ;
foreach ( DataRow publisher in parents )
Console.WriteLine ( "이름 : {0} , {1}의 출신" , people["Name"] , publisher["Name"] ) ;
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
class CommandNonQueryTest
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=0000;database=northwind";
string createQuery = "create table Address ( id int, name char(20), addr char(40))";
string query1 ="Insert into Address values (1, '김이한', '서울시')";
string query2 ="Insert into Address values (2, '홍길동', '대전시')";
string query3 ="Insert into Address values (3, '춘향이', '대구시')";
string query4 ="Insert into Address values (4, '박문수', '부산시')";
string query5 ="Insert into Address values (5, '이순신', '인천시')";
Console.WriteLine("1. Connection 생성과 Open");
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
Console.WriteLine("2. Command 생성");
SqlCommand comm = new SqlCommand(createQuery, conn);
SqlCommand comm1 = new SqlCommand(query1, conn);
SqlCommand comm2 = new SqlCommand(query2, conn);
SqlCommand comm3 = new SqlCommand(query3, conn);
SqlCommand comm4 = new SqlCommand(query4, conn);
SqlCommand comm5 = new SqlCommand(query5, conn);
Console.WriteLine("3. Command 수행");
comm.ExecuteNonQuery();
comm1.ExecuteNonQuery();
comm2.ExecuteNonQuery();
comm3.ExecuteNonQuery();
comm4.ExecuteNonQuery();
comm5.ExecuteNonQuery();
Console.WriteLine("4. Connection Close");
conn.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class CommandParamTest
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
string query ="Insert into Address values (@ID, @Name, @Address)";
Console.WriteLine("1. Connection 생성과 Open");
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
Console.WriteLine("2. Command 생성");
SqlCommand comm = new SqlCommand(query, conn);
Console.WriteLine("3. Command의 Parameter Type설정");
comm.Parameters.Add("@ID", SqlDbType.TinyInt);
comm.Parameters.Add("@Name", SqlDbType.Char);
comm.Parameters.Add("@Address", SqlDbType.Char);
Console.WriteLine("4. Command의 Parameter 값설정과 명령 실행1");
comm.Parameters["@ID"].Value = 6;
comm.Parameters["@Name"].Value = "Namil Park";
comm.Parameters["@Address"].Value = "Incheon";
comm.ExecuteNonQuery();
Console.WriteLine("5. Command의 Parameter 값설정과 명령 실행2");
comm.Parameters["@ID"].Value = 7;
comm.Parameters["@Name"].Value = "MR.Lee";
comm.Parameters["@Address"].Value = "Jeju";
comm.ExecuteNonQuery();
Console.WriteLine("6. Connection Close");
conn.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data.SqlClient;
public class CommandReader
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
string query = "select * from Address";
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
SqlCommand comm = new SqlCommand(query, conn);
SqlDataReader sr = comm.ExecuteReader();
while(sr.Read())
{
Console.WriteLine(sr.GetInt32(0)+"|"+ sr.GetString(1).Trim()+"|"+ sr.GetString(2) );
}
sr.Close();
conn.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class CommandParamTest2
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
string query = "select * from Address where addr=@addr1 or addr=@addr2";
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
SqlCommand comm = new SqlCommand(query, conn);
comm.Parameters.Add("@addr1", SqlDbType.Char);
comm.Parameters.Add("@addr2", SqlDbType.Char);
comm.Parameters["@addr1"].Value = "서울시";
comm.Parameters["@addr2"].Value = "대전시";
SqlDataReader sr = comm.ExecuteReader();
while(sr.Read())
{
Console.WriteLine(sr.GetInt32(0)+"|"+ sr.GetString(1).Trim()+"|"+ sr.GetString(2) );
}
sr.Close();
conn.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class AdapterHandleTest
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
string query = "select * from Address";
Console.WriteLine("1. Connenction 생성과 Open");
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
Console.WriteLine("2. SqlDataAdapter 생성");
SqlDataAdapter adapter = new SqlDataAdapter();
Console.WriteLine("3. Adapter에 SelectCommand 할당");
adapter.SelectCommand = new SqlCommand(query, conn);
Console.WriteLine("4. DataSet 생성");
DataSet ds = new DataSet();
Console.WriteLine("5. Adapter를 통해서 DataSet 채우기");
adapter.Fill(ds);
Console.WriteLine("6. Connection 닫기");
conn.Close();
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class DataSetHandleTest
{
public static void Main()
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
string query = "select * from Address";
Console.WriteLine("1. Connenction 생성과 Open");
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
Console.WriteLine("2. SqlDataAdapter 생성");
SqlDataAdapter adapter = new SqlDataAdapter();
Console.WriteLine("3. Adapter에 SelectCommand 할당");
adapter.SelectCommand = new SqlCommand(query, conn);
Console.WriteLine("4. DataSet 생성");
DataSet ds = new DataSet();
Console.WriteLine("5. Adapter를 통해서 DataSet 채우기");
adapter.Fill(ds);
Console.WriteLine("6. Connection 닫기");
conn.Close();
Console.WriteLine("7. DataSet으로 작업하기");
DataTable table= ds.Tables[0];
DataRowCollection rows = table.Rows;
foreach (DataRow dr in rows)
{
for (int i = 0; i<table.Columns.Count; i++)
Console.Write("{0,15}",dr[i]);
Console.WriteLine();
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class AdapterHandleTest2
{
public static void Main(string[ ] args)
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter("select * from Address", conn);
DataSet ds = new DataSet("MyAddressDataSet"); //DataSet의 이름 지정
adapter.Fill(ds); //테이블의 이름
conn.Close();
DataTable table = ds.Tables[0];
DataRowCollection rows = table.Rows;
foreach (DataRow dr in rows)
{
for (int i = 0; i<table.Columns.Count; i++)
Console.Write("{0,15}",dr[i]);
Console.WriteLine();
}
}
}
========================================================================
using System.Reflection;
using System.Runtime.CompilerServices;
//
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 제어됩니다.
// 어셈블리와 관련된 정보를 수정하려면
// 이 특성 값을 변경하십시오.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
//
// 주 버전
// 부 버전
// 빌드 번호
// 수정 번호
//
// 모든 값을 지정하거나
// 아래와 같이 '*'를 사용하여 수정 번호 및 빌드 번호가 자동으로 지정되도록 할 수 있습니다.
[assembly: AssemblyVersion("1.0.*")]
//
// 어셈블리에 서명하려면 사용할 키를 지정해야 합니다. 어셈블리 서명에 대한 자세한 내용은
// Microsoft .NET Framework 설명서를 참조하십시오.
//
// 서명하는 데 사용할 키를 제어하려면 아래 특성을 사용합니다.
//
// 참고:
// (*) 키를 지정하지 않으면 어셈블리에 서명할 수 없습니다.
// (*) KeyName은
// 사용자 컴퓨터의 CSP(암호화 서비스 공급자)에
// 설치되어 있는 키를 참조하고 KeyFile은 키가 포함된 파일을
// 참조합니다.
// (*) KeyFile과 KeyName 값을 모두 지정하면
// 다음과 같은 프로세스가 발생합니다.
// (1) CSP에 KeyName이 있으면 해당 키가 사용됩니다.
// (2) KeyName은 없고, KeyFile이 있으면
// KeyFile의 키가 CSP에 설치되어 사용됩니다.
// (*) sn.exe(강력한 이름 유틸리티)를 사용하면 KeyFile을 만들 수 있습니다.
// KeyFile을 지정하는 경우
// KeyFile의 위치는 %Project Directory%\obj\<configuration>의 프로젝트 출력 디렉터리 위치를 기준으로 하는 상대 위치이어야 합니다.
// 예를 들어, KeyFile이 프로젝트 디렉터리에 있는 경우
// AssemblyKeyFile 특성을
// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]로 지정합니다.
// (*) 서명 연기는 고급 옵션입니다.
// 이 옵션에 대한 자세한 내용은 Microsoft .NET Framework 설명서를 참조하십시오.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
public class AdapterCommandTest
{
public static void Main(string[ ] args)
{
string conStr = "Server=localhost;user id=sa;password=1004;database=northwind";
SqlConnection conn = new SqlConnection(conStr);
conn.Open();
SqlDataAdapter adapter=new SqlDataAdapter("select * from Address",conn);
DataSet ds = new DataSet("MyAddressDataSet"); //DataSet의 이름
adapter.Fill(ds,"Address"); //테이블의 이름
conn.Close();
DataTable table = ds.Tables["Address"];
Console.WriteLine("============ 테이터 삽입 전 ===========");
Print(table); //Connection을 닫은 상태에서 DataSet으로 작업
//1. DataRow 생성하여 Row를 삽입하기
DataRow row = table.NewRow();
row["id"] = "8";
row["name"] = "JiSun";
row["addr"] = "Ameria";
table.Rows.Add(row);
//2. SqlCommand 지정하기
conn.Open();
string strSql = "Insert into Address(id,name,addr)values(@id,@name,@addr)";
adapter.InsertCommand = new SqlCommand(strSql, conn);
adapter.InsertCommand.Parameters.Add("@id", SqlDbType.TinyInt,0, "id");
adapter.InsertCommand.Parameters.Add("@name", SqlDbType.Char, 20, "name");
adapter.InsertCommand.Parameters.Add("@addr", SqlDbType.Char, 40, "addr");
//3. DataAdapter를 이용하여 DataSet 업데이트하기
adapter.Update(ds,"Address"); //DataSet에 있는 Insert된 정보를 테이터베이스로 업데이트
conn.Close();
Console.WriteLine("============ 테이터 삽입 후 ===========");
Print(table);
}
public static void Print(DataTable table)
{
DataRowCollection rows = table.Rows;
foreach (DataRow dr in rows)
{
for (int i = 0; i<table.Columns.Count; i++)
Console.Write("{0,15}",dr[i]);
Console.WriteLine();
}
}
}
TOTAL COMMENTS : 0
24 | Naver 카페 게시글 조회수 및 페이지 뷰 증가 | asia | 2018/11/22 | 210 |
23 | 카카오톡 자동친구 추가 프로그램 | asia | 2018/11/21 | 93 |
22 | 키워드 고객 정보 수집 프로그램 | asia | 2018/11/21 | 57 |
21 | 타겟 고객정보 수집 프로그램 | asia | 2018/11/21 | 50 |
20 | 블록체인 강의자료 | asia | 2018/11/20 | 71 |
19 | 다음 카페 글 자동 등록 프로그램 | asia | 2018/11/20 | 61 |
18 | 네이버 블로그 글 자동 등록프로그램 | asia | 2018/11/19 | 435 |
17 | 네이버 카페 글 자동 등록기 | asia | 2018/11/19 | 816 |
16 | 사이버해킹박스 시스템 | ASIAGROUP | 2018/04/06 | 316 |
15 | 사이버침해 모니터링 시스템 | ASIAGROUP | 2018/04/02 | 383 |
14 | 정보보안 해킹 시뮬레이션 시스템 | ASIAGROUP | 2018/03/23 | 306 |
13 | 사이버해킹박스 시스템 | ASIAGROUP | 2018/04/06 | 314 |
12 | 사이버침해 모니터링 시스템 | ASIAGROUP | 2018/04/02 | 387 |
11 | 블록체인 강의자료 | asia | 2018/11/20 | 59 |
10 | c#3-03 | help@asiagroup.co.kr | 2015/08/05 | 2481 |
9 | C#3-02 | help@asiagroup.co.kr | 2015/01/12 | 3965 |
8 | C#3-01 | help@asiagroup.co.kr | 2014/11/05 | 4549 |
7 | C#2 | help@asiagroup.co.kr | 2014/10/23 | 3301 |
» | C#1 | help@asiagroup.co.kr | 2014/03/02 | 2382 |
5 | C#2 | help@asiagroup.co.kr | 2012/03/05 | 3396 |