You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.1 KiB

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 Sql
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
toolStripStatusLabel3.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
timer1.Start();
Table();
}
private void timer1_Tick(object sender, EventArgs e)
{
toolStripStatusLabel3.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
//定义表
public void Table()
{
dataGridView1.Rows.Clear(); //清除前面的数据,方便后面重新刷新数据
string sql = "select * from seat";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
while (dr.Read())
{
string a, b, c, d;
a = dr["Id"].ToString(); //这例可以自己修改
b = dr["Name"].ToString();
c = dr["Time"].ToString();
d = dr["Password"].ToString();
string[] str = { a, b, c, d };
dataGridView1.Rows.Add(str); //添加数据
}
dr.Close();//关闭连接
}
//添加
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form41 f = new Form41(this); //调用form41中的函数
f.ShowDialog();
}
//修改
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
string[] str = { dataGridView1.SelectedCells[0].Value.ToString(), dataGridView1.SelectedCells[1].Value.ToString(), dataGridView1.SelectedCells[2].Value.ToString(), dataGridView1.SelectedCells[3].Value.ToString() };
// MessageBox.Show(str[0]+str[4]);
Form41 f = new Form41(str, this);
f.ShowDialog();
}
//删除
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult r = MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
string id, name;
id = dataGridView1.SelectedCells[0].Value.ToString();
name = dataGridView1.SelectedCells[1].Value.ToString();
string sql = "delete from seat where Id='" + id + "'and Name='" + name + "'";
MessageBox.Show("已删除座位——" + name + "");
Dao dao = new Dao();
dao.Execute(sql);
Table(); //调用36行的私有类函数实现刷新表的功能
}
}
private void 退ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
}
}
}