二、用戶登錄和注冊

一、頁面設計

一共四個頁面
主頁面Form1,登錄頁面login,注冊頁面resister,主菜單頁面main_page
系統運行進入Form1,單擊登錄按鈕跳轉到login,數據庫中得存在數據信息且輸入正確才可登錄成功,跳轉到main_page
單擊注冊按鈕跳轉到register,用戶需要注冊賬號、密碼、性別、手機號信息

Form1
在這里插入圖片描述
login
在這里插入圖片描述

register
在這里插入圖片描述
main_page
在這里插入圖片描述
四個頁面如下
在這里插入圖片描述

二、數據庫的創建

創建fiber_yy數據庫,在其下創建yy_user表,其中id為主鍵自增
在這里插入圖片描述
整體結構如下
在這里插入圖片描述

三、相關代碼

Form1代碼

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.Sql;
using System.Data.SqlClient;namespace fiber_yy
{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void label2_Click(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){this.Hide();new login().Show();}private void button3_Click(object sender, EventArgs e){MessageBox.Show("see you again~");Application.Exit();  //退出進程}private void button2_Click(object sender, EventArgs e){this.Hide();new register().Show();}}
}

login代碼

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;namespace fiber_yy
{public partial class login : Form{public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public string identification = null;public login(){InitializeComponent();conn.Open();}private void button1_Click(object sender, EventArgs e)//登錄{string username = textBox1.Text;string password = textBox2.Text;string identify = textBox3.Text;if (username.Equals("") || password.Equals("") || identify.Equals("")){MessageBox.Show("提示:請輸入用戶名、密碼、驗證碼!", "警告");}else{string sqlSel = "select count(*)  from yy_user where username = '" + username + "' and password = '" + password + "'";SqlCommand cmd = new SqlCommand(sqlSel, conn);if (Convert.ToInt32(cmd.ExecuteScalar()) > 0 ){if(identify==identification){this.Close();MessageBox.Show("用戶登錄成功");new main_page().Show();}else {MessageBox.Show("驗證碼輸入錯誤");}}else{MessageBox.Show("賬號或密碼錯誤");}}}private void pictureBox1_Click(object sender, EventArgs e){Random r = new Random();string str = null;for (int i = 0; i < 5; i++){int n = r.Next(0, 10);str += n;//包括字符串在內}identification = str;Bitmap b = new Bitmap(100, 15);Graphics g = Graphics.FromImage(b);for (int i = 0; i < 5; i++){String[] fonts = { "宋體", "黑體", "隸書", "仿宋", "微軟雅黑" };//字體數組Color[] colors = { Color.Red, Color.Black, Color.Blue,Color.YellowGreen ,Color.Green };//顏色數組Font f = new Font(fonts[r.Next(0, 5)], 25, FontStyle.Bold);SolidBrush s = new SolidBrush(colors[r.Next(0, 5)]);//定義一個單獨的畫筆,使每個字符的顏色隨機Point p = new Point(i * 20, 0);//每個字符間隔20g.DrawString(str[i].ToString(), Font, s, p);}for (int a = 0; a < 5; a++){Point p1 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));Point p2 = new Point(r.Next(0, b.Width), r.Next(0, b.Height));//線的兩點不能超過圖片的長和寬Pen pen = new Pen(Brushes.Cyan);//青色線段g.DrawLine(pen, p1, p2);}pictureBox1.Image = b;}}
}

register代碼

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;namespace fiber_yy
{public partial class register : Form{public static string str_conn = "server=CY-20190824RMES;Initial Catalog=fiber_yy;User ID=sa;pwd=beyond";SqlConnection conn = new SqlConnection(str_conn);public register(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){string sex="man";long phone_number;int account_number, password, sum=0;account_number = textBox1.Text.Length;password = textBox2.Text.Length;phone_number = long.Parse(textBox3.Text);if (account_number <= 3 || account_number >= 16){label6.Text = "賬號長度應該在3~16字符之間";sum++;}else{label6.Text = "校驗成功";}if (password <= 3 || password >= 16){label7.Text = "密碼長度應該在3~16字符之間";sum++;}else{label7.Text = "校驗成功";}if (radioButton1.Checked){sex = "man";}else if (radioButton2.Checked){sex = "woman";}if (phone_number < 10000000000 || phone_number > 99999999999){label9.Text = "請輸入正確的手機號";sum++;}else{label9.Text = "校驗成功";}if (sum == 0){label6.Text = "√";label7.Text = "√";label8.Text = "√";label9.Text = "√";try{string sql = string.Format("select count(*) from yy_user where username='{0}'", textBox1.Text);SqlCommand cmd = new SqlCommand(sql, conn);conn.Open();int a = (int)cmd.ExecuteScalar();//返回一個值,看用戶是否存在    1存在 0不存在StringBuilder strsql = new StringBuilder();//MessageBox.Show(a.ToString());if(a==1){MessageBox.Show("用戶名已存在");}else{MessageBox.Show("okk");//string INSERT_sql = string.Format("INSERT INTO user_yy VALUES ('{0}','{1}')", textBox1.Text,textBox2.Text);string INSERT_sql = string.Format("INSERT INTO yy_user VALUES ('{0}','{1}','{2}','{3}')", textBox1.Text.Trim(), textBox2.Text.Trim(), sex, textBox3.Text.Trim());SqlCommand INSERT_cmd = new SqlCommand(INSERT_sql, conn);int count = INSERT_cmd.ExecuteNonQuery();if (count > 0){MessageBox.Show("注冊成功!");this.Close();new Form1().Show();}else {MessageBox.Show("GG");}}}catch(Exception ex){MessageBox.Show(ex.Message);}}}private void button2_Click(object sender, EventArgs e){this.Close();MessageBox.Show("用戶登錄成功");new main_page().Show();}}
}

main_page代碼

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;namespace fiber_yy
{public partial class main_page : Form{public main_page(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){MessageBox.Show("退出成功");this.Close();new Form1().Show();}}
}

四、效果展示

原始數據集數據信息
在這里插入圖片描述
運行程序
在這里插入圖片描述
注冊
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
右擊 yy_user—> 選擇前1000行
在這里插入圖片描述
已經注冊成功了,接下來開始登錄
隨便輸入一個賬號
在這里插入圖片描述
在這里插入圖片描述

輸入正確的賬號,但驗證碼輸入錯誤
在這里插入圖片描述
在這里插入圖片描述

賬號密碼驗證碼輸入正確
在這里插入圖片描述
在這里插入圖片描述

跳轉到main_page
在這里插入圖片描述
退出登錄之后會返回到Form1
在這里插入圖片描述
在這里插入圖片描述
退出系統,提示see you again~
在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377711.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377711.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377711.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

readdir函數_PHP readdir()函數與示例

readdir函數PHP readdir()函數 (PHP readdir() function) The full form of readdir is "Read Directory", the function readdir() is used to read the directory i.e. read the name of the next entry in the directory. readdir的完整形式為“ Read Directory”…

【C++grammar】訪問控制與抽象類與純虛函數

目錄一、訪問控制 (可見性控制)1.private、public、protected關鍵字2.關鍵字示例1、關鍵字對類數據成員訪問的限制3. 公有繼承4. 私有繼承5. 保護繼承6. 私有繼承和保護繼承的區別二、抽象類與純虛函數1.什么是抽象類2.抽象函數/純虛函數3.抽象類示例一、訪問控制 (可見性控制)…

mongodb 如何刪除 字段值為 json對象中的某個字段值

例如&#xff1a; { attributes: { birthday:1988-01-01, name: aq } } birthday是attributes字段的value的一個字段&#xff0c; 我要刪除birthday 用這句話&#xff1a; db.User.update({email:adminlinkris.com},{$unset:{attributes.birthday:}})轉載于:https://www.cnblog…

使用 Spring 的 Web 服務模擬器框架解決方案

http://www.ibm.com/developerworks/cn/web/wa-aj-simulator/index.html轉載于:https://www.cnblogs.com/diyunpeng/archive/2012/02/28/2371390.html

三、上傳織物圖片至SQL Server并提供name進行展示織物照片

一、數據庫的建立 還是在fiber_yy數據庫下創建images表 images表設計如下 二、頁面完善設計 main_page頁面進行功能完善 入庫管理系統 warehousing頁面 庫存查詢系統 query頁面 登錄注冊頁面前面幾個博文已經實現過了&#xff0c;這里就再贅述了&#xff0c;仍是沿用前…

gettype_PHP gettype()函數與示例

gettypePHP gettype()函數 (PHP gettype() function) In PHP, we have a library function gettype() to identify the type of data. The function is primarily used to sanity check the type of data being input in a variable. The function can identify the data into …

ARM MMU工作原理剖析[轉]

一、MMU的產生 許多年以前&#xff0c;當人們還在使用DOS或是更古老的操作系統的時候&#xff0c;計算機的內存還非常小&#xff0c;一般都是以K為單位進行計算&#xff0c;相應的&#xff0c;當時的程序規模也不大&#xff0c;所以內存容量雖然小&#xff0c;但還是可以容納當…

棧與隊列在SGI STL的底層實現

棧 棧提供push和pop等接口&#xff0c;不提供走訪功能&#xff0c;也不提供迭代器。 STL中棧不被歸類為容器&#xff0c;而被歸類為container adapter(容器適配器)&#xff0c;這是因為棧是以底層容器完成其所有的工作&#xff0c;對外提供統一的接口&#xff0c;底層容器是可…

【原創】SharePoint Document library List Check out 文檔時碰到的問題解決

環境&#xff1a;TFS(Team Foundation Server)集成的WSS 3.0&#xff08;SharePoint Service 3.0&#xff09; 問題&#xff1a;如題&#xff0c;祥見下圖 解決&#xff1a;一般碰到沒有經驗的問題&#xff0c;大家當然是外事不決問谷歌了&#xff0c;于是谷歌搜到了這篇博客 h…

getdate函數_PHP getdate()函數與示例

getdate函數PHP getdate()函數 (PHP getdate() function) getdate() function is used to get the local date/time (or it is also used to get the date/time based on the given timestamp. getdate()函數用于獲取本地日期/時間(或也用于根據給定的時間戳獲取日期/時間。 S…

四、入庫管理功能的完善

一、數據庫的創建 在fiber_yy數據庫下創建yy_textile表 先隨便添加幾條數據 二、頁面的完善 登錄注冊頁面我就不演示了&#xff0c;前幾篇博文也都有介紹 warehousing入庫頁面 main_page頁面進行功能完善 三、代碼實現 warehousing頁面 using System; using System.…

leetcode 232. 用棧實現隊列 思考分析

題目 請你僅使用兩個棧實現先入先出隊列。隊列應當支持一般隊列的支持的所有操作&#xff08;push、pop、peek、empty&#xff09;&#xff1a; 實現 MyQueue 類&#xff1a; void push(int x) 將元素 x 推到隊列的末尾 int pop() 從隊列的開頭移除并返回元素 int peek() 返…

YCSB初步介紹

隨著大數據時代的到來和云計算的不斷發展&#xff0c;作為云計算最基礎的設施存儲產品也越來越多&#xff0c;開源分布式存儲系統有BigTable-like系統HBase&#xff0c;dynamo-like系統Cassandra&#xff0c;voldemort&#xff0c;Riak&#xff0c;淘寶開源的OceanBase等。當然…

kotlin實現繼承_Kotlin程序| 繼承的例子

kotlin實現繼承遺產 (Inheritance) Inheritance is a mechanism wherein a new class is derived from an existing class. 繼承是一種機制&#xff0c;其中新類是從現有類派生的。 All Kotlin Classes have a common Superclass Any, it is the Default Superclass with no S…

【C++grammar】動態類型轉換、typeid與RTTI

目錄動態類型轉換1、為何需要動態類型轉換2、dynamic_cast<>();運算符3、向上轉換和向下轉換( Upcasting and Downcasting)4、 基類對象和派生類對象的互操作5、Upcasting/Downcasting與繼承鏈上不同類的對象之間的賦值有什么關系和區別&#xff1f;typeid 運行時查詢類型…

nginx資源定向 css js路徑問題

今天玩玩項目&#xff0c;學學nginx發現還不錯&#xff0c;速度還可以&#xff0c;但是CSS JS確無法使用&#xff0c;原來Iginx配置時需要對不同類型的文件配置規則&#xff0c;真是很郁悶&#xff0c;不過想想也還是很有道理。閑暇之際&#xff0c;把配置貼上來。#user nobody…

五、庫存查詢功能的完善

一、數據庫的建立 由于查詢功能和之前的 入庫管理功能 所用的數據庫都一樣&#xff0c;這里仍使用yy_textile表 在fiber_yy數據庫下創建yy_textile表 初始數據庫信息 二、頁面的完善 登錄注冊頁面我就不演示了&#xff0c;前幾篇博文也都有介紹 query查詢頁面 main_page…

整合ajaxmin 和 less 到VS.net

我用的前端框架是bootstrap_extra, twitter團隊做的&#xff0c;這個是他的一個擴展&#xff0c;首先從上面下載一個。至于ajaxmin&#xff0c;請參考這里1) 從bootstrap_extra的解壓包中&#xff0c;復制build目錄下三個文件到項目中去&#xff0c;這三個文件分別是BatchSubsi…

轉:只能選擇GridView中的一個CheckBox(單選CheckBox)

方法1&#xff1a; protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e){CheckBox cbx e.Row.FindControl("cbID") as CheckBox;try{//綁定選中CheckBox 客戶端IDcbx.Attributes.Add("onclick", "Change(" cbx.Cli…

六、出庫管理功能的實現

一、數據庫的建立 這里仍使用yy_textile表 在fiber_yy數據庫下創建yy_textile表 初始數據庫信息 二、頁面的完善 登錄注冊頁面我就不演示了&#xff0c;前幾篇博文也都有介紹 shipment出庫管理頁面 main_page頁面進行功能完善 三、代碼實現 shipment出庫管理頁面 u…