From 555a9b01016c3ea1b708463d9bcee1ce149bb062 Mon Sep 17 00:00:00 2001 From: "LAPTOP-87USMBHE\\lenovo" <1574914261@qq.com> Date: Sat, 23 Dec 2023 23:25:42 +0800 Subject: [PATCH 1/4] tetris --- Tetris/App.config | 18 +- Tetris/App.xaml | 2 +- Tetris/MainWindow.xaml | 44 ++-- Tetris/MainWindow.xaml.cs | 148 ++++++++++++- Tetris/Page1.xaml | 29 +++ Tetris/Page1.xaml.cs | 55 +++++ Tetris/Properties/Resources.Designer.cs | 6 +- Tetris/Properties/Settings.Designer.cs | 2 +- Tetris/Resources/tetris.png | Bin 0 -> 1064033 bytes Tetris/Tetris.csproj | 80 ++++++- Tetris/View/LoginView.xaml | 203 ++++++++++++++++++ Tetris/View/LoginView.xaml.cs | 89 ++++++++ Tetris/View/Window1.xaml | 36 ++++ Tetris/View/Window1.xaml.cs | 63 ++++++ Tetris/bin/Debug/Tetris.exe | Bin 46080 -> 1268736 bytes Tetris/bin/Debug/Tetris.exe.config | 18 +- Tetris/bin/Debug/Tetris.pdb | Bin 42496 -> 71168 bytes Tetris/images/background.jpg | Bin 0 -> 137503 bytes Tetris/images/loginbackground.jpg | Bin 0 -> 6048 bytes Tetris/obj/Debug/App.g.cs | 4 +- Tetris/obj/Debug/App.g.i.cs | 4 +- ...gnTimeResolveAssemblyReferencesInput.cache | Bin 7642 -> 10039 bytes Tetris/obj/Debug/MainWindow.baml | Bin 5804 -> 6184 bytes Tetris/obj/Debug/MainWindow.g.cs | 118 +++++----- Tetris/obj/Debug/MainWindow.g.i.cs | 100 +++++---- .../Properties.Resources.Designer.cs.dll | Bin 3584 -> 4096 bytes .../Debug/Tetris.csproj.FileListAbsolute.txt | 110 ++++++++++ .../Tetris.csproj.GenerateResource.Cache | Bin 954 -> 84 bytes Tetris/obj/Debug/Tetris.exe | Bin 46080 -> 1268736 bytes Tetris/obj/Debug/Tetris.g.resources | Bin 14702 -> 1231781 bytes Tetris/obj/Debug/Tetris.pdb | Bin 42496 -> 71168 bytes Tetris/obj/Debug/Tetris_MarkupCompile.cache | 14 +- Tetris/obj/Debug/Tetris_MarkupCompile.i.cache | 16 +- Tetris/obj/Debug/Tetris_MarkupCompile.lref | 5 +- Tetris/packages.config | 19 ++ 35 files changed, 1045 insertions(+), 138 deletions(-) create mode 100644 Tetris/Page1.xaml create mode 100644 Tetris/Page1.xaml.cs create mode 100644 Tetris/Resources/tetris.png create mode 100644 Tetris/View/LoginView.xaml create mode 100644 Tetris/View/LoginView.xaml.cs create mode 100644 Tetris/View/Window1.xaml create mode 100644 Tetris/View/Window1.xaml.cs create mode 100644 Tetris/images/background.jpg create mode 100644 Tetris/images/loginbackground.jpg create mode 100644 Tetris/packages.config diff --git a/Tetris/App.config b/Tetris/App.config index d740e88..302ddb6 100644 --- a/Tetris/App.config +++ b/Tetris/App.config @@ -1,6 +1,18 @@ - + - + - \ No newline at end of file + + + + + + + + + + + + + diff --git a/Tetris/App.xaml b/Tetris/App.xaml index fdbbbca..2d1a15f 100644 --- a/Tetris/App.xaml +++ b/Tetris/App.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Tetris" - StartupUri="MainWindow.xaml" Deactivated="Application_Deactivated"> + StartupUri="/View/LoginView.xaml" Deactivated="Application_Deactivated"> diff --git a/Tetris/MainWindow.xaml b/Tetris/MainWindow.xaml index 8e7fe3b..f855525 100644 --- a/Tetris/MainWindow.xaml +++ b/Tetris/MainWindow.xaml @@ -22,7 +22,12 @@ - + + + + + + @@ -47,23 +52,25 @@ - + + + + + + + + + + + + + + + + + + + + + diff --git a/Tetris/View/LoginView.xaml.cs b/Tetris/View/LoginView.xaml.cs new file mode 100644 index 0000000..264be9d --- /dev/null +++ b/Tetris/View/LoginView.xaml.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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.Navigation; +using System.Windows.Shapes; +using MySql.Data.MySqlClient; +using static Tetris.Page1; + + +namespace Tetris.View +{ + /// + /// LoginView.xaml 的交互逻辑 + /// + public partial class LoginView : Window + { + public LoginView() + { + InitializeComponent(); + } + + private void Window_MouseDown(object sender, MouseButtonEventArgs e) + { + if(e.LeftButton == MouseButtonState.Pressed) + { + DragMove(); + } + } + + private void BtnMinimize_Click(object sender, RoutedEventArgs e) + { + WindowState = WindowState.Minimized; + } + + private void BtnClose_Click(object sender, RoutedEventArgs e) + { + Application.Current.Shutdown(); + } + + private void BtnLogin_Click(object sender, RoutedEventArgs e) + { + string username = txtUsername.Text; + string password = txtPassword.Password; + + string connectionString = "Server=localhost;Database=login;Uid=root;Pwd=root;"; + + using (MySqlConnection connection = new MySqlConnection(connectionString)) + { + connection.Open(); + string query = "SELECT COUNT(*) FROM Users WHERE Username = @username AND Password = @password"; + MySqlCommand command = new MySqlCommand(query, connection); + command.Parameters.AddWithValue("@username", username); + command.Parameters.AddWithValue("@password", password); + + int count = Convert.ToInt32(command.ExecuteScalar()); + + if (count > 0) + { + // 登录成功 + Window1 window1 = new Window1(); + + // 关闭 LoginView 窗口并显示 Window1 窗口 + this.Close(); + window1.Show(); + + } + else + { + // 登录失败 + MessageBox.Show("用户名或密码错误"); + // 刷新登录界面 + txtUsername.Text = ""; + txtPassword.Password = ""; + } + } + + } + } +} diff --git a/Tetris/View/Window1.xaml b/Tetris/View/Window1.xaml new file mode 100644 index 0000000..1653fe1 --- /dev/null +++ b/Tetris/View/Window1.xaml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tetris/View/LoginView.xaml.cs b/Tetris/View/LoginView.xaml.cs deleted file mode 100644 index 264be9d..0000000 --- a/Tetris/View/LoginView.xaml.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -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.Navigation; -using System.Windows.Shapes; -using MySql.Data.MySqlClient; -using static Tetris.Page1; - - -namespace Tetris.View -{ - /// - /// LoginView.xaml 的交互逻辑 - /// - public partial class LoginView : Window - { - public LoginView() - { - InitializeComponent(); - } - - private void Window_MouseDown(object sender, MouseButtonEventArgs e) - { - if(e.LeftButton == MouseButtonState.Pressed) - { - DragMove(); - } - } - - private void BtnMinimize_Click(object sender, RoutedEventArgs e) - { - WindowState = WindowState.Minimized; - } - - private void BtnClose_Click(object sender, RoutedEventArgs e) - { - Application.Current.Shutdown(); - } - - private void BtnLogin_Click(object sender, RoutedEventArgs e) - { - string username = txtUsername.Text; - string password = txtPassword.Password; - - string connectionString = "Server=localhost;Database=login;Uid=root;Pwd=root;"; - - using (MySqlConnection connection = new MySqlConnection(connectionString)) - { - connection.Open(); - string query = "SELECT COUNT(*) FROM Users WHERE Username = @username AND Password = @password"; - MySqlCommand command = new MySqlCommand(query, connection); - command.Parameters.AddWithValue("@username", username); - command.Parameters.AddWithValue("@password", password); - - int count = Convert.ToInt32(command.ExecuteScalar()); - - if (count > 0) - { - // 登录成功 - Window1 window1 = new Window1(); - - // 关闭 LoginView 窗口并显示 Window1 窗口 - this.Close(); - window1.Show(); - - } - else - { - // 登录失败 - MessageBox.Show("用户名或密码错误"); - // 刷新登录界面 - txtUsername.Text = ""; - txtPassword.Password = ""; - } - } - - } - } -} diff --git a/Tetris/View/Window1.xaml b/Tetris/View/Window1.xaml deleted file mode 100644 index 1653fe1..0000000 --- a/Tetris/View/Window1.xaml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - -