public Boolean KendaraanMasuk(Entity.EntEnter enter) //fungsi memasukkan data baru ke database { Fungsi.CodeGenerate objcode = new Fungsi.CodeGenerate(); //objek fungsi pembuatan kode baru string newcode, sto = ""; status = false; for (int i = 0; i < 4; i++) //4 langkah penambahan data baru { switch (i) { case 0: //masukkan data ke tabel Kendaraan newcode = objcode.NewCode("Kendaraan"); query = "INSERT into Kendaraan values('" + newcode + "', '" + enter.Plat + "', 'SP001')"; sto = newcode; //simpan kode untuk digunakan di query berikutnya break; case 1: //masukkan data ke tabel Record_Masuk newcode = objcode.NewCode("Record_Masuk"); query = "INSERT into Record_Masuk values('" + newcode + "', '" + sto + "', (SELECT No_Lokasi FROM Lokasi WHERE Kode_Lokasi = '" + enter.Lokasi + "'),'" + DateTime.Now.ToString(@"MM/dd/yyyy") + "','" + DateTime.Now.ToString(@"HH") + ':' + DateTime.Now.ToString(@"mm") + ':' + DateTime.Now.ToString(@"ss") + "')"; sto = newcode; //simpan kode untuk digunakan di query berikutnya break; case 2: //masukkan data ke tabel Status_Parkir newcode = objcode.NewCode("Status_Parkir"); query = "INSERT into Status_Parkir values('" + newcode + "', '" + sto + "','Tidak','Tidak')"; break; case 3: //ubah data ketersediaan lokasi di tabel Lokasi query = "UPDATE Lokasi set Ketersediaan = 'Tidak' WHERE Kode_Lokasi = '" + enter.Lokasi + "'"; break; default: query = ""; break; } try { if (connection.State == ConnectionState.Open) //pengecekan jika koneksi masih terbuka, ditutup terlebih dahulu { connection.Close(); } connection.Open(); command = connection.CreateCommand(); command.CommandText = query; command.ExecuteNonQuery(); status = true; connection.Close(); } catch (SqlException err) { Console.WriteLine("ERROR" + err); //error handling } } return(status); }
public void ProsesData(Entity.EntExit exit) //fungsi memasukkan data pembayaran ke dalam database { Fungsi.CodeGenerate objcode = new Fungsi.CodeGenerate(); //objek fungsi pembuatan kode baru string newcode, sto = ""; for (int i = 0; i < 2; i++) //2 langkah pembayaran { switch (i) { case 0: //masukkan data ke tabel Record Keluar newcode = objcode.NewCode("Record_Keluar"); query = "insert into Record_Keluar values('" + newcode + "', '" + exit.Id + "', '" + exit.Nostatus + "', '" + exit.Tglkeluar + "', '" + exit.Waktukeluar + "', '" + exit.Total + "')"; sto = newcode; break; case 1: //masukkan data ke tabel transaksi <--Denil lupa nambahin untuk insert di tabel Transaksi newcode = objcode.NewCode("Transaksi"); query = "insert into Transaksi values ('" + newcode + "','" + sto + "','KR001')"; break; default: query = ""; break; } try { if (connection.State == ConnectionState.Open) //pengecekan jika koneksi masih terbuka, ditutup terlebih dahulu { connection.Close(); } connection.Open(); command = connection.CreateCommand(); command.CommandText = query; command.ExecuteNonQuery(); connection.Close(); } catch (SqlException err) { Console.WriteLine("ERROR" + err); //error handling } } }
public void InputQuery(Entity.EntLogin e) //fungsi memasukan data login ke tabel presensi { Fungsi.CodeGenerate objcode = new Fungsi.CodeGenerate(); //objek pembuatan kode baru string newcode = objcode.NewCode("Presensi"); koneksi.Open(); // catat pada presensi kode pegawai yang login dan waktu login (sekarang) query = "insert into Presensi values('" + newcode + "', '" + e.Kode + "', '" + DateTime.Now.ToString(@"MM/dd/yyyy HH") + ':' + DateTime.Now.ToString(@"mm") + ':' + DateTime.Now.ToString(@"ss") + "', '')"; SqlCommand command = koneksi.CreateCommand(); command.CommandText = query; command.ExecuteNonQuery(); koneksi.Close(); }