public ClassViewModel(int _id)
        {
            LoadGrades();
            _className = DataProvider.Ins.DB.classes.Where(x => x.id == _id).ToArray()[0].name;
            int IdGrade = DataProvider.Ins.DB.classes.Where(x => x.id == _id).ToArray()[0].id_grade;

            GradeName   = DataProvider.Ins.DB.grades.Where(x => x.id == IdGrade).ToArray()[0].name;
            SaveCommand = new RelayCommand <Window>((p) => { return(true); },
                                                    async(p) =>
            {
                EditClass w    = p as EditClass;
                var mySettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Ok",
                    ColorScheme           = w.MetroDialogOptions.ColorScheme
                };
                @class EditingClass   = DataProvider.Ins.DB.classes.Where(x => x.id == w.Id).ToArray()[0];
                EditingClass.name     = _className;
                EditingClass.id_grade = DataProvider.Ins.DB.grades.Where(x => x.name == _gradeName).ToArray()[0].id;
                if (DataProvider.Ins.DB.classes.Where(x => x.name == EditingClass.name && x.id_grade == EditingClass.id_grade).FirstOrDefault() != null)
                {
                    await w.ShowMessageAsync("Hello!", "The class is exist.", MessageDialogStyle.Affirmative, mySettings);
                    return;
                }
                DataProvider.Ins.DB.SaveChanges();
                await w.ShowMessageAsync("Hello!", "Saved success.", MessageDialogStyle.Affirmative, mySettings);
                LoadData();
                EnrollViewModel.LoadClasses();
                w.Close();
            });
        }
Example #2
0
        public EditChildrenViewModel()
        {
            LoadClasses();
            LoadConditions();
            SaveCommand = new RelayCommand <object>((p) => { return(true); },
                                                    async(p) =>
            {
                var mySettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText    = "Ok",
                    NegativeButtonText       = "Go away!",
                    FirstAuxiliaryButtonText = "Cancel",
                    ColorScheme = Window.MetroDialogOptions.ColorScheme
                };
                Child.name         = this._childrenName;
                Child.sex          = this._sex;
                Child.birthdate    = this._birthDate;
                Child.nickname     = this._nickName;
                Child.id_class     = DataProvider.Ins.DB.classes.Where(x => x.name == selectedClass).ToArray()[0].id;
                Child.id_condition = DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).ToArray()[0].id;
                DataProvider.Ins.DB.SaveChanges();
                ManageChildrenViewModel.Ins.LoadData();
                EnrollViewModel.LoadClasses();
                await Window.ShowMessageAsync("Hello!", "Saved changes successfully.", MessageDialogStyle.Affirmative, mySettings);
                Window.Close();
            });

            foreach (Window window in Application.Current.Windows)
            {
                if (window.Name == "EditChildrenWindow")
                {
                    this.Window = window as EditChildren;
                    break;
                }
            }
            Child = DataProvider.Ins.DB.children.Where(x => x.id == Window.id).Join(
                DataProvider.Ins.DB.parents,
                d => d.id_parent,
                f => f.id,
                (d, f) => d
                ).ToArray()[0];
            this.selectedClass = DataProvider.Ins.DB.classes.Where(x => x.id == Child.id_class).ToArray()[0].name;
            this._childrenName = Child.name;
            this._nickName     = Child.nickname;
            this._birthDate    = Child.birthdate;
            this._sex          = Child.sex;
            this._motherName   = Child.parent.Mothername;
            this._fatherName   = Child.parent.FatherName;
            if (DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).Count() > 0)
            {
                this.selectedCondition = DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).ToArray()[0].name;
            }
        }
        public EditChildrenViewModel()
        {
            LoadClasses();
            LoadConditions();
            UploadImageCommand = new RelayCommand <object>((p) => true, (p) =>
            {
                var dlg              = new OpenFileDialog();
                dlg.Title            = "Choose profile picture";
                dlg.InitialDirectory = "";
                dlg.Filter           = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                       "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                       "Portable Network Graphic (*.png)|*.png";
                dlg.Multiselect = false;
                if (dlg.ShowDialog() == true)
                {
                    this.ImageURL = dlg.FileName;
                }
            });
            SaveCommand = new RelayCommand <object>((p) => { return(true); },
                                                    async(p) =>
            {
                var mySettings = new MetroDialogSettings()
                {
                    AffirmativeButtonText    = "Ok",
                    NegativeButtonText       = "Go away!",
                    FirstAuxiliaryButtonText = "Cancel",
                    ColorScheme = Window.MetroDialogOptions.ColorScheme
                };
                Child.name      = this._childrenName;
                Child.sex       = this._sex;
                Child.birthdate = this._birthDate;
                Child.nickname  = this._nickName;
                Child.imageUrl  = this.ImageURL;
                Child.id_class  = DataProvider.Ins.DB.classes.Where(x => x.name == selectedClass).ToArray()[0].id;
                if (DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).FirstOrDefault() != null)
                {
                    Child.id_condition = DataProvider.Ins.DB.conditions.Where(x => x.name == selectedCondition).FirstOrDefault().id;
                }
                DataProvider.Ins.DB.SaveChanges();
                ManageChildrenViewModel.Ins.LoadData();
                EnrollViewModel.LoadClasses();
                await Window.ShowMessageAsync("Hello!", "Save changes success.", MessageDialogStyle.Affirmative, mySettings);
                Window.Close();
            });

            foreach (Window window in Application.Current.Windows)
            {
                if (window.Name == "EditChildrenWindow")
                {
                    this.Window = window as EditChildren;
                    break;
                }
            }
            Child = DataProvider.Ins.DB.children.Where(x => x.id == Window.id).Join(
                DataProvider.Ins.DB.parents,
                d => d.id_parent,
                f => f.id,
                (d, f) => d
                ).ToArray()[0];
            this.selectedClass = DataProvider.Ins.DB.classes.Where(x => x.id == Child.id_class).ToArray()[0].name;
            this._childrenName = Child.name;
            this._nickName     = Child.nickname;
            this._birthDate    = Child.birthdate;
            this._sex          = Child.sex;
            this.ImageURL      = Child.imageUrl;
            this._motherName   = Child.parent.Mothername;
            this._fatherName   = Child.parent.FatherName;
            if (DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).Count() > 0)
            {
                this.selectedCondition = DataProvider.Ins.DB.conditions.Where(x => x.id == Child.id_condition).ToArray()[0].name;
            }
        }
        public ClassViewModel()
        {
            LoadGrades();
            AddClassCommand = new RelayCommand <UserControl>((p) => { return(true); },
                                                             async(p) =>
            {
                MetroWindow CurrentWindow = Application.Current.MainWindow as MetroWindow;
                var mySettings            = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Ok",
                    ColorScheme           = CurrentWindow.MetroDialogOptions.ColorScheme
                };

                var mySettings2 = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Yes",
                    NegativeButtonText    = "No",
                    ColorScheme           = CurrentWindow.MetroDialogOptions.ColorScheme
                };

                if (_className == null || _className == "")
                {
                    await CurrentWindow.ShowMessageAsync("Hello!", "Please fill in every blanks.", MessageDialogStyle.Affirmative, mySettings);
                    return;
                }

                if (_gradeName == null || _gradeName == "")
                {
                    await CurrentWindow.ShowMessageAsync("Hello!", "This grade doesn't exist.", MessageDialogStyle.Affirmative, mySettings);
                    return;
                }

                if (DataProvider.Ins.DB.grades.Where(x => x.name == _gradeName).Count() == 0)
                {
                    await CurrentWindow.ShowMessageAsync("Hello!", "This grade doesn't exist.", MessageDialogStyle.Affirmative, mySettings);
                    return;
                }

                MessageDialogResult mr = await CurrentWindow.ShowMessageAsync("Hello!", "Do you want to add class " + _className + " ?", MessageDialogStyle.AffirmativeAndNegative, mySettings2);
                if (mr == MessageDialogResult.Negative)
                {
                    return;
                }
                if (DataProvider.Ins.DB.classes.Where(x => x.name == this._className).Count() > 0)
                {
                    await CurrentWindow.ShowMessageAsync("Hello!", "This class existed.", MessageDialogStyle.Affirmative, mySettings);
                }
                else
                {
                    @class AddingClass   = new @class();
                    AddingClass.name     = this._className;
                    AddingClass.id_grade = DataProvider.Ins.DB.grades.Where(x => x.name == _gradeName).ToArray()[0].id;
                    DataProvider.Ins.DB.classes.Add(AddingClass);
                    DataProvider.Ins.DB.SaveChanges();
                    await CurrentWindow.ShowMessageAsync("Hello!", "Added successfully.", MessageDialogStyle.Affirmative, mySettings);
                }
                LoadData();
                EnrollViewModel.LoadClasses();
                ReportViewModel.LoadClass();
            });



            EditCommand = new RelayCommand <Button>((p) => { return(true); },
                                                    (p) =>
            {
                int id = Convert.ToInt32(p.Tag);
                EditClass editClass = new EditClass(id);
                editClass.ShowDialog();
            });

            DeleteCommand = new RelayCommand <int>((p) => { return(true); },
                                                   async(p) =>
            {
                MetroWindow CurrentWindow = Application.Current.MainWindow as MetroWindow;
                var mySettings            = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Ok",
                    ColorScheme           = CurrentWindow.MetroDialogOptions.ColorScheme
                };
                var mySettings2 = new MetroDialogSettings()
                {
                    AffirmativeButtonText = "Yes",
                    NegativeButtonText    = "No",
                    ColorScheme           = CurrentWindow.MetroDialogOptions.ColorScheme
                };

                MessageDialogResult mr = await CurrentWindow.ShowMessageAsync("Hello!", "Do you really want to delete this class?", MessageDialogStyle.AffirmativeAndNegative, mySettings2);
                if (mr == MessageDialogResult.Affirmative)
                {
                    @class DeletingClass = DataProvider.Ins.DB.classes.Where(x => x.id == p).ToArray()[0];
                    DataProvider.Ins.DB.classes.Remove(DeletingClass);
                    DataProvider.Ins.DB.SaveChanges();
                    await CurrentWindow.ShowMessageAsync("Hello!", "Deleted successfully.", MessageDialogStyle.Affirmative, mySettings);
                    LoadData();
                    EnrollViewModel.LoadClasses();
                }
            });
            SearchCommand = new RelayCommand <String>((p) => { return(true); },
                                                      (p) =>
            {
                if (p == null)
                {
                    return;
                }
                List <@class> SearchedClass = DataProvider.Ins.DB.classes.Where <@class>(x => x.name.Contains(p)).Join(
                    DataProvider.Ins.DB.grades,
                    d => d.id_grade,
                    f => f.id,
                    (d, f) => d
                    ).ToList();
                LoadData(SearchedClass);
            });
            LoadData();
        }