using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp10
{
public partial class Form1 : Form
{
string conStr = "Data Source=(local);Initial Catalog=db_student;Integrated Security=True;";
SqlConnection con = null;
SqlDataAdapter da = null;
DataSet ds = null;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection(conStr);
da = new SqlDataAdapter("select * from studentscore", con);
ds = new DataSet();
da.Fill(ds, "studentscore");
dataGridView1.DataSource = ds.Tables["studentscore"];
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
txtNum.Text = dataGridView1.CurrentRow.Cells["num"].Value.ToString();
txtName.Text = dataGridView1.CurrentRow.Cells["name"].Value.ToString();
txtScore.Text = dataGridView1.CurrentRow.Cells["score"].Value.ToString();
}
private void btnselect_Click(object sender, EventArgs e)
{
SqlCommandBuilder builder = new SqlCommandBuilder(da);
DataRow r1 = ds.Tables["studentscore"].NewRow();
r1[0] = txtNum.Text;
r1[1] = txtName.Text;
r1[2] = txtScore.Text;
ds.Tables[0].Rows.Add(r1);
da.Update(ds, "studentscore");
dataGridView1.DataSource = ds.Tables["studentscore"];
}
private void btnUpdate_Click(object sender, EventArgs e)
{
SqlCommandBuilder builder= new SqlCommandBuilder(da);
DataRowCollection rows = ds.Tables["studentscore"].Rows;
DataRow row;
for(int i = 0; i < rows.Count; i++)
{
row = rows[i];
if (row["num"].ToString()==txtNum.Text)
{
row["score"]=txtScore.Text;
row["name"] = txtName.Text;
}
}
dataGridView1.DataSource = ds.Tables["studentscore"];
da.Update(ds, "studentscore");
}
private void btnDelete_Click(object sender, EventArgs e)
{
SqlCommandBuilder builder=new SqlCommandBuilder(da);
DataRowCollection rows = ds.Tables["studentscore"].Rows;
DataRow row;
for (int i = 0;i < rows.Count;i++)
{
row = rows[i];
if (row["num"].ToString()==txtNum.Text)
{
row.Delete();
}
}
da.Update(ds, "studentscore");
dataGridView1.DataSource = ds.Tables["studentscore"];
}
}
public class User {
private string name;
private string pwd;
private int role;
public string Name {
get { return name;}
set { name = value; }
}
public string Pwd
{
get { return pwd; }
set { pwd = value; }
}
public int Role
{
get { return role; }
set { role = value; }
}
public User()
{
name = "";
pwd = "";
role = 0;
}
public User(string _name,string _pwd,int _role)
{
name = _name;
pwd = _pwd;
role = _role;
}
}
public class RoomInfo {
private string roomId;
private string roomType;
private string roomFloor;
private double price;
private int personNum;
private int inPerson;
private string note;
public string RoomId {
get { return roomId; }
set { roomId = value; }
}
public string RoomType
{
get { return roomType; }
set { roomType = value; }
}
public string RoomFloor
{
get { return roomFloor; }
set { roomFloor = value; }
}
public double Price
{
get { return price; }
set { price = value; }
}
public int PersonNum
{
get { return personNum; }
set { personNum = value; }
}
public int InPerson
{
get { return inPerson; }
set { inPerson = value; }
}
public string Note
{
get { return note; }
set { note = value; }
}
}
public class CheckInRoom {
private int inId;
private string roomId;
private double price;
private double foregift;
private DateTime inTime;
private DateTime outTime;
private string clientName;
private bool sex;
private string phone;
private string certType;
private string certId;
private string address;
private string oper;
private int personNum;
private int delMark;
public int InId{
get { return inId; }
set { inId = value; }
}
public string RoomId
{
get { return roomId; }
set { roomId = value; }
}
public double Price
{
get { return price; }
set { price= value; }
}
public double Foregift
{
get { return foregift; }
set { foregift = value; }
}
public DateTime InTime
{
get { return inTime; }
set { inTime = value; }
}
public DateTime OutTime
{
get { return outTime; }
set { outTime = value; }
}
public string ClientName
{
get { return clientName; }
set { clientName = value; }
}
public bool Sex
{
get { return sex; }
set { sex = value; }
}
public string Phone
{
get { return phone; }
set { phone = value; }
}
public string CertType
{
get { return certType; }
set { certType = value; }
}
public string CertId
{
get { return certId; }
set { certId = value; }
}
public string Address
{
get { return address; }
set { address= value; }
}
public int PersonNum
{
get { return personNum; }
set { personNum= value; }
}
public string Oper
{
get { return oper; }
set { oper = value; }
}
public int DelMark
{
get { return delMark; }
set { delMark = value; }
}
}
}