Ejemplo n.º 1
0
        private void mnuNivel2Salvar_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNivel2Desc.Text.Trim().Replace(".", "").Replace(",", "").Replace("-", "").Replace("/", "").Replace("_", "") == string.Empty)
                {
                    MessageBox.Show(MensagensDoSistema._0001.ToString().Replace("$Campo", "Descrição do nivel 2 "), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNivel2Desc.Focus();
                    return;
                }

                CategoriaNegocios   Registro_N = new CategoriaNegocios();
                CategoriaController Registro_C = new CategoriaController();

                Registro_C.TB021_id        = Convert.ToInt64(lblNivel1Id.Text);
                Registro_C.TB022_Descricao = txtNivel2Desc.Text.TrimEnd();

                if (lblNivel2Id.Text.Trim() == string.Empty)
                {
                    //Novo
                    Int64 Id = Registro_N.IncluirNivel2(Registro_C);
                    if (Id > 0)
                    {
                        lblNivel2Id.Text = Id.ToString();
                        MessageBox.Show(MensagensDoSistema._0017, "Incluido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    //Atualização
                    Registro_C.TB022_id = Convert.ToInt64(lblNivel2Id.Text);
                    if (Registro_N.AtualizarNivel2(Registro_C))
                    {
                        MessageBox.Show(MensagensDoSistema._0018, "Atualização", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                lsbNivel2.DataSource    = Registro_N.RetoranarcCategoriaNivel2(Registro_C.TB021_id);
                lsbNivel2.DisplayMember = "TB022_Descricao";
                lsbNivel2.ValueMember   = "TB022_id";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro ao executar operação", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }