Beispiel #1
0
        //Method to save a book
        public static void SaveBook(BookClass myBook, string cwid, string mode)
        {
            var    content = new StringContent(JsonConvert.SerializeObject(myBook).ToString(), Encoding.UTF8, "application/json");
            string url;

            if (mode == "edit")
            {
                url = @"http://lucas-swami-api.herokuapp.com/books/" + myBook._id;
            }
            else
            {
                url = @"http://lucas-swami-api.herokuapp.com/books/"; // + cwid;
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");

                if (mode == "edit")
                {
                    var response = httpClient.PutAsync(new Uri(url), content).Result;
                }
                else
                {
                    var response = httpClient.PostAsync(new Uri(url), content).Result;
                }
            }
        }
Beispiel #2
0
        private void BtnReturn_Click(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;

            myBook.copies++;
            BookFile.SaveBook(myBook, cwid, "edit");
            LoadList();
        }
Beispiel #3
0
 //Method for the form edit design
 public frmEdit(Object tempBook, string tempMode, string tempCwid)
 {
     //Variables for the form edit design box
     myBook = (BookClass)tempBook;
     cwid   = tempCwid;
     mode   = tempMode;
     InitializeComponent();
     pbCover.SizeMode = PictureBoxSizeMode.StretchImage;
 }
Beispiel #4
0
        //Method to delete a book
        public static void DeleteBook(BookClass myBook, string cwid)
        {
            string url = @"http://lucas-swami-api.herokuapp.com/books/" + myBook._id;

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");

                var response = httpClient.DeleteAsync(new Uri(url)).Result;
            }
        }
Beispiel #5
0
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;

            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete?", "Delete", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                BookFile.DeleteBook(myBook, cwid);
                LoadList();
            }
        }
Beispiel #6
0
        private void BtnNew_Click(object sender, EventArgs e)
        {
            BookClass myBook = new BookClass();
            frmEdit   myForm = new frmEdit(myBook, "new", cwid);

            if (myForm.ShowDialog() == DialogResult.OK)
            {
            }
            else
            {
                LoadList();
            }
        }
Beispiel #7
0
        private void BtnEdit_Click(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;
            frmEdit   myForm = new frmEdit(myBook, "edit", cwid);

            if (myForm.ShowDialog() == DialogResult.OK)
            {
            }
            else
            {
                LoadList();
            }
        }
Beispiel #8
0
        //Loads the book cover
        private void LstBooks_SelectedIndexChanged(object sender, EventArgs e)
        {
            BookClass myBook = (BookClass)lstBooks.SelectedItem;

            txtTitleData.Text  = myBook.title;
            txtAuthorData.Text = myBook.author;
            txtGenreData.Text  = myBook.genre;
            txtCopiesAvbl.Text = myBook.copies.ToString();
            txtLengthData.Text = myBook.length.ToString();
            txtISPNData.Text   = myBook.isbn;

            try
            {
                pbCover.Load(myBook.cover);
            }
            catch
            {
            }
        }