コード例 #1
0
 /// <summary>
 /// use this method only when recreate a map or the map id the database is null
 /// </summary>
 /// <param name="MapName"></param>
 /// <param name="layers"></param>
 /// <param name="racks"></param>
 /// <param name="columns"></param>
 /// <returns></returns>
 public Entity.Map CreateNewMap(string MapName, int layers, int racks, int columns)
 {
     using (TransactionScope scope = new TransactionScope())
     {
         Map             = new Entity.Map();
         Map.MapName     = MapName;
         Map.RackCount   = racks;
         Map.LayerCount  = layers;
         Map.ColumnCount = columns;
         //first save map initial messages
         this.MapDictionaryService = new Repository.MapDictionaryService();
         this.MapDictionaryService.InsertMap(Map);
         //Reset Zones' static color
         Zone.ResetRrandomColor();
         //initial all services as the map reference for one
         InitialServices(Map);
         //create general types list
         List <Entity.Types> generalTypes = TypesService.LoadTypes();
         if (generalTypes.Count == 0)//if there has no types in the database, create new and save from code
         {
             generalTypes = GetGeneralTypes();
             this.TypesService.InsertTypes(generalTypes);
         }
         //ALERT!! must be constrainted here as the same name of all the GENERAL_TYPES, or will has logical error
         //ALERT!! you can modify and make contraint from "public class ItemTypesString" in this singleton class
         Entity.Types tt = Map.Types.Single(t => t.Name == ItemTypesString.ITEM_TYPE_DEFAULT_STORAGE);
         this._default_storage = tt;
         //then set mapitems, default type Id is zt's Type Id
         List <Entity.MapItems> additionMapItemList = new List <MapItems>();
         for (int i = 0; i < layers; i++)
         {
             for (int j = 0; j < racks; j++)
             {
                 for (int k = 0; k < columns; k++)
                 {
                     Entity.MapItems tmp     = new Entity.MapItems();
                     DAL.MapItems    DAL_tmp = new DAL.MapItems()
                     {
                         MapItemLayer  = i,
                         MapItemRack   = j,
                         MapItemColumn = k,
                         TypeId        = tt.Id,
                         ZoneId        = 0,
                         CargowayId    = 0,
                         Status        = (int)MapItems.MapItemStatus.STATUS_NOT_STORAGE
                     };
                     tmp.DAL_SetMapItem(DAL_tmp);
                     additionMapItemList.Add(tmp);
                 }
             }
         }
         MapItemsService.InsertMapItems(additionMapItemList);
         scope.Complete();
     }
     return(Map);
 }