Exemple #1
0
        private void BtGravar_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Gravar os dados?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Centrocusto reg = new Centrocusto {
                    Vinculo   = Convert.ToInt16(txtVinculo.Tag),
                    Codigo    = Convert.ToInt16(txtDescricao.Tag),
                    Descricao = txtDescricao.Text,
                    Telefone  = txtFone.Text,
                    Ativo     = chkAtivo.Checked
                };

                Processo_bll clsProcesso = new Processo_bll(_connection);
                Exception    ex;

                if (bAddNew)
                {
                    short nLastCod = clsProcesso.Retorna_Ultimo_Codigo_Local();
                    reg.Vinculo = Convert.ToInt16(txtDescricao.Tag);
                    reg.Codigo  = Convert.ToInt16(nLastCod + 1);
                    ex          = clsProcesso.Incluir_Local(reg);
                    if (ex != null)
                    {
                        ErrorBox eBox = new ErrorBox("Atenção", ex.Message, ex);
                        eBox.ShowDialog();
                    }
                    else
                    {
                        var child = new TreeNode()
                        {
                            Text = txtDescricao.Text.ToUpper(),
                            Tag  = (nLastCod + 1).ToString(),
                        };
                        tvMain.SelectedNode.Nodes.Add(child);
                        Lista.Add(reg);
                        ControlBehaviour(true);
                    }
                }
                else
                {
                    ex = clsProcesso.Alterar_Local(reg);
                    if (ex != null)
                    {
                        ErrorBox eBox = new ErrorBox("Atenção", ex.Message, ex);
                        eBox.ShowDialog();
                    }
                    else
                    {
                        tvMain.SelectedNode.Text = txtDescricao.Text.ToUpper();
                        for (int i = 0; i < Lista.Count; i++)
                        {
                            if (Lista[i].Codigo == Convert.ToInt32(txtDescricao.Tag.ToString()))
                            {
                                Lista[i].Telefone = txtFone.Text;
                                Lista[i].Ativo    = chkAtivo.Checked;
                                break;
                            }
                        }
                        ControlBehaviour(true);
                    }
                }
            }
        }