Beispiel #1
0
        public void main()
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                // Set filter for file extension and default file extension
                dlg.DefaultExt = ".txt";
                dlg.Filter     = "TXT Files (*.txt)|*.txt";

                // Display OpenFileDialog by calling ShowDialog method
                Nullable <bool> result = dlg.ShowDialog();

                // Get the selected file name and display in a TextBox
                if (result == true)
                {
                    //clean timetable_temp
                    DBConnection.Delete("timetable_temp");

                    // Open document
                    string        filename = dlg.FileName;
                    List <string> myValues = new List <string>();
                    string        line;
                    // Read the file and display it line by line.
                    StreamReader file = new StreamReader(filename);
                    while ((line = file.ReadLine()) != null)
                    {
                        myValues.Add(line);
                    }

                    foreach (string item in myValues)
                    {
                        string   row   = string.Join(" ", item.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));
                        string[] items = row.Split(' ');

                        if ((items.Count() != 4) || !items[0].StartsWith("c") || !items[1].StartsWith("r"))
                        {
                            throw new Exception("Selected file is not on the correct format!");
                        }

                        string values = "'" + items[0] + "', '" + items[1] + "', '" + items[2] + "', '" + items[3] + "'";

                        int res = DBConnection.Create("timetable_temp", "course_code, room_code, day, start_period", values);
                    }

                    TimetablingResultDisplay display = new TimetablingResultDisplay();
                    display.Show();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Beispiel #2
0
        private string getCurrentPeriod(UControl position, int courseId)
        {
            string returnText = "";

            Dictionary <string, string> first = new Dictionary <string, string>();
            string    name;
            ArrayList rec = DBConnection.Get("subPeriods", int.Parse(position.Row));

            first = (Dictionary <string, string>)rec[0];
            first.TryGetValue("name", out name);

            returnText = name + " to " + TimetablingResultDisplay.getEndingPeriod(name, courseId);

            return(returnText);
        }
        private void validateTimetableOpen(LoadingPanel.LoadingPanel bar)
        {
            string Columns = " c.id AS course_id";
            string From    = "courses c" +
                             " LEFT JOIN course_teacher_rel ctr ON c.id=ctr.course_id ";
            string Conditions = " c.parent_id IS NOT NULL AND ctr.teacher_id IS NULL ";

            DataTable unasignedCoursesT = DBConnection.Select(From, Columns, Conditions);

            if (unasignedCoursesT.Rows.Count != 0)
            {
                MessageBox.Show("Every course should have a teacher assigned! In order to open Timetable window, you have to assign teachers to these courses first!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                CourseTeacherRelation relationGrid = new CourseTeacherRelation();
                relationGrid.Owner = this;
                relationGrid.checkBox.IsChecked = true;
                bar.Close();
                relationGrid.ShowDialog();
            }
            else
            {
                string ColumnsD = " c.id AS course_id";
                string FromD    = "courses c" +
                                  " LEFT JOIN course_department_rel cdr ON c.id=cdr.course_id ";
                string ConditionsD = " c.parent_id IS NOT NULL AND cdr.department_id IS NULL ";

                DataTable unasignedCoursesD = DBConnection.Select(FromD, ColumnsD, ConditionsD);
                if (unasignedCoursesD.Rows.Count != 0)
                {
                    MessageBox.Show("Every course should have at least a study program assigned! In order to open Timetable window, you have to assign study programs to these courses first!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    CourseDepartmentRel relationGrid = new CourseDepartmentRel();
                    relationGrid.Owner = this;
                    relationGrid.checkBox.IsChecked = true;
                    bar.Close();
                    relationGrid.ShowDialog();
                }
                else
                {
                    TimetablingResultDisplay timetabling = new TimetablingResultDisplay();
                    timetabling.Owner = this;
                    bar.Close();
                    timetabling.ShowDialog();
                }
            }
        }