public MainMenu_Form(User u) { InitializeComponent(); currentUser = u; currentShift = u.GetOpenShift(); InitializeFormElements(); this.Size = DEFAULT_SIZE; numVehicle.Value = currentUser.LastVehicleUsed(); }
private void btnClock_Click(object sender, EventArgs e) { if (currentShift != null) { currentUser.ClockOut(currentShift); } else { currentShift = currentUser.ClockIn(1); //TODO: Get input for vehicle number } LogOutAndReopen(); }
public Shift ClockIn(int vehicleNum) { DatabaseConnection con = new DatabaseConnection(DatabaseConnection.DATABASE_LOG); con.Open(); string stm = String.Format(@" INSERT INTO T_SHIFT (employee_id, vehicle_number, start_time) VALUES ('{0}', '{1}', datetime('now'))", id.ToString(), vehicleNum.ToString()); DatabaseConnection.ExecuteUpdate(stm); stm = String.Format(@" SELECT id FROM T_SHIFT WHERE employee_id = '{0}' AND end_time IS NULL", id); var newRowId = DatabaseConnection.ExecuteScalar(stm); Shift ret = new Shift(Convert.ToInt32(newRowId), id, vehicleNum, DateTime.Now); return ret; }
public Shift GetOpenShift() { DataTable latestOpenShiftTable = DatabaseConnection.ExecuteSelect(String.Format(@"SELECT id, employee_id, vehicle_number, start_time FROM T_SHIFT WHERE employee_id = {0} AND end_time IS NULL", id.ToString())); if (latestOpenShiftTable.Rows.Count > 0) { Shift shf = new Shift(Convert.ToInt32(latestOpenShiftTable.Rows[0][0]), Convert.ToInt32(latestOpenShiftTable.Rows[0][1]), Convert.ToInt32(latestOpenShiftTable.Rows[0][2]), Convert.ToDateTime(latestOpenShiftTable.Rows[0][3])); return shf; } else { return null; } }
public void ClockOut(Shift s) { string stm = String.Format(@"UPDATE T_SHIFT SET end_time = datetime('now') WHERE id = '{0}'", s.id); DatabaseConnection.ExecuteUpdate(stm); s.endTime = DateTime.Now; }
private void LogOutAndReopen() { Login_Form loginForm = new Login_Form(); this.Visible = false; mainMenuOpen = false; if (loginForm.ShowDialog() == DialogResult.OK) { currentUser = loginForm.currentUser; currentShift = currentUser.GetOpenShift(); lastShift = null; InitializeFormElements(); this.Visible = true; chkVehicleLocked.Checked = true; if (btnReview.Visible == false) { this.Size = DEFAULT_SIZE; lblLastShift.Visible = false; lblLastShiftInformation.Visible = false; btnCloseReviewShifts.Visible = false; btnMoreShiftInformation.Visible = false; btnReview.Visible = true; } mainMenuOpen = true; } else { Application.Exit(); } }