예제 #1
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");
                }
            }
        }