private void InsertInitialJobStatus() { JobStatus submittedStatus = JobStatus.Submitted; int submittedStatusId = submittedStatus.JobStatusId; //int jobStatusChangeId = ClientData.Current.InsertJobStatusChange(newJob.JobId, submittedStatusId, newJob.DateSubmitted); JobStatusChange change = JobStatusChange.InsertJobStatusChange(newJob, JobStatus.Submitted, newJob.DateSubmitted); if (change == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job status change is null.")); } }
private void InsertSegment() { DateTime nowUtc = DateTime.UtcNow; string notes = this.txtSegmentNotesForStart.Text.Trim(); // insert job segment JobSegment segment = JobSegment.InsertJobSegment(curJob, curEmployee, nowUtc, notes); if (segment == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job segment to database.")); } // insert job status change JobStatusChange change = JobStatusChange.InsertJobStatusChange(curJob, JobStatus.InProgress, nowUtc); if (change == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job status change.")); } }
private void UpdateSegment() { if (curSegment == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Current segment is null.")); } DateTime startTime = DateTime.Parse(this.txtTimeStarted.Text); startTime = AdminUtils.UtcOfEmployeeDate(startTime, curEmployee); DateTime stopTime = DateTime.Parse(this.txtTimeStopped.Text); stopTime = AdminUtils.UtcOfEmployeeDate(stopTime, curEmployee); int minutesWorked = Convert.ToInt32(Convert.ToDecimal(this.txtHoursWorked.Text) * 60m); //(int) Math.Round(nowUtc.Subtract(curSegment.StartDate).TotalMinutes); // make new segment, so we can test for null -- necessary ?? JobSegment newSegment = curSegment.UpdateJobSegment(startTime, stopTime, minutesWorked, this.txtSegmentNotesForStop.Text.Trim()); if (newSegment == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job segment.")); } // assign successful result curSegment = newSegment; // update job status JobStatus newStatus = JobStatus.JobStatusFromId(Convert.ToInt32(this.ddStatuses.SelectedValue)); bool statusChanged = !newStatus.Equals(curJob.JobStatus); if (statusChanged) { JobStatusChange change = JobStatusChange.InsertJobStatusChange(curJob, newStatus, DateTime.UtcNow); if (change == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job status change.")); } if (newStatus.IsAClosedStatus()) { // update the job to insert completion date Job newJob = curJob.ShallowCopy(); DateTime dateCompleted = Convert.ToDateTime(this.txtTimeStopped.Text); dateCompleted = AdminUtils.UtcOfEmployeeDate(dateCompleted, curEmployee); newJob.DateCompleted = dateCompleted; bool ret = ClientData.Current.UpdateJob(newJob.BillingReference, newJob.JobType.JobTypeId, newJob.ToApplication, newJob.Formatted, newJob.Proofread, newJob.DateDue, newJob.DateCompleted, newJob.Instructions, newJob.Estimate, newJob.FinalCharge, newJob.Taxes, newJob.DeliveryNotes, newJob.IsArchived, newJob.JobId); if (!ret) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job in database.")); } // update cached job List <Job> jobsInCache = CacheLayer.RecentJobs(); int index = jobsInCache.IndexOf(curJob); if (index != -1) { jobsInCache.Remove(curJob); jobsInCache.Insert(index, newJob); } // replace global ref curJob = newJob; } } }
private void UpdateJob() { Job newJob = curJob.ShallowCopy(); // copy to new Job in case db update fails // (we don't want to update the cached job in that case) // check fields // job type int selectedJobTypeId = Convert.ToInt32(this.ddJobTypes.SelectedValue); JobType jobType = JobType.JobTypeFromId(selectedJobTypeId); // new job status int newJobStatusId = Convert.ToInt32(this.ddStatuses.SelectedValue); JobStatus newJobStatus = JobStatus.JobStatusFromId(newJobStatusId); bool statusChanged = !curJob.JobStatus.Equals(newJobStatus); // date due DateTime dateDue = Convert.ToDateTime(this.txtDateDue.Text); // convert to utc dateDue = AdminUtils.UtcOfEmployeeDate(dateDue, curAdmin); newJob.DateDue = dateDue; // billing ref newJob.BillingReference = txtBillingRef.Text; // job type newJob.JobType = jobType; // job type options newJob.ToApplication = this.txtToApplication.Text.Trim(); newJob.Formatted = this.chkFormatted.Checked; newJob.Proofread = this.chkProofed.Checked; // date completed object objDateCompleted = null; if (!String.IsNullOrEmpty(this.txtDateCompleted.Text.Trim())) { DateTime dateCompleted = Convert.ToDateTime(this.txtDateCompleted.Text); // to utc dateCompleted = AdminUtils.UtcOfEmployeeDate(dateCompleted, curAdmin); newJob.DateCompleted = dateCompleted; objDateCompleted = dateCompleted; } else { newJob.DateCompleted = DateTime.MinValue; } // instructions newJob.Instructions = this.txtInstructions.Text.Trim(); // estimate newJob.Estimate = Convert.ToDecimal(this.txtEstimate.Text.Replace("$", "")); // final charge newJob.FinalCharge = Convert.ToDecimal(this.txtFinalCharge.Text.Replace("$", "")); // taxes newJob.Taxes = Convert.ToDecimal(this.txtTaxes.Text.Replace("$", "")); // delivery notes newJob.DeliveryNotes = txtNotes.Text.Trim(); // archive newJob.IsArchived = chkArchive.Checked; // to do - newJob.PickedUp - no, done in /clients/job.aspx, right ?? // date for status change DateTime nowUtc = DateTime.UtcNow; bool ret = ClientData.Current.UpdateJob(newJob.BillingReference, newJob.JobType.JobTypeId, newJob.ToApplication, newJob.Formatted, newJob.Proofread, newJob.DateDue, objDateCompleted, newJob.Instructions, newJob.Estimate, newJob.FinalCharge, newJob.Taxes, newJob.DeliveryNotes, newJob.IsArchived, newJob.JobId); if (!ret) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job in database.")); } // changed status if (statusChanged) { //int jobStatusChangeId = ClientData.Current.InsertJobStatusChange(newJob.JobId, newJobStatusId, nowUtc); JobStatusChange change = JobStatusChange.InsertJobStatusChange(newJob, newJobStatus, nowUtc); if (change == null) { throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job status change is null.")); } } // update cached job List <Job> jobsInCache = CacheLayer.RecentJobs(); int index = jobsInCache.IndexOf(curJob); if (index != -1) { jobsInCache.Remove(curJob); jobsInCache.Insert(index, newJob); } // replace global ref curJob = newJob; pnlUpdated.Visible = true; }