Пример #1
0
        /// <summary>
        /// Configures the app to use the Sqlite data source. If no existing Sqlite database exists,
        /// loads a demo database filled with fake data so the app has content.
        /// </summary>
        public static void UseSqlite()
        {
            string databasePath = ApplicationData.Current.LocalFolder.Path + @"\contoso.db";
            var    dbOptions    = new DbContextOptionsBuilder <ContosoContext>().UseSqlite(
                "Data Source=" + databasePath);

            Repository = new SqlContosoRepository(dbOptions);
        }
Пример #2
0
 public OrderDetailViewModel(IContainerProvider containerProvider,
                             IContosoRepository contosoRepository)
     : base(containerProvider)
 {
     _contosoRepository = contosoRepository;
     Title = "Order Details";
     Init();
 }
Пример #3
0
 public CustomerDetailViewModel(IContainerProvider containerProvider,
                                IContosoRepository contosoRepository)
     : base(containerProvider)
 {
     Title = "Details";
     _contosoRepository = contosoRepository;
     Init();
 }
Пример #4
0
        public HomeViewModel(IContainerProvider containerProvider,
                             IContosoRepository contosoRepository)
            : base(containerProvider)
        {
            Title = "Home!";
            _contosoRepository = contosoRepository;

            Init();
        }
Пример #5
0
        /// <summary>
        /// Configures the app to use the Sqlite data source. If no existing Sqlite database exists,
        /// loads a demo database filled with fake data so the app has content.
        /// </summary>
        public static void UseSqlite()
        {
            string demoDatabasePath = Package.Current.InstalledLocation.Path + @"\Assets\Contoso.db";
            string databasePath     = ApplicationData.Current.LocalFolder.Path + @"\Contoso.db";

            if (!File.Exists(databasePath))
            {
                File.Copy(demoDatabasePath, databasePath);
            }
            var dbOptions = new DbContextOptionsBuilder <ContosoContext>().UseSqlite(
                "Data Source=" + databasePath);

            Repository = new SqlContosoRepository(dbOptions);
        }
Пример #6
0
        // Configures the app to use the Sqlite data source. If no existing Sqlite database exists, loads a demo database filled with fake data so the app has content.
        public static void UseSqlite()
        {
            // string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            string demoDatabasePath = $"{AppDomain.CurrentDomain.BaseDirectory}Assets\\Contoso.db";



            if (File.Exists(demoDatabasePath))
            {
                var dbOptions = new DbContextOptionsBuilder <ContosoContext>()
                                .UseSqlite("Data Source=" + demoDatabasePath)
                ;

                Repository = new SqlContosoRepository(dbOptions);
            }
        }
Пример #7
0
        public OrderWrapper(IContosoRepository contosoRepository, Order model = null)
        {
            Model = model;
            _contosoRepository = contosoRepository;
            // Create an ObservableCollection to wrap Order.LineItems so we can track
            // product additions and deletions.
            LineItems = new ObservableCollection <LineItem>(Model.LineItems);
            LineItems.CollectionChanged += LineItems_Changed;

            NewLineItem = new LineItemWrapper();

            if (model.Customer == null)
            {
                Task.Run(() => LoadCustomer(Model.CustomerId));
            }
        }
Пример #8
0
        /// <summary>
        /// 在应用程序由最终用户正常启动时进行调用。
        /// 将在启动应用程序以打开特定文件等情况下使用。
        /// </summary>
        /// <param name="e">有关启动请求和过程的详细信息。</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // 初始化网络请求接口地址
            Repository = new RestContosoRepository(URL);

            Frame rootFrame = Window.Current.Content as Frame;

            // 不要在窗口已包含内容时重复应用程序初始化,
            // 只需确保窗口处于活动状态
            if (rootFrame == null)
            {
                // 创建要充当导航上下文的框架,并导航到第一页
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: 从之前挂起的应用程序加载状态
                }

                // 将框架放在当前窗口中
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // 当导航堆栈尚未还原时,导航到第一页,
                    // 并通过将所需信息作为导航参数传入来配置
                    // 参数
                    if (localSettings.Values.ContainsKey("token"))
                    {
                        rootFrame.Navigate(typeof(MainPage), e.Arguments);
                    }
                    else
                    {
                        rootFrame.Navigate(typeof(LoginPage), e.Arguments);
                    }
                }
                // 确保当前窗口处于活动状态
                Window.Current.Activate();
            }
        }
Пример #9
0
 /// <summary>
 /// Configures the app to use the REST data source. For convenience, a read-only source is provided.
 /// You can also deploy your own copy of the REST service locally or to Azure. See the README for details.
 /// </summary>
 public static void UseRest() =>
 Repository = new RestContosoRepository("https://customers-orders-api-prod.azurewebsites.net/api/");
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the CustomerViewModel class that wraps a Customer object.
 /// </summary>
 public CustomerWrapper(IContosoRepository contosoRepository, Customer model = null)
 {
     _contosoRepository = contosoRepository;
     Model = model ?? new Customer();
 }