Beispiel #1
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            data = new ProductsDataSource();
            this.productList.DataContext = data.Products;

            this.order = new Order { Date = DateTime.Now, Items = new List<OrderItem>(), OrderID = Guid.NewGuid(), TotalValue = 0 };
        }
Beispiel #2
0
        private async void doShipping(Order order)
        {
            try
            {
                StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("dispatch-" + order.OrderID.ToString() + ".txt");
                if (file != null)
                {
                    string dispatchNote = "Order Summary: " + 
                                          "\r\nOrder ID: " + order.OrderID +
                                          "\r\nOrder Total: " + String.Format("{0:C}", order.TotalValue);

                    var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
                    var writeStream = stream.GetOutputStreamAt(0);
                    DataWriter writer = new DataWriter(writeStream);
                    writer.WriteString(dispatchNote);
                    await writer.StoreAsync();
                    await writeStream.FlushAsync();
                    writeStream.Dispose();
                }
                else
                {
                    MessageDialog dlg = new MessageDialog(String.Format("Unable to save to file: {0}", file.DisplayName), "Not saved");
                    dlg.ShowAsync();
                }
            }
            catch (Exception ex)
            {
                MessageDialog dlg = new MessageDialog(ex.Message, "Exception");
                dlg.ShowAsync();
            }
        }
Beispiel #3
0
        private async void doShipping(Order order)
        {
            try
            {
                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                char seperator = Path.DirectorySeparatorChar;
                FileStream file = await Task.Run<FileStream>(() => File.Create(path + seperator + "dispatch-" + order.OrderID.ToString() + ".txt"));

                if (file != null)
                {
                    string dispatchNote = "Order Summary: " + 
                                          "\r\nOrder ID: " + order.OrderID +
                                          "\r\nOrder Total: " + String.Format("{0:C}", order.TotalValue);

                    StreamWriter writer = new StreamWriter(file);
                    await writer.WriteAsync(dispatchNote);
                    await Task.Run(() => writer.Close());
                }
                else
                {
                    MessageBox.Show(String.Format("Unable to save to file: {0}", file.Name), "Not saved");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception");
            }
        }
Beispiel #4
0
 public void StartCheckoutProcessing(Order order)
 {
     // Perform the checkout processing
     if (this.requestPayment() && this.CheckoutProcessing != null)
     {
         this.CheckoutProcessing(order);
     }
 }
Beispiel #5
0
        private async void doAuditing(Order order)
        {
            List<OrderItem> ageRestrictedItems = findAgeRestrictedItems(order);
            if (ageRestrictedItems.Count > 0)
            {
                try
                {
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    char seperator = Path.DirectorySeparatorChar;
                    FileStream file = await Task.Run<FileStream>(() => File.Create(path + seperator + "audit-" + order.OrderID.ToString() + ".xml"));

                    if (file != null)
                    {
                        XmlDocument doc = new XmlDocument();
                        XmlElement root = doc.CreateElement("Order");
                        root.SetAttribute("ID", order.OrderID.ToString());
                        root.SetAttribute("Date", order.Date.ToString());

                        foreach (OrderItem orderItem in ageRestrictedItems)
                        {
                            XmlElement itemElement = doc.CreateElement("Item");
                            itemElement.SetAttribute("Product", orderItem.Item.Name);
                            itemElement.SetAttribute("Description", orderItem.Item.Description);
                            root.AppendChild(itemElement);
                        }

                        doc.AppendChild(root);

                        await Task.Run(() => doc.Save(file));
                        await Task.Run(() => file.Close());
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Unable to save to file: {0}", file.Name), "Not saved");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception");
                }
                finally
                {
                    if (this.AuditProcessingComplete != null)
                    {
                        this.AuditProcessingComplete(String.Format(
                            "Audit record written for Order {0}", order.OrderID));
                    }
                }
            }
        }
Beispiel #6
0
        private async void doAuditing(Order order)
        {
            List<OrderItem> ageRestrictedItems = findAgeRestrictedItems(order);
            if (ageRestrictedItems.Count > 0)
            {
                try
                {
                    StorageFile file = await KnownFolders.DocumentsLibrary.CreateFileAsync("audit-" + order.OrderID.ToString() + ".xml");
                    if (file != null)
                    {
                        XmlDocument doc = new XmlDocument();
                        XmlElement root = doc.CreateElement("Order");
                        root.SetAttribute("ID", order.OrderID.ToString());
                        root.SetAttribute("Date", order.Date.ToString());

                        foreach (OrderItem orderItem in ageRestrictedItems)
                        {
                            XmlElement itemElement = doc.CreateElement("Item");
                            itemElement.SetAttribute("Product", orderItem.Item.Name);
                            itemElement.SetAttribute("Description", orderItem.Item.Description);
                            root.AppendChild(itemElement);
                        }

                        doc.AppendChild(root);

                        await doc.SaveToFileAsync(file);
                    }
                    else
                    {
                        MessageDialog dlg = new MessageDialog(String.Format("Unable to save to file: {0}", file.DisplayName), "Not saved");
                        dlg.ShowAsync();
                    }
                }
                catch (Exception ex)
                {
                    MessageDialog dlg = new MessageDialog(ex.Message, "Exception");
                    dlg.ShowAsync();
                }
                finally 
                {
                    if (this.AuditProcessingComplete != null) 
                    {
                        this.AuditProcessingComplete(String.Format(
                            "Audit record written for Order {0}", order.OrderID)); 
                    }
                }
            }
        }
Beispiel #7
0
        private async void doAuditing(Order order)
        {
            List<OrderItem> ageRestrictedItems = findAgeRestrictedItems(order); // Cerco la presenza di item restricted nella lista degli ordini
            if (ageRestrictedItems.Count > 0)
            {
                try
                {
                    // stringa che contine il percorso della cartella documenti
                    string path= Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    // Separatore livelli cartelle
                    char seperator = Path.DirectorySeparatorChar;

                    // Creo un metodo asincrono (infatti ho dichiarato la funzione async) per la creazione del file (così evito di bloccare tutto se quest'operazione impiega più del dovuto
                    FileStream file = await Task.Run<FileStream>(() => File.Create(path + seperator + "audit-" + order.OrderID.ToString() + ".xml"));

                    if (file != null)
                    {
                        XmlDocument doc = new XmlDocument();
                        XmlElement root = doc.CreateElement("Order");                        
                        root.SetAttribute("ID", order.OrderID.ToString());
                        root.SetAttribute("Date", order.Date.ToString());

                        foreach (OrderItem orderItem in ageRestrictedItems)
                        {
                            XmlElement itemElement = doc.CreateElement("Item");
                            itemElement.SetAttribute("Product", orderItem.Item.Name);
                            itemElement.SetAttribute("Description", orderItem.Item.Description);
                            root.AppendChild(itemElement);
                        }

                        doc.AppendChild(root);

                        await Task.Run(() => doc.Save(file));
                        await Task.Run(() => file.Close());
                    }
                    else
                    {
                        MessageBox.Show(String.Format("Unable to save to file: {0}", file.Name), "Not saved");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Exception");
                }
            }
        }
Beispiel #8
0
 private List<OrderItem> findAgeRestrictedItems(Order order)
 {
     return order.Items.FindAll(o => o.Item.AgeRestricted == true);
 }
Beispiel #9
0
 public void AuditOrder(Order order)
 {
     this.doAuditing(order);
 }
Beispiel #10
0
        private void CheckoutButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                // Perform the checkout processing
                if (this.requestPayment())
                {
                    this.auditor.AuditOrder(this.order);
                    this.shipper.ShipOrder(this.order);
                }

                // Display a summary of the order
                MessageBox.Show(String.Format("Order {0}, value {1:C}", order.OrderID, order.TotalValue), "Order Placed");
                
                // Clear out the order details so the user can start again with a new order
                this.order = new Order { Date = DateTime.Now, Items = new List<OrderItem>(), OrderID = Guid.NewGuid(), TotalValue = 0 };
                this.orderDetails.DataContext = null;
                this.orderValue.Text = String.Format("{0:C}", order.TotalValue);
                this.listViewHeader.Visibility = Visibility.Collapsed;
                this.checkout.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception");
            }
        }
Beispiel #11
0
 public void ShipOrder(Order order)
 {
     this.doShipping(order);
 }
Beispiel #12
0
        private void CheckoutButtonClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                // Perform the checkout processing
                this.checkoutController.StartCheckoutProcessing(this.order);

                // Clear out the order details so the user can start again with a new order
                this.order = new Order { Date = DateTime.Now, Items = new List<OrderItem>(), OrderID = Guid.NewGuid(), TotalValue = 0 };
                this.orderDetails.DataContext = null;
                this.orderValue.Text = String.Format("{0:C}", order.TotalValue);
                this.listViewHeader.Visibility = Visibility.Collapsed;
                this.checkout.IsEnabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Exception");
            }
        }
Beispiel #13
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            data = new ProductsDataSource(); //Creo il "database" degli oggetti in vendita
            this.productList.DataContext = data.Products; //Carica i dati creati prima nell'interfaccia

            //Creo un oggetto Order per contenere la lista di oggetti da comprare
            this.order = new Order { Date = DateTime.Now, Items = new List<OrderItem>(), OrderID = Guid.NewGuid(), TotalValue = 0 };
        }