public void loadTimetable_Click(object sender, RoutedEventArgs e)
        {
            using (var fbd = new System.Windows.Forms.FolderBrowserDialog())
            {
                fbd.RootFolder          = Environment.SpecialFolder.Desktop;
                fbd.SelectedPath        = userMyDocumentsPath + @"\" + @"Timetable App";
                fbd.ShowNewFolderButton = false;
                System.Windows.Forms.DialogResult result = fbd.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    int    index = fbd.SelectedPath.LastIndexOf(@"\");
                    string tName = fbd.SelectedPath.Substring(index + 1);
                    //MessageBox.Show(tName);
                    insertRoomCsv     irc = new insertRoomCsv(tName);
                    insertLecturerCSV ilc = new insertLecturerCSV(tName);
                    insertCourseCSV   icc = new insertCourseCSV(tName);
                    insertModuleCSV   imc = new insertModuleCSV(tName);
                    bool ifValid          = ifVaildLoadFile(fbd.SelectedPath);
                    if (ifValid)
                    {
                        DataTable roomCSV = irc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "rooms.txt");
                        irc.InsertDataTableToSQL(roomCSV);
                        irc.selectIntoDistinct();
                        irc.truncateTempAfterCSVInsert();
                        DataTable lecturerCSV = irc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturers.txt");
                        ilc.InsertDataTableToSQL(lecturerCSV);
                        ilc.selectIntoDistinct();
                        ilc.truncateTempAfterCSVInsert();
                        DataTable courseCSV = icc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "courses.txt");
                        icc.InsertDataTableToSQL(courseCSV);
                        icc.selectIntoDistinct();
                        icc.truncateTempAfterCSVInsert();
                        DataTable modulesCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "modules.txt");
                        imc.InsertDataTableToSQL(modulesCSV);
                        imc.selectIntoDistinct();
                        imc.truncateTempAfterCSVInsert();

                        DataTable courseModuleCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "coursemodules.txt");
                        InsertDataTableToSQL(courseModuleCSV);
                        DataTable timetableCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "timetable.txt");
                        InsertDataTableToSQLTimetable(timetableCSV);

                        DataTable lecturerModuleCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturermodules.txt");
                        InsertDataTableToSQLlecturerModules(lecturerModuleCSV);

                        Window1 win1 = new Window1(tName);
                        win1.Show();
                        irc.Close();
                        ilc.Close();
                        icc.Close();
                        imc.Close();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Timetable must be loaded from the Timetable App folder");
                    }
                }
            }
        }
Example #2
0
        public void menuCoursesCSV_Click(object sender, RoutedEventArgs e)
        {
            insertCourseCSV icc = new insertCourseCSV(timetableName);

            icc.Owner = this;
            string fileName     = "courses.txt";
            string tableColumns = "courseCode,courseName,noOfStudents";

            createExampleCSVFile(fileName, tableColumns);
            icc.ShowDialog();
        }
        // event handler for the load buton
        public void loadTimetable_Click(object sender, RoutedEventArgs e)
        {
            // clear all database table incase the program crashes
            truncateAllTables();
            using (var fbd = new System.Windows.Forms.FolderBrowserDialog())
            {
                // set the root folder for the dialog box
                fbd.RootFolder = Environment.SpecialFolder.Desktop;
                // set the folder the dialog box opens on
                fbd.SelectedPath = userMyDocumentsPath + @"\" + @"Timetable App";
                // get rid of the create new folder button
                fbd.ShowNewFolderButton = false;
                // used folder browser dialog from windows forms
                System.Windows.Forms.DialogResult result = fbd.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    int    index = fbd.SelectedPath.LastIndexOf(@"\");
                    string tName = fbd.SelectedPath.Substring(index + 1);
                    // instantiate
                    insertRoomCsv     irc = new insertRoomCsv(tName);
                    insertLecturerCSV ilc = new insertLecturerCSV(tName);
                    insertCourseCSV   icc = new insertCourseCSV(tName);
                    insertModuleCSV   imc = new insertModuleCSV(tName);
                    //
                    bool ifValid = ifVaildLoadFile(fbd.SelectedPath);
                    if (ifValid)
                    {
                        bool roomSuccess     = false;
                        bool lecturerSuccess = false;
                        bool courseSuccess   = false;
                        bool moduleSuccess   = false;

                        // if file exists load data from csv
                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "rooms.txt"))
                        {
                            DataTable roomCSV = irc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "rooms.txt");
                            roomSuccess = irc.InsertDataTableToSQL(roomCSV);

                            if (roomSuccess)
                            {
                                //irc.InsertDataTableToSQL(roomCSV);
                                irc.selectIntoDistinct();
                                irc.truncateTempAfterCSVInsert();
                            }
                        }
                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturers.txt"))
                        {
                            DataTable lecturerCSV = irc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturers.txt");
                            lecturerSuccess = ilc.InsertDataTableToSQL(lecturerCSV);

                            if (lecturerSuccess)
                            {
                                ilc.selectIntoDistinct();
                                ilc.truncateTempAfterCSVInsert();
                            }
                        }

                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "courses.txt"))
                        {
                            DataTable courseCSV = icc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "courses.txt");
                            courseSuccess = icc.InsertDataTableToSQL(courseCSV);

                            if (courseSuccess)
                            {
                                icc.selectIntoDistinct();
                                icc.truncateTempAfterCSVInsert();
                            }
                        }

                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "modules.txt"))
                        {
                            DataTable modulesCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "modules.txt");
                            moduleSuccess = imc.InsertDataTableToSQL(modulesCSV);

                            if (moduleSuccess)
                            {
                                imc.selectIntoDistinct();
                                imc.truncateTempAfterCSVInsert();
                            }
                        }


                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "coursemodules.txt"))
                        {
                            DataTable courseModuleCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "coursemodules.txt");
                            InsertDataTableToSQL(courseModuleCSV);
                        }

                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "timetable.txt"))
                        {
                            DataTable timetableCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "timetable.txt");
                            InsertDataTableToSQLTimetable(timetableCSV);
                        }

                        if (File.Exists(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturermodules.txt"))
                        {
                            DataTable lecturerModuleCSV = imc.getDataTableCSVFile(userMyDocumentsPath + "/Timetable App/" + tName + "/" + "lecturermodules.txt");
                            InsertDataTableToSQLlecturerModules(lecturerModuleCSV);
                        }
                        // this if statment was used to stop the user being able to load if the was a formating issue in a csv file

                        /* if(roomSuccess && moduleSuccess && courseSuccess && lecturerSuccess)
                         * {*/
                        // load new window pass in the timetable name
                        Window1 win1 = new Window1(tName);
                        win1.Show();
                        irc.Close();
                        ilc.Close();
                        icc.Close();
                        imc.Close();
                        this.Close();
                        //}
                    }
                    else
                    {
                        MessageBox.Show("Timetable must be loaded from the Timetable App folder");
                    }
                }
            }
        }