• 大小: 93KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: 其他
  • 标签: 练习  新手  

资源简介

初学者练习的小项目,虽然简单但用到的初学的知识点,包括主界面,添加菜品,查询菜品等...

资源截图

代码片段和文件信息

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 FOODSEARCHSYS
{
    public partial class addfood : Form
    {
        public addfood()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            //得到文本框中的值
            string txtFoodName = this.txtFoodName.Text.ToString();
            float txtOldPrice = float.Parse(this.txtOldPrice.Text.ToString());
            float txtNewPrice = float.Parse(this.txtNewPrice.Text.ToString());
            string txtRemark = this.txtRemark.Text.ToString();
            //获取组合框中的value值
            int typeId = int.Parse(this.comboBox1.SelectedValue.ToString());
            //创建数据库连接字符串
            string connstring = “server=.;database=FOODDB;uid=sa;pwd=123456“;
            //创建连接对象
            SqlConnection con = new SqlConnection(connstring);
            //打开数据库连接
            con.Open();
            //判断是否已经打开连接
            if (con.State == ConnectionState.Open)
            {
                string sql = “insert into FOOD values(‘“+txtFoodName+“‘“+ txtOldPrice + ““+ txtNewPrice +“‘“+ txtRemark +“‘“+ typeId +“)“;
                //创建命令对象
                SqlCommand cmd = new SqlCommand(sql con);
                //执行sql语句
                int i = cmd.ExecuteNonQuery();
                //判断是否执行成功
                if (i == 0)
                {
                    MessageBox.Show(“菜品添加失败!“);
                }
                else
                {
                    MessageBox.Show(“菜品添加成功!“);
                }
            }
        }


        public void selectAllTypeName()
        {
            string connstring = “server=.;database=FoodDB;uid=sa;pwd=123456“;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            if (con.State == ConnectionState.Open)
            {
                string sql = “select TYPENAMETYPEID from FOODTPYE“;
                SqlDataAdapter adapter = new SqlDataAdapter(sql con);
                DataSet ds = new DataSet();
                adapter.Fill(ds);
                this.comboBox1.DataSource = ds.Tables[0].DefaultView;
                this.comboBox1.DisplayMember = “TYPENAME“;
                this.comboBox1.ValueMember = “TYPEID“;

            }
            else
            {
                MessageBox.Show(“数据库连接失败!“);
            }
        }
        private void addfood_Load(object sender EventArgs e)
        {
            selectAllTypeName();
        }

        private void selectAllTypeNmae_SelectedIndexChanged(object sender EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender EventArgs e)
        {

        }

    }   
    }


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-04 14:19  菜品\
     目录           0  2018-01-04 14:19  菜品\FOODSEARCHSYS\
     目录           0  2018-01-02 17:13  菜品\FOODSEARCHSYS\FOODSEARCHSYS\
     文件         881  2017-12-29 15:35  菜品\FOODSEARCHSYS\FOODSEARCHSYS.sln
     文件       29696  2018-04-21 13:53  菜品\FOODSEARCHSYS\FOODSEARCHSYS.suo
     文件        3163  2018-01-02 17:21  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfood.cs
     文件        8098  2018-01-02 15:27  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfood.Designer.cs
     文件        5817  2018-01-02 15:27  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfood.resx
     文件        2706  2018-01-02 17:23  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfoodtype.cs
     文件        4945  2018-01-02 10:46  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfoodtype.Designer.cs
     文件        5817  2018-01-02 10:46  菜品\FOODSEARCHSYS\FOODSEARCHSYS\addfoodtype.resx
     目录           0  2018-01-02 17:13  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\
     目录           0  2018-01-02 17:13  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\Debug\
     文件       24064  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\Debug\FOODSEARCHSYS.exe
     文件       75264  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\Debug\FOODSEARCHSYS.pdb
     文件       11600  2018-04-21 13:50  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\Debug\FOODSEARCHSYS.vshost.exe
     文件         490  2014-01-13 21:31  菜品\FOODSEARCHSYS\FOODSEARCHSYS\bin\Debug\FOODSEARCHSYS.vshost.exe.manifest
     文件        9264  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\foodmanage.cs
     文件       12437  2018-01-04 14:26  菜品\FOODSEARCHSYS\FOODSEARCHSYS\foodmanage.Designer.cs
     文件        5817  2018-01-04 14:26  菜品\FOODSEARCHSYS\FOODSEARCHSYS\foodmanage.resx
     文件        4662  2018-01-02 10:46  菜品\FOODSEARCHSYS\FOODSEARCHSYS\FOODSEARCHSYS.csproj
     文件        1058  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\Form1.cs
     文件        4967  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\Form1.Designer.cs
     文件        6015  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\Form1.resx
     目录           0  2018-01-02 17:13  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\
     目录           0  2018-01-02 17:13  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\
     目录           0  2018-01-04 14:40  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\Debug\
     文件        5420  2018-01-02 08:19  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6341  2018-04-08 16:44  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     文件         180  2018-01-02 15:27  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\Debug\FOODSEARCHSYS.addfood.resources
     文件         180  2018-01-02 10:46  菜品\FOODSEARCHSYS\FOODSEARCHSYS\obj\x86\Debug\FOODSEARCHSYS.addfoodtype.resources
............此处省略16个文件信息

评论

共有 条评论