private void editaCliente(object sender, EventArgs e) { frmCli = sender as CadastraCliente; frmCli.btnEnviar.Click -= frmCli.btnEnviar_Click; frmCli.btnEnviar.Click += ConfirmaEditarCliente; frmCli.btnCancelar.Click += CancelaEditarCliente; frmCli.AutoScroll = true; frmCli.btnPFisica.Enabled = false; frmCli.btnPJuridica.Enabled = false; frmCli.Parent = splitContainerContent.Panel2; frmCli.Dock = DockStyle.Fill; splitPrincipal.Panel2.Controls.Add(frmCli); frmCli.BringToFront(); }
private void btnEditar_Click(object sender, EventArgs e) { try { MySqlConnection objcon = new MySqlConnection("server=localhost;port=3306;User Id=root;database=splash_shark;Character Set=utf8"); // abre o banco objcon.Open(); string id = dataGridViewPF.CurrentRow.Cells[0].Value.ToString(); MySqlCommand endereco = new MySqlCommand("select id_endereco from clienteendereco where id_cliente = " + id, objcon); int idEnd = Convert.ToInt32(endereco.ExecuteScalar()); MySqlCommand objcmd1 = new MySqlCommand("select logradouro from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmd2 = new MySqlCommand("select bairro from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmd3 = new MySqlCommand("select cidade from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmd4 = new MySqlCommand("select cep from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmd5 = new MySqlCommand("select numero from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmd6 = new MySqlCommand("select uf from endereco where id_endereco = " + idEnd, objcon); MySqlCommand objcmdPF1 = new MySqlCommand("select CPF from ClientePF where ID = " + id, objcon); MySqlCommand objcmdPF2 = new MySqlCommand("select RG from ClientePF where ID = " + id, objcon); CadastraCliente cli = new CadastraCliente(); cli.lbId.Text = id; if (radioFisica.Checked) { cli.txtNome.Text = dataGridViewPF.CurrentRow.Cells[1].Value.ToString(); cli.txtTelefone.Text = dataGridViewPF.CurrentRow.Cells[5].Value.ToString(); cli.txtEmail.Text = dataGridViewPF.CurrentRow.Cells[2].Value.ToString(); cli.txtCPF.Text = objcmdPF1.ExecuteScalar().ToString(); cli.txtRG.Text = objcmdPF2.ExecuteScalar().ToString(); cli.btnPFisica.Checked = true; } else { cli.txtNome.Text = dataGridViewPJ.CurrentRow.Cells[1].Value.ToString(); cli.txtTelefone.Text = dataGridViewPJ.CurrentRow.Cells[3].Value.ToString(); cli.txtEmail.Text = dataGridViewPJ.CurrentRow.Cells[2].Value.ToString(); cli.txtCNPJ.Text = dataGridViewPJ.CurrentRow.Cells[4].Value.ToString(); cli.txtInscEstadual.Text = dataGridViewPJ.CurrentRow.Cells[5].Value.ToString(); cli.txtRazaoSocial.Text = dataGridViewPJ.CurrentRow.Cells[6].Value.ToString(); cli.btnPJuridica.Checked = true; cli.lbCNPJ.Visible = true; cli.lbInscricaoEstadual.Visible = true; cli.lbRazaoSocial.Visible = true; cli.txtCNPJ.Visible = true; cli.txtInscEstadual.Visible = true; cli.txtRazaoSocial.Visible = true; cli.txtRG.Visible = false; cli.txtRazaoSocial.TabIndex = 5; cli.txtCNPJ.TabIndex = 6; cli.txtInscEstadual.TabIndex = 7; cli.txtRG.TabIndex = 100; cli.txtCPF.TabIndex = 101; } cli.txtRua.Text = objcmd1.ExecuteScalar().ToString(); cli.txtBairro.Text = objcmd2.ExecuteScalar().ToString(); cli.txtCidade.Text = objcmd3.ExecuteScalar().ToString(); cli.txtCep.Text = objcmd4.ExecuteScalar().ToString(); cli.txtNum.Text = objcmd5.ExecuteScalar().ToString(); cli.txtEstado.SelectedItem = objcmd6.ExecuteScalar().ToString(); cli.BackColor = Color.FromArgb(240, 240, 240); cli.AutoScroll = true; objcon.Close(); cli.lbTitulo.Text = "Edita Cliente"; cli.btnCancelar.Visible = true; EventHandler handler = EditaCli; handler?.Invoke(cli, e); } catch { MessageBox.Show("Não há registros para editar!"); } }