コード例 #1
0
        void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var callEntity = Call.CallEntities[e.Position];

            // Do not allow user to tap on the cell if call is canceled or completed
            // return if so
            if (callEntity.Status == (int)CallUtil.StatusCode.Canceled || callEntity.Status == (int)CallUtil.StatusCode.Completed) return;

            new AlertDialog.Builder(this.Activity)
                .SetTitle(Strings.CallRegretTitle)
                .SetMessage(Strings.CallRegretMessage)
                .SetPositiveButton(Strings.CallSend, delegate
                {
                    ThreadPool.QueueUserWorkItem(o =>
                    {
                        // Update status
                        callEntity.Status = (int)CallUtil.StatusCode.Canceled;

                        try
                        {
                            // Put the async patient call here
                            ICall patientCall = new PatientCall();
                            patientCall.UpdateCall(callEntity);

                            this.Activity.RunOnUiThread(() =>
                            {
                                new AlertDialog.Builder(this.Activity).SetTitle(Strings.CallRegretted)
                                    .SetPositiveButton("OK", delegate { })
                                    .Show();

                                DataHandler.UpdateMyCallToLocalDatabase(new LocalDB(), callEntity);
                                Call.SetNewCalls(callEntity);
                                GenerateList();
                                arrayAdapter.NotifyDataSetChanged();
                            });
                        }
                        catch (Exception ex)
                        {
                            
                        }
                        

                    });

                })
            .SetNegativeButton(Strings.Cancel, delegate {/* Do nothing */ })
            .Show();
        }
コード例 #2
0
ファイル: MyCallsSource.cs プロジェクト: dsb92/patientcare
        // Fortryd kald
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            // Get the selected call
            var callEntity = CallEntities[indexPath.Row];

            // Do not allow user to tap on the cell if call is canceled or completed
            // return if so
            if (callEntity.Status == (int)CallUtil.StatusCode.Canceled || callEntity.Status == (int)CallUtil.StatusCode.Completed) return;

            // Selected Call is active
            tableView.DeselectRow(indexPath, true);

            var regretAlertController = UIAlertController.Create(Strings.CallRegretTitle, Strings.CallRegretMessage, UIAlertControllerStyle.Alert);

            var regretAction = UIAlertAction.Create(Strings.OK, UIAlertActionStyle.Destructive, action =>
            {
                new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                {
                    // Update status
                    callEntity.Status = (int)CallUtil.StatusCode.Canceled;

                    // Try update the call
                    try
                    {
                        // Put the async patient call here
                        ICall patientCall = new PatientCall();
                        patientCall.UpdateCall(callEntity);

                        vc.InvokeOnMainThread(() =>
                        {
                            // (Get a confirm message that the patient call was successfull)
                            new UIAlertView(Strings.CallRegretted, null, null, "OK", null).Show();

                            DataHandler.UpdateMyCallToLocalDatabase(new LocalDB(), callEntity);

                            // Reload data
                            SetCallEntities(callEntity);
                            tableView.ReloadData();
                        });
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR updaing call: " + ex.Message);

                        vc.InvokeOnMainThread(() =>
                        {
                            new UIAlertView(Strings.Error, Strings.ErrorSendingCall, null, "OK", null).Show();

                            return;
                        });
                    } 
                })).Start();
            });

            // When user cancels the service
            var cancelAction = UIAlertAction.Create("Annullér", UIAlertActionStyle.Cancel, action =>
            {
                // Do nothing.

            });

            regretAlertController.AddAction(regretAction);
            regretAlertController.AddAction(cancelAction);

            // Display the alert
            vc.PresentViewController(regretAlertController, true, null);
        }