您好,登錄后才能下訂單哦!
本文實(shí)例為大家分享了C#實(shí)現(xiàn)餐廳管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
部分代碼:
fm_change_password.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Data.SqlClient; namespace FoodManage { public partial class fm_change_password : Form { public fm_change_password() { InitializeComponent(); } public string useridname = ""; private void bt_ok_Click(object sender, EventArgs e) { SqlConnection conn=new SqlConnection(fm_public.strcon); conn.Open(); SqlDataAdapter sda = new SqlDataAdapter("SELECT Password FROM TUser WHERE UserIDName='" + useridname + "'", conn); DataTable DT=new DataTable(); sda.Fill(DT); if(DT.Rows[0]["Password"].ToString()!=tb_oldpass.Text) { MessageBox.Show("舊密碼錯誤請重新輸入"); return; } if (tb_newpassw.Text != tb_newpass.Text) { MessageBox.Show("兩次密碼不相同請重新輸入"); return; } SqlCommand cmd = new SqlCommand("UPDATE TUser SET Password=@Password WHERE UserIDName='" + useridname + "'", conn); cmd.Parameters.Add("@Password",SqlDbType.VarChar,128).Value=tb_newpassw.Text; cmd.ExecuteNonQuery(); MessageBox.Show("修改密碼成功!(* ̄︶ ̄)y "); conn.Close(); this.Close(); } private void bt_esc_Click(object sender, EventArgs e) { this.Close(); } } }
fm_login.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace FoodManage { public partial class fm_login : Form { public fm_login() { InitializeComponent(); } private void bt_login_Click(object sender, EventArgs e) { //判斷用戶名或密碼文本框是否為空 if(tb_username.Text==""||tb_password.Text=="") { if(tb_username.Text=="") { MessageBox.Show("用戶名為空,請重新輸入!(* ̄︶ ̄)y "); return; } if (tb_password.Text == "") { MessageBox.Show("密碼為空,請重新輸入!(* ̄︶ ̄)y "); return; } } //連接數(shù)據(jù)庫 SqlConnection conn = new SqlConnection(fm_public.strcon); conn.Open(); string selectsql = "SELECT * FROM TUser WHERE UserIDName='" + tb_username.Text + "'"; SqlDataAdapter sda = new SqlDataAdapter(selectsql, conn); DataTable dt = new DataTable(); sda.Fill(dt); //判斷用戶是否存在 if (dt.Rows.Count == 0) { MessageBox.Show("無該用戶"); return; } //判斷用戶名是否被鎖定 if (Convert.ToBoolean(dt.Rows[0]["LockIf"]) == true) { MessageBox.Show("該用戶已經(jīng)被鎖定,請聯(lián)系管理員!/(ㄒoㄒ)/~~ "); return; } //更新數(shù)據(jù)庫前的準(zhǔn)備 SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; //判斷輸入密碼是否正確,輸入錯誤則“錯誤次數(shù)”+1,成功登錄則“錯誤次數(shù)”清零 if(tb_password.Text!=dt.Rows[0]["Password"].ToString()) { //錯誤次數(shù)+1 cmd.CommandText = @"UPDATE TUser SET ErrorTime=ErrorTime+1 WHERE UserIDName=@UserName"; cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 8); cmd.Parameters["@UserName"].Value = tb_username.Text.Trim(); cmd.ExecuteNonQuery(); MessageBox.Show("密碼錯誤請重新輸入!/(ㄒoㄒ)/~~ "); return; } //經(jīng)過以上驗(yàn)證用戶名密碼無錯執(zhí)行以下代碼(設(shè)置錯誤次數(shù)為0) cmd.CommandText = "update TUser set ErrorTime=0 where UserIDName=@UserName"; cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 8); cmd.Parameters["@UserName"].Value = tb_username.Text.Trim(); cmd.ExecuteNonQuery(); conn.Close(); fm_public.LoginSuccess = true; //設(shè)置用戶權(quán)限以及初始化主界面的相關(guān)參數(shù) if (dt.Rows[0]["Post"].ToString() == "管理員") { fm_public.userpower = "管理員"; } else { fm_public.userpower = "服務(wù)員"; } fm_public.useridname = dt.Rows[0]["UserIDName"].ToString(); fm_public.logintime = DateTime.Now.ToShortDateString(); this.Close(); } private void bt_esc_Click(object sender, EventArgs e) { if (MessageBox.Show("確定退出系統(tǒng)嗎?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK) { Application.Exit(); } } private void fm_login_Activated(object sender, EventArgs e) { tb_username.Focus(); } private void fm_login_Load(object sender, EventArgs e) { fm_start fm_starts = new fm_start(); fm_starts.ShowDialog(); } } }
源碼下載:C#實(shí)現(xiàn)餐廳管理系統(tǒng)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。