📄 查找空闲医生.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
{
private int ValidateData()
{
int flag = 0;
if (textBox2.Text == "")
{
textBox2.Focus();
errorProvider1.SetError(textBox2, "Enter the IPID");
flag = 1;
}
return flag;
}
public 查找空闲医生()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string choice;
string connecString = "Data Source=sclab76\\SQLEXPRESS;Initial Catalog=医院管理系统;User id=sa;Password=niit#1234";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = connecString;
cn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("Select * from Doctor", cn);
choice = textBox1.Text;
switch (choice)
{
case "A":
cmd = new SqlCommand("Select Department_Code,Doctor_Code,Doctor_Name,Is_Busy from Doctor where Department_Code ='A' and Is_Busy ='0'", cn);
break;
case "B":
cmd = new SqlCommand("Select Department_Code,Doctor_Code,Doctor_Name,Is_Busy from Doctor where Department_Code ='B' and Is_Busy ='0'", cn);
break;
case "C":
cmd = new SqlCommand("Select Department_Code,Doctor_Code,Doctor_Name,Is_Busy from Doctor where Department_Code ='C' and Is_Busy ='0'", cn);
break;
case "D":
cmd = new SqlCommand("Select Department_Code,Doctor_Code,Doctor_Name,Is_Busy from Doctor where Department_Code ='D' and Is_Busy ='0'", cn);
break;
default:
MessageBox.Show("输入不正确,请参考全部就诊部门重新输入!");
break;
}
da.SelectCommand = cmd;
da.Fill(ds, "Doctor");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Doctor";
dataGridView1.Columns[0].HeaderText = "Department_Code";
dataGridView1.Columns[1].HeaderText = "Doc_Code";
dataGridView1.Columns[2].HeaderText = "Doctor_Name";
dataGridView1.Columns[3].HeaderText = "Is_Busy";
cn.Close();
}
private void button3_Click(object sender, EventArgs e)
{
string connectString = "Initial Catalog=医院管理系统;Data Source=sclab76\\SQLEXPRESS;User id=sa;Password=niit#1234";
SqlConnection cn = new SqlConnection();
cn.ConnectionString = connectString;
cn.Open();
SqlTransaction tran = null;
try
{
if (ValidateData() == 0)
{
tran = cn.BeginTransaction();
SqlCommand cmd = new SqlCommand("Update Doctor Set Is_Busy='1' Where Doctor_Code=@Doctor_Code ", cn, tran);
cmd.Parameters.Add(new SqlParameter("@Doctor_Code", textBox2.Text));
cmd.ExecuteNonQuery();
tran.Commit();
MessageBox.Show("医生空闲修改完毕\n");
}
else
MessageBox.Show("请输入选择看病医生的Code");
}
catch (SqlException ex)
{
tran.Rollback();
Console.WriteLine("ERROR-Transaction rolled back\n" + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("System Error\n" + ex.Message);
}
finally
{
cn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -