那时候的小小记忆--KFC点菜系统

看着自己大二时候写的代码,好稚嫩啊。虽然现在也是稚嫩,哈哈。
虽然这个系统小,功能也不是很健壮。但那时候付出了很多时间,也是我的第一个花了好多时间,也有成就感 的项目项目。这是一个KFC点菜系统。


那时候觉得没有实现的功能,不能使控件随窗体的改变而改变。右键的刷新功能刷新后会在界面上留下痕迹。没有把图片存入数据库中,然后在程序中随着查询而调用。打印消费凭条的打印功能没有做等等。


现在想想,要实现 的话,也有很多。要改的也有很多。而且相信,我也可以再写得更漂亮。


那时候刚开始的时候是没有什么的灵感,数据库的查询编号功能也用了好几天去查资料,费了很多时间。不过在这个查询功能做好以后,灵感来了。看了别人的软件时,自己也为软件添加了一些功能。添了文本保存打开,添了音乐背景,添了文本滚动,等等。


在考虑查询的时候也比较全面,如果输入非法的字,或者输入的字不在数据库中,要防止出错。


还算不错呀,不过总是担心还不够好,老师给不了高分,呵呵,


处女作啊处女作


留下一些痕迹,让自己越往后,回头看,更有滋味。
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.OleDb ;
using System.IO;
using System.Drawing.Printing;


namespace 点菜3
{
    public partial class Form1 : Form
    {
       
       
        public Form1()
        {
            InitializeComponent();
            this.skinEngine1.SkinFile = "SportsOrange.ssk";
           
 
        }

 

 

 

        //菜单 配餐
        private void button1_Click(object sender, EventArgs e)
        { 
            //弹出窗体
            Form obj = new 配餐();
            obj.Show();


     
            listBox2.Items.Clear();
            //连接数据库
            string mystr, mysql;
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            mystr = "Provider = Microsoft.Jet.OLEDB.4.0;" +
               "Data Source = KFC.mdb";
            myconn.ConnectionString = mystr;
            myconn.Open();
            mysql = "SELECT * FROM 配餐";
            mycmd.CommandText = mysql;
            mycmd.Connection = myconn;
            OleDbDataReader myreader = mycmd.ExecuteReader();

            listBox2.Items.Add("\t编号\tKFC\t\t价格\t");
            listBox2.Items.Add("============================================================");
            //循环读取信息
            while (myreader.Read())
                listBox2.Items.Add(String.Format("\t{0}\t{1}\t{2}\t",
                                myreader[0].ToString(), myreader[1].ToString() ,myreader [2].ToString ()));
            myconn.Close();
            myreader.Close();


        }

        //菜单  营养早餐
       private void button6_Click(object sender, EventArgs e)
        {
            Form obj = new 营养早餐();
            obj.Show();

           listBox2.Items.Clear();
            string mystr, mysql;
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            mystr = "Provider = Microsoft.Jet.OLEDB.4.0;" +
               "Data Source = KFC.mdb";
            myconn.ConnectionString = mystr;
            myconn.Open();
            mysql = "SELECT * FROM 早餐";
            mycmd.CommandText = mysql;
            mycmd.Connection = myconn;
            OleDbDataReader myreader = mycmd.ExecuteReader();

            //循环读取信息
           listBox2.Items.Add("\t编号\tKFC\t\t价格\t");
            listBox2.Items.Add("============================================================");

            while (myreader.Read())
                listBox2.Items.Add(String.Format("\t{0}\t{1}\t{2}\t",
                                myreader[0].ToString(), myreader[1].ToString(), myreader[2].ToString()));
            myconn.Close();
            myreader.Close();

        }
       //菜单 甜点
        private void button9_Click(object sender, EventArgs e)
       {
           Form obj = new 甜点();
           obj.Show();
            listBox2.Items.Clear();
            string mystr, mysql;
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            mystr = "Provider = Microsoft.Jet.OLEDB.4.0;" +
               "Data Source = KFC.mdb";
            myconn.ConnectionString = mystr;
            myconn.Open();
            mysql = "SELECT * FROM 甜点";
            mycmd.CommandText = mysql;
            mycmd.Connection = myconn;
            OleDbDataReader myreader = mycmd.ExecuteReader();
            listBox2.Items.Add("\t编号\tKFC\t\t价格\t");
            listBox2.Items.Add("============================================================");
            //循环读取信息
            while (myreader.Read())
                listBox2.Items.Add(String.Format("\t{0}\t{1}\t{2}\t",
                                myreader[0].ToString(), myreader[1].ToString(), myreader[2].ToString()));
            myconn.Close();
            myreader.Close();


        }
        //菜单 小食
        private void button3_Click_1(object sender, EventArgs e)
        {
            Form obj = new 小食();
            obj.Show();
            listBox2.Items.Clear();
            string mystr, mysql;
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            mystr = "Provider = Microsoft.Jet.OLEDB.4.0;" +
               "Data Source = KFC.mdb";
            myconn.ConnectionString = mystr;
            myconn.Open();
            mysql = "SELECT * FROM 小食";
            mycmd.CommandText = mysql;
            mycmd.Connection = myconn;
            OleDbDataReader myreader = mycmd.ExecuteReader();
            listBox2.Items.Add("\t编号\tKFC\t\t价格\t");
            listBox2.Items.Add("============================================================");
            //循环读取信息
            while (myreader.Read())
                listBox2.Items.Add(String.Format("\t{0}\t{1}\t{2}\t",
                                myreader[0].ToString(), myreader[1].ToString(), myreader[2].ToString()));
            myconn.Close();
            myreader.Close();

        }
        //菜单 主食
        private void button2_Click_1(object sender, EventArgs e)
        {
            Form obj = new 主食();
            obj.Show();

            listBox2.Items.Clear();
            string mystr, mysql;
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            mystr = "Provider = Microsoft.Jet.OLEDB.4.0;" +
               "Data Source = KFC.mdb";
            myconn.ConnectionString = mystr;
            myconn.Open();
            mysql = "SELECT * FROM 主食";
            mycmd.CommandText = mysql;
            mycmd.Connection = myconn;
            OleDbDataReader myreader = mycmd.ExecuteReader();
            listBox2.Items.Add("\t编号\tKFC\t\t价格\t");
            listBox2.Items.Add("============================================================");
            //循环读取信息
            while (myreader.Read())
                listBox2.Items.Add(String.Format("\t{0}\t{1}\t{2}\t",
                                myreader[0].ToString(), myreader[1].ToString(), myreader[2].ToString()));
            myconn.Close();
            myreader.Close();
        }

   

//点菜  确认
private void button4_Click_1(object sender, EventArgs e)
        {
            String mysql;
            String ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=KFC.mdb";
            OleDbConnection myconn = new OleDbConnection();
            OleDbCommand mycmd = new OleDbCommand();
            myconn.ConnectionString = ConnString ;
            myconn.Open();

            //查询编号
            mysql= "SELECT * FROM 总括 WHERE 编号=@no";
            mycmd.CommandText =mysql;
            mycmd.Connection =myconn;
            mycmd.Parameters .Add ("@no",OleDbType .VarChar ,5).Value=txtid.Text;
           
            //未输入编号
            if (txtid.Text == "")
            {
                MessageBox.Show("请输入您要点的食物编号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {

                int num = Convert.ToInt32(txtid.Text);

                //编号不在数据库
                if ((11 <= num && num <= 16) || (21 <= num && num <= 27) || (31 <= num && num <= 35) || (41 <= num && num <= 48) || (51 <= num && num <= 58))//数据不存在
                {


                    //txtname.Text =mycmd .ExecuteScalar().ToString ();
                    OleDbDataReader myreader = mycmd.ExecuteReader();
                    myreader.Read();
                    txtname.Text = myreader.GetValue(1).ToString();
                    txtprice.Text = myreader.GetValue(2).ToString();

                    //确认是否点菜
                    string str2 = "确认要点" + txtname.Text.ToString();
                   DialogResult yesno = MessageBox.Show(str2, "", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (yesno == DialogResult.Yes)
                    { 
                        //显示点的菜的信息,并复制到列表框中
                        listBox1.Items.Add(String.Format("{0}\t\t{1}\t",
                                         txtname.Text.ToString(), txtprice.Text.ToString()));
                        count += Convert.ToDouble(txtprice.Text.ToString());
                        //消费金额
                        txtcount.Text = Convert.ToString(count);
                        txtid.Clear();
                    }

                    else
                    {
                        txtid.Clear();
                        txtname.Clear();
                        txtprice.Clear();
                       
            }

 


            //mysql = "SELECT KFC FROM 总括 ";
            //mycmd.CommandText = mysql;
            // mycmd.Connection = myconn;
            // mysql = string.Format("SELECT * FROM 总括 WHERE 编号=@no");
            //mycmd.Parameters.Add("@no", OleDbType.VarChar, 5).Value = txtid.Text;
            //  mycmd = new OleDbCommand(mysql, myconn);

            //txtprice .Text=dr[1].ToString ();
            //string temp = Convert.ToString(dr[1]);
            //txtprice.Text = temp.ToString();
            //  }

            //dr.Close();
          
        }
        else
        {
            MessageBox.Show("您输入的编号不存在,请重新确认输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            txtid.Clear();
        }
    }
       
}


    private void Form1_Load(object sender, EventArgs e)
      {
            listBox1.Items.Add("\t\t消费凭条  ");
            listBox1.Items.Add("\tKFC\t\t价格\t");
            listBox1.Items.Add("=================================");
            //系统时间
            label7.Text = System.DateTime.Now.ToLongDateString();
            label8.Text = System.DateTime.Now.ToLongTimeString();
          
}
//点菜结束
   private void btnprint_Click(object sender, EventArgs e)
     {
         
        String str3 = "您好!您共需支付" + txtcount.Text.ToString() + "元";
        if (txtcount.Text == "")
        {
            MessageBox.Show("您还没点菜!", "KFC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
        }
        else
        {
            MessageBox.Show(str3, "KFC", MessageBoxButtons.OK, MessageBoxIcon.Asterisk );
        }

   
  

}

            //链接
    private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        linkLabel1.LinkVisited = true;
        System.Diagnostics.Process.Start(linkLabel1.Text);
    }

 

    private void timer1_Tick(object sender, EventArgs e)
    {
        label7.Text = System.DateTime.Now.ToLongDateString();
        label8.Text = System.DateTime.Now.ToLongTimeString();

        label13.Left = label13.Left - 4;
        if (label13.Right < 0)
        {
            label13.Left = this.Width;
        }
  
}

        //外观

        private void 蓝色天下ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.skinEngine1.SkinFile = "SportsBlue.ssk";
        }

        private void 运动橙ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.skinEngine1.SkinFile = "SportsOrange.ssk";
        }

        private void 活力绿ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.skinEngine1.SkinFile = "vista1_green.ssk";
        }

        private void 清爽海ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.skinEngine1.SkinFile = "MP10.ssk";
        }

        //退出提示
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
           DialogResult  result= MessageBox .Show ("是否要继续退出","提示",MessageBoxButtons .YesNo ,MessageBoxIcon.Question );
           if (result == DialogResult.No)
           {
               e.Cancel = true;  //取消窗体的退出
           }
        }

 


        //客户建议
        private void button5_Click(object sender, EventArgs e)
        {  
            //保存
             SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                        saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
                        }
            MessageBox.Show("感谢您的宝贵建议,我们将努力做到更好!", "Thanks", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

 

        private void tabPage5_Enter(object sender, EventArgs e)
        {
            Form obj = new music();
            obj.Show();
        }

 


        //读取文本
        private void richTextBox2_Click(object sender, EventArgs e)
        {
            StreamReader strReader1 = new StreamReader("kfc.txt", System.Text.Encoding.Default);
            string strContent1 = strReader1.ReadToEnd();
            richTextBox2.Text = strContent1;
        }

        //KFC 特荐
        private void pictureBox7_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox7.Left  += 60;
            pictureBox1.Hide();
            pictureBox8.Hide();
            pictureBox9.Hide();
            pictureBox10.Hide();
            pictureBox7.Show();
           
        }

        private void pictureBox7_DragLeave(object sender, EventArgs e)
        {

        }

        private void pictureBox7_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox7.Left -= 60;
            pictureBox1.Show();
            pictureBox8.Show();
            pictureBox9.Show();
            pictureBox10.Show();
            pictureBox7.Show();
        }

        private void pictureBox8_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox8.Left +=40;
            pictureBox1.Hide();
            pictureBox7.Hide();
            pictureBox9.Hide();
            pictureBox10.Hide();
            pictureBox8.Show();
        }

        private void pictureBox8_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox8.Left -= 40;
            pictureBox1.Show();
            pictureBox7.Show();
            pictureBox9.Show();
            pictureBox10.Show();
            pictureBox8.Show();
        }

        private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
        {

        
            pictureBox1.Hide();
            pictureBox7.Hide();
            pictureBox8.Hide();
            pictureBox10.Hide();
            pictureBox9.Show();
        }

        private void pictureBox9_MouseUp(object sender, MouseEventArgs e)
        {
        
            pictureBox1.Show();
            pictureBox7.Show();
            pictureBox9.Show();
            pictureBox10.Show();
            pictureBox8.Show();
        }

 

        private void pictureBox10_MouseDown(object sender, MouseEventArgs e)
        {

            pictureBox1.Hide();
            pictureBox7.Hide();
            pictureBox9.Hide();
            pictureBox8.Hide();
            pictureBox10.Show();
        }

        private void pictureBox10_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox1.Show();
            pictureBox7.Show();
            pictureBox9.Show();
            pictureBox10.Show();
            pictureBox8.Show();
        }

 

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox10.Hide();
            pictureBox7.Hide();
            pictureBox9.Hide();
            pictureBox8.Hide();
            pictureBox1.Show();
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox1.Show();
            pictureBox7.Show();
            pictureBox9.Show();
            pictureBox10.Show();
            pictureBox8.Show();
        }

        //关于
        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form obj = new 关于();
            obj.Show();
        }

         //限制文本被编辑
        private void txtid_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar))
                e.Handled = true;
            if (e.KeyChar == '\b' || e.KeyChar == '.')//b是退格键
                e.Handled = false;

        }//textbox只能输入数字

        private void timer2_Tick(object sender, EventArgs e)
        {
         
            //  statusStrip1.Panels[2].Text = DateTime.Now.ToString();
            label3.Left = label3.Left - 2;
            if (label3.Right < 0)
            {
                label3.Left = this.Width;
            }
        }


       

               

              

 

 

 

 

 

 

 

 

    }
}

 

 

 

/

//音乐播放
        private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
        {
          //  AxWMPLib.AxWindowsMediaPlayer wmp = new AxWMPLib.AxWindowsMediaPlayer();
           // this.Controls.Add(wmp);
        
            this.axWindowsMediaPlayer1 .URL = "kfc 广告歌.mp3";
            this.axWindowsMediaPlayer1 .Ctlcontrols.play();
        }

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

        private void music_Load(object sender, EventArgs e)
        {
            timer.Interval = 3000;//5秒
            timer .Tick +=new EventHandler(timer_Tick);
        }



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值