欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)簡(jiǎn)單的點(diǎn)餐系統(tǒng)

 更新時(shí)間:2022年01月20日 12:06:23   作者:talent_wei  
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)簡(jiǎn)單的點(diǎn)餐系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文項(xiàng)目為大家分享了C#實(shí)現(xiàn)點(diǎn)餐系統(tǒng),供大家參考,具體內(nèi)容如下

項(xiàng)目介紹:一家店鋪使用的外賣點(diǎn)餐系統(tǒng)
本項(xiàng)目分三大模塊:登錄注冊(cè)模塊,用戶模塊,店家模塊

1.登錄注冊(cè)模塊

登錄分為用戶登錄和管理員登錄(店家),管理員有且只有一個(gè)賬號(hào)可以登錄。用戶登錄需要先注冊(cè),注冊(cè)必須用手機(jī)號(hào)注冊(cè)。

登錄界面效果圖

登錄主要就是判斷,多加些判斷就行了

登錄代碼展示: 

#region 窗體效果
? ? ? ? public class Win32
? ? ? ? {
? ? ? ? ? ? public const Int32 AW_HOR_POSITIVE = 0x00000001; // 從左到右打開窗口
? ? ? ? ? ? public const Int32 AW_HOR_NEGATIVE = 0x00000002; // 從右到左打開窗口
? ? ? ? ? ? public const Int32 AW_VER_POSITIVE = 0x00000004; // 從上到下打開窗口
? ? ? ? ? ? public const Int32 AW_VER_NEGATIVE = 0x00000008; // 從下到上打開窗口
? ? ? ? ? ? public const Int32 AW_CENTER = 0x00000010; //若使用了AW_HIDE標(biāo)志,則使窗口向內(nèi)重疊;若未使用AW_HIDE標(biāo)志,則使窗口向外擴(kuò)展。
? ? ? ? ? ? public const Int32 AW_HIDE = 0x00010000; //隱藏窗口,缺省則顯示窗口。
? ? ? ? ? ? public const Int32 AW_ACTIVATE = 0x00020000; //激活窗口。在使用了AW_HIDE標(biāo)志后不要使用這個(gè)標(biāo)志。
? ? ? ? ? ? public const Int32 AW_SLIDE = 0x00040000; //使用滑動(dòng)類型。缺省則為滾動(dòng)動(dòng)畫類型。當(dāng)使用AW_CENTER標(biāo)志時(shí),這個(gè)標(biāo)志就被忽略。
? ? ? ? ? ? public const Int32 AW_BLEND = 0x00080000; //使用淡出效果。只有當(dāng)hWnd為頂層窗口的時(shí)候才可以使用此標(biāo)志。
? ? ? ? ? ? [DllImport("user32.dll", CharSet = CharSet.Auto)]
? ? ? ? ? ? public static extern bool AnimateWindow(
? ? ? ? ? IntPtr hwnd, // handle to window
? ? ? ? ? ? ? int dwTime, // duration of animation
? ? ? ? ? ? ? int dwFlags // animation type
? ? ? ? ? ? ? );
? ? ? ? }
? ? ? ? #endregion
? ? ? ? ValidCode validCode = new ValidCode(5, ValidCode.CodeType.Numbers);//實(shí)例化這個(gè)對(duì)象
? ? ? ??
? ? ? ? //窗體加載
? ? ? ? private void Login_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? picValidCode.Image = Bitmap.FromStream(validCode.CreateCheckCodeImage());//點(diǎn)擊圖片更換驗(yàn)證碼
? ? ? ? ? ? Win32.AnimateWindow(this.Handle,500, Win32.AW_VER_POSITIVE);//窗體出現(xiàn)效果
? ? ? ? }

? ? ? ? //驗(yàn)證碼圖片
? ? ? ? private void picValidCode_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? picValidCode.Image = Bitmap.FromStream(validCode.CreateCheckCodeImage());//點(diǎn)擊圖片更換驗(yàn)證碼
? ? ? ? }

? ? ? ? //注冊(cè)
? ? ? ? private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
? ? ? ? {
? ? ? ? ? ? Enroll EN = new Enroll();
? ? ? ? ? ? this.Hide();
? ? ? ? ? ? EN.ShowDialog();
? ? ? ? ? ? Application.ExitThread();
? ? ? ? }

? ? ? ? //登錄按鈕
? ? ? ? private void LoginButton_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Saveusername.name = Username.Text;
? ? ? ? ? ? string sql = string.Format("select * from UserList where UserID='{0}'and UserPassword='{1} '", Username.Text, password.Text);
? ? ? ? ? ? SqlDataReader reader = DBHelper.GetDataReader(sql);
? ? ? ? ? ? if (Username.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入用戶名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? }
? ? ? ? ? ? else if (password.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入密碼!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? }
? ? ? ? ? ? else if (!this.txtValidCode.Text.Equals(validCode.CheckCode))//驗(yàn)證是否輸入正確
? ? ? ? ? ? {

? ? ? ? ? ? ? ? MessageBox.Show(" 請(qǐng)輸入正確的驗(yàn)證碼!", this.Text);

? ? ? ? ? ? ? ? this.txtValidCode.Focus();
? ? ? ? ? ? ? ? this.txtValidCode.Text = "";
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return;

? ? ? ? ? ? }
? ? ? ? ? ? else if (reader.Read())
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Saveusername.ID = reader["ID"].ToString();//獲取ID用于個(gè)人中心修改信息
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? if (Saveusername.name=="Sweet")
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? 管理員界面.GLY gLY = new 管理員界面.GLY();
? ? ? ? ? ? ? ? ? ? this.Hide();
? ? ? ? ? ? ? ? ? ? gLY.ShowDialog();
? ? ? ? ? ? ? ? ? ? Application.ExitThread();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? XMB xMB = new XMB();
? ? ? ? ? ? ? ? this.Hide();
? ? ? ? ? ? ? ? xMB.ShowDialog();
? ? ? ? ? ? ? ? Application.ExitThread();
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("用戶名或密碼輸入錯(cuò)誤!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
? ? ? ? ? ? }
? ? ? ? ? ? reader.Close();

? ? ? ? ? ? picValidCode.Image = Bitmap.FromStream(validCode.CreateCheckCodeImage());//點(diǎn)擊圖片更換驗(yàn)證碼
? ? ? ? }

? ? ? ? //忘記密碼
? ? ? ? private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e)
? ? ? ? {
? ? ? ? ? ? ForgetPwd forget = new ForgetPwd();
? ? ? ? ? ? this.Hide();
? ? ? ? ? ? forget.ShowDialog();
? ? ? ? ? ? Application.ExitThread();
? ? ? ? }
? ? ? ? #region 用于窗體移動(dòng)
? ? ? ? private Point mPoint;//定義一個(gè)位置信息Point用于存儲(chǔ)鼠標(biāo)位置
? ? ? ? private void Login_MouseDown(object sender, MouseEventArgs e)
? ? ? ? {
? ? ? ? ? ? mPoint = new Point(e.X, e.Y);
? ? ? ? }

? ? ? ? private void Login_MouseMove(object sender, MouseEventArgs e)
? ? ? ? {
? ? ? ? ? ? if (e.Button == MouseButtons.Left)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? #endregion

? ? ? ? private void Login_FormClosed(object sender, FormClosedEventArgs e)
? ? ? ? {
? ? ? ? ? ? Win32.AnimateWindow(this.Handle, 500, Win32.AW_BLEND|Win32.AW_HIDE);
? ? ? ? }

? ? ? ? private void pictureBox3_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.Close();
? ? ? ? }

? ? ? ? private void pictureBox4_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? this.WindowState = FormWindowState.Minimized;//最小化
? ? ? ? }

圖片驗(yàn)證碼代碼展示:

public class ValidCode
? ? {
? ? ? ? #region Private Fields
? ? ? ? private const double PI = 3.1415926535897932384626433832795;
? ? ? ? private const double PI2 = 6.283185307179586476925286766559;
? ? ? ? //private readonly int _wordsLen = 4;?
? ? ? ? private int _len;
? ? ? ? private CodeType _codetype;
? ? ? ? private readonly Single _jianju = (float)18.0;
? ? ? ? private readonly Single _height = (float)24.0;
? ? ? ? private string _checkCode;
? ? ? ? #endregion
? ? ? ? #region Public Property
? ? ? ? public string CheckCode
? ? ? ? {

? ? ? ? ? ? get
? ? ? ? ? ? {
? ? ? ? ? ? ? ?return _checkCode;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? #endregion
? ? ? ? #region Constructors
? ? ? ? /// <summary>?
? ? ? ? /// public constructors?
? ? ? ? /// </summary>?
? ? ? ? /// <param name="len"> 驗(yàn)證碼長(zhǎng)度 </param>?
? ? ? ? /// <param name="ctype"> 驗(yàn)證碼類型:字母、數(shù)字、字母+ 數(shù)字 </param>?
? ? ? ? public ValidCode(int len, CodeType ctype)
? ? ? ? {

? ? ? ? ? ? this._len = len;
? ? ? ? ? ? this._codetype = ctype;

? ? ? ? }

? ? ? ? #endregion
? ? ? ? #region Public Field
? ? ? ? public enum CodeType { Words, Numbers, Characters, Alphas }
? ? ? ? #endregion
? ? ? ? #region Private Methods

? ? ? ? private string GenerateNumbers()
? ? ? ? {
? ? ? ? ? ? string strOut = "";
? ? ? ? ? ? System.Random random = new Random();
? ? ? ? ? ? for (int i = 0; i < _len; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? string num = Convert.ToString(random.Next(10000) % 10);
? ? ? ? ? ? ? ? strOut += num;

? ? ? ? ? ? }

? ? ? ? ? ? return strOut.Trim();

? ? ? ? }

? ? ? ? private string GenerateCharacters()
? ? ? ? {
? ? ? ? ? ? string strOut = "";
? ? ? ? ? ? System.Random random = new Random();
? ? ? ? ? ? for (int i = 0; i < _len; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? string num = Convert.ToString((char)(65 + random.Next(10000) % 26));
? ? ? ? ? ? ? ? strOut += num;

? ? ? ? ? ? }

? ? ? ? ? ? return strOut.Trim();

? ? ? ? }

? ? ? ? //?

? ? ? ? private string GenerateAlphas()
? ? ? ? {
? ? ? ? ? ? string strOut = "";
? ? ? ? ? ? string num = "";
? ? ? ? ? ? System.Random random = new Random();
? ? ? ? ? ? for (int i = 0; i < _len; i++)
? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (random.Next(500) % 2 == 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? num = Convert.ToString(random.Next(10000) % 10);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ?{
? ? ? ? ? ? ? ? ? ?num = Convert.ToString((char)(65 + random.Next(10000) % 26));
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? strOut += num;

? ? ? ? ? ? }

? ? ? ? ? ? return strOut.Trim();

? ? ? ? }

? ? ? ? private System.Drawing.Bitmap TwistImage(Bitmap srcBmp, bool bXDir, double dMultValue, double dPhase)
? ? ? ? {
? ? ? ? ? ? System.Drawing.Bitmap destBmp = new Bitmap(srcBmp.Width, srcBmp.Height);

? ? ? ? ? ? // 將位圖背景填充為白色?
? ? ? ? ? ? System.Drawing.Graphics graph = System.Drawing.Graphics.FromImage(destBmp);
? ? ? ? ? ? graph.FillRectangle(new SolidBrush(System.Drawing.Color.White), 0, 0, destBmp.Width, destBmp.Height);
? ? ? ? ? ? graph.Dispose();

? ? ? ? ? ? double dBaseAxisLen = bXDir ? (double)destBmp.Height : (double)destBmp.Width;

? ? ? ? ? ? for (int i = 0; i < destBmp.Width; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int j = 0; j < destBmp.Height; j++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? double dx = 0;
? ? ? ? ? ? ? ? ? ? dx = bXDir ? (PI2 * (double)j) / dBaseAxisLen : (PI2 * (double)i) / dBaseAxisLen;
? ? ? ? ? ? ? ? ? ? dx += dPhase;
? ? ? ? ? ? ? ? ? ? double dy = Math.Sin(dx);
?
? ? ? ? ? ? ? ? ? ? // 取得當(dāng)前點(diǎn)的顏色?
? ? ? ? ? ? ? ? ? ? int nOldX = 0, nOldY = 0;
? ? ? ? ? ? ? ? ? ? nOldX = bXDir ? i + (int)(dy * dMultValue) : i;
? ? ? ? ? ? ? ? ? ? nOldY = bXDir ? j : j + (int)(dy * dMultValue);

? ? ? ? ? ? ? ? ? ? System.Drawing.Color color = srcBmp.GetPixel(i, j);
? ? ? ? ? ? ? ? ? ? if (nOldX >= 0 && nOldX < destBmp.Width
? ? ? ? ? ? ? ? ? ? ?&& nOldY >= 0 && nOldY < destBmp.Height)
? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? destBmp.SetPixel(nOldX, nOldY, color);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? return destBmp;

? ? ? ? }
? ? ? ? #endregion
? ? ? ? #region Public Methods
? ? ? ? public Stream CreateCheckCodeImage()
? ? ? ? {
? ? ? ? ? ? string checkCode;

? ? ? ? ? ? switch (_codetype)
? ? ? ? ? ? {

? ? ? ? ? ? ? ? case CodeType.Alphas:
? ? ? ? ? ? ? ? ? ? checkCode = GenerateAlphas();
? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case CodeType.Numbers:
? ? ? ? ? ? ? ? ? ? checkCode = GenerateNumbers();
? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case CodeType.Characters:
? ? ? ? ? ? ? ? ? ? checkCode = GenerateCharacters();
? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? ? ? checkCode = GenerateAlphas();
? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? this._checkCode = checkCode;
? ? ? ? ? ? MemoryStream ms = null;
? ? ? ? ? ? //?
? ? ? ? ? ? if (checkCode == null || checkCode.Trim() == String.Empty)
? ? ? ? ? ? ? ?return null;

? ? ? ? ? ? Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * _jianju)), (int)_height);
? ? ? ? ? ? Graphics g = Graphics.FromImage(image);

? ? ? ? ? ? try
? ? ? ? ? ? {

? ? ? ? ? ? ? ? Random random = new Random();
? ? ? ? ? ? ? ? g.Clear(Color.White);
? ? ? ? ? ? ? ? // 畫圖片的背景噪音線?
? ? ? ? ? ? ? ? for (int i = 0; i < 18; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int x1 = random.Next(image.Width);
? ? ? ? ? ? ? ? ? ? int x2 = random.Next(image.Width);
? ? ? ? ? ? ? ? ? ? int y1 = random.Next(image.Height);
? ? ? ? ? ? ? ? ? ? int y2 = random.Next(image.Height);

? ? ? ? ? ? ? ? ? ? g.DrawLine(new Pen(Color.FromArgb(random.Next()), 1), x1, y1, x2, y2);

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Font font = new System.Drawing.Font("Times New Roman", 14, System.Drawing.FontStyle.Bold);
? ? ? ? ? ? ? ? LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true);
? ? ? ? ? ? ? ? if (_codetype != CodeType.Words)
? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? for (int i = 0; i < checkCode.Length; i++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? g.DrawString(checkCode.Substring(i, 1), font, brush, 2 + i * _jianju, 1);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? g.DrawString(checkCode, font, brush, 2, 2);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? // 畫圖片的前景噪音點(diǎn)?
? ? ? ? ? ? ? ? for (int i = 0; i < 150; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? int x = random.Next(image.Width);
? ? ? ? ? ? ? ? ? ? int y = random.Next(image.Height);
? ? ? ? ? ? ? ? ? ? image.SetPixel(x, y, Color.FromArgb(random.Next()));

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? // 畫圖片的波形濾鏡效果?
? ? ? ? ? ? ? ? if (_codetype != CodeType.Words)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ?image = TwistImage(image, true, 3, 1);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? // 畫圖片的邊框線?
? ? ? ? ? ? ? ? g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
? ? ? ? ? ? ? ? ms = new System.IO.MemoryStream();
? ? ? ? ? ? ? ? image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);

? ? ? ? ? ? }

? ? ? ? ? ? finally
? ? ? ? ? ? {

? ? ? ? ? ? ? ? g.Dispose();
? ? ? ? ? ? ? ? image.Dispose();
? ? ? ? ? ? }

? ? ? ? ? ? return ms;
? ? ? ? }
?
#endregion

注冊(cè)界面效果圖

注冊(cè)界面代碼展示

短信驗(yàn)證碼,用接口就能實(shí)現(xiàn)

?TimeSpan dtTo = new TimeSpan(0, 0, 60);//設(shè)置計(jì)時(shí)器的開始時(shí)間
? ? ? ? int value;//用來(lái)存儲(chǔ)隨機(jī)數(shù)
? ? ? ? public Enroll()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? }

? ? ? ? //獲取短信驗(yàn)證碼
? ? ? ? private void CodeButton_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Regex rx = new Regex(@"^0{0,1}(13[0-9]|15[0-9]|15[0-9]|18[0-9]|17[0-9])[0-9]{8}$");
? ? ? ? ? ? if (!rx.IsMatch(EnrollTel.Text))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? EnrollTel.Text = "";
? ? ? ? ? ? ? ? MessageBox.Show("手機(jī)號(hào)格式不正確,請(qǐng)重新輸入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Random rad = new Random();//實(shí)例化隨機(jī)數(shù)產(chǎn)生器rad;
? ? ? ? ? ? ? ? value = rad.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的隨機(jī)數(shù);
? ? ? ? ? ? ? ? Note.NoTe(EnrollTel.Text, value);
? ? ? ? ? ? ? ? timer1.Start();
? ? ? ? ? ? ? ? dtTo = new TimeSpan(0, 0, 60);
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? //時(shí)間控件用來(lái)實(shí)現(xiàn)60秒倒計(jì)時(shí)
? ? ? ? private void timer1_Tick_1(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? CodeButton.Enabled = false;
? ? ? ? ? ? dtTo = dtTo.Subtract(new TimeSpan(0, 0, 1));//每隔一秒減一
? ? ? ? ? ? CodeButton.Text = "(" + dtTo.Seconds.ToString() + ")" + "重新獲取";

? ? ? ? ? ? if (dtTo.TotalSeconds == 0.0)//當(dāng)?shù)褂?jì)時(shí)完畢
? ? ? ? ? ? {
? ? ? ? ? ? ? ? this.CodeButton.Enabled = true;
? ? ? ? ? ? ? ? CodeButton.Text = "點(diǎn)擊獲取驗(yàn)證碼";
? ? ? ? ? ? ? ? this.timer1.Stop();
? ? ? ? ? ? ? ? timer1.Dispose();
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? //注冊(cè)按鈕
? ? ? ? private void FinishButton_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? bool Bool = Fac();
? ? ? ? ? ? if (Bool)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? string type = "普通用戶";
? ? ? ? ? ? ? ? string sex = "";
? ? ? ? ? ? ? ? if (RadioMan.Checked)//判斷單選按鈕的text
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sex = RadioMan.Text;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else if (RadioWoman.Checked)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sex = RadioWoman.Text;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? string sql = string.Format("insert into UserList values('{0}','{1}','{2}','{3}','{4}','{5}')", EnrollUser.Text, EnrollPwd.Text, sex, EnrollTel.Text, EnrollAddress.Text, type);
? ? ? ? ? ? ? ? bool sqlinsert = DBHelper.ExecuteNonQuery(sql);
? ? ? ? ? ? ? ? if (sqlinsert)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? DialogResult result = MessageBox.Show("注冊(cè)成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
? ? ? ? ? ? ? ? ? ? this.Hide();
? ? ? ? ? ? ? ? ? ? Login LG = new Login();
? ? ? ? ? ? ? ? ? ? LG.ShowDialog();
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? /// <summary>
? ? ? ? /// 用于注冊(cè)界面里格式的判斷
? ? ? ? /// </summary>
? ? ? ? /// <returns></returns>
? ? ? ? private bool Fac()
? ? ? ? {
? ? ? ? ? ? string sql = string.Format("select * from UserList where UserID='{0}'", EnrollUser.Text);
? ? ? ? ? ? SqlDataReader reader = DBHelper.GetDataReader(sql);
? ? ? ? ? ? if (EnrollUser.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("用戶名不能為空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (EnrollPwd.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入密碼!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (EnrollPwd.Text != EnrollPwdY.Text)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("兩次密碼必須一樣!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (EnrollTel.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入手機(jī)號(hào)!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (EtxtValidCode.Text == "")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入驗(yàn)證碼!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (int.Parse(EtxtValidCode.Text) != value)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)輸入正確的驗(yàn)證碼!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? }
? ? ? ? ? ? else if (reader.Read())
? ? ? ? ? ? {
? ? ? ? ? ? ? ? DialogResult result = MessageBox.Show("此用戶已存在,是否前往登錄?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
? ? ? ? ? ? ? ? if (result == DialogResult.Yes)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Login LG = new Login();
? ? ? ? ? ? ? ? ? ? LG.ShowDialog();
? ? ? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? ? ? this.Close();
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? reader.Close();
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? //窗體加載事件
? ? ? ? private void Enroll_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? CodeButton.Text = "點(diǎn)擊獲取驗(yàn)證碼";
? ? ? ? ? ? timer1.Interval = 1000;//設(shè)置每次間隔一秒

? ? ? ? }

忘記密碼界面效果圖

下面為用戶界面的展示

簡(jiǎn)單介紹一下:由于菜品是有很多的而且不確定數(shù)量,所以必須動(dòng)態(tài)加載,不能拖圖片控件等。
用戶功能實(shí)現(xiàn)思路:首先要知道每個(gè)用戶只能看自己的,所以在登錄時(shí)候就必須用一個(gè)東西接收用戶輸入的名字,以便在主界面顯示出與該用戶相匹配的數(shù)據(jù)。

購(gòu)物車界面

購(gòu)物車首先要有一個(gè)購(gòu)物車表用來(lái)存儲(chǔ)用戶添加的商品,當(dāng)用戶結(jié)賬以后,購(gòu)物車表中該用戶的信息就應(yīng)全部清除。然后為該用戶生成訂單(存入信息到訂單表),并將用戶購(gòu)買的商品存入訂單詳情表中。

動(dòng)態(tài)加載菜品代碼展示

private void XMB_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? /*SetStyle(ControlStyles.UserPaint, true);
? ? ? ? ? ? SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
? ? ? ? ? ? SetStyle(ControlStyles.DoubleBuffer, true); // 雙緩沖*/
? ? ? ? ? ? linke_熱菜.LinkColor = Color.Gray;
? ? ? ? ? ? Win32.AnimateWindow(this.Handle, 500, Win32.AW_CENTER);//窗體出現(xiàn)效果
? ? ? ? ? ? Order_pl.Visible = false;
? ? ? ? ? ? Or_panel1.Visible = false;//隱藏訂單控件
? ? ? ? ? ? menu_all_全部.AutoScroll = true;//添加滾動(dòng)條
? ? ? ? ? ? this.toolStripStatusLabel1.Font = new Font("微軟雅黑", 12, FontStyle.Bold);
? ? ? ? ? ? toolStripStatusLabel1.Text = string.Format("歡迎“{0}”使用Sweet點(diǎn)餐系統(tǒng)! ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ", Saveusername.name);
? ? ? ? ? ? this.timer2.Start();

? ? ? ? ? ? string sql = "select * from Food_table";
? ? ? ? ? ? DataSet ds = DBHelper.GetDataSet(sql);
? ? ? ? ? ? int xx = 0;
? ? ? ? ? ? int yy = 0;
? ? ? ? ? ? for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Label FoodName = new Label();
? ? ? ? ? ? ? ? Label FoodPrice = new Label();
? ? ? ? ? ? ? ? PictureBox picture = new PictureBox();
? ? ? ? ? ? ? ? Button button = new Button();//創(chuàng)建控件
? ? ? ? ? ? ? ? FoodName.Name = "FoodName_" + i;
? ? ? ? ? ? ? ? FoodPrice.Name = "FoodPrice_" + i;
? ? ? ? ? ? ? ? picture.Name = "picture_" + i;
? ? ? ? ? ? ? ? button.Name = ds.Tables[0].Rows[i]["FoodID"].ToString();//加入購(gòu)物車按鈕命名為菜品表的FoodID
? ? ? ? ? ? ? ? FoodName.Text = ds.Tables[0].Rows[i]["FoodName"].ToString();
? ? ? ? ? ? ? ? FoodPrice.Text = "¥" + ds.Tables[0].Rows[i]["FoodPrice"].ToString() + "/份";//控件text屬性賦值
? ? ? ? ? ? ? ? button.Text = "加入購(gòu)物車";
? ? ? ? ? ? ? ? FoodName.AutoSize = true;
? ? ? ? ? ? ? ? FoodPrice.AutoSize = true;
? ? ? ? ? ? ? ? button.AutoSize = true;
? ? ? ? ? ? ? ? FoodName.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? FoodPrice.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? button.Font = new Font("微軟雅黑", 6);
? ? ? ? ? ? ? ? button.BackColor = Color.Gray;
? ? ? ? ? ? ? ? button.ForeColor = Color.Transparent;
? ? ? ? ? ? ? ? button.FlatStyle = FlatStyle.Flat;
? ? ? ? ? ? ? ? button.Size = new Size(60, 10);
? ? ? ? ? ? ? ? picture.Location = new Point(100 * xx, 20 + yy);
? ? ? ? ? ? ? ? FoodName.Location = new Point(100 * xx, 100 + yy);
? ? ? ? ? ? ? ? FoodPrice.Location = new Point(100 * xx, 120 + yy);
? ? ? ? ? ? ? ? button.Location = new Point(100 * xx, 140 + yy);//控件定位
? ? ? ? ? ? ? ? picture.Image = Image.FromFile(Application.StartupPath + @"\FoodPhoto\" + ds.Tables[0].Rows[i]["PhotoName"].ToString());//顯示圖片,路徑為可執(zhí)行文件所在文件夾的FoodPhoto文件夾內(nèi)的圖片
? ? ? ? ? ? ? ? picture.SizeMode = PictureBoxSizeMode.StretchImage;
? ? ? ? ? ? ? ? picture.Size = new Size(150, 80);
? ? ? ? ? ? ? ? picture.BorderStyle = BorderStyle.FixedSingle;
? ? ? ? ? ? ? ? button.Cursor = Cursors.Hand;
? ? ? ? ? ? ? ? button.Click += new EventHandler(this.Button_Click);
? ? ? ? ? ? ? ? menu_all_全部.Controls.Add(FoodName);
? ? ? ? ? ? ? ? menu_all_全部.Controls.Add(FoodPrice);
? ? ? ? ? ? ? ? menu_all_全部.Controls.Add(picture);
? ? ? ? ? ? ? ? menu_all_全部.Controls.Add(button);//把控件綁定到panel中
? ? ? ? ? ? ? ? xx++;
? ? ? ? ? ? ? ? if (xx++ >= 4)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? xx = 0;
? ? ? ? ? ? ? ? ? ? yy += 180;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }

動(dòng)態(tài)加載菜品解決窗體控件閃爍問題代碼展示

protected override CreateParams CreateParams//解決窗體控件閃爍問題
? ? ? ? {
? ? ? ? ? ? get

? ? ? ? ? ? {
? ? ? ? ? ? ? ? CreateParams cp = base.CreateParams;
? ? ? ? ? ? ? ? cp.ExStyle |= 0x02000000;
? ? ? ? ? ? ? ? return cp;

? ? ? ? ? ? }

}

加入購(gòu)物車按鈕代碼展示

?#region 購(gòu)物車
? ? ? ? private void 購(gòu)物車_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
? ? ? ? {
? ? ? ? ? ? ?// 禁止用戶改變DataGridView1的所有列的列寬
? ? ? ? ? ? dataGridView1.AllowUserToResizeColumns = false;
? ? ? ? ? ? //禁止用戶改變DataGridView1所有行的行高
? ? ? ? ? ? dataGridView1.AllowUserToResizeRows = false;
? ? ? ? ? ? dataGridView1.Columns[0].ReadOnly = true; //禁止用戶編輯第一列
? ? ? ? ? ? dataGridView1.Columns[1].ReadOnly = true; //禁止用戶編輯第二列
? ? ? ? ? ? dataGridView1.Columns[2].ReadOnly = true;//禁止用戶編輯第三列
? ? ? ? ? ? this.dataGridView1.AllowUserToResizeColumns = false; //禁止用戶拖動(dòng)標(biāo)題寬度
? ? ? ? ? ? dataGridView1.AutoGenerateColumns = false;//取消自動(dòng)生成列
? ? ? ? ? ? dataGridView1.RowHeadersVisible = false; //隱藏前面空白選擇部分 ? ??
? ? ? ? ? ? string sql = string.Format("select FoodName,ShoppingCount,ShoppingPrice,ShoppingID from Food_table join Shopping_table on Food_table.FoodID=Shopping_table.FoodID join UserList on '{0}'=Shopping_table.UserID where UserList.UserID='{1}'", Saveusername.name,Saveusername.name);//三表查詢
? ? ? ? ? ? dataGridView1.DataSource = DBHelper.GetDataSet(sql).Tables[0];
? ? ? ? ? ? double SumPrice = 0;//用來(lái)存儲(chǔ)總金額
? ? ? ? ? ? if (DBHelper.GetDataSet(sql).Tables[0].Rows.Count > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int i = 0; i < DBHelper.GetDataSet(sql).Tables[0].Rows.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? SumPrice += double.Parse(DBHelper.GetDataSet(sql).Tables[0].Rows[i][2].ToString());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Money_label.Text = "¥" + SumPrice.ToString() + "元";
? ? ? ? ? ? }
? ? ? ? ? ? dataGridView1.ClearSelection(); //取消默認(rèn)選中
? ? ? ? ? ? if (show_shopping_pl.Visible == true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? show_shopping_pl.Visible = false;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? show_shopping_pl.Visible = true;
? ? ? ? ? ? }
? ? ? ? ? ? if (Or_panel1.Visible == true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Or_panel1.Visible = false;
? ? ? ? ? ? }
? ? ? ? ? ? if (Order_pl.Visible == true)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Order_pl.Visible = false;
? ? ? ? ? ? }
? ? ? ? }

? ? ? ? //清空購(gòu)物車
? ? ? ? private void delete_label_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
? ? ? ? {
? ? ? ? ? ? DialogResult result = MessageBox.Show("是否清空購(gòu)物車", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
? ? ? ? ? ? if (result == DialogResult.OK)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? string sql = string.Format("delete from Shopping_table where UserID='{0}'", Saveusername.name);
? ? ? ? ? ? ? ? if (DBHelper.ExecuteNonQuery(sql))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sql = string.Format("select FoodName,ShoppingCount,ShoppingPrice,ShoppingID from Food_table join Shopping_table on Food_table.FoodID=Shopping_table.FoodID join UserList on '{0}'=Shopping_table.UserID ", Saveusername.name);
? ? ? ? ? ? ? ? ? ? dataGridView1.DataSource = DBHelper.GetDataSet(sql);
? ? ? ? ? ? ? ? ? ? dataGridView1.AllowUserToAddRows = false;
? ? ? ? ? ? ? ? ? ? Money_label.Text = "¥0元";
? ? ? ? ? ? ? ? ? ? MessageBox.Show("成功清空購(gòu)物車!", "提示", MessageBoxButtons.OK);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ??
? ? ? ? #endregion

主界面結(jié)賬功能界面

結(jié)賬部分代碼展示

?private void Yes_Order_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Or_label1.Text = "["+Saveusername.name+"]" + ">確認(rèn)購(gòu)買";
? ? ? ? ? ? dataGridView1.RowHeadersVisible = false; //隱藏前面空白選擇部分
? ? ? ? ? ? // ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 禁止用戶改變DataGridView1的所有列的列寬
? ? ? ? ? ? //dataGridView1.AllowUserToResizeColumns = false;
? ? ? ? ? ? 禁止用戶改變DataGridView1所有行的行高
? ? ? ? ? ? //dataGridView1.AllowUserToResizeRows = false;
? ? ? ? ? ? dataGridView1.Columns[0].ReadOnly = true; //禁止用戶編輯第一列
? ? ? ? ? ? dataGridView1.Columns[1].ReadOnly = true; //禁止用戶編輯第二列
? ? ? ? ? ? dataGridView1.Columns[2].ReadOnly = true;//禁止用戶編輯第三列
? ? ? ? ? ? this.dataGridView1.AllowUserToResizeColumns = false; //禁止用戶拖動(dòng)標(biāo)題寬度
? ? ? ? ? ? dataGridView1.AutoGenerateColumns = false;//取消自動(dòng)生成列
? ? ? ? ? ? dataGridView1.RowHeadersVisible = false; //隱藏前面空白選擇部分 ? ??
? ? ? ? ? ? string sql = string.Format("select FoodName,ShoppingCount,ShoppingPrice,ShoppingID from Food_table join Shopping_table on Food_table.FoodID=Shopping_table.FoodID join UserList on '{0}'=Shopping_table.UserID where UserList.UserID='{1}'", Saveusername.name,Saveusername.name);//三表查詢
? ? ? ? ? ? dataGridView1.DataSource = DBHelper.GetDataSet(sql).Tables[0];
? ? ? ? ? ? ?SumPrice = 0;//用來(lái)存儲(chǔ)總金額
? ? ? ? ? ? if (DBHelper.GetDataSet(sql).Tables[0].Rows.Count > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int i = 0; i < DBHelper.GetDataSet(sql).Tables[0].Rows.Count; i++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? SumPrice += double.Parse(DBHelper.GetDataSet(sql).Tables[0].Rows[i][2].ToString());
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Money_label.Text = "¥" + SumPrice.ToString() + "元";
? ? ? ? ? ? }
? ? ? ? ? ? dataGridView1.ClearSelection(); //取消默認(rèn)選中
? ? ? ? ? ? string sql_1 = string.Format("select * from UserList where UserID='{0}'",Saveusername.name);
? ? ? ? ? ? DataSet ds = DBHelper.GetDataSet(sql_1);
? ? ? ? ? ? Name_label.Text = ds.Tables[0].Rows[0]["UserID"].ToString()+":";
? ? ? ? ? ? Tel_label.Text = ds.Tables[0].Rows[0]["UserTel"].ToString();
? ? ? ? ? ? Address_label.Text = ds.Tables[0].Rows[0]["UserAddress"].ToString();
? ? ? ? ? ? Yes_Money_label.Text = Money_label.Text;
? ? ? ? }
? ? ? ? private void Yes_pay_btn_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (Address_label.Text=="")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("地址信息不完整,請(qǐng)?zhí)顚懲暾?, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? }
? ? ? ? ? ? string Order_Data = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); //下單日期
? ? ? ? ? ? string OrderNumber = DateTime.Now.ToString("yyyyMMddhhmmss");//訂單編號(hào)
? ? ? ? ? ? string sql = string.Format("select * from Shopping_table where UserID='{0}'",Saveusername.name);//查詢購(gòu)物車表
? ? ? ? ? ? DataTable table_shopping = DBHelper.GetDataSet(sql).Tables[0];
? ? ? ? ? ? if (table_shopping.Rows.Count>0)//購(gòu)物車有數(shù)據(jù)就創(chuàng)建訂單
? ? ? ? ? ? {
? ? ? ? ? ? ? ?string sql_order = string.Format("insert into Order_table values('{0}','{1}','{2}','{3}','{4}','{5}')",OrderNumber,Saveusername.name,SumPrice,Address_label.Text,Order_Data,Tel_label.Text);//創(chuàng)建訂單
? ? ? ? ? ? ? ?string sql_state = string.Format("insert into OrderState_table values('{0}','{1}')",OrderNumber,"等待確認(rèn)");//訂單狀態(tài)
? ? ? ? ? ? ? ? if (DBHelper.ExecuteNonQuery(sql_order)&&DBHelper.ExecuteNonQuery(sql_state))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? sql_order = string.Format("select top 1 * from Order_table where UserID='{0}' order by OrderID desc",Saveusername.name);
? ? ? ? ? ? ? ? ? ? DataTable table_order = DBHelper.GetDataTable(sql_order);
? ? ? ? ? ? ? ? ? ? for (int i = 0; i < table_shopping.Rows.Count; i++)//把數(shù)據(jù)逐條插入訂單詳情表
? ? ? ? ? ? ? ? ? ? {
string sql_datailde = string.Format("insert into Datailedorder_table values('{0}','{1}','{2}','{3}')", int.Parse(table_shopping.Rows[i]["FoodID"].ToString()),int.Parse(table_shopping.Rows[i]["ShoppingCount"].ToString()),double.Parse(table_shopping.Rows[i]["ShoppingPrice"].ToString()),int.Parse(table_order.Rows[0]["OrderID"].ToString()));
? ? ? ? ? ? ? ? ? ? ? ? //try
? ? ? ? ? ? ? ? ? ? ? ? //{
DBHelper.ExecuteNonQuery(sql_datailde);
? ? ? ? ? ? ? ? ? ? ? ? //}
? ? ? ? ? ? ? ? ? ? ? ?/* catch (Exception)
? ? ? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? ? ? ? ? MessageBox.Show("異常");
? ? ? ? ? ? ? ? ? ? ? ? ? ? return
? ? ? ? ? ? ? ? ? ? ? ? }*/
? ? ? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? string sql_delete = string.Format("delete from Shopping_table where UserID='{0}'",Saveusername.name);
? ? ? ? ? ? ? ? ? ? DBHelper.ExecuteNonQuery(sql_delete);//創(chuàng)建訂單后清空購(gòu)物車
? ? ? ? ? ? ? ? ? ?DialogResult result= MessageBox.Show("支付成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? ? ? ? ? if (result==DialogResult.OK)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ?string sql_select = string.Format("select * from Shopping_table where UserID='{0}'",Saveusername.name);
? ? ? ? ? ? ? ? ? ? dataGridView1.DataSource = DBHelper.GetDataSet(sql_select).Tables[0];
? ? ? ? ? ? ? ? ? ? ? ? Money_label.Text = "¥0元";
? ? ? ? ? ? ? ? ? ? ? ? Yes_Money_label.Text = "¥0元";
? ? ? ? ? ? ? ? ? ? ? ? XMB.GetXMB.Money_label.Text = "¥0元";
? ? ? ? ? ? ? ? ? ? Order_Form order_ = new Order_Form();
? ? ? ? ? ? ? ? ? ? XMB.GetXMB.Or_from(order_);
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("未選擇菜品", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
? ? ? ? ? ? }
? ? ? ? }

訂單功能界面

點(diǎn)擊訂單,出現(xiàn)訂單詳情

訂單功能部分代碼

private void Order_Form_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? OR_panel.AutoScroll = true;//添加滾動(dòng)條
? ? ? ? ? ? int xx = 0;
? ? ? ? ? ? int yy = 0;
? ? ? ? ? ? string sql = string.Format("select * from Order_table where UserID='{0}'",Saveusername.name);
? ? ? ? ? ? DataTable Or_table = DBHelper.GetDataTable(sql);
DataTable State = DBHelper.GetDataTable(string.Format("select OrderState from OrderState_table join Order_table on Order_table.OrderNumber=OrderState_table.OrderNumber where Order_table.UserID='{0}'",Saveusername.name));
? ? ? ? ? ? for (int i = 0; i < Or_table.Rows.Count; i++)
? ? ? ? ? ? { ?
? ? ? ? ? ? ? ? Label OrderNumber = new Label();//編號(hào)
? ? ? ? ? ? ? ? Label ShoppingPrice = new Label();//價(jià)格
? ? ? ? ? ? ? ? Label SaleDate = new Label();//時(shí)間
? ? ? ? ? ? ? ? Label OrderState = new Label();//狀態(tài)
? ? ? ? ? ? ? ? Label sweet = new Label();
? ? ? ? ? ? ? ? Panel panel = new Panel();
? ? ? ? ? ? ? ? PictureBox Db = new PictureBox(); //實(shí)例化一個(gè)控件
? ? ? ? ? ? ? ? Db.Name = "Db_PictureBox" + i;//設(shè)定名稱
? ? ? ? ? ? ? ? OrderNumber.Name = "Label" + i;
? ? ? ? ? ? ? ? ShoppingPrice.Name = "Label" + i;
? ? ? ? ? ? ? ? SaleDate.Name = "Label" + i;
? ? ? ? ? ? ? ? OrderState.Name = "Label" + i;
? ? ? ? ? ? ? ? sweet.Name = "Label" + i;
? ? ? ? ? ? ? ? panel.Name = "Panel" + i;//設(shè)定名稱
? ? ? ? ? ? ? ? panel.Text = Or_table.Rows[i]["OrderID"].ToString();//把訂單ID賦給控件的Text,以便取消訂單
? ? ? ? ? ? ? ? SaleDate.Text = Or_table.Rows[i]["SaleDate"].ToString();
? ? ? ? ? ? ? ? ShoppingPrice.Text = " ¥ " + ?Or_table.Rows[i]["ShoppingPrice"].ToString();
? ? ? ? ? ? ? ? OrderNumber.Text = "訂單編號(hào): " + Or_table.Rows[i]["OrderNumber"].ToString();
? ? ? ? ? ? ? ? sweet.Text = "Sweet點(diǎn)餐";
? ? ? ? ? ? ? ? OrderState.Text = State.Rows[i]["OrderState"].ToString();
? ? ? ? ? ? ? ? sweet.Location = new Point(150,30);
? ? ? ? ? ? ? ? ShoppingPrice.Location = new Point(480,30);
? ? ? ? ? ? ? ? OrderState.Location = new Point(595,30);
? ? ? ? ? ? ? ? SaleDate.Location = new Point(150,70);
? ? ? ? ? ? ? ? OrderNumber.Location = new Point(450,70);
? ? ? ? ? ? ? ? Db.Location = new Point(15, 10 + yy);//設(shè)定位置
? ? ? ? ? ? ? ? panel.Location = new Point(5, 0 + yy);//設(shè)定位置
? ? ? ? ? ? ? ? sweet.AutoSize = true;
? ? ? ? ? ? ? ? OrderState.AutoSize = true;
? ? ? ? ? ? ? ? ShoppingPrice.AutoSize = true;
? ? ? ? ? ? ? ? SaleDate.AutoSize = true;
? ? ? ? ? ? ? ? OrderNumber.AutoSize = true;
? ? ? ? ? ? ? ? Db.Image = Image.FromFile(Application.StartupPath + @"\FoodPhoto\" + "sezhi.png");
? ? ? ? ? ? ? ? Db.SizeMode = PictureBoxSizeMode.StretchImage; //設(shè)定圖像如何顯示
? ? ? ? ? ? ? ? sweet.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? OrderNumber.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? OrderState.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? ShoppingPrice.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? SaleDate.Font = new Font("微軟雅黑", 11);
? ? ? ? ? ? ? ? Db.Size = new Size(80, 80);
? ? ? ? ? ? ? ? panel.Size = new Size(683, 100);
? ? ? ? ? ? ? ? Db.BorderStyle = BorderStyle.FixedSingle; //設(shè)置邊框樣式
? ? ? ? ? ? ? ? panel.BorderStyle = BorderStyle.FixedSingle; //設(shè)置邊框樣式
? ? ? ? ? ? ? ? panel.BackColor = Color.White;
? ? ? ? ? ? ? ? SaleDate.ForeColor = Color.Red;
? ? ? ? ? ? ? ? ShoppingPrice.ForeColor = Color.Red;
? ? ? ? ? ? ? ? OrderNumber.ForeColor = Color.Green;
? ? ? ? ? ? ? ? OrderState.ForeColor = Color.Green;
? ? ? ? ? ? ? ? panel.Cursor = Cursors.Hand;
? ? ? ? ? ? ? ? OR_panel.Controls.Add(Db);
? ? ? ? ? ? ? ? OR_panel.Controls.Add(panel);
? ? ? ? ? ? ? ? panel.Controls.Add(OrderState);
? ? ? ? ? ? ? ? panel.Controls.Add(sweet);
? ? ? ? ? ? ? ? panel.Controls.Add(OrderNumber);
? ? ? ? ? ? ? ? panel.Controls.Add(SaleDate);
? ? ? ? ? ? ? ? panel.Controls.Add(ShoppingPrice);
? ? ? ? ? ? ? ? panel.Click += new EventHandler(this.panel1_MouseClick); //添加單擊事件
? ? ? ? ? ? ? ? panel.MouseEnter += new EventHandler(this.panel1_MouseEnter); //添加單擊事件
? ? ? ? ? ? ? ? panel.MouseLeave += new EventHandler(this.panel1_MouseLeave); //添加單擊事件
? ? ? ? ? ? ? ? xx++;
? ? ? ? ? ? ? ? if (xx++ >= 1)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? yy += 110;
? ? ? ? ? ? ? ? ? ? //aa += 10;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }

接下來(lái)是管理員界面展示

1.菜品管理界面

菜品管理添加菜品關(guān)鍵代碼

private void Food_in_tbn_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? if (Fag() == false)
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? string FilePath = Application.StartupPath + @"\FoodPhoto";//獲取可執(zhí)行文件所在位置的FoodPhoto文件夾路徑
? ? ? ? ? ? if (Directory.Exists(FilePath) == false)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //判斷文件夾是否存在如果不存在創(chuàng)建文件夾
? ? ? ? ? ? ? ? Directory.CreateDirectory(FilePath);//創(chuàng)建文件夾
? ? ? ? ? ? }
? ? ? ? ? ? string FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + new Random().Next(1000, 9999);
? ? ? ? ? ? //以當(dāng)前時(shí)間和1000到9999的隨機(jī)數(shù)合起來(lái)作為文件的名字
? ? ? ? ? ? FileName += nj.Substring(nj.LastIndexOf("."));//截取圖片的后綴名
? ? ? ? ? ? File.Copy(nj, FilePath + @"\" + FileName);//把圖片復(fù)制到FoodPhoto文件夾
? ? ? ? ? ? string SQLst = string.Format("insert into Food_table values('{0}','{1}','{2}','{3}')", Add_Food_tb.Text,Add_money_tb.Text,Add_type_ctb.Text, FileName);
? ? ? ? ? ? if (DBHelper.ExecuteNonQuery(SQLst))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("菜品添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("保存失敗", "錯(cuò)誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? public static string nj;
? ? ? ? public static string name;
? ? ? ? private void pictureBox1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? //打開資源管理器選擇圖片
? ? ? ? ? ? OpenFileDialog openFileDialog1 = new OpenFileDialog();
? ? ? ? ? ? nj = "";
? ? ? ? ? ? name = "";
? ? ? ? ? ? if (openFileDialog1.ShowDialog() == DialogResult.OK)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? nj = openFileDialog1.FileName;
? ? ? ? ? ? ? ? pictureBox1.Image = Image.FromFile(nj);
? ? ?}

}

2.訂單管理界面

主要實(shí)現(xiàn)思路:動(dòng)態(tài)加載控件,控件定位,查詢數(shù)據(jù)庫(kù),修改表信息

3.銷售統(tǒng)計(jì)界面

點(diǎn)擊確認(rèn)訂單后會(huì)生成一個(gè)訂單,效果圖如下:

代碼展示

?private void Button_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Button button = (Button)sender;//將觸發(fā)此事件的對(duì)象轉(zhuǎn)換為該對(duì)象
? ? ? ? ? ? OrderID = int.Parse(button.Name.ToString());
? ? ? ? ? ? string FilePath = @"D:\訂單票據(jù)";//獲取可執(zhí)行文件所在位置的FoodPhoto文件夾路徑
? ? ? ? ? ? if (Directory.Exists(FilePath) == false)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //判斷文件夾是否存在如果不存在創(chuàng)建文件夾
? ? ? ? ? ? ? ? Directory.CreateDirectory(FilePath);//創(chuàng)建文件夾
? ? ? ? ? ? }
? ? ? ? ? ? string sql_12 = string.Format("select * from Order_table where OrderID='{0}'", OrderID);
? ? ? ? ? ? DataTable piao = DBHelper.GetDataTable(sql_12);
? ? ? ? ? ? for (int i = 0; i < piao.Rows.Count; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? StreamWriter sw = new StreamWriter(@"D:\訂單票據(jù)\Sweet點(diǎn)餐"+piao.Rows[0]["OrderNumber"].ToString()+".txt");
? ? ? ? ? ? ? ? string a = "訂單編號(hào):"+piao.Rows[i]["OrderNumber"].ToString();
? ? ? ? ? ? ? ? string b = "訂單內(nèi)容:";
? ? ? ? ? ? ? ? sw.WriteLine(a);
? ? ? ? ? ? ? ? sw.WriteLine("-------------------------------------------");
? ? ? ? ? ? ? ? sw.WriteLine(b);
? ? ? ? ? ? ? ? string sql_13 = "select Food_table.FoodName,Datailedorder_table.ShoppingCount,Datailedorder_table.ShoppingPrice from Order_table join Datailedorder_table on Datailedorder_table.OrderID=Order_table.OrderID join Food_table on Food_table.FoodID=Datailedorder_table.FoodID where Order_table.OrderNumber='" + piao.Rows[i]["OrderNumber"] + "'";//查找需要的菜品名稱,菜品購(gòu)買的數(shù)量,每一種菜品購(gòu)買的總金額
? ? ? ? ? ? ? ? DataTable table = DBHelper.GetDataTable(sql_13);
? ? ? ? ? ? ? ? for (int j = 0; j < table.Rows.Count; j++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? string FoodName = table.Rows[i]["FoodName"].ToString();
? ? ? ? ? ? ? ? ? ? string FoodCount = table.Rows[i]["ShoppingCount"].ToString();
? ? ? ? ? ? ? ? ? ? string ShoppingPrice = table.Rows[i]["ShoppingPrice"].ToString();
? ? ? ? ? ? ? ? ? ? sw.Write(" {0}",FoodName);
? ? ? ? ? ? ? ? ? ? sw.Write(" ? ? ? ? ?x{0}", FoodCount);
? ? ? ? ? ? ? ? ? ? sw.WriteLine(" ? ? ? ? ? ? ? ? ? ? ? ? ? ?{0}",ShoppingPrice);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? sw.WriteLine("-------------------------------------------");
? ? ? ? ? ? ? ? string sum = "總計(jì):"+piao.Rows[i]["ShoppingPrice"].ToString();
? ? ? ? ? ? ? ? string c = "聯(lián)系地址:";
? ? ? ? ? ? ? ? string Address = "聯(lián)系地址:"+piao.Rows[i]["Address"].ToString();
? ? ? ? ? ? ? ? string User = "聯(lián)系人:"+piao.Rows[i]["UserID"].ToString();
? ? ? ? ? ? ? ? string tel = "聯(lián)系電話:"+piao.Rows[i]["UserTel"].ToString();
? ? ? ? ? ? ? ? sw.WriteLine(sum);
? ? ? ? ? ? ? ? sw.WriteLine();
? ? ? ? ? ? ? ? sw.WriteLine(c);
? ? ? ? ? ? ? ? sw.WriteLine("-------------------------------------------");
? ? ? ? ? ? ? ? sw.WriteLine(User);
? ? ? ? ? ? ? ? sw.WriteLine(tel);
? ? ? ? ? ? ? ? sw.WriteLine(Address);
? ? ? ? ? ? ? ? sw.Close();
? ? ? ? ? ? }

我們的項(xiàng)目大概就這么多了,還有一些小功能沒有詳細(xì)介紹了。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論