2014년 12월 10일 수요일

닷넷,ADO.NET예제-2(오라클,C#주소록윈폼,ListVew,DataGrid,MDIForm응용예제소스)[실무기초닷넷/초보자닷넷교육/C#/ASP.NET/ADO.NET/.NET/C#한번배우세요]

닷넷,ADO.NET예제-2(오라클,C#주소록윈폼,ListVew,DataGrid,MDIForm응용예제소스)
 
 
: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 = new System.Windows.Forms.ListView();
                                                     this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
                                                     this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
                                                     this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
                                                     this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
                                                     this.btnRefresh = new System.Windows.Forms.Button();
                                                     this.btnSearch = new System.Windows.Forms.Button();
                                                     this.txtSearchName = new System.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 += new System.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 = new System.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 += new System.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 = new System.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 += new System.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 = new System.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 += new System.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 = new System.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 = new System.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(new System.Windows.Forms.ColumnHeader[] {
                                                                                                                                                                                                                                                                                                                                                                                                    this.columnHeader1,
                                                                                                                                                                                                                                                                                                                                                                                                    this.columnHeader2,
                                                                                                                                                                                                                                                                                                                                                                                                    this.columnHeader3,
                                                                                                                                                                                                                                                                                                                                                                                                    this.columnHeader4});
                                                     this.listView1.FullRowSelect = true;
                                                     this.listView1.GridLines = true;
                                                     this.listView1.Location = new System.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 += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
                                                     this.listView1.SelectedIndexChanged += new System.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 = new System.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 += new System.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 = new System.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 += new System.EventHandler(this.btnSearch_Click);
                                                     //
                                                     // txtSearchName
                                                     //
                                                     this.txtSearchName.AutoSize = false;
                                                     this.txtSearchName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                                                     this.txtSearchName.Font = new System.Drawing.Font("굴림", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(129)));
                                                     this.txtSearchName.Location = new System.Drawing.Point(24, 24);
                                                     this.txtSearchName.Name = "txtSearchName";
                                                     this.txtSearchName.Size = new System.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(new System.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 += new System.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 = new ListViewItem(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)       {
                                                                                        case Sorting.Ascending : columnsorter.sort = Sorting.Descending;
                                                                                                                             break;
                                                                                        case Sorting.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 = new System.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 += new System.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 = new AddrBook();
                                                                       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();
        }
                  }
}
 
 



 [100%환급,실무전문]빅데이터/SQL/자바/스프링/안드로이드/닷넷C… 오라클자바…12-272801
 [채용확정무료교육]오라클자바개발잘하는신입뽑기2개월과정,교육…오라클자바…12-112036
53 [평일100%환급7건]웹퍼블리싱,자바&JSP,안드로이드,C#닷넷,SQL기… 오라클자바…03-151854
52 [주말]C#,ASP.NET마스터 오라클자바…01-312012
51 [기업100%환급,평일주간]SQL기초에서스키마오브젝트,PLSQL,힌트… 오라클자바…01-312972
50 [주말주간]자바&웹,jQUERY,스프링프레임워크,마이바티스 오라클자바…01-311554
49 [평일주간/야간,주말주간/야간]Spring,MyBatis,Hibernate개발자… 오라클자바…01-191874
48 [평일주간/야간,주말주간/야간]안드로이드개발자과정(Adnroid 교… 오라클자바…01-111747
47 [평일야간,주말주간야간]JAVA,Network&JSP&Spring,MyBatis,Hiber… 오라클자바…01-032320
46 [100%환급,실무전문]빅데이터/SQL/자바/스프링/안드로이드/닷넷C… 오라클자바…12-272801
45 [주말야간]개발자를위한PLSQL,SQL튜닝,힌트(토/일) 오라클자바…12-191962
44 [평일주간/야간,주말주간/야간]웹퍼블리싱 마스터(HTML5,CSS3,jQ… 오라클자바…12-141944
43 [채용확정무료교육]오라클자바개발잘하는신입뽑기2개월과정,교육… 오라클자바…12-112036
42 [주말야간]JAVA,JSP,Spring,PLSQL,힌트,웹퍼블리싱,안드로이드,… 오라클자바…12-091583
41 [평일야간,주말야간]닷넷(C#,Network,ADO.NET,ASP.NET)마스터 오라클자바…12-011809
40 [기업100%환급]오라클&자바웹스프링신입과정3주(SQL,JAVA,JSP,Se… 오라클자바…12-012030
39 [평일야간,주말]SQL기초에서실무까지(SQL기초,PLSQL,힌트,튜닝) 오라클자바…12-011458

댓글 없음:

댓글 쓰기