private GuichesSetup[] CarregarSetup(String path) { System.IO.StreamReader file = new System.IO.StreamReader(path);//busca o arquivo de texto int counter = 0; postos = new char[20]; posto = new int[20]; string line; //cria uma string que recebe as linhas string[] setup; //declara o vetor de setup setup = new string[50]; //declara que setup terá 9 posições while ((line = file.ReadLine()) != null) //laço que le linha por linha { if (counter == 0) { atendente = Convert.ToInt32(line); //MessageBox.Show(Convert.ToString(atendente)); } else if (counter == 1) { var vetor_aux = line.ToCharArray(); postos = new char[20]; int condicional = 0, k = 0; for (int i = 0; i < vetor_aux.Length; i++) { if (vetor_aux[i] == ':') { condicional = 1; } else if (condicional == 1) { postos[k] = vetor_aux[i]; k++; } } //string temp = new string(postos); //MessageBox.Show(temp); } else if (counter == 2) { var vetor_aux = line.ToCharArray(); atendente_pos = new char[20]; int condicional = 0, k = 0; for (int i = 0; i < vetor_aux.Length; i++) { if (vetor_aux[i] == ':') { condicional = 1; } else if (condicional == 1) { atendente_pos[k] = vetor_aux[i]; k++; } } //string temp = new string(atendente_pos); //MessageBox.Show(temp); } else if (counter == 3) { var vetor_aux = line.ToCharArray(); char[] numfinal; numfinal = new char[10]; int condicional = 0, k = 0; for (int i = 0; i < (vetor_aux.Length); i++) { if (condicional == 1) { numfinal[k] = vetor_aux[i]; k++; } else if (vetor_aux[i] == ':') { condicional = 1; } } string temp = new string(numfinal); troca = Convert.ToInt32(temp); //MessageBox.Show(Convert.ToString(troca)); } else if (counter >= 4) { var vetor_aux = line.ToCharArray(); char[] numfinal; numfinal = new char[10]; int k = 0, condicional = 0; for (int i = 0; i < (vetor_aux.Length); i++) { if (vetor_aux[i] == ':') { condicional = 1; } else if (i > 0 && condicional != 1) { numfinal[k] = vetor_aux[i]; k++; } } string temp = new string(numfinal); posto[counter - 4] = Convert.ToInt32(temp); //MessageBox.Show(Convert.ToString(posto[counter-4])); } counter++;//aumenta o contador para ler e armazenar novas linhas até o fim do arquivo(!=null) } //obtendo a quantidade de guiches (metodo provisorio enquanto não arruma a classe) int quantidade = 0; String auxiliar = ""; for (int i = 0; i < 20; i++) { auxiliar += postos[i]; } auxiliar = new String(auxiliar.Where(Char.IsLetter).ToArray()); quantidade = auxiliar.Length; //criando as classes setupguiches GuichesSetup[] guichesSetup; guichesSetup = new GuichesSetup [quantidade]; //setando os guiches int j = 0; char aux = 'x'; //serve para guardar o char do ultimo posto, para comparar com o que vai ser lido atualmente for (int i = 0; i < quantidade; i++) { guichesSetup[i] = new GuichesSetup(); guichesSetup[i].guiche = postos[i]; //simplesmente joga o char do guiche //isso serve para verificar quantos guiches iguais tem, assim o primeiro guiches dos iguais (por exemplo, 3 guiches A's, o primeiro A terá a quantidadeGuiches igual a 3) if (guichesSetup[i].guiche != aux && i != 19) { int k = i + 1; aux = guichesSetup[i].guiche; while (postos[k] == aux) //atualizando a quantidade de guiches iguais (somente no primeiro guiche) { guichesSetup[i].guichesIguais++; k++; if (k > 19) { break; } } } //colocando os atendentes nos devidos guiches if (atendente_pos[j] == guichesSetup[i].guiche) { guichesSetup[i].atendente = true; j++; } if (guichesSetup[i].guiche == 'A') { guichesSetup[i].turnosNecessarios = posto[0]; } if (guichesSetup[i].guiche == 'B') { guichesSetup[i].turnosNecessarios = posto[1]; } if (guichesSetup[i].guiche == 'C') { guichesSetup[i].turnosNecessarios = posto[2]; } if (guichesSetup[i].guiche == 'D') { guichesSetup[i].turnosNecessarios = posto[3]; } if (guichesSetup[i].guiche == 'E') { guichesSetup[i].turnosNecessarios = posto[4]; } if (guichesSetup[i].guiche == 'F') { guichesSetup[i].turnosNecessarios = posto[5]; } if (guichesSetup[i].guiche == 'G') { guichesSetup[i].turnosNecessarios = posto[6]; } if (guichesSetup[i].guiche == 'H') { guichesSetup[i].turnosNecessarios = posto[7]; } if (guichesSetup[i].guiche == 'I') { guichesSetup[i].turnosNecessarios = posto[8]; } if (guichesSetup[i].guiche == 'J') { guichesSetup[i].turnosNecessarios = posto[9]; } if (guichesSetup[i].guiche == 'K') { guichesSetup[i].turnosNecessarios = posto[10]; } if (guichesSetup[i].guiche == 'L') { guichesSetup[i].turnosNecessarios = posto[11]; } if (guichesSetup[i].guiche == 'M') { guichesSetup[i].turnosNecessarios = posto[12]; } } file.Close();//fecha o txt atendentesIniciais = new Boolean [guichesSetup.Length]; for (int k = 0; k < guichesSetup.Length; k++) { atendentesIniciais[k] = guichesSetup[k].atendente; } return(guichesSetup); }
//private System.Windows.Forms.ToolTip[] toolTip; private void entrarGuiches(Pessoas pessoa, GuichesSetup guiche) { guiche.vazio = false; guiche.pessoaDentro = pessoa; }
void processo(Queue <Pessoas>[] fila, String pathFila, GuichesSetup[] guiches, double tempo) { int turno = 1; int guichesDiferentes = GuichesSetup.getGuichesDiferentes(guiches); List <EstatisticaComb> estatisticaPorGuiches = new List <EstatisticaComb>(); Estatistica estatistica = new Estatistica(guichesDiferentes); GuichesSetup.resetGuiches(guiches, atendentesIniciais); System.IO.StreamReader arquivo = new System.IO.StreamReader(pathFila); //carrega a fila String linha = arquivo.ReadLine(); //inicializa lendo a linha linha += ';'; //já adiciona o . no final da linha Boolean continuar = true; //esse laço vai até entrar todas as pessoas nas filas while (continuar) { //lê as pessoas da fila e joga elas na fila do guiche A lerFila(fila[0], turno, ref linha, arquivo, ref continuar); //essa função atualiza se o tempo de troca de um atendente que vai de um guiche a outro já passou atualizarTempoTroca(guiches); //jogando as primeiras pessoas das filas nos guiches atualizarFilas(guiches, fila, estatistica, turno); //atualizando os guiches e jogando as pessoas pras respectivas filas atualizarGuiches(guiches, fila, estatistica, estatisticaPorGuiches, turno); //Verificando se vale a pena fazer trocas if (troca != 0) { realizarTrocas(guiches, fila); } //jogando as primeiras pessoas das filas nos guiches atualizarFilas(guiches, fila, estatistica, turno); //atualizando as barras de progresso atualizarBarrasProgresso(); //atualizando a cor dos botões atualizarCorBotoes(guiches); //Atualizando o label que conta os turnos textoTurno.Text = "Turno: " + turno; Application.DoEvents(); turno = contarTurnos(tempo, turno); } //Atualizando o label que conta os turnos textoTurno.Text = "Turno: " + turno; for (int k = 0; k < textoFila.Length; k++) { if (textoFila[k] != null) { textoFila[k].Text = "" + fila[k].Count; } } // Refresh(); //esse laço vai até esvaziar todos os guiches, assim, terminando continuar = true; while (continuar) { //essa função atualiza se o tempo de troca de um atendente que vai de um guiche a outro já passou atualizarTempoTroca(guiches); //jogando as primeiras pessoas das filas nos guiches atualizarFilas(guiches, fila, estatistica, turno); //atualizando os guiches e jogando as pessoas pras respectivas filas atualizarGuiches(guiches, fila, estatistica, estatisticaPorGuiches, turno); //Verificando se vale a pena fazer trocas if (troca != 0) { realizarTrocas(guiches, fila); } //jogando as primeiras pessoas das filas nos guiches atualizarFilas(guiches, fila, estatistica, turno); //atualizando as barras de progresso atualizarBarrasProgresso(); //atualizando a cor dos botões atualizarCorBotoes(guiches); //testando se todos os guiches estão vazios, se algum não estiver vazio, então continuar se torna verdade continuar = false; for (int j = 0; j < guiches.Length; j++) { if (guiches[j].vazio == false) { continuar = true; } } if (continuar == false && troca != 0) { continuar = condicaoEspecial(guiches, fila); } //Atualizando o label que conta os turnos textoTurno.Text = "Turno: " + turno; textoTurno.Refresh(); // Refresh(); Application.DoEvents(); turno = contarTurnos(tempo, turno); } MessageBox.Show("Turno terminado: " + (turno - 1)); mostrarEstatisticas(estatistica, estatisticaPorGuiches); }