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

📄 建立文档.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
    {
        private int ValidateData1()
        {
            int flag = 0;
            if (textBox1.Text == "")
            {
                textBox1.Focus();
                errorProvider1.SetError(textBox1, "");
                flag = 1;
            }

            return flag;
        }
        private int ValidateData2()
        {
            int flag = 0;
            if (textBox2.Text == "")
            {
                textBox2.Focus();
                errorProvider1.SetError(textBox2 , "");
                flag = 1;
            }
            return flag;
        }

        public 建立文档()
        {
            InitializeComponent();
        }

        private void button1_Click_1(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 ((ValidateData1() == 0) && ValidateData2() == 0)
                {
                    tran = cn.BeginTransaction();
                    SqlCommand cmd1 = new SqlCommand("Update Patient Set IPID=@IPID Where OPID=@OPID", cn, tran);
                    cmd1.Parameters.Add(new SqlParameter("@OPID", textBox1.Text));
                    cmd1.Parameters.Add(new SqlParameter("@IPID", textBox2.Text));
                    cmd1.ExecuteNonQuery();

                    SqlCommand cmd2 = new SqlCommand("Update Treatment Set IPID=@IPID Where OPID=@OPID", cn, tran);
                    cmd2.Parameters.Add(new SqlParameter("@OPID", textBox1.Text));
                    cmd2.Parameters.Add(new SqlParameter("@IPID", textBox2.Text));
                    cmd2.ExecuteNonQuery();
                    tran.Commit();
                    MessageBox.Show("IPID 已经建立\n");
                }
                else
                    MessageBox.Show("请查看输入是否有问题!");

            }
            catch (SqlException ex)
            {
                tran.Rollback();
                MessageBox.Show(ex.Message);
                //Console.WriteLine("ERROR-Transaction rolled back\n" + ex.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                //Console.WriteLine("System Error\n" + ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }

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


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

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

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

⌨️ 快捷键说明

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