private void CreateNewLocation(Type_Emplacement type, int x = 30, int y = 30) { LoginTools.CheckConnection(); Emplacement newLocation = new Emplacement(); _db.Emplacement.Add(newLocation); newLocation.Taille_X = 10; newLocation.Taille_Y = 10; int i = _locationsList.Count; while (_db.Emplacement.Any(a => a.Nom_Emplacement.Equals("Emplacement " + i))) { i++; } foreach (GraphicLocation graphicLocation in _locationsList) { if (graphicLocation.Location.Nom_Emplacement.Equals("Emplacement " + i)) { i++; } } newLocation.Nom_Emplacement = "Emplacement " + i; newLocation.Type_Emplacement = type; GraphicLocation newGraphicLocation = new GraphicLocation(newLocation); newGraphicLocation.Move(new Point(x, y), pictureBox); _locationsList.Add(newGraphicLocation); SelectedLocation = newGraphicLocation; Refresh(); }
private void TypePanel_MouseDown(object sender, MouseEventArgs e) { Panel panel = getParentTypePanel(sender); if (e.Clicks == 2) { LoginTools.CheckConnection(); Label typeLabel = (Label)panel.Controls.Find("typeLabel", true).First(); Type_Emplacement typeLocation = _db.Type_Emplacement.FirstOrDefault(a => a.Libelle_Type.Equals(typeLabel.Text)); CreateNewLocation(typeLocation); } else { panel.DoDragDrop(panel, DragDropEffects.Move); } }
private void MapTablePanel_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(TableLayoutPanel).FullName, false)) { TableLayoutPanel panel = (TableLayoutPanel)e.Data.GetData(typeof(TableLayoutPanel).FullName, false); panel.BackColor = Color.Gray; Label typeLabel = (Label)panel.Controls.Find("typeLabel", true).First(); if (typeLabel != null) { Type_Emplacement typeLocation = _db.Type_Emplacement.FirstOrDefault(a => a.Libelle_Type.Equals(typeLabel.Text)); if (typeLocation != null) { Point controlCoordinate = pictureBox.PointToClient(new Point(e.X, e.Y)); Rectangle validRectangle = new Rectangle(0, 0, pictureBox.Width - 30, pictureBox.Height - 30); if (validRectangle.Contains(controlCoordinate)) { CreateNewLocation(typeLocation, controlCoordinate.X, controlCoordinate.Y); } } } } }
private TableLayoutPanel CreateInsertLocationButton(Type_Emplacement type) { TableLayoutPanel typePanel = new TableLayoutPanel(); PictureBox typePicture = new PictureBox(); Label typeLabel = new Label(); // // panel // typePanel.ColumnCount = 2; typePanel.Size = new Size(150, 50); typePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 50)); typePanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize)); typePanel.Controls.Add(typePicture, 0, 0); typePanel.Controls.Add(typeLabel, 1, 0); typePanel.RowCount = 1; typePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50F)); typePanel.TabIndex = 0; typePanel.Dock = DockStyle.Top; typePanel.Anchor = AnchorStyles.Top | AnchorStyles.Left; typePanel.Margin = new Padding(5); typePanel.BackColor = Color.Gray; typePanel.MouseEnter += PanelType_MouseEnter; typePanel.MouseLeave += PanelType_MouseLeave; typePanel.MouseDown += TypePanel_MouseDown; foreach (Control control in typePanel.Controls) { control.MouseEnter += PanelType_MouseEnter; control.MouseDown += TypePanel_MouseDown; control.MouseLeave += PanelType_MouseLeave; } // // pictureBox // typePicture.Dock = DockStyle.Fill; typePicture.TabIndex = 0; typePicture.TabStop = false; typePicture.SizeMode = PictureBoxSizeMode.StretchImage; if (type.Icone != null) { MemoryStream ms = new MemoryStream(type.Icone); typePicture.Image = new Bitmap(ms); ms.Close(); } else { using (FileDialog fd = new OpenFileDialog()) { fd.Title = Resources.select_image_for_the_type + type.Libelle_Type; fd.Filter = Resources.images_files_formats; if (fd.ShowDialog() == DialogResult.OK) { try { _image = new Bitmap(fd.FileName); if (_image == null) { throw new FileLoadException(); } _image.SetResolution(50, 50); ImageConverter converter = new ImageConverter(); type.Icone = (byte[])converter.ConvertTo(_image, typeof(byte[])); _db.SaveChanges(); typePicture.Image = _image; } catch (FileNotFoundException) { MessageBox.Show(Resources.file_not_found_please_retry); } catch (FileLoadException) { MessageBox.Show(Resources.error_when_opening_the_file_please_retry); } } } } // // label // typeLabel.Anchor = AnchorStyles.Right; typeLabel.AutoSize = true; typeLabel.TabIndex = 1; typeLabel.Text = type.Libelle_Type; typeLabel.ForeColor = Color.White; typeLabel.Name = "typeLabel"; return(typePanel); }