111111111111111111111111111111111111111111111111111111111111111111111111111
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace BB
{
    public partial class Form1 : Form
    {        private Form2 form2 = null;
        private Form3 form3 = null;        public Form1()
        {
            InitializeComponent();            this.myInit();
        }        private void myInit()
        {
            this.form2 = new Form2();
            this.form2.Visible = false;
            this.form3 = new Form3();
            this.form3.Visible = false;
        }        private void Form1_Load(object sender, EventArgs e)
        {        }
        private void Form1_Click(object sender, EventArgs e)
        {
            string checkString1 = "select * from B1 where name='" + this.textBox1.Text + "' and password = '"+ this.textBox2.Text +"'";
            string checkString2 = "select * from B2 where super='" + this.textBox1.Text + "' and password = '" + this.textBox2.Text + "'";
            try
             {
                SqlConnection sqlcon=new SqlConnection();
                sqlcon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True"; 
                sqlcon.Open();
                                
                SqlCommand sc = new SqlCommand(checkString1, sqlcon);
                SqlCommand ac = new SqlCommand(checkString2, sqlcon);
                SqlDataReader sdr = sc.ExecuteReader();
                //SqlDataReader adr = ac.ExecuteReader();                if (sdr.Read())
                {
                    // 登?录?成é功|后ó显?示?出?第台?二t个?窗洹?口ú
                    this.form2.Visible = true;
                    this.form2.setText(this.textBox1.Text);
                    //MessageBox.Show("login success!?");
                }
                else
                {
                    sdr.Close();
                    sdr = ac.ExecuteReader();
                    if (sdr.Read())
                    {
                        // 登?录?成é功|后ó显?示?出?第台?三▂个?窗洹?口ú
                        this.form3.Visible = true;                        this.form3.Show();
                        //MessageBox.Show("login success!?");
                    }
                    else
                    {
                        MessageBox.Show("用?户§名?或ò密ü码?错洙?误ó!?");
                    }
                }                //sqlcmd.CommandText=checkString ;
                //sqlcmd.Connection=sqlcon ;
                //SqlDataReader dr=sqlcmd.ExecuteReader();
                //if(dr.HasRows)
                //{
                //    Home Form2=new Home();
                //    Form2.Show();
                //    this.Hide();
                //}
                //else
                //{MessageBox.Show ("用?户§名?或ò密ü码?错洙?误ó!?");
                //}                sqlcon.Close();            }
            catch (Exception error)
            {
                MessageBox .Show (error.ToString ());
            }
            finally {}
          }    }
}2222222222222222222222222222222222222222222222222222222222222222222222using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace BB
{
    public partial class Form2 : Form
    {
        //public const String DatabaseConnectString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Persist Security Info=True;";
            
        //private SqlConnection conn = null;
        public Form2()
        {            InitializeComponent();
        }        public void setText(String name)
        {
            //SQL 的?查é询ˉ语?句?
            String sqlStr = "with ts(名?字?,row_number) as (select name,row_number() over(order by ability desc) as ab from B3) SELECT name, " +
              " ability FROM B3 WHERE name IN (select 名?字? from ts where (row_number+1) = (select row_number from ts where 名?字?='" + name + "') " +
              " or (row_number-1) = (select row_number from ts where 名?字?='" + name + "'));";
            try
            {                SqlConnection sqlcon = new SqlConnection();
                sqlcon.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True";
                sqlcon.Open();                // 创洹?建¨SQL命ü令?
                SqlCommand sc = new SqlCommand(sqlStr, sqlcon);
                // 进?行D查é询ˉ
                SqlDataReader sdr = sc.ExecuteReader();
                this.richTextBox1.Text = "";
                // 用?循-环·进?行D读á取?
                while (sdr.Read())
                {
                    // SqlDataReader.GetXXXX()取?得?数簓据Y库a中D表括?的?各÷字?段?
                    String str = "名?字?:" + sdr.GetString(0) + "\t能ü力值μ:" + sdr.GetString(1) + "\n";
                    this.richTextBox1.AppendText(str);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            { }
        }
        private void Form1_Click(object sender, EventArgs e)
        {
        }        private void Form2_Load(object sender, EventArgs e)
        {        }
    }
}
3333333333333333333333333333333333333333333333333333333333333333333333333333using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace BB
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
            this.myint();
        }
        private void myint()
        {
            this.panel1.Hide();
            this.panel2.Hide();
            this.panel3.Hide();
            this.panel4.Hide();
            this.panel5.Hide();
        }
        //各÷个?按恪?键ü的?功|能ü
        private void button5_Click(Object sender, EventArgs e)//返う?回?
        {
            this.panel1.Show();
        }
        private void button1_Click(Object sender, EventArgs e)//显?示?全?部?
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True;";
            conn.Open();
            SqlDataAdapter dataSelect = new SqlDataAdapter("select * from B3 ", conn);
            DataTable dt = new DataTable();
            dataSelect.Fill(dt);
            dataGridView1.DataSource = dt.DefaultView;
            this.dataGridView1.RowHeadersVisible = true;
            conn.Close();
            this.panel2.Show();
        }
        private void button2_Click(Object sender, EventArgs e)//添?加ó
        {
            this.panel3.Show();
        }
          
             private void button21_Click(Object sender, EventArgs e)//添?加ó
             {
                   SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True;";
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            string AddString = "insert into B3(name,ability ) values('" + textBox2.Text + "','" + textBox4.Text + "') " +
                "insert into B1 (name ,password  ) values('" + textBox2.Text + "','" + textBox3.Text + "')";
            cmd.CommandText = AddString;
            cmd.ExecuteNonQuery();
            conn.Close();
                 MessageBox.Show("添?加ó成é功|");
                  textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            this.panel3.Show();             }
           
      
        private void button3_Click(Object sender, EventArgs e)//删?除y
        {
            this.panel4.Show();
        }
        private void button22_Click(Object sender, EventArgs e)//删?除y
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True;";
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();            string ModifyString = "delete from B1 where name = '" + textBox1.Text + "' delete from B3 where name = '" + textBox1.Text + "'";
            cmd.CommandText = ModifyString;
            cmd.ExecuteNonQuery();
            MessageBox.Show("删?除y成é功|");
            conn.Close();
            
            textBox1.Clear();
           
        }
                  private void button4_Click(Object sender, EventArgs e)//修T改?
        {
            this.panel5.Show();
        }
        private void button23_Click(Object sender, EventArgs e)//修T改?
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=B313;Integrated Security=True;";
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            string ModifyString = "update B1 set password ='" + textBox7.Text + "'  where name = '" + textBox6.Text + "' update B3 set ability  ='" + textBox5.Text + "'  where name = '" + textBox6.Text + "'";            cmd.CommandText = ModifyString;
            cmd.ExecuteNonQuery();
            MessageBox.Show("更ü新?成é功|");
            conn.Close();
         
            textBox6.Clear();
            textBox7.Clear();
            textBox5.Clear();
        }               private void Form3_Load(object sender, EventArgs e)
        {        }        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {        }        private void Form3_Load_1(object sender, EventArgs e)
        {        }
    }
}