Example #1
0
        public WindowViewModel()
        {
            Title = "ShuffleLunch";

            _lunchInfo = new LunchInfo();

            var setting = Setting.Instance;

            setting.Get();
            FontSizeDesk       = setting.FontSizeDesk;
            FontSizePerson     = setting.FontSizePerson;
            ImageWidth         = setting.ImageWidth;
            ImageHeight        = setting.ImageHeight;
            ShuffleImageWidth  = setting.ShuffleImageWidth;
            ShuffleImageHeight = setting.ShuffleImageHeight;


            FileOpen = new DelegateCommand(_ =>
            {
                var b = _lunchInfo.Get();
                if (b == false)
                {
                    return;
                }

                PersonList        = new ObservableCollection <Person>(_lunchInfo.PersonList());
                DeskList          = new ObservableCollection <Desk>(_lunchInfo.DeskList());
                PersonAndDeskList = new ObservableCollection <PersonAndDesk>(_lunchInfo.PersonAndDeskList());
            });

            ButtonShuffle = new DelegateCommand(_ =>
            {
                var shuffle = new Shuffle();
                var b       = shuffle.shuffle(DeskList.ToList <Desk>(), PersonAndDeskList.ToList <PersonAndDesk>());
                if (b == false)
                {
                    return;
                }

                ShuffleResultList = new ObservableCollection <ShuffleResult>(shuffle.Get());
            });

            ButtonAddUser = new DelegateCommand(_ =>
            {
                var deskList = new List <string>();
                for (int i = 0; i < DeskList.Count; i++)
                {
                    deskList.Add(DeskList[i].name);
                }

                var myAssembly    = Assembly.GetEntryAssembly();
                string path       = myAssembly.Location;
                path              = path.Replace("ShuffleLunch.exe", "");
                var personAndDesk = new PersonAndDesk
                {
                    name       = AddUserName,
                    desk       = deskList,
                    selectDesk = 0,
                    image      = path + @"image\guest.png"
                };
                PersonAndDeskList.Add(personAndDesk);
                AddUserName = "";
            });

            ExportImage = new DelegateCommand(element =>
            {
                PngExporter.Export((FrameworkElement)element);
            });
        }