欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

超市管理系统

程序员文章站 2022-04-08 20:27:52
数据库 use masterif exists (select * from sysdatabases where name='SuperMark')drop database SuperMarkcreate database SuperMarkon PRIMARY(name='SuperMark_ ......

数据库

use master
if exists (select * from sysdatabases where name='supermark')
drop database supermark
create database supermark
on primary
(
name='supermark_data',
filename='f:\supermark.mdf',
filegrowth=20%,
size=10mb
)
log on
(
name='supermark_log',
filename='f:\supermark_log.ldf',
size=3mb,
maxsize=20mb
)

 


use [supermark]
go
set ansi_nulls on
go

set quoted_identifier on
go

set ansi_padding on
go

create table [dbo].[states](
[id] [int] identity(1,1) not null,
[statesname] [varchar](20) not null,
constraint [pk_states] primary key clustered
(
[id] asc
)with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]
) on [primary]

go

set ansi_padding off
go
set ansi_nulls on
go

set quoted_identifier on
go

set ansi_padding on
go

create table [dbo].[usersinfo](
[id] [int] identity(1,1) not null,
[customerid] [varchar](20) not null,
[customerpassword] [varchar](20) not null,
[customertype] [varchar](10) not null,
[score] [int] not null,
[statusid] [int] not null,
constraint [pk_usersinfo] primary key clustered
(
[id] asc
)with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]
) on [primary]

go

set ansi_padding off
go

alter table [dbo].[usersinfo] with check add constraint [fk_usersinfo_states] foreign key([statusid])
references [dbo].[states] ([id])
go

alter table [dbo].[usersinfo] check constraint [fk_usersinfo_states]
go

窗体

超市管理系统

超市管理系统

帐号文本框 name 为 txtcustomerid
密码文本框 name为txtpwd
金卡 name 为rdojinka
铂金卡 name为rdobojinka
钻石卡 name为rdozuanshika
状态 下拉框 name 为cbostatus
账户积分文本框name 为 txtscore 属性readonly 为true
显示控件 name为dgvuserinfo
id 绑定数据id
账号 绑定数据customerid
卡别绑定数据customertype
积分绑定数据score
状态绑定数据statesname
超市管理系统

后台代码

链接数据库字符串请根据实际情况而定

using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.threading.tasks;
using system.windows.forms;
using system.data.sqlclient;

namespace supermarksystem
{
public partial class frmmain : form
{
//链接数据库字符串
string connstr = "data source=.;initial catalog=supermark;integrated security=true";
dataset ds;
sqldataadapter adapter;


public frmmain()
{
initializecomponent();
}

private void frmmain_load(object sender, eventargs e)
{
this.dgvuserinfo.autogeneratecolumns = false;

bindstates();

binduserinfo();
}

//绑定会员状态下拉菜单
private void bindstates()
{
try
{
sqlconnection conn = new sqlconnection(connstr);
ds = new dataset();
string sql = "select id,statesname from states";
adapter = new sqldataadapter(sql, conn);
adapter.fill(ds, "states");
this.cbostatus.datasource = ds.tables["states"];
this.cbostatus.valuemember = "id";
this.cbostatus.displaymember = "statesname";
this.cbostatus.selectedindex = 0;
}
catch (exception)
{

}
}

private void btnexit_click(object sender, eventargs e)
{
application.exit();
}

private void rdojinka_checkedchanged(object sender, eventargs e)
{
if (rdojinka.checked==true)
{
txtscore.text = "500";
}
}

private void rdobojinka_checkedchanged(object sender, eventargs e)
{
if (rdobojinka.checked == true)
{
txtscore.text = "2000";
}
}

private void rdozuanshika_checkedchanged(object sender, eventargs e)
{
if (rdozuanshika.checked == true)
{
txtscore.text = "5000";
}
}

/// <summary>
/// 绑定会员信息
/// </summary>
private void binduserinfo()
{
try
{
sqlconnection conn = new sqlconnection(connstr);
ds = new dataset();
string sql = "select u.id,customerid,customertype,score,s.statesname from usersinfo as u,states as s where u.statusid=s.id";
adapter = new sqldataadapter(sql, conn);
adapter.fill(ds, "usersinfo");
this.dgvuserinfo.datasource = ds.tables["usersinfo"];
}
catch (exception)
{

}
}

private void btnadd_click(object sender, eventargs e)
{
if (txtcustomerid.text.trim().equals(string.empty) || txtpwd.text.trim().equals(string.empty) || cbostatus.text.trim().equals(string.empty))
{
messagebox.show("请填写完整的会员信息!");
return;
}
sqlconnection conn = new sqlconnection(connstr);
try
{
string customertype = string.empty;
if (rdojinka.checked == true)
{
customertype = "金卡";
}
else if (rdobojinka.checked == true)
{
customertype = "铂金卡";
}
else
{
customertype = "钻石卡";
}
string sql = string.format(@"insert into usersinfo(customerid,customerpassword,customertype,score,statusid)
values('{0}','{1}','{2}',{3},{4})",
txtcustomerid.text.trim(),
txtpwd.text.trim(),
customertype,
txtscore.text.trim(),
cbostatus.selectedvalue);
conn.open();
sqlcommand command = new sqlcommand(sql, conn);
int count = command.executenonquery();
if (count == 1)
{
messagebox.show("新增成功!");
//刷新用户列表数据
binduserinfo();
}
else
{
messagebox.show("新增失败!");
}
}
catch (exception)
{
messagebox.show("发生异常!");
}
finally
{
conn.close();
}
}

private void 删除toolstripmenuitem_click(object sender, eventargs e)
{
string id = this.dgvuserinfo.selectedrows[0].cells["id"].value.tostring();
if (messagebox.show("确定要删除该条信息吗?" + id, "提示", messageboxbuttons.yesno, messageboxicon.information) == dialogresult.yes)
{
sqlconnection conn = new sqlconnection(connstr);
try
{
string sql = "delete from usersinfo where id=" + id;
conn.open();
sqlcommand command = new sqlcommand(sql, conn);
int count = command.executenonquery();
if (count == 1)
{
messagebox.show("删除成功!");
//刷新用户列表数据
binduserinfo();
}
else
{
messagebox.show("删除成功!");
}
}
catch (exception)
{
messagebox.show("发生异常!");
}
finally
{
conn.close();
}
}

}
}
}

 

上一篇: EF

下一篇: 早上