1 Star 0 Fork 0

wyb/SlSoftSecond

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
subjectRecord.cs 3.09 KB
一键复制 编辑 原始数据 按行查看 历史
wyb 提交于 2024-04-07 17:08 . 四五次作业
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using WindowsFormsApp1.lei;
namespace WindowsFormsApp1
{
public partial class subjectRecord : Form
{
private DBHelper Dbh = new DBHelper();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
public subjectRecord()
{
InitializeComponent();
}
//查询学生档案信息
public void readStudentMessage(string name)
{
dt.Clear();
string sql;
if(!string.IsNullOrEmpty(name))
{
sql = "select id,姓名,性别,年龄,用户ID from 学生信息 where 姓名 = '{0}'";
sql = string.Format(sql, name);
}else
{
sql = "select id,姓名,性别,年龄,用户ID from 学生信息";
}
dt = Dbh.ExecSqlForDataTable(sql);
this.dataGridView1.DataSource = null;
this.dataGridView1.DataSource = dt;
}
//页面加载展示数据
private void subjectRecord_Load(object sender, EventArgs e)
{
readStudentMessage(null);
}
//根据名字查询数据
private void TeacherQuery_Click(object sender, EventArgs e)
{
readStudentMessage(this.textBoxT1.Text);
}
//添加数据
private void buttonAdd_Click(object sender, EventArgs e)
{
studentAM sdam = new studentAM(null);
if(sdam.ShowDialog() == DialogResult.OK)
{
readStudentMessage(null);
}
}
//修改
private void buttonModiy_Click(object sender, EventArgs e)
{
string name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
studentAM students = new studentAM(name);
if(students.ShowDialog() == DialogResult.OK)
{
readStudentMessage(null);
}
}
//删除
private void buttonDelete_Click(object sender, EventArgs e)
{
int id = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
string name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
string sql = "select 姓名 from 学生信息 where 姓名 = '{0}'";
sql = string.Format(sql,name);
dt1 = Dbh.ExecSqlForDataTable(sql);
if(dt1.Rows.Count <= 0)
{
MessageBox.Show("需要删除的信息不存在");
return;
}
else
{
string sql1 = "delete from 学生信息 where id = {0}";
sql1 = string.Format(sql1,id);
int a = Dbh.ExecSql(sql1);
if (a>0)
{
readStudentMessage(null);
MessageBox.Show("删除成功");
return;
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wyhwd/sl-soft-second.git
git@gitee.com:wyhwd/sl-soft-second.git
wyhwd
sl-soft-second
SlSoftSecond
master

搜索帮助