예제 #1
0
        public static bool Delete(Reservation c)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Delete Reservation where id = @id", cn);
                cmd.Parameters.AddWithValue("@id", c.Id);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
예제 #2
0
        public static bool Insert(Reservation c)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Insert into Reservation(borrowerNumber, bookNumber, date, status)"
                    + "values(@borrowerNumber, @bookNumber, @date, @status)", cn);
                cmd.Parameters.AddWithValue("@borrowerNumber", c.BorrowerNumber);
                cmd.Parameters.AddWithValue("@bookNumber", c.BookNumber);
                cmd.Parameters.AddWithValue("@date", c.Date);
                cmd.Parameters.AddWithValue("@status", c.Status);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();
                return true;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
예제 #3
0
        public static bool Update(Reservation c)
        {
            try
            {
                SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=Library;Integrated Security=True");
                SqlCommand cmd = new SqlCommand("Update Reservation set borrowerNumber = @borrowerNumber, "
                + "bookNumber = @bookNumber, date = @date, status=@status where id = @id", cn);
                cmd.Parameters.AddWithValue("@borrowerNumber", c.BorrowerNumber);
                cmd.Parameters.AddWithValue("@bookNumber", c.BookNumber);
                cmd.Parameters.AddWithValue("@date", c.Date);
                cmd.Parameters.AddWithValue("@status", c.Status);
                cmd.Parameters.AddWithValue("@id", c.Id);

                cn.Open();
                cmd.ExecuteNonQuery();
                cn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }