Пример #1
0
        private void LoadDriveDetails(DriveTable currentDrive)
        {
            DriveShiftCount++;
            DriveShiftTitle = "Drive Shift " + DriveShiftCount.ToString() + " of " + DriveShiftTotalCount.ToString();
            VehicleTable currentVehicle;

            if (currentDrive.ServerVehicleKey == 0)
            {
                currentVehicle = dbService.GetVehicleById(currentDrive.VehicleKey);
            }
            else
            {
                currentVehicle = dbService.GetVehicleByServerId(currentDrive.ServerVehicleKey);
            }

            RegistrationTitle    = currentVehicle.Registration;
            StartTimeDrivePicker = DateTime.Parse(currentDrive.StartDate).TimeOfDay;
            EndTimeDrivePicker   = DateTime.Parse(currentDrive.EndDate).TimeOfDay;
            StartHubo            = currentDrive.StartHubo;
            EndHubo = currentDrive.EndHubo;
        }
Пример #2
0
        internal async Task <int> QueryDrive(bool driveStarted, DriveTable drive)
        {
            string url;
            string contentType = Constants.CONTENT_TYPE;
            string json;
            HttpResponseMessage response;

            if (!driveStarted)
            {
                url = GetBaseUrl() + Constants.REST_URL_ADDDRIVESTART;

                DriveStartModel driveModel = new DriveStartModel()
                {
                    shiftId = drive.ServerShiftKey,
                    startDrivingDateTime = drive.StartDate,
                    vehicleId            = drive.ServerVehicleKey,
                    startHubo            = drive.StartHubo,
                    startNote            = drive.StartNote
                };
                json = JsonConvert.SerializeObject(driveModel);
            }
            else
            {
                url = GetBaseUrl() + Constants.REST_URL_ADDDRIVEEND;

                DriveEndModel driveModel = new DriveEndModel()
                {
                    id = drive.ServerId,
                    stopDrivingDateTime = drive.EndDate,
                    stopHubo            = drive.EndHubo,
                    endNote             = drive.EndNote
                };
                json = JsonConvert.SerializeObject(driveModel);
            }

            HttpContent content = new StringContent(json, Encoding.UTF8, contentType);

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", accessToken);
                try
                {
                    response = await client.PostAsync(url, content);
                }
                catch
                {
                    return(-1);
                }
            }

            if (response.IsSuccessStatusCode)
            {
                QueryDriveResponse result = JsonConvert.DeserializeObject <QueryDriveResponse>(response.Content.ReadAsStringAsync().Result);

                if (result.Success)
                {
                    if (result.Result > 0)
                    {
                        return(result.Result);
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else
                {
                    return(-2);
                }
            }
            else
            {
                return(-1);
            }
        }
Пример #3
0
        private void Add()
        {
            if (Instruction == "Break")
            {
                if (!CheckValidHuboEntry(HuboStart))
                {
                    return;
                }

                if (!CheckValidHuboEntry(HuboEnd))
                {
                    return;
                }

                BreakTable breakAdd = new BreakTable()
                {
                    StartDate     = BreakStart.ToString(Resource.DateFormat),
                    EndDate       = BreakEnd.ToString(Resource.DateFormat),
                    StartLocation = LocationStart,
                    EndLocation   = LocationEnd
                };
                MessagingCenter.Send(this, "Break_Added", breakAdd);
            }
            else if (Instruction == "Note")
            {
                NoteTable note = new NoteTable()
                {
                    Date = NoteTime.ToString(Resource.DateFormat),
                    Note = NoteDetail
                };
                MessagingCenter.Send(this, "Note_Added", note);
            }
            else if (Instruction == "Drive Shift")
            {
                if (!CheckValidHuboEntry(HuboStart))
                {
                    return;
                }

                if (!CheckValidHuboEntry(HuboEnd))
                {
                    return;
                }

                List <VehicleTable> vehicleKey = new List <VehicleTable>();
                vehicleKey = GetVehicles();

                DriveTable drive = new DriveTable()
                {
                    StartDate     = DriveStartTime.ToString(Resource.DateFormat),
                    EndDate       = DriveEndTime.ToString(Resource.DateFormat),
                    StartHubo     = int.Parse(HuboStart),
                    EndHubo       = int.Parse(HuboEnd),
                    ActiveVehicle = false,
                    VehicleKey    = vehicleKey[SelectedVehicle].Key
                };
                MessagingCenter.Send(this, "Drive_Added", drive);
            }

            Navigation.PopModalAsync();
        }