1.B,源代码
/App_Data/sql-basic.sql
复制代码 代码如下:
use master
go
if exists(select * from sysdatabases where)
begin
drop database db1
end
go
create database db1
go
use db1
go
-- ================================
-- ylb:1,类别表
-- ================================
create table category
(
categoryid int identity(1,1) primary key, --编号【PK】
categoryname varchar(20) not null --名称
)
insert into category(categoryname) values('饮料')
insert into category(categoryname) values('主食')
insert into category(categoryname) values('副食')
insert into category(categoryname) values('蔬菜')
-- ================================
-- ylb:2,产品表
-- ================================
create table product
(
productid int identity(1001,1) primary key, --编号【PK】
productname varchar(20), --名称
unitprice numeric(7,2), --单价
special varchar(10) check(special in('特价','非特价')), --是否特价【C】
categoryid int foreign key references category(categoryid) --类别编号【FK】
)
insert into product(productname,unitprice,special,categoryid) values('可乐1',12.6,'特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐2',12.6,'非特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐3',12.6,'非特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐4',12.6,'非特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐5',12.6,'特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐6',12.6,'特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐7',12.6,'特价',1)
insert into product(productname,unitprice,special,categoryid) values('可乐8',12.6,'特价',1)
insert into product(productname,unitprice,special,categoryid) values('馒头1',12.6,'特价',2)
insert into product(productname,unitprice,special,categoryid) values('豆腐1',12.6,'特价',3)
insert into product(productname,unitprice,special,categoryid) values('冬瓜1',12.6,'特价',4)
select * from category
select productid,productname,unitprice,special,categoryid from product
,2
/App_Code/
/App_Code/DBConnection.cs
复制代码 代码如下:
using System.Data.SqlClient;
/// <summary>
///DBConnection 的摘要说明
///数据连接类
/// </summary>
public class DBConnection
{
SqlConnection con = null;
public DBConnection()
{
//创建连接对象
con = new SqlConnection("Server=.;Database=db1;Uid=sa;pwd=sa");
}
/// <summary>
/// 数据连接对象
/// </summary>
public SqlConnection Con
{
get { return con; }
set { con = value; }
}
}
/App_Code/CategoryInfo.cs
/App_Code/CategoryOper.cs
/App_Code/ProductInfo.cs
复制代码 代码如下:
using System;
/// <summary>
///ProductInfo 的摘要说明
///产品实体类
/// </summary>
public class ProductInfo
{
//1,Attributes
int productId;
string productName;
decimal unitprice;
string special;
int categoryId;
public ProductInfo()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
//3,
/// <summary>
/// 产品编号【PK】
/// </summary>
public int ProductId
{
get { return productId; }
set { productId = value; }
}
/// <summary>
/// 产品名称
/// </summary>
public string ProductName
{
get { return productName; }
set { productName = value; }
}
/// <summary>
/// 单位价格
/// </summary>
public decimal Unitprice
{
get { return unitprice; }
set { unitprice = value; }
}
/// <summary>
/// 是否为特价【C】(特价、非特价)
/// </summary>
public string Special
{
get { return special; }
set { special = value; }
}
/// <summary>
/// 类编编号【FK】
/// </summary>
public int CategoryId
{
get { return categoryId; }
set { categoryId = value; }
}
}
/App_Code/ProductOper.cs
复制代码 代码如下:
using System;
using System.Collections.Generic;