DataFlex currently offers the developer the ability to create Desktop applications or web applications.
There are two different frameworks for web applications. One is more geared towards web application that look and feel like a desktop application and the other more geared towards mobile devices such as tablets and phones.
Both of them create web applications. Sooner or later you will be faced with the need to offer a true native mobile application.
Why a native application
There are a number of reasons why a native mobile application can be preferred over a web application.
For one a native mobile application can run without an active internet connection. Another is the user experience.
While web applications have come a long way it is still a lot easier to build a rich user interface with native development tools
We have built native mobile applications that run side by side with a DataFlex application for a long time.
Blackberry -> iOS -> Windows Universal App
The first was a blackberry application written in Java quite a while ago. It was actually communicating with the main application using specially coded email messages.
Then we created a Silverlight application that is somewhat in between because it cannot run disconnected but is a natively coded application.
The next step was a nativre iOS application to run on iPads and iPhones and then a native Windows Universal App to run on windows desktops, windows tablets and windows phones.
We also built the same app as a .NET web application and also as a DataFlex web application
The way we implemented the native apps is that at login time the app will request the users pertinent data based on the users login and the day. The app is a medical scheduling type application so it downloads the users clients with geographic information and treatment information etc.
Persistent Local Storage
The data is stored locally on the device at that time so the device can function without an internet connection
The user can now use the device and lookup information such as the next appointment, address, map, tasks and more.
The server keeps track of what data is sent to each device. If any data that was sent to a device on the server changes the server sends a push notification to the device telling the device that there is updated data. The device will then download the updates.
When the user modifies data on the device, for example recording an arrival at the client site, the device will try to send that data to the server. If there is no internet connection the update will be queued and automatically uploaded the next time the device connects to the internet.
To implement this kind of application we need 2 parts
First on the server we need a way to allow the device to communicate with the server
An easy way to do this is via the use of web services
For our example we will use the WebOrder sample workspace. We want to be able to look at a list of customers on a windows tablet
Web Service
So first we need to add a web service object to the WebOrder workspace
Under File->New->Web Object
select Web Service Object. I called mine OrderService
the code looks like this
Use cWebService.pkg Struct tCustomer String Number String Name End_Struct Object oOrder is a cWebService Set psServiceName to "OrderService" Set psServiceURI to "http://tempuri.org/" Set psServiceTitle to "Test Order Service" { Published = True } Function GetCustomers Returns tCustomer[] tCustomer[] custs Open Customer Clear Customer Find GE Customer by Index.1 While (Found) tCustomer cust Move (trim(Customer.Customer_Number)) to cust.Number Move (trim(Customer.Name)) to cust.Name Move cust to custs[SizeOfArray(custs)] Find GT Customer by Index.1 Loop Function_Return custs End_Function End_Object
A simple web service function that returns the name and number of all customers in an array
The second part is the actual mobile app. For this example I chose to create a Windows Universal Application using Visual Studio. This will allow me to run the application on windows desktops, windows tablets and windows phones.
I create a simple application in Visual Studio.
The data model in Visual Studio looks as follows
public class Customer { public string Number { get; set; } public string Name { get; set; } }
I then created a page for the customer list
it contains a Title and a ListView object that will show the customers
The next step is to call the web service and retrieve the data
in App.cs (the application object) we added the following
public List<Customer> customerData;
this will hold the customer data once downloaded
I added the following method to download the data from the web service
private async void LoadData() { string uri = String.Format("http://localhost/WebOrderMobile_18_1/OrderService.wso/GetCustomers/"); HttpClient cl = new HttpClient(); var content = await cl.GetStringAsync(uri); customerData = content.Deserialize<Customer[]>().ToList(); }
the method has to be marked async as it will make and await an asynchronous call to the web service
it then simply calls the web service and deserializes the returned JSON data.
The customer page now needs to show that data in the ListView object
public sealed partial class customersPage : Page { public customersPage() { this.InitializeComponent(); FillData(); } private async void FillData() { custListView.ItemsSource = ((App)App.Current).customerData; } }
we simply set the ItemsSource property of the ListView object to our customerData property in the application object.
The nice thing of course is that the web services can be used for multiple different mobile applications in different platforms