private void VisitsCheckInBtn_Click(object sender, EventArgs e) { DateTime currentTime = DateTime.Now; string CheckInTime = $"{currentTime.Hour.ToString(): D2}:{currentTime.Minute.ToString(): D2}:{currentTime.Second.ToString(): D2}"; string CheckInDay = $"{currentTime.Year.ToString()}/{currentTime.Month.ToString(): D2}/{currentTime.Day.ToString(): D2}"; try { if (LibraryDBCon.State == ConnectionState.Closed) { LibraryDBCon.Open(); } // Create Connection With DataBase sqlcom.Connection = LibraryDBCon; sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = $"INSERT INTO Visits (MemberId, Date ,CheckIn, CheckOut) VALUES({VisitMemberId}, '{CheckInDay}', '{CheckInTime}', '00:00:00')"; sqlcom.ExecuteNonQuery(); if (LibraryDBCon.State == ConnectionState.Open) { LibraryDBCon.Close(); } FillVisitsTable(); VisitsMemberName.Visible = false; VisitsCheckOutBtn.Visible = false; VisitsCheckInBtn.Visible = false; VisitsMemberIdTB.Reset(); } catch { MessageBox.Show("Something Went Wrong, Please Try Again"); } }
private void VisitsCheckOutBtn_Click(object sender, EventArgs e) { DateTime currentTime = DateTime.Now; string CheckOutTime = $"{currentTime.Hour.ToString(): D2} : {currentTime.Minute.ToString(): D2} : {currentTime.Second.ToString(): D2}"; try { if (LibraryDBCon.State == ConnectionState.Closed) { LibraryDBCon.Open(); } // Create Connection With DataBase sqlcom.Connection = LibraryDBCon; sqlcom.CommandType = CommandType.Text; sqlcom.CommandText = $"UPDATE Visits SET CheckOut = '{CheckOutTime}' WHERE VisitId = {VisitsId}"; sqlcom.ExecuteNonQuery(); if (LibraryDBCon.State == ConnectionState.Open) { LibraryDBCon.Close(); } FillVisitsTable(); VisitsMemberName.Visible = false; VisitsCheckOutBtn.Visible = false; VisitsCheckInBtn.Visible = false; VisitsMemberIdTB.Reset(); } catch { MessageBox.Show("Something Went Wrong, Please Try Again"); } }