private void collectionPressed(object sender, MouseEventArgs e) { if (!ButtonControl.enableDrag) { if (!ButtonControl.enableDelete) { int btnId = (int)((Button)sender).Tag; buttonsStack.Push(btnId); panelGUI.Controls.Clear(); foreach (var item in collectionButtons[btnId]) { panelGUI.Controls.Add(item); } btnBackFromChild.Visible = true; lblCurrentButtonID.Text = ""; foreach (int id in buttonsStack) { lblCurrentButtonID.Text += ($"/{allButtons[id].Text}"); } if (searchActive) { Search(); } } else { DragButton btnPressed = (DragButton)sender; DialogResult dialogResult = MessageBox.Show("Delete?", btnPressed.Name, MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { if (collectionButtons[int.Parse(btnPressed.Tag.ToString())].Count > 0) { MessageBox.Show("To delete collection you must first delete all units it contains"); return; } try { ButtonsClient.DeleteButtonConnection(int.Parse(btnPressed.Tag.ToString())); } catch (Exception) { MessageBox.Show("Failed to delete"); } allButtons.Remove(int.Parse(btnPressed.Tag.ToString())); collectionButtons[buttonsStack.Peek()].Remove(btnPressed); panelGUI.Controls.Remove(btnPressed); } else if (dialogResult == DialogResult.No) { return; } } } }
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); }
private void LoadTable(List <int> thisUnitProductsID) { List <UnitProductConnection> unitConnections = new List <UnitProductConnection>(); try { unitConnections = ButtonsClient.GetUnitPorductConnections(); } catch (Exception) { MessageBox.Show("Failed to get product for unit from database"); } //Go through all products and add those that belong in this unit foreach (Product product in ProductsHolder.products) { if (thisUnitProductsID.Contains(product.id)) { unitProducts.Add(new ProductDisplay(product, unitConnections.Where(conn => conn.ProductId == product.id && conn.ButtonId == btnId).FirstOrDefault().amount)); } } if (unitProducts.Count > 0) { //dipslay unit products dgvUnitProducts.DataSource = null; dgvUnitProducts.DataSource = unitProducts; } }
private void GUI_FormClosing(object sender, FormClosingEventArgs e) { //Save buttons for (int i = 0; i < allButtons.Count; i++) { ButtonsClient.AddButtonToAllButtons(Mapper.mapDragButtonToTransferButton(allButtons[i])); } }
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 AddProductToUnit(int id, double amount) { Product productToAdd = ProductsHolder.products.Find(p => p.id == id); //Product already exists if (unitProducts.FindAll(product => product.id == productToAdd.id).Count > 0) { //increase amount localy unitProducts.Where(product => product.id == productToAdd.id).FirstOrDefault().inUnit += amount; //get connection info int productId = unitProducts.Where(product => product.id == productToAdd.id).FirstOrDefault().id; double increasedAmount = unitProducts.Where(product => product.id == productToAdd.id).FirstOrDefault().inUnit; //increase amount in database try { ButtonsClient.UpdateUnitProductConnection(btnId, productId, increasedAmount); } catch (Exception) { MessageBox.Show("Failed to update database"); } } //product does not exists in this unit else { //add to local unitProducts.Add(new ProductDisplay(productToAdd, amount)); //Get connectionID connectionID = UnitProductConnectionHolder.Connections.Count == 0 ? 0 : UnitProductConnectionHolder.Connections.Max(con => con.ConnectionId) + 1; //create connection var connection = new UnitProductConnection { ConnectionId = connectionID, ButtonId = btnId, ProductId = productToAdd.id, amount = amount }; //add to database try { ButtonsClient.AddUnitProuductConnection(connection); } catch (Exception) { MessageBox.Show("Failed to add to database"); } //add to holder UnitProductConnectionHolder.Connections.Add(connection); } dgvUnitProducts.DataSource = null; dgvUnitProducts.DataSource = unitProducts;//get from local }
private static List <int> GetUnitButtonsContaining(List <Product> products) { UnitProductConnectionHolder.Connections = ButtonsClient.GetUnitPorductConnections(); List <int> buttonsIDs = new List <int>(); foreach (UnitProductConnection connection in UnitProductConnectionHolder.Connections) { if (products.Select(elem => elem.id).Contains(connection.ProductId)) { buttonsIDs.Add(connection.ButtonId); } } return(buttonsIDs); }
private void unitPressed(object sender, MouseEventArgs e) { if (!ButtonControl.enableDrag) { if (!ButtonControl.enableDelete) { DragButton btnPressed = (DragButton)sender; this.Hide(); //Send pressed button ID StorageUnitTable unitTable = new StorageUnitTable(int.Parse(btnPressed.Tag.ToString())); unitTable.Location = this.Location; unitTable.StartPosition = this.StartPosition; unitTable.FormClosing += delegate { this.Show(); }; unitTable.ShowDialog(); } else { DragButton btnPressed = (DragButton)sender; DialogResult dialogResult = MessageBox.Show("Delete?", btnPressed.Name, MessageBoxButtons.OKCancel); if (dialogResult == DialogResult.OK) { try { ButtonsClient.DeleteButtonConnection(int.Parse(btnPressed.Tag.ToString())); } catch (Exception) { MessageBox.Show("Failed to delete"); } allButtons.Remove(int.Parse(btnPressed.Tag.ToString())); collectionButtons[buttonsStack.Peek()].Remove(btnPressed); panelGUI.Controls.Remove(btnPressed); } else if (dialogResult == DialogResult.No) { return; } } } }
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; }
//Mouse clicked inside GUI panel, create dragButton object private void MouseClicked(object sender, MouseEventArgs e) { if (ButtonControl.enableAdd) { int btnId; if (allButtons.Count != 0) { btnId = allButtons.Keys.Max() > collectionButtons.Keys.Max() ? allButtons.Keys.Max() + 1 : collectionButtons.Keys.Max() + 1; } else { btnId = collectionButtons.Keys.Max() + 1; } //Creating StorageCollection button if (cmbAddType.Text == "Storage collection") { //Create collection button DragButton dragButton = new DragButton(Enums.ButtonTypes.Collection); dragButton.Text = tBoxAddName.Text; dragButton.Name = "btnCollection_" + btnId.ToString(); dragButton.Tag = btnId; dragButton.Location = new System.Drawing.Point(PointToClient(Cursor.Position).X, PointToClient(Cursor.Position).Y); dragButton.MouseDown += collectionPressed; //When button is clicked //Add button to panel [display it] panelGUI.Controls.Add(dragButton); dragButton.BringToFront(); //Add button to it's collection [to all btns] collectionButtons[buttonsStack.Peek()].Add(dragButton); //Create this button collection [this collection] collectionButtons.Add(btnId, new List <DragButton>()); //Add to all buttns [database] try{ ButtonsClient.AddButtonToAllButtons(Mapper.mapDragButtonToTransferButton(dragButton)); } catch (Exception) { MessageBox.Show("Failed to add to database"); } //Add to all buttons [holder] allButtons.Add(btnId, dragButton); //Create new connnection ButtonConnection connection = new ButtonConnection { ConnectionID = ButtonConnectionHolder.connections.Count == 0 ? 0 : ButtonConnectionHolder.connections.Max(elem => elem.ConnectionID) + 1, CollectionButtonId = buttonsStack.Peek(), UnitButtonID = btnId }; //Add connection to database, so we know in which layer it is [database] try { ButtonsClient.AddButtonConnection(connection); } catch (Exception) { MessageBox.Show("Failed to add to database"); } //Add connection to connection holder ButtonConnectionHolder.connections.Add(connection); //Push on stack [stack] buttonsStack.Push(btnId); panelGUI.Controls.Clear(); //make backbtn visible btnBackFromChild.Visible = true; } else { //Create Unit button DragButton dragButton = new DragButton(Enums.ButtonTypes.Unit); dragButton.Text = tBoxAddName.Text; dragButton.Name = "btnUnit_" + btnId.ToString(); dragButton.Tag = btnId; dragButton.Location = new System.Drawing.Point(PointToClient(Cursor.Position).X, PointToClient(Cursor.Position).Y); dragButton.MouseDown += unitPressed; //When button is clicked //Add button to panel [display it] panelGUI.Controls.Add(dragButton); dragButton.BringToFront(); //Add UnitButton to it's collectionButton [list] collectionButtons[buttonsStack.Peek()].Add(dragButton); //Add button to allButtons [list] allButtons.Add(btnId, dragButton); //Add button to database, all buttons table [database] try { ButtonsClient.AddButtonToAllButtons(Mapper.mapDragButtonToTransferButton(dragButton)); } catch (Exception) { MessageBox.Show("Failed to add to database"); } //Create new connnection ButtonConnection connection = new ButtonConnection { ConnectionID = ButtonConnectionHolder.connections.Count == 0 ? 0 : ButtonConnectionHolder.connections.Max(elem => elem.ConnectionID) + 1, CollectionButtonId = buttonsStack.Peek(), UnitButtonID = btnId }; try { //Add connection to database, so we know in which layer it is [database] ButtonsClient.AddButtonConnection(connection); } catch (Exception) { MessageBox.Show("Failed to add to database"); } //Add connection to connection holder [Holder] ButtonConnectionHolder.connections.Add(connection); } //btn.Image = System.Drawing.Image.FromFile(@"C:\Users\Alen\Desktop\faks\0.ZAVRSNI\images\container.png"); ButtonControl.enableAdd = false; } }