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

📄 医用处方.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
    {
        SqlCommand cmd;
        SqlDataReader dr;
        SqlConnection cn = new SqlConnection();

        public 医用处方()
        {
            InitializeComponent();
        }

        private void Form7_Load(object sender, EventArgs e)
        {
            comboBox4.Items.Add("1.程度为轻");
            comboBox4.Items.Add("2.程度一般");
            comboBox4.Items.Add("3.程度较重");

            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();

            cmd = new SqlCommand("Select OPID,IPID from Patient", cn);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                comboBox1.Items.Add(dr["OPID"].ToString());
                comboBox2.Items.Add(dr["IPID"].ToString());
            }
            cn.Close();

            cn.Open();
            cmd = new SqlCommand("Select Medicine_Code from Medicine_Store", cn);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                comboBox3.Items.Add(dr["Medicine_Code"].ToString());
            }
            cn.Close();

            cn.Open();
            cmd = new SqlCommand("Select Doctor_Code from Doctor", cn);
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                comboBox5.Items.Add(dr["Doctor_Code"].ToString());
            }

            cn.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            药品信息 ob = new 药品信息();
            ob.ShowDialog();
        }

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

            SqlTransaction tran = null;
            try
            {
                tran = cn.BeginTransaction();
                SqlCommand cmd = new SqlCommand("insert into Account values(@IPID,@Date,@MedicineCode,@MedicineAmount)", cn, tran);
                cmd.Parameters.Add(new SqlParameter("@IPID", comboBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@Date", dateTimePicker1.Text));
                cmd.Parameters.Add(new SqlParameter("@MedicineCode", comboBox3.Text));
                cmd.Parameters.Add(new SqlParameter("@MedicineAmount", textBox1.Text));
                cmd.ExecuteNonQuery();

                SqlCommand cmd2 = new SqlCommand("UPDATE Doctor SET Is_Busy=0 WHERE Doctor_Code=@code", cn, tran);
                cmd2.Parameters.Add(new SqlParameter("@code", comboBox5.Text));
                cmd2.ExecuteNonQuery();
                tran.Commit();
                
            }
            catch (SqlException ex)
            {
                tran.Rollback();
                MessageBox.Show(ex.Message);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                cn.Close();
            }

            cn.Open();

            //SqlTransaction tran = null;
            try
            {
                tran = cn.BeginTransaction();
                SqlCommand cmd = new SqlCommand("insert into Treatment values(@OPID,@IPID,' ',@doctor,@degree)", cn, tran);
                cmd.Parameters.Add(new SqlParameter("@OPID", comboBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@IPID", comboBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@doctor", comboBox5.Text));
                cmd.Parameters.Add(new SqlParameter("@degree",comboBox4.Text));

                cmd.ExecuteNonQuery();

                SqlCommand cmd1 = new SqlCommand("update Patient set Degree=@degree where OPID=@opid", cn, tran);
                cmd1.Parameters.Add(new SqlParameter("@opid", comboBox1.Text));
                cmd1.Parameters.Add(new SqlParameter("@degree", comboBox4.Text));
                cmd1.ExecuteNonQuery();

                tran.Commit();
                MessageBox.Show("更新成功");
            }
            catch (SqlException ex)
            {
                tran.Rollback();
                MessageBox.Show(ex.Message);

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                cn.Close();
            }

        }

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

⌨️ 快捷键说明

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