示例#1
0
        private void Btn_Material_Click(object sender, RoutedEventArgs e)
        {
            CarboGroup carboGroup = (CarboGroup)dgv_Overview.SelectedItem;

            if (carboGroup != null)
            {
                MaterialEditor materialEditor = new MaterialEditor(carboGroup.Material.Name, CarboLifeProject.CarboDatabase);
                materialEditor.ShowDialog();

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

                    CarboLifeProject.UpdateMaterial(carboGroup, materialEditor.selectedMaterial);

                    /*
                     * carboGroup.Material = materialEditor.selectedMaterial;
                     * carboGroup.MaterialName = materialEditor.selectedMaterial.Name;
                     */
                }
            }
            CarboLifeProject.CalculateProject();
            refreshData();
        }
示例#2
0
        private void Btn_Material_Click(object sender, RoutedEventArgs e)
        {
            /*
             * if (dgv_Overview.SelectedItems.Count > 0)
             * {
             *  try
             *  {
             *      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;
             *          selectedGroups.Add(cg);
             *      }
             *
             *      if (selectedGroups.Count > 0)
             *      {
             *          CarboGroup carboGroup = selectedGroups[0];
             *
             *          MaterialEditor materialEditor = new MaterialEditor(carboGroup.Material.Name, CarboLifeProject.CarboDatabase);
             *          materialEditor.ShowDialog();
             *
             *          if (materialEditor.acceptNew == true)
             *          {
             *              CarboLifeProject.CarboDatabase = materialEditor.returnedDatabase;
             *
             *              foreach (CarboGroup cg in selectedGroups)
             *              {
             *                  CarboLifeProject.UpdateMaterial(cg, materialEditor.selectedMaterial);
             *              }
             *              CarboLifeProject.UpdateAllMaterials();
             *          }
             *      }
             *  }
             *  catch(Exception ex)
             *  {
             *      MessageBox.Show(ex.Message);
             *  }
             * }
             */

            if (dgv_Overview.SelectedItems.Count > 0)
            {
                try
                {
                    //Select all the groups
                    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;
                        selectedGroups.Add(cg);
                    }

                    if (selectedGroups.Count > 0)
                    {
                        CarboGroup carboGroup = selectedGroups[0];

                        MaterialSelector materialEditor = new MaterialSelector(carboGroup.Material.Name, CarboLifeProject.CarboDatabase);
                        materialEditor.ShowDialog();
                        //If okay change the materials and re-calculate project
                        if (materialEditor.isAccepted == true)
                        {
                            foreach (CarboGroup cg in selectedGroups)
                            {
                                CarboLifeProject.UpdateMaterial(cg, materialEditor.selectedMaterial);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }



            CarboLifeProject.CalculateProject();
            refreshData();
        }