public void atribuireMasinaCoada(int idAngajat) { if (masiniAsteptare.Count != 0) { Masina m = masiniAsteptare.Dequeue(); if (m is MasinaStandard) { atribuireMasina(m, idAngajat, true, false, false); } else if (m is Autobuz) { atribuireMasina(m, idAngajat, false, true, false); } else if (m is Camion) { atribuireMasina(m, idAngajat, false, false, true); } } else { Console.WriteLine("Nicio masina in lista de asteptare!\n\n"); } }
public int atribuireMasina(Masina m, int idAngajat, bool masina, bool autobuz, bool camion) { if (m != null) { int ok = 0; if (masina) { for (int i = 0; i < listaAngajati.Count; i++) { for (int j = 0; j < 3; j++) { if (matriceAtelier[i, j] == 0) { ok = 1; break; } } } } else if (autobuz) { for (int i = 0; i < listaAngajati.Count; i++) { if (matriceAtelier[i, 3] == 0) { ok = 1; break; } } } else if (camion) { for (int i = 0; i < listaAngajati.Count; i++) { if (matriceAtelier[i, 4] == 0) { ok = 1; break; } } } if (ok == 0) { string raspuns = "0"; Console.WriteLine("Niciun angajat disponibil! Alegeti un numar:\n1.Asteapta\n2.Pleaca"); while (raspuns != "1" && raspuns != "2") { raspuns = Console.ReadLine(); if (raspuns != "1" && raspuns != "2") { Console.WriteLine("Raspuns invalid. Reincercati!"); } else if (raspuns == "1") { masiniAsteptare.Enqueue(m); return(1); } else if (raspuns == "2") { return(-1); } } return(-1); } else { if (m.Id <= 0 || idAngajat <= 0 || idAngajat > listaAngajati.Count) { Console.WriteLine("Atribuire imposibila. Revizuiti datele!"); return(-1); } if (masina) { if (matriceAtelier[idAngajat - 1, 0] == 0) { matriceAtelier[idAngajat - 1, 0] = m.Id; return(1); } else if (matriceAtelier[idAngajat - 1, 1] == 0) { matriceAtelier[idAngajat - 1, 1] = m.Id; return(1); } else if (matriceAtelier[idAngajat - 1, 2] == 0) { matriceAtelier[idAngajat - 1, 2] = m.Id; return(1); } else { string raspuns = "0"; Console.WriteLine("Angajat ocupat! Alegeti un numar:/n1.Asteapta/n2.Treci la un angajat liber/n3.Pleaca"); while (raspuns != "1" && raspuns != "2" && raspuns != "3") { raspuns = Console.ReadLine(); if (raspuns != "1" && raspuns != "2" && raspuns != "3") { Console.WriteLine("Raspuns invalid. Reincercati!"); } else if (raspuns == "1") { masiniAsteptare.Enqueue(m); return(-1); } else if (raspuns == "2") { foreach (Angajat a in listaAngajati) { if (matriceAtelier[a.Id - 1, 0] == 0) { matriceAtelier[a.Id - 1, 0] = m.Id; return(1); } else if (matriceAtelier[a.Id - 1, 1] == 0) { matriceAtelier[a.Id - 1, 1] = m.Id; return(1); } else if (matriceAtelier[a.Id - 1, 2] == 0) { matriceAtelier[a.Id - 1, 2] = m.Id; return(1); } else { ; } } } else if (raspuns == "3") { return(-1);; } } return(-1); } } else if (autobuz) { if (matriceAtelier[idAngajat - 1, 3] == 0) { matriceAtelier[idAngajat - 1, 3] = m.Id; return(1); } else { string raspuns = "0"; Console.WriteLine("Angajat ocupat! Alegeti un numar:/n1.Asteapta/n2.Treci la un angajat liber/n3.Pleaca"); while (raspuns != "1" && raspuns != "2" && raspuns != "3") { raspuns = Console.ReadLine(); if (raspuns != "1" && raspuns != "2" && raspuns != "3") { Console.WriteLine("Raspuns invalid. Reincercati!"); } else if (raspuns == "1") { masiniAsteptare.Enqueue(m); return(-1); } else if (raspuns == "2") { foreach (Angajat a in listaAngajati) { if (matriceAtelier[a.Id - 1, 3] == 0) { matriceAtelier[a.Id - 1, 0] = m.Id; return(1); } else { ; } } } else if (raspuns == "3") { return(-1);; } } return(-1); } } else if (camion) { if (matriceAtelier[idAngajat - 1, 4] == 0) { matriceAtelier[idAngajat - 1, 4] = m.Id; return(1); } else { string raspuns = "0"; Console.WriteLine("Angajat ocupat! Alegeti un numar:/n1.Asteapta/n2.Treci la un angajat liber/n3.Pleaca"); while (raspuns != "1" && raspuns != "2" && raspuns != "3") { raspuns = Console.ReadLine(); if (raspuns != "1" && raspuns != "2" && raspuns != "3") { Console.WriteLine("Raspuns invalid. Reincercati!"); } else if (raspuns == "1") { masiniAsteptare.Enqueue(m); return(-1); } else if (raspuns == "2") { foreach (Angajat a in listaAngajati) { if (matriceAtelier[a.Id - 1, 4] == 0) { matriceAtelier[a.Id - 1, 4] = m.Id; return(1); } else { ; } } } else if (raspuns == "3") { return(-1);; } } return(-1); } } else { return(-1); } } } else { return(-1); } }