Ejemplo n.º 1
0
        private void btn_OpenMaterialEditor_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //Check if a group has been selected:
                CarboGroup PotentialSelectedCarboGroup = new CarboGroup();
                PotentialSelectedCarboGroup.MaterialName = "";

                if (dgv_Overview.SelectedItems.Count > 0)
                {
                    var selectedItems = dgv_Overview.SelectedItems;
                    IList <CarboGroup> selectedGroups = new List <CarboGroup>();

                    // ... Add all Names to a List.
                    foreach (var item in selectedItems)
                    {
                        CarboGroup cg = item as CarboGroup;
                        if (cg != null)
                        {
                            selectedGroups.Add(cg);
                        }
                    }

                    if (selectedGroups.Count > 0)
                    {
                        PotentialSelectedCarboGroup = selectedGroups[0];
                    }
                }

                if (CarboLifeProject.CarboDatabase.CarboMaterialList.Count > 0)
                {
                    CarboMaterial carbomat = CarboLifeProject.CarboDatabase.CarboMaterialList[0];

                    if (PotentialSelectedCarboGroup.MaterialName != "")
                    {
                        //A group with a valid material was selected
                        carbomat = PotentialSelectedCarboGroup.Material;
                    }

                    if (carbomat == null)
                    {
                        carbomat = new CarboMaterial();
                    }

                    MaterialEditor materialEditor = new MaterialEditor(carbomat.Name, CarboLifeProject.CarboDatabase);
                    materialEditor.ShowDialog();

                    if (materialEditor.acceptNew == true)
                    {
                        CarboLifeProject.CarboDatabase = materialEditor.returnedDatabase;

                        CarboLifeProject.UpdateAllMaterials();
                    }
                }
                else
                {
                    MessageBox.Show("There were no materials found in the project, please re-create your project");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            CarboLifeProject.CalculateProject();
            refreshData();
        }