internal bool BoxIsFull(I3DStorageObject newProduct, long weight, int volym, bool isFragile, int maxDimension) { if (!isFragile && !FragileProductsAlreadyAdded()) { if (CalculateVolume(volym) < MaxVolume) { if (maxDimension < this.MaxDimension) { if (CalculateWeigh(weight) < this.MaxWeight) { this.combinedProductVolym += volym; this.combinedProductWeight += weight; return(false);//box isnt full } } } return(true); } else if (isFragile) { if (wareHouse.Count < 1) { return(false);//box isnt full } } return(true); }
} //Lägger till en ny BlobBox på första lediga plats enligt satta regler //-----Misc box actions----- public bool RetreiveBox(int iD, out I3DStorageObject outBox, out string result) { bool found = false; for (int i = 0; i < wareHouseLocation.GetLength(0); i++) { for (int j = 0; j < wareHouseLocation.GetLength(1); j++) { foreach (var box in wareHouseLocation[i, j].Lshelf) //kollar igenom alla hyllor i WareHouse { if (box.ID == iD) //om lådans ID hittas { result = $"The box was found on floor {i + 1}, shelf {j + 1}.\nAnd is now removed from Santa's Workshop\n"; //en string retuneras med att lådan togs bort outBox = box; //den hittade lådan sparas i ett nytt object wareHouseLocation[i, j].RemoveBox(box); //skickar den nya lådan till RemoveBox Metoden i WareHouseLocation iDDic.Remove(box.ID); //Tar bort lådans ID från dictionaryn found = true; Weight(); //vikten uppdateras return(found); //retunerar true } } } } Weight(); //vikten uppdateras result = "There was no match"; //string retuneras om det inte gick outBox = null; //temp lådan blir null return(found); //retunerar false } //hämtar ut en låda med ID
public I3DStorageObject StoreAtFreeLocation(I3DStorageObject product)//calling this method if user didnt say where it wanted to store the object { for (int i = startindex; i < slots.GetLength(0); i++) { for (int j = startindex; j < slots.GetLength(1);) { if (slots[i, j] != null) { result = slots[i, j].StoreProduct(product, product.Weight, product.Volume, product.IsFragile, product.MaxDimension); if (!result) { j++; } else { return(slots[i, j].FoundByID(product.ID)); } } else if (slots[i, j] == null) { slots[i, j] = new WareHouseLocation(i, j); slots[i, j].StoreProduct(product, product.Weight, product.Volume, product.IsFragile, product.MaxDimension); return(slots[i, j].FoundByID(product.ID)); } } } return(null); }
public void RemoveBox(int id) { //Gets the position and box and then removes it if no exceptions occurs. int pos = GetLocationByID(id); I3DStorageObject b = GetBoxByID(id); location[pos].Remove(b); }
internal void Remove(I3DStorageObject b) { if (!LocationContainsBox(b)) { throw new Exception("Could not find a box to remove."); } _boxes.Remove(b); }
internal bool StoreProduct(I3DStorageObject newProduct, long weigth, int volym, bool isFragile, int maxDimension) { if (!BoxIsFull(newProduct, weigth, volym, isFragile, maxDimension)) { wareHouse.Add(newProduct); return(true); } return(false); }
public bool LäggTill(I3DStorageObject låda) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 100; k++) { if (lagret[j, k].SökEfterLåda(låda.ID) == true) { throw new FormatException("Det finns redan en låda med detta ID"); } } } for (int j = 0; j < 2; j++) { for (int k = 0; k < 100; k++) { if (låda.Ömtåligt == true) //om lådan är ömtålig, fortsätt { if (lagret[j, k].ÄrLådaÖmtålig() == true) //finns det redan en låda som är ömtålig i den här lagerplatsen ska den frtsätta leta plats. { continue; } else if (lagret[j, k].FörMycketVikt() == 0) //är vikten i lagerplatsen 0 så kan man lägga till en ömtålig { lagret[j, k].LäggTillLåda(låda); return(true); } else { continue; } } else if (låda.Ömtåligt == false) { if (lagret[j, k].ÄrLådaÖmtålig() == true) { continue; } else if (lagret[j, k].FinnsDetUtrymme(låda.Vikt, låda.Volym) == true) // överstiger vikten och volymen max?? { lagret[j, k].LäggTillLåda(låda); //annars lägg till en ny låda return(true); } else if (lagret[j, k].FinnsDetUtrymme(låda.Vikt, låda.Volym) == false) // överstiger vikten och volymen max?? { continue; //om, fortsätt leta plats } } } } return(false); }
static void AddBox(string boxType) { I3DStorageObject box = null; int id = GetId(true); string description = GetDescription(); double weight = GetWeight(); bool isFragile = GetFragile(); try { switch (boxType) { case "cube": int side = GetSide(string.Empty); box = _wareHouse.CreateCube(id, description, weight, isFragile, side); break; case "cubeoid": int xSide = GetSide("x"); int ySide = GetSide("y"); int zSide = GetSide("z"); box = _wareHouse.CreateCubeoid(id, description, weight, isFragile, xSide, ySide, zSide); break; case "sphere": int radius = GetRadius(); box = _wareHouse.CreateSphere(id, description, weight, isFragile, radius); break; case "blob": side = GetSide(""); box = _wareHouse.CreateBlob(id, description, weight, side); break; } int pos = -1; if (ManualPos()) { pos = GetManualLocation(); } else { pos = GetAutomaticLocation(box); } _wareHouse.StoreBox(box, pos); Console.WriteLine("The box was added succesfully"); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } }
internal bool LocationContainsBox(I3DStorageObject b) { foreach (var box in _boxes) { if (box == b) { return(true); } } return(false); }
public bool hasAvailableVolumeForObject(I3DStorageObject s) { double currentVolume = 0; foreach (I3DStorageObject obj in storage) { currentVolume += obj.Volume; } double available = MaxVolume - currentVolume; return(s.Volume <= available); }
public int GetFreeLocation(I3DStorageObject b) { for (int i = 0; i < location.Length; i++) { if (location[i].AddableLocation(b)) { return(i); } } throw new ArgumentOutOfRangeException("Could not find an addable location for your box."); }
public bool LäggTillPåPlats(I3DStorageObject låda, int plats, int hylla) { for (int j = 0; j < 2; j++) { for (int k = 0; k < 100; k++) { if (lagret[j, k].SökEfterLåda(låda.ID) == true) { throw new FormatException("Det finns redan en låda med detta ID"); } } } for (int j = 0; j < 2; j++) { for (int k = 0; k < 100; k++) { if (låda.Ömtåligt == true) // ömtålig ja! { if (lagret[plats, hylla].ÄrLådaÖmtålig() == true) //om lådan i är ömtålig kan man inte ställa en låda till. { throw new ArgumentException("Här får du inte ställa lådan"); } else if (lagret[plats, hylla].FörMycketVikt() == 0) //är lagret tomt kan man ställa en ömtålig { lagret[plats, hylla].LäggTillLåda(låda); return(true); } } else if (låda.Ömtåligt == false) //ömtålig nej! { if (lagret[plats, hylla].ÄrLådaÖmtålig() == true) //om lådan i är ömtålig kan man inte ställa en låda till. { throw new ArgumentException("Här får du inte ställa lådan"); } else if (lagret[plats, hylla].FinnsDetUtrymme(låda.Vikt, låda.Volym) == true) //kollar volym och vikt { lagret[plats, hylla].LäggTillLåda(låda); return(true); } else if (lagret[plats, hylla].FinnsDetUtrymme(låda.Vikt, låda.Volym) == false) { throw new ArgumentException("Lådan får inte plats"); } } } } return(false); }
} //Lägger till ny CubeBox på vald plats public bool AddNewCubeoidBox(int iD, uint weight, bool isFragile, int insurance, decimal xSide, decimal ySide, decimal zSide, int floor, int row, out string result) { bool valid = false; if (!iDDic.ContainsKey(iD)) //kollar så att det id man skickar in inte redans finns i lagret { bool wareHouseWeight = false; bool floorWeight = false; BoxCreator boxCreator = new CubeoidBoxCreator(iD, weight, isFragile, insurance, xSide, ySide, zSide); //skapar en ny låda med in parametrarna I3DStorageObject boxes = boxCreator.CreateBox(); Weight(); //kallar på weight metoden för att få viktinformation if (CurrentWeight + boxes.Weight <= MaxWeight) //kollar så att lådan inte får totalviken på warehouse att överskridas { wareHouseWeight = true; if (stackWeight[row] + boxes.Weight <= 2000) //kollar så att lådan inte får vånings "stacken" att överskridas { floorWeight = true; } } if (wareHouseWeight == true & floorWeight == true) //om lådan inte överskrider nån vikt { valid = wareHouseLocation[floor, row].AddNewBox(boxes); //lådan läggs till i arrayens lista och får tillbaka en bool om det gick eller inte if (valid == true) //om det gick sparas lådans ID i dictionaryn { iDDic.Add(boxes.ID, 1); } result = wareHouseLocation[floor, row].ToString(); //en string retuneras med information om lådan } else //om lådan överskrider nån vikt, skickas ett felmeddelande { throw new ArgumentException("The floor or the warehouse is full"); } } else //om IDt redan används skickas ett felmeddelande { throw new ArgumentException("The Product ID is allready in use"); } Weight(); return(valid); } //Lägger till ny CubeoidBox på vald plats
internal void Add(I3DStorageObject b) { if (b is null) { throw new ArgumentNullException("Can't add a box that is null."); } else if (LocationContainsBox(b)) { throw new InvalidOperationException($"Box {b} is already added"); } else if (b.Weight + CalculateCurrentLocationWeight() > MaxWeight) { throw new ArgumentOutOfRangeException("Box could not be added because the location would surpass it's max weight."); } _boxes.Add(b); }
internal bool AddableLocation(I3DStorageObject b) { double newWeight = b.Weight + CalculateCurrentLocationWeight(); double newVolume = b.Volume + CalculateCurrentLocationVolume(); //if a box is fragile it needs to be stored alone if (b.IsFragile == true && _boxes.Count > 0) { return(false); } if (newWeight > MaxWeight || MaxVolume < newVolume) { return(false); } return(true); }
} //Lägger till en ny Cubeoid på första lediga plats enligt satta regler public bool AutoAddNewSphereBox(int iD, uint weight, bool isFragile, int insurance, decimal radius, out string result) { bool valid = false; BoxCreator boxCreator = null; //skapar en ny låda med in parametrarna boxCreator = new SphereBoxCreator(iD, weight, isFragile, insurance, radius); I3DStorageObject boxes = boxCreator.CreateBox(); Weight(); for (int i = 0; i < wareHouseLocation.GetLength(0); i++) { for (int j = 0; j < wareHouseLocation.GetLength(1); j++) { if (!iDDic.ContainsKey(iD)) //kollar så att det id man skickar in inte redans finns i lagret { if ((wareHouseLocation[i, j].CurrentWeigth + weight <= wareHouseLocation[i, j].MaxWeight) & (stackWeight[j] + boxes.Weight <= 2000)) //Kollar så att lådan int får totalvikten eller vånings "stacken" att överskridas" { if (wareHouseLocation[i, j].CurrentVolume + boxes.Volume <= wareHouseLocation[i, j].MaxVolume) //kollar så att lådans volym får plats på hyllan { if (boxes.MaxDimension <= wareHouseLocation[i, j].Width ^ boxes.MaxDimension <= wareHouseLocation[i, j].Depth ^ boxes.MaxDimension <= wareHouseLocation[i, j].Height) //kollar så att lådans största sida får plats på hyllan { if (boxes.IsFragile == false & wareHouseLocation[i, j].ContainsFragile == false) //om lådan inte är fragile och det inte redan finns en fragile låda på hyllan { wareHouseLocation[i, j].AddNewBox(boxes); //lådan läggs till i hyllan (listan) iDDic.Add(iD, 1); //lådans ID sparas i dictionaryn result = $"{boxes.ID} was added on floor {+1}, shelf {j + 1}"; //en string skickas tillbaka med information om vart den lagrades return(valid); //retunerar true om det gick } if (boxes.IsFragile == true & wareHouseLocation[i, j].Lshelf.Count < 1 & wareHouseLocation[i, j].ContainsFragile == false) //om lådan är fragile och hyllan är tom och hyllan inte redan har en fragile { wareHouseLocation[i, j].AddNewBox(boxes); //lådan läggs till i hyllan (listan) iDDic.Add(iD, 1); //lådans ID sparas i dictionaryn result = $"{boxes.ID} was added on floor {+1}, shelf {j + 1}"; //en string skickas tillbaka med information om vart den lagrades return(valid); //retunerar true om det gick } } } } } } } result = "The box could not be added to Santa's WorkShop"; //om det inte gick att lägga till lådan retuneras denna string return(valid); //retunerar false om det inte gick } //Lägger till en ny Spherebox på första lediga plats enligt satta regler
} //hämtar ut en låda med ID public bool MoveBox(int iD, int floor, int shelf, out string result) { bool found = false; for (int i = 0; i < wareHouseLocation.GetLength(0); i++) { for (int j = 0; j < wareHouseLocation.GetLength(1); j++) { foreach (var box in wareHouseLocation[i, j].Lshelf) //loopar igenom alla hyllor i WareHouse { if (box.ID == iD) //om lådans ID hittas { I3DStorageObject temp = box; //en temp låda Weight(); //uppdaterar vikten för WareHouse if (stackWeight[shelf] + box.Weight > 2000) //kollar så att lådan inte får vånings "stacken" att överskridas { throw new ArgumentException("The box could not be moved here as the floor would brake..."); //skickar felmeddelande om vikten överskrids } found = wareHouseLocation[floor, shelf].AddNewBox(temp); //försöker lägger till lådan på den nya platesn if (found == true) //om det gick { wareHouseLocation[i, j].RemoveBox(temp); //tar bort lådan från den gamla platsen result = $"The box was found on floor {i + 1}, shelf {j + 1}!\nAnd was moved to floor {floor + 1}, shelf {shelf + 1}\nID: {temp.ID}, {temp.Description}"; //retunerar en string med information om förflyttningen Weight(); //uppdaterar WareHouse vikten return(found); //retunerar true } else //om det inte gick att flytta lådan { Weight(); //uppdaterar WareHouse vikten result = $"The Box could not be moved to that location"; //retunerar en string om att det inte gick att flytta lådan } } } } } Weight(); //uppdaterar viken result = "There was no match"; //om lådan inte kunde hittas return(found); //retunerar false } //Flyttar en låda med hjälp av ID till en ny position i WareHouse
public I3DStorageObject GetBoxByID(int id) { I3DStorageObject b = null; for (int i = 0; i < location.Length; i++) { if (location[i].LocationContainsID(id)) { b = location[i].GetByID(id); } } if (b is null) { throw new ArgumentOutOfRangeException("Could not find a box with that ID"); } return(b); }
static void ShowBox() { bool correctinput = true; I3DStorageObject box = null; int id = -1; do { try { Console.Clear(); Console.WriteLine("Enter id to see content of a box:"); id = int.Parse(Console.ReadLine()); correctinput = true; } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); correctinput = false; } } while (correctinput == false); try { box = _wareHouse.GetBoxByID(id); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.ReadLine(); } if (box != null) { Console.Clear(); int pos = _wareHouse.GetLocationByID(id); string frontendpos = _wareHouse.GetFrontedLocation(pos); Console.WriteLine($"Box Location: {frontendpos}"); Console.WriteLine(box.ToString()); Console.ReadLine(); } }
public I3DStorageObject StoreAtIndexLocation(int slot, int floor, I3DStorageObject product, int oldFloorPosition, int oldBoxPosition) { if (slots[floor, slot] == null) { if (oldFloorPosition > 0 && oldBoxPosition > 0) { slots[oldFloorPosition, oldBoxPosition].RemoveProduct(product.ID, product.Weight, product.Volume); if (slots[oldFloorPosition, oldBoxPosition].ProductCount == 0) { slots[oldFloorPosition, oldBoxPosition] = null; } } slots[floor, slot] = new WareHouseLocation(floor, slot); slots[floor, slot].StoreProduct(product, product.Weight, product.Volume, product.IsFragile, product.MaxDimension); return(slots[floor, slot].FoundByID(product.ID)); } if (slots[floor, slot] != null) { result = slots[floor, slot].StoreProduct(product, product.Weight, product.Volume, product.IsFragile, product.MaxDimension); if (result) { if (oldFloorPosition > 0 && oldBoxPosition > 0) { slots[oldFloorPosition, oldBoxPosition].RemoveProduct(product.ID, product.Weight, product.Volume); if (slots[oldFloorPosition, oldBoxPosition].ProductCount == 0) { slots[oldFloorPosition, oldBoxPosition] = null; } } //slots[floor, slot].StoreProduct(product, product.Weight, product.Volume, product.IsFragile, product.MaxDimension); } else { //removes the product from its old position throw new ArgumentException($"Level {floor} at box positon {slot} is full" + $" the product could not be added\n"); //adds the product to the new positon / "moves it to the new position box" } return(slots[floor, slot].FoundByID(product.ID)); } return(null); }
static int GetAutomaticLocation(I3DStorageObject box) { return(_wareHouse.GetFreeLocation(box)); }
public void StoreBox(I3DStorageObject b, int pos) { location[pos].Add(b); }