コード例 #1
0
 public bool IsWRNItemDeleted(Guid wrnItemId)
 {
     using (var context = new SCMSEntities())
     {
         Model.WarehouseReleaseItem wrnitm = context.WarehouseReleaseItems.FirstOrDefault(p => p.Id == wrnItemId);
         string itemCategory = context.Inventories.FirstOrDefault(p => p.Id == wrnitm.InventoryId).Item.ItemCategory.CategoryCode;
         if (itemCategory.Equals("A"))
         {
             wrnitm.Quantity = 1;
             Model.Asset ass = context.Assets.FirstOrDefault(p => p.Id == wrnitm.AssetId);
             ass.IsReleased     = false;
             ass.CurrentOwnerId = null;
             ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(ass, System.Data.EntityState.Modified);
         }
         Model.Inventory inv = context.Inventories.First(p => p.Id == wrnitm.InventoryId);
         inv.Quantity += (Int64)wrnitm.Quantity;
         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(inv, System.Data.EntityState.Modified);
         context.WarehouseReleaseItems.Remove(wrnitm);
         int affectedColumns = context.SaveChanges();
         SessionData.CurrentSession.ReleaseOrderList     = null;
         SessionData.CurrentSession.ReleaseOrderItemList = null;
         SessionData.CurrentSession.AssetList            = null;
         SessionData.CurrentSession.InventoryList        = null;
         return(affectedColumns > 0 ? true : false);
     }
 }
コード例 #2
0
ファイル: WayBillService.cs プロジェクト: rjakech/SCMS
 public bool ReceiveWB(Model.WayBill entity, List <WarehouseReleaseItem> writemList)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 StringBuilder msg = new StringBuilder();
                 Model.WayBill wb  = context.WayBills.First(p => p.Id == entity.Id);
                 wb.ReceivedBy                  = entity.ReceivedBy;
                 wb.ArrivalDate                 = entity.ArrivalDate;
                 wb.RecvDRCVehicleOdometer      = entity.RecvDRCVehicleOdometer;
                 wb.RecvDRCVehicleTotalDistance = entity.RecvDRCVehicleTotalDistance;
                 wb.RecvDstnationOfficeId       = entity.RecvDstnationOfficeId;
                 wb.IsReceived                  = true;
                 ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(wb, System.Data.EntityState.Modified);
                 int count = 0;
                 foreach (WarehouseReleaseItem item in writemList)
                 {
                     Model.WarehouseReleaseItem it = context.WarehouseReleaseItems.First(p => p.Id == item.Id);
                     if (it.Quantity > item.QuantityReceived)
                     {
                         count++;
                         msg.Append(string.Format("{0}.  Item Name: {1}\t\tIssued Qty: {2}\tQty Received: {3}\tQty damaged: {4}\n", count, it.Inventory.Item.Name, it.Quantity, item.QuantityReceived, item.QuantityDamaged));
                     }
                     it.QuantityReceived = item.QuantityReceived;
                     it.QuantityDamaged  = item.QuantityDamaged;
                     ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(it, System.Data.EntityState.Modified);
                 }
                 if ((context.SaveChanges() > 0))
                 {
                     if (!msg.ToString().IsNullOrEmpty())
                     {
                         NotificationService.SendNotification(NotificationService.GetStaffEmailAddress(wb.PreparedBy), string.Format(string.Empty, wb.RefNumber, msg.ToString()), NotificationHelper.wbsubject);
                     }
                     scope.Complete(); return(true);
                 }
                 else
                 {
                     scope.Dispose(); return(false);
                 }
             }
             catch (Exception ex) { scope.Dispose(); throw new Exception(ex.Message); }
         }
     }
 }
コード例 #3
0
        private bool AddItems(Model.WarehouseRelease wrEntity, Model.WarehouseReleaseItem entity, SCMSEntities context, TransactionScope scope, bool sendmail = false)
        {
            string itemCategory = context.Inventories.FirstOrDefault(p => p.Id == entity.InventoryId).Item.ItemCategory.CategoryCode;

            if (wrEntity == null)
            {
                wrEntity = context.WarehouseReleases.FirstOrDefault(w => w.Id == entity.WarehouseReleaseId);
            }
            entity.Id = Guid.NewGuid();
            if (itemCategory.Equals("C"))
            {
                entity.AssetId = Guid.Empty; context.WarehouseReleaseItems.Add(entity);
            }
            else
            {
                entity.Quantity = 1;
                Model.Asset ass = context.Assets.FirstOrDefault(p => p.Id == entity.AssetId);
                ass.IsReleased     = true;
                ass.CurrentOwnerId = wrEntity.ReceivedBy;
                ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(ass, System.Data.EntityState.Modified);
                context.WarehouseReleaseItems.Add(entity);
            }
            Model.Inventory inv = context.Inventories.First(p => p.Id == entity.InventoryId);
            inv.Quantity -= (Int64)entity.Quantity;
            ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(inv, System.Data.EntityState.Modified);

            if ((context.SaveChanges() > 0))
            {
                SessionData.CurrentSession.ReleaseOrderList     = null;
                SessionData.CurrentSession.ReleaseOrderItemList = null;
                SessionData.CurrentSession.AssetList            = null;
                SessionData.CurrentSession.InventoryList        = null;
                if (sendmail)
                {
                    NotificationServicee.SendNotification(NotificationServicee.GetApproverEmailAddress(1, NotificationHelper.wrnCode), NotificationHelper.wrnMsgBody, NotificationHelper.wrnsubject);
                }
                scope.Complete();
                return(true);
            }
            else
            {
                scope.Dispose(); return(false);
            }
        }
コード例 #4
0
 public bool SaveWRF(Model.WarehouseRelease WR, Model.WarehouseReleaseItem entity)
 {
     using (var context = new SCMSEntities())
     {
         using (TransactionScope scope = new TransactionScope())
         {
             try
             {
                 if (WR != null)
                 {
                     context.WarehouseReleases.Add(WR);
                     return(AddItems(WR, entity, context, scope, true));
                 }
                 else
                 {
                     if (entity.Id.Equals(Guid.Empty))
                     {
                         return(AddItems(WR, entity, context, scope));
                     }
                     else
                     {
                         ((IObjectContextAdapter)context).ObjectContext.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
                         if ((context.SaveChanges() > 0))
                         {
                             scope.Complete(); SessionData.CurrentSession.ReleaseOrderItemList = null; return(true);
                         }
                         else
                         {
                             scope.Dispose(); return(false);
                         }
                     }
                 }
             }
             catch (Exception ex) { scope.Dispose(); throw ex; }
         }
     }
 }