精华内容
下载资源
问答
  • MySQL数据库设计 课程设计...系统概述 驾校学员管理系统主要用于管理驾校的各种数据,利用这种mysql数据库的驾校管理系统可以给学员的管理资料的整理,资料的查询,数据的处理带来了很的方便,能够很的提高管理员的工作
  • 数据库原理及应用课程设计 设计题目 机票预订信息系统 系 部 信息技术工程学院 班 级 网络 1302 学 号 姓 名 2016 年 1 月 目录 TOC \h \z \t "样式1,1,样式2,2,样式3,3" 一 需求分析 3 ? 背景分析 3 ? 需求分析 3 1...
  • SQL作业 SQL作业
  • 数据库大作业sql server) 数据库大作业sql server) 数据库大作业sql server) 数据库大作业sql server)
  • 这学期老师让做的数据库大作业的各种文件,应用SQl server2005以及visual studio工具
  • 餐饮业信息管理系统的开发 第一:在员工使用本餐饮信息管理系统应可以实现以下功能: 1. 添加修改查询客户会员信息(修改客户信息需客户确认) 2. 查询菜单 3. 添加查询预定信息,为老顾客打折 ...第二:管理员使用本餐饮...
  • 学校数据库大作业,包括数据库基本题型,设计数据库,ER图,sql,t-sql,添加约束,设计事务,并发控制知识框架
  • 数据库SQL大作业

    2018-06-20 13:52:46
    基于myeclipse+SQL的设计 导入可使用,内附文档,代码
  • 基于课上内容,利用课件中的sql文件,将对应数据库和表格导入到本机中,并查询以下内容: 销售id- 销售姓名- 沟通用户总数- 直接成单- 跟单成功数- 总成单数- 直接成单率- 跟单成功率- 总成功率- 非意向用户数- ...
  • 数据库大作业

    2018-12-30 00:31:38
    适用于初学者,数据库大作业,主题学生管理系统,内含完整代码,sql文件和文档,还包含很多文档模板
  • SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text); command.Parameters.Add(sqlParameter); sqlParameter = new SqlParameter("@userpassword", textBox2.Text); command.Parameters.Add...

    视频讲解链接:https://www.bilibili.com/video/BV1FA411B74H/
    一 层级概括
    主要界面包括学生登录界面,管理员登录界面,注册界面,学生表,课程表,SC表的查看,
    以及增删改查界面
    二主要代码和界面演示
    1.注册界面
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.IO;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class Register : Form
        {
            public Register()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
    
                if (comboBox1.Text.Trim() == "学生")//如果是学生注册,添加到SysUsers
                {
                    try
                    {
                        string connString = "Data Source=.;Initial Catalog=School;User ID=sa;Password=lrx359641708";//数据库连接字符串
                        SqlConnection connection = new SqlConnection(connString);//创建connection对象
                        string sql = "insert into SysUser (UserID,   UserPassWord ,   UserSchoolID, UserMobile, UserBirthday , UserIdentity  ) " +
                                                                         "values (@userid, @userpassword,@userschoolid,@usermobile,@userbirthday,@useridentity)";
                        SqlCommand command = new SqlCommand(sql, connection);
                        SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userpassword", textBox2.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userschoolid", textBox3.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@usermobile", textBox4.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userbirthday", dateTimePicker1.Value);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@useridentity", comboBox1.Text);
                        command.Parameters.Add(sqlParameter);
                        
                        //打开数据库连接
                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                        MessageBox.Show("注册成功");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                if (comboBox1.Text.Trim() == "管理员")//如果是管理员注册,添加到SyUsers
                {
                    try
                    {
                        string connString = "Data Source=.;Initial Catalog=School;User ID=sa;Password=lrx359641708";//数据库连接字符串
                        SqlConnection connection = new SqlConnection(connString);//创建connection对象
                        string sql = "insert into SyUser (UserID,   UserPassWord ,   UserSchoolID, UserMobile, UserBirthday , UserIdentity  ) " +
                                                                            "values (@userid, @userpassword,@userschoolid,@usermobile,@userbirthday,@useridentity)";
                        SqlCommand command = new SqlCommand(sql, connection);
                        SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userpassword", textBox2.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userschoolid", textBox3.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@usermobile", textBox4.Text);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@userbirthday", dateTimePicker1.Value);
                        command.Parameters.Add(sqlParameter);
                        sqlParameter = new SqlParameter("@useridentity", comboBox1.Text);
                        command.Parameters.Add(sqlParameter);
                       
                        //打开数据库连接
                        connection.Open();
                        command.ExecuteNonQuery();
                        connection.Close();
                        MessageBox.Show("注册成功");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                this.Close();//界面关闭
    
            }
    
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
            public Byte[] mybyte = new byte[0];
    
          
    
            private void textBox1_Leave(object sender, EventArgs e)
            {
                if (textBox1.Text.Trim() != "")
                {
                    //使用regex(正则表达式)进行格式设置 至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符。
                    Regex regex = new Regex(@"(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{3,20}");
    
                    if (regex.IsMatch(textBox1.Text))//判断格式是否符合要求
                    {
                        //MessageBox.Show("输入密码格式正确!");
                    }
                    else
                    {
                        MessageBox.Show("至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符!");
                        textBox1.Focus();
                    }
                }
                else
                {
                    MessageBox.Show("Please fill in the full information!");
                }
    
            }
    
            private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox4_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label9_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label8_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label7_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label6_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label5_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label4_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label2_Click(object sender, EventArgs e)
            {
    
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void Register_Load(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    2.学生登录界面
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class StudentLogin : Form
        {
            public StudentLogin()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string username = textBox1.Text.Trim();  //取出账号
                string password = textBox2.Text.Trim();  //取出密码并加密
    
         
    
                //string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
                string myConnString = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
    
                SqlConnection sqlConnection = new SqlConnection(myConnString);  //实例化连接对象
                sqlConnection.Open();
    
                string sql = "select UserID,UserPassword from SysUser where UserID = '" + username + "' and UserPassword = '" + password + "'";                                            //编写SQL命令
                SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
    
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
    
                if (sqlDataReader.HasRows && textBox3.Text == code)
                {
                    MessageBox.Show("欢迎使用!");             //登录成功
                    stumain stumain= new stumain();
                  stumain.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("登录失败!");
                    return;
                }
                sqlDataReader.Close();
              //  sql = "insert into SysLog values ( '" + username + "' , '" + DateTime.Now + "' , '" + "Login" + "')";                                            //编写SQL命令
             //   sqlCommand = new SqlCommand(sql, sqlConnection);
               // sqlCommand.ExecuteNonQuery();
                //sqlConnection.Close();
            }
    
          
    
            public string code;        
    
            private void button2_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                Register register = new Register();
                register.ShowDialog();
            }
    
            private void Login_Load(object sender, EventArgs e)
            {
                //随机实例化 
                Random ran = new Random();
                int number;
                char code1;
                //取五个数 
                for (int i = 0; i < 5; i++)
                {
                    number = ran.Next();
                    if (number % 2 == 0)
                        code1 = (char)('0' + (char)(number % 10));
                    else
                        code1 = (char)('A' + (char)(number % 26)); //转化为字符 
    
                    this.code += code1.ToString();
                }
    
                label5.Text = code;
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                glyLogin glyLogin = new glyLogin();
                glyLogin.Show();
             
            }
    
            private void label5_Click(object sender, EventArgs e)
            {
    
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label4_Click(object sender, EventArgs e)
            {
    
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label2_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    3.管理员登录界面
    在这里插入图片描述

    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.Security.Cryptography;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class glyLogin : Form
        {
            public glyLogin()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string username = textBox1.Text.Trim();  //取出账号
                string password = textBox2.Text.Trim();  //取出密码并加密
    
    
    
                //string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
                string myConnString = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
    
                SqlConnection sqlConnection = new SqlConnection(myConnString);  //实例化连接对象
                sqlConnection.Open();
    
                string sql = "select UserID,UserPassword from SyUser where UserID = '" + username + "' and UserPassword = '" + password + "'";                                            //编写SQL命令
                SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
    
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
    
                if (sqlDataReader.HasRows )
                {
                    MessageBox.Show("欢迎使用!");             //登录成功
                    glymain glymain = new glymain();                                      //Main form2 = new Main();
                    glymain.Show();                                     // form2.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("登录失败!");
                    return;
                }
                sqlDataReader.Close();
                //  sql = "insert into SysLog values ( '" + username + "' , '" + DateTime.Now + "' , '" + "Login" + "')";                                            //编写SQL命令
                //   sqlCommand = new SqlCommand(sql, sqlConnection);
                // sqlCommand.ExecuteNonQuery();
                //sqlConnection.Close();
            }
    
    
           
    
            private void label5_Click(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click_1(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void textBox2_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
    
            }
    
            private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
            {
                Register register = new Register();
                register.ShowDialog();
            }
    
            private void glyLogin_Load(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    4.学生系统主要界面
    在这里插入图片描述

    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.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class stumain : Form
        {
            public stumain()
            {
                InitializeComponent();
            }
    
            private void stumain_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet3.Student”中。您可以根据需要移动或删除它。
              //  this.studentTableAdapter.Fill(this.schoolDataSet3.Student);
    
            }
    
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                
            }
    
            private void button1_Click_1(object sender, EventArgs e)
            {
                Form1 form1 = new Form1();
                form1.ShowDialog();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                Form2 form2 = new Form2();
                form2.ShowDialog();
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                Form3 form3 = new Form3();
                form3.ShowDialog();
            }
        }
    }
    

    5.学生查看学生表
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet13.Student”中。您可以根据需要移动或删除它。
                this.studentTableAdapter1.Fill(this.schoolDataSet13.Student);
            
            }
    
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
            }
        }
    }
    

    6.学生查看课程表
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet9.Course”中。您可以根据需要移动或删除它。
                this.courseTableAdapter.Fill(this.schoolDataSet9.Course);
    
            }
    
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
            }
        }
    }
    

    7.学生查看成绩
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
            }
    
            private void Form3_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet10.SC”中。您可以根据需要移动或删除它。
                this.sCTableAdapter.Fill(this.schoolDataSet10.SC);
    
            }
    
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
    
            }
        }
    }
    

    8.管理员对学生信息的增删改查
    在这里插入图片描述

      private void button1_Click(object sender, EventArgs e)
            {
                String StuID = textBox1.Text.Trim();
                String StuName = textBox2.Text.Trim();
                String StuSex = textBox3.Text.Trim();
                String Stuage = textBox4.Text.Trim();
                String StuSdept = textBox5.Text.Trim();//取出字符串
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
                try
                {
                    con.Open();
                    String insertstr = "INSERT INTO  Student (Sno,Sname,Ssex,Sdept,Sage)    " + "VALUES ('" + StuID + "','" + StuName + "','" + StuSex + "','" + StuSdept + "'," + Stuage + ")";
                    SqlCommand cmd = new SqlCommand(insertstr, con); //实例化数据库命令对象
                    cmd.ExecuteNonQuery(); //执行命令
                }
                catch
                {
                    MessageBox.Show("输入数据有误,请输入有效数据!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    con.Dispose(); //释放
                }
                this.studentTableAdapter4.Fill(this.schoolDataSet15.Student);//使其显示更新后的表
    
            }
    

    private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
                try
                {
    
                    con.Open();
                    string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                    string delete_by_id = "delete from Student where Sno=" +  select_id ;
                    SqlCommand cmd = new SqlCommand(delete_by_id, con);
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    MessageBox.Show("请正确选择行!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    con.Dispose();
                }
                this.studentTableAdapter4.Fill(this.schoolDataSet15.Student);// 使其显示更新后的表
    
            }
    
    改
     
    
    
    
     private void button3_Click(object sender, EventArgs e)
            {
                String StuID = "";
                if (textBox1.Text == "")
                {
                    StuID = dataGridView1.SelectedCells[0].Value.ToString();
    
                }   //选中学号修改 }
                else StuID = textBox1.Text.Trim();//输入学号修改
                String StuName = textBox2.Text.Trim();
                String StuSex = textBox3.Text.Trim();
                String StuAge = textBox4.Text.Trim();
                String StuSdept = textBox5.Text.Trim();
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
                try
                {
                    string insertStr = "";
                    string insertStr1 = "";
                    string insertStr2 = "";
                    string insertStr3 = "";
                    con.Open();
                    if (StuName != "")
                    {
                        insertStr = "UPDATE Student SET Sname = '" + StuName + "' WHERE Sno = '" + StuID + "'";    //修改名字
                        SqlCommand cmd = new SqlCommand(insertStr, con);
                        cmd.ExecuteNonQuery();
                    }
    
                    if (StuSex != "")
                    {
                        insertStr1 = "UPDATE Student SET Ssex = '" + StuSex + "' WHERE Sno = '" + StuID + "'";    //修改性别
                        SqlCommand cmd1 = new SqlCommand(insertStr1, con);
                        cmd1.ExecuteNonQuery();
                    }
                    if (StuSdept != "")
                    {
                        insertStr2 = "UPDATE Student SET Sdept = '" + StuSdept + "' WHERE Sno = '" + StuID + "'";    //修改专业
                        SqlCommand cmd2 = new SqlCommand(insertStr2, con);
                        cmd2.ExecuteNonQuery();
                    }
                    if (StuAge != "")
                    {
                        insertStr3 = "UPDATE Student SET Sage = '" + StuAge + "' WHERE Sno = '" + StuID + "'";    //修改年龄
                        SqlCommand cmd3 = new SqlCommand(insertStr3, con);
                        cmd3.ExecuteNonQuery();
                    }
                }
                catch
                {
                    MessageBox.Show("输入数据违反要求!");
                }
                finally
                {
                    con.Dispose();
                }
                this.studentTableAdapter4.Fill(this.schoolDataSet15.Student);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
            }
    

      private void button4_Click(object sender, EventArgs e)
            {
                String StuID = textBox1.Text.Trim();
                String StuName = textBox2.Text.Trim();
                String StuSex = textBox3.Text.Trim();
                String StuAge = textBox4.Text.Trim();
                String StuSdept = textBox5.Text.Trim();
                String conn = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
                SqlConnection sqlConnection = new SqlConnection(conn);  //实例化连接对象
                try
                {
                    String select_by_id = "select * from Student where ";
                    int flag = 0;  //0是单条件,1是多条件
                    sqlConnection.Open();
                    if (StuID != "")
                        select_by_id += "Sno='" + StuID + "'";    //单条件 按学号
                    if (StuName != "")
                    {
                        if (flag == 0)
                        {
                            select_by_id += "Sname LIKE'" + StuName + "'";
                            flag = 1;
                        }
                        if (flag == 1)
                            select_by_id += "And Sname LIKE'" + StuName + "'";
                    }
                    if (StuAge != "")
                    {
                        if (flag == 0)
                        {
                            select_by_id += "Sage='" + StuAge + "'";
                            flag = 1;
                        }
                        if (flag == 1)
                            select_by_id += "And Sage='" + StuAge + "'";
                    }
                    if (StuSdept != "")
                    {
                        if (flag == 0)
                        {
                            select_by_id += "Sdept='" + StuSdept + "'";
                            flag = 1;
                        }
                        if (flag == 1)
                            select_by_id += "And Sdept='" + StuSdept + "'";
                    }
                    if (StuSex != "")
                    {
                        if (flag == 0)
                        {
                            select_by_id += "Ssex='" + StuSex + "'";
                            flag = 1;
                        }
                        if (flag == 1)
                            select_by_id += "And Ssex='" + StuSex + "'";
                    }
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                catch
                {
                    MessageBox.Show("查询语句有误,请认真检查SQL语句!");
                }
                finally
                {
                    sqlConnection.Close();
                }
    
            }
    

    返回

     private void button5_Click(object sender, EventArgs e)
            {
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
                textBox5.Text = "";
                String conn = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
                SqlConnection sqlConnection = new SqlConnection(conn);  //实例化连接对象
                try
                {
                    String select_by_id = "select * from Student";
    
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                catch
                {
                    MessageBox.Show("查询语句有误,请认真检查SQL语句!");
                }
                finally
                {
                    sqlConnection.Close();
                }
    
            }
    

    9.管理员对课程信息的增删改查
    在这里插入图片描述

    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.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class COURD : Form
        {
            public COURD()
            {
                InitializeComponent();
            }
    
            private void COURD_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet6.Course”中。您可以根据需要移动或删除它。
                this.courseTableAdapter.Fill(this.schoolDataSet6.Course);
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                String Cno = textBox1.Text.Trim();
                String Cname = textBox2.Text.Trim();
                String Cpno = textBox3.Text.Trim();
                String Ccredit = textBox4.Text.Trim();                 //读取需要插入的值
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
                try
                {
                    con.Open();
                    string insertStr = "INSERT INTO  Course (Cno,Cname,Cpno,Ccredit)    " +              //拼接字符串
                        "VALUES ('" + Cno + "','" + Cname + "','" + Cpno + "','" + Ccredit + "')";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    MessageBox.Show("输入数据违反要求!");
                }
                finally
                {
                    con.Dispose();
                }
                this.courseTableAdapter.Fill(this.schoolDataSet6.Course);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
    
            }
    
            private void textBox4_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");     //定义
                try
                {
                    con.Open();    //打开
                    string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是ID
                    string delete_by_id = "delete from Course where Cno=" + select_id;//sql删除语句
                    SqlCommand cmd = new SqlCommand(delete_by_id, con);        //使用
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    MessageBox.Show("请正确选择行!");
                }
                finally
                {
                    con.Dispose();     //释放
                }
                this.courseTableAdapter.Fill(this.schoolDataSet6.Course);
    
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                this.Close();
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                String Cno = "";
                if (textBox1.Text == "")
                { Cno = dataGridView1.SelectedCells[0].Value.ToString(); }
                else Cno = textBox1.Text.Trim();
    
                String Cname = textBox2.Text.Trim();
                String Cpno = textBox3.Text.Trim();
                String Ccredit = textBox4.Text.Trim();
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
    
                try
                {
                    string insertStr = "";
                    string insertStr1 = "";
                    string insertStr3 = "";
                    con.Open();
                    if (Cname != "")
                    {
                        insertStr = "UPDATE Course SET Cname = '" + Cname + "' WHERE Cno = '" + Cno + "'";    //修改名字
                        SqlCommand cmd = new SqlCommand(insertStr, con);
                        cmd.ExecuteNonQuery();
                    }
    
                    if (Cpno != "")
                    {
                        insertStr1 = "UPDATE Course SET Cpno = '" + Cpno + "' WHERE Cno = '" + Cno + "'";    //修改先导
                        SqlCommand cmd1 = new SqlCommand(insertStr1, con);
                        cmd1.ExecuteNonQuery();
                    }
    
                    if (Ccredit != "")
                    {
                        insertStr3 = "UPDATE Course SET Ccredit = '" + Ccredit + "' WHERE Cno = '" + Cno + "'";    //修改学分
                        SqlCommand cmd3 = new SqlCommand(insertStr3, con);
                        cmd3.ExecuteNonQuery();
                    }
    
                }
                catch
                {
                    MessageBox.Show("输入数据违反要求!");
                }
                finally
                {
                    con.Dispose();
                }
                this.courseTableAdapter.Fill(this.schoolDataSet6.Course);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
                textBox4.Text = "";
    
            }
        }
    }
    

    10.管理员对学生选课成绩增删改查
    在这里插入图片描述

    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.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace Test518
    {
        public partial class SCURD : Form
        {
            public SCURD()
            {
                InitializeComponent();
            }
    
            internal static void showdialog()
            {
                //      throw new NotImplementedException();
            }
    
            private void SCURD_Load(object sender, EventArgs e)
            {
                // TODO: 这行代码将数据加载到表“schoolDataSet5.SC”中。您可以根据需要移动或删除它。
                this.sCTableAdapter.Fill(this.schoolDataSet5.SC);
    
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                String StuID = textBox1.Text.Trim();
                String StuCno = textBox2.Text.Trim();
                String StuGrade = textBox3.Text.Trim();
                //读取需要插入的值
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
                try
                {
                    con.Open();
                    string insertStr = "INSERT INTO  SC (Sno,Cno,Grade)    " +             "VALUES ('" + StuID + "','" + StuCno + "','" + StuGrade + "')";
                    SqlCommand cmd = new SqlCommand(insertStr, con);
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    MessageBox.Show("输入数据违反要求!");
                }
                finally
                {
                    con.Dispose();
                }
                this.sCTableAdapter.Fill(this.schoolDataSet5.SC);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");     //定义
                try
                {
                    con.Open();    //打开
                    string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是ID
                    string select_cno = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();//选择的当前行第2列的值,也就是cno
                    string delete_by_id = "delete from SC where Sno=" + select_id + "AND Cno=" + select_cno;//sql删除语句
                    SqlCommand cmd = new SqlCommand(delete_by_id, con);        //使用
                    cmd.ExecuteNonQuery();
                }
                catch
                {
                    MessageBox.Show("请正确选择行!");
                }
                finally
                {
                    con.Dispose();     //释放
                }
                this.sCTableAdapter.Fill(this.schoolDataSet5.SC);
    
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                String StuID = "";
                String StuGrade = "";
                String StuCno = "";
                if (textBox1.Text == "")
                { StuID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); }
                else StuID = textBox1.Text.Trim();//输入学号修改
                if (textBox2.Text == "")
                {
                    StuCno = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                } //选中行修改          
                else StuCno = textBox2.Text.Trim();//输入修改
                if (textBox3.Text == "")
                {
                    StuGrade = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                }//选中行修改
                else StuGrade = textBox3.Text.Trim();//输入修改
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708");
    
                try
                {
                    string insertStr = "";
                    string insertStr1 = "";
                    con.Open();
                    if (StuCno != "")
                    {
                        insertStr = "UPDATE SC SET Cno = '" + StuCno + "' WHERE Sno = '" + StuID + "'" + "AND Grade='" + StuGrade + "'";    //修改课程
                        SqlCommand cmd = new SqlCommand(insertStr, con);
                        cmd.ExecuteNonQuery();
                    }
                    if (StuGrade != "")
                    {
                        insertStr1 = "UPDATE SC SET Grade = '" + StuGrade + "' WHERE Sno = '" + StuID + "'" + "AND Cno='" + StuCno + "'"; ;    //修改成绩
                        SqlCommand cmd1 = new SqlCommand(insertStr1, con);
                        cmd1.ExecuteNonQuery();
                    }
                }
                catch
                {
                    MessageBox.Show("输入数据违反要求!");
                }
                finally
                {
                    con.Close();
                }
                this.sCTableAdapter.Fill(this.schoolDataSet5.SC);
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
    
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                String StuID = textBox1.Text.Trim();
                String StuCno = textBox2.Text.Trim();
                String StuGrade = textBox3.Text.Trim();
                String conn = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
                SqlConnection sqlConnection = new SqlConnection(conn);  //实例化连接对象
                try
                {
                    String select_by_id = "select * from SC where ";
                    int flag = 0;  //0是单条件,1是多条件
                    sqlConnection.Open();
                    if (StuID != "")
                    {
                        select_by_id += "Sno='" + StuID + "'"; flag = 1;
                    } //单条件 按学号
                    if (StuCno != "")
                    {
                        if (flag == 0)
                        {
                            select_by_id += "Cno='" + StuCno + "'" + " ORDER BY Grade DESC";//单条件按课程号
                            flag = 1;
                        }
                        else if (flag == 1)//多条件按学号+课程号
                        { select_by_id += "And Cno='" + StuCno + "'"; }
    
                    }
                    if (flag == 0 && StuGrade != "")//单条件,查询平均分高于输入的学号
                    {
                        select_by_id = "select Sno,AVG(Grade) AS Avg FROM SC" + " GROUP BY Sno HAVING AVG(Grade)>=" + "'" + StuGrade + "'";
                    }
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                catch
                {
                    MessageBox.Show("查询语句有误,请认真检查SQL语句!");
                }
                finally
                {
                    sqlConnection.Close();
                }
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
    
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
    
                String conn = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";
                SqlConnection sqlConnection = new SqlConnection(conn);  //实例化连接对象
                try
                {
                    String select_by_id = "select * from SC";
    
                    sqlConnection.Open();
                    SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);
                    SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                    BindingSource bindingSource = new BindingSource();
                    bindingSource.DataSource = sqlDataReader;
                    dataGridView1.DataSource = bindingSource;
                }
                catch
                {
                    MessageBox.Show("查询语句有误,请认真检查SQL语句!");
                }
                finally
                {
                    sqlConnection.Close();
    
                }
            }
    
            private void label2_Click(object sender, EventArgs e)
            {
    
            }
    
            private void label3_Click(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    我的数据库大作业终于告一段落
    不得不说相比于以往的语言类课程我更喜欢数据库的学习,可能是懒惰,或许是天生对代码不感冒,不太擅长编程的我也愿意做一做数据库大作业,虽然我知道和同一起跑线的同学的成果与我的小程序判若云泥,自己动手做出一点东西已经心满意足

    展开全文
  • 数据库大作业by C#、SQL sever 需要准备:1、SQL sever数据库 2、Visual studio 2019(类似版本均可) 3、VS中安装.Net插件 第一步:使用VS打开打开代码 GitHub地址下载代码 不会使用GitHub的同学点开上面的...

    b站上陆陆续续有小伙伴对配置环境之类的有疑问,这里整体解答一下使用代码的过程:

    数据库大作业by C#、SQL sever

    需要准备:1、SQL sever数据库  2、Visual studio 2019(类似版本均可)  3、VS中安装.Net插件

     

    第一步:使用VS打开打开代码

    GitHub地址下载代码

    不会使用GitHub的同学点开上面的地址后,点击下面的红箭头部分下载代码到电脑,然后解压:

     

    第二步:打开VS,打开刚解压的文件夹里面的.sln文件

    然后我们可以看到以下界面:

    说明一下:

    ClassInfo为课程信息表的界面、Form1.cs为登陆界面、FormMain.cs为课程表界面、Sign为注册界面、TeacherInfo为教师信息表界面

    然后我们配置数据库:

    第一步:打开SQL sever(没学过数据库的同学建议稍微学习一下数据库的入门知识,比如增删改查),具体的初始使用的过程如果不太清楚可以百度,我们这儿直接sa连接(身份验证方式不是windows,需要注意一下):

     

    然后右键看到的数据库,选择新建数据库选项,数据库名称:classtime,注意此处尽量不要用别的,因为源代码里面配置的数据库连接名称为classtime,如果非要用其他的名称,源代码中的连接数据库名称也需要更改:

    然后在这个数据库中,新建查询:

    建立数据库代码,复制下面代码,然后执行:

    ​
    create table teacher(
    
    				tno char(9) primary key, 
    
    				tname char(10),
    
    				title char(10),  
    
    				tmajor char(10),
                                    tsex char(10)
    
    				)
    
    				
    
    create table course(
    
    				cno char(9) primary key,
    
    				cname char(10),
    
    				ctime char(10),   
    
    				examine char(10),   
    
    				ctno char(9),    
    
    				foreign key(ctno) references teacher(tno)
    
    				)
    
    create table clatime(
    
    				weektime char(10) ,
    
    				classnumber int,
    
    				scno char(9),
    
    				foreign key(scno) references course(cno),
    
    				stno char(9),
    
    				foreign key(stno) references teacher(tno),
    
    				primary key(weektime,classnumber)
    
    				)
    
    insert into teacher values('1555','王明','副教授','CS','男');
    
    insert into teacher values('1444','赵天海','讲师','AI','女');
    
    insert into teacher values('1111','李杰','无','CS','女');
    
    insert into teacher values('1222','孙磊','副教授','AI','女');
    
    insert into teacher values('1333','周悦','教授','AI','男');
    
    insert into teacher values('2333','郑平','副教授','政法','男');
    
    insert into teacher values('2666','周悦','教授','政法','男');
    
    insert into teacher values('3666','王东','教授','体育','男');
    
     
    
     
    
    insert into course values('02','数据库原理','52','考试','1222');
    
    insert into course values('03','电子线路','72','考试','1111');
    
    insert into course values('04','马原','72','考试','2333');
    
    insert into course values('05','创业基础','36','论文','1555');
    
    insert into course values('06','大学英语','72','考试','1444');
    
    insert into course values('07','电路实验','72','考察','1111');
    
    insert into course values('08','数据库实验','72','考察','1222');
    
    insert into course values('09','毛概','72','论文','2666');
    
    insert into course values('10','大学体育','72','考察','3666');
    
    insert into course values('11','运筹学','72','考试','1333');
    
    insert into course values('12','数学模型','72','考察','1333');
    
     
    
    insert into course values('01','数学模型','72','考试','1233');
    
    insert into clatime values('周一',1,'02','1222');
    
    insert into clatime values('周一',2,'03','1111');
    
    insert into clatime values('周一',3,'02','1555');
    
    insert into clatime values('周一',5,'04','2333');
    
    insert into clatime values('周二',2,'12','1333');
    
    insert into clatime values('周二',3,'06','1444');
    
    insert into clatime values('周二',5,'12','1333');
    
    insert into clatime values('周三',2,'07','1111');
    
    insert into clatime values('周三',3,'02','1222');
    
    insert into clatime values('周三',4,'02','1222');
    
    insert into clatime values('周三',5,'09','2666');
    
    insert into clatime values('周四',1,'06','1444');
    
    insert into clatime values('周四',2,'03','1111');
    
    insert into clatime values('周四',5,'09','2666');
    
    insert into clatime values('周五',2,'11','1333');
    
    insert into clatime values('周五',3,'10','3666');
    
    insert into clatime values('周五',3,'10','3666');
    ​

    然后在建立一个存储账号密码的表格

    create table login1(
                    account char(20) primary key,
                    pass char(64),
                    userphoto image
                    )

    检查一下数据库中是否存在这四个表,如果有就没问题,如果修改下面显示修改成功,但打开没有的话可以先刷新一下数据库,然后再点开:

    现在数据库中的数据和VS的数据基本上就对应上了,然后最重要的一步:

     SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=classtime;Persist Security Info=True;User ID=sa;Password=admin");

    把源代码中,sa密码改成你自己电脑数据库的密码:

    一定要注意哈,如果你前面数据库的名称没有用classtime,请把这里改成你前面输入的名称,后面的password虽然显示admin,但这个admin是我自己设置的,不是系统自带的,这里需要改成自己的密码!!!不然sa登陆也会错误!!!(补充:由于C#建立连接数据库的过程中生成了很多后端看不到的代码,因此此处建议直接把sa密码改成admin,不然也可能会报错)

     

    最后通过左键双击cs里的各种属性按钮就可以进行升级修改了。

    补充:由于一些原因,我当时在编程的时候用了我自己电脑上的另一个数据库TEST 进行了调试,后来只在C#中把有关TEST的数据库部分删除了,但由于C#后端自动生成代码,所以后端一些部分没有删除干净,因此如果电脑上只有classtime数据库还不太行。

    解决方法:(比较粗暴),直接另外新建立一个TEST数据库,然后在TEST模式下建立一个Student表,然后运行就OK了。

    create table Student(
    sno char(9)  primary key,
    sname  char(20),
    ssex char(2),  sage smallint, sdept char(20) 
    )
    
    

     

     

     

     

     

     

     

     

    展开全文
  • 一、Android Studio连接数据库 在连接我们本地的数据库之前,我们先要了解

    在这里插入图片描述

    一、Android Studio连接SQLserver数据库

    首先连接SQLserver需要向library中导入jdbc的jar包,将下载的jar包复制到libs中,右键包选择 add as library
    在这里插入图片描述
    可以到官网自行下载,为了方便我也上传了资源。点击下载

    接着我们创建一个DBUtil类,封装一个getSQLConnection(String ip, String user, String pwd, String db)类型的函数,用于获取Connection对象。
    我们使用jdbc来连接数据库,jdbc获取数据库连接代码如下:

    DriverManager.getConnection("jdbc:jtds:sqlserver://" + "你的ip" + ":1433/" + "数据库名" + ";charset=utf8", "数据库账户", "密码");
    

    ip地址为当前连接网络的ip地址,可以在命令提示符(cmd)里输入ipconfig找到。在这里插入图片描述

    为了实现登录功能我们还要获取登录界面里EditText里输入的文本和Spinner里的选项,并把数据打包成Bundle,传给DBUtil类,判断账号密码是否正确。具体代码已经贴在了下面。

    DBUtil具体代码如下:

    public class DBUtil
    {
        private  String name=null;
        private  String pass=null;
    
        public DBUtil(String m,String p){
            this.name=m;
            this.pass=p;
        }
        private static Connection getSQLConnection(String ip, String user, String pwd, String db)
        {
            Connection con = null;
            try
            {
                Class.forName("net.sourceforge.jtds.jdbc.Driver");
                con = DriverManager.getConnection("jdbc:jtds:sqlserver://" + "你的ip" + ":1433/" + "SCsystem" + ";charset=utf8", "账户", "密码");
            } catch (ClassNotFoundException e)
            {
                e.printStackTrace();
            } catch (SQLException e)
            {
                e.printStackTrace();
            }
            return con;
        }
    
        public String QuerySQL(String name,String pass,String ut)
        {
            String result = "";
            try
            {
                Connection conn= getSQLConnection("你的ip", "账号", "密码", "数据库名称");//根据自己的数据库信息填写对应的值
                String sql=null;
                if(ut=="学生登录") sql = "select * from Student_login where Sno='"+name+"' and  Spassword='"+pass+"'";
                else if(ut=="教师登录") sql= "select * from Teacher_login where Tno='"+name+"' and  Tpassword='"+pass+"'";//加单引号!不然隐式转换会报错查询不出来
                System.out.println(sql);
                Statement stat = conn.createStatement();
                ResultSet rs = stat.executeQuery(sql);
                while (rs.next())
                {
                    result= "1" ;
                }
                rs.close();
                conn.close();
            } catch (SQLException e)
            {
                e.printStackTrace();
                result += "查询数据异常!" + e.getMessage();
            }
            return result;
        }
        public static void main(String[] args)
        {
        }
    }
    

    MainActivity代码:

    public class MainActivity extends AppCompatActivity {
    
        private Spinner userSpinner=null;
        private Handler handler;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_login);
            findViews();
        }
    
        private void findViews() {
            //Spinner
            userSpinner=(Spinner)findViewById(R.id.spin_1);
            String[] usertype={"学生登录","教师登录"};
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,usertype);
            userSpinner.setAdapter(adapter);
    
            //EditText
            final EditText musername=(EditText) findViewById(R.id.edit_text_1);
            final EditText mpassword=(EditText) findViewById(R.id.edit_text_2);
            //button
            Button button1 = (Button) findViewById(R.id.button_1);
            WorkThread wt=new WorkThread();
            wt.start();
            button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String ut = userSpinner.getSelectedItem().toString();
                    String no = musername.getText().toString().trim();
                    String pw = mpassword.getText().toString().trim();
                    Message m=handler.obtainMessage();
                    Bundle b=new Bundle();
                    b.putString("name",no);
                    b.putString("pass",pw);
                    b.putString("ut",ut);
                    m.setData(b);
                    handler.sendMessage(m);
    
                }
            });
            //隐藏标题栏
            ActionBar actionbar= getSupportActionBar();
            if(actionbar!=null){
                actionbar.hide();
            }
        }
    
        //登录查询
        class WorkThread extends  Thread{
            @Override
            public  void run(){
                Looper.prepare();
                handler=new Handler(){
                    @Override
                    public  void handleMessage(Message m){
                        super.handleMessage(m);
                        Bundle b= m.getData();//得到与信息对用的Bundle
                        String name=b.getString("name");//根据键取值
                        String pass=b.getString("pass");
                        String ut=b.getString("ut");
                        DBUtil db=new DBUtil(name,pass);//调用数据库查询类
                        String ret=db.QuerySQL(name,pass,ut);//得到返回值
                        if (ret.equals("1"))//为1,页面跳转,登陆成功
                        {
                            Intent localIntent = new Intent();
                            localIntent.setClass(MainActivity.this, StudentView.class);
                            MainActivity.this.startActivity(localIntent);
                            Toast.makeText(MainActivity.this, "登录成功",Toast.LENGTH_SHORT).show();//显示提示框
                            return;
                        }
                        Toast.makeText(MainActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
    
                    }
                };
                Looper.loop();//Looper循环,通道中有数据执行,无数据堵塞
            }
        }
    }
    

    二、登录界面

    这个界面经过来来回回地更改,也算是变得好看了点(CardView真好用)
    没什么可说的就把布局文件贴出来好了

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#DCDCDC">
    
    
        <androidx.cardview.widget.CardView
            android:id="@+id/cardView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:alpha="0.7"
            app:cardCornerRadius="15dp"
            app:cardElevation="0dp"
            android:background="@drawable/school"
            app:cardBackgroundColor = "#FFFFFF">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="137dp"
                    android:background="@drawable/school1" />
                <TextView
                    android:id="@+id/tv_college_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="30dp"
                    android:gravity="center"
                    android:text="欢迎来到选课系统"
                    android:textColor="@color/purple_200"
                    android:textSize="35sp"
                    android:textStyle="bold" />
                <EditText
                    android:id="@+id/edit_text_1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="24dp"
                    android:layout_marginTop="30dp"
                    android:layout_marginEnd="24dp"
                    android:hint="@string/prompt_id"
                    android:inputType="number"
                    android:selectAllOnFocus="true" />
                <EditText
                    android:id="@+id/edit_text_2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="24dp"
                    android:layout_marginTop="8dp"
                    android:layout_marginEnd="24dp"
    
                    android:hint="@string/prompt_password"
                    android:inputType="textPassword"
                    android:selectAllOnFocus="true" />
                <Spinner
                    android:id="@+id/spin_1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="12dp"
                    android:scrollbarSize="20sp"
                    android:spinnerMode="dialog"
                    android:text="选择账户类型" />
                <Button
                    android:id="@+id/button_1"
                    android:layout_width="match_parent"
                    android:layout_height="72dp"
                    android:layout_marginTop="12dp"
                    android:layout_marginBottom="8dp"
                    android:layout_marginStart="8dp"
                    android:layout_marginEnd="8dp"
                    android:layout_gravity="center"
                    android:maxLines="1"
                    android:shadowColor="#FFF94C87"
                    android:text="登录" />
            </LinearLayout>
        </androidx.cardview.widget.CardView>
    </LinearLayout>
    

    三、小结

    这个部分最难搞的主要还是怎么把数据库连接到SQLserver,自己去寻找方法还是比较头疼的一件事,网上关于如何连接SQLserver的教程其实也不少,但总会多多少少的有些问题,还是自己钻研了一下语句,才做出来的这个登录界面。
    如果你也由连接数据库的问题,可以去看看下面这个文章,还是会有帮助的

    Android APP连接电脑数据库(以SQL Server为例)
    https://blog.csdn.net/qq_40399080/article/details/97630894

    展开全文
  • 数据库大作业--网上购物系统(sql server)--zq 数据库大作业--网上购物系统(sql server)--zq
  • 北航数据库大作业

    2016-04-01 18:20:51
    偶然翻到了原来做的数据库大作业,包含文档,源代码,和原始数据库文件,实现是用的VS2012+MFC+SQLSERVER2012,因为是当时赶工完成的,全部完成只用了1星期不到,所以质量很难保证。下下来看看文档啥的还可以,代码...
  • 数据库大作业复习 Oracle复习,附有各章节重要知识点和sql代码
  • 固定资产管理系统 数据库 大作业 课程设计 Eclipse MS SQL SERVER2000 文档 程序 齐全
  • 题目和要求链接如下 https://blog.csdn.net/weixin_46629224/article/details/111999429
  • 题目与要求链接:https://blog.csdn.net/weixin_46629224/article/details/111999429
  • 大型数据库大作业

    2013-05-23 21:35:12
    1)熟悉ORACLE的环境,学习使用SQL*Plus与ORACLE进行交互; (2)掌握连接数据库以及断开连接的方法; (3)掌握数据文件和控制文件的管理基本命令 (4)掌握表空间管理的基本命令
  • 题目和要求链接如下 https://blog.csdn.net/weixin_46629224/article/details/111999429
  • 本资源是自己写的asp大作业,包含数据库文件,直接自动生成数据库,可以直接运行。
  • 数据库大作业---人才招聘网站数据库,包含需求分析,sql语句,db文件。说明一下本身资源需要积分很少,不知道怎么现在变成这么多
  • 数据库大作业——仓库管理系统

    热门讨论 2010-04-02 15:12:46
    数据库大作业——有关仓库管理的大作业,有关使用sql—server数据库做数据库大作业的实验报告以及源程序。
  • 里面有多个数据库的文档 (6个) sql 包括 毕业设计安排,网店,教室,图书馆,仓库等。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 945
精华内容 378
关键字:

sql数据库大作业