您好,登錄后才能下訂單哦!
本文實例為大家分享了C#實現餐廳管理系統的具體代碼,供大家參考,具體內容如下
部分代碼:
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; } } //連接數據庫 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("該用戶已經被鎖定,請聯系管理員!/(ㄒoㄒ)/~~ "); return; } //更新數據庫前的準備 SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.Text; //判斷輸入密碼是否正確,輸入錯誤則“錯誤次數”+1,成功登錄則“錯誤次數”清零 if(tb_password.Text!=dt.Rows[0]["Password"].ToString()) { //錯誤次數+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; } //經過以上驗證用戶名密碼無錯執行以下代碼(設置錯誤次數為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; //設置用戶權限以及初始化主界面的相關參數 if (dt.Rows[0]["Post"].ToString() == "管理員") { fm_public.userpower = "管理員"; } else { fm_public.userpower = "服務員"; } 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("確定退出系統嗎?", "提示", 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#實現餐廳管理系統
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。