Exemplo n.º 1
0
        /// <seealso cref="IApplicationCommand.Execute"/>
        public async void Execute(IApplicationCommandArguments arguments)
        {
            var args = (ApplicationCommandArguments)arguments;

            // Let's deserialize the timer data
            // stored by the start button.
            var timerData = JsonParser.FromJson <TimerData>(args
                                                            .DataMap
                                                            .CustomFields[TimerData.CustomFieldKey]);

            // And now we can create the new labor.
            var labor = await CreateLabor(args, timerData.UtcStart, DateTime.UtcNow);

            // We don't need the timer data anymore.
            args.DataMap
            .CustomFields
            .Remove(TimerData.CustomFieldKey);

            // As we've emptied timer data, now we
            // need to save the parent data map.
            await((DetailController)args
                  .Controller)
            .SaveAsync();

            // Finally, let's instruct the controller to
            // activate and display the new labor on the
            // screen so the user can complement it and
            // commit the operation.
            ((DetailController)args
             .Controller)
            .ShowSegment(LaborApplicationName, labor);
        }
Exemplo n.º 2
0
        public async void Execute(IApplicationCommandArguments arguments)
        {
            var args = (ApplicationCommandArguments)arguments;

            // TODO: Execute the OnNew pipeline?
            var sequence = await args
                           .MetadataRepository
                           .LoadAndIncrementSequenceAsync(args.ApplicationSchemaDefinition, "wonum");

            var originator = args.DataMap;
            var followUp   = new DataMap(args.ApplicationSchemaDefinition);

            ConfigureFollowUp(originator, followUp, sequence, args.User, arguments.ApplicationSchemaDefinition);
            ConfigureOriginator(originator, args.User);

            // Save the originator work order with our recent
            // modifications. We can safely bypass the Save
            // method provided by the controller because by
            // design the data is saved before the command
            // execution, so we just need to save our changes.
            await args
            .DataRepository
            .SaveAsync(args.ApplicationSchemaDefinition, originator);

            // And now let's save a data operation
            // to register it and later process it.
            await args
            .DataRepository
            .SaveAsync(CreateDataOperation(args, followUp));

            Alert.Show("Follow-Up", "Here is your new work order. You can now provide the follow-up details.", explicitlyInvokeOnMainThread: true);

            SimpleEventBus.Publish(new DataMapSaved(originator));
            SimpleEventBus.Publish(new DataMapSelected(followUp, true));
        }
Exemplo n.º 3
0
        private static DataOperation CreateDataOperation(IApplicationCommandArguments args, DataMap followUp)
        {
            var data = new Dictionary <string, string>
            {
                { "localid", followUp.LocalState.LocalId.ToString() },
                { "origrecordid", followUp.Value("origrecordid") },
                { "origrecordclass", followUp.Value("origrecordclass") }
            };

            return(new DataOperation(args.ApplicationSchemaDefinition, data, typeof(Handler)));
        }
Exemplo n.º 4
0
        /// <seealso cref="IApplicationCommand.Execute"/>
        public void Execute(IApplicationCommandArguments arguments)
        {
            var args = (ApplicationCommandArguments)arguments;

            // Do we have a camera, boss?
            if (false == Camera.CanTakePicture())
            {
                Alert.Show("Oops...", "We couldn't find an available camera on this device. Is it available?");
                return;
            }
            //            OnImagePicked(new NSDictionary(), args);
            Camera.TakePicture(args.Controller, info => OnImagePicked(info, args));
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Creates a new labtrans data map using
        ///     the specified start and finish date as
        ///     the default values.
        /// </summary>
        /// <param name="arguments">The application command arguments.</param>
        /// <param name="utcStart">The labor UTC start time.</param>
        /// <param name="utcFinish">The labor UTC finish time.</param>
        private static async Task <DataMap> CreateLabor(IApplicationCommandArguments arguments, DateTime utcStart, DateTime utcFinish)
        {
            var laborMetadata = await arguments
                                .MetadataRepository
                                .LoadApplicationAsync(LaborApplicationName);

            var labor = await arguments
                        .DataRepository
                        .NewAsync(laborMetadata, arguments.Composite);

            var regularHours = Convert.ToInt32((utcFinish - utcStart).TotalHours);

            labor.Value("startdate", utcStart.ToLocalTime());
            labor.Value("starttime", utcStart.ToLocalTime());
            labor.Value("finishdate", utcFinish.ToLocalTime());
            labor.Value("finishtime", utcFinish.ToLocalTime());
            labor.Value("regularhrs", regularHours);

            return(labor);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Creates a new attachment data map using
        ///     the specified image.
        /// </summary>
        /// <param name="arguments">The application command arguments.</param>
        /// <param name="image">The image.</param>
        private static async Task <DataMap> CreateAttachment(IApplicationCommandArguments arguments, UIImage image)
        {
            var imageAsBase64 = image
                                .AsPNG()
                                .GetBase64EncodedString(NSDataBase64EncodingOptions.None);

            var attachmentMetadata = await arguments
                                     .MetadataRepository
                                     .LoadApplicationAsync(AttachmentApplicationName);

            var attachment = await arguments
                             .DataRepository
                             .NewAsync(attachmentMetadata, arguments.Composite);

            attachment.Value("document", "NewImage");
            attachment.Value("createdate", DateTime.Now.ToString("MM-dd-yyyy hh:mm:ss"));
            attachment.Value("newattachment", imageAsBase64);

            //attachment.CustomFields[CustomFieldKey] = imageAsBase64;

            return(attachment);
        }
Exemplo n.º 7
0
        public void Execute(IApplicationCommandArguments arguments)
        {
            var args             = (ApplicationCommandArguments)arguments;
            var detailController = (DetailController)args.Controller;
            var formController   = (DetailFormController)detailController.SelectedController;

            var statusField = args
                              .ApplicationSchemaDefinition
                              .Fields
                              .First(f => f.Attribute == "synstatus_.description");

            // We'll need to know when the status lookup
            // completes so we can actually perform the
            // status change operation.
            var onCompletion = new Action <LookupController.Result>(result => OnLookupCompleted(args));

            // And now tells the controller to trigger the
            // navigation to the work order status lookup.
            var adHocFilters = CreateFilters(args.DataMap);

            detailController.InvokeOnMainThread(() => formController.Lookup(statusField, onCompletion, adHocFilters));
        }
Exemplo n.º 8
0
        /// <seealso cref="IApplicationCommand.Execute"/>
        public async void Execute(IApplicationCommandArguments arguments)
        {
            var args = (ApplicationCommandArguments)arguments;

            // Stores a custom field tracking
            // which time the timer started.
            args.DataMap
            .CustomFields[TimerData.CustomFieldKey] = new TimerData(DateTime.UtcNow).ToJson();

            // We'll ask the controller to save the changes
            // instead of doing ourselves because it will
            // continue active in the screen, and we don't
            // want to mess with its state.
            var success = await((DetailController)args
                                .Controller)
                          .SaveAsync();

            if (success)
            {
                Alert.Show("Timer Started", "The app is now tracking the time spent on this work order.", explicitlyInvokeOnMainThread: true);
            }
        }