Beispiel #1
0
        private void SaveFiles()
        {
            // create directory
            //HesterConsultants.Properties.Settings settings =
            //    HesterConsultants.Properties.Settings.Default;

            // job files virtual root
            string jobFilesRootVirtual = Settings.Default.JobFilesRoot;

            if (!jobFilesRootVirtual.EndsWith(@"/"))
            {
                jobFilesRootVirtual += @"/";
            }

            // get local path
            string jobFilesRootLocal = this.Server.MapPath(jobFilesRootVirtual);

            if (!jobFilesRootLocal.EndsWith(@"\"))
            {
                jobFilesRootLocal += @"\";
            }

            DirectoryInfo jobInFolder = Directory.CreateDirectory(jobFilesRootLocal + newJob.JobId.ToString() + @"\in"); // "in" for submitted files

            // six file upload controls
            for (int k = 1; k <= 6; k++)
            {
                FileUpload fu = (FileUpload)this.FindControl("file" + k.ToString());
                if (fu.HasFile)
                {
                    string filename = HesterConsultants.AppCode.SiteUtils.WindowsSafeFilename(fu.FileName);

                    // adjust filename if necessary
                    filename = HesterConsultants.AppCode.SiteUtils.ConflictFreeFilename(jobInFolder.FullName, filename, Settings.Default.FilenameAppendedDigitsMax);
                    string virtualPath = jobFilesRootVirtual + newJob.JobId.ToString() + @"/in/" + filename;

                    try
                    {
                        fu.SaveAs(jobInFolder.FullName + @"\" + filename);
                    }
                    catch (Exception ex)
                    {
                        ClientData.Current.LogErrorAndSendAlert(ex);
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to save file."));
                    }

                    //int jobFileId = ClientData.Current.InsertJobFile(newJob.JobId, filename, virtualPath, false, true);

                    //if (jobFileId == 0)
                    //    throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job file to database."));

                    JobFile jobFile = JobFile.InsertJobFile(newJob, filename, virtualPath, false, true);

                    if (jobFile == null)
                    {
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job file is null."));
                    }
                }
            }
        }
Beispiel #2
0
        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 JobStatusChange InsertJobStatusChange(Job job, JobStatus jobStatus, DateTime dateOfChange)
        {
            JobStatusChange change = null;

            int changeId = ClientData.Current.InsertJobStatusChange(job.JobId, jobStatus.JobStatusId, dateOfChange);

            if (changeId == 0)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job status change to database."));
            }

            change = new JobStatusChange();
            change.JobStatusChangeId = changeId;
            change.Job         = job;
            change.JobId       = job.JobId;
            change.JobStatus   = jobStatus;
            change.JobStatusId = jobStatus.JobStatusId;
            change.Date        = dateOfChange;

            if (job.JobStatusChanges == null)
            {
                job.JobStatusChanges = new List <JobStatusChange>();
            }

            job.JobStatusChanges.Add(change);

            return(change);
        }
Beispiel #4
0
 private void InsertNewClientToken()
 {
     try
     {
         token = ClientData.Current.InsertNewClientToken(authUserId);
     }
     catch (Exception ex)
     {
         throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to insert new client token in database. " + ex));
     }
 }
Beispiel #5
0
        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."));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Inserts JobFile and relates it to Job. Returns the JobFile or null.
        /// </summary>
        /// <param name="job"></param>
        /// <param name="filename"></param>
        /// <param name="path"></param>
        /// <param name="isReturnedFile"></param>
        /// <param name="isSubmittedFile"></param>
        /// <returns></returns>
        public static JobFile InsertJobFile(Job job, string filename, string path, bool isReturnedFile, bool isSubmittedFile)
        {
            JobFile jobFile = null;

            int jobFileId = ClientData.Current.InsertJobFile(job.JobId, filename, path, isReturnedFile, isSubmittedFile);

            if (jobFileId == 0)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to add job file to database."));
            }

            jobFile                 = new JobFile();
            jobFile.JobFileId       = jobFileId;
            jobFile.Job             = job;
            jobFile.JobId           = job.JobId;
            jobFile.Name            = filename;
            jobFile.Path            = path;
            jobFile.IsReturnedFile  = isReturnedFile;
            jobFile.IsSubmittedFile = isSubmittedFile;

            if (jobFile.IsReturnedFile)
            {
                if (job.ReturnedFiles == null)
                {
                    job.ReturnedFiles = new List <JobFile>();
                }

                job.ReturnedFiles.Add(jobFile);
            }
            else if (jobFile.IsSubmittedFile)
            {
                if (job.SubmittedFiles == null)
                {
                    job.SubmittedFiles = new List <JobFile>();
                }

                job.SubmittedFiles.Add(jobFile);
            }
            else
            {
                if (job.WorkingFiles == null)
                {
                    job.WorkingFiles = new List <JobFile>();
                }

                job.WorkingFiles.Add(jobFile);
            }

            return(jobFile);
        }
Beispiel #7
0
        public JobSegment UpdateJobSegment(DateTime startDate, DateTime endDate, int minutesWorked, string notes)
        {
            bool ret = ClientData.Current.UpdateJobSegment(startDate, endDate, minutesWorked, notes, this.JobSegmentId);

            if (ret == false)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to update job segment in database."));
            }

            this.StartDate     = startDate;
            this.EndDate       = endDate;
            this.MinutesWorked = minutesWorked;
            this.Notes         = notes;

            return(this);
        }
 private void TransmitFile()
 {
     if (jobFile != null)
     {
         if (!jobFile.Job.IsArchived)
         {
             this.Response.AppendHeader("Content-Disposition", "attachment; filename=" + jobFile.Name);
             this.Response.TransmitFile(this.Server.MapPath(jobFile.Path));
         }
         else
         {
             throw new Exception(SiteUtils.ExceptionMessageForCustomer("File is archived or removed per file retention policy."));
         }
     }
     //this.Response.End();
     HttpContext.Current.ApplicationInstance.CompleteRequest();
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (curClient == null)
            {
                return;
            }

            //this.Response.Cache.SetCacheability(HttpCacheability.NoCache); // messes up ie
            this.Response.ContentType = "application/octet-stream";

            string qs = this.Request.QueryString["fileId"];

            if (!String.IsNullOrEmpty(qs))
            {
                fileId = Convert.ToInt32(qs);
            }
            else
            {
                return;
            }

            GetSelectedFile();

            if (jobFile == null)
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to retrieve file."));
            }

            if (CheckSelectedFileIsForClient())
            {
                if (jobFile.Job.IsArchived)
                {
                    throw new Exception(SiteUtils.ExceptionMessageForCustomer("File is archived or removed per file retention policy."));
                }
                else
                {
                    TransmitFile();
                }
            }
            else
            {
                throw new Exception(SiteUtils.ExceptionMessageForCustomer("File does not show requesting client as owner."));
            }
        }
Beispiel #10
0
        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."));
            }
        }
Beispiel #11
0
        public bool Delete()
        {
            bool ret = ClientData.Current.DeleteJobFile(this.JobFileId);

            if (ret)
            {
                string physicalPath    = HttpContext.Current.Server.MapPath(this.Path);
                string trashPath       = HttpContext.Current.Server.MapPath(Settings.Default.TrashFolder);
                string safeName        = SiteUtils.ConflictFreeFilename(trashPath, this.Name, 2);
                string fileInTrashPath = trashPath + @"\" + safeName;

                try
                {
                    FileInfo fi = new FileInfo(physicalPath);
                    fi.MoveTo(fileInTrashPath);
                }
                catch
                {
                    throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to delete file."));
                }
            }

            return(ret);
        }
Beispiel #12
0
        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;
                }
            }
        }
Beispiel #13
0
        private void SaveFiles()
        {
            filesChanged = true;

            // get or create directory

            // virtual jobfiles root
            string jobFilesRootVirtual = Settings.Default.JobFilesRoot;

            if (!jobFilesRootVirtual.EndsWith(@"/"))
            {
                jobFilesRootVirtual += @"/";
            }

            // get local path
            string jobFilesRootLocal = this.Server.MapPath(jobFilesRootVirtual);

            // file upload controls
            for (int j = 0; j < 2; j++)
            {
                JobFile.JobFileType fileType;
                string whichFileControl;
                string whichDirectory;

                if (j == 0)
                {
                    fileType         = JobFile.JobFileType.Returned;
                    whichFileControl = "returnFile";
                    whichDirectory   = "out";
                }
                else if (j == 1)
                {
                    fileType         = JobFile.JobFileType.Working;
                    whichFileControl = "workingFile";
                    whichDirectory   = "working";
                }
                else
                {
                    fileType         = JobFile.JobFileType.Submitted;
                    whichFileControl = "submittedFile";
                    whichDirectory   = "in";
                }


                FileUpload fu = (FileUpload)this.FindControl(whichFileControl + "1");
                if (fu.HasFile)
                {
                    DirectoryInfo fileFolder = Directory.CreateDirectory(jobFilesRootLocal + @"\" + jobId.ToString() + @"\" + whichDirectory);

                    string filename = HesterConsultants.AppCode.SiteUtils.WindowsSafeFilename(fu.FileName);

                    // adjust filename if necessary
                    filename = HesterConsultants.AppCode.SiteUtils.ConflictFreeFilename(fileFolder.FullName, filename, Settings.Default.FilenameAppendedDigitsMax);

                    string virtualPath = jobFilesRootVirtual + jobId.ToString() + @"/" + whichDirectory + @"/" + filename;

                    // save file
                    try
                    {
                        fu.SaveAs(fileFolder.FullName + @"\" + filename);
                    }
                    catch (Exception ex)
                    {
                        ClientData.Current.LogErrorAndSendAlert(ex);
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Failed to save file."));
                    }

                    JobFile jobFile = JobFile.InsertJobFile(curJob, filename, virtualPath, (fileType == JobFile.JobFileType.Returned), (fileType == JobFile.JobFileType.Submitted));

                    if (jobFile == null)
                    {
                        throw new Exception(SiteUtils.ExceptionMessageForCustomer("Job file is null."));
                    }
                }
            }
        }
        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;
        }