virtual protected void ExecuteModifySelectedStorageCommandDo()
        {
            //first to pick all the MapItems as a list
            //then create a new list of goods
            //create goods
            //save goods--> transaction
            //save map-- transaction
            //over
            List <Models.Entity.Goods> addList    = new List <Models.Entity.Goods>();
            List <Models.Entity.Goods> deleteList = new List <Models.Entity.Goods>();

            for (int i = 0; i < SelectedStorages.Count; i++)
            {
                addList.Add(new Models.Entity.Goods()
                {
                    Name           = GoodName,
                    Batch          = GoodBatch,
                    Model          = GoodModel,
                    Count          = _goodCount,
                    MapItemsId     = SelectedStorages[i].SingleStorage.MapItemID,
                    CargoWayLockId = 0,
                    //TODO::set GoodId and BarCode interfaces
                    ProductId = "",
                    BarCode   = ""
                });
            }
            using (TransactionScope scope = new TransactionScope())
            {
                Models.Service.IMapSingletonService mapSingletonService = Models.Service.MapSingletonService.Instance;
                for (int i = 0; i < SelectedStorages.Count; i++)
                {
                    Models.Entity.Goods todel = _map.Goods.SingleOrDefault(g => g.MapItemsId == SelectedStorages[i].SingleStorage.MapItemID);
                    if (todel != null && todel.Id != 0)
                    {
                        deleteList.Add(todel);
                    }
                }
                //先删除,后赋值保存
                mapSingletonService.GetGoodsService().DeleteGoods(deleteList);
                mapSingletonService.GetGoodsService().InsertGoods(addList);
                //存储栅格状态
                mapSingletonService.GetMapItemsService().UpdateAllMapItems();
                scope.Complete();
                refreshGridColorCallBack();
                StringBuilder sb = new StringBuilder();
                sb.Append("Delete ").Append(deleteList.Count).Append(" goods. And add ")
                .Append(addList.Count).Append(" new goods.");
                mainStatusCallBack(sb.ToString());
                _self.Close();
            }
        }
Exemplo n.º 2
0
 private void ConfirmSave(List <Goods> toDeleteList, List <MapItems> toAddMIList, List <MapItems> toDeleteMIList)
 {
     //do as a transcaction
     using (TransactionScope trans = new TransactionScope())
     {
         Models.Service.IMapSingletonService mapSingletonService = Models.Service.MapSingletonService.Instance;
         mapSingletonService.GetMapItemsService().UpdateAllMapItems();
         mapSingletonService.GetMapItemsService().InserSpecialtMapItems(toAddMIList);
         mapSingletonService.GetMapItemsService().DeleteSpecialMapItems(toDeleteMIList);
         mapSingletonService.GetGoodsService().DeleteGoods(toDeleteList);
         trans.Complete();
     }
 }