Esempio n. 1
0
 bool CanAddASubject(SubjectClass subjectClass)
 {
     foreach (var tmpSubjectClass in chosenSubjectClass)
     {
         if (tmpSubjectClass.IsIntersect(subjectClass))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
        public bool IsIntersect(SubjectClass other)
        {
            var otherClassTimes = other.GetClassTimes();

            foreach (Range thisClassPeriod in times)
            {
                foreach (Range otherClassPeriod in otherClassTimes)
                {
                    if (thisClassPeriod.IsIntersect(otherClassPeriod))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 3
0
        private void OnLoadDatabase(String excelFileDirectory)
        {
            statusBar.Text = "Opening " + excelFileDirectory;
            var excelApplication = new Microsoft.Office.Interop.Excel.Application();
            var databaseBook     = excelApplication.Workbooks.Add(excelFileDirectory);

            excelApplication.Visible = false;

            // read from row id 3
            // read from column id 2
            // Subject code: AQ203 - Column 2
            // Subject sign: 01, 02 ... Column 3
            // Subject present day: Column 4
            // Subject class start period: Column 5
            // Subject class number of period: Column 6
            // Subject class present room: Column 7
            // Subject name:  Column 11

            var activeWorkSheet = databaseBook.Sheets[1];

            object[,] openSubjectClassData = activeWorkSheet.Range("A3", "L" + activeWorkSheet.UsedRange.Rows.Count.ToString()).Value2;
            databaseBook.Close(false);
            excelApplication.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication);

            database = new Dictionary <string, List <SubjectClass> >();

            statusBar.Text = "Converting format of " + excelFileDirectory;
            int    rowIndex    = openSubjectClassData.GetLowerBound(0);
            int    targetIndex = openSubjectClassData.GetUpperBound(0);
            string prevClassID = "";

            while (rowIndex <= targetIndex)
            {
                List <SubjectClass> subjectCode = null;
                object subjectCell = openSubjectClassData[rowIndex, 7];
                if (subjectCell == null)
                {
                    ++rowIndex;
                    continue;
                }

                database.TryGetValue(openSubjectClassData[rowIndex, 2].ToString(), out subjectCode);

                if (subjectCode == null)
                {
                    subjectCode = new List <SubjectClass>();
                    database.Add(openSubjectClassData[rowIndex, 2].ToString(), subjectCode);
                    prevClassID = "";
                }

                SubjectClass focusSubjectClass = null;
                string       classCode         = openSubjectClassData[rowIndex, 3].ToString();
                if (!prevClassID.Equals(classCode))
                {
                    prevClassID       = classCode;
                    focusSubjectClass = new SubjectClass(openSubjectClassData[rowIndex, 11].ToString(),
                                                         openSubjectClassData[rowIndex, 3].ToString());
                    subjectCode.Add(focusSubjectClass);
                }
                else
                {
                    focusSubjectClass = subjectCode[subjectCode.Count - 1];
                }

                string debug = rowIndex.ToString() + " "
                               + openSubjectClassData[rowIndex, 4].ToString() + " "
                               + openSubjectClassData[rowIndex, 5].ToString() + " "
                               + openSubjectClassData[rowIndex, 6].ToString() + " "
                               + openSubjectClassData[rowIndex, 7].ToString();

                Console.Write(debug);
                try
                {
                    Range tmp;
                    focusSubjectClass.AddRange(tmp = new Range(
                                                   int.Parse(openSubjectClassData[rowIndex, 4].ToString()),
                                                   int.Parse(openSubjectClassData[rowIndex, 5].ToString()),
                                                   int.Parse(openSubjectClassData[rowIndex, 6].ToString()),
                                                   openSubjectClassData[rowIndex, 7].ToString()
                                                   ));
                    //Console.WriteLine(" " + tmp.startPivot.ToString () + " " + tmp.endPivot.ToString ());
                } catch (Exception exception)
                {
                }

                ++rowIndex;
            }

            statusBar.Text = "Imported " + excelFileDirectory;
        }