.NET Logo
Welcome Guest Search | Active Topics | Members | Log In | Register

Error ช่วยดูหน่อยคับ Options · View
benzraksa
Posted: Monday, October 06, 2008 6:49:37 PM
Rank: มือฝึกหัด
Groups: Member

Joined: 10/4/2008
Posts: 4
Location: BKK

โค้ดนี้ผมเขียนตามหนังสือแต่เกิด error จะมีวิธีแก้ไขอย่างไรคับ

error:

The type or namespace name 'connDatabase' could not be found(are you missing a using directive or an assembly reference?)

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace BOOKSHOP
{
    public partial class frmBookShop : Form
    {
        enum State { None, Add, Modify, Delete }
        connDatabase cnnBase = new connDatabase();
        private OleDbDataAdapter adapter;
        private DataSet ds;
        private int current_pos;
        private int row_count;
        private State state = 0;
        private int sumStock;
        private int stock;
        private string checkID;
       
        public frmBookShop()
        {
            InitializeComponent();
        }

        private void addStock(int stockIn)
        {
            stockIn = Convert.ToInt32(txtOrderIN.Text);
            sumStock = stock + stockIn;
        }
        private void showCombo()
        {
            cnnBase.SelectDatabase(@"C:\dbBook.mdb");
            cnnBase.Open();
            adapter = cnnBase.ExeCuteQuery("SELECT * FROM tblBookType order by bookTypeID");
            ds = new DataSet();
            adapter.Fill(ds, "tblBookType");
            cnbTypeBook.DataSource = ds.Tables["tblBookType"];
            cnbTypeBook.DisplayMember = "bookTypeName";
            cnbTypeBook.ValueMember = "bookTypeID";
        }

        private void loadDtabase()
        {
            cnnBase.SelectDatabase(@"C:\dbBook.mdb");
            cnnBase.Open();
            adapter = cnnBase.ExecuteQuery("SELECT * FROM tblBookInfo order by bookID");
            ds = new DataSet();
            adapter.Fill(ds, "tblBookInfo");
            dataGridView2.DataSource = ds;
            dataGridView2.DataMember = "tblBookInfo";
        }

        private void loadData(int position)
        {
            txtIDBook.ReadOnly = true;
            txtNameBook.ReadOnly = true;
            cnbTypeBook.Enabled = false;
            txtWriter.ReadOnly = true;
            txtOffice.ReadOnly = true;
            txtCost.ReadOnly = true;
            txtPointOrder.ReadOnly = true;
            txtInStock.ReadOnly = true;
            txtOrderIN.ReadOnly = true;
            if (position > this.BindingContext[ds, "tblBookInfo"].Count - 1)
            {
                current_pos = this.BindingContext[ds, "tblBookInfo"].Count - 1;
                position = this.BindingContext[ds, "tblBookInfo"].Count - 1;
            }
            if (position < 0)
            {
                tsTxtPageNum.Text = "No Record";
                tsBDelete.Enabled = false;
                tsBEdit.Enabled = false;
                txtIDBook.Text = "";
                txtNameBook.Text = "";
                cnbTypeBook.Text = "";
                txtWriter.Text = "";
                txtOffice.Text = "";
                txtCost.Text = "";
                txtPointOrder.Text = "";
                txtInStock.Text = "";
                txtOrderIN.Text = "";
                return;
            }
            checkID = ds.Tables["tblBookInfo"].Rows[position][0].ToString();
            txtIDBook.Text = ds.Tables["tblBookInfo"].Rows[position][0].ToString();
            cnbTypeBook.Text = ds.Tables["tblBookInfo"].Rows[position][1].ToString();
            txtNameBook.Text = ds.Tables["tblBookInfo"].Rows[position][2].ToString();
            txtWriter.Text = ds.Tables["tblBookInfo"].Rows[position][3].ToString();
            txtOffice.Text = ds.Tables["tblBookInfo"].Rows[position][4].ToString();
            txtCost.Text = ds.Tables["tblBookInfo"].Rows[position][5].ToString();
            txtInStock.Text = ds.Tables["tblBookInfo"].Rows[position][6].ToString();
            stock = Convert.ToInt32(ds.Tables["tblBookInfo"].Rows[position][6].ToString());
            txtPointOrder.Text=ds.Tables["tblBookInfo"].Rows[position][7].ToString();
            row_count = this.BindingContext[ds,"tblBookInfo"].Count;
            if (current_pos >= row_count - 1)
            {
                tsBMoveNext.Enabled = false;
                tsBMoveFirst.Enabled = false;
            }
            else
            {
                tsBMoveNext.Enabled = true;
                tsBMoveFirst.Enabled = true;
            }
            if (current_pos <= 0)
            {
                tsBMovePrevious.Enabled = false;
                tsBMoveLast.Enabled = false;
            }
            else
            {
                tsBMovePrevious.Enabled = true;
                tsBMoveLast.Enabled = true;
            }
            tsBAdd.Enabled = true;
            tsBEdit.Enabled = true;
            tsBDelete.Enabled = true;
            tsBCancel.Enabled = false;
            this.BindingContext[ds, "tblBookInfo"].Position = position;
            tsTxtPageNum.Text = Convert.ToString(current_pos + 1);
        }
       
        private void frmBookShop_Load(object sender, EventArgs e)
        {
            showCombo();
            loadDtabase();
            current_pos = this.BindingContext[ds, "tblBookInfo"].Count;
            tsTxtPageNum.Text = "of{" + current_pos + "}";                //tsTxtPageSum.Text = "of{" + current_pos + "}";
            current_pos = this.BindingContext[ds, "tblBookInfo"].Position;
            loadData(current_pos);
        }

        private void tsBMoveNext_Click(object sender, EventArgs e)
        {
            if (state != State.None)
                return;
            this.BindingContext[ds, "tblBookInfo"].Position = this.BindingContext[ds, "tblBookInfo"].Position + 1;
            current_pos = this.BindingContext[ds, "tblBookInfo"].Position;
            loadData(current_pos);
        }

        private void tsBMoveFirst_Click(object sender, EventArgs e)
        {
            if (state != State.None)
                return;
            this.BindingContext[ds, "tblBookInfo"].Position = this.BindingContext[ds, "tblBookInfo"].Count - 1;
            current_pos = this.BindingContext[ds, "tblBookInfo"].Position;
            loadData(current_pos);
        }

        private void tsBMovePrevious_Click(object sender, EventArgs e)
        {
            if (state != State.None)
                return;
            this.BindingContext[ds, "tblBookInfo"].Position = this.BindingContext[ds, "tblBookInfo"].Position - 1;
            current_pos = this.BindingContext[ds, "tblBookInfo"].Position;
            loadData(current_pos);
        }

        private void tsBMoveLast_Click(object sender, EventArgs e)
        {
            if (state != State.None)
                return;
            this.BindingContext[ds, "tblBookInfo"].Position = 0;
            current_pos = this.BindingContext[ds, "tblBookInfo"].Position;
            loadData(current_pos);
        }

        private void tsBAdd_Click(object sender, EventArgs e)
        {
            if (state == State.None)
            {
                state = State.Add;
                tsBAdd.Text = "&Save";
                txtIDBook.ReadOnly = false;
                txtNameBook.ReadOnly = false;
                cnbTypeBook.Enabled = false;
                txtWriter.ReadOnly = false;
                txtOffice.ReadOnly = false;
                txtCost.ReadOnly = false;
                txtPointOrder.ReadOnly = false;
                txtInStock.ReadOnly = false;
                txtOrderIN.ReadOnly = false;
                txtIDBook.Text = "";
                txtNameBook.Text = "";
                cnbTypeBook.Text = "";
                txtWriter.Text = "";
                txtOffice.Text = "";
                txtCost.Text = "";
                txtPointOrder.Text = "";
                txtInStock.Text = "";
                txtInStock.Enabled = false;
                txtOrderIN.Text = "";
                tsBEdit.Enabled = false;
                tsBOrderIN.Enabled = false;
                tsBDelete.Enabled = false;
                tsBCancel.Enabled = true;
            }
            else
            {
                if (txtIDBook.Text == "" || txtNameBook.Text == "" || cnbTypeBook.Text == "" ||
                    txtWriter.Text == "" || txtOffice.Text == "" || txtCost.Text == "" ||
                    txtOrderIN.Text == "" || txtPointOrder == "")
                {
                    if (MessageBox.Show("กรุณากรอกข้อมูลให้ครบ", "แจ้งเตือน", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)==DialogResult.OK)
                    {
                        return;
                    }
                }
                string db = "INSERT INTO tblBookInfo VALUES(";
                db += txtIDBook.Text + "," + cnbTypeBook.SelectedValue + ",";
                db += txtNameBook.Text + "," + txtWriter.Text + ",";
                db += txtOffice.Text + "," + txtCost.Text + ",";
                db += txtOrderIN.Text + "," + txtPointOrder.Text + ");";
                cnnBase.ExecuteNonQuery(db);
                txtIDBook.ReadOnly = true;
                txtNameBook.ReadOnly = true;
                cnbTypeBook.Enabled = false;
                txtWriter.ReadOnly = true;
                txtOffice.ReadOnly = true;
                txtCost.ReadOnly = true;
                txtPointOrder.ReadOnly = true;
                txtInStock.Text = txtOrderIN.Text;
                txtInStock.ReadOnly = true;
                loadData();
                current_pos = this.BindingContext[ds, "tblBookInfo"].Count;
                tsTxtPageNum.Text = "of{" + current_pos + "}";
                loadData(current_pos);
                tsBCancel.Enabled = false;
                state = State.None;
                txtOrderIN.ReadOnly = true;
                txtOrderIN.Text = "";
                tsBAdd.Text = "&Add";
                tsBOrderIN.Enabled = true;
            }
        }

        private void tsBEdit_Click(object sender, EventArgs e)
        {
            if (state == State.None)
            {
                tsBAdd.Enabled = false;
                tsBEdit.Enabled = true;
                tsBDelete.Enabled = false;
                tsBOrderIN.Enabled = false;
                tsBCancel.Enabled = true;
                txtIDBook.ReadOnly = true;
                txtNameBook.ReadOnly = false;
                cnbTypeBook.Enabled = true;
                txtWriter.ReadOnly = false;
                txtOffice.ReadOnly = false;
                txtCost.ReadOnly = false;
                txtPointOrder.ReadOnly = false;
                txtInStock.ReadOnly = false;
                txtOrderIN.ReadOnly = true;
                tsBEdit.Text = "Update";
                state = State.Modify;
            }
            else
            {
                tsBAdd.Enabled = true;
                tsBEdit.Enabled = true;
                tsBDelete.Enabled = true;
                tsBOrderIN.Enabled = true;
                tsBCancel.Enabled = false;
                txtIDBook.ReadOnly = true;
                txtNameBook.ReadOnly = true;
                cnbTypeBook.Enabled = false;
                txtWriter.ReadOnly = true;
                txtOffice.ReadOnly = true;
                txtCost.ReadOnly = true;
                txtPointOrder.ReadOnly = true;
                txtInStock.ReadOnly = true;
                txtOrderIN.ReadOnly = true;
                string db = "Update tblBookInfo SET bookID =" + txtIDBook.Text + ",";
                db += "bookTypeID =" + cnbTypeBook.Text + ",";
                db += "bookName =" + txtNameBook.Text + ",";
                db += "authorName =" + txtWriter.Text + ",";
                db += "office =" + txtOffice.Text + ",";
                db += "UnitPrice ="+txtCost.Text+",";
                db += "UniislnStock ="+txtInStock.Text+",";
                db += "WHERE bookID =" + txtIDBook.Text + ";";
                cnnBase.ExecuteNonQuery(db);
                loadDtabase();
                loadData(current_pos);
                tsBEdit.Text = "Edit";
                state = State.None;
            }
        }

        private void tsBDelete_Click(object sender, EventArgs e)
        {
            cnnBase.ExecuteNonQuery("DELETE FROM tblBookInfo WHERE bookID="+txtIDBook.Text+"");
            loadDtabase();
            loadData(current_pos);
            current_pos = this.BindingContext[ds, "tblBookInfo"].Count;
            tsTxtPageNum.Text = "of{" + current_pos + "}";
            tsBMoveFirst_Click(sender, e);
        }

        private void tsBCancel_Click(object sender, EventArgs e)
        {
            switch (state)
            {
                case State.Add:
                    tsBAdd.Text = "Add";
                    txtIDBook.ReadOnly = true;
                    txtNameBook.ReadOnly = true;
                    cnbTypeBook.Enabled = false;
                    txtWriter.ReadOnly = true;
                    txtOffice.ReadOnly = true;
                    txtCost.ReadOnly = true;
                    txtPointOrder.ReadOnly = true;
                    txtInStock.ReadOnly = true;
                    txtOrderIN.ReadOnly = true;
                    loadData(current_pos);
                    break;
                case State.Modify:
                    tsBEdit.Text = "Edit";
                    tsBOrderIN.Text = "จัดเพิ่มหนังสือในคลังสินค้า";
                    txtIDBook.ReadOnly = true;
                    txtNameBook.ReadOnly = true;
                    cnbTypeBook.Enabled = false;
                    txtWriter.ReadOnly = true;
                    txtOffice.ReadOnly = true;
                    txtCost.ReadOnly = true;
                    txtPointOrder.ReadOnly = true;
                    txtInStock.ReadOnly = true;
                    txtOrderIN.ReadOnly = true;
                    loadData(current_pos);
                    break;
                case State.Delete:
                    break;
                default:
                    break;
            }
            state = State.None;
            tsBCancel.Enabled = false;
            tsBOrderIN.Enabled = true;
            txtOrderIN.Text = "";
        }

        private void tsBOrderIN_Click(object sender, EventArgs e)
        {
            if (state == State.None)
            {
                tsBAdd.Enabled = false;
                tsBEdit.Enabled = false;
                tsBDelete.Enabled = false;
                tsBOrderIN.Enabled = true;
                tsBCancel.Enabled = true;
                txtIDBook.ReadOnly = true;
                txtNameBook.ReadOnly = true;
                cnbTypeBook.Enabled = false;
                txtWriter.ReadOnly = true;
                txtOffice.ReadOnly = true;
                txtCost.ReadOnly = true;
                txtPointOrder.ReadOnly = true;
                txtInStock.ReadOnly = true;
                txtOrderIN.ReadOnly = false;
                tsBOrderIN.Text = "รับสินค้าเข้าในคลัง";
                state = State.Modify;
            }
            else
            {
                tsBAdd.Enabled = true;
                tsBEdit.Enabled = true;
                tsBOrderIN.Enabled = true;
                tsBDelete.Enabled = true;
                tsBCancel.Enabled = false;
                txtIDBook.ReadOnly = false;
                txtNameBook.ReadOnly = false;
                cnbTypeBook.Enabled = true;
                txtWriter.ReadOnly = false;
                txtOffice.ReadOnly = false;
                txtCost.ReadOnly = false;
                txtPointOrder.ReadOnly = false;
                txtInStock.ReadOnly = false;
                txtOrderIN.ReadOnly = false;
                addStock(sumStock);
                string db = "UPDATE tblBookInfo SET bookID =" + txtIDBook.Text + ",";
                db += "bookTypeID = " + cnbTypeBook.Text + ",bookName =" + txtNameBook.Text + ",";
                db += "authorName =" + txtWriter.Text + ",office =" + txtOffice.Text + ",";
                db += "Uniprice =" + txtCost.Text + ",UnitsInStock =" + sumStock + "WHERE bookID =" + txtIDBook.Text + ";";
                cnnBase.ExecuteNonQuery(db);
                loadDtabase();
                loadData(current_pos);
                txtOrderIN.Enabled = false;
                tsBOrderIN.Text = "จัดเพิ่มหนังสือในคลังสินค้า";
                state = State.None;
                txtOrderIN.Enabled = true;
                txtOrderIN.Text = "";
            }
        }
    }
}

File Attachment(s):
BOOKSHOP.rar (22kb) downloaded 2 time(s).


abcomp01
Posted: Monday, October 06, 2008 7:30:54 PM

Rank: มือพระกาฬ
Groups: Member

Joined: 4/22/2008
Posts: 18
Location: thailand

'connDatabase' ไม่ทราบมีคลาสนี้ไหมอะคัฟ

ว่ากันไป

Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.


Sponsored by