Esempio n. 1
0
        void methodInvokeAlertDialogWithListView(object sender, EventArgs e)
        {
            string endpoint2;
            bool   IsValidJson1;

            _lstDataItem = new List <string>();
            _lstDataItem.Clear();
            //object strResponse2;
            ConsumeRest cRest = new ConsumeRest();
            //List<FullNames> fullName;

            object  strResponse;
            Address address = new Address();

            if (IsDoctor == false)
            {
                endpoint2 = address.Endpoint + "PatientFriends/" + myID;
            }
            else
            {
                endpoint2 = address.Endpoint + "DoctorFriends/" + myID;
            }

            strResponse = cRest.makeRequest(endpoint2);
            ValidateJson validateJson = new ValidateJson();

            IsValidJson1 = validateJson.IsValidJson(strResponse);

            if (IsValidJson1)
            {
                deserializedContacts = JsonConvert.DeserializeObject <List <friends> >(strResponse.ToString());
                for (int i = 0; i < deserializedContacts.Count; i++)
                {
                    string NAME = deserializedContacts[i].FirstName + " " + deserializedContacts[i].LastName;

                    _lstDataItem.Add(NAME);
                }

                var dlgAlert = (new AlertDialog.Builder(this)).Create();
                dlgAlert.SetTitle("Select Person");
                var listView = new ListView(this);
                listView.Adapter    = new EHR_Application.AlertListViewAdapter(this, _lstDataItem);      // changed
                listView.ItemClick += listViewItemClick;
                dlgAlert.SetView(listView);
                dlgAlert.SetButton("OK", handllerNotingButton);
                dlgAlert.Show();
            }
            else
            {
                new AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetMessage("No data found due to unexpected problem" + "\n" + strResponse)
                .SetIcon(Resource.Drawable.error)
                .Show();
            }
        }
        public void Actions()
        {
            List <string> Teleph       = new List <string>();
            List <string> emails       = new List <string>();
            ConsumeRest   cRest        = new ConsumeRest();
            ValidateJson  validateJson = new ValidateJson();
            Address       address      = new Address();
            object        strResponse;
            bool          IsValidJson;
            string        endpoint;
            demographics  demogr;

            endpoint = address.Endpoint + "Demographics/" + myID;

            strResponse = cRest.makeRequest(endpoint);
            IsValidJson = validateJson.IsValidJson(strResponse);

            DateTime d;

            if (IsValidJson)
            {
                demogr     = JsonConvert.DeserializeObject <demographics>(strResponse.ToString());
                txt13.Text = demogr.FirstName;
                txt14.Text = demogr.LastName;
                txt15.Text = demogr.Country;
                txt16.Text = demogr.City;
                txt24.Text = demogr.StreetName;
                txt17.Text = demogr.StreetNumber.ToString();
                txt18.Text = demogr.Sex;
                txt19.Text = demogr.Birthday.ToString();

                if (demogr.Communications.Count != 0)
                {
                    for (int i = 0; i < demogr.Communications.Count; i++)
                    {
                        Teleph.Add(demogr.Communications[i].Telephone.ToString());
                        emails.Add(demogr.Communications[i].email);
                    }

                    adapt         = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, Teleph);
                    adapt1        = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, emails);
                    spin.Adapter  = adapt;
                    spin1.Adapter = adapt1;
                }
            }
            else
            {
                new AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetMessage("No data found due to unexpected problem" + "n/" + strResponse)
                .Show();
            }
        }
        void methodInvokeAlertDialogWithListView()
        {
            ConsumeRest cRest   = new ConsumeRest();
            Address     address = new Address();
            bool        IsValidJson1;
            object      strResponse;

            _lstDataItem = new List <string>();
            _lstDataItem.Clear();

            string endpoint = address.Endpoint + "PatientFriends/" + myID;

            strResponse = cRest.makeRequest(endpoint);

            ValidateJson validateJson = new ValidateJson();

            IsValidJson1 = validateJson.IsValidJson(strResponse);

            if (IsValidJson1)
            {
                List <friends> deserializedContacts = JsonConvert.DeserializeObject <List <friends> >(strResponse.ToString());

                Number = deserializedContacts.Count;
                for (int i = 0; i < deserializedContacts.Count; i++)
                {
                    string NAME = deserializedContacts[i].FirstName + " " + deserializedContacts[i].LastName + "  " + deserializedContacts[i].speciality;

                    _lstDataItem.Add(NAME);
                }

                var dlgAlert = (new AlertDialog.Builder(this)).Create();
                dlgAlert.SetTitle(" Contacts ");
                var listView = new ListView(this);
                listView.Adapter = new EHR_Application.AlertListViewAdapter(this, _lstDataItem);
                dlgAlert.SetView(listView);
                dlgAlert.SetButton("OK", handllerNotingButton);
                dlgAlert.Show();
            }
            else
            {
                new AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetIcon(Resource.Drawable.error)
                .SetMessage("No data found due to unexpected problem" + "\n" + strResponse)
                .Show();
            }
        }
        private void Actions()
        {
            string      endpoint;
            ConsumeRest cRest   = new ConsumeRest();
            Address     address = new Address();

            RetrieveData retrieve = new RetrieveData();  // retrieve "IsDoctor"

            IsDoctor = retrieve.RetreiveBool();

            if (IsDoctor == false)
            {
                endpoint = address.Endpoint2 + "visits//?PersonId=" + myID;
            }
            else
            {
                endpoint = address.Endpoint2 + "visits//?PersonId=" + receiverID;
            }

            strResponse = cRest.makeRequest(endpoint);

            ValidateJson validateJson = new ValidateJson();

            IsValid = validateJson.IsValidJson(strResponse);

            if (IsValid)
            {
                VISIT2 = JsonConvert.DeserializeObject <List <Visit2> >(strResponse.ToString());
                VISIT2 = VISIT2.OrderBy(i => i.Date).ToList();

                //convertClasses();
                SetData(out mAdapter);
                expandableListView.SetAdapter(mAdapter);
                expandableListView.ChildClick += ExpandableListView_ChildClick1;
            }
            else
            {
                VISIT2 = JsonConvert.DeserializeObject <List <Visit2> >("[]".ToString());

                new Android.App.AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetMessage("No data found do to unexpected problem" + "\n" + strResponse)
                .SetIcon(Resource.Drawable.error)
                .Show();
            }
        }
        void methodInvokeAlertDialogWithListView2()
        {
            object strResponse;
            bool   IsValidJson1;

            _lstDataItem2 = new List <string>();
            _lstDataItem2.Clear();
            ConsumeRest cRest   = new ConsumeRest();
            Address     address = new Address();

            string endpoint = address.Endpoint + "PatientNewMessages/" + myID;

            strResponse = cRest.makeRequest(endpoint);

            ValidateJson validateJson = new ValidateJson();

            IsValidJson1 = validateJson.IsValidJson(strResponse);

            if (IsValidJson1)
            {
                deserializedContacts = JsonConvert.DeserializeObject <List <NewMessages2> >(strResponse.ToString());
                receivedMes          = deserializedContacts.OrderBy(c => c.FirstName).ToList();
                for (int i = 0; i < receivedMes.Count; i++)
                {
                    string NAME = "New Message from: " + receivedMes[i].FirstName + " " + receivedMes[i].LastName;
                    _lstDataItem2.Add(NAME);
                }

                var dlgAlert = (new AlertDialog.Builder(this)).Create();
                dlgAlert.SetTitle(" New Messages ");
                var listView = new ListView(this);
                listView.Adapter    = new EHR_Application.AlertListViewAdapter(this, _lstDataItem2);
                listView.ItemClick += ListView_ItemClick;
                dlgAlert.SetView(listView);
                dlgAlert.SetButton("OK", handllerNotingButton1);
                dlgAlert.Show();
            }
            else
            {
                new AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetMessage("No data found due to unexpected problem" + "\n" + strResponse)
                .Show();
            }
        }
        private void MessagesPopUp()
        {
            object      strResponse, strResponse2;
            bool        IsValidJson, IsValidJson2, newImages;
            string      endpoint, endpoint2;
            ConsumeRest cRest   = new ConsumeRest();
            Address     address = new Address();

            if (IsDoctor == false)
            {
                endpoint  = address.Endpoint + "PatientNewMessages1/" + myId;
                endpoint2 = address.Endpoint + "PatientNewImages1/" + myId;
            }
            else
            {
                endpoint  = address.Endpoint + "DoctorNewMessages1/" + myId;
                endpoint2 = address.Endpoint + "DoctorNewImages1/" + myId;
            }

            strResponse  = cRest.makeRequest(endpoint);  // elegxos gia nea mhnumata keimenou
            strResponse2 = cRest.makeRequest(endpoint2); // elegxos gia nea mhnumata eikonas
            ValidateJson validateJson = new ValidateJson();

            IsValidJson  = validateJson.IsValidJson(strResponse);
            IsValidJson2 = validateJson.IsValidJson(strResponse2);

            if (IsValidJson && IsValidJson2)
            {
                // check for new images
                newMessages2 = JsonConvert.DeserializeObject <List <NewMessages2> >(strResponse2.ToString());
                if (newMessages2.Count != 0)
                {
                    newImages = true;
                }
                else
                {
                    newImages = false;
                }


                newMessages = JsonConvert.DeserializeObject <List <NewMessages2> >(strResponse.ToString());

                if (newMessages.Count != 0 || newImages == true)
                {
                    if (newMessages.Count != 0)
                    {
                        for (int i = 0; i < newMessages.Count; i++)
                        {
                            MessageDelivered(i, false);
                        }
                    }
                    if (newImages == true)
                    {
                        for (int i = 0; i < newMessages2.Count; i++)
                        {
                            MessageDelivered(i, true);
                        }
                    }

                    RunOnUiThread(() =>
                    {
                        Toast.MakeText(this, "New message Arrived", ToastLength.Short).Show();
                    });

                    // Set up an intent so that tapping the notifications returns to this app:
                    Intent intent = new Intent(this, typeof(NewMessagesListActivity));

                    // Pass some information to SecondActivity:
                    intent.PutExtra("myID", myId);
                    intent.PutExtra("newImage", newImages);
                    Intent.PutExtra("message", "Greetings from MainActivity!");

                    // Create a task stack builder to manage the back stack:
                    TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);

                    // Add all parents of SecondActivity to the stack:
                    stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(NewMessagesListActivity)));

                    // Push the intent that starts SecondActivity onto the stack:
                    stackBuilder.AddNextIntent(intent);


                    // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
                    const int     pendingIntentId = 0;
                    PendingIntent pendingIntent   =
                        PendingIntent.GetActivity(this, pendingIntentId, intent, PendingIntentFlags.OneShot);


                    //Instantiate the builder and set notification elements:
                    Notification.Builder builder = new Notification.Builder(this)
                                                   .SetAutoCancel(true)
                                                   .SetOnlyAlertOnce(true)
                                                   .SetContentIntent(pendingIntent)
                                                   .SetContentTitle("New messages arrived")
                                                   .SetContentText("There are " + newMessages.Count.ToString() + " new text messages , and " + newMessages2.Count.ToString() + " new image messages")
                                                   .SetDefaults(NotificationDefaults.Sound | NotificationDefaults.Vibrate)
                                                   .SetSmallIcon(Resource.Drawable.Icon);

                    // Build the notification:
                    Notification notification = builder.Build();

                    // Get the notification manager:
                    NotificationManager notificationManager =
                        GetSystemService(Context.NotificationService) as NotificationManager;

                    // Publish the notification:
                    const int notificationId = 0;
                    notificationManager.Notify(notificationId, notification);
                }
            }
        }
        //public override bool OnCreateOptionsMenu(IMenu menu)
        //{
        //    MenuInflater.Inflate(Resource.Menu.option_menuGener, menu);
        //    return true;
        //}
        //public override bool OnOptionsItemSelected(IMenuItem item)
        //{
        //    int id = item.ItemId;
        //    if (id == Resource.Id.action_settings2)
        //    {
        //        Toast.MakeText(this, "Exit", ToastLength.Short).Show();
        //        History_ListviewActivity histListView = new History_ListviewActivity();
        //        histListView.AlertBox();
        //        return true;
        //    }
        //    else if (id == Resource.Id.action_settings3)
        //    {
        //        Toast.MakeText(this, "Reload", ToastLength.Short).Show();
        //        this.Recreate();
        //        return true;
        //    }
        //    return base.OnOptionsItemSelected(item);
        //    //return super.onCreateView(inflater, container, savedInstanceState);
        //}
        #endregion

        private void setupMessages()
        {
            bool   IsValid;
            string endpoint;

            List <ReceivedMessages> chMessages;
            Address address = new Address();

            RetrieveData retrieve = new RetrieveData();  // retrieve "IsDoctor"

            IsDoctor = retrieve.RetreiveBool();

            if (IsDoctor == false)
            {
                endpoint = address.Endpoint + "MessagesCommunication/" + myID + "/" + receiverID;
            }
            else
            {
                endpoint = address.Endpoint + "MessagesCommunication/" + receiverID + "/" + myID;
            }

            ConsumeRest cRest = new ConsumeRest();

            strResponse = cRest.makeRequest(endpoint);

            ValidateJson validateJson = new ValidateJson();

            IsValid = validateJson.IsValidJson(strResponse);

            if (IsValid)
            {
                chMessages     = JsonConvert.DeserializeObject <List <ReceivedMessages> >(strResponse.ToString());
                receivedMessag = chMessages.OrderBy(i => i.Date).ToList();
                bool isSend;
                for (int i = 0; i < chMessages.Count; i++)
                {
                    if ((IsDoctor == false) && (receivedMessag[i].IsMe == 0))
                    {
                        isSend = true;
                    }                                                                                  // check if message is send or received
                    else if ((IsDoctor == true) && (receivedMessag[i].IsMe == 1))
                    {
                        isSend = true;
                    }
                    else
                    {
                        isSend = false;
                    }

                    lstChat.Add(new chatMessages()
                    {
                        ChatMessage = receivedMessag[i].Text + "\n" + receivedMessag[i].Date, IsSend = isSend
                    });
                }
            }
            else
            {
                chMessages = JsonConvert.DeserializeObject <List <ReceivedMessages> >("[]".ToString());

                new Android.App.AlertDialog.Builder(this)
                .SetTitle("An error has occured")
                .SetMessage("No data found do to unexpected problem" + "\n" + strResponse)
                .SetIcon(Resource.Drawable.error)
                .Show();
            }
        }