Save selected radioButton option for future reference

0

I would like to know if you can save a DataTable (or something like this, to be queried later) to the information that a radioButton was clicked on. I am making a simple program for a client to report three information in three% with% of this is saved in a textbox and is shown in DataTable . Also, I would like to show which DataGrid (if radioButton of physical person is selected, then radiobutton will receive a cpf number) was clicked on the register that the user is viewing in txt_registro you can check the registration information later just by clicking on the DataGrid line.

I thought maybe this should be done within the class, in a method, but I'm not sure why I have yet to make an option to edit the selected record (for the user to edit what he had written in an old record by means of the text box and save in the same place of the old cadastre.

public int con;

DataSet ds = new DataSet();
DataTable dt = new DataTable("Cadastro");


public Form1()
{
    InitializeComponent();

    dt.Columns.Add("Nome", Type.GetType("System.String"));
    dt.Columns.Add("Email", Type.GetType("System.String"));
    dt.Columns.Add("Registro", Type.GetType("System.String"));

    dataGridView1.DataSource = dt;
}

private void bt_salvar_Click_1(object sender, EventArgs e)
{

    DataRow dr = dt.NewRow();

    if (con == 1) 
    {
        Fisica dadosfisica = new Fisica(txt_nome.Text, txt_email, txt_registro.Text);
        dr["Registro"] = "CPF: " + dadosfisica.CPF;
        dr["Nome"] = dadosfisica.Nome;
        dr["Endereco"] = dadosfisica.Email;

    }

    if (con == 2)
    {
        Juridica dadosjuridica = new Juridica(txt_nome.Text, txt_email,txt_registro.Text);
        dr["Registro"] = "CNPJ: " + dadosjuridica.CNPJ;
        dr["Nome"] = dadosjuridica.Nome;
        dr["Endereco"] = dadosjuridica.Email;

    }


    dt.Rows.Add(dr);
    dataGridView1.DataSource = dt;


}>



                 <public class Dados
            {

            private string _nome;
            private string _email;

            //construtor para iniciar os dados privados - recebe parametros
            public Dados(string nome, string email)
            {
             this._nome = nome;

             this._email = email;
            }


            public string Nome
            {
             get
             {
                 return _nome;
             }
             set
             {
                 _nome = value;
             }
            }

            public string Email
            {
             get
             {
                 return _email;
             }
             set
             {
                 _email = value;
             }
            }
            }>

              <//Classe Juridica herdada da classe Dados
            public class Juridica : Dados
            {

                private string nCNPJ;

                public Juridica(string nome, string email, string nCNPJ)
                    : base(nome, email) //chama o construtor da classe base
                {
                    this.nCNPJ = nCNPJ;
                }

                public string CNPJ
                {
                    get{return nCNPJ;}

                    set{nCNPJ = value;}
                }

            }>


              </Classe Fisica herdada da classe Dados
            public class Fisica : Dados
            {
                private string nCPF;

                public Fisica(string nome, string email, string nCPF)
                    : base(nome, email) //chama o construtor da classe base
                {
                    this.nCPF = nCPF;
                }

                public string CPF
                {
                    get{return nCPF;}

                    set{nCPF = value;}
                }

            }>



//Seleção do RadioButton
private void bt_pfisica_CheckedChanged_1(object sender, EventArgs e)
{
    if (bt_pfisica.Checked)
    {
        txt_registro.Enabled = true;
        txt_registro.Mask = "000,000,000-00";
        con = 1;
    }
}

private void bt_pjuridica_CheckedChanged_1(object sender, EventArgs e)
{
    if (bt_pjuridica.Checked)
    {
        txt_registro.Enabled = true;
        txt_registro.Mask = "00,000,000/0000-00";
        con = 2;
    }
}
    
asked by anonymous 09.03.2017 / 13:22

1 answer

0

You can save a symbolic value in the DataTable, indicating if it has been clicked or not, eg

dr["Registro"] = "CPF: " + dadosfisica.CPF;
dr["Nome"] = dadosfisica.Nome;
dr["Endereco"] = dadosfisica.Email;
//Crie uma coluna para salvar o dado pretendido. No caso, usarei o valor '1' para 'clicado' e '0' para não clicado
dr["PessoaFisica"] = dadosfisica.Juridica ? "1" : "0";

And so, you can create a Boolean attribute in your class to save this information:

private bool bJuridica;
public bool PessoaJuridica
{
      get{return bJuridica;}

      set{bJuridica = value;}
}

, so you can set the value in the attribute like this:

dados.Juridica = bt_pjuridica.Checked;

I hope I understand your question correctly

    
09.03.2017 / 13:58