예제 #1
0
        private async void Sync_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new OrdersContext())
            {
                var orders = db.Orders.Where(o => o.IsShipped && !o.IsShippingSynced).ToList();

                if (orders.Any())
                {
                    try
                    {
                        foreach (var order in orders)
                        {
                            await UnicornStoreService.ShippedOrder(order.OrderId);
                            order.IsShippingSynced = true;
                            db.SaveChanges();
                        }

                        var dialog = new MessageDialog("All shipped orders now recorded in central database.");
                        await dialog.ShowAsync();
                    }
                    catch (HttpRequestException)
                    {
                        var dialog = new MessageDialog("Could not connect. Try again when you have a network connection.");
                        await dialog.ShowAsync();
                    }
                }
                else
                {
                    var dialog = new MessageDialog("There weren't any shipped orers not already recorded in central database.");
                    await dialog.ShowAsync();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            Microsoft.ApplicationInsights.WindowsAppInitializer.InitializeAsync(
                Microsoft.ApplicationInsights.WindowsCollectors.Metadata |
                Microsoft.ApplicationInsights.WindowsCollectors.Session);
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new OrdersContext())
            {
                db.Database.Migrate();
            }
        }
예제 #3
0
        private async void AssignOrders_Click(object sender, RoutedEventArgs e)
        {
            var selectedOrders = Orders.SelectedItems.Cast<Order>().ToList();

            // Assign selected orders to current user
            var selectedIds = selectedOrders.Select(o => o.OrderId);

            try
            {
                await UnicornStoreService.PackingOrders(selectedIds);

                // Take a local copy of the orders
                using (var db = new OrdersContext())
                {
                    foreach (var order in selectedOrders)
                    {
                        db.Orders.Add(order);
                        db.OrderLines.AddRange(order.Lines);
                    }

                    db.SaveChanges();
                }

                // Refresh the page with pending orders
                await ReLoadPendingOrders();

                // Inform user of success
                var dialog = new MessageDialog("Orders successfully assigned.");
                await dialog.ShowAsync();
            }
            catch (HttpRequestException)
            {
                var dialog = new MessageDialog("Could not connect. Try again when you have a network connection.");
                await dialog.ShowAsync();
            }
            
        }
예제 #4
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            using (var db = new OrdersContext())
            {
                // TODO Workaround for DDL APIs not working on UAP
                if (!db.Database.AsRelational().HasTables())
                {
                    var conn = db.Database.AsRelational().Connection.DbConnection;

                    var orderCmd = conn.CreateCommand();
                    orderCmd.CommandText = @"
            CREATE TABLE [Order] (
              OrderId INTEGER PRIMARY KEY,
              Addressee,
              LineOne,
              LineTwo,
              CityOrTown,
              StateOrProvince,
              ZipOrPostalCode,
              Country,
              IsShipped,
              IsShippingSynced
            );";

                    var lineCmd = conn.CreateCommand();
                    lineCmd.CommandText = @"
            CREATE TABLE OrderLine (
              OrderId,
              ProductId,
              ProductName,
              Quantity,
              IsPacked,
              CONSTRAINT PK_OrderLine PRIMARY KEY (OrderId, ProductId)
            );";

                    conn.Open();
                    orderCmd.ExecuteNonQuery();
                    lineCmd.ExecuteNonQuery();
                    conn.Close();

                }
            }

            #if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
            #endif

            Frame rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                rootFrame.Navigate(typeof(MainPage), e.Arguments);
            }
            // Ensure the current window is active
            Window.Current.Activate();
        }