1 Star 0 Fork 0

wyb/SlSoftSecond

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
teacherFiles.cs 3.74 KB
一键复制 编辑 原始数据 按行查看 历史
wyb 提交于 2024-04-08 09:07 . 打印和bug完成
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);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wyhwd/sl-soft-second.git
git@gitee.com:wyhwd/sl-soft-second.git
wyhwd
sl-soft-second
SlSoftSecond
master

搜索帮助