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 Enter() { enter = new Entity.EntEnter(); impEnter = new Implement.ImpEnter(); InitializeComponent(); WindowStyle = WindowStyle.None; ResizeMode = ResizeMode.NoResize; Left = 0; Top = 0; Width = 1366; Height = 768; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer_Tick; timer.Start(); CheckColour(); }