public FinishPage(PotentialCustomer Customer1, Transport TransportToSend, List <string> GoodsName, List <CartGoods> GoodsInCart, List <int> Piece1) { InitializeComponent(); Piece = Piece1; Address Address = new Address(); Address.Street = Customer1.Street; Address.Town = Customer1.Town; Address.PostNumber = int.Parse(Customer1.PostCode.ToString()); AddressDatabase.SaveItemAsync(Address); DebugMethod(); ContactInformation Contact = new ContactInformation(); Contact.Email = Customer1.Mail; Contact.Phone = Customer1.Phone; ContactInformationDatabase.SaveItemAsync(Contact); DebugMethod(); Customer Customer = new Customer(); Customer.AddressID = Address.AddressID; Customer.ContactInformationID = Contact.ContactInformationID; Customer.Name = Customer1.Name; Customer.Surname = Customer1.Surname; CustomerDatabase.SaveItemAsync(Customer); DebugMethod(); OrderTransport Transport = new OrderTransport(); Transport.TypeOfTransport = TransportToSend.Name; Transport.Price = TransportToSend.Price; OrderTransportDatabase.SaveItemAsync(Transport); DebugMethod(); Random r = new Random(); int rnd = r.Next(); int TotalPrice = 0; for (int i = 0; i < GoodsInCart.Count; i++) { TotalPrice += GoodsInCart[i].TotalPrice; } TotalPrice += Transport.Price; Order Order = new Order(); Order.CustomerID = Customer.CustomerID; Order.TransportID = Transport.TransportID; Order.OrderNumber = rnd; Order.OrderPrice = TotalPrice; OrderDatabase.SaveItemAsync(Order); DebugMethod(); Number.Text = Order.OrderNumber.ToString(); List <Customer> clist = new List <Customer>(); clist = CustomerDatabase.GetItemsAsync().Result; for (int i = 0; i < GoodsName.Count; i++) { OrderGoods OrderGoods = new OrderGoods(); OrderGoods.OrderID = Order.OrderID; Goods goods = GoodsDatabase.GetItemAsync(GoodsName[i]).Result; OrderGoods.GoodsQauntity = GoodsInCart[i].GoodsQauntity; OrderGoods.GoodsID = goods.GoodsID; OrderGoodsDatabase.SaveItemAsync(OrderGoods); DebugMethod(); } var ordergoods = OrderGoodsDatabase.GetItemsAsync().Result; var order = OrderDatabase.GetItemsAsync().Result; }
private void SearchOrderButton_Click(object sender, RoutedEventArgs e) { int SearchNumber; if (int.TryParse(SearchWordText.Text, out SearchNumber)) { List <Order> orderlist = new List <Order>(); var orderlist1 = OrderDatabase.GetItemAsync(SearchNumber).Result; if (orderlist1 != null) { orderlist.Add(orderlist1); List <OrderGoods> ordergoods1 = new List <OrderGoods>(); ordergoods1 = OrderGoodsDatabase.GetItemsAsync().Result; var query_where1 = from a in ordergoods1 where a.OrderID.Equals(orderlist[0].OrderID) select a; List <OrderGoods> ordergoods2 = new List <OrderGoods>(); foreach (var a in query_where1) { ordergoods2.Add(a); } List <Goods> goodslist1 = new List <Goods>(); goodslist1 = GetGoodsToList(ordergoods2); var query = from ordergoods in ordergoods2 join goodslist in goodslist1 on ordergoods.GoodsID equals goodslist.GoodsID select new { Name = goodslist.Name, Price = goodslist.Price, TotalPrice = (goodslist.Price * ordergoods.GoodsQauntity), GoodsQauntity = ordergoods.GoodsQauntity }; ListViewOfOrder.ItemsSource = query; List <OrderTransport> transport = new List <OrderTransport>(); transport = OrderTransportDatabase.GetItemsAsync().Result; var query_where4 = from a in transport where a.TransportID.Equals(orderlist[0].TransportID) select a; foreach (var a in query_where4) { transport.Add(a); } List <Customer> customer = new List <Customer>(); var query_where = CustomerDatabase.GetItemAsync(orderlist[0].CustomerID).Result; customer.Add(query_where); List <Address> address = new List <Address>(); var query_address = AddressDatabase.GetItemAsync(orderlist[0].CustomerID).Result; address.Add(query_address); List <ContactInformation> contactinformation = new List <ContactInformation>(); var query_contactinformation = ContactInformationDatabase.GetItemAsync(orderlist[0].CustomerID).Result; contactinformation.Add(query_contactinformation); Name.Text = customer[0].Name + " " + customer[0].Surname; Address.Text = address[0].Street + ", " + address[0].Town + ", " + address[0].PostNumber.ToString(); Transport.Text = transport[0].TypeOfTransport; Phone.Text = contactinformation[0].Phone.ToString(); Mail.Text = contactinformation[0].Email.ToString(); Price.Text = orderlist[0].OrderPrice.ToString(); ChangeVisibility(); } else { ChangeVisibility1(); SearchWordText.Text = ""; Warning.Visibility = Visibility.Visible; } } else { ChangeVisibility1(); SearchWordText.Text = ""; Warning.Visibility = Visibility.Visible; } }