private void btnLogin_Click(object sender, EventArgs e) { string strName = txtName.Text; string strPasw = txtPassword.Text; string sql = "select id " + "from reader " + "where name = @strName and password = @strPasw"; SqlCommand cmd = new SqlCommand(sql, Library.Connection.Instance()); cmd.Parameters.AddWithValue("@strName", strName); cmd.Parameters.AddWithValue("@strPasw", strPasw); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { int id = reader.GetInt32(0); frmMain main = new frmMain(); this.Hide(); readerId = id; reader.Close(); main.ShowDialog(); } else { MessageBox.Show("你的账号或密码错误。"); reader.Close(); } }
private void button1_Click(object sender, EventArgs e) { DateTime nowtime = System.DateTime.Now; int readerId = frmLogin.readerId; string sql3 = "INSERT INTO reserve(reader_id, book_isbn, reserve_time, available) " + "VALUES (@readerId, @ISBN, @nowtime, 1)"; SqlCommand cmd = new SqlCommand(sql3, Library.Connection.Instance()); cmd = new SqlCommand(sql3, Library.Connection.Instance()); cmd.Parameters.AddWithValue("@readerid", readerId); cmd.Parameters.AddWithValue("@ISBN", isbn); cmd.Parameters.AddWithValue("@nowtime", nowtime); //cmd.Parameters.AddWithValue("@1", 1); cmd.ExecuteNonQuery(); frmMain frm = new frmMain(); this.Hide(); frm.ShowDialog(); this.Show(); }