Ejemplo n.º 1
0
        private void btNovoLivro_Click(object sender, EventArgs e)
        {
            ((Form)this.TopLevelControl).Hide();
            frmLivroConf lc = new frmLivroConf();

            lc.Show();
        }
Ejemplo n.º 2
0
        private void btEditarLivro_Click(object sender, EventArgs e)
        {
            if (dgvLivros.CurrentRow.Cells[0].Value != null)
            {
                List <string> campos = new List <string>();
                for (int i = 0; i < dgvLivros.Columns.Count; i++)
                {
                    if (dgvLivros.CurrentRow.Cells[i].Value.ToString() != null)
                    {
                        campos.Add(dgvLivros.CurrentRow.Cells[i].Value.ToString());
                    }
                }
                if (Conexao.con.State.ToString() == "Open")
                {
                    Conexao.con.Close();
                }
                DataTable dt = new DataTable();
                try
                {
                    Conexao.con.Open();
                    MySqlCommand cmd = Conexao.con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "call pesquisa_editar_livro(@id)";
                    cmd.Parameters.AddWithValue("@id", dgvLivros.CurrentRow.Cells[0].Value.ToString());
                    cmd.ExecuteNonQuery();
                    MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                    Conexao.con.Close();
                    da.Fill(dt);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Não foi possível trazer o registro: " + ex.Message);
                    Conexao.con.Close();
                }

                foreach (DataRow row in dt.Rows)
                {
                    campos.Add(row[0].ToString());
                    campos.Add(row[1].ToString());
                    campos.Add(row[2].ToString());
                }

                ((Form)this.TopLevelControl).Hide();
                frmLivroConf lc = new frmLivroConf(campos, "editar");
                lc.Show();
            }
            else
            {
                MessageBox.Show("Escolha um registro para editar.");
            }
        }