3. Tạo lớp khai báo dữ liệu
- Tạo thư mục Entities (Bấm phải chuột vào dự án và chọn lệnh
Add Folder)
- Khai báo lớp Book
Dạng Class Library, trong thư mục Entities (file book.cs), nội
dung coding:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Data;
namespace BookShop.Entities
{
class Book
{
private
int _bookID;
public int BookID
{
get
{ return _bookID; }
set
{ _bookID = value; }
}
private
string _bookName;
public string BookName
{
get
{ return _bookName; }
set
{ _bookName = value; }
}
private
string _author;
public string Author
{
get
{ return _author; }
set
{ _author = value; }
}
private
int _amount;
public int Amount
{
get
{ return _amount; }
set
{ _amount = value; }
}
private
int _price;
public int Price
{
get
{ return _price; }
set
{ _price = value; }
}
public
Book()
{
}
public
Book(string bookName, string
author, int amount, int
price)
{
this._bookName
= bookName;
this._author
= author;
this._amount
= amount;
this._price
= price;
}
public
Book(int bookID, string
bookName, string author, int amount, int
price)
{
this._bookID
= bookID;
this._bookName
= bookName;
this._author
= author;
this._amount
= amount;
this._price
= price;
}
public
Book(DataRow row)
{
this._bookID
= (int)row["BookID"];
this._bookName
= row["BookName"].ToString();
this._author
= row["Author"].ToString();
this._amount
= (int)row["Amount"];
this._price
= (int)row["Price"];
}
}
}
- Khai báo
lớp Order, dạng Class Library, trong thư mục Entities (file order.cs),
nội dung coding:
using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BookShop.Entities
{
class Order
{
private
int _orderID;
public int OrderID
{
get
{ return _orderID; }
set
{ _orderID = value; }
}
private
string _customerName;
public string CustomerName
{
get
{ return _customerName; }
set
{ _customerName = value; }
}
private
DateTime _orderDate;
public DateTime OrderDate
{
get
{ return _orderDate; }
set
{ _orderDate = value; }
}
private
int _total;
public int Total
{
get
{ return _total; }
set
{ _total = value; }
}
private
List<OrderDetail>
_listOrderDetail;
internal
List<OrderDetail>
ListOrderDetail
{
get
{ return _listOrderDetail; }
set
{ _listOrderDetail = value; }
}
public
Order()
{
}
public
Order(string customerName, DateTime orderDate, int
total)
{
this._customerName
= customerName;
this._orderDate
= orderDate;
this._total
= total;
}
public
Order(DataRow row)
{
this._orderID
= (int)row["OrderID"];
this._customerName
= row["CustomerName"].ToString();
this._orderDate
= DateTime.Parse(row["OrderDate"].ToString());
this._total
= (int)row["Total"];
}
}
}
- Khai báo
lớp OrderDetail, dạng Class Library, trong thư mục Entities (file orderdetail.cs),
nội dung coding:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BookShop.Entities
{
class OrderDetail
{
private
int _recordID;
public int RecordID
{
get
{ return _recordID; }
set
{ _recordID = value; }
}
private
int _orderID;
public int OrderID
{
get
{ return _orderID; }
set
{ _orderID = value; }
}
private
int _bookID;
public int BookID
{
get
{ return _bookID; }
set
{ _bookID = value; }
}
private
int _quantity;
public int Quantity
{
get
{ return _quantity; }
set
{ _quantity = value; }
}
private
int _price;
public int Price
{
get
{ return _price; }
set
{ _price = value; }
}
private
int _totalPrice;
public int TotalPrice
{
get
{ return _totalPrice; }
set
{ _totalPrice = value; }
}
public
OrderDetail()
{
}
public
OrderDetail(DataRow row)
{
this._recordID
= (int)row["RecordID"];
this._orderID
= (int)row["OrderID"];
this._bookID
= (int)row["BookID"];
this._quantity
= (int)row["Quantity"];
this._price
= (int)row["Price"];
this._totalPrice
= (int)row["TotalPrice"];
}
}
}
Không có nhận xét nào:
Đăng nhận xét