Search This Blog

Wednesday, 7 December 2016

N

 public partial class MedicationPage : ContentPage
    {
        ObservableCollection<MedicationWithDosage> objMEdicationWithDosage = null;
        public MedicationPage()
        {
            Title = "Medication";
            InitializeComponent();

            btnSave.Clicked += BtnSave_Clicked;
            addMedicineDialogScroll.IsVisible = false;
            LoadMEdicationWithDosageData();
            btnMedicationRemindme.Clicked += delegate
            {
                Navigation.PushModalAsync(new NotePage());
            };
            btnMedicationNext.Clicked += delegate
            {
                string strMedicationName = "";
                foreach (var eachItem in objMEdicationWithDosage)
                {
                    if (eachItem.ImgPic == "med_select.png" && eachItem.MedicationName != "None")
                    {
                        strMedicationName = strMedicationName + eachItem.MedicationName + ",";
                    }
                }
                strMedicationName = strMedicationName.Substring(0, strMedicationName.Length - 1);
                strMedicationName = strMedicationName + ".";

             
                App.strMedicationName = strMedicationName;
                Navigation.PushModalAsync(new NotePage());
            };
            int _Medicianlimit = 30;
            etMedicationName.TextChanged += (sender, args) =>
            {
                string _text = etMedicationName.Text;      //Get Current Text
                if (_text.Length > _Medicianlimit)       //If it is more than your character restriction
                {
                    _text = _text.Remove(_text.Length - 1);  // Remove Last character
                    etMedicationName.Text = _text;        //Set the Old value
                }
            };
            int _Dosagelimit = 3;
            etDosage.TextChanged += (sender, args) =>
            {
                string _text = etDosage.Text;      //Get Current Text
                if (_text.Length > _Dosagelimit)       //If it is more than your character restriction
                {
                    _text = _text.Remove(_text.Length - 1);  // Remove Last character
                    etDosage.Text = _text;        //Set the Old value
                }
            };
        }
        private void BtnSave_Clicked(object sender, EventArgs e)
        {
            if(etMedicationName!=null && etMedicationName.Text.Trim().Length>0)
            {
                var selectedItems = (from p in objMEdicationWithDosage where p.MedicationName == etMedicationName.Text select p).ToList();
                if (selectedItems.Count > 0)
                {
                    DisplayAlert("error", "medicationName already you have added to List.", "ok");
                    return;
                }
                else
                {
                    objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = etMedicationName.Text, ImgPic = "med_deselect.png" });
                    lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;
                    etMedicationName.Text = "";
                    etDosage.Text = "";
                }
            }
            else
            {
                DisplayAlert("error", "Please Enter medicationName", "ok");
                return;
            }
        }
        public void Handle_Clicked(object sender, EventArgs e)
        {
            addMedicineDialogScroll.IsVisible = true;
        }

        public void OnSaveButtonClicked(object sender, EventArgs args)
        {
            addMedicineDialogScroll.IsVisible = false;
        }

        public void OnCancelButtonClicked(object sender, EventArgs args)
        {
            addMedicineDialogScroll.IsVisible = false;
        }
        public void LoadMEdicationWithDosageData()
        {
            objMEdicationWithDosage = new ObservableCollection<MedicationWithDosage>();
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "None", ImgPic = "med_select.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Zooming (600 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Calpol (650 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Figorty (230 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Higtyui (500 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Firtosia (300 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Glinica (300 mg)", ImgPic = "med_deselect.png" });
            objMEdicationWithDosage.Add(new MedicationWithDosage { MedicationName = "Migoi (300 mg)", ImgPic = "med_deselect.png" });
            lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;

            lstMedicationWithDosage.ItemSelected += LstMedicationWithDosage_ItemSelected;
        }

        private void LstMedicationWithDosage_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return; // ensures we ignore this handler when the selection is just being cleared
            }
            lstMedicationWithDosage.ItemsSource = null;
            MedicationWithDosage item = e.SelectedItem as MedicationWithDosage;
            if (item.ImgPic == "med_select.png")
            {
                item.ImgPic = "med_deselect.png";
            }
            else
            {
                item.ImgPic = "med_select.png";
            }
            var selectedItems = (from s in objMEdicationWithDosage where s.ImgPic == "med_select.png"
                                 && s.MedicationName!= "None" select s).ToList();
            if (selectedItems.Count > 0)
            {
                objMEdicationWithDosage[0].ImgPic = "med_deselect.png";
            }
            else
            {
                objMEdicationWithDosage[0].ImgPic = "med_select.png";
            }

            if (item.MedicationName == "None")
            {
                var selectedItemsList = (from s in objMEdicationWithDosage
                                         where s.ImgPic == "med_select.png" select s).ToList();
                foreach(var eachItem in selectedItemsList)
                {
                    eachItem.ImgPic = "med_deselect.png";
                }
                item.ImgPic ="med_select.png";
            }
            lstMedicationWithDosage.ItemsSource = objMEdicationWithDosage;
            ((ListView)sender).SelectedItem = null;
        }
    }

No comments:

Post a Comment