Ejemplo n.º 1
0
        private async void downloadItemList()
        {
            var serverDb = new ServerDatabaseService();
            List <Models.Item> itemList = new List <Models.Item>();

            if (ItemCatalogue == null)
            {
                ItemCatalogue = new ObservableCollection <SalesItemSelection>();
            }
            Models.Item temp;
            foreach (SalesItemSelection item in ItemCatalogue)
            {
                temp = new Models.Item(item.ItemId, item.Name, item.Price, item.UnitMeasurement, item.Barcode);
                itemList.Add(temp);
            }
            var fetchedItem = await serverDb.getAllItems();

            if (fetchedItem != null)
            {
                //compare with local
                List <Models.Item> fetchedData = new List <Models.Item>(fetchedItem);
                List <Models.Item> newData     = fetchedData.Except(itemList).ToList();
                List <Models.Item> deletedData = itemList.Except(fetchedData).ToList();
                if (newData != null)
                {
                    //insert new data to local db
                    await itemDb.InsertItems(new ObservableCollection <Models.Item>(newData));
                }
                if (deletedData != null)
                {
                    //delete deleted data in local db
                    foreach (Models.Item data in deletedData)
                    {
                        await itemDb.DeleteItem(data);
                    }
                }
                loadItemCatalogue();
            }
        }
Ejemplo n.º 2
0
        /* Function: funcLogin
         * input: username and password
         * This function performs validation of user and password with the database
         * if the login credential correct, this method leads to showing sales screen
         * otherwise, it is still in login page
         */
        private async void funcLogin(string username, string password)
        {
            if (username == "warehouse" && password == "warehouse")
            {
                var serverDb = new ServerDatabaseService();
                try
                {
                    var deleteLocalSalesLines = await salesLineDb.DeleteAll();

                    var deleteLocalSales = await salesDb.DeleteAll();

                    var deleteLocalCustomer = await customerDb.DeleteAll();

                    var deleteLocalItem = await itemDb.DeleteAll();

                    var allSales = await serverDb.getAllSales();

                    var allSalesLines = await serverDb.getAllSalesLines();

                    var allCustomer = await serverDb.getAllCustomers();

                    var allItem = await serverDb.getAllItems();

                    await salesDb.InsertAllSales(allSales);

                    await salesLineDb.InsertSalesLines(allSalesLines);

                    await customerDb.InsertAllCustomers(allCustomer);

                    await itemDb.InsertItems(allItem);

                    //go to shipment view
                    ShowViewModel <ShipmentViewModel>();
                    Close(this);
                }
                catch (Exception e)
                {
                    await dialog.Show(e.Message, "Error");
                }
            }
            else
            {
                //integrate with server database to check username and password
                var serverDb = new ServerDatabaseService();
                int isLogged = await serverDb.checkLogin(username, password);

                if (isLogged == 1)
                {
                    loggingIn();
                }
                else if (isLogged == 0)
                {
                    //login fail, send notification to user
                    await dialog.Show("Username or password is incorrect. Please try again.", "Login Failed");
                }
                else if (isLogged == 3)
                {
                    //network error
                    await dialog.Show("Please check your network and try again later", "Network Error");
                }
            }
        }