private void deleteLayer(object sender, RoutedEventArgs e)
        {
            EnclosingStructureMaterial esm = esmDataGrid.SelectedItem as EnclosingStructureMaterial;
            EnclosingStructure         es  = cBoxES.SelectedItem as EnclosingStructure;
            int index = cBoxES.SelectedIndex;

            if (esm != null)
            {
                var result = MessageBox.Show("Вы уверены?", "Удалить слой", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    context.EnclosingStructureMaterials.Delete(esm.EnclosingStructureId, esm.MaterialID);
                    es.EnclosingStructureMaterials.Remove(esm);
                    context.Save();
                    context = new EFUnitOfWork("ThermalCalcDbConnection");

                    calculateService = new CalculateService("ThermalCalcDbConnection");
                    calculateService.Calculate();

                    enclosingStructures = new ObservableCollection <EnclosingStructure>(context.EnclosingStructures.GetAll());
                    buildingTypes       = new ObservableCollection <BuildingType>(context.BuildingTypes.GetAll());
                    cities    = new ObservableCollection <City>(context.Cities.GetAll());
                    materials = new ObservableCollection <Material>(context.Materials.GetAll());

                    cBoxES.DataContext   = enclosingStructures;
                    cBoxES.SelectedIndex = index;
                }
            }
        }
        private void editLayer(object sender, RoutedEventArgs e)
        {
            EnclosingStructureMaterial esm = esmDataGrid.SelectedItem as EnclosingStructureMaterial;
            EnclosingStructure         es  = cBoxES.SelectedItem as EnclosingStructure;
            int index = cBoxES.SelectedIndex;

            if (esm != null)
            {
                AddEditESMaterialWindow addEditESMaterialWindow = new AddEditESMaterialWindow();
                var result = addEditESMaterialWindow.ShowDialog();

                if (result == true)
                {
                    esm.MaterialID     = addEditESMaterialWindow.AddMaterialID;
                    esm.LayerThickness = addEditESMaterialWindow.AddLayerThickness;
                    context.Save();
                    context = new EFUnitOfWork("ThermalCalcDbConnection");

                    calculateService = new CalculateService("ThermalCalcDbConnection");
                    calculateService.Calculate();

                    enclosingStructures = new ObservableCollection <EnclosingStructure>(context.EnclosingStructures.GetAll());
                    buildingTypes       = new ObservableCollection <BuildingType>(context.BuildingTypes.GetAll());
                    cities    = new ObservableCollection <City>(context.Cities.GetAll());
                    materials = new ObservableCollection <Material>(context.Materials.GetAll());

                    cBoxES.DataContext   = enclosingStructures;
                    cBoxES.SelectedIndex = index;
                    addEditESMaterialWindow.Close();
                }
            }
        }
        private void editES(object sender, RoutedEventArgs e)
        {
            var enclosingStructure = cBoxES.SelectedItem as EnclosingStructure;
            int index = cBoxES.SelectedIndex;

            if (enclosingStructure != null)
            {
                AddEditESWindow addEditESWindow = new AddEditESWindow(enclosingStructure);
                var             result          = addEditESWindow.ShowDialog();
                if (result == true)
                {
                    context.Save();
                    context = new EFUnitOfWork("ThermalCalcDbConnection");

                    calculateService = new CalculateService("ThermalCalcDbConnection");
                    calculateService.Calculate();

                    enclosingStructures = new ObservableCollection <EnclosingStructure>(context.EnclosingStructures.GetAll());
                    buildingTypes       = new ObservableCollection <BuildingType>(context.BuildingTypes.GetAll());
                    cities    = new ObservableCollection <City>(context.Cities.GetAll());
                    materials = new ObservableCollection <Material>(context.Materials.GetAll());

                    cBoxES.DataContext   = enclosingStructures;
                    cBoxES.SelectedIndex = index;
                    addEditESWindow.Close();
                }
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            context = new EFUnitOfWork("ThermalCalcDbConnection");

            calculateService = new CalculateService("ThermalCalcDbConnection");
            calculateService.Calculate();

            enclosingStructures = new ObservableCollection <EnclosingStructure>(context.EnclosingStructures.GetAll());
            buildingTypes       = new ObservableCollection <BuildingType>(context.BuildingTypes.GetAll());
            cities    = new ObservableCollection <City>(context.Cities.GetAll());
            materials = new ObservableCollection <Material>(context.Materials.GetAll());

            cBoxES.DataContext = enclosingStructures;
        }
        private void editBuildingType(object sender, RoutedEventArgs e)
        {
            ViewBuildingTypeWindow viewBuildingTypeWindow = new ViewBuildingTypeWindow(buildingTypes);
            var result = viewBuildingTypeWindow.ShowDialog();

            if (result == true)
            {
                context.Save();
                context = new EFUnitOfWork("ThermalCalcDbConnection");

                calculateService = new CalculateService("ThermalCalcDbConnection");
                calculateService.Calculate();

                enclosingStructures = new ObservableCollection <EnclosingStructure>(context.EnclosingStructures.GetAll());
                buildingTypes       = new ObservableCollection <BuildingType>(context.BuildingTypes.GetAll());
                cities    = new ObservableCollection <City>(context.Cities.GetAll());
                materials = new ObservableCollection <Material>(context.Materials.GetAll());

                cBoxES.DataContext   = enclosingStructures;
                cBoxES.SelectedIndex = 0;
            }
        }