📄 info.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 info : Form
{
public string USERID;
public info()
{
InitializeComponent();
skinEngine1.SkinFile = "DiamondBlue.ssk";
login temp = new login(this);
temp.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text != "")
{
dataGridView1.DataSource = null;
try
{
SqlConnection myconnection = new SqlConnection();
myconnection.ConnectionString = "server=hxl;database=studentpoints;integrated security=true ";
myconnection.Open();
SqlCommand mycommand = new SqlCommand();
mycommand.CommandText = "select * from 学生信息 where 学号='" + Convert.ToInt64(textBox1.Text.Trim()) + "'";
mycommand.Connection = myconnection;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.SelectCommand.Connection = myconnection;
DataSet ds = new DataSet();
da.Fill(ds, "学生信息");
dataGridView1.DataSource = ds.Tables["学生信息"];
if (ds.Tables["学生信息"].Rows.Count<1)
{
MessageBox.Show("不存在该学生!");
}
textBox1.Text = "";
}
catch (FormatException fe)
{
MessageBox.Show("学号输入错误," + fe.Message);
}
}
else
{
MessageBox.Show("请输入需要查找的学生的学号!");
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox3.Text = "";
}
private void button4_Click(object sender, EventArgs e)
{
if (textBox2.Text != "")
{
dataGridView1.DataSource = null;
try
{
SqlConnection myconnection = new SqlConnection();
myconnection.ConnectionString = "server=hxl;database=studentpoints;integrated security=true ";
myconnection.Open();
SqlCommand mycommand = new SqlCommand();
mycommand.CommandText = "select 成绩表.学号,学生信息.姓名,成绩表.课程名,成绩表.分数,成绩表.重考分数,成绩表.学分,成绩表.学期 from 成绩表,学生信息 where 学生信息.学号=成绩表.学号 and 成绩表.学号='" + Convert.ToInt64(textBox2.Text.Trim()) + "'";
mycommand.Connection = myconnection;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.SelectCommand.Connection = myconnection;
DataSet ds = new DataSet();
da.Fill(ds, "成绩表");
dataGridView2.DataSource = ds.Tables["成绩表"];
if (ds.Tables["成绩表"].Rows.Count < 1)
{
MessageBox.Show("不存在该学生!");
}
textBox1.Text = "";
}
catch (FormatException fe)
{
MessageBox.Show("学号输入错误," + fe.Message);
}
}
else
{
MessageBox.Show("请输入需要查找的学生的学号!");
}
}
private void 成绩管理ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
pointoperate temp = new pointoperate();
temp.ShowDialog();
}
private void 学生信息管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
insertstudent temp = new insertstudent();
temp.ShowDialog();
}
private void 帐户管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
user temp = new user();
temp.ShowDialog();
}
private void button3_Click(object sender, EventArgs e)
{
textBox2.Text = "";
textBox4.Text = "";
}
private void info_Load(object sender, EventArgs e)
{
authrity(USERID);
}
public void authrity(string userid)
{
if (userid == "3")
{
学生信息管理ToolStripMenuItem.Enabled = false;
成绩管理ToolStripMenuItem.Enabled = false;
帐户管理ToolStripMenuItem.Enabled = false;
}
else if (userid == "2")
{
帐户管理ToolStripMenuItem.Enabled = false;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
if (textBox3.Text != "")
{
dataGridView1.DataSource = null;
try
{
SqlConnection myconnection = new SqlConnection();
myconnection.ConnectionString = "server=hxl;database=studentpoints;integrated security=true ";
myconnection.Open();
SqlCommand mycommand = new SqlCommand();
mycommand.CommandText = "select * from 学生信息 where 姓名='" +textBox3.Text.Trim() + "'";
mycommand.Connection = myconnection;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.SelectCommand.Connection = myconnection;
DataSet ds = new DataSet();
da.Fill(ds, "学生信息");
dataGridView1.DataSource = ds.Tables["学生信息"];
if (ds.Tables["学生信息"].Rows.Count < 1)
{
MessageBox.Show("不存在该学生!");
}
textBox3.Text = "";
}
catch (FormatException fe)
{
MessageBox.Show("输入错误," + fe.Message);
}
}
else
{
MessageBox.Show("请输入需要查找的学生的姓名!");
}
}
private void button6_Click(object sender, EventArgs e)
{
if (textBox4.Text != "")
{
dataGridView1.DataSource = null;
try
{
SqlConnection myconnection = new SqlConnection();
myconnection.ConnectionString = "server=hxl;database=studentpoints;integrated security=true ";
myconnection.Open();
SqlCommand mycommand = new SqlCommand();
mycommand.CommandText = "select 成绩表.学号,学生信息.姓名,成绩表.课程名,成绩表.分数,成绩表.重考分数,成绩表.学分,成绩表.学期 from 成绩表,学生信息 where 学生信息.学号=成绩表.学号 and 学生信息.姓名='" + textBox4.Text.Trim() + "'";
mycommand.Connection = myconnection;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = mycommand;
da.SelectCommand.Connection = myconnection;
DataSet ds = new DataSet();
da.Fill(ds, "成绩表");
dataGridView2.DataSource = ds.Tables["成绩表"];
if (ds.Tables["成绩表"].Rows.Count < 1)
{
MessageBox.Show("不存在该学生!");
}
textBox4.Text = "";
}
catch (FormatException fe)
{
MessageBox.Show("输入错误," + fe.Message);
}
}
else
{
MessageBox.Show("请输入需要查找的学生的姓名!");
}
}
private void button7_Click(object sender, EventArgs e)
{
//dataGridView1.DataSource = this.学生信息BindingSource;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -