Beispiel #1
0
        private void OneFieldOfRoomForm_Load(object sender, EventArgs e)
        {
            cr = (from c in db.Classroom_Times
                  where ((c.Class_ID == _classId) && (c.Room_ID == _roomKey) && (c.StartTime == _startTime) && (c.Day_No == _dayNo))
                  select c).SingleOrDefault();

            txtProfessor.RightToLeft     = _RightToLeft;
            txtProfessor.Text            = cr.Professor.Name_Professor;
            chkListProfessor.RightToLeft = _RightToLeft;

            var ng = (from g in db.New_GroupsPerClasses
                      where ((g.Class_ID == _classId) && (g.Room_ID == _roomKey) && (g.StartTime == _startTime) && (g.Day_No == _dayNo))
                      select g.Group_ID).ToList();

            var gs = (from g in db.Groups
                      select g).ToList();

            chkGroups.RightToLeft = _RightToLeft;
            int IndexOfList = 0;

            foreach (var g in gs)
            {
                chkGroups.Items.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - {1}   {2}-{3}",
                                                  g.Branch.Branch_Name, g.Branch.Degree, g.Semester_Entry_Year, ((g.Semester_Entry_FS) ? "1" : "2")), ng.Contains(g.ID));
                dicGroups.Add(IndexOfList++, g);
            }
            txtInfo.RightToLeft = _RightToLeft;
            txtInfo.Text        = CurrentCell.Value.ToString();
            //
            // Find any professor for this time slot's
            //
            chkListProfessor.Items.Clear();
            int pI = 0;

            foreach (var p in db.Professors)
            {
                ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
                if (PIC.StartScanner(p.Schedule))
                {
                    if (PIC.CompiledData[_startTime, _dayNo + 1])
                    {
                        Prof.Add(pI++, p);
                        chkListProfessor.Items.Add(p.Name_Professor, (cr.Professor.ID == p.ID));
                    }
                }
            }
            //
        }
Beispiel #2
0
 /// <summary>
 /// Fill DataGridViews by Professor Data
 /// </summary>
 private void FillDGV()
 {
     //
     // Read any Group in _professors list's
     foreach (var p in _professors)
     {
         //
         // set Free Slot BackColors
         ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
         PIC.StartScanner(p.Value.Schedule);
         for (int t = 0; t < 12; t++)
         {
             for (int d = 1; d < 8; d++)
             {
                 dgvList[p.Key][d, t].Style.BackColor = PIC.CompiledData[t, d] ? freeTimeBackColor : Color.White;
             }
         }
         //
         // Find any classroom for this professor
         List <MakeClassSchedule.Classroom_Time> lstClassrooms = p.Value.Classroom_Times.ToList();
         //
         // Read any classroom for this Professor
         foreach (var cr in lstClassrooms)
         {
             //
             // Merge Cells according by classroom Unit (duration)
             ((DataGridViewTextBoxCellEx)dgvList[p.Key][cr.Day_No + 1, cr.StartTime]).RowSpan = cr.Duration;
             //
             // Set cell value's
             dgvList[p.Key][cr.Day_No + 1, cr.StartTime].Value =
                 string.Format(CultureInfo.CurrentCulture,
                               "{0}{3}{1}{3}{2}{3}",
                               cr.Class.Course.Name_Course, // Course Name
                               cr.Class.Course.CourseCode,  // Course Code
                               cr.Room.Name_Room,           // Room Name
                               Environment.NewLine);        // {3} = NewLine = "\n\r"
         }
     }
 }
Beispiel #3
0
        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog save2Excel = new SaveFileDialog();

            save2Excel.Filter     = @"Excel files|*.xls";
            save2Excel.DefaultExt = "ProfessorsSchedule.xls";
            save2Excel.FileName   = "ProfessorsSchedule.xls";
            if (save2Excel.ShowDialog() == DialogResult.OK)
            {
                CheckListCellsTextDataForm CLCTDF = new CheckListCellsTextDataForm();
                //
                // check default items
                CLCTDF.chklstExportCell.Items.Clear();
                CLCTDF.chklstExportCell.Items.Add("Course Code", false);
                CLCTDF.chklstExportCell.Items.Add("Course Name", true);
                CLCTDF.chklstExportCell.Items.Add("Room Name", false);
                //
                CheckedListBox chklstCTD_buffer = CLCTDF.chklstExportCell;
                CLCTDF.Location = new Point(btnExportToExcel.Location.X + this.Location.X + 7,
                                            this.Location.Y + btnExportToExcel.Location.Y + btnExportToExcel.Size.Height + 32);
                CLCTDF.ShowDialog();
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    //
                    // delete exist file's
                    //
                    if (System.IO.File.Exists(save2Excel.FileName))
                    {
                        System.IO.File.Delete(save2Excel.FileName);
                    }
                    //
                    // If using Professional version, put your serial key below. Otherwise, keep following
                    // line commented out as Free version doesn't have SetLicense method.
                    // SpreadsheetInfo.SetLicense("YOUR-SERIAL-KEY-HERE");

                    ExcelFile ef = new ExcelFile();
                    ef.LimitReached += new LimitEventHandler(ef_LimitReached);
                    ef.LimitNear    += new LimitEventHandler(ef_LimitNear);

                    ExcelWorksheet ws          = ef.Worksheets.Add("ProfessorsSchedule");
                    int            numberSheet = 1;
                    int            numberFile  = 1;
                    int            startRow_No = 0;

                    #region Professor Name Style's
                    CellStyle ProfessorTitleStyle = new CellStyle();
                    ProfessorTitleStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    ProfessorTitleStyle.VerticalAlignment   = VerticalAlignmentStyle.Center;
                    ProfessorTitleStyle.Font.Weight         = ExcelFont.BoldWeight;
                    ProfessorTitleStyle.FillPattern.SetSolid(Color.Azure);
                    ProfessorTitleStyle.Font.Color = Color.RoyalBlue;
                    ProfessorTitleStyle.WrapText   = false;
                    ProfessorTitleStyle.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Top, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Header Style's (Example First Professor  Row[2~3] , Column[0~7])
                    CellStyle headerStyle = new CellStyle();
                    headerStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    headerStyle.VerticalAlignment   = VerticalAlignmentStyle.Center;
                    headerStyle.FillPattern.SetSolid(Color.Chocolate);
                    headerStyle.Font.Weight = ExcelFont.BoldWeight;
                    headerStyle.Font.Color  = Color.White;
                    headerStyle.WrapText    = true;
                    headerStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Header Text Data
                    object[,] headerText = new object[1, 8] {
                        {
                            "Time Slot",
                            "Saturday",
                            "Sunday",
                            "Monday",
                            "Tuesday",
                            "Wednesday",
                            "Thursday",
                            "Friday"
                        }
                    };

                    #endregion

                    #region Column width
                    // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                    ws.Columns[0].Width = 16 * 226;
                    ws.Columns[1].Width = 22 * 226;
                    ws.Columns[2].Width = 22 * 226;
                    ws.Columns[3].Width = 22 * 226;
                    ws.Columns[4].Width = 22 * 226;
                    ws.Columns[5].Width = 22 * 226;
                    ws.Columns[6].Width = 22 * 226;
                    ws.Columns[7].Width = 22 * 226;
                    #endregion

                    #region Any Cells Style's
                    CellStyle AnyCellStyle = new CellStyle();
                    AnyCellStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    AnyCellStyle.VerticalAlignment   = VerticalAlignmentStyle.Center;
                    AnyCellStyle.Font.Size           = 14 * 16;
                    AnyCellStyle.Font.Weight         = ExcelFont.BoldWeight;
                    AnyCellStyle.FillPattern.SetSolid(Color.White);
                    AnyCellStyle.Font.Color = Color.Black;
                    AnyCellStyle.WrapText   = true;
                    AnyCellStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Read any Professor in DataGridView and Save in Excel files
                    foreach (var p in _professors)
                    {
checkLoop:
                        if (startRow_No + 16 <= 149) // Write in Exist Worksheet
                        {
                            #region Save in Excel Row by database.Professors
                            //
                            // set Professor Name Style
                            ws.Cells.GetSubrangeAbsolute(0 + startRow_No, 0, 1 + startRow_No, 7).Style = ProfessorTitleStyle;
                            //
                            // set Professor Name text in Title
                            ws.Cells[0 + startRow_No, 0].Value = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                                               "Professor:   {0}   {1}     ,         ID: {2}",
                                                                               p.Value.Name_Professor,
                                                                               string.IsNullOrEmpty(p.Value.Email) ? "" : "Email: " + p.Value.Email,
                                                                               p.Value.ID);
                            //
                            // set Header Styles
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 0, 3 + startRow_No, 7).Style = headerStyle;
                            //
                            // set Header Text data
                            for (int j = 0; j < 8; j++)
                            {
                                ws.Cells[3 + startRow_No, j].Value = headerText[0, j];
                            }
                            //
                            // set Merged Band
                            #region Merged Band
                            //
                            // First Row for Group Name
                            ws.Cells.GetSubrangeAbsolute(0 + startRow_No, 0, 1 + startRow_No, 7).Merged = true;
                            //
                            // Second Row for Group Header "Time Slot"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 0, 3 + startRow_No, 0).Merged = true;
                            //
                            // Second Row for Group Header "Saturday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 1, 3 + startRow_No, 1).Merged = true;
                            //
                            // Second Row for Group Header "Sunday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 2, 3 + startRow_No, 2).Merged = true;
                            //
                            // Second Row for Group Header "Monday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 3, 3 + startRow_No, 3).Merged = true;
                            //
                            // Second Row for Group Header "Tuesday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 4, 3 + startRow_No, 4).Merged = true;
                            //
                            // Second Row for Group Header "Wednesday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 5, 3 + startRow_No, 5).Merged = true;
                            //
                            // Second Row for Group Header "Thursday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 6, 3 + startRow_No, 6).Merged = true;
                            //
                            // Second Row for Group Header "Friday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 7, 3 + startRow_No, 7).Merged = true;
                            #endregion
                            //
                            // set Time Slot Styles
                            for (int row = 4; row < 12 + 4; row++)
                            {
                                ws.Cells[row + startRow_No, 0].Style = headerStyle; // headerStyle is equal by timeSlot Style
                                ws.Cells[row + startRow_No, 0].Value = string.Format("{0} ~ {1}", (row - 4) + 8, (row - 4) + 9);
                            }
                            //
                            // set all cells style's
                            for (int row = 0; row < 12; row++)
                            {
                                for (int column = 1; column < 8; column++)
                                {
                                    ws.Cells[row + startRow_No + 4, column].Style = AnyCellStyle;
                                }
                            }
                            //
                            // read any Classroom_Time for this Professor and save that
                            #region Read and Save Cells by this Professor classrooms data
                            //-------------------------------------------------------------------------------------------------
                            //
                            // Find any classroom for this Professor
                            List <MakeClassSchedule.Classroom_Time> lstClassrooms = p.Value.Classroom_Times.ToList();
                            //
                            // Set Free Time Slot Colors for this Professor
                            ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
                            PIC.StartScanner(p.Value.Schedule);
                            for (int t = 0; t < 12; t++)
                            {
                                for (int d = 1; d < 8; d++)
                                {
                                    if (PIC.CompiledData[t, d])
                                    {
                                        ws.Cells[t + startRow_No + 4, d].Style.FillPattern.SetSolid(freeTimeBackColor);
                                    }
                                }
                            }
                            //
                            // Read any classroom for this Professor
                            foreach (var cr in lstClassrooms)
                            {
                                //
                                // 0. Course Code
                                // 1. Course Name
                                // 2. Room Name
                                string classesValue = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                                                    "{0}{1}{2}",
                                                                    (chklstCTD_buffer.GetItemChecked(1) ? cr.Class.Course.Name_Course + Environment.NewLine : string.Empty),                           // Course Name
                                                                    (chklstCTD_buffer.GetItemChecked(0) ? (cr.Class.Course.CourseCode.HasValue ? cr.Class.Course.CourseCode.Value : 0) + "\r\n" : ""), // Course Code
                                                                    (chklstCTD_buffer.GetItemChecked(2) ? cr.Room.Name_Room : ""));                                                                    // Room Name


                                int row    = cr.StartTime;
                                int column = cr.Day_No + 1;
                                ws.Cells[row + startRow_No + 4, column].Value = classesValue;
                                ws.Cells[row + startRow_No + 4, column].Style.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.DashDotDot);

                                try
                                {
                                    if (cr.Duration > 1)
                                    {
                                        ws.Cells.GetSubrangeAbsolute(row + startRow_No + 4,
                                                                     column,
                                                                     (row + startRow_No + 4) + (cr.Duration - 1),
                                                                     column).Merged = true;
                                    }
                                }
                                catch { } // maybe two class overlap in a cell

                                for (int d = 0; d < cr.Duration; d++)
                                {
                                    ws.Rows[row + startRow_No + 4 + d].AutoFit();
                                }
                                // ws.Rows[row + startRow_No + 4 + d].Height = 10 * 256;
                            }

                            //--------------------------------------------------------------------------------------------------
                            #endregion
                            //
                            // set to next step (add (2_Title + 2_Headers + 12_Row + 2_SpaceRow) = 18 step to start row)
                            startRow_No += 18;
                            #endregion
                        }
                        else if (numberSheet > 5) // Go to Next File's
                        {
                            #region Save and open New Excel file's
                            try
                            {
                                //
                                // Save in File *.xls
                                //
                                numberFile++;
                                string NextFile = save2Excel.FileName.Substring(0, save2Excel.FileName.Length - 5) +
                                                  numberFile.ToString() + ".xls";
                                ef.SaveXls(NextFile);
                                ef = new ExcelFile();
                                ef.LimitReached += new LimitEventHandler(ef_LimitReached);
                                ef.LimitNear    += new LimitEventHandler(ef_LimitNear);
                                ws = ef.Worksheets.Add("ProfessorsSchedule");
                                //
                                // Try to open created excel file's
                                //
                                System.Diagnostics.Process.Start(NextFile);
                            }
                            finally
                            {
                                numberSheet = 1;
                                startRow_No = 0;
                                #region Column width
                                // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                                ws.Columns[0].Width = 16 * 226;
                                ws.Columns[1].Width = 22 * 226;
                                ws.Columns[2].Width = 22 * 226;
                                ws.Columns[3].Width = 22 * 226;
                                ws.Columns[4].Width = 22 * 226;
                                ws.Columns[5].Width = 22 * 226;
                                ws.Columns[6].Width = 22 * 226;
                                ws.Columns[7].Width = 22 * 226;
                                #endregion
                            }
                            goto checkLoop;
                            #endregion
                        }
                        else // 150 row is complete go to next worksheet
                        {
                            #region Create New WorkSheet
                            startRow_No = 0;
                            numberSheet++;
                            ws = ef.Worksheets.Add("ProfessorsSchedule (" + numberSheet.ToString() + ")");
                            //
                            // set column width again
                            #region Column width
                            // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                            ws.Columns[0].Width = 16 * 226;
                            ws.Columns[1].Width = 22 * 226;
                            ws.Columns[2].Width = 22 * 226;
                            ws.Columns[3].Width = 22 * 226;
                            ws.Columns[4].Width = 22 * 226;
                            ws.Columns[5].Width = 22 * 226;
                            ws.Columns[6].Width = 22 * 226;
                            ws.Columns[7].Width = 22 * 226;
                            #endregion
                            //
                            // go to check again
                            goto checkLoop;
                            #endregion
                        }
                    }
                    #endregion

                    #region Save and open Excel file's
                    try
                    {
                        //
                        // Save in File *.xls
                        //
                        string NextFile;
                        if (numberFile <= 1)
                        {
                            NextFile = save2Excel.FileName;
                        }
                        else
                        {
                            NextFile = save2Excel.FileName.Substring(0, save2Excel.FileName.Length - 5) +
                                       numberFile.ToString() + ".xls";
                        }
                        ef.SaveXls(NextFile);
                        //
                        // Try to open created excel file's
                        //
                        System.Diagnostics.Process.Start(NextFile);
                    }
                    catch
                    { }
                    #endregion
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
Beispiel #4
0
        // Parse file and store parsed object
        public void ParseFile(LINQDataContext db)
        {
            // clear previously parsed objects
            _professors.Clear();
            _studentGroups.Clear();
            _courses.Clear();
            _rooms.Clear();
            _courseClasses.Clear();

            Room.RestartIDs();
            //
            // Save Professor Data
            //
            foreach (var any in db.Professors)
            {
                ProfessorInfoCompiler pIc = new ProfessorInfoCompiler();
                Professor             p;
                if (pIc.StartScanner(any.Schedule))
                {
                    p = new Professor(any.ID, any.Name_Professor, pIc.CompiledData);
                    _professors.Add(p.GetId, p);
                }
            }
            //
            // Save StudentsGroup Data
            //
            foreach (var any in db.Groups)
            {
                StudentsGroup sg;
                string        sg_name = string.Format(CultureInfo.CurrentCulture, "{0}  {1}  {2}-{3}", any.Branch.Degree,
                                                      any.Branch.Branch_Name, any.Semester_Entry_Year, (any.Semester_Entry_FS) ? "1" : "2");
                sg = new StudentsGroup(any.ID, sg_name, any.Size_No);
                _studentGroups.Add(sg.GetId, sg);
            }
            //
            // Save Course Data
            //
            foreach (var any in db.Courses)
            {
                Course c;
                c = new Course(any.Course_ID, any.Name_Course);
                _courses.Add(c.GetId, c);
            }
            //
            // Save Room Data
            //
            foreach (var any in db.Rooms)
            {
                Room r;
                r = new Room(any.Room_ID, any.Name_Room, any.Type_Room, any.Size_No);
                _rooms.Add(r.GetId, r);
            }
            //
            // Save CourseClass Data -----------------------------------------------------------------------------
            //
            foreach (var any in db.Classes)
            {
                //
                // set Professor by best priority
                //
                var prof = (from p1 in db.Priority_Professors
                            join p2 in db.Professors on p1.Professor_ID equals p2.ID
                            where (p1.Class_ID == any.Class_ID)
                            orderby p1.Priority
                            select new
                {
                    p1.Professor_ID,
                    p2.Name_Professor,
                    p2.Schedule
                }).ToArray()[0];
                ProfessorInfoCompiler pIc = new ProfessorInfoCompiler();
                Professor             p   = (pIc.StartScanner(prof.Schedule)) ?
                                            new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData) :
                                            new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData);
                //
                // set selected course for class
                //
                Course c = new Course(any.Course_ID, any.Course.Name_Course);
                //
                // set StudentsGroup in List
                //
                List <StudentsGroup> g = new List <StudentsGroup>();
                foreach (var lstGroup in (from gil in db.Group_ID_Lists
                                          join groups in db.Groups on gil.Group_ID equals groups.ID
                                          where gil.Class_ID == any.Class_ID
                                          select new
                {
                    gil.Group_ID,
                    groups.Size_No,
                    sg_name = string.Format(CultureInfo.CurrentCulture, "{0}  {1}  {2}-{3}",
                                            groups.Branch.Degree,
                                            groups.Branch.Branch_Name,
                                            groups.Semester_Entry_Year,
                                            (groups.Semester_Entry_FS) ? "1" : "2")
                }))
                {
                    StudentsGroup sg = new StudentsGroup(lstGroup.Group_ID, lstGroup.sg_name, lstGroup.Size_No);
                    g.Add(sg);
                }
                //
                // save class by created data
                //
                CourseClass cc = new CourseClass(p, c, g, any.RoomType, (any.Practical_unit + any.Theory_unit), any.Class_ID);
                _courseClasses.Add(cc);
            }
            //----------------------------------------------------------------------------------------------------------------
            //
            db.Dispose();
            _isEmpty = false;
        }
        private void OneFieldOfRoomForm_Load(object sender, EventArgs e)
        {
            cr = (from c in db.Classroom_Times
                  where ((c.Class_ID == _classId) && (c.Room_ID == _roomKey) && (c.StartTime == _startTime) && (c.Day_No == _dayNo))
                  select c).SingleOrDefault();

            txtProfessor.RightToLeft = _RightToLeft;
            txtProfessor.Text = cr.Professor.Name_Professor;
            chkListProfessor.RightToLeft = _RightToLeft;

            var ng = (from g in db.New_GroupsPerClasses
                      where ((g.Class_ID == _classId) && (g.Room_ID == _roomKey) && (g.StartTime == _startTime) && (g.Day_No == _dayNo))
                      select g.Group_ID).ToList();

            var gs = (from g in db.Groups
                      select g).ToList();

            chkGroups.RightToLeft = _RightToLeft;
            int IndexOfList = 0;
            foreach (var g in gs)
            {
                chkGroups.Items.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0} - {1}   {2}-{3}",
                    g.Branch.Branch_Name, g.Branch.Degree, g.Semester_Entry_Year, ((g.Semester_Entry_FS) ? "1" : "2")), ng.Contains(g.ID));
                dicGroups.Add(IndexOfList++, g);
            }
            txtInfo.RightToLeft = _RightToLeft;
            txtInfo.Text = CurrentCell.Value.ToString();
            //
            // Find any professor for this time slot's
            //
            chkListProfessor.Items.Clear();
            int pI = 0;
            foreach (var p in db.Professors)
            {
                ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
                if (PIC.StartScanner(p.Schedule))
                {
                    if (PIC.CompiledData[_startTime, _dayNo + 1])
                    {
                        Prof.Add(pI++, p);
                        chkListProfessor.Items.Add(p.Name_Professor, (cr.Professor.ID == p.ID));
                    }
                }
            }
            //
        }
        // Parse file and store parsed object
        public void ParseFile(LINQDataContext db)
        {
            // clear previously parsed objects
            _professors.Clear();
            _studentGroups.Clear();
            _courses.Clear();
            _rooms.Clear();
            _courseClasses.Clear();

            Room.RestartIDs();
            //
            // Save Professor Data
            //
            foreach (var any in db.Professors)
            {
                ProfessorInfoCompiler pIc = new ProfessorInfoCompiler();
                Professor p;
                if (pIc.StartScanner(any.Schedule))
                {
                    p = new Professor(any.ID, any.Name_Professor, pIc.CompiledData);
                    _professors.Add(p.GetId, p);
                }
            }
            //
            // Save StudentsGroup Data
            //
            foreach (var any in db.Groups)
            {
                StudentsGroup sg;
                string sg_name = string.Format(CultureInfo.CurrentCulture, "{0}  {1}  {2}-{3}", any.Branch.Degree,
                    any.Branch.Branch_Name, any.Semester_Entry_Year, (any.Semester_Entry_FS) ? "1" : "2");
                sg = new StudentsGroup(any.ID, sg_name, any.Size_No);
                _studentGroups.Add(sg.GetId, sg);
            }
            //
            // Save Course Data
            //
            foreach (var any in db.Courses)
            {
                Course c;
                c = new Course(any.Course_ID, any.Name_Course);
                _courses.Add(c.GetId, c);
            }
            //
            // Save Room Data
            //
            foreach (var any in db.Rooms)
            {
                Room r;
                r = new Room(any.Room_ID, any.Name_Room, any.Type_Room, any.Size_No);
                _rooms.Add(r.GetId, r);
            }
            //
            // Save CourseClass Data -----------------------------------------------------------------------------
            //
            foreach (var any in db.Classes)
            {
                //
                // set Professor by best priority
                //
                var prof = (from p1 in db.Priority_Professors
                            join p2 in db.Professors on p1.Professor_ID equals p2.ID
                            where (p1.Class_ID == any.Class_ID)
                            orderby p1.Priority
                            select new
                            {
                                p1.Professor_ID,
                                p2.Name_Professor,
                                p2.Schedule
                            }).ToArray()[0];
                ProfessorInfoCompiler pIc = new ProfessorInfoCompiler();
                Professor p = (pIc.StartScanner(prof.Schedule)) ?
                    new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData) :
                    new Professor(prof.Professor_ID, prof.Name_Professor, pIc.CompiledData);
                //
                // set selected course for class
                //
                Course c = new Course(any.Course_ID, any.Course.Name_Course);
                //
                // set StudentsGroup in List
                //
                List<StudentsGroup> g = new List<StudentsGroup>();
                foreach (var lstGroup in (from gil in db.Group_ID_Lists
                                          join groups in db.Groups on gil.Group_ID equals groups.ID
                                          where gil.Class_ID == any.Class_ID
                                          select new
                                          {
                                              gil.Group_ID,
                                              groups.Size_No,
                                              sg_name = string.Format(CultureInfo.CurrentCulture, "{0}  {1}  {2}-{3}",
                                                                                                 groups.Branch.Degree,
                                                                                                 groups.Branch.Branch_Name,
                                                                                                 groups.Semester_Entry_Year,
                                                                                                 (groups.Semester_Entry_FS) ? "1" : "2")
                                          }))
                {
                    StudentsGroup sg = new StudentsGroup(lstGroup.Group_ID, lstGroup.sg_name, lstGroup.Size_No);
                    g.Add(sg);
                }
                //
                // save class by created data
                //
                CourseClass cc = new CourseClass(p, c, g, any.RoomType, (any.Practical_unit + any.Theory_unit), any.Class_ID);
                _courseClasses.Add(cc);
            }
            //----------------------------------------------------------------------------------------------------------------
            //
            db.Dispose();
            _isEmpty = false;
        }
        private void btnExportToExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog save2Excel = new SaveFileDialog();
            save2Excel.Filter = @"Excel files|*.xls";
            save2Excel.DefaultExt = "ProfessorsSchedule.xls";
            save2Excel.FileName = "ProfessorsSchedule.xls";
            if (save2Excel.ShowDialog() == DialogResult.OK)
            {
                CheckListCellsTextDataForm CLCTDF = new CheckListCellsTextDataForm();
                //
                // check default items
                CLCTDF.chklstExportCell.Items.Clear();
                CLCTDF.chklstExportCell.Items.Add("Course Code", false);
                CLCTDF.chklstExportCell.Items.Add("Course Name", true);
                CLCTDF.chklstExportCell.Items.Add("Room Name", false);
                //
                CheckedListBox chklstCTD_buffer = CLCTDF.chklstExportCell;
                CLCTDF.Location = new Point(btnExportToExcel.Location.X + this.Location.X + 7,
                    this.Location.Y + btnExportToExcel.Location.Y + btnExportToExcel.Size.Height + 32);
                CLCTDF.ShowDialog();
                this.Cursor = Cursors.WaitCursor;
                try
                {
                    //
                    // delete exist file's
                    //
                    if (System.IO.File.Exists(save2Excel.FileName))
                        System.IO.File.Delete(save2Excel.FileName);
                    //
                    // If using Professional version, put your serial key below. Otherwise, keep following
                    // line commented out as Free version doesn't have SetLicense method.
                    // SpreadsheetInfo.SetLicense("YOUR-SERIAL-KEY-HERE");

                    ExcelFile ef = new ExcelFile();
                    ef.LimitReached += new LimitEventHandler(ef_LimitReached);
                    ef.LimitNear += new LimitEventHandler(ef_LimitNear);

                    ExcelWorksheet ws = ef.Worksheets.Add("ProfessorsSchedule");
                    int numberSheet = 1;
                    int numberFile = 1;
                    int startRow_No = 0;

                    #region Professor Name Style's
                    CellStyle ProfessorTitleStyle = new CellStyle();
                    ProfessorTitleStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    ProfessorTitleStyle.VerticalAlignment = VerticalAlignmentStyle.Center;
                    ProfessorTitleStyle.Font.Weight = ExcelFont.BoldWeight;
                    ProfessorTitleStyle.FillPattern.SetSolid(Color.Azure);
                    ProfessorTitleStyle.Font.Color = Color.RoyalBlue;
                    ProfessorTitleStyle.WrapText = false;
                    ProfessorTitleStyle.Borders.SetBorders(MultipleBorders.Right | MultipleBorders.Top, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Header Style's (Example First Professor  Row[2~3] , Column[0~7])
                    CellStyle headerStyle = new CellStyle();
                    headerStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    headerStyle.VerticalAlignment = VerticalAlignmentStyle.Center;
                    headerStyle.FillPattern.SetSolid(Color.Chocolate);
                    headerStyle.Font.Weight = ExcelFont.BoldWeight;
                    headerStyle.Font.Color = Color.White;
                    headerStyle.WrapText = true;
                    headerStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Header Text Data
                    object[,] headerText = new object[1, 8] {                                           
                                                            {
                                                                "Time Slot",
                                                                "Saturday", 
                                                                "Sunday", 
                                                                "Monday", 
                                                                "Tuesday", 
                                                                "Wednesday", 
                                                                "Thursday", 
                                                                "Friday"
                                                            }
                                                            };

                    #endregion

                    #region Column width
                    // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                    ws.Columns[0].Width = 16 * 226;
                    ws.Columns[1].Width = 22 * 226;
                    ws.Columns[2].Width = 22 * 226;
                    ws.Columns[3].Width = 22 * 226;
                    ws.Columns[4].Width = 22 * 226;
                    ws.Columns[5].Width = 22 * 226;
                    ws.Columns[6].Width = 22 * 226;
                    ws.Columns[7].Width = 22 * 226;
                    #endregion

                    #region Any Cells Style's
                    CellStyle AnyCellStyle = new CellStyle();
                    AnyCellStyle.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    AnyCellStyle.VerticalAlignment = VerticalAlignmentStyle.Center;
                    AnyCellStyle.Font.Size = 14 * 16;
                    AnyCellStyle.Font.Weight = ExcelFont.BoldWeight;
                    AnyCellStyle.FillPattern.SetSolid(Color.White);
                    AnyCellStyle.Font.Color = Color.Black;
                    AnyCellStyle.WrapText = true;
                    AnyCellStyle.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.Thin);
                    #endregion

                    #region Read any Professor in DataGridView and Save in Excel files
                    foreach (var p in _professors)
                    {
                    checkLoop:
                        if (startRow_No + 16 <= 149) // Write in Exist Worksheet
                        {
                            #region Save in Excel Row by database.Professors
                            //
                            // set Professor Name Style
                            ws.Cells.GetSubrangeAbsolute(0 + startRow_No, 0, 1 + startRow_No, 7).Style = ProfessorTitleStyle;
                            //
                            // set Professor Name text in Title
                            ws.Cells[0 + startRow_No, 0].Value = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                      "Professor:   {0}   {1}     ,         ID: {2}",
                                      p.Value.Name_Professor,
                                      string.IsNullOrEmpty(p.Value.Email) ? "" : "Email: " + p.Value.Email,
                                      p.Value.ID);
                            //
                            // set Header Styles
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 0, 3 + startRow_No, 7).Style = headerStyle;
                            //
                            // set Header Text data
                            for (int j = 0; j < 8; j++)
                                ws.Cells[3 + startRow_No, j].Value = headerText[0, j];
                            //
                            // set Merged Band
                            #region Merged Band
                            //
                            // First Row for Group Name
                            ws.Cells.GetSubrangeAbsolute(0 + startRow_No, 0, 1 + startRow_No, 7).Merged = true;
                            //
                            // Second Row for Group Header "Time Slot"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 0, 3 + startRow_No, 0).Merged = true;
                            //
                            // Second Row for Group Header "Saturday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 1, 3 + startRow_No, 1).Merged = true;
                            //
                            // Second Row for Group Header "Sunday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 2, 3 + startRow_No, 2).Merged = true;
                            //
                            // Second Row for Group Header "Monday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 3, 3 + startRow_No, 3).Merged = true;
                            //
                            // Second Row for Group Header "Tuesday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 4, 3 + startRow_No, 4).Merged = true;
                            //
                            // Second Row for Group Header "Wednesday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 5, 3 + startRow_No, 5).Merged = true;
                            //
                            // Second Row for Group Header "Thursday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 6, 3 + startRow_No, 6).Merged = true;
                            //
                            // Second Row for Group Header "Friday"
                            ws.Cells.GetSubrangeAbsolute(2 + startRow_No, 7, 3 + startRow_No, 7).Merged = true;
                            #endregion
                            //
                            // set Time Slot Styles
                            for (int row = 4; row < 12 + 4; row++)
                            {
                                ws.Cells[row + startRow_No, 0].Style = headerStyle; // headerStyle is equal by timeSlot Style
                                ws.Cells[row + startRow_No, 0].Value = string.Format("{0} ~ {1}", (row - 4) + 8, (row - 4) + 9);
                            }
                            //
                            // set all cells style's
                            for (int row = 0; row < 12; row++)
                                for (int column = 1; column < 8; column++)
                                {
                                    ws.Cells[row + startRow_No + 4, column].Style = AnyCellStyle;
                                }
                            //
                            // read any Classroom_Time for this Professor and save that
                            #region Read and Save Cells by this Professor classrooms data
                            //-------------------------------------------------------------------------------------------------
                            //
                            // Find any classroom for this Professor
                            List<MakeClassSchedule.Classroom_Time> lstClassrooms = p.Value.Classroom_Times.ToList();
                            //
                            // Set Free Time Slot Colors for this Professor
                            ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
                            PIC.StartScanner(p.Value.Schedule);
                            for (int t = 0; t < 12; t++)
                                for (int d = 1; d < 8; d++)
                                {
                                    if (PIC.CompiledData[t, d])
                                        ws.Cells[t + startRow_No + 4, d].Style.FillPattern.SetSolid(freeTimeBackColor);
                                }
                            //            
                            // Read any classroom for this Professor
                            foreach (var cr in lstClassrooms)
                            {
                                //
                                // 0. Course Code
                                // 1. Course Name
                                // 2. Room Name
                                string classesValue = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                    "{0}{1}{2}",
                                    (chklstCTD_buffer.GetItemChecked(1) ? cr.Class.Course.Name_Course + Environment.NewLine : string.Empty), // Course Name
                                    (chklstCTD_buffer.GetItemChecked(0) ? (cr.Class.Course.CourseCode.HasValue ? cr.Class.Course.CourseCode.Value : 0) + "\r\n" : ""), // Course Code
                                    (chklstCTD_buffer.GetItemChecked(2) ? cr.Room.Name_Room : "")); // Room Name 


                                int row = cr.StartTime;
                                int column = cr.Day_No + 1;
                                ws.Cells[row + startRow_No + 4, column].Value = classesValue;
                                ws.Cells[row + startRow_No + 4, column].Style.Borders.SetBorders(MultipleBorders.Outside, Color.Black, LineStyle.DashDotDot);

                                try
                                {
                                    if (cr.Duration > 1)
                                        ws.Cells.GetSubrangeAbsolute(row + startRow_No + 4,
                                                                     column,
                                                                     (row + startRow_No + 4) + (cr.Duration - 1),
                                                                     column).Merged = true;
                                }
                                catch { } // maybe two class overlap in a cell

                                for (int d = 0; d < cr.Duration; d++)
                                    ws.Rows[row + startRow_No + 4 + d].AutoFit();
                                // ws.Rows[row + startRow_No + 4 + d].Height = 10 * 256;
                            }

                            //--------------------------------------------------------------------------------------------------
                            #endregion
                            //
                            // set to next step (add (2_Title + 2_Headers + 12_Row + 2_SpaceRow) = 18 step to start row)
                            startRow_No += 18;
                            #endregion
                        }
                        else if (numberSheet > 5) // Go to Next File's
                        {
                            #region Save and open New Excel file's
                            try
                            {
                                //
                                // Save in File *.xls
                                //
                                numberFile++;
                                string NextFile = save2Excel.FileName.Substring(0, save2Excel.FileName.Length - 5) +
                                                                             numberFile.ToString() + ".xls";
                                ef.SaveXls(NextFile);
                                ef = new ExcelFile();
                                ef.LimitReached += new LimitEventHandler(ef_LimitReached);
                                ef.LimitNear += new LimitEventHandler(ef_LimitNear);
                                ws = ef.Worksheets.Add("ProfessorsSchedule");
                                //
                                // Try to open created excel file's
                                //
                                System.Diagnostics.Process.Start(NextFile);
                            }
                            finally
                            {
                                numberSheet = 1;
                                startRow_No = 0;
                                #region Column width
                                // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                                ws.Columns[0].Width = 16 * 226;
                                ws.Columns[1].Width = 22 * 226;
                                ws.Columns[2].Width = 22 * 226;
                                ws.Columns[3].Width = 22 * 226;
                                ws.Columns[4].Width = 22 * 226;
                                ws.Columns[5].Width = 22 * 226;
                                ws.Columns[6].Width = 22 * 226;
                                ws.Columns[7].Width = 22 * 226;
                                #endregion
                            }
                            goto checkLoop;
                            #endregion
                        }
                        else // 150 row is complete go to next worksheet
                        {
                            #region Create New WorkSheet
                            startRow_No = 0;
                            numberSheet++;
                            ws = ef.Worksheets.Add("ProfessorsSchedule (" + numberSheet.ToString() + ")");
                            //
                            // set column width again
                            #region Column width
                            // Column width of 16, 22, 22, 22, 22, 22, 22, 22 characters.
                            ws.Columns[0].Width = 16 * 226;
                            ws.Columns[1].Width = 22 * 226;
                            ws.Columns[2].Width = 22 * 226;
                            ws.Columns[3].Width = 22 * 226;
                            ws.Columns[4].Width = 22 * 226;
                            ws.Columns[5].Width = 22 * 226;
                            ws.Columns[6].Width = 22 * 226;
                            ws.Columns[7].Width = 22 * 226;
                            #endregion
                            //
                            // go to check again
                            goto checkLoop;
                            #endregion
                        }
                    }
                    #endregion

                    #region Save and open Excel file's
                    try
                    {
                        //
                        // Save in File *.xls
                        //
                        string NextFile;
                        if (numberFile <= 1)
                            NextFile = save2Excel.FileName;
                        else
                        {
                            NextFile = save2Excel.FileName.Substring(0, save2Excel.FileName.Length - 5) +
                                                                          numberFile.ToString() + ".xls";
                        }
                        ef.SaveXls(NextFile);
                        //
                        // Try to open created excel file's
                        //
                        System.Diagnostics.Process.Start(NextFile);
                    }
                    catch
                    { }
                    #endregion
                }
                catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); }
                finally
                {
                    this.Cursor = Cursors.Default;
                }
            }
        }
 /// <summary>
 /// Fill DataGridViews by Professor Data
 /// </summary>
 private void FillDGV()
 {
     //
     // Read any Group in _professors list's
     foreach (var p in _professors)
     {
         //
         // set Free Slot BackColors
         ProfessorInfoCompiler PIC = new ProfessorInfoCompiler();
         PIC.StartScanner(p.Value.Schedule);
         for (int t = 0; t < 12; t++)
             for (int d = 1; d < 8; d++)
             {
                 dgvList[p.Key][d, t].Style.BackColor = PIC.CompiledData[t, d] ? freeTimeBackColor : Color.White;
             }
         //
         // Find any classroom for this professor
         List<MakeClassSchedule.Classroom_Time> lstClassrooms = p.Value.Classroom_Times.ToList();
         //
         // Read any classroom for this Professor
         foreach (var cr in lstClassrooms)
         {
             //
             // Merge Cells according by classroom Unit (duration)
             ((DataGridViewTextBoxCellEx)dgvList[p.Key][cr.Day_No + 1, cr.StartTime]).RowSpan = cr.Duration;
             //
             // Set cell value's
             dgvList[p.Key][cr.Day_No + 1, cr.StartTime].Value =
                 string.Format(CultureInfo.CurrentCulture,
                     "{0}{3}{1}{3}{2}{3}",
                     cr.Class.Course.Name_Course, // Course Name
                     cr.Class.Course.CourseCode,  // Course Code
                     cr.Room.Name_Room,          // Room Name
                     Environment.NewLine);   // {3} = NewLine = "\n\r"
         }
     }
 }