コード例 #1
0
        private CompleteJobResult CompleteCstJob(ProductionJob editJob)
        {
            var itm = (from i in PrdnDBContext.PrdnInvItems
                       where i.SerialNo == editJob.SerialNo
                       select new { i.SerialNo }).FirstOrDefault();

            if (itm != null)
            {
                return new CompleteCstJobResult(ActionUpdateType.Invalid) { InvItemID = editJob.PrdnInvItem.InvItemID };
            }

            EnsurePrdnDBContextOpen();
            using (var transaction = PrdnDBContext.Connection.BeginTransaction())
            {
                try
                {
                    decimal invItemID = 0m;
                    PrdnDBContext.ExecuteStoreCommand(@"BEGIN FG_CREATE_ITEM_FROM_PRDN_JOB(:p0, :p1); END;", invItemID, editJob.ID);

                    if (editJob.Status != PrdnJobStatus.Completed)
                    {
                        editJob.UpdateStatus(PrdnJobStatus.Completed, GetCurrentUserID());
                        PrdnDBContext.SaveChanges();
                    }

                    transaction.Commit();
                    return new CompleteCstJobResult(ActionUpdateType.Success) { InvItemID = editJob.PrdnInvItem.InvItemID };
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    return new CompleteCstJobResult(ActionUpdateType.Exception, "Error Saving Job " + ex.Message);
                }
            }
        }
コード例 #2
0
        private ActionUpdateResult AddNewJobFromViewModel(EditPrdnJobViewModel newViewJob, IEnumerable<HttpPostedFileBase> uploadedFiles, out ProductionJob addedJob,
            Action<EditPrdnJobViewModel, ProductionJob> extraSaveProc=null)
        {
            addedJob = null;

            ProcessAttacherForSave(newViewJob.Attacher, uploadedFiles);

            JobModelValidate(newViewJob);
            if (ModelState.IsValid)
            {
                EnsurePrdnDBContextOpen();
                using (var transaction = PrdnDBContext.Connection.BeginTransaction())
                {
                    try
                    {
                        newViewJob.RunSeqNo = PrdnDBContext.NextRunSequence(newViewJob.RunID);
                        newViewJob.SerialNo = PrdnDBContext.NextSerialStr();

                        ProductionJob newJob = new ProductionJob(DateTime.Now, GetCurrentUserID());

                        Mapper.Map<EditPrdnJobViewModel, ProductionJob>(newViewJob, newJob);

                        newJob.UpdateStatus((PrdnJobStatus)newViewJob.EditStatus, GetCurrentUserID());

                        PrdnDBContext.ProductionJobs.AddObject(newJob);

                        UpdateJobWorksheet(newJob, newViewJob);

                        UpdateJobAttachments(newJob, newViewJob.Attacher);

                        PrdnDBContext.SaveChanges();
                        if (extraSaveProc != null) {
                            extraSaveProc(newViewJob, newJob);
                        }

                        if ((newViewJob.EditRunSeqNo != null) && (newJob.RunSeqNo != newViewJob.EditRunSeqNo))
                        {
                            InsertRunSeqs(PrdnDBContext, newJob, (int)newViewJob.EditRunSeqNo);
                        }
                        ReSequenceRun(newJob.RunID);

                        transaction.Commit();

                        addedJob = newJob;

                        return new ActionUpdateResult(ActionUpdateType.Success);
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return new ActionUpdateResult(ActionUpdateType.Exception, ex.Message);
                    }
                }
            }
            else
            {
                loadViewJobForPost(newViewJob);
                return new ActionUpdateResult(ActionUpdateType.Invalid);
            }
        }