Ejemplo n.º 1
0
        private void ChooseUser_Click(object sender, RoutedEventArgs e)
        {
            DatabaseSave.SaveDatabase();
            UserSelection userSelection = new UserSelection(this);

            userSelection.Show();
        }
Ejemplo n.º 2
0
 //JSON Save
 private void JSONSaveClick(Object sender, RoutedEventArgs e)
 {
     DatabaseSave.SaveDatabase();
 }
Ejemplo n.º 3
0
        public MainWindow()
        {
            // Ensure only one USurvive is running
            Process proc  = Process.GetCurrentProcess();
            int     count = Process.GetProcesses().Where(p => p.ProcessName == proc.ProcessName).Count();

            if (count > 1)
            {
                MessageBox.Show("Only one instance of USurvive can run at a time.");
                App.Current.Shutdown();
            }

            InitializeComponent();
            Globals.tempClasses     = new ObservableCollection <Class>();
            Globals.tempAssignments = new List <Assignment>();
            //NavigationService service = NavigationService.GetNavigationService(NavigationFrame);


            //Set up dataDir varaiable
            Globals.dataDir  = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            Globals.dataDir += "\\USurvive";
            //Set up data directory
            if (!Directory.Exists(Globals.dataDir))
            {
                //Create data dir in AppData
                Directory.CreateDirectory(Globals.dataDir);
                //Create default database directory
                Directory.CreateDirectory(Globals.dataDir + "\\default");
            }
            //Add final '\' to place path inside %AppData%/USurvive
            Globals.dataDir += "\\";

            Globals.databaseName = "default";
            //Check for different database setting
            if (File.Exists(Globals.dataDir + "databaseSetting"))
            {
                string[] databaseName = File.ReadAllLines(Globals.dataDir + "databaseSetting");
                if (databaseName.Length == 1)//Ensure database file is somewhat correct
                {
                    string databaseString = databaseName[0];
                    if (Directory.Exists(Globals.dataDir + databaseString))
                    {
                        Globals.databaseName = databaseString;
                    }
                }
            }

            //Add final '\' to path
            Globals.databaseName += "\\";

            //Ensure a directory exists
            if (!Directory.Exists(Globals.dataDir + Globals.databaseName))
            {
                //Display message saying database is corrupt
                //TODO: Display message saying database is corrupt

                //Ask user to choose new database file

                //Create new folder if none exist
                Directory.CreateDirectory(Globals.dataDir + Globals.databaseName);
            }


            //Make sure temporary directory doesn't exist
            if (Directory.Exists(Globals.dataDir + "\\tempDir"))
            {
                Directory.Delete(Globals.dataDir + "\\tempDir", true);
            }

            //Set up working dir variable
            Globals.workingDir = Globals.dataDir + Globals.databaseName;

            //Ensure syllabus folder exists
            if (!Directory.Exists(Globals.workingDir + "syllabus"))
            {
                Directory.CreateDirectory(Globals.workingDir + "syllabus");
            }

            Globals.clList    = new ClassList();
            Globals.cwList    = new ClassworkList();
            Globals.gradebook = new GradeList();

            //Load databases
            DatabaseLoad.LoadDatabase();//Load the database

            if (Globals.cwList == null)
            {
                Globals.cwList = new ClassworkList();
            }

            //Set up sidebar
            Globals.SidebarWidth = 200;
            SidebarColumn.Width  = new GridLength(Globals.SidebarWidth);
            sidebar = new Sidebar();
            SidebarFrame.Navigate(sidebar);


            //Timer that calls tick every 200ms
            DispatcherTimer dispatcherTimer = new DispatcherTimer();

            dispatcherTimer.Tick    += new EventHandler(tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 200);
            dispatcherTimer.Start();

            //Determine what color to paint the buttons

            //https://stackoverflow.com/a/58528170
            var uiSettings  = new UISettings();
            var accentColor = uiSettings.GetColorValue(UIColorType.Accent);

            accent = new SolidColorBrush(Color.FromArgb(accentColor.A, accentColor.R, accentColor.G, accentColor.B));

            //Check if accent color is dark.  If it is, we don't want to use it since it won't be easy to see
            if (accentColor.R <= 100 && accentColor.G <= 100 && accentColor.B <= 100)
            {
                accent = new SolidColorBrush(Color.FromArgb(accentColor.A, 0, 120, 215));
            }

            //Now opens to the Home View
            HomeView homeView = new HomeView();

            Select(Selection.Home);
            NavigationFrame.Navigate(homeView);
            DatabaseSave.SaveDatabase();
        }
Ejemplo n.º 4
0
 void DataWindow_Closing(object sender, EventArgs e)
 {
     //backWork.Abort();
     DatabaseSave.SaveDatabase();
     System.Windows.Application.Current.Shutdown();
 }