public static List <int> GetButtonsContaining(List <Product> products) { ButtonConnectionHolder.connections = ButtonsClient.GetButtonConnections(); List <int> unitButtons = GetUnitButtonsContaining(products); bool added = true; List <int> allButtonsContaining = new List <int>(); foreach (ButtonConnection connection in ButtonConnectionHolder.connections) { if (unitButtons.Contains(connection.UnitButtonID)) { allButtonsContaining.Add(connection.CollectionButtonId); } } while (added) { foreach (ButtonConnection connection in ButtonConnectionHolder.connections) { if (allButtonsContaining.Contains(connection.UnitButtonID)) { allButtonsContaining.Add(connection.CollectionButtonId); added = true; } } added = false; } allButtonsContaining.AddRange(unitButtons); return(allButtonsContaining); }
public StartingForm() { InitializeComponent(); try { //Get all Products DataHolders.ProductsHolder.products = ProductClient.GetProducts(); //Get all connections DataHolders.ButtonConnectionHolder.connections = ButtonsClient.GetButtonConnections(); DataHolders.UnitProductConnectionHolder.Connections = ButtonsClient .GetUnitPorductConnections(); //Documents DataHolders.DocumentConnectionHolder.documentProductConnections = DocumentClient .GetAllDocumnetProductConnections(); //Warehouse DataHolders.WarehouseHolder.warehouses = DatabaseManagers.WarehouseClient.GetWarehouses(); //DatabaseManagers.WarehouseManager.GetWarehouses(); DataHolders.WarehouseHolder.warehouseProductConnections = DatabaseManagers.WarehouseClient .GetWarehouseProductConnection(); //workers DataHolders.WorkerHolder.workers = WorkerClient.GetWorkers(); DataHolders.WorkerHolder.avaliableWorkers = WorkerClient.GetAavalibleWorkers(); //Delivery DataHolders.DeliveryHolder.partners = DeliveryClient.GetPartners(); DataHolders.DeliveryHolder.locations = DeliveryClient.GetLocations(); DataHolders.DeliveryHolder.vehicles = DeliveryClient.GetVehicles(); DataHolders.DeliveryHolder.routes = DeliveryClient.GetRoutes(); DataHolders.DeliveryHolder.avaliableVehicles = DeliveryClient.GetAvalibleVehicles(); //properties if (PropertiesClient.GetProperties().Exists((e) => e.name == Enums.PropertyName.distance)) { DataHolders.PropertiesHolder.distanceUnit = PropertiesClient.GetProperties() .Find((e) => e.name == Enums.PropertyName.distance).value; } if (PropertiesClient.GetProperties().Exists((e) => e.name == Enums.PropertyName.weight)) { DataHolders.PropertiesHolder.weightUnit = PropertiesClient.GetProperties() .Find((e) => e.name == Enums.PropertyName.weight).value; } } catch (Exception) { MessageBox.Show("Error connecting to database, initial data couldn't be load"); Environment.Exit(1); } }
private void GUI_Load(object sender, EventArgs e) { //Get all buttons List <DragButton> allDragButtons = new List <DragButton>(); try { allDragButtons = Mapper.mapTransferButtonsToDragButtons(ButtonsClient.GetButtons()); } catch (Exception) { MessageBox.Show("Failed to get units from database"); } foreach (DragButton item in allDragButtons) { //Add mouseDown event if (item.Type.ToString() == "Unit") //For unit { item.MouseDown += unitPressed; } else //For collection { item.MouseDown += collectionPressed; collectionButtons.Add(int.Parse(item.Tag.ToString()), new List <DragButton>()); } allButtons.Add(int.Parse(item.Tag.ToString()), item); } //Get Collection buttons and create collection button map try { foreach (ButtonConnection buttonConnection in ButtonsClient.GetButtonConnections()) { //Colection button list doesn't contain this collection if (!collectionButtons.Select(elem => elem.Key).Contains(buttonConnection.CollectionButtonId)) { //Add this collection to collection list collectionButtons.Add(buttonConnection.CollectionButtonId, new List <DragButton>()); } //Check if unit button exist if (allButtons.Select(elem => elem.Key).Contains(buttonConnection.UnitButtonID)) { //Add connected unit to that collection collectionButtons[buttonConnection.CollectionButtonId].Add(allButtons[buttonConnection.UnitButtonID]); } else { MessageBox.Show("Fatal error: unit lost (No unit was found with that connection)"); } } } catch (Exception) { MessageBox.Show("Error fetching collectiong buttons"); } foreach (DragButton item in collectionButtons[0]) { //Add button to panel [display it] panelGUI.Controls.Add(item); item.BringToFront(); } //Remove back button btnBackFromChild.Visible = false; //Disable cmbFound cmbFoundProducts.Enabled = false; }