大二上c#课程的大作业,有需要的可以借鉴一下。点个赞就行
?
下载地址:阿里云盘分享https://www.aliyundrive.com/s/ztMFnB7Z7Pt
有条件的hxd也可以支持一波:基于C#WPF和SQLserver的小管理系统-C#文档类资源-CSDN下载
本小系统基于wpf和SQL server构建。
大致框架如下图所示,数据库文件在SQL server中
?实现了增删改查,以及注册等功能。
增:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace bigwork
{
/// <summary>
/// zeng.xaml 的交互逻辑
/// </summary>
public partial class Add : Window
{
public Add()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string strCon = @"Data Source=.;Initial Catalog=Phone_manager;Integrated Security=True";
SqlConnection con = new SqlConnection(strCon);
con.Open();
var phonename = textbox1.Text;
var name = textbox2.Text;
var pwd = textbox3.Text;
var cost = textbox4.Text;
var balance = textbox5.Text;
while (true)
{
if (textbox1.Text == "")
{
MessageBox.Show("电话号码不能为空");
break;
}
if (textbox2.Text == "")
{
MessageBox.Show("名字不能为空");
break;
}
if (textbox3.Text == "")
{
MessageBox.Show("密码不能为空");
break;
}
if (textbox4.Text == "")
{
MessageBox.Show("消费不能为空");
break;
}
if (textbox5.Text == "")
{
MessageBox.Show("余额不能为空");
break;
}
string sql = "INSERT INTO god(number,name,password,cost,balance) VALUES (@phonename,@name,@pwd,@cost,@balance)";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@phonename", phonename);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@pwd", pwd);
cmd.Parameters.AddWithValue("@cost", cost);
cmd.Parameters.AddWithValue("@balance", balance);
int i = cmd.ExecuteNonQuery();
// while (true)
// {
if (i > 0)
{
MessageBox.Show("添加成功");
break;
}
else
{
MessageBox.Show("添加失败");
// Add add = new Add();
// add.ShowDialog();
continue;
}
}
con.Close();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
this.Hide();
Administration administration= new Administration();
administration.ShowDialog();
}
}
}
删:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace bigwork
{
/// <summary>
/// shan.xaml 的交互逻辑
/// </summary>
public partial class Deletess : Window
{
public Deletess()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string strCon = @"Data Source=.;Initial Catalog=Phone_manager;Integrated Security=True";
SqlConnection con = new SqlConnection(strCon);
con.Open();
String sql = "delete from god where number=" + "\'" + textbox1.Text + "\'";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Connection = con;
while (true)
{
if (textbox1.Text == "")
{
MessageBox.Show("电话号码不能为空");
break;
}
//var phonenumber = textbox1.Text;
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("删除成功");
textbox1.Text = "";
break;
}
else
{
MessageBox.Show("删除失败");
break;
}
}
con.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
this.Hide();
Administration administration = new Administration();
administration.ShowDialog();
}
}
}
改:
using System;
using System.Data.SqlClient;
using System.Windows;
namespace bigwork
{
/// <summary>
/// gai.xaml 的交互逻辑
/// </summary>
public partial class Changess : Window
{
public Changess()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var balance = textbox1.Text;
var name = textbox2.Text;
var pwd = textbox3.Text;
var phonenumber = textbox4.Text;
var cost = textbox5.Text;
string strCon = @"Data Source=.;Initial Catalog=Phone_manager;Integrated Security=True";
SqlConnection con = new SqlConnection(strCon);
con.Open();
while (true)
{
if (textbox1.Text == "")
{
MessageBox.Show("余额不能为空");
break;
}
if (textbox2.Text == "")
{
MessageBox.Show("名字不能为空");
break;
}
if (textbox3.Text == "")
{
MessageBox.Show("密码不能为空");
break;
}
if (textbox4.Text == "")
{
MessageBox.Show("电话号码不能为空");
break;
}
if (textbox5.Text == "")
{
MessageBox.Show("消费不能为空");
break;
}
//update god set cost = '100', balance = '100', password = '321' where number = '110'and name = 'pdd';
String sql = "update god set cost = " + "\'" + cost + "\'" + ",balance= " + "\'" + balance + "\'" + ",password=" + "\'" + pwd + "\'" + "where number=" + "\'" + phonenumber + "\'" + " and name=" + "\'" + name + "\'";
SqlCommand cmd = new SqlCommand(sql, con);
int hang = cmd.ExecuteNonQuery();
if (hang > 0)
{
MessageBox.Show("修改成功");
break;
}
else
{
MessageBox.Show("修改失败");
continue;
}
}
con.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
this.Hide();
Administration administration = new Administration();
administration.ShowDialog();
}
}
}
查:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace bigwork
{
/// <summary>
/// yhjm.xaml 的交互逻辑
/// </summary>
public partial class Userss : Window
{
public Userss()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string strCon = @"Data Source=.;Initial Catalog=Phone_manager;Integrated Security=True";
SqlConnection con = new SqlConnection(strCon);
con.Open();
var phonenumber = textbox1.Text;
while (true)
{
if (textbox1.Text == "")
{
MessageBox.Show("查询不能为空");
break;
}
//String sql = "select balance from god where number=" + "\'" + (phonenumber) + "\'";
SqlCommand cmd = new SqlCommand("select balance, cost from god where number = @phonenumber", con);
cmd.Parameters.AddWithValue("@phonenumber", phonenumber);
SqlDataReader myReader = cmd.ExecuteReader();
myReader.Read();
if (myReader.HasRows)
{
label2.Content = Convert.ToString(myReader["balance"]);
label3.Content = Convert.ToString(myReader["cost"]);
break;
}
else
{
label2.Content = "";
label3.Content = "";
MessageBox.Show("不存在");
break;
}
}
//将两次的查询结果显示出来
con.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
this.Hide();
Sign_in_2 sign = new Sign_in_2();
sign.ShowDialog();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
MessageBox.Show("请拨打10086");
}
}
}
登录:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace bigwork
{
/// <summary>
/// login2.xaml 的交互逻辑
/// </summary>
public partial class Sign_in_2 : Window
{
public Sign_in_2()
{
InitializeComponent();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
string strCon = @"Data Source=.;Initial Catalog=Phone_manager;Integrated Security=True";
SqlConnection con = new SqlConnection(strCon);
con.Open();
var phonename = textbox1.Text;
var pwd = textbox2.Password;
while (true)
{
if (textbox1.Text == "")
{
MessageBox.Show("id不能为空");
break;
}
if (textbox2.Password == "")
{
MessageBox.Show("密码不能为空");
break;
}
SqlCommand cmd = new SqlCommand("select number,password from god where number=@phonename and password=@pwd", con);
cmd.Connection = con;
cmd.Parameters.AddWithValue("@phonename", phonename);
cmd.Parameters.AddWithValue("@pwd", pwd);
SqlDataReader read = cmd.ExecuteReader();
while (true)
{
if (read.Read())
{
MessageBox.Show("登录成功");
Userss userss = new Userss();
userss.ShowDialog();
}
else
{
textbox1.Text = "";
textbox2.Password = "";
MessageBox.Show("用户名或密码错误");
Sign_in_2 signs = new Sign_in_2();
signs.ShowDialog();
}
}
}
con.Close();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
User_register user_Register = new User_register();
user_Register.ShowDialog();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
Environment.Exit(0);
}
private void Button_Click_4(object sender, RoutedEventArgs e)
{
this.Hide();
MainWindow mw = new MainWindow();
mw.ShowDialog();
}
}
}
数据库部分:
管理员字段:
用户字段:
?
?
|