C#WPF と SQL サーバーに基づく小規模な管理システム

2 年生の C# コースの大きな宿題ですが、必要に応じて学習できます。それと同じように

 

ダウンロードアドレス: Alibaba Cloud Disk Sharing https://www.aliyundrive.com/s/ztMFnB7Z7Pt

条件付き hxd は Wave もサポートできます: C#WPF および SQLserver に基づく小規模管理システム - C#document リソース - CSDN ダウンロード

この小さなシステムは、wpf と SQL サーバーに基づいて構築されています。

一般的なフレームワークは次の図に示されており、データベース ファイルは SQL サーバーにあります。

 追加、削除、変更、確認、登録機能を実現しました。

増加:

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();
        }
    }
}

データベースセクション:

管理フィールド:

ユーザーフィールド:

 

 

おすすめ

転載: blog.csdn.net/weixin_52357218/article/details/122831849