コード例 #1
0
        public async void Search(object sender, EventArgs args)
        {
            Application.Current.Properties["id"] = "Entered Picker";
            Cover.IsVisible = true;
            await SearchButton.ScaleTo(0.95, 50, Easing.CubicOut);

            await SearchButton.ScaleTo(1, 50, Easing.CubicIn);

            bool state = true;

            var CityName      = Application.Current.Properties["City"];
            var HospitalName  = Application.Current.Properties["Hospital"];
            var SpecialtyName = Application.Current.Properties["Specialty"];

            try
            {
                if (HospitalName.ToString() != "Choose Hospital" && SpecialtyName.ToString() != "Choose Specialty")
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Hospital = HospitalName.ToString(), Specialty = SpecialtyName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }

                else if (CityName.ToString() != "Choose City" && SpecialtyName.ToString() != "Choose Specialty")
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        City = CityName.ToString(), Specialty = SpecialtyName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }
                else if (CityName.ToString() != "Choose City" && HospitalName.ToString() != "Choose Hospital")  ///////////     important for repeated hospitals in diffrent cities
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        City = CityName.ToString(), Hospital = HospitalName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }

                else if (CityName.ToString() != "Choose City")
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        City = CityName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }
                else if (HospitalName.ToString() != "Choose Hospital")
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Hospital = HospitalName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }

                else if (SpecialtyName.ToString() != "Choose Specialty")
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Specialty = SpecialtyName.ToString()
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }
                else
                {
                    ListOfDoctors.Clear();
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?");
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                    HttpResponseMessage response = await client.SendAsync(message);

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

                    DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);
                    foreach (var item in a.GetStringList())
                    {
                        ListOfDoctors.Add(item);
                    }

                    if (ListOfDoctors.Count == 0)
                    {
                        await DisplayAlert("Problem", " No Doctor in database", "ok");

                        Cover.IsVisible = false;
                    }
                    else
                    {
                        //loading.IsVisible = false;
                        Cover.IsVisible = false;
                        await Navigation.PushAsync(new ResultsC(ListOfDoctors, username));
                    }
                }
            }
            catch (Exception e)
            {
                state = false;
            }
            if (state == false)
            {
                await DisplayAlert("Problem", "Issue with connection", "ok");

                Cover.IsVisible = false;
                state           = true;
            }
        }
コード例 #2
0
        public async void Picker(object sender, EventArgs args)
        {
            await CreateUser.ScaleTo(0.95, 50, Easing.CubicOut);

            await CreateUser.ScaleTo(1, 50, Easing.CubicIn);

            CreateLoading.IsRunning = true;

            // here you Create Data
            if (DoctorName.Text != null)
            {
                string Doctor  = DoctorName.Text;
                string Doctor2 = Doctor.Trim();

                int CityNumber      = ListOfCities.SelectedIndex;
                int HospitalNumber  = ListOfHospitals.SelectedIndex;
                int SpecialtyNumber = ListOfSpecialties.SelectedIndex;
                if (CityNumber != -1 && HospitalNumber != -1 && SpecialtyNumber != -1 && Doctor2 != "")
                {
                    Debug.WriteLine("city selected was " + MyCity[CityNumber]);
                    Debug.WriteLine("hospital selected was " + MyHospital[HospitalNumber]);
                    Debug.WriteLine("Specialty selected was " + MySpecialty[SpecialtyNumber]);

                    ///////////////////////// CHECK IF DOCTOR ALREADY EXISTS

                    HttpClient         client1  = new HttpClient();
                    HttpRequestMessage message1 = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/EmployeeData?" + JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Name = DoctorName.Text
                    }));
                    message1.Headers.Clear();
                    message1.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message1.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                    bool state = true;
                    try
                    {
                        HttpResponseMessage response = await client1.SendAsync(message1);

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

                        DataToListForEmployees a = JsonConvert.DeserializeObject <DataToListForEmployees>(content);


                        if (a.GetStringList().Contains(DoctorName.Text))
                        {
                            CreateLoading.IsRunning = false;
                            await DisplayAlert("Problem", "Doctor already exists", "ok");

                            return;
                        }
                        // listView.ItemsSource = MyList;
                    }
                    catch (Exception e)
                    {
                        state = false;
                    }
                    if (state == false)
                    {
                        await DisplayAlert("Problem", "Issue with connection", "ok");
                    }



                    ////////////////////////////////////////////////////////////////////////////////////////////
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://api.parse.com/1/classes/EmployeeData");
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                    string json = JsonConvert.SerializeObject(new DataParserForEmployees()
                    {
                        Name = DoctorName.Text, Hospital = MyHospital[HospitalNumber], Specialty = MySpecialty[SpecialtyNumber], City = MyCity[CityNumber]
                    });
                    message.Content = new StringContent(json, Encoding.UTF8, "application/json");
                    message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    try
                    {
                        HttpResponseMessage response = await client.SendAsync(message);

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

                        CreateLoading.IsRunning = false;
                        await DisplayAlert("Congratulations", DoctorName.Text + " was created !", "ok");

                        DoctorName.Text = "";
                    }
                    catch (Exception e1)
                    {
                    }
                }
                else
                {
                    CreateLoading.IsRunning = false;
                    await DisplayAlert("Problem", " Must fill all the blanks", "ok");
                }
            }
            else
            {
                CreateLoading.IsRunning = false;
                await DisplayAlert("Problem", " Must fill all the blanks", "ok");
            }
        }