Ejemplo n.º 1
0
 /// <summary>
 /// Evento Clik - Reinicia Ou Inicia Todo form
 /// </summary>
 /// <param name="sender">object</param>
 /// <param name="e">event</param>
 private void BtnReiniciar_Click(object sender, EventArgs e)
 {
     Inicializar();
     MonteGrids();
     btnIniciar.Visible = true;
     btnLimpar.Visible  = true;
     btnGerarVetorDAutomaticamente.Visible = true;
     btnGerarVetorDAutomaticamente.Visible = true;
     Parametros = null;
     gerouErro  = false;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Popula a grid com um objeto deadlockparams  passado por parametro
        /// </summary>
        /// <param name="lockParams">Objeto DeadLockParams</param>
        private void PopuleGrids(DeadLockParams lockParams)
        {
            for (int i = 0; i < decimal.Parse(numeroDeColuna); ++i)
            {
                gridVetor_E.Rows[0].Cells[i].Value = lockParams.Vetor_E[i];

                gridVetor_D.Rows[0].Cells[i].Value = lockParams.Vetor_D[i];
            }

            for (int i = 0; i < decimal.Parse(numeroDeColuna); ++i)
            {
                for (int j = 0; j < decimal.Parse(numeroDeLinha); ++j)
                {
                    gridMatriz_C.Rows[i].Cells[j].Value = lockParams.Matriz_C[i, j];
                    gridMatriz_R.Rows[i].Cells[j].Value = lockParams.Matriz_R[i, j];
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Vai para o promixo passo se possivel
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">event</param>
        private void BtnProximoPasso_Click(object sender, EventArgs e)
        {
            try
            {
                Parametros.QtdLinha  = decimal.Parse(numeroDeLinha);
                Parametros.QtdColuna = decimal.Parse(numeroDeColuna);
                if (Parametros == null)
                {
                    throw new Exception("O estado não é seguro e os processos foram finalizados!");
                }

                var objDeadLock = new DeadLock(Parametros);
                Parametros = objDeadLock.Execute();

                if (Parametros == null)
                {
                    throw new Exception("Erro - DeadLock - A quantidade necessaria para a execução do processo é maior que a quantidade disponivel!");
                }

                MessageBox.Show(objDeadLock.DescricaoExecucao,
                                Program.TitleProgram, MessageBoxButtons.OK, MessageBoxIcon.Information);
                PopuleGrids();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                Program.TitleProgram,
                                MessageBoxButtons.OK,
                                ex.Message.Contains("DeadLock")
                                    ?MessageBoxIcon.Error
                                    :MessageBoxIcon.Warning);
                btnProximoPasso.Visible = false;
                btnIniciar.Visible      = true;
                btnLimpar.Visible       = true;
                btnGerarVetorDAutomaticamente.Visible = true;
                BloqueiGrids();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inicia as configurações
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnIniciar_Click(object sender, EventArgs e)
        {
            try
            {
                BtnGerarVetorDAutomaticamente_Click(null, null);
                if (gerouErro)
                {
                    gerouErro = false;
                    return;
                }
                gerouErro = false;
                if (string.IsNullOrEmpty(numeroDeColuna) || string.IsNullOrEmpty(numeroDeLinha))
                {
                    throw new Exception("Deve se iniciar a quatidade de Processos e recursos!");
                }
                int qtdLinha  = int.Parse(numeroDeLinha);
                int qtdColuna = int.Parse(numeroDeColuna);

                Parametros = new DeadLockParams()
                {
                    Vetor_E  = new decimal[qtdColuna],
                    Vetor_D  = new decimal[qtdColuna],
                    Matriz_C = new decimal[qtdLinha, qtdColuna],
                    Matriz_R = new decimal[qtdLinha, qtdColuna]
                };

                //apenas os vetores
                for (int i = 0; i < int.Parse(numeroDeColuna); ++i)
                {
                    decimal decOut_D = 0;
                    decimal decOut_E = 0;
                    string  aux      = gridVetor_D.Rows[0].Cells[i].Value?.ToString()?.Trim();
                    if (aux == null || aux.Equals(string.Empty))
                    {
                        throw new Exception("A Linha do vetor D não pode ser vazia");
                    }
                    else if (!decimal.TryParse(aux, out decOut_D))
                    {
                        throw new Exception("A Linha do vetor D não pode conter letra");
                    }


                    aux = gridVetor_E.Rows[0].Cells[i].Value?.ToString().Trim();
                    if (aux == null || aux.Equals(string.Empty))
                    {
                        throw new Exception("A Linha do vetor E não pode ser vazio");
                    }
                    else if (!decimal.TryParse(aux, out decOut_E))
                    {
                        throw new Exception("A Linha do vetor E não pode conter letra");
                    }

                    Parametros.Vetor_D[i] = decOut_D;
                    Parametros.Vetor_E[i] = decOut_E;
                }

                var vetAux = new decimal[qtdColuna];

                //apenas as matrizes
                for (int i = 0; i < int.Parse(numeroDeLinha); ++i)
                {
                    for (int j = 0; j < int.Parse(numeroDeColuna); ++j)
                    {
                        decimal decOut_C;
                        decimal decOut_R;
                        string  aux = gridMatriz_C.Rows[i].Cells[j].Value?.ToString().Trim();
                        if (string.IsNullOrEmpty(aux))
                        {
                            throw new Exception("A Linha da Matriz C não pode ser vazio");
                        }
                        else if (!decimal.TryParse(aux, out decOut_C))
                        {
                            throw new Exception("A Linha da Matriz C não pode conter letra");
                        }

                        aux = gridMatriz_R.Rows[i].Cells[j].Value?.ToString().Trim();
                        if (string.IsNullOrEmpty(aux))
                        {
                            throw new Exception("A Linha da Matriz R não pode ser vazio");
                        }
                        else if (!decimal.TryParse(aux, out decOut_R))
                        {
                            throw new Exception("A Linha da Matriz R não pode conter letra");
                        }

                        Parametros.Matriz_C[i, j] = decOut_C;
                        Parametros.Matriz_R[i, j] = decOut_R;
                    }
                }
                btnProximoPasso.Visible = true;
                btnIniciar.Visible      = false;
                btnLimpar.Visible       = false;
                btnGerarVetorDAutomaticamente.Visible = false;
                BloqueiGrids();
            }

            catch (Exception ex)
            {
                gerouErro = true;
                MessageBox.Show(ex.Message, Program.TitleProgram, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }