Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
 public void AddTitle_Click(object sender, EventArgs e)
 {
     //get title of book
     try
     {
         int  Quantity;
         bool Qty = int.TryParse(QuantityText.Text, out Quantity);             //grab number input
         if (Qty && Quantity != 0 && !(Quantity < 0))                          //handle exception 0 and negative numbers
         {
             decimal totalCost = Quantity * Convert.ToDecimal(PriceText.Text); //Get the total
             // Populate the rows.
             string   selectedItem = (string)comboBox1.SelectedItem;
             string[] row          = new string[] { selectedItem, PriceText.Text, Quantity.ToString(), totalCost.ToString() }; //populate and add row
                                                                                                                               //populate dataGridView upon click Add Title
             dataGridView1.Rows.Add(row);
             subTotal          += Quantity * Convert.ToDouble(PriceText.Text);                                                 //add total
             Subtotal_Text.Text = Math.Round(subTotal, 2).ToString();
             TaxText.Text       = (Math.Round(subTotal * tax, 2)).ToString();
             TotalText.Text     = (Math.Round((subTotal * tax) + subTotal, 2)).ToString();
         }
         else
         {
             MessageBox.Show("Please enter a valid number");
             QuantityText.Focus();//cursor on field
         }
     }
     catch
     {
         MessageBox.Show("Please select a book from the list.");
     }
 }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// When the "Add Title" button is clicked, the selected book and all of its characteristics will appear in
        /// dataGridView1 and also update the subtotal, tax, and total boxes with correct values and information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTitle_Click(object sender, EventArgs e)
        {
            //get title
            try
            {
                int  quantity;
                bool QTY = int.TryParse(QuantityText.Text, out quantity);

                if (QTY && quantity != 0 && !(quantity < 0))
                {
                    decimal? totalCost    = quantity * Convert.ToDecimal(PriceText.Text);
                    string   SelectedItem = (string)comboBox1.SelectedItem;
                    string[] row          = new string[] { SelectedItem, "$" + PriceText.Text, quantity.ToString(), "$" + totalCost.ToString() };

                    dataGridView1.Rows.Add(row);
                    subTotal          += quantity * Convert.ToDouble(PriceText.Text);
                    Subtotal_Text.Text = "$" + subTotal.ToString();
                    TaxText.Text       = (subTotal * tax).ToString();
                    TotalText.Text     = "$" + ((subTotal * tax) + subTotal).ToString();
                    QuantityText.Text  = quantity.ToString();
                }
                else
                {
                    MessageBox.Show("Enter a Number");
                    QuantityText.Focus();
                }
            }
            catch
            {
                MessageBox.Show("Select a Book");
            }
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
0
            public void Bind(IOrderContent model)
            {
                CellContentRootView?.SetBackgroundColor(ColorConstants.BackroundCell, 5);

                CategoryImage?.SetImageFromUrl(model.ImagePath);

                if (!ItemNameText.IsNull())
                {
                    ItemNameText.Text = model.OrderName;
                    ItemNameText?.SetTextColor(ColorConstants.WhiteColor);
                    ItemNameText.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!PriceText.IsNull())
                {
                    PriceText.Text = "€" + model.Price * Convert.ToInt32(model.Quantity);
                    PriceText?.SetTextColor(ColorConstants.SelectorHome);
                    PriceText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (QuantityText.IsNull())
                {
                    return;
                }
                QuantityText.Text = model.Quantity + " pcs";
                QuantityText?.SetTextColor(ColorConstants.WhiteColor);
                QuantityText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
            }
Ejemplo n.º 7
0
            public void Bind(IOrderContent model)
            {
                CellContentRootView?.SetBackgroundColor(ColorConstants.BackroundCell, 5);
                CategoryImage?.SetImageFromUrl(model.ImagePath);

                if (!RemoveOrderImage.IsNull())
                {
                    RemoveOrderImage?.SetImageFromResource(DrawableConstants.OrderRemoveIcon);

                    RemoveOrderImage.Tag = model;

                    RemoveOrderImage.Click -= RemoveOrderImage_Click;
                    RemoveOrderImage.Click += RemoveOrderImage_Click;
                }

                if (!ItemNameText.IsNull())
                {
                    ItemNameText.Text = model.OrderName;
                    ItemNameText?.SetTextColor(ColorConstants.WhiteColor);
                    ItemNameText.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!PriceText.IsNull())
                {
                    PriceText.Text = "€" + model.Price * Convert.ToInt32(model.Quantity);
                    PriceText?.SetTextColor(ColorConstants.SelectorHome);
                    PriceText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (!MinusText.IsNull())
                {
                    MinusText?.SetTextColor(ColorConstants.WhiteColor);
                    MinusText?.SetFont(FontsConstant.OpenSansRegular, FontsConstant.Size20);
                    MinusText?.SetBackgroundColor(ColorConstants.SelectorHome, type: RadiusType.Aspect);
                    MinusText?.SetSelectedColor(ColorConstants.SelectorHome.SelectorTransparence(ColorConstants.Procent50));
                    MinusText.Text = "-";
                    MinusText.Tag  = new { Model = model };

                    MinusText.Click -= MinusText_Click;
                    MinusText.Click += MinusText_Click;
                }

                if (!QuantityText.IsNull())
                {
                    QuantityText.Text = model.Quantity;
                    QuantityText?.SetTextColor(ColorConstants.WhiteColor);
                    QuantityText?.SetFont(FontsConstant.OpenSansBold, FontsConstant.Size14);
                }

                if (PlusText.IsNull())
                {
                    return;
                }
                PlusText?.SetTextColor(ColorConstants.WhiteColor);
                PlusText?.SetFont(FontsConstant.OpenSansRegular, FontsConstant.Size20);
                PlusText.Text = "+";
                PlusText?.SetBackgroundColor(ColorConstants.SelectorHome, type: RadiusType.Aspect);
                PlusText?.SetSelectedColor(ColorConstants.SelectorHome.SelectorTransparence(ColorConstants.Procent50));

                PlusText.Tag = new { Model = model };

                PlusText.Click -= PlusText_Click;
                PlusText.Click += PlusText_Click;
            }