Esempio n. 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();
        }
Esempio n. 2
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;
        }
Esempio n. 4
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());
            }
        }