Esempio n. 1
0
        async void userdetails(object UserDetails = null)
        {
            try
            {
                overlay.IsVisible = true;
                UserDetais objUserDetais = new Models.UserDetais();

                if (UserDetails == null)
                {
                    var Dropdowns = new CommonDropDowns();
                    objUserDetais = await App.TodoManager.UserDetais(App.id);

                    pkrGender.ItemsSource         = Dropdowns.Gender();
                    pkrseniorityLevel.ItemsSource = Dropdowns.GetSenorityLevels();
                }
                txtId.Text                      = objUserDetais.data.employee_code;
                txtName.Text                    = objUserDetais.data.name;
                txtEmail.Text                   = objUserDetais.data.email;
                txtPhone.Text                   = objUserDetais.data.phone;
                txtDesignation.Text             = objUserDetais.data.designation;
                txtDob.Date                     = Convert.ToDateTime(objUserDetais.data.date_of_birth);
                pkrBloodGroup.SelectedItem      = objUserDetais.data.blood_group;
                pkrGender.SelectedIndex         = objUserDetais.data.gender.ToLower() == "male" ? 0 : 1;
                pkrseniorityLevel.SelectedIndex = objUserDetais.data.seniority_level - 1;
                txtId.Text                      = objUserDetais.data.info.employee_id;
                txtEmergencyNumber.Text         = objUserDetais.data.info.emergency_number;
                ImgUserImage.Source             = objUserDetais.data.photo_url;
                ImgUserImage.Source             = App.KyorData != null ? App.KyorData.photo_url : "http://squareboat.testing.kyor.com/profile/photo/default.png";
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMessage>().LongAlert();
            }
            finally
            {
                overlay.IsVisible = false;
            }
        }
Esempio n. 2
0
        private async void btnSave_Clicked(object sender, EventArgs e)
        {
            try
            {
                string Message = "All Fields are Required";
                //await Navigation.PushAsync(new AddTest());
                //return;
                var Valid = true;
                #region Validation
                foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                {
                    if (hc.Name == "")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.Relation == null)
                    {
                        Valid = false;
                        break;
                    }
                    hc.RelationID = objCommonDropDowns.GetRalations().Find(x => x.Name == hc.Relation).ID.ToString();
                    if (hc.EmployeeCode == "" && hc.Relation == "Self")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.ID == 0 && hc.Relation == "Self")
                    {
                        if (hc.SeniorityLevel == null)
                        {
                            Valid = false;
                            break;
                        }
                        else if (hc.SeniorityLevelID == null)
                        {
                            hc.SeniorityLevelID = objCommonDropDowns.GetSenorityLevels().Find(x => x.Name == hc.SeniorityLevel).ID.ToString();
                        }
                    }
                    else
                    {
                        if (hc.SeniorityLevelID == null && hc.SeniorityLevel != null)
                        {
                            hc.SeniorityLevelID = objCommonDropDowns.GetSenorityLevels().Find(x => x.Name == hc.SeniorityLevel).ID.ToString();
                        }
                    }

                    if (hc.Phone == "")
                    {
                        Valid = false;
                        break;
                    }
                    else if (!Regex.IsMatch(hc.Phone, @"^[0-9]{10}$"))
                    {
                        Message = "Not Valid Mobile No.";
                        // DependencyService.Get<IMessage>().LongAlert("Not Valid Mobile No.");
                        Valid = false;
                    }
                    if (hc.DateOfBirth == "")
                    {
                        Valid = false;
                        break;
                    }
                    if (hc.MaritalStatus == null)
                    {
                        Valid = false;
                        break;
                    }
                    else if (hc.MaritalStatusID == null)
                    {
                        hc.MaritalStatusID = objCommonDropDowns.MaritalStatus().Find(x => x.Name == hc.MaritalStatus).ID;
                    }
                    if (hc.Gender == null)
                    {
                        Valid = false;
                        break;
                    }
                    else
                    {
                        hc.GenderID = objCommonDropDowns.Gender().Find(x => x.Name == hc.Gender).ID;
                    }

                    if (hc.Name.Length < 2)
                    {
                        Valid   = false;
                        Message = "Name should be of atleast 2 characters";
                    }
                }
                #endregion Validation
                string   errorstring = "";
                AHCError err         = new AHCError();
                MessagingCenter.Subscribe <App, string>((App)Xamarin.Forms.Application.Current, "AHCHealthCheckup", (app, message) =>
                {
                    try
                    {
                        err = JsonConvert.DeserializeObject <AHCError>(message);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                    //var options = obj["fields"][0]["options"].ToList();
                });

                if (Valid)
                {
                    PatientDetailsList    objPatientDetailsList = new PatientDetailsList();
                    List <PatientDetails> lstPatientDetails     = new List <Models.PatientDetails>();
                    PatientDetails        objPatientDetails;

                    foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                    {
                        objPatientDetails                       = new PatientDetails();
                        objPatientDetails.relation              = hc.RelationID.ToString();
                        objPatientDetails.employee_code         = hc.EmployeeCode;
                        objPatientDetails.name                  = hc.Name;
                        objPatientDetails.phone                 = hc.Phone;
                        CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
                        try
                        {
                            objPatientDetails.date_of_birth = Convert.ToDateTime(hc.DateOfBirth).ToString("yyyy-MM-dd"); //hc.DateOfBirth;
                        }
                        catch (Exception)
                        {
                            string Date = hc.DateOfBirth.ToString().Replace("00:00:00", "").Replace(" ", "");
                            objPatientDetails.date_of_birth = Date;
                        }
                        objPatientDetails.marital_status  = hc.MaritalStatusID.ToString();
                        objPatientDetails.gender          = hc.GenderID.ToString();
                        objPatientDetails.seniority_level = hc.SeniorityLevelID;
                        lstPatientDetails.Add(objPatientDetails);
                    }
                    objPatientDetailsList.patients = lstPatientDetails;
                    overlay.IsVisible = true;
                    SavePatientResponse objSavePatientResponse = await App.TodoManager.SavePatientDetails(objPatientDetailsList);

                    if (objSavePatientResponse.status == "success")
                    {
                        #region  Remove error messages
                        int index = 0;
                        foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                        {
                            lstHealthCheckupInitial[index].ErrormessageVisiblity = false;
                            lstHealthCheckupInitial[index].ErrorMessage          = "";
                            //  lstHealthCheckUpDeafult.Add(objHealthCheckUpDeafult);
                            index++;
                        }

                        lvHealthCheckups.ItemsSource = null;
                        lvHealthCheckups.ItemsSource = lstHealthCheckupInitial;
                        #endregion
                        await Navigation.PushAsync(new AddTest(objSavePatientResponse.data.id, objSavePatientResponse.data.patients[0].id));

                        //await DisplayAlert("Success", "Patient Added Successfully", "Ok");
                    }
                    else
                    {
                        int     index        = 0;
                        int     errorindex   = 0;
                        string  Errormessage = "";
                        dynamic item         = null;
                        ObservableCollection <HealthCheckUpDeafult> lstHealthCheckUpDeafult = new ObservableCollection <HealthCheckUpDeafult>();
                        HealthCheckUpDeafult objHealthCheckUpDeafult = new HealthCheckUpDeafult();
                        foreach (HealthCheckUpDeafult hc in lstHealthCheckupInitial)
                        {
                            objHealthCheckUpDeafult = hc;
                            if (errorindex < index | index == 0)
                            {
                                item       = err.data.ElementAt(index);
                                errorindex = Convert.ToInt32(item.Key.ToString().Substring(item.Key.IndexOf('.') + 1, 1));
                            }
                            if (errorindex == index)
                            {
                                Errormessage             = "";
                                hc.ErrormessageVisiblity = true;
                                Errormessage            += "\n Error: \n" + string.Join("\n", item.Value) + "\n";
                                objHealthCheckUpDeafult.ErrormessageVisiblity = true;
                                objHealthCheckUpDeafult.ErrorMessage          = Errormessage;
                                //lstHealthCheckUpDeafult[index]=
                                //lstHealthCheckupInitial[index].ErrormessageVisiblity  = true;
                                //  lstHealthCheckupInitial[index].ErrorMessage = Errormessage;
                            }
                            else
                            {
                                objHealthCheckUpDeafult.ErrormessageVisiblity = false;
                                objHealthCheckUpDeafult.ErrorMessage          = "";
                            }
                            lstHealthCheckUpDeafult.Add(objHealthCheckUpDeafult);
                            index++;
                        }
                        lstHealthCheckupInitial      = lstHealthCheckUpDeafult;
                        lvHealthCheckups.ItemsSource = lstHealthCheckUpDeafult;
                        DependencyService.Get <IMessage>().LongAlert(objSavePatientResponse.message);
                    }
                }
                else

                {
                    DependencyService.Get <IMessage>().LongAlert(Message);
                }
            }
            catch (InvalidOperationException ex)
            {
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMessage>().LongAlert();
            }
            finally
            {
                overlay.IsVisible = false;
            }
        }