コード例 #1
0
ファイル: Color.cs プロジェクト: tunglbt/test-scheduler
        public List <ExaminationRoom> getAvailableRooms()
        {
            List <ExaminationRoom> listAvailableRooms = new List <ExaminationRoom>();

            for (int i = 0; i < listRoom.Count(); i++)
            {
                ExaminationRoom room = listRoom.ElementAt(i);
                if (room.Capacity > 0)
                {
                    listAvailableRooms.Add(room);
                }
            }
            return(listAvailableRooms);
        }
コード例 #2
0
        private List <ExaminationRoom> getRoom(int numOfStudents, List <ExaminationRoom> sortedList)
        {
            List <ExaminationRoom> listSelectedRooms = new List <ExaminationRoom>();

            while (numOfStudents > 0)
            {
                int i = binarySearch(sortedList, numOfStudents);
                if (i < 0)
                {
                    i = 0;
                }
                else if (i >= sortedList.Count())
                {
                    i = sortedList.Count() - 1;
                }
                if (i < 0)
                {
                    listSelectedRooms = new List <ExaminationRoom>();
                    break;
                }
                numOfStudents -= sortedList.ElementAt(i).Capacity;
                ExaminationRoom selectedRoom   = sortedList.ElementAt(i);
                string          selectedRoomID = selectedRoom.Id;

                sortedList.RemoveAt(i);

                listSelectedRooms.Add(selectedRoom);

                for (int j = 0; j < sortedList.Count; j++)
                {
                    if (sortedList.ElementAt(j).Id == selectedRoomID)
                    {
                        sortedList.RemoveAt(j);
                        break;
                    }
                }
            }
            return(listSelectedRooms);
        }
コード例 #3
0
        private void btnImportListExamRoom_Click(object sender, EventArgs e)
        {
            progressBar1.Value = 0;

            OpenFileDialog fopenListExamRoom = new OpenFileDialog();

            fopenListExamRoom.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            fopenListExamRoom.ShowDialog();

            if (fopenListExamRoom.FileName != "")
            {
                timer          = new System.Timers.Timer();
                timer.Interval = 1000;
                timer.Enabled  = true;
                timer.Start();
                timer.Elapsed += new ElapsedEventHandler(timer_Tick);

                lstCourseEnroll.Clear();
                // Open Excel file
                Excel.Application app = new Excel.Application();
                Excel.Workbook    wb  = app.Workbooks.Open(fopenListExamRoom.FileName);
                try
                {
                    // Open sheet


                    Excel._Worksheet sheet = wb.Sheets[1];
                    Excel.Range      range = sheet.UsedRange;
                    // Read data
                    int rows = range.Rows.Count;
                    int cols = range.Columns.Count;
                    // Read the first row to make columns in listview
                    List <string> lstColumnName = new List <string>();
                    for (int c = 1; c <= cols; c++)
                    {
                        string       columnName = Convert.ToString(range.Cells[1, c].Value);
                        ColumnHeader col        = new ColumnHeader();
                        col.Text  = columnName;
                        col.Width = 120;
                        lstCourseEnroll.Columns.Add(col);
                        lstColumnName.Add(columnName);
                    }
                    // Import data

                    lstExamRoom = new List <ExaminationRoom>();

                    for (int i = 2; i <= rows; i++)
                    {
                        ListViewItem item     = new ListViewItem();
                        string       id       = null;
                        int          capacity = 0;
                        string       kind     = null;
                        string       note     = null;

                        for (int j = 1; j <= cols; j++)
                        {
                            if (j == 1)
                            {
                                item.Text = Convert.ToString(range.Cells[i, j].Value);

                                //Console.WriteLine(item.Text);
                                id = item.Text;
                            }
                            else
                            {
                                string subItem = Convert.ToString(range.Cells[i, j].Value);
                                item.SubItems.Add(subItem);
                                if (j == lstColumnName.IndexOf("SucChua") + 1)
                                {
                                    capacity = Convert.ToInt32(subItem);
                                }
                                if (j == lstColumnName.IndexOf("TinhChatPhong") + 1)
                                {
                                    kind = subItem;
                                }
                                if (j == lstColumnName.IndexOf("Note") + 1)
                                {
                                    note = subItem;
                                }
                            }
                        }

                        ExaminationRoom room = new ExaminationRoom(id, capacity, kind, note);
                        lstExamRoom.Add(room);


                        lstCourseEnroll.Items.Add(item);
                        //Console.WriteLine(item.Text);
                    }

                    for (int k = 0; k < lstExamRoom.Count; k++)
                    {
                        ExaminationRoom test = lstExamRoom.ElementAt(k);
                        Console.WriteLine(test.Id + " " + test.Capacity + " " + test.Kind + " " + test.Note);
                    }

                    //MessageBox.Show(message1);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                finally
                {
                    app.Quit();
                    wb = null;
                }
            }
            progressBar1.Value = progressBar1.Maximum;
            timer.Stop();
        }