public FrmCabutSuara() { keterangan = "INSERT"; suara = new Entity.EntSuara(); suaraDao = Factory.FactLogin.GetInterfaceSuara(); InitializeComponent(); }
public Boolean updateSuara(Entity.EntSuara e) { status = false; try { query = "UPDATE tb_suara SET suara_masuk = suara_masuk-1, waktu_suara = GETDATE() WHERE nomor_calon =" + e.GetNomor() + "\r\n" + "IF EXISTS(SELECT 1 FROM tb_suara WHERE nomor_calon=" + e.GetNomor() + " AND suara_masuk < 1)\r\n" + "DELETE from tb_suara WHERE nomor_calon =" + e.GetNomor(); koneksi.Open(); command = koneksi.CreateCommand(); command.CommandText = query; command.ExecuteNonQuery(); status = true; koneksi.Close(); } catch (SqlException ex) { Console.WriteLine("ERROR" + ex.Message); } return(status); }
public Boolean tambahSuara(Entity.EntSuara e) { status = false; try { query = "IF NOT EXISTS(SELECT 1 FROM tb_suara WHERE nomor_calon=" + e.GetNomor() + ")\r\n" + "INSERT INTO tb_suara VALUES ('" + e.GetNomor() + "', 1, GETDATE())" + "\r\nELSE\r\n" + "UPDATE tb_suara SET suara_masuk=suara_masuk+1, waktu_suara = GETDATE() WHERE nomor_calon=" + e.GetNomor(); koneksi.Open(); command = new SqlCommand(query, koneksi); command.ExecuteNonQuery(); status = true; koneksi.Close(); } catch (SqlException ex) { Console.WriteLine("ERROR" + ex.Message); } return(status); }