Beispiel #1
0
        private void AlterarlayoutButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Deseja alterar o layout? ", ParametroInfo.SistemaVersao, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    statuslayoutLabel.Text    = "Processando...";
                    statuslayoutLabel.Visible = true;
                    List <ErrosTela> ErrosTela = new List <ErrosTela>();
                    Utilities.ValidarTextBoxes(conteudoGroupBox, ref ErrosTela);
                    if (ErrosTela.Count() > 0)
                    {
                        string strCamposInvalidos = Utilities.CriarMensagemErro(conteudoGroupBox, ErrosTela);
                        statuslayoutLabel.Text = "Não foi possível alterar...";
                        MessageBox.Show("Preencher Campo(s):" + Environment.NewLine + strCamposInvalidos, ParametroInfo.SistemaVersao, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(nomelayoutTextBox.Text))
                        {
                            throw new Exception("Favor preencher o nome do layout.");
                        }
                        Layout ObjLayout = new Layout()
                        {
                            Nome = nomelayoutTextBox.Text
                        };
                        for (int i = 0; i < ConteudoComboBoxes.Count(); i++)
                        {
                            switch (ConteudoComboBoxes.ElementAt(i).SelectedIndex)
                            {
                            case 1:    //Código Empresa
                                if (!string.IsNullOrEmpty(InicioComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.InicioEmpresa = int.Parse(InicioComboBoxes.ElementAt(i).Text);
                                }
                                if (!string.IsNullOrEmpty(TamanhoComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.TamanhoEmpresa = int.Parse(TamanhoComboBoxes.ElementAt(i).Text);
                                }
                                break;

                            case 2:    //Código Funcionário
                                if (!string.IsNullOrEmpty(InicioComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.InicioFuncionario = int.Parse(InicioComboBoxes.ElementAt(i).Text);
                                }
                                if (!string.IsNullOrEmpty(TamanhoComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.TamanhoFuncionario = int.Parse(TamanhoComboBoxes.ElementAt(i).Text);
                                }
                                break;

                            case 3:    //Código Evento
                                if (!string.IsNullOrEmpty(InicioComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.InicioEvento = int.Parse(InicioComboBoxes.ElementAt(i).Text);
                                }
                                if (!string.IsNullOrEmpty(TamanhoComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.TamanhoEvento = int.Parse(TamanhoComboBoxes.ElementAt(i).Text);
                                }
                                break;

                            case 4:    //Horas
                                if (!string.IsNullOrEmpty(InicioComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.InicioHoras = int.Parse(InicioComboBoxes.ElementAt(i).Text);
                                }
                                if (!string.IsNullOrEmpty(TamanhoComboBoxes.ElementAt(i).Text))
                                {
                                    ObjLayout.TamanhoHoras = int.Parse(TamanhoComboBoxes.ElementAt(i).Text);
                                }
                                break;
                            }
                        }
                        statuslayoutLabel.Text = "Layout alterado com sucesso.";
                        DataBaseBLL.AlterarLayout(ObjLayout, linhaSelecionada["nomeDataGridViewTextBoxColumn"].Value.ToString());
                        MessageBox.Show("Layout alterado com sucesso!", ParametroInfo.SistemaVersao, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        VerificarLayoutVazio(ObjLayout);
                        if (consultaLayoutGridView != null)
                        {
                            consultaLayoutGridView.DataSource = DataBaseBLL.CarregarLayoutGrid(nomelayoutTextBox.Text);
                        }
                        if (nomelayoutComboBox != null)
                        {
                            nomelayoutComboBox.DataSource = DataBaseBLL.CarregarLayoutComboBox();
                        }
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "23505")
                {
                    MessageBox.Show("Layout já cadastrado.", ParametroInfo.SistemaVersao, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(ex.Message, ParametroInfo.SistemaVersao, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }