Beispiel #1
0
        async void LoadMainMenu()
        {
            try
            {
                //load user account info
                List <SummaryItems> information = App.Database.GetSummarysAsync("Info", "UserInfo");
                userInfo.Children.Clear();
                foreach (SummaryItems userSummary in information)
                {
                    string labelStyle = (userSummary.Caption == "") ? "ProfileNameLabel" : "ProfileTagLabel";

                    Label info = new Label
                    {
                        Style = (Xamarin.Forms.Style)Application.Current.Resources[labelStyle],
                        HorizontalTextAlignment = TextAlignment.Center
                    };

                    info.Text = (userSummary.Caption == "") ? userSummary.Value : userSummary.Caption + ": " + userSummary.Value;

                    userInfo.Children.Add(info);
                }

                //load menu item with custom template
                loading.IsVisible   = true;
                Ultis.Settings.List = "Main_Menu";
                ObservableCollection <ListItems> Item = new ObservableCollection <ListItems>(App.Database.GetMainMenu("MainMenu"));
                listView.ItemsSource = Item;
                //listView.HeightRequest = (expiryStack.IsVisible == false) ? Item.Count * 120 : Item.Count * 130;
                listView.ItemTemplate = new DataTemplate(typeof(CustomListViewCell));

                System.TimeSpan interval = new System.TimeSpan();
                if (!(String.IsNullOrEmpty(Ultis.Settings.UpdateTime)))
                {
                    DateTime enteredDate = DateTime.Parse(Ultis.Settings.UpdateTime);
                    interval = DateTime.Now.Subtract(enteredDate);
                }

                if (NetworkCheck.IsInternet())
                {
                    if (Item.Count == 0 || userInfo.Children.Count == 0 || Ultis.Settings.RefreshListView == "Yes" || interval.Hours >= 1 || interval.Hours < 0)
                    {
                        GetMainMenu();
                        Ultis.Settings.RefreshListView = "No";
                        Ultis.Settings.UpdateTime      = DateTime.Now.ToString();
                    }
                }
            }
            catch
            {
            }
        }
        public RefuelEntry(string title)
        {
            // this screen need to call web servvice to get the current date cost rate, so it do not allow user to enter new record when they is no internet to call the get cost rate web service.
            InitializeComponent();

            //initialized height for image grid row
            imageWidth          = App.DisplayScreenWidth / 3;
            imageGridRow.Height = imageWidth;

            StackLayout main = new StackLayout();

            Label title1 = new Label
            {
                FontSize  = 15,
                Text      = title,
                TextColor = Color.White
            };

            Label title2 = new Label
            {
                FontSize  = 10,
                Text      = Ultis.Settings.SubTitle,
                TextColor = Color.White
            };

            main.Children.Add(title1);
            main.Children.Add(title2);

            NavigationPage.SetTitleView(this, main);

            if (Ultis.Settings.Language.Equals("English"))
            {
                Title             = "Refuel Entry";
                liter.Placeholder = "Maximum 500 liter.";
            }
            else
            {
                Title             = "Isi Minyak";
                liter.Placeholder = "Maksimum 500 liter.";
            }

            if (NetworkCheck.IsInternet())
            {
                DownloadDefaultValue();
            }

            recordID = Guid.NewGuid().ToString();
        }
        public static async Task GetGPS()
        {
            //var locator = CrossGeolocator.Current;
            //position = await locator.GetPositionAsync();

            /*var position = await Geolocation.GetLastKnownLocationAsync();
             *
             * if (App.gpsLocationLat.Equals(0) || App.gpsLocationLong.Equals(0))
             * {
             *  if (position != null)
             *  {
             *      location = String.Format("{0:0.000000}", position.Latitude.ToString()) + "," + String.Format("{0:0.000000}", position.Longitude.ToString());
             *  }
             *  else
             *  {
             *      location = "0,0";
             *  }
             * }
             * else
             * {
             *  location = String.Format("{0:0.000000}", App.gpsLocationLat) + "," + String.Format("{0:0.000000}", App.gpsLocationLong);
             * }*/

            location = (App.gpsLocationLat.Equals(0) || App.gpsLocationLong.Equals(0)) ? ""  : String.Format("{0:0.000000}", App.gpsLocationLat) + "," + String.Format("{0:0.000000}", App.gpsLocationLong);

            if (!(String.IsNullOrEmpty(Ultis.Settings.SessionSettingKey)) && NetworkCheck.IsInternet())
            {
                try
                {
                    if (Ultis.Settings.SessionUserItem.GetGPS)
                    {
                        var client = new HttpClient();
                        client.BaseAddress = new Uri(Ultis.Settings.SessionBaseURI);
                        var sendGPSURI = ControllerUtil.getGPSTracking(location, address);
                        var content    = await client.GetAsync(sendGPSURI);

                        var response = await content.Content.ReadAsStringAsync();

                        clsResponse gps_response = JsonConvert.DeserializeObject <clsResponse>(response);
                        Debug.WriteLine(response);
                    }
                }
                catch
                {
                }
            }
        }
        //download the bus stop list and store locally
        public static async Task DownloadBusStopList()
        {
            try
            {
                var localStoredOutboundStops = new ObservableCollection <ListItems>(App.Database.GetMainMenu("OutboundList"));
                var localStoredInboundStops  = new ObservableCollection <ListItems>(App.Database.GetMainMenu("InboundList"));

                if (NetworkCheck.IsInternet())
                {
                    if (!(String.IsNullOrEmpty(Ultis.Settings.SessionSettingKey)))
                    {
                        if (localStoredOutboundStops.Count == 0)
                        {
                            var outbound_content = await CommonFunction.CallWebService(0, null, "https://api.asolute.com/host/api/", ControllerUtil.getBusStops("OutboundList"), null);

                            clsResponse outbound_response = JsonConvert.DeserializeObject <clsResponse>(outbound_content);

                            if (outbound_response.IsGood)
                            {
                                StoreData(outbound_content, "OutboundList");
                            }
                        }

                        if (localStoredInboundStops.Count == 0)
                        {
                            var inbound_content = await CommonFunction.CallWebService(0, null, "https://api.asolute.com/host/api/", ControllerUtil.getBusStops("InboundList"), null);

                            clsResponse inbound_response = JsonConvert.DeserializeObject <clsResponse>(inbound_content);

                            if (inbound_response.IsGood)
                            {
                                StoreData(inbound_content, "InboundList");
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #5
0
        public LogEntry(string id, string title)
        {
            InitializeComponent();

            //initialized height for image grid row
            imageWidth          = App.DisplayScreenWidth / 3;
            imageGridRow.Height = imageWidth;

            StackLayout main   = new StackLayout();
            Label       title1 = new Label
            {
                FontSize  = 15,
                Text      = title,
                TextColor = Color.White
            };
            Label title2 = new Label
            {
                FontSize  = 10,
                Text      = Ultis.Settings.SubTitle,
                TextColor = Color.White
            };

            main.Children.Add(title1);
            main.Children.Add(title2);
            NavigationPage.SetTitleView(this, main);

            Title = (Ultis.Settings.Language.Equals("English")) ? "Log Entry" : "Buku Log";

            existingRecordId = id;


            if (NetworkCheck.IsInternet())
            {
                logDefaultValue();
            }
            else
            {
                DisplayAlert("Reminder", "You are currently offline", "OK");
            }
        }
        //search database for pending bus trip and sync to server
        public static async Task UploadPendingRecord()
        {
            try
            {
                if (NetworkCheck.IsInternet())
                {
                    if (!(String.IsNullOrEmpty(Ultis.Settings.SessionSettingKey)))
                    {
                        //upload bus trip record
                        var pendingBusTrip = App.Database.GetPendingTrip();

                        List <clsTrip> completeTrips = new List <clsTrip>();

                        foreach (BusTrip busTrip in pendingBusTrip)
                        {
                            if (busTrip.EndTime != null && busTrip.Uploaded == false)
                            {
                                clsTrip trip = new clsTrip
                                {
                                    Id                = busTrip.Id,
                                    TruckId           = busTrip.TruckId,
                                    DriverId          = busTrip.DriverId,
                                    StartTime         = busTrip.StartTime,
                                    StartOdometer     = 0,
                                    StartLocationName = "",
                                    StartGeoLoc       = busTrip.StartGeoLoc,
                                    EndTime           = busTrip.EndTime,
                                    EndOdometer       = 0,
                                    EndLocationName   = "",
                                    EndGeoLoc         = busTrip.EndGeoLoc,
                                    TrxStatus         = 5,
                                    LinkId            = "",
                                    LocationList      = {},
                                    Captions          = {}
                                };

                                completeTrips.Add(trip);
                            }
                        }

                        if (completeTrips.Count != 0)
                        {
                            var content = await CommonFunction.CallWebService(1, completeTrips, Ultis.Settings.SessionBaseURI, ControllerUtil.postTrips(), null);

                            clsResponse response = JsonConvert.DeserializeObject <clsResponse>(content);

                            if (response.IsGood)
                            {
                                /*foreach (clsTrip uploadedTrip in completeTrips)
                                 * {
                                 *  var completedTrip = App.Database.GetUploadedTrip(uploadedTrip.Id);
                                 *
                                 *  if (completedTrip != null)
                                 *  {
                                 *      completedTrip.Uploaded = true;
                                 *
                                 *      App.Database.SaveBusTrip(completedTrip);
                                 *  }
                                 * }*/

                                App.Database.DeleteBusTrip();

                                //upload bus ticket record
                                var pendingTicket        = App.Database.GetSoldTicket();
                                List <clsTicket> tickets = new List <clsTicket>();
                                foreach (SoldTicket soldTicket in pendingTicket)
                                {
                                    if (!(String.IsNullOrEmpty(soldTicket.TripId)))
                                    {
                                        clsTicket ticket = new clsTicket
                                        {
                                            TrxTime     = soldTicket.TrxTime,
                                            TruckId     = soldTicket.TruckId,
                                            DriverId    = soldTicket.DriverId,
                                            TripId      = soldTicket.TripId,
                                            RouteId     = soldTicket.RouteId,
                                            StopId      = soldTicket.StopId,
                                            TicketType  = soldTicket.TicketType,
                                            PaymentType = soldTicket.PaymentType,
                                            Amount      = soldTicket.Amount
                                        };

                                        tickets.Add(ticket);
                                    }
                                }

                                if (tickets.Count != 0)
                                {
                                    var ticket_content = await CommonFunction.CallWebService(1, tickets, Ultis.Settings.SessionBaseURI, ControllerUtil.postTickets(), null);

                                    clsResponse ticket_response = JsonConvert.DeserializeObject <clsResponse>(ticket_content);

                                    if (ticket_response.IsGood)
                                    {
                                        /*foreach (clsTicket ticket in tickets)
                                         * {
                                         *  var completeTicket = App.Database.GetUploadedTicket(ticket.);
                                         *
                                         *  if (completeTicket != null)
                                         *  {
                                         *      completeTicket.Uploaded = true;
                                         *
                                         *      App.Database.SaveTicketTransaction(completeTicket);
                                         *  }
                                         * }*/
                                        App.Database.DeleteTicket();

                                        var test = App.Database.gettesting();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #7
0
        public async void checkEquipment(object sender, EventArgs e)
        {
            string equipmentId = equipmentID.Text;

            if (NetworkCheck.IsInternet())
            {
                try
                {
                    var client = new HttpClient();
                    client.BaseAddress = new Uri(Ultis.Settings.SessionBaseURI);

                    var eqUri = ControllerUtil.getEquipmentURL(equipmentId);

                    var eqResponse = await client.GetAsync(eqUri);

                    var eqContent = await eqResponse.Content.ReadAsStringAsync();

                    Debug.WriteLine(eqContent);

                    newEqResponse = JsonConvert.DeserializeObject <clsResponse>(eqContent);

                    List <clsCaptionValue> eqInfo = new List <clsCaptionValue>();

                    int count = 0;
                    for (int i = 0; i < newEqResponse.Result.Count; i++)
                    {
                        string caption = newEqResponse.Result[i]["Caption"];
                        string value   = newEqResponse.Result[i]["Value"];
                        bool   display = newEqResponse.Result[i]["Display"];
                        eqInfo.Add(new clsCaptionValue(caption, value, display));
                    }
                    count++;

                    List <EqDetails> numberRow = new List <EqDetails>();
                    for (int j = 0; j < count; j++)
                    {
                        EqDetails listRow = new EqDetails();
                        listRow.count = "true";

                        numberRow.Add(listRow);
                    }

                    ObservableCollection <EqDetails> row = new ObservableCollection <EqDetails>(numberRow);



                    var Template = new DataTemplate(() =>
                    {
                        AbsoluteLayout absoluteLayout = new AbsoluteLayout();
                        StackLayout cellWrapper       = new StackLayout()
                        {
                            Padding           = new Thickness(10, 20, 20, 20),
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            VerticalOptions   = LayoutOptions.FillAndExpand
                        };

                        foreach (clsCaptionValue items in eqInfo)
                        {
                            Label label = new Label
                            {
                                Text = items.Caption + ": " + items.Value
                            };

                            label.FontAttributes = FontAttributes.Bold;


                            cellWrapper.Children.Add(label);
                        }

                        absoluteLayout.Children.Add(cellWrapper);


                        return(new ViewCell {
                            View = absoluteLayout
                        });
                    });

                    euipmentList.ItemsSource   = row;
                    euipmentList.HasUnevenRows = true;
                    euipmentList.ItemTemplate  = Template;
                }
                catch (HttpRequestException)
                {
                    await DisplayAlert("Unable to connect", "Please try again later", "Ok");
                }
            }
            else
            {
                await DisplayAlert("Reminder", "Currently offline cant search", "OK");
            }
        }