手机号卡销售系统c#版.doc_第1页
手机号卡销售系统c#版.doc_第2页
手机号卡销售系统c#版.doc_第3页
手机号卡销售系统c#版.doc_第4页
手机号卡销售系统c#版.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

一、【实验目的】通过编写完整的程序,掌握SqlServer各种语句的使用,添加,删除,更新等,学习程序的编写,学会分析问题,解决问题。二、【实验内容】通过学过的SqlServer知识,编写手机号卡销售系统,实现具体功能:1、 实现管理员的登录操作2、 创建数据库,建立管理员账号表,手机号码表,客户表3、 输入一个号码段,比如13882368,生成手机号码最后四位4、 将生成的手机号码进行分类,A类卡,比如后四位为1234,4567等,B类卡,比如后四位为1111,4444等,C类卡,比如出去A,B类卡末尾为6或者8的号码,D类卡,出去A,B,C类卡号类型的卡5、 对所选择的卡号类型进行显示,选择,查询已出售卡的信息6、 对所出售的卡号进行状态修改,将“未出售”改为“已出售”,并将客户的信息写入表中三、【实验步骤】 1、 E-R图卡号管理人员用户名密码销售修改销售状态卡号类型销售状态购买客户电话号码姓名性别地址身份证号码2、登陆程序编写 登陆窗口界面登陆窗口代码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.SqlClient;namespace WindowsApplication3 public partial class Form1 : Form public Form1() /这段代码的功能是在SqlServer中创建数据库和生产表,包括管理人员表,号码表和销售表,当程序运行时,它会自动进行创建 SqlConnection conn = new SqlConnection(server=.;user id=sa;password=;Trusted_Connection=yes;); conn.Open(); SqlCommand myCommand = conn.CreateCommand(); myCommand.CommandText = select * from master.dbo.sysdatabases where name = 手机号码生成系统; SqlDataReader sdr =myCommand.ExecuteReader(); if (sdr.Read() sdr .Close (); else sdr.Close(); myCommand.CommandText = create database 手机号码生成系统; myCommand.ExecuteNonQuery(); myCommand.CommandText = use 手机号码生成系统; myCommand.ExecuteNonQuery(); myCommand.CommandText = create table worker(ID int identity primary key,name varchar(50) not null,pwd varchar(50) not null); myCommand.ExecuteNonQuery(); myCommand.CommandText = insert into worker values(wang,wang); myCommand.ExecuteNonQuery(); myCommand.CommandText = create table card (telenumber varchar(30) primary key,sort varchar(30) not null,sta varchar(30) not null); myCommand.ExecuteNonQuery(); myCommand.CommandText = create table client (telenumber varchar(30) primary key,name varchar(50) not null,sex varchar(10) not null,address varchar(50) not null,IDcard varchar(30) not null); myCommand.ExecuteNonQuery(); conn.Close(); InitializeComponent(); private void but2Close_Click(object sender, EventArgs e) /弹出提示信息,如果点击确认退出,则退出应用程序 if (MessageBox.Show(你确定要退出系统吗?, 提示信息!, MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) = DialogResult.OK) Application.Exit(); private void login_Click(object sender, EventArgs e) /登陆代码,判断用户名和密码是否和数据库中的用户名和密码是否相同,如果登陆成功就弹出FORM2窗口 SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlCommand cmd = new SqlCommand(select * from worker where name= + textBox1.Text.Trim() + and pwd= + textBox2.Text.Trim() + , conn); conn .Open() ; SqlDataReader sdr =cmd.ExecuteReader(); if (sdr.Read () Form2 form2 = new Form2(); form2.ShowDialog(); Close(); else MessageBox.Show(登陆失败!); this.textBox1.Text = ; this.textBox2.Text = ; conn.Close(); 3、手机号码生成程序编写 手机号码生成窗口界面 (1)号码生成(2)号码选择(3)出售信息手机号码生成代码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.SqlClient;namespace WindowsApplication3 public partial class Form2 : Form public Form2() InitializeComponent(); public static string A = A类卡; public static string B = B类卡; public static string C = C类卡; public static string D = D类卡; public static string F = 未出售; private void Form2_Load(object sender, EventArgs e) private void radioButton1_Click(object sender, EventArgs e) /点击选择A类卡按钮后,查找出类型为A类卡并且销售状态为未出售 SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlDataAdapter sda= new SqlDataAdapter(select * from card where sort=+A+ and sta=+F+, conn); DataTable dt = new DataTable(); sda.Fill(dt); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; bs.PositionChanged +=new EventHandler(bs_PositionChanged); private void bs_PositionChanged(object sender, EventArgs e) /对所选择的卡号进行显示 BindingSource bsc = (BindingSource)dataGridView1.DataSource; DataRowView div = (DataRowView)bsc.Current; label3.Text = divtelenumber.ToString(); private void radioButton2_Click(object sender, EventArgs e) /点击选择B类卡按钮后,查找出类型为B类卡并且销售状态为未出售 SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlDataAdapter sda = new SqlDataAdapter(select * from card where sort=+B+ and sta=+F+, conn); DataTable dt = new DataTable(); sda.Fill(dt); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; bs.PositionChanged += new EventHandler(bs_PositionChanged); private void radioButton3_Click(object sender, EventArgs e) /点击选择C类卡按钮后,查找出类型为C类卡并且销售状态为未出售 SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlDataAdapter sda = new SqlDataAdapter(select * from card where sort=+C+ and sta=+F+, conn); DataTable dt = new DataTable(); sda.Fill(dt); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; bs.PositionChanged += new EventHandler(bs_PositionChanged); private void radioButton4_Click(object sender, EventArgs e) /点击选择D类卡按钮后,查找出类型为D类卡并且销售状态为未出售 SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlDataAdapter sda = new SqlDataAdapter(select * from card where sort=+D+ and sta=+F+, conn); DataTable dt = new DataTable(); sda.Fill(dt); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; bs.PositionChanged += new EventHandler(bs_PositionChanged); private void button1_Click(object sender, EventArgs e) Form3 f3 = new Form3(this.label3.Text.Trim(); f3.ShowDialog(); private void button2_Click(object sender, EventArgs e) Close(); private void button3_Click(object sender, EventArgs e) /此处为手机号码最后四位的生成代码,生产后,会自动将所生成的电话号码插入到表中 try SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlCommand cmd = conn.CreateCommand(); string tel =textBox1.Text.Trim (); conn.Open(); cmd.CommandText = truncate table card; cmd.ExecuteNonQuery(); for (int i = 10000; i = 19999; i+) int temp1, temp2, temp3, temp4; string strsub = Convert.ToString(i).Substring(1, 4); string str = tel + strsub; temp1 = Convert.ToInt32(str.Substring(7, 1); temp2 = Convert.ToInt32(str.Substring(8, 1); temp3 = Convert.ToInt32(str.Substring(9, 1); temp4 = Convert.ToInt32(str.Substring(10, 1); if (temp1 + 1 = temp2 & temp2 + 1 = temp3 & temp3 + 1 = temp4) | (temp1 - 1 = temp2 & temp2 - 1 = temp3 & temp3 - 1 = temp4) cmd.CommandText = insert into card(telenumber,sort,sta) values( + str + ,+A+,+F+); cmd.ExecuteNonQuery(); else if (temp1 = temp2 & temp3 = temp4 & temp2 = temp3) cmd.CommandText = insert into card(telenumber,sort,sta) values( + str + ,+B+, + F + ); cmd.ExecuteNonQuery(); else if (temp4 = 6 | temp4 = 8) cmd.CommandText = insert into card(telenumber,sort,sta) values( + str + , + C + , + F + ); cmd.ExecuteNonQuery(); else cmd.CommandText = insert into card(telenumber,sort,sta) values( + str + , + D + , + F + ); cmd.ExecuteNonQuery(); conn.Close(); MessageBox.Show(号码生成成功!, 提示信息!, MessageBoxButtons.OK, MessageBoxIcon.Information); catch MessageBox.Show(号码生成失败!, 提示信息!, MessageBoxButtons.OK, MessageBoxIcon.Information); private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) private void textBox1_TextChanged(object sender, EventArgs e) private void button4_Click(object sender, EventArgs e) SqlConnection conn = new SqlConnection(server=.;database=手机号码生成系统;uid=sa;pwd=;); SqlDataAdapter sda = new SqlDataAdapter(select * from client, conn); DataTable dt = new DataTable(); sda.Fill(dt); BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; 3、客户信息程序编写客户信息窗口界面 客户信息代码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.SqlClient;namespace WindowsApplication3 public partial class Form3 : Form public Form3() InitializeComponent(); public Form3(string strlable3Text) InitializeComponent(); this.label7.Text= strlable3Text; private void button2_Click(object sender, EventArgs e) Close()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论