//return a list of computers public List <Computer> getComputers(Lab l) { List <Computer> computers = new List <Computer>(); int cID = 0; string cType = ""; bool cStatus = true; int cLID = 0; string query = "select * from computers"; if (OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cID = reader.GetInt32(0); cType = reader.GetString(1); if (reader.GetInt32(2) == 1) { cStatus = true; } else { cStatus = false; } cLID = reader.GetInt32(3); if (cLID == l.getLabID()) { Computer aComputer = new Computer(cID, cType, cStatus, cLID); computers.Add(aComputer); } } } CloseConnection(); return(computers); }
public void refreshDisplay(Lab selectedLab) { ConnectDB db = new ConnectDB(); label1.Text = selectedLab.getLabName().ToUpper(); List <Button> computersList = this.panel1.Controls.OfType <Button>().ToList(); List <Computer> computerList = db.getComputers(selectedLab); computersList.Reverse(); //setup computers ========================================================================= foreach (Button b in computersList) { b.Hide(); } for (int i = 0; i < selectedLab.getCapacity(); i++) { computersList.ElementAt(i).Show(); computersList.ElementAt(i).Text = computerList.ElementAt(i).getComputerID().ToString(); if (computerList.ElementAt(i).getCompStatus()) { computersList.ElementAt(i).BackColor = Color.Green; } else { computersList.ElementAt(i).BackColor = Color.Red; } } //========================================================================================== //setup detail information ================================================================= capacityBox.Text = selectedLab.getCapacity().ToString() + " computers are in this lab"; if (selectedLab.getPrinter()) { printerBox.Text = "Printer is available"; } else { printerBox.Text = "No printer is in this lab"; } if (selectedLab.getProjector()) { projectorBox.Text = "Projector is available"; } else { projectorBox.Text = "No projector is in this lab"; } if (selectedLab.getAvailableComp() > 1) { availableC.Text = selectedLab.getAvailableComp().ToString() + " computers are available"; } else { availableC.Text = selectedLab.getAvailableComp().ToString() + " computer is available"; } //============================================================================================ //setup schedule scheduleBox.Clear(); string[] s; s = selectedL.getSchedule().Split(','); foreach (string ss in s) { scheduleBox.AppendText(ss + "\n"); } }
//return a list of labs public List <Lab> getLabs() { List <Lab> labs = new List <Lab>(); int labid = 0; string name = ""; bool proj = true; bool printer = true; string sche = ""; bool status = true; int capacity = 0; string query = "select * from labs"; if (OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { labid = reader.GetInt32(0); name = reader.GetString(1); if (reader.GetInt32(2) == 1) { proj = true; } else { proj = false; } if (reader.GetInt32(3) == 1) { printer = true; } else { printer = false; } sche = reader.GetString(4); if (reader.GetInt32(5) == 1) { status = true; } else { status = false; } capacity = reader.GetInt32(6); Lab aLab = new Lab(labid, name, proj, printer, status, sche, capacity); labs.Add(aLab); } } foreach (Lab l in labs) { l.setAvailableComp(GetAvailableComp(l.getLabID())); } return(labs); }
public LabDetail(Lab sL) { InitializeComponent(); selectedL = sL; refreshDisplay(selectedL); }