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

📄 添加医生.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;
using System.Transactions;

namespace WindowsApplication1
{
    public partial class 添加医生 : Form
    {
        public 添加医生()
        {
            InitializeComponent();
        }


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

        private void Form15_Load_1(object sender, EventArgs e)
        {
            int num = 1;
            SqlConnection cn = new SqlConnection();
            SqlCommand cmd;
            SqlDataReader dr;
            cn.ConnectionString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
            cn.Open();
            cmd = new SqlCommand("Select Doctor_Code from Doctor", cn);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                num += 1;
            }
            textBox2.Text = "0" + num.ToString();
            cn.Close();

        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            SqlCommand cmd;
            SqlConnection cn = new SqlConnection();

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

            SqlTransaction tran = null;
            try
            {
                tran = cn.BeginTransaction();
                cmd = new SqlCommand("insert into Doctor(Department_Code,Doctor_Code,Doctor_Name,Is_Busy,Doctor_Password)values(@Department_Code,@Doctor_Code,@Doctor_Name,@Is_Busy,@Doctor_Password)", cn, tran);
                cmd.Parameters.Add(new SqlParameter("@Department_Code", textBox1.Text));
                cmd.Parameters.Add(new SqlParameter("@Doctor_Code", textBox2.Text));
                cmd.Parameters.Add(new SqlParameter("@Doctor_Name", textBox3.Text));
                cmd.Parameters.Add(new SqlParameter("@Is_Busy", textBox4.Text));
                cmd.Parameters.Add(new SqlParameter("@Doctor_Password", textBox5.Text));

                cmd.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();
            }

        }
    }
}

⌨️ 快捷键说明

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