コード例 #1
0
        public void SavePhysicalCount(PhysicalCountInfo physicalCount)
        {
            PhysicalCountInfo originalPhysicalCount = OpenPhysicalCount(physicalCount.Id);
            AuditTrailWrapper atw = new AuditTrailWrapper(AuditTrailWrapper.InvCount,
                                                          new object[][] { new object[] { originalPhysicalCount, physicalCount, AuditTrailWrapper.ExistingRecord } }, "Inventory Control");

            foreach (PhysicalCountInspectorInfo inspector in physicalCount.Inspectors)
            {
                PhysicalCountInspectorInfo originalInspector = originalPhysicalCount.Inspectors.Find(oi => oi.Id == inspector.Id);
                if (originalInspector == null)
                {
                    atw.AddChange(null, inspector, AuditTrailWrapper.NewRecord);
                }
                else
                {
                    atw.AddChange(originalInspector, inspector, AuditTrailWrapper.ExistingRecord);
                }
            }
            foreach (StackPhysicalCountInfo stack in originalPhysicalCount.Stacks)
            {
                StackPhysicalCountInfo originalStack = physicalCount.Stacks.Find(os => os.Id == stack.Id);
                if (originalStack == null)
                {
                    atw.AddChange(null, stack, AuditTrailWrapper.NewRecord);
                }
                else
                {
                    atw.AddChange(originalStack, stack, AuditTrailWrapper.ExistingRecord);
                }
            }

            Dictionary <string, object> contextParameters = new Dictionary <string, object>();

            contextParameters.Add("CurrentUser", new Guid(SystemLookup.LookupSource.GetLookup("CurrentUser")["Id"]));
            Queue <object> queue = new Queue <object>(new object[] { physicalCount });

            foreach (PhysicalCountInspectorInfo inspector in physicalCount.Inspectors)
            {
                queue.Enqueue(inspector);
            }
            foreach (StackPhysicalCountInfo stack in physicalCount.Stacks)
            {
                queue.Enqueue(stack);
            }
            try
            {
                SqlTransaction transaction = PersistenceTransactionFactory.CreatePersistenceTransaction().Persist(
                    queue, contextParameters);
                if (!atw.Save())
                {
                    transaction.Rollback();
                    throw new Exception("Failed to save audit trail!");
                }
                transaction.Commit();
            }
            catch (Exception ex)
            {
                throw new Exception("Physical Count couldn't be saved to the database", ex);
            }
        }
コード例 #2
0
        public void AddStackPhysicalCount(PhysicalCountInfo physicalCount, StackPhysicalCountInfo stackPhysicalCount)
        {
            if (physicalCount.Stacks.Any(s => (s.StackId == stackPhysicalCount.StackId)))
            {
                throw new Exception("Invalid Stack Count : Stack count shall not be duplicated");
            }
            Dictionary <string, object> contextParameters = new Dictionary <string, object>();

            contextParameters.Add("StackId", stackPhysicalCount.StackId);
            contextParameters.Add("PhysicalCountId", stackPhysicalCount.PhysicalCountId);
            try
            {
                XmlSerializer s        = new XmlSerializer(typeof(StackInventoryStatusInfo));
                XmlDocument   document = PersistenceTransactionFactory.CreatePersistenceTransaction().Open(
                    "spGetStackInventoryStatus", contextParameters);
                StringBuilder sb     = new StringBuilder();
                TextWriter    writer = new StringWriter(sb);
                document.Save(writer);

                StackInventoryStatusInfo sis = (StackInventoryStatusInfo)s.Deserialize(new StringReader(sb.ToString()));
                stackPhysicalCount.CummulatedShortage = sis.CummulatedShortage;
                stackPhysicalCount.CumulatedOverage   = sis.CumulatedOverage;
                stackPhysicalCount.ExpectedBalance    = sis.ExpectedBalance;
            }
            catch (Exception ex)
            {
                throw new Exception("The database failed to load a required Stack Inventory Status ", ex);
            }
            physicalCount.Stacks.Add(stackPhysicalCount);
        }
コード例 #3
0
 public void Copy(StackPhysicalCountInfo stack)
 {
     Id = stack.Id;
     PhysicalCountId    = stack.PhysicalCountId;
     ShedId             = stack.ShedId;
     StackId            = stack.StackId;
     ExpectedBalance    = stack.ExpectedBalance;
     Balance            = stack.Balance;
     CummulatedShortage = stack.CummulatedShortage;
     CumulatedOverage   = stack.CumulatedOverage;
 }