Пример #1
0
        public store()
        {
            InitializeComponent();
            // create a teas list object
            teas = new TeaList();

            // load combobox of teas
            for (var i = 0; i < teas.Length(); ++i)
            {
                cbTeas.Items.Add(teas.GetTea(i).Name);
            }

            //set data for first tea object
            imgTeaPicture.Source = new BitmapImage(new Uri(teas.GetTea(0).Image, UriKind.Relative));
            tbName.Text          = teas.GetTea(0).Name;
            tbDescription.Text   = teas.GetTea(0).Description;
            tbCost.Text          = string.Format("${0:0.00}", teas.GetTea(0).Cost);

            //enable button when your checkoutlist is bigger than 0
            if (StaticCheckOutList.Count() != 0)
            {
                btnProccedToCheckOut.IsEnabled = true;
            }

            //load combo box
            lvCheckOut.ItemsSource = StaticCheckOutList.GetList();
        }
Пример #2
0
        private void AddToCartOnClick(object sender, RoutedEventArgs e)
        {
            // grab the combo box index
            int currentMyComboBoxIndex = cbTeas.SelectedIndex;

            item                    = new CheckOut();
            item.ProductName        = teas.GetTea(currentMyComboBoxIndex).Name;
            item.ProductDescription = teas.GetTea(currentMyComboBoxIndex).Description;

            SetDefaultColors();
            //if valid
            if (IsValid())
            {
                item.ProductSize  = cbSize.Text;
                item.Quntity      = Int32.Parse(cbQty.Text);
                item.ProductCost  = teas.GetTea(currentMyComboBoxIndex).Cost;
                item.ProductTotal = item.ProductCost * item.Quntity;

                //use the message queue to send a message.
                var messageQueue = SnackbarAdded.MessageQueue;
                var message      = item.Quntity + " " + item.ProductName + " Added";

                //the message queue can be called from any thread
                Task.Factory.StartNew(() => messageQueue.Enqueue(message));
                StaticCheckOutList.Add(item);

                //load items into list view from static object
                lvCheckOut.Items.Refresh();

                btnProccedToCheckOut.IsEnabled = true;
            }
        }
 private void LvCheckOut_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     //display values to user
     listViewIndex      = lvCheckOut.SelectedIndex;
     tbProductName.Text = StaticCheckOutList.GetByIndex(listViewIndex).ProductName;
     tbChangeQty.Text   = StaticCheckOutList.GetByIndex(listViewIndex).Quntity.ToString();
 }
Пример #4
0
 private void CheckOutOnClick(object sender, RoutedEventArgs e)
 {
     //disable button if the user isn't set and checkoutlist isn't set
     if (StaticUser.FirstName != null && StaticCheckOutList.Count() != 0)
     {
         Main.Content = new Checkout();
     }
 }
Пример #5
0
 public home()
 {
     InitializeComponent();
     //load user from file
     LoadUserData();
     //load static checkoutList
     lvCheckOut.ItemsSource = StaticCheckOutList.GetList();
     //load video from bin debug
     meVideo.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "my.wmv");
 }
        public Checkout()
        {
            DataContext = this;
            InitializeComponent();

            //load items into list view from static object
            lvCheckOut.ItemsSource = StaticCheckOutList.GetList();
            for (var i = 0; i < StaticCheckOutList.Count(); ++i)
            {
                subtotal += StaticCheckOutList.GetByIndex(i).ProductTotal;
            }

            //load sub-total tax and grand total
            tbSubTotal.Text = string.Format("${0:0.00}", subtotal);
            tbTax.Text      = string.Format("${0:0.00}", (subtotal * 0.13));
            tbTotal.Text    = string.Format("${0:0.00}", (subtotal * 1.13));

            //set mail address from static user
            tbMailAddress.Text = StaticUser.Address;
        }
Пример #7
0
 /*The user has the option to load the tea order from file if the file exists or create a new order */
 private void LoadCheckout(object sender, RoutedEventArgs e)
 {
     try
     {
         // grab path from bin debug
         var shopPath = AppDomain.CurrentDomain.BaseDirectory + "shop.json";
         // read the file and store as a string
         var readText = File.ReadAllText(shopPath);
         // deseralize the data
         var json = JsonConvert.DeserializeObject <List <CheckOut> >(readText);
         /// set data from Json
         StaticCheckOutList.SetList(json);
         // load the checkout to screen
         lvCheckOut.ItemsSource = StaticCheckOutList.GetList();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Sorry but you need to add an Order before loading nothing also here is the error: " + ex);
     }
 }
        /* Correctly saves all user information (personal information and order) to a file(s) when user clicks Purchase Order */
        private void BtnPurchaseOrderOnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                // get User Creditcard from textfield
                string number = tbCreditCard.Text;
                //do luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm
                if (DoLuhn(number))
                {
                    //create Json String from the static user
                    string Userjson = JsonConvert.SerializeObject(StaticUser.GetUser());
                    //create Json String from the static checkout
                    string Shoppingjson = JsonConvert.SerializeObject(StaticCheckOutList.GetList());

                    //set Paths
                    var userPath = AppDomain.CurrentDomain.BaseDirectory + "user.json";
                    var shopPath = AppDomain.CurrentDomain.BaseDirectory + "shop.json";

                    //write to files
                    File.WriteAllText(userPath, Userjson);
                    File.WriteAllText(shopPath, Shoppingjson);

                    //use the message queue to send a message.
                    var messageQueue = SnackbarAdded.MessageQueue;
                    var message      = "Your Order has been Sent for proccessing";

                    //the message queue can be called from any thread
                    Task.Factory.StartNew(() => messageQueue.Enqueue(message));
                }
                else
                {
                    tbCreditCard.Text = "invalid credit card number";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write to file :" + ex.ToString());
            }
        }
        private void UpdateOnClick(object sender, RoutedEventArgs e)
        {
            if (tbChangeQty.Text != "")
            {
                // if the user types a letter or anything else don't crash
                bool isNumeric = int.TryParse(tbChangeQty.Text, out int n);
                if (isNumeric)
                {
                    //if user puts number 0 or negative
                    if (Convert.ToInt32(tbChangeQty.Text) <= 0)
                    {
                        StaticCheckOutList.EditQty(listViewIndex, 0);
                    }
                    else
                    {
                        StaticCheckOutList.EditQty(listViewIndex, Convert.ToInt32(tbChangeQty.Text));
                    }
                    lvCheckOut.Items.Refresh();

                    //load sub-total tax and grand total
                    subtotal = 0;
                    for (var i = 0; i < StaticCheckOutList.Count(); ++i)
                    {
                        subtotal += StaticCheckOutList.GetByIndex(i).ProductTotal;
                    }
                    tbSubTotal.Text = string.Format("${0:0.00}", subtotal);
                    tbTax.Text      = string.Format("${0:0.00}", (subtotal * 0.13));
                    tbTotal.Text    = string.Format("${0:0.00}", (subtotal * 1.13));
                }
                else
                {
                    // show the user the error
                    tbProductName.Text = "Not a number";
                }
            }
        }