닷넷,ADO.NET예제-2(오라클,C#주소록윈폼,ListVew,DataGrid,MDIForm응용예제소스)
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
9. AddrBook.cs(ListView를 이용한 CRUD화면)
using System;
using System.Data.OleDb;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace 주소록
{
/// <summary>
/// Form1에 대한 요약 설명입니다.
/// </summary>
public class AddrBook : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.Button btnInput;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.Button btnDelete;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtAddr;
private System.Windows.Forms.TextBox txtTel;
private System.Windows.Forms.ComboBox comSex;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.TextBox txtSearchName;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.Container components = null;
public AddrBook()
{
//
// 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 Designer generated code
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.btnNew = new System.Windows.Forms.Button();
this.btnInput = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
this.btnDelete = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.txtAddr = new System.Windows.Forms.TextBox();
this.txtTel = new System.Windows.Forms.TextBox();
this.comSex = new System.Windows.Forms.ComboBox();
this.listView1 = newSystem.Windows.Forms.ListView();
this.columnHeader1 = newSystem.Windows.Forms.ColumnHeader();
this.columnHeader2 = newSystem.Windows.Forms.ColumnHeader();
this.columnHeader3 = newSystem.Windows.Forms.ColumnHeader();
this.columnHeader4 = newSystem.Windows.Forms.ColumnHeader();
this.btnRefresh = new System.Windows.Forms.Button();
this.btnSearch = new System.Windows.Forms.Button();
this.txtSearchName = newSystem.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnNew
//
this.btnNew.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnNew.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnNew.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnNew.Location = new System.Drawing.Point(328, 24);
this.btnNew.Name = "btnNew";
this.btnNew.Size = new System.Drawing.Size(56, 24);
this.btnNew.TabIndex = 0;
this.btnNew.Text = "신규";
this.btnNew.Click += newSystem.EventHandler(this.btnNew_Click);
//
// btnInput
//
this.btnInput.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnInput.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnInput.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnInput.Location = newSystem.Drawing.Point(383, 24);
this.btnInput.Name = "btnInput";
this.btnInput.Size = new System.Drawing.Size(56, 24);
this.btnInput.TabIndex = 1;
this.btnInput.Text = "입력";
this.btnInput.Click += newSystem.EventHandler(this.btnInput_Click);
//
// btnUpdate
//
this.btnUpdate.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnUpdate.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnUpdate.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnUpdate.Location = newSystem.Drawing.Point(438, 24);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Size = new System.Drawing.Size(56, 24);
this.btnUpdate.TabIndex = 2;
this.btnUpdate.Text = "수정";
this.btnUpdate.Click += newSystem.EventHandler(this.btnUpdate_Click);
//
// btnDelete
//
this.btnDelete.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnDelete.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDelete.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnDelete.Location = newSystem.Drawing.Point(493, 24);
this.btnDelete.Name = "btnDelete";
this.btnDelete.Size = new System.Drawing.Size(56, 24);
this.btnDelete.TabIndex = 3;
this.btnDelete.Text = "삭제";
this.btnDelete.Click += newSystem.EventHandler(this.btnDelete_Click);
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label1.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label1.Location = new System.Drawing.Point(24, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 24);
this.label1.TabIndex = 4;
this.label1.Text = "성 명";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label2.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label2.Location = new System.Drawing.Point(278, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 24);
this.label2.TabIndex = 5;
this.label2.Text = "성 별";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label3.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label3.Location = new System.Drawing.Point(24, 87);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 24);
this.label3.TabIndex = 6;
this.label3.Text = "주 소";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label4.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.label4.Location = new System.Drawing.Point(278, 87);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 24);
this.label4.TabIndex = 7;
this.label4.Text = "전화번호";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtName
//
this.txtName.AutoSize = false;
this.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtName.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.txtName.Location = newSystem.Drawing.Point(103, 64);
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(176, 24);
this.txtName.TabIndex = 8;
this.txtName.Text = "";
//
// txtAddr
//
this.txtAddr.AutoSize = false;
this.txtAddr.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtAddr.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.txtAddr.Location = newSystem.Drawing.Point(103, 87);
this.txtAddr.Name = "txtAddr";
this.txtAddr.Size = new System.Drawing.Size(176, 24);
this.txtAddr.TabIndex = 9;
this.txtAddr.Text = "";
//
// txtTel
//
this.txtTel.AutoSize = false;
this.txtTel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtTel.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.txtTel.Location = new System.Drawing.Point(357, 87);
this.txtTel.Name = "txtTel";
this.txtTel.Size = new System.Drawing.Size(200, 24);
this.txtTel.TabIndex = 10;
this.txtTel.Text = "";
//
// comSex
//
this.comSex.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comSex.Location = new System.Drawing.Point(357, 64);
this.comSex.Name = "comSex";
this.comSex.Size = new System.Drawing.Size(200, 23);
this.comSex.TabIndex = 11;
//
// listView1
//
this.listView1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.listView1.Columns.AddRange(newSystem.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.listView1.FullRowSelect = true;
this.listView1.GridLines = true;
this.listView1.Location = newSystem.Drawing.Point(24, 120);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(536, 200);
this.listView1.TabIndex = 12;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.ColumnClick += newSystem.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
this.listView1.SelectedIndexChanged += newSystem.EventHandler(this.listView1_SelectedIndexChanged);
//
// columnHeader1
//
this.columnHeader1.Text = " 성 명";
this.columnHeader1.Width = 100;
//
// columnHeader2
//
this.columnHeader2.Text = "성 별";
this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader2.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Text = "주 소";
this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader3.Width = 220;
//
// columnHeader4
//
this.columnHeader4.Text = "전화번호";
this.columnHeader4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.columnHeader4.Width = 100;
//
// btnRefresh
//
this.btnRefresh.BackColor = System.Drawing.SystemColors.Info;
this.btnRefresh.Cursor = System.Windows.Forms.Cursors.PanWest;
this.btnRefresh.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnRefresh.Font = new System.Drawing.Font("굴림", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnRefresh.Location = newSystem.Drawing.Point(249, 24);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(80, 24);
this.btnRefresh.TabIndex = 13;
this.btnRefresh.Text = "Refresh";
this.btnRefresh.Click += newSystem.EventHandler(this.btnRefresh_Click);
//
// btnSearch
//
this.btnSearch.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.btnSearch.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.btnSearch.Location = newSystem.Drawing.Point(135, 24);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(72, 26);
this.btnSearch.TabIndex = 49;
this.btnSearch.Text = "검색";
this.btnSearch.Click += newSystem.EventHandler(this.btnSearch_Click);
//
// txtSearchName
//
this.txtSearchName.AutoSize = false;
this.txtSearchName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtSearchName.Font = newSystem.Drawing.Font("굴림", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.txtSearchName.Location = newSystem.Drawing.Point(24, 24);
this.txtSearchName.Name = "txtSearchName";
this.txtSearchName.Size = newSystem.Drawing.Size(112, 26);
this.txtSearchName.TabIndex = 48;
this.txtSearchName.Text = "";
//
// AddrBook
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(576, 325);
this.Controls.AddRange(newSystem.Windows.Forms.Control[] {
this.btnSearch,
this.txtSearchName,
this.btnRefresh,
this.listView1,
this.comSex,
this.txtTel,
this.txtAddr,
this.txtName,
this.label4,
this.label3,
this.label2,
this.label1,
this.btnDelete,
this.btnUpdate,
this.btnInput,
this.btnNew});
this.Font = new System.Drawing.Font("굴림", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
this.Name = "AddrBook";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += newSystem.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
private OleDbConnection LocalConn;
//--------------------------------------------------------
//
// Desc : 메인화면 로딩시 처리되는 부분
// :
// Param :
// Modify:
// :
//--------------------------------------------------------
private void Form1_Load(object sender, System.EventArgs e)
{
OleDbDataReader myReader = null;
try
{
//--------------------------------------------
LocalConn =Common_DB.DBConnection();
//--------------------------------------------
LocalConn.Open();
myReader =Common_DB.DataSelect("select * from AddrBook ",LocalConn);
DataLoad(myReader);
//Combo Box 채우기
comSex.Items.Add("남자");
comSex.Items.Add("여자");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,"AddrBook Form Loading");
}
finally
{
if (!myReader.IsClosed)
{
myReader.Close();
myReader = null;
}
LocalConn.Close();
}
}
//**************************************************************
//
// ListView에 성명 데이터 전체를 로드하는 함수
//
//
//**************************************************************
private void DataLoad(OleDbDataReader myDataReader)
{
listView1.Items.Clear();
while(myDataReader.Read())
{
ListViewItem myitem1;
string gubun;
if(myDataReader["Sex"].ToString()=="M")
{
gubun = "남자";
}
else
{
gubun = "여자";
}
myitem1 = newListViewItem(myDataReader["Name"].ToString());
myitem1.SubItems.Add(gubun);
//myitem1.SubItems.Add(myDataReader["Addr"].ToString());
//주소가 null 값을 리턴하면...
if(myDataReader.IsDBNull(2))
{
myitem1.SubItems.Add("");
}
else
{
myitem1.SubItems.Add(myDataReader["Addr"].ToString());
}
myitem1.SubItems.Add(myDataReader["Tel"].ToString());
listView1.Items.Add(myitem1);
}
myDataReader.Close();
}
//-----------------------------------------------------------
// 신규 버튼
//-----------------------------------------------------------
private void btnNew_Click(object sender, System.EventArgs e)
{
this.txtName.Clear();
this.txtAddr.Clear();
this.txtTel.Clear();
this.comSex.Text = "남자";
this.txtName.Focus();
}
//-------------------------------------------------------------
// 입력 버튼
//-------------------------------------------------------------
private void btnInput_Click(object sender, System.EventArgs e)
{
if(txtName.Text=="" || txtTel.Text=="")
{
MessageBox.Show("성명, 전화번호는필수 입력사항 입니다.");
txtName.Focus();
return;
}
string gubun;
if (comSex.Text=="남자") { gubun="M"; }
else { gubun="F"; }
LocalConn.Open();
string sql = "Insert Into AddrBook (Name, Sex, Addr, Tel) values(";
sql += "'" + txtName.Text+"'"+",";
sql += "'" + gubun+"'"+",";
sql += "'"+ txtAddr.Text + "'" + ",";
sql += "'"+ txtTel.Text + "'" + ")";
if (Common_DB.DataManupulation(sql, LocalConn))
{
OleDbDataReader myReader =Common_DB.DataSelect("select * from AddrBook",LocalConn);
DataLoad(myReader);
Log.WriteLine("AddrBook","데이터 한건 입력(" + txtName + "," + txtTel + ")");
MessageBox.Show("정상적으로 입력되었습니다...");
}
LocalConn.Close();
}
//**************************************************************
//
// 수정 버튼 클릭시 DB에 Update 하는 부분
//
//
//**************************************************************
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if(txtName.Text==""|| txtTel.Text=="")
{
MessageBox.Show("성명, 전화번호는필수 입력사항 입니다.");
txtName.Focus();
return;
}
string gubun;
if (comSex.Text=="남자")
{
gubun="M";
}
else
{
gubun="F";
}
LocalConn.Open();
string myExecuteQuery = "Update AddrBook set Name='"+ txtName.Text + "'" + ",";
myExecuteQuery += " Addr = '" + txtAddr.Text + "'" +",";
myExecuteQuery += " Sex = '" + gubun + "'" + ",";
myExecuteQuery += " Tel = '" + txtTel.Text + "'" ;
myExecuteQuery += " where Name = " + "'" + txtName.Text + "'";
if (Common_DB.DataManupulation(myExecuteQuery, LocalConn))
{
OleDbDataReader myReader =Common_DB.DataSelect("select * from AddrBook",LocalConn);
DataLoad(myReader);
MessageBox.Show(" 정상적으로 수정되었습니다...");
}
LocalConn.Close();
}
//**************************************************************
//
//
// 삭제 버튼클릭시 DB의 자료를 Delete
//
//
//**************************************************************
private void btnDelete_Click(object sender, System.EventArgs e)
{
OleDbDataReader myReader=null;
if(txtName.Text==""|| txtTel.Text=="")
{
MessageBox.Show("성명, 전화번호는필수 입력사항 입니다.");
txtName.Focus();
return;
}
//-------------------------------- 삭제 확인
if (MessageBox.Show ("정말 삭제 하시겠습니까?", "삭제확인",
MessageBoxButtons.YesNo,MessageBoxIcon.Question)
!= DialogResult.Yes)
{
return;
}
LocalConn.Open();
string myExecuteQuery = "Delete AddrBook ";
myExecuteQuery += " where Name = " + "'" + txtName.Text + "'";
if (Common_DB.DataManupulation(myExecuteQuery, LocalConn))
{
myReader =Common_DB.DataSelect("select * from AddrBook",LocalConn);
DataLoad(myReader);
MessageBox.Show(" 정상적으로 삭제되었습니다...");
}
LocalConn.Close();
}
//-----------------------------------------------------------
// ListView에서 클릭시 데이를 보여줌
//-----------------------------------------------------------
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
txtName.Text = listView1.SelectedItems[0].SubItems[0].Text;
comSex.Text = listView1.SelectedItems[0].SubItems[1].Text;
txtAddr.Text = listView1.SelectedItems[0].SubItems[2].Text;
txtTel.Text = listView1.SelectedItems[0].SubItems[3].Text;
}
catch(Exception)
{
//MessageBox.Show(ex.Message, "listView1_SelectedIndexChanged");
}
}
//------------------------------------------------------
// Refresh
//------------------------------------------------------
private void btnRefresh_Click(object sender, System.EventArgs e)
{
LocalConn.Open();
OleDbDataReader myReader =Common_DB.DataSelect("select * from AddrBook",LocalConn);
DataLoad(myReader);
LocalConn.Close();
}
//------------------------------------------------------------
// 검색 버튼
//------------------------------------------------------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
LocalConn.Open();
string sql = "select * from AddrBook ";
sql += " where name like '%" + txtSearchName.Text +"%'";
OleDbDataReader myReader =Common_DB.DataSelect(sql,LocalConn);
if (myReader != null)
{
DataLoad(myReader);
myReader.Close();
}
LocalConn.Close();
}
//-----------------------------------------------------------------
// ListView의 헤더를 클릭시 정렬
//-----------------------------------------------------------------
ColumnSorter columnsorter = new ColumnSorter();
private int flag = 0;
private void listView1_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
{
columnsorter.currentColumn = e.Column;
//전에 선택한 컬럼과 다르면 우선 오름차순 정렬
if (columnsorter.previousColumn != columnsorter.currentColumn) {
columnsorter.sort =Sorting.Ascending;
}
else { //이전에 손택한 컬럼과 같을때 ...
switch(columnsorter.sort) {
caseSorting.Ascending : columnsorter.sort = Sorting.Descending;
break;
caseSorting.Descending :columnsorter.sort = Sorting.Ascending;
break;
}
}
if (flag == 0) {
//자동으로 listView1.Sort 함수 수행
listView1.ListViewItemSorter = columnsorter;
flag = 1;
}
else {
listView1.Sort();
}
//현재 선택한 컬럼을 기억
columnsorter.previousColumn = columnsorter.currentColumn;
return;
}
}
}
10. MDIMain.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace 주소록
{
/// <summary>
/// MDIMain에 대한 요약 설명입니다.
/// </summary>
public class MDIMain : 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.TreeView treeView1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.MenuItem menuItem7;
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
///
[STAThread]
static void Main()
{
Application.Run(new MDIMain());
}
private System.ComponentModel.IContainer components;
public MDIMain()
{
//
// 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 Designer generated code
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마십시오.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = newSystem.ComponentModel.ComponentResourceManager(typeof(MDIMain));
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem7 = 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.treeView1 = new System.Windows.Forms.TreeView();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem2});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem7});
this.menuItem1.Text = "File";
//
// menuItem7
//
this.menuItem7.Index = 0;
this.menuItem7.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menuItem7.Text = "Exit";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem2
//
this.menuItem2.Index = 1;
this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4,
this.menuItem5});
this.menuItem2.Text = "주소록";
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.Text = "ListView이용";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.Text = "DataGrid이용";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 2;
this.menuItem5.Text = "-";
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
this.treeView1.ImageIndex = 0;
this.treeView1.ImageList = this.imageList1;
this.treeView1.Location = new System.Drawing.Point(0, 0);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = 0;
this.treeView1.Size = new System.Drawing.Size(144, 497);
this.treeView1.TabIndex = 1;
this.treeView1.AfterSelect += newSystem.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "");
this.imageList1.Images.SetKeyName(1, "");
//
// MDIMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 497);
this.Controls.Add(this.treeView1);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "MDIMain";
this.Text = "MDIMain";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.MDIMain_Load);
this.ResumeLayout(false);
}
#endregion
private void MDIMain_Load(object sender, System.EventArgs e)
{
TreeNode node1 = new TreeNode("화일");
node1.Tag = 1;
node1.ImageIndex = 0;
node1.SelectedImageIndex= 0;
node1.Expand();
TreeNode node11 = new TreeNode("Exit");
node11.ImageIndex = 1;
node11.SelectedImageIndex= 1;
node11.Tag = 11;
node1.Nodes.Add(node11);
//-------------------------------------
TreeNode node2 = new TreeNode("주소록");
node2.ImageIndex = 0;
node2.SelectedImageIndex= 0;
node2.Tag = 2;
node2.Expand();
TreeNode node21 = new TreeNode("ListView이용");
node21.ImageIndex = 1;
node21.SelectedImageIndex= 1;
node21.Tag = 21;
TreeNode node22 = new TreeNode("DataGrid이용");
node22.ImageIndex = 1;
node22.SelectedImageIndex= 1;
node22.Tag = 22;
node2.Nodes.Add(node21);
node2.Nodes.Add(node22);
treeView1.Nodes.Add(node1);
treeView1.Nodes.Add(node2);
}
//-------------------------------------------
// DataGird를 이용한 주소록
//-------------------------------------------
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
FrmGrid frmgrid = new FrmGrid();
frmgrid.MdiParent = this;
frmgrid.Show();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
//-------------------------------------------
//ListView를 이용한 주소록
//-------------------------------------------
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
AddrBook addrbook = new AddrBook();
addrbook.MdiParent = this;
addrbook.Show();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
//-------------------------------------------
// TreeView에서 선택 시...
//-------------------------------------------
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
TreeNode trnode = new TreeNode();
trnode = e.Node;
//EXIT
if (trnode.Tag.ToString() == "11")
{
Application.Exit();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
//ListView를 이용
if (trnode.Tag.ToString() == "21")
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
AddrBook addrbook = newAddrBook();
addrbook.MdiParent = this;
addrbook.Show();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
//DataGrid 이용
else if (trnode.Tag.ToString() == "22")
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
FrmGrid frmgrid = new FrmGrid();
frmgrid.MdiParent = this;
frmgrid.Show();
this.Cursor = System.Windows.Forms.Cursors.Default;
}
}
private void menuItem7_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
댓글 없음:
댓글 쓰기