private void deleteGalimTest_Click(object sender, EventArgs e) { try { GalimiTestai gl = new GalimiTestai(); gl.testoKodas = int.Parse(deleteGalTestTestoKodas.Text); galimiTestRep.DeleteGalimiTestai(gl); deleteGalTestTestoKodas.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Deleted succesfully"); getGalimiTestDisplay(); getTransTest(); }
public void DeleteGalimiTestai(GalimiTestai galimiTestai) { try { cnn = new MySqlConnection(connectionString); string newSql = ("Delete from galimi_test where galimi_test.Testo_kodas=@id "); cnn.Open(); //open connection. we use the Open method of the cnn variable to open a connection to the database. MySqlCommand cmd = new MySqlCommand(newSql, cnn); //select all from newTestTable cmd.Parameters.AddWithValue("@id", galimiTestai.testoKodas); cmd.ExecuteNonQuery(); //execute function cnn.Close(); } catch (Exception exc) { Console.WriteLine(exc); } }
//REGISTER STUDENT public GalimiTestai InsertGalimiTestai(GalimiTestai galimiTestai)//provide transportas object when calling this function { try { //setting new SqlConnection, providing connectionString cnn = new MySqlConnection(connectionString); cnn.Open();//open database MySqlCommand cmd1 = new MySqlCommand("Insert into galimi_test (Test_pav,TestId) VALUES(@Test_pav,@TestId)", cnn); cmd1.Parameters.AddWithValue("@Test_pav", galimiTestai.testPav); cmd1.Parameters.AddWithValue("@TestId", galimiTestai.testId); cmd1.ExecuteNonQuery(); cnn.Close(); } catch (Exception exc) { Console.WriteLine(exc); } return(galimiTestai);//return }
public void UpdateGalimiTestai(GalimiTestai galimiTestai) { try { //setting new SqlConnection, providing connectionString cnn = new MySqlConnection(connectionString); //check if user exist MySqlCommand cmd = new MySqlCommand("Update galimi_test SET Test_pav=@Test_pav, TestId=@TestId WHERE Testo_kodas=@Testo_kodas", cnn);//to check if username exist we have to select all items with username cmd.Parameters.AddWithValue("@Test_pav", galimiTestai.testPav); cmd.Parameters.AddWithValue("@TestId", galimiTestai.testId); cmd.Parameters.AddWithValue("@Testo_kodas", galimiTestai.testoKodas); cnn.Open(); cmd.ExecuteNonQuery(); cnn.Close(); } catch (Exception ex) { Console.WriteLine(ex); } }
private void updateGalimiTest_Click(object sender, EventArgs e) { try { GalimiTestai gt = new GalimiTestai(); gt.testPav = updateGalimiTestTestPav.Text; gt.testId = int.Parse(updateGalimiTestTestId.Text); gt.testoKodas = int.Parse(updateGalimiTestTestoKodas.Text); galimiTestRep.UpdateGalimiTestai(gt); updateGalimiTestTestPav.Clear(); updateGalimiTestTestId.Clear(); updateGalimiTestTestoKodas.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } MessageBox.Show("Succesfully updated"); getGalimiTestDisplay(); }
private void addGalimiTest_Click(object sender, EventArgs e) { try { GalimiTestai gt = new GalimiTestai(); gt.testPav = addGalimiTestTestPav.Text; gt.testId = int.Parse(addGalimiTestTestId.Text); GalimiTestai insertedGalimiTest = galimiTestRep.InsertGalimiTestai(gt); if (insertedGalimiTest.testPav != null && insertedGalimiTest.testPav != "") { MessageBox.Show("Succesfully inserted"); } addGalimiTestTestPav.Clear(); addGalimiTestTestId.Clear(); } catch (Exception ex) { MessageBox.Show(ex.Message); } getGalimiTestDisplay(); }