public static JobSegment InsertJobSegment(Job job, Employee employee, DateTime startDate, string notes) { int jobSegmentId = ClientData.Current.InsertJobSegment(job.JobId, employee.EmployeeId, startDate, notes); if (jobSegmentId == 0) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to insert job segment into database.")); } JobSegment segment = new JobSegment(); segment.JobSegmentId = jobSegmentId; segment.Job = job; segment.JobId = job.JobId; segment.Employee = employee; segment.EmployeeId = employee.EmployeeId; segment.StartDate = startDate; segment.Notes = notes; segment.MinutesWorked = 0; if (job.JobSegments == null) { job.JobSegments = new List <JobSegment>(); } job.JobSegments.Add(segment); return(segment); }
public static List <JobSegment> JobSegmentsForJob(Job job) { DataTable dtSegmentsForJob = ClientData.Current.JobSegmentsForJobDataTable(job.JobId); List <JobSegment> segments = new List <JobSegment>(); foreach (DataRow drSegment in dtSegmentsForJob.Rows) { JobSegment segment = new JobSegment(); segment.SetFieldsFromDataRow(drSegment); segment.Job = job; //if (job.JobSegments == null) // job.JobSegments = new List<JobSegment>(); //job.JobSegments.Add(segment); segments.Add(segment); } return(segments); }
private void SetFieldsFromDataRow(DataRow drJob) { object temp; this.JobId = (int)drJob["JobId"]; this.ClientId = (int)drJob["ClientId"]; this.BillingReference = drJob["BillingReference"].ToString(); //this.JobStatusId = (int)drJob["JobStatusId"]; this.JobTypeId = (int)drJob["JobTypeId"]; this.ToApplication = drJob["ToApplication"].ToString(); this.Formatted = (bool)drJob["Formatted"]; this.Proofread = (bool)drJob["Proofread"]; this.DateDue = Convert.ToDateTime(drJob["DateDue"]); this.OriginalDateDue = Convert.ToDateTime(drJob["OriginalDateDue"]); this.DateSubmitted = Convert.ToDateTime(drJob["DateSubmitted"]); if ((temp = drJob["DateCompleted"]) != DBNull.Value) { this.DateCompleted = Convert.ToDateTime(temp); } else { this.DateCompleted = DateTime.MinValue; } this.Instructions = drJob["Instructions"].ToString(); this.Estimate = (decimal)drJob["Estimate"]; this.FinalCharge = (decimal)drJob["FinalCharge"]; this.Taxes = (decimal)drJob["Taxes"]; this.PickedUp = (bool)drJob["PickedUp"]; this.DeliveryNotes = drJob["DeliveryNotes"].ToString(); this.IsArchived = (bool)drJob["IsArchived"]; if ((temp = drJob["InvoiceId"]) != DBNull.Value) { this.InvoiceId = (int)temp; } else { this.InvoiceId = 0; } // get jobtype - no circular calls this.JobType = JobType.JobTypeFromId(this.JobTypeId); // don't need parent objects (Client, Invoice) at this point // that would cause circular calls // set those later, depending on what is calling // get child objects // that are relevant only in the context of a Job. this.JobStatusChanges = JobStatusChange.JobStatusChangesForJob(this); this.JobSegments = JobSegment.JobSegmentsForJob(this); //JobFile.JobFilesForJob(this); List <JobFile> files = JobFile.JobFilesForJob(this); foreach (JobFile file in files) { if (file.IsReturnedFile) { if (this.ReturnedFiles == null) { this.ReturnedFiles = new List <JobFile>(); } this.ReturnedFiles.Add(file); } else if (file.IsSubmittedFile) { if (this.SubmittedFiles == null) { this.SubmittedFiles = new List <JobFile>(); } this.SubmittedFiles.Add(file); } else // working { if (this.WorkingFiles == null) { this.WorkingFiles = new List <JobFile>(); } this.WorkingFiles.Add(file); } } }