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;
using System.Data.SqlClient;
using System.IO;
namespace Checkguest
{
public partial class Checkguest : Form
{
public Checkguest()
{
InitializeComponent();
}
private void btQuery_Click(object sender, EventArgs e)
{
sqlConnection.Open();
ds = new DataSet();
string sql;
if (dormid.Text.Trim() == "")
sql = "select * from register where datecome='" + date.Value.Date.ToString() + "'";
else
sql = "select * from register where dormid like '%" + dormid.Text.Trim() + "%'";
SqlDataAdapter adp = new SqlDataAdapter(sql, sqlConnection);
adp.Fill(ds, "register");
DataTable dt = ds.Tables[0];
dt.Columns["registerid"].ColumnName = "编号";
dt.Columns["dormid"].ColumnName = "宿舍号";
dt.Columns["comename"].ColumnName = "来访人";
dt.Columns["datecome"].ColumnName = "来访时间";
dt.Columns["lookname"].ColumnName = "被访人";
dt.Columns["dateleave"].ColumnName = "离开时间";
dt.Columns["remark"].ColumnName = "备注";
dataGridView1.DataSource = dt;
for (int i = 0; i < this.dataGridView1.Rows.Count; )
{
this.dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightBlue;
i += 2;
}
sqlConnection.Close();
}
private void btDelete_Click(object sender, EventArgs e)
{
if (this.dataGridView1.CurrentRow != null)
{
sqlConnection1.Open();
string sql = "delete from register where registerid='" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][0].ToString().Trim() + "'";
if (MessageBox.Show("你真的要删除该条信息吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
SqlCommand cmd = new SqlCommand(sql, sqlConnection1);
cmd.ExecuteNonQuery();
MessageBox.Show("删除'" + ds.Tables[0].Rows[dataGridView1.CurrentRow.Index][4].ToString().Trim() + "'成功!", "提示");
sqlConnection1.Close();
}
else
sqlConnection1.Close();
}
}
}
}