예제 #1
0
        public TimeKeepEntry Create()
        {
            // Validate
            if (string.IsNullOrEmpty(User) || string.IsNullOrWhiteSpace(User))
            {
                throw new ArgumentNullException("user");
            }

            if (ID.HasValue)
            {
                if (Category == null)
                {
                    throw new ArgumentNullException("category");
                }

                if (Category.IsScorecard && (string.IsNullOrEmpty(CaseNumber) || string.IsNullOrWhiteSpace(CaseNumber)))
                {
                    throw new ArgumentNullException("category", "Parameter cannot be null if the labor is a scorecard labor");
                }

                if (!Category.IsScorecard && !string.IsNullOrEmpty(CaseNumber) && !string.IsNullOrEmpty(CaseNumber))
                {
                    throw new ArgumentException("Cannot specify a case number for non-scorecard labor");
                }
            }


            DataAccess dal = new DataAccess("TimeKeepEntries");
            // This is supposed to return the altered and the new row
            TimeKeepEntry newEntry = null, modifiedEntry = null;

            using (IDataReader reader = dal.Create(
                       new Dictionary <string, object>
            {
                ["@RowID"] = (ID.HasValue ? (object)ID.Value : DBNull.Value),
                ["@User"] = User.Trim(),
                ["@Category"] = (Category == null ? DBNull.Value : (object)Category.ID),
                ["@CaseNumber"] = (CaseNumber == null ? DBNull.Value : (object)CaseNumber.Trim())
            }
                       ))
            {
                newEntry      = ReadOneFromDataReader(reader);
                modifiedEntry = ReadOneFromDataReader(reader);
            }

            this.ID         = newEntry.ID;
            this.User       = newEntry.User;
            this.IsDetailed = newEntry.IsDetailed;
            this.IsLogged   = newEntry.IsLogged;
            this.StartTime  = newEntry.StartTime;
            this.CaseNumber = newEntry.CaseNumber;
            this.Category   = newEntry.Category;
            this.EndTime    = newEntry.EndTime;

            return(modifiedEntry);
        }
예제 #2
0
        public void Update()
        {
            // Validate
            if (string.IsNullOrEmpty(User) || string.IsNullOrWhiteSpace(User))
            {
                throw new ArgumentNullException("user");
            }

            if (Category == null)
            {
                throw new ArgumentNullException("category");
            }

            if (Category.IsScorecard && (string.IsNullOrEmpty(CaseNumber) || string.IsNullOrWhiteSpace(CaseNumber)))
            {
                throw new ArgumentNullException("category", "Parameter cannot be null if the labor is a scorecard labor");
            }

            if (!Category.IsScorecard && !string.IsNullOrEmpty(CaseNumber) && !string.IsNullOrEmpty(CaseNumber))
            {
                throw new ArgumentException("Cannot specify a case number for non-scorecard labor");
            }

            if (EndTime.HasValue && EndTime <= StartTime)
            {
                throw new ArgumentOutOfRangeException("EndTime", "The end time must be after the start time");
            }

            DataAccess    dal          = new DataAccess("TimeKeepEntries");
            TimeKeepEntry modifiedItem = null;

            using (IDataReader reader = dal.Update(
                       new Dictionary <string, object>
            {
                ["@RowID"] = this.ID,
                ["@StartTime"] = this.StartTime,
                ["@EndTime"] = (object)this.EndTime ?? DBNull.Value,
                ["@Category"] = this.Category == null ? DBNull.Value : (object)this.Category.ID,
                ["@CaseNumber"] = (string.IsNullOrEmpty(CaseNumber) || string.IsNullOrWhiteSpace(CaseNumber)) ? DBNull.Value : (object)this.CaseNumber
            }
                       ))
            {
                modifiedItem = ReadOneFromDataReader(reader);
            }

            this.ID         = modifiedItem.ID;
            this.CaseNumber = modifiedItem.CaseNumber;
            this.Category   = modifiedItem.Category;
            this.EndTime    = modifiedItem.EndTime;
            this.IsDetailed = modifiedItem.IsDetailed;
            this.IsLogged   = modifiedItem.IsLogged;
            this.StartTime  = modifiedItem.StartTime;
            this.User       = modifiedItem.User;
        }
예제 #3
0
        public void ToggleIsLogged()
        {
            DataAccess    dal          = new DataAccess("TimeKeepEntries");
            TimeKeepEntry modifiedItem = null;

            using (IDataReader reader = dal.UpdateFilter("IsLogged", new Dictionary <string, object> {
                ["@RowID"] = this.ID
            }))
            {
                modifiedItem = ReadOneFromDataReader(reader);
            }

            this.ID         = modifiedItem.ID;
            this.CaseNumber = modifiedItem.CaseNumber;
            this.Category   = modifiedItem.Category;
            this.EndTime    = modifiedItem.EndTime;
            this.IsDetailed = modifiedItem.IsDetailed;
            this.IsLogged   = modifiedItem.IsLogged;
            this.StartTime  = modifiedItem.StartTime;
            this.User       = modifiedItem.User;
        }