⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 药品信息.cs

📁 本人课程设计时开发的一个医院管理系统
💻 CS
字号:
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 WindowsApplication1
{
    public partial class 药品信息 : Form
    {
        public 药品信息()
        {
            InitializeComponent();
        }

        private void Form8_Load(object sender, EventArgs e)
        {
            SqlConnection cn = new SqlConnection();
            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();

            DataSet ds = new DataSet();
            SqlDataReader dr;
            SqlCommand cmd = new SqlCommand("Select * from Medicine_Store", cn);

            dr = cmd.ExecuteReader();

            DataTable dt = new DataTable("MedicineStore");
            dt.Columns.Add("MedicineCode");
            dt.Columns.Add("MedicineName");
            dt.Columns.Add("Price");
            dt.Columns.Add("Amount");

            ds.Tables.Add(dt);

            while (dr.Read())
            {
                comboBox1.Items.Add(dr["Medicine_Name"]);
                DataRow drow = dt.NewRow();
                drow["MedicineCode"] = (string)(dr["Medicine_Code"]);
                drow["MedicineName"] = dr["Medicine_Name"].ToString();
                drow["Price"] = dr["Price"].ToString();
                drow["Amount"] = dr["Store_Amount"].ToString();
                dt.Rows.Add(drow);
            }
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "MedicineStore";

            cn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text != "")
            {
                SqlConnection cn = new SqlConnection();
                cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
                cn.Open();
                SqlCommand cmd = new SqlCommand("Select * from Medicine_Store where Medicine_Name=@name", cn);
                cmd.Parameters.Add(new SqlParameter("@name",comboBox1.Text));
                SqlDataReader dr = cmd.ExecuteReader();
                DataSet ds = new DataSet();
                DataTable dt = new DataTable("record");
                dt.Columns.Add("MedicineCode");
                dt.Columns.Add("MedicineName");
                dt.Columns.Add("Price");
                dt.Columns.Add("Amount");
                ds.Tables.Add(dt);

                while (dr.Read())
                {
                    DataRow drow = dt.NewRow();
                    drow["MedicineCode"] = (string)(dr["Medicine_Code"]);
                    drow["MedicineName"] = dr["Medicine_Name"].ToString();
                    drow["Price"] = dr["Price"].ToString();
                    drow["Amount"] = dr["Store_Amount"].ToString();
                    dt.Rows.Add(drow);
                }
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "record";

                cn.Close();
            }
        }

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

⌨️ 快捷键说明

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