Exemplo n.º 1
0
        /// <summary>
        /// This creates the book and if a certain book is picked, the corresponding text boxes will update with the
        /// correct information in each box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string SelectedItem = (string)comboBox1.SelectedItem;

            try
            {
                string  jsonBook     = File.ReadAllText(@"Z:\Desktop\Fourth Year (F18-S19)\CompE561\Lab1\Lab1\bin\Debug\BookList.json");
                JObject JSON         = JObject.Parse(jsonBook);
                JObject targetBook   = (JObject)JSON[SelectedItem];
                string  s_targetBook = targetBook.ToString();
                Book    found        = new Book();
                Newtonsoft.Json.JsonConvert.PopulateObject(s_targetBook, found);
                AuthorText.Text = found.author;;
                IsbnText.Text   = found.ISBN;
                PriceText.Text  = found.price.ToString();
            }

            catch
            {
                AuthorText.Clear();
                IsbnText.Clear();
                PriceText.Clear();
            }
            QuantityText.Focus();
        }
Exemplo n.º 2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) //event handle when picking an item
        {
            try
            {
                MySqlConnection connection = new MySqlConnection("Datasource=localhost;port=3306;username=root;password="******"\"{comboBox1.SelectedItem.ToString()}\"";
                string query        = "SELECT * FROM bookstore.books WHERE title = " + selectedItem;
                connection.Open();
                MySqlCommand    command = new MySqlCommand(query, connection);
                MySqlDataReader reader  = command.ExecuteReader();
                if (reader.Read())
                {
                    AuthorText.Text = reader["author"].ToString();
                    PriceText.Text  = reader["price"].ToString();
                    IsbnText.Text   = reader["ISBN"].ToString();
                }
                connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //clear form
                AuthorText.Clear();
                IsbnText.Clear();
                PriceText.Clear();
            }

            QuantityText.Focus();
        }
Exemplo n.º 3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) //event handle when picking an item
        {
            string SelectedItem = (string)comboBox1.SelectedItem;

            try
            {
                //access books
                string  BookJSON = File.ReadAllText(@"C:\Users\RMBonMAC\Documents\GitHub\BookStore\BookStore\BookStore\bin\Debug\Books.json");
                JObject json     = JObject.Parse(BookJSON);

                JObject BookTarget = (JObject)json[SelectedItem];

                string book_target = BookTarget.ToString();

                Book foundBook = new Book();
                Newtonsoft.Json.JsonConvert.PopulateObject(book_target, foundBook);
                AuthorText.Text = foundBook.author;;
                IsbnText.Text   = foundBook.ISBN;
                PriceText.Text  = foundBook.price.ToString();
            }
            catch {
                AuthorText.Clear();
                IsbnText.Clear();
                PriceText.Clear();
            }

            QuantityText.Focus();
        }