C# 도서관리 프로그램

2012. 12. 15. 17:032010년/C#.NET

C#으로 만드는 도서관리 프로그램


booknum =  책번호

bookname = 책이름

bookwriter =저자

publisher = 출판사

price = 가격

pubDate = 출판일


지금까지는 텍스트 검색기능만 추가시켰다 근데.. 기존 DB에 저장된것들을 찾기위해서는  힘들다


using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.OleDb;


namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

           

        }

        

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        {

            


        }


        private void btnSelect_Click(object sender, EventArgs e)

        {

            listView1.View = View.Details;

            listView1.Items.Clear();

            string sql = "Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=soullex;Persist Security Info=True";     //oracle 서버 연결

            string comboText = "";

            switch (this.comboBox1.SelectedIndex)

            {


                case 0:

                    comboText = "booknum";

                    break;

                case 1:

                    comboText = "bookname";

                    break;

                case 2:

                    comboText = "bookwriter";

                    break;

                case 3:

                    comboText = "publisher";

                    break;



            }

            OleDbConnection conn = new OleDbConnection(sql);

           


            try

            {


                conn.Open();            //데이터베이스 연결



                MessageBox.Show("데이터베이스연결");


           


            OleDbCommand cmd = new OleDbCommand();

            if (selectTextbox.Text.ToString() == "")

            {

                cmd.CommandText = "select * from BookManager";   //테이블 형태 

            }

            else

                cmd.CommandText = "select * from BookManager where " + comboText + "=" + selectTextbox.Text.ToString();   //테이블 형태 

              

                cmd.CommandType = CommandType.Text;         //검색명령을 쿼리 형태로


                cmd.Connection = conn;

                OleDbDataReader read = cmd.ExecuteReader();

                if (read.HasRows)

                {

                    while (read.Read())

                    {

                        string booknum = read["booknum"].ToString();

                        string bookname = read["bookname"].ToString();

                        string bookwriter = read["bookwriter"].ToString();

                        string publisher = read["publisher"].ToString();

                        string price = read["price"].ToString();

                        string pubdate = read["pubdate"].ToString();


                        ListViewItem lv = this.listView1.Items.Add(booknum);

                        lv.SubItems.Add(bookname);

                        lv.SubItems.Add(bookwriter);

                        lv.SubItems.Add(publisher);

                        lv.SubItems.Add(price);

                        lv.SubItems.Add(pubdate);



                    }

                }

                else

                {

                    MessageBox.Show("검색한파일을 찾을수 없습니다");

                }

                read.Close();

            }


            catch (Exception ex)

            {


                MessageBox.Show("에러발생{0}", ex.Message);


            }

            

        }


        private void Form1_Load(object sender, EventArgs e)

        {

            comboBox1.Items.Add("책번호");

            comboBox1.Items.Add("책이름");

            comboBox1.Items.Add("저자");

            comboBox1.Items.Add("출판사");

            comboBox1.Text = "책번호";



         


        }


    }

}




'2010년 > C#.NET' 카테고리의 다른 글

Delegate의 이해  (0) 2012.12.15
C# Oracle 연결및 확인  (0) 2012.12.15