代码拉取完成,页面将自动刷新
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Xml.Linq;
using WindowsFormsApp1.lei;
using WindowsFormsApp1.entity;
namespace WindowsFormsApp1
{
public partial class teacherFiles : Form
{
private DBHelper DBHelper = new DBHelper();
DataTable dataTable = new DataTable();
public teacherFiles()
{
InitializeComponent();
}
//读取数据库中的数据
public void readMes(string name)
{
dataTable.Clear();
string sql = null;
if (!string.IsNullOrEmpty(name))
{
sql = "select id,姓名,性别,年龄,用户ID from 教师信息 where 姓名 = '{0}'";
sql = string.Format(sql, name);
}
else
{
sql = "select id,姓名,性别,年龄,用户ID from 教师信息";
}
dataTable = DBHelper.ExecSqlForDataTable(sql);
this.dataGridView1.DataSource = null;
this.dataGridView1.DataSource = dataTable;
}
//查询数据
private void TeacherQuery_Click(object sender, EventArgs e)
{
readMes(this.textBoxTeacher.Text);
}
//页面加载初始化数据
public void teacherFiles_Load(object sender, EventArgs e)
{
readMes(null);
this.dataGridView1.AllowUserToAddRows = false;
}
//添加数据
private void buttonQuery_Click(object sender, EventArgs e)
{
teacherAdd tea = new teacherAdd();
if (tea.ShowDialog() == DialogResult.OK)
{
readMes(null);
}
}
//修改数据
public void buttonModiy_Click(object sender, EventArgs e)
{
int id = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
teacheModity teachermodity = new teacheModity(id);
if (teachermodity.ShowDialog() == DialogResult.OK)
{
readMes(null);
}
}
//删除数据
private void buttonDelete_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()))
{
int id = int.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
string sql = "delete from 教师信息 where id = {0}";
sql = string.Format(sql, id);
if (MessageBox.Show("是否删除","success", MessageBoxButtons.OKCancel)==DialogResult.OK)
{
int a = DBHelper.ExecSql(sql);
}
}
readMes(null);
}
private void button1_Click(object sender, EventArgs e)
{
string dir = AppDomain.CurrentDomain.BaseDirectory;
string path = string.Format("{0}\\teacher.grf",dir);
Teacher teacher = new Teacher();
teacher.ID = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
teacher.Name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
teacher.Sex = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
teacher.Age = this.dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
teacher.Uid = this.dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
PrintUtil printUtil = new PrintUtil();
printUtil.Teacher = teacher;
printUtil.ExecPrintPreview(path);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。