depotform.cs

来自「主要实现仓库的入库与出库的基本功能」· CS 代码 · 共 70 行

CS
70
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Elysian
{
    public partial class depotForm : Form
    {
        SqlConnection sqlconn;
        SqlDataAdapter adapter;
        DataSet ds = new DataSet();
        public depotForm()
        {
            InitializeComponent();
        }

        private static string GetConnectionString()
        {
            return "data source=.;initial catalog=ElysianDB;integrated security=true";
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            string selectStr = string.Empty;
            selectStr = "select * from 库存表";
            if (textBox1.Text != "")
            {
                selectStr = selectStr + " " + "where 商品编号='" + textBox1.Text + "'";
                if (textBox2.Text != "")
                {
                    selectStr = selectStr + " " + "and 商品名称='" + textBox2.Text + "'";
                }
            }
            else
            {
                if (textBox2.Text != "")
                {
                    selectStr = selectStr + " " + "where 商品名称='" + textBox2.Text + "'";
                }
                else
                {
                    MessageBox.Show("请您输入要查询的信息");
                }
            }
            sqlconn = new SqlConnection(GetConnectionString());
            SqlCommand sqlcomm = new SqlCommand();
            sqlcomm.CommandText = selectStr;
            sqlcomm.Connection = sqlconn;
            sqlconn.Open();
            ds.Clear();
            adapter = new SqlDataAdapter(sqlcomm);
            adapter.Fill(ds, "库存表");
            dataGridView1.DataSource = ds.Tables[0];
            sqlconn.Close();
            textBox1.Text = "";
            textBox2.Text = "";
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?