public static List <ButtonConnection> GetButtonConnections() { MySqlCommand cmd = new MySqlCommand("GetButtonConnections", new MySqlConnection(connectionString)); cmd.CommandType = CommandType.StoredProcedure; cmd.Connection.Open(); MySqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); List <ButtonConnection> connections = new List <ButtonConnection>(); while (rdr.Read()) { ButtonConnection connection = new ButtonConnection(); connection.ConnectionID = int.Parse(rdr[0].ToString()); connection.CollectionButtonId = int.Parse(rdr[1].ToString()); connection.UnitButtonID = int.Parse(rdr[2].ToString()); connections.Add(connection); } rdr.Close(); return(connections); }
public static void AddButtonConnection(ButtonConnection connection) { MySqlCommand cmd = new MySqlCommand("CreateButtonConnection", new MySqlConnection(connectionString)); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new MySqlParameter("_bondID", connection.ConnectionID)); cmd.Parameters.Add(new MySqlParameter("_collection_btnID", connection.CollectionButtonId)); cmd.Parameters.Add(new MySqlParameter("_unit_buttonID", connection.UnitButtonID)); cmd.Connection.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); }
public static void AddButtonConnection(ButtonConnection connection) { TcpClient.sendObject <ButtonConnection>(new DBMsg(ManagerType.ButtonsManager, "AddButtonConnection", JsonConvert.SerializeObject(connection))); }
//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; } }