private displayMaterial PushMaterialControl(int summaryTop, int summaryleft, MaterialsBySupplier material)
        {
            var displayMaterialControl = new displayMaterial(material);

            displayMaterialControl.SelectionChanged += DisplayMaterialControl_SelectionChanged;
            displayMaterialControl.Top   = summaryTop;
            displayMaterialControl.Width = 208;
            //    displayMaterialControl.Height = 126;
            displayMaterialControl.Left = summaryleft;

            if (this.pnlMaterialDisplay.InvokeRequired)
            {
                this.pnlMaterialDisplay.Invoke(new MethodInvoker(delegate
                {
                    this.pnlMaterialDisplay.Controls.Add(displayMaterialControl);
                }));
            }
            else
            {
                this.pnlMaterialDisplay.Controls.Add(displayMaterialControl);
            }


            return(displayMaterialControl);
        }
        private void DisplayMaterialControl_SelectionChanged(object sender, EventArgs e)
        {
            displayMaterial displayMaterial = sender as displayMaterial;

            if (displayMaterial != null)
            {
                if (displayMaterial.IsSelected)
                {
                    if (!SelectedMaterials.Contains(displayMaterial.Material))
                    {
                        SelectedMaterials.Add(displayMaterial.Material);
                    }
                }
                else
                {
                    if (SelectedMaterials.Contains(displayMaterial.Material))
                    {
                        SelectedMaterials.Remove(displayMaterial.Material);
                    }
                }
                UpdateControls();
            }
        }
        private void FillAvailableMaterials()
        {
            SelectedMaterials = new List <MaterialsBySupplier>();
            UpdateControls();

            var summaryTop  = 24;
            var summaryleft = 24;

            var i = 0;

            foreach (var catalog in this._allOnlineMaterials)
            {
                List <MaterialsBySupplier> materialListBySupplier = new List <MaterialsBySupplier>();
                materialListBySupplier = catalog.Value.OrderBy(x => x.Supplier).ToList();

                foreach (var materialBySupplier in materialListBySupplier)
                {
                    foreach (var material in materialBySupplier.Materials)
                    {
                        i += 1;
                        var materialWithSupplier = new MaterialsBySupplier();
                        materialWithSupplier.Supplier = materialBySupplier.Supplier;
                        materialWithSupplier.Materials.Add(material);

                        displayMaterial displayMaterialControl = PushMaterialControl(summaryTop, summaryleft, materialWithSupplier);
                        if (i % 3 == 0)
                        {
                            summaryTop += (displayMaterialControl.Height + 24);
                            summaryleft = 24;
                        }
                        else
                        {
                            summaryleft += (displayMaterialControl.Width + 24);
                        }
                    }
                }
                if (this.pnlMaterialDisplay.InvokeRequired)
                {
                    this.pnlMaterialDisplay.Invoke(new MethodInvoker(delegate
                    {
                        this.pnlMaterialDisplay.AutoScroll = true;
                    }));
                }
                else
                {
                    this.pnlMaterialDisplay.AutoScroll = true;
                }
            }

            #region Testing Data
            //foreach (var materialBySupplier in MaterialManager.Catalog)
            //{
            //    foreach (var material in materialBySupplier.Materials)
            //    {
            //        i += 1;
            //        if (i % 3 == 0)
            //        {
            //            var displayMaterialControl = new displayMaterial(material);
            //            displayMaterialControl.SelectionChanged += DisplayMaterialControl_SelectionChanged;
            //            displayMaterialControl.Top = summaryTop;
            //            displayMaterialControl.Width = 208;
            //            displayMaterialControl.Height = 126;
            //            displayMaterialControl.Left = summaryleft;
            //            this.pnlMaterialDisplay.Controls.Add(displayMaterialControl);
            //            summaryTop += (displayMaterialControl.Height + 24);
            //            summaryleft = 24;
            //        }
            //        else
            //        {
            //            var displayMaterialControl = new displayMaterial(material);
            //            displayMaterialControl.SelectionChanged += DisplayMaterialControl_SelectionChanged;
            //            displayMaterialControl.Top = summaryTop;
            //            displayMaterialControl.Width = 208;
            //            displayMaterialControl.Height = 126;
            //            displayMaterialControl.Left = summaryleft;
            //            this.pnlMaterialDisplay.Controls.Add(displayMaterialControl);
            //            summaryleft += (displayMaterialControl.Width + 24);
            //        }
            //    }
            //}
            //this.pnlMaterialDisplay.AutoScroll = true;
            #endregion
        }