private void Btn_Enviar_Click(object sender, EventArgs e) { Banco_dados db = new Banco_dados(); db.Conect_to_database(db.con); String comando = null; if (check_professor.Checked) { Professor p = new Professor(txt_Nome.Text, Int32.Parse(txt_id.Text), txt_IdCard.Text); comando = "INSERT INTO Professor (Cod_professor, RFID, Nome) VALUES (" + p.Id + ", '" + p.RFID + "', '" + p.Nome + "')"; Console.WriteLine(comando); } else { Aluno a = new Aluno(txt_Nome.Text, Int32.Parse(txt_id.Text), txt_IdCard.Text, (cb_curso.Items.IndexOf(cb_curso.Text) + 1)); comando = "INSERT INTO Aluno (RA, Cod_curso, RFID, Nome) VALUES (" + a.RA + ", " + a.cod_curso + ", '" + a.RFID + "', '" + a.Nome + "')"; Console.WriteLine(comando); } MySqlCommand edh = new MySqlCommand(comando, db.con); try { edh.ExecuteNonQuery(); db.Close_database(db.con); MessageBox.Show("Cadastro realizado com sucesso"); } catch { MessageBox.Show("Erro ao fazer cadastro"); db.Close_database(db.con); } //db.Close_database(db.con); }
public void get_grid_faltas(Banco_dados db, String comando, DataGridView cb) { db.Conect_to_database(db.con); MySqlCommand edh = new MySqlCommand(comando, db.con); MySqlDataReader myReader; myReader = edh.ExecuteReader(); DataTable dtb1 = new DataTable(); DataColumn turma = new DataColumn(); DataColumn faltas = new DataColumn(); turma.ColumnName = "Turma"; faltas.ColumnName = "Faltas"; dtb1.Columns.Add(turma); dtb1.Columns.Add(faltas); while (myReader.Read()) { DataRow row = dtb1.NewRow(); row["Turma"] = myReader.GetString(1); row["Faltas"] = myReader.GetString(2); dtb1.Rows.Add(row); } cb.DataSource = dtb1; }
public void get_grid(Banco_dados db, String comando, DataGridView cb, SerialPort serialListener) { db.Conect_to_database(db.con); string name = ""; MySqlCommand edh = new MySqlCommand(comando, db.con); MySqlDataReader myReader; myReader = edh.ExecuteReader(); DataTable dtb1 = new DataTable(); DataColumn ra = new DataColumn(); DataColumn nome = new DataColumn(); ra.ColumnName = "Ra"; nome.ColumnName = "Nome"; dtb1.Columns.Add(ra); dtb1.Columns.Add(nome); while (myReader.Read()) { DataRow row = dtb1.NewRow(); row["Ra"] = myReader.GetString(0); row["nome"] = myReader.GetString(1); name = myReader.GetString(0).ToString(); dtb1.Rows.Add(row); } serialListener.WriteLine("Chamada Ok!\r" + name); //Imprime que a chamada está OK junto com o RA do aluno cb.DataSource = dtb1; }
public void execute_query(Banco_dados db, String comando) { Console.WriteLine(comando); db.Conect_to_database(db.con); MySqlCommand edh = new MySqlCommand(comando, db.con); edh.ExecuteNonQuery(); db.Close_database(db.con); }
public void get_cb(Banco_dados db, String comando, ComboBox cb) { db.Conect_to_database(db.con); MySqlCommand edh = new MySqlCommand(comando, db.con); MySqlDataReader myReader; myReader = edh.ExecuteReader(); while (myReader.Read()) { cb.Items.Add(myReader.GetString(0)); } }