/// <summary> /// Add a new entry to the RegisterMove table /// </summary> public static RegisterMove Add(int registerDrawerId, int sourceRegisterId, int sourceRegisterSubId) { RegisterMove result = null; DateTime startTime = DateTime.Now; sourceRegisterId = MathHelper.Clamp(sourceRegisterId, 0, 255); sourceRegisterSubId = MathHelper.Clamp(sourceRegisterSubId, 0, 255); SqlConnection cn = GetConnection(); string cmd = "AddRegisterMove"; using (SqlCommand sqlCmd = new SqlCommand(cmd, cn)) { sqlCmd.CommandType = CommandType.StoredProcedure; BuildSqlParameter(sqlCmd, "@RegisterMoveRegisterDrawerId", SqlDbType.Int, registerDrawerId); BuildSqlParameter(sqlCmd, "@RegisterMoveSourceRegisterId", SqlDbType.TinyInt, sourceRegisterId); BuildSqlParameter(sqlCmd, "@RegisterMoveSourceRegisterSubId", SqlDbType.TinyInt, sourceRegisterSubId); BuildSqlParameter(sqlCmd, "@RegisterMoveStartTime", SqlDbType.DateTime, startTime); BuildSqlParameter(sqlCmd, "@RegisterMoveId", SqlDbType.Int, ParameterDirection.ReturnValue); if (sqlCmd.ExecuteNonQuery() > 0) { result = new RegisterMove(Convert.ToInt32(sqlCmd.Parameters["@RegisterMoveId"].Value), registerDrawerId, sourceRegisterId, sourceRegisterSubId, startTime, null, null, null); } } FinishedWithConnection(cn); return(result); }
/// <summary> /// Update an entry in the RegisterMove table /// </summary> public static bool Update(RegisterMove registerMove) { bool result = false; SqlConnection cn = GetConnection(); result = Update(cn, registerMove); FinishedWithConnection(cn); return(result); }
/// <summary> /// Get an entry from the RegisterMove table /// </summary> public static RegisterMove Get(int id) { RegisterMove result = null; SqlConnection cn = GetConnection(); result = Get(cn, id); FinishedWithConnection(cn); return(result); }
private static RegisterMove Get(SqlConnection cn, int id) { RegisterMove result = null; using (SqlCommand cmd = new SqlCommand("SELECT * FROM RegisterMove WHERE RegisterMoveId=" + id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildRegisterMove(rdr); } } } return(result); }
private static bool Update(SqlConnection cn, RegisterMove registerMove) { Int32 rowsAffected = 0; using (SqlCommand sqlCmd = cn.CreateCommand()) { sqlCmd.CommandText = "UPDATE RegisterMove SET RegisterMoveRegisterDrawerId=@RegisterMoveRegisterDrawerId,RegisterMoveSourceRegisterId=@RegisterMoveSourceRegisterId,RegisterMoveSourceRegisterSubId=@RegisterMoveSourceRegisterSubId,RegisterMoveStartTime=@RegisterMoveStartTime,RegisterMoveTargetRegisterId=@RegisterMoveTargetRegisterId,RegisterMoveTargetRegisterSubId=@RegisterMoveTargetRegisterSubId,RegisterMoveEndTime=@RegisterMoveEndTime WHERE RegisterMoveId=@RegisterMoveId"; BuildSqlParameter(sqlCmd, "@RegisterMoveId", SqlDbType.Int, registerMove.Id); BuildSqlParameter(sqlCmd, "@RegisterMoveRegisterDrawerId", SqlDbType.Int, registerMove.RegisterDrawerId); BuildSqlParameter(sqlCmd, "@RegisterMoveSourceRegisterId", SqlDbType.TinyInt, registerMove.SourceRegisterId); BuildSqlParameter(sqlCmd, "@RegisterMoveSourceRegisterSubId", SqlDbType.TinyInt, registerMove.SourceRegisterSubId); BuildSqlParameter(sqlCmd, "@RegisterMoveStartTime", SqlDbType.DateTime, registerMove.StartTime); BuildSqlParameter(sqlCmd, "@RegisterMoveTargetRegisterId", SqlDbType.TinyInt, registerMove.TargetRegisterId); BuildSqlParameter(sqlCmd, "@RegisterMoveTargetRegisterSubId", SqlDbType.TinyInt, registerMove.TargetRegisterSubId); BuildSqlParameter(sqlCmd, "@RegisterMoveEndTime", SqlDbType.DateTime, registerMove.EndTime); rowsAffected = sqlCmd.ExecuteNonQuery(); } return(rowsAffected != 0); }
/// <summary> /// Gets the open (no target specified) RegisterMove for the spcified employee id /// </summary> /// <param name="employeeId"></param> /// <returns></returns> public static RegisterMove GetOpen(int employeeId) { RegisterDrawer registerDrawer = RegisterDrawer.GetFloating(employeeId); if (registerDrawer == null) { return(null); } RegisterMove result = null; SqlConnection cn = GetConnection(); using (SqlCommand cmd = new SqlCommand("SELECT * FROM RegisterMove WHERE (RegisterMoveEndTime IS NULL) AND RegisterMoveRegisterDrawerId=" + registerDrawer.Id, cn)) { using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { result = BuildRegisterMove(rdr); } } } FinishedWithConnection(cn); return(result); }