예제 #1
0
        private async Task ExecuteOnSave()
        {
            if (Drugs.Duration < 1 & !Drugs.Indeterminer)
            {
                DependencyService.Get <IMessage>().ShortAlert("Invalid Duration !");
                return;
            }
            if (!string.IsNullOrEmpty(Drugs.Drug) & index >= 0 & Times_List.Count > 0 & Drugs.Dose > 0)
            {
                if (await DependencyService.Get <IDialog>().AlertAsync("", "Voulez Vous Enregistrer ?", "Oui", "Non"))
                {
                    Drugs.Times_List = Times_List.ToList();
                    switch (Index)
                    {
                    case 0: Drugs.Taking_Time = "unimportant"; break;

                    case 1: Drugs.Taking_Time = "without food"; break;

                    case 2: Drugs.Taking_Time = "preparandial"; break;

                    case 3: Drugs.Taking_Time = "postparandial"; break;
                    }
                    Drugs.PicturePathe = PicturePath;
                    DataStore.AddDrugs(Drugs);
                    MessagingCenter.Send(this, "DataUpdated");
                    RappelService.SetRappel();
                    await Navigation.PopModalAsync();
                }
            }
            else
            {
                DependencyService.Get <IMessage>().ShortAlert("Invalide Data !");
            }
        }
예제 #2
0
        private async Task ExecuteOnEdit()
        {
            if (Drugs != null)
            {
                if (Drugs.Duration < 1 & !Drugs.Indeterminer)
                {
                    DependencyService.Get <IMessage>().ShortAlert("Invalid Duration !");
                    return;
                }
                if (!string.IsNullOrEmpty(Drugs.Drug) & !string.IsNullOrEmpty(Drugs.Taking_Time) & Times_List.Count > 0 & Drugs.Dose > 0)
                {
                    if (await DependencyService.Get <IDialog>().AlertAsync("", Resources["EditMessage"], Resources["Yes"], Resources["No"]))
                    {
                        Drugs.Times_List   = Times_List.ToList();
                        Drugs.PicturePathe = PicturePath;
                        DataStore.UpdateDrugs(Drugs);

                        MessagingCenter.Send(this, "DataUpdated");
                        RappelService.SetRappel();
                        await Navigation.PopModalAsync();
                    }
                }
                else
                {
                    DependencyService.Get <IMessage>().ShortAlert("Invalid Data !");
                }
            }
        }
예제 #3
0
        public AddDrugs_ViewModel(INavigation navigation, IDataStore dataStore, Drugs_Model drug = null)
        {
            DataStore         = dataStore;
            Navigation        = navigation;
            Taking_Times_List = new List <string>();
            Taking_Times_List.Add(Resources["Unimportant"]);
            Taking_Times_List.Add(Resources["Without food"]);
            Taking_Times_List.Add(Resources["Before_Meal"]);
            Taking_Times_List.Add(Resources["After_Meals"]);
            if (drug != null)
            {
                Drugs       = drug;
                Times_List  = new ObservableCollection <string>(Drugs.Times_List);
                PicturePath = Drugs.PicturePathe;
                Picture     = ImageSource.FromFile(PicturePath);
                IsVisible   = true;
            }
            else
            {
                Drugs      = new Drugs_Model();
                Times_List = new ObservableCollection <string>();
            }
            string JsonFile = "DrugsJson.json";
            var    assembly = IntrospectionExtensions.GetTypeInfo(typeof(AddDrugs_ViewModel)).Assembly;
            Stream stream   = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.{JsonFile}");

            using (var reader = new StreamReader(stream))
            {
                var json = reader.ReadToEnd();
                DrugsList = JsonConvert.DeserializeObject <List <DrugsJsonModel> >(json).Select(i => i.Name).ToList();
            }
            PermissionsRequest = new PermissionsRequest();
            MessagingCenter.Subscribe <AddDrugs_View, string>(this, "AddDrugs", (sender, args) =>
            {
                Times_List.Add(args);
            });
            SaveCommand = new Command(async() =>
            {
                await ExecuteOnSave();
            });
            TakePictureCommand = new Command(async() =>
            {
                await ExecuteOnTakePicture();
            });
            PictureTappedCommand = new Command(async() =>
            {
                await ExecuteOnPictureTapped();
            });
            DeleteCommand = new Command(async() =>
            {
                await ExecuteOnDelete();
            });
            EditCommand = new Command(async() =>
            {
                await ExecuteOnEdit();
            });
        }