Esempio n. 1
0
        private void btn_Open_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|All files (*.*)|*.*";

                var path = openFileDialog.ShowDialog();

                if (openFileDialog.FileName != "")
                {
                    CarboProject newProject = new CarboProject();

                    CarboProject buffer = new CarboProject();
                    newProject           = buffer.DeSerializeXML(openFileDialog.FileName);
                    newProject.justSaved = true;

                    Dispatcher.BeginInvoke(new Action(() => OpenProject(newProject)), DispatcherPriority.ContextIdle, null);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";

                var path = openFileDialog.ShowDialog();

                if (openFileDialog.FileName != "")
                {
                    CarboProject newProject = new CarboProject();

                    CarboProject buffer = new CarboProject();
                    newProject = buffer.DeSerializeXML(openFileDialog.FileName);

                    CarboLifeUI.UI.CarboLifeMainWindow CarboApp = new CarboLifeUI.UI.CarboLifeMainWindow(newProject);
                    CarboApp.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 3
0
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                DependencyObject    parent       = VisualTreeHelper.GetParent(this);
                Window              parentWindow = Window.GetWindow(parent);
                CarboLifeMainWindow mainViewer   = parentWindow as CarboLifeMainWindow;

                if (mainViewer != null)
                {
                    CarboLifeProject = mainViewer.getCarbonLifeProject();
                }

                if (CarboLifeProject != null)
                {
                    //A project Is loaded, Proceed to next

                    SetupInterFace();
                }


                //Rebuild the materialList
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 4
0
        internal static string writeHeader(CarboProject carboProject)
        {
            string html = "";

            try
            {
                html = "<HTML><HEAD><TITLE>Carbon Life Calculation for: " + carboProject.Name + " </TITLE>" + System.Environment.NewLine;
                //add header row
                html += "<LINK href = 'https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet'>" + System.Environment.NewLine;

                html += getCSS();
                html += "</HEAD><BODY>";
                html += "<H1>Project Info:</H1>" + System.Environment.NewLine;
                html += "<H2>Name: " + carboProject.Name + "</H2>" + System.Environment.NewLine;
                html += "<H2>Description: " + carboProject.Description + "</H2>" + System.Environment.NewLine;
                html += "<H2>Value: £ " + carboProject.Value + " </H2>" + System.Environment.NewLine;
                html += "<H2>Area: " + carboProject.Area + " m²</H2>" + System.Environment.NewLine;
                html += "<H2>" + Math.Round(carboProject.getTotalEC(), 2) + " tCO<SUB>2</SUB></H2>" + System.Environment.NewLine;
                html += "<H2>" + Math.Round((carboProject.getTotalEC() / carboProject.Area), 2) + " tCO<SUB>2</SUB>/m²</H2>" + System.Environment.NewLine;

                html += "<H2>Category: " + carboProject.Category + "</H2>" + System.Environment.NewLine;
                html += "<H2>Export Date: " + DateTime.Today.ToShortDateString() + "</H2>" + System.Environment.NewLine;

                html += "<H3>" + carboProject.getSummaryText(true, true, true, true) + "</H3>" + System.Environment.NewLine;
            }
            catch (Exception ex)
            {
            }

            return(html);
        }
Esempio n. 5
0
        /// <summary>
        /// Builds an overview A1-Mix graph for the user to add to a graph
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public static SeriesCollection BuildBarGraph(CarboProject project)
        {
            List <CarboDataPoint> pointCollection = new List <CarboDataPoint>();

            // get the current Project
            pointCollection = project.getPhaseTotals();

            SeriesCollection result = new SeriesCollection();

            //Build series

            foreach (CarboDataPoint pont in pointCollection)
            {
                StackedColumnSeries series = new StackedColumnSeries
                {
                    Values = new ChartValues <double>
                    {
                        Math.Round((pont.Value / 1000), 2),
                    },
                    StackMode  = StackMode.Values,
                    DataLabels = true,
                    Title      = pont.Name
                };

                result.Add(series);
            }

            return(result);
        }
Esempio n. 6
0
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                DependencyObject    parent       = VisualTreeHelper.GetParent(this);
                Window              parentWindow = Window.GetWindow(parent);
                CarboLifeMainWindow mainViewer   = parentWindow as CarboLifeMainWindow;

                if (mainViewer != null)
                {
                    CarboLifeProject = mainViewer.getCarbonLifeProject();
                }

                if (CarboLifeProject != null)
                {
                    //A project Is loaded, Proceed to next

                    RefreshInterFace();

                    if (cbb_GraphType.Items.Count <= 0)
                    {
                        cbb_GraphType.Items.Add("Materials");
                        cbb_GraphType.Items.Add("Totals");
                        cbb_GraphType.Text = "Totals";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 7
0
        public Overview(CarboProject carboLifeProject)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            InitializeComponent();

            CarboLifeProject = carboLifeProject;
        }
Esempio n. 8
0
        private CarboProject openNewProject()
        {
            CarboProject result = null;

            try
            {
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Carbo Life Project File (*.clcx)|*.clcx|Carbo Life Project File (*.xml)| *.xml|All files (*.*)|*.*";

                var path = openFileDialog.ShowDialog();

                if (openFileDialog.FileName != "")
                {
                    CarboProject buffer = new CarboProject();
                    result = buffer.DeSerializeXML(openFileDialog.FileName);

                    result.Audit();
                    result.CalculateProject();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }

            return(result);
        }
Esempio n. 9
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CarboProject newProject = new CarboProject();

            CarboLifeUI.UI.CarboLifeMainWindow CarboApp = new CarboLifeMainWindow(newProject);
            CarboApp.Show();
        }
Esempio n. 10
0
        public static void ExportComaringGraphs(CarboProject carboLifeProject, List <CarboProject> projectListToCompareTo)
        {
            //Check if user has excel
            string path = GetSaveAsLocation();

            if (path != null)
            {
                Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                if (xlApp == null)
                {
                    System.Windows.MessageBox.Show("You need to have excel installed to continue", "Computer says no", MessageBoxButton.OK);
                    return;
                }

                if (carboLifeProject != null)
                {
                    projectListToCompareTo.Insert(0, carboLifeProject);
                }

                CreateTotalsExcelFile(projectListToCompareTo, xlApp, path);

                if (File.Exists(path))
                {
                    System.Windows.MessageBox.Show("Excel export succesful, click OK to open!", "Success!", MessageBoxButton.OK);
                    System.Diagnostics.Process.Start(path);
                }
            }
        }
Esempio n. 11
0
        private void Mnu_openDataBase_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Save First?", "Warning", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.No)
            {
                try
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog();
                    openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";

                    var path = openFileDialog.ShowDialog();

                    if (openFileDialog.FileName != "")
                    {
                        CarboProject newProject = new CarboProject();

                        CarboProject buffer = new CarboProject();
                        carboLifeProject = buffer.DeSerializeXML(openFileDialog.FileName);

                        carboLifeProject.Audit();

                        tab_Main.Visibility = Visibility.Hidden;
                        tab_Main.Visibility = Visibility.Visible;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 12
0
        //public List<Person> Persons { get; set; }
        //public List<MyLocation> Locations { get; set; }


        public MaterialMapper(CarboProject carboProject)
        {
            List <CarboMaterial> list = carboProject.CarboDatabase.CarboMaterialList;



            this.InitializeComponent();

            mappinglist = new List <CarboMapElement>();

            foreach (CarboGroup cg in carboProject.getGroupList)
            {
                //Only add if they have revit elements
                if (cg.AllElements.Count > 0)
                {
                    CarboMapElement mapElement = new CarboMapElement();

                    mapElement.revitName = cg.AllElements[0].MaterialName;
                    mapElement.carboNAME = cg.MaterialName;
                    mapElement.category  = cg.Category;

                    mappinglist.Add(mapElement);
                }
            }

            materialList = new List <CarboName>();
            foreach (CarboMaterial cm in list)
            {
                materialList.Add(new CarboName {
                    carboNAME = cm.Name
                });
            }

            DataContext = this;
        }
Esempio n. 13
0
 private void OpenProject(CarboProject project)
 {
     CarboLifeUI.UI.CarboLifeMainWindow CarboApp = new CarboLifeMainWindow(project);
     this.Visibility = Visibility.Hidden;
     CarboApp.ShowDialog();
     Environment.Exit(0);
     this.Close();
 }
Esempio n. 14
0
        public CarboCompare(CarboProject carboLifeProject)
        {
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
            InitializeComponent();

            CarboLifeProject       = carboLifeProject;
            projectListToCompareTo = new List <CarboProject>();
        }
Esempio n. 15
0
 private void setProject(CarboProject clp)
 {
     if (clp != null)
     {
         projectListToCompareTo.Add(clp);
     }
     RefreshInterFace();
 }
Esempio n. 16
0
        public CarboLifeMainWindow(CarboProject myProject)
        {
            carboLifeProject = myProject;
            //carboDataBase = carboDataBase.DeSerializeXML("");
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            //carboLifeProject.CreateGroups();
            InitializeComponent();
        }
        /////////////

        //public CarboDatabase carboDataBase { get; set; }
        public CarboLifeMainWindow()
        {
            //UserPaths
            PathUtils.CheckFileLocationsNew();

            IsRevit          = false;
            carboLifeProject = new CarboProject();
            InitializeComponent();
        }
Esempio n. 18
0
        private void btn_Add_Click(object sender, RoutedEventArgs e)
        {
            CarboProject clp = openNewProject();

            if (clp != null)
            {
                setProject(clp);
            }
        }
        /// <summary>
        /// Start A new Project
        /// </summary>
        private void mnu_newProject_Click(object sender, RoutedEventArgs e)
        {
            bool fileSaved = false;

            //This bit is a verification code, to make sure the user is given the opportunity to save teh work before continuing:
            if (carboLifeProject.justSaved == false)
            {
                MessageBoxResult result = MessageBox.Show("Do you want to save your project first?", "Warning", MessageBoxButton.YesNoCancel);
                if (result == MessageBoxResult.Yes)
                {
                    if (carboLifeProject.filePath == "")
                    {
                        fileSaved = SaveFileAs();
                    }
                    else
                    {
                        fileSaved = SaveFile(carboLifeProject.filePath);
                    }
                }
                else if (result == MessageBoxResult.No)
                {
                    //The user didnt want to save
                    fileSaved = true;
                }
                else
                {
                    //the user cancels
                    fileSaved = false;
                }
            }
            else
            {
                //The file was already saved
                fileSaved = true;
            }
            //
            //the file is either saved, or used didnt want to save:
            if (fileSaved == true)
            {
                try
                {
                    carboLifeProject = new CarboProject();

                    carboLifeProject.Audit();
                    carboLifeProject.CalculateProject();
                    carboLifeProject.justSaved = false;

                    tab_Main.Visibility = Visibility.Hidden;
                    tab_Main.Visibility = Visibility.Visible;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Esempio n. 20
0
        private void btn_Remove_Click(object sender, RoutedEventArgs e)
        {
            if (liv_Projects.SelectedItems.Count > 0)
            {
                CarboProject selectedProject = liv_Projects.SelectedItem as CarboProject;
                projectListToCompareTo.Remove(selectedProject);
            }

            RefreshInterFace();
        }
        public CarboLifeMainWindow(CarboProject myProject)
        {
            //UserPaths
            PathUtils.CheckFileLocationsNew();

            carboLifeProject = myProject;
            IsRevit          = false;
            //carboDataBase = carboDataBase.DeSerializeXML("");
            AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

            //carboLifeProject.CreateGroups();
            InitializeComponent();
        }
Esempio n. 22
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication app   = commandData.Application;
            UIDocument    uidoc = app.ActiveUIDocument;
            Document      doc   = uidoc.Document;

            string MyAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string MyAssemblyDir  = Path.GetDirectoryName(MyAssemblyPath);

            CarboProject myProject = new CarboProject();

            ICollection <ElementId> selectionList = uidoc.Selection.GetElementIds();


            //Get levels
            List <CarboLevel> levellist = new List <CarboLevel>();
            List <Level>      levels    = new FilteredElementCollector(doc).OfClass(typeof(Level)).Cast <Level>().OrderBy(l => l.Elevation).ToList();

            foreach (Level lvl in levels)
            {
                CarboLevel newlvl = new CarboLevel();
                newlvl.Id    = lvl.Id.IntegerValue;
                newlvl.Name  = lvl.Name;
                newlvl.Level = (lvl.Elevation * 304.8);

                levellist.Add(newlvl);
            }

            myProject.carboLevelList = levellist;

            //Get Settings
            ImportSettingsWindow importGroupWindow = new ImportSettingsWindow(levellist);

            importGroupWindow.ShowDialog();
            CarboRevitImportSettings importsettings = importGroupWindow.importSettings;

            if (importGroupWindow.dialogOk == System.Windows.MessageBoxResult.Yes)
            {
                //Import the elements
            }
            else
            {
                return(Result.Succeeded);
            }


            //Launch normal Command
            CarboLifeRevitImport.ImportElements(app, importsettings, "");

            return(Result.Succeeded);
        }
Esempio n. 23
0
        public static void ExportToExcel(CarboProject carboProject, string Path, bool exportResults, bool exportElements, bool exportMaterials)
        {
            reportpath = Path;

            //Check if user has excel
            Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            if (xlApp == null)
            {
                System.Windows.MessageBox.Show("You need to have excel installed to continue", "Computer says no", MessageBoxButton.OK);
                return;
            }

            CreateExcelFile(carboProject, xlApp, exportResults, exportElements, exportMaterials);
        }
Esempio n. 24
0
        private List <CarboMapElement> GenerateMappinglist(CarboProject returnedDatabase)
        {
            List <CarboMapElement> result = new List <CarboMapElement>
            {
                new CarboMapElement {
                    revitName = "Revit Material 1", carboNAME = "Carbo Material 1"
                },
                new CarboMapElement {
                    revitName = "Revit Material 2", carboNAME = "Carbo Material 2"
                }
            };

            return(result);
        }
Esempio n. 25
0
        private void btn_Materials_Click(object sender, RoutedEventArgs e)
        {
            CarboProject  newProject = new CarboProject();
            CarboDatabase cd         = newProject.CarboDatabase;

            cd.DeSerializeXML("");
            if (newProject != null && cd != null && cd.CarboMaterialList.Count > 0)
            {
                MaterialEditor mateditor = new MaterialEditor(cd.CarboMaterialList[0].Name, cd);
                mateditor.ShowDialog();

                if (mateditor.acceptNew == true)
                {
                    CarboDatabase database = mateditor.returnedDatabase;
                    database.SerializeXML("");
                }
            }
            else
            {
                MessageBox.Show("Template Database not found");
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Returns a comaring bar chart showing the total values of the project
        /// </summary>
        /// <param name="carboLifeProject"></param>
        /// <param name="projectListToCompareTo"></param>
        /// <returns></returns>
        internal static SeriesCollection BuildComparingTotalsBarGraph(CarboProject project, List <CarboProject> projectListToCompareTo)
        {
            SeriesCollection result = new SeriesCollection();

            //Full list to compare to:
            List <CarboProject> fullProjectListToCompareTo = new List <CarboProject>();

            //bool hasCurrent = false;

            if (project != null)
            {
                fullProjectListToCompareTo.Add(project);
                //hasCurrent = true;
            }
            foreach (CarboProject projectToCompare in projectListToCompareTo)
            {
                if (projectToCompare != null)
                {
                    fullProjectListToCompareTo.Add(projectToCompare);
                }
            }
            //The list has been created
            List <List <CarboDataPoint> > pointList = new List <List <CarboDataPoint> >();

            foreach (CarboProject dp in fullProjectListToCompareTo)
            {
                List <CarboDataPoint> listofPoints = dp.getPhaseTotals();
                pointList.Add(listofPoints);
            }

            try
            {
                /*
                 * DataTable dt = new DataTable();
                 *
                 * dt.Columns.Add("A1-A3");
                 * dt.Columns.Add("A4");
                 * dt.Columns.Add("A5");
                 * dt.Columns.Add("B1B7");
                 * dt.Columns.Add("C1-C4");
                 * dt.Columns.Add("D");
                 * dt.Columns.Add("Mix");
                 * dt.Columns.Add("Add");
                 * dt.Columns.Add("B4");
                 *
                 *
                 * foreach (List<CarboDataPoint> pr in pointList)
                 * {
                 *  DataRow dr = dt.NewRow();
                 *  for (int i = 0; i < pr.Count - 1; i++)
                 *  {
                 *      dr[i] = pr[i].Value / 1000;
                 *  }
                 *  dt.Rows.Add(dr);
                 * }
                 *
                 * 0  CarboDataPoint cb_A1A3 = new CarboDataPoint("A1-A3", 0);
                 * 1 CarboDataPoint cb_A4 = new CarboDataPoint("A4", 0);
                 * 2 CarboDataPoint cb_A5 = new CarboDataPoint("A5(Material)",0);
                 * 3 CarboDataPoint cb_A5Global = new CarboDataPoint("A5(Global)", this.A5Global);
                 * 4 CarboDataPoint cb_B1B5 = new CarboDataPoint("B1-B7", 0);
                 * 5 CarboDataPoint cb_C1C4 = new CarboDataPoint("C1-C4", 0);
                 * 6 CarboDataPoint cb_C1Global = new CarboDataPoint("C1(Global)", this.C1Global);
                 * 7 CarboDataPoint cb_D = new CarboDataPoint("D", 0);
                 * 8 CarboDataPoint Added = new CarboDataPoint("Additional", 0);
                 *
                 *
                 */

                //loop though
                // i is nr type of information extracted
                for (int i = 0; i < 9; i++)
                {
                    StackedColumnSeries newSeries = new StackedColumnSeries();

                    ChartValues <double> Values = new ChartValues <double>();

                    //get all Values from all loaded projects
                    foreach (List <CarboDataPoint> dataPointList in pointList)
                    {
                        Values.Add(Math.Round((dataPointList[i].Value / 1000), 1));
                    }

                    newSeries.Title      = pointList[0][i].Name;
                    newSeries.Values     = Values;
                    newSeries.StackMode  = StackMode.Values;
                    newSeries.DataLabels = true;
                    newSeries.Foreground = Brushes.Black;
                    //newSeries.Width = 100;
                    newSeries.MaxColumnWidth = 50;
                    newSeries.LabelsPosition = BarLabelPosition.Perpendicular;
                    result.Add(newSeries);
                }
            }
            catch
            {
                return(null);
            }
            return(result);
        }
Esempio n. 27
0
        internal static SeriesCollection GetPieChartMaterials(CarboProject carboLifeProject)
        {
            SeriesCollection result = new SeriesCollection();

            try
            {
                List <CarboDataPoint>     PieceListMaterial = new List <CarboDataPoint>();
                Func <ChartPoint, string> labelPoint        = chartPoint => string.Format("{0} tCO₂", chartPoint.Y, chartPoint.Participation);

                PieceListMaterial = carboLifeProject.getMaterialTotals();

                PieceListMaterial = PieceListMaterial.OrderByDescending(o => o.Value).ToList();

                //int total = monValues.Sum(x => Convert.ToInt32(x));

                double total = PieceListMaterial.Sum(x => x.Value);

                //Old Code:
                //if there are too many materials in the list combine any items over 8.

                /*
                 * if (PieceListMaterial.Count > 8)
                 * {
                 *  CarboDataPoint otherPoint = new CarboDataPoint();
                 *  otherPoint.Name = "Miscellaneous";
                 *
                 *  for (int i = PieceListMaterial.Count -1; i>7; i--)
                 *  {
                 *      CarboDataPoint cp = PieceListMaterial[i] as CarboDataPoint;
                 *      otherPoint.Value += cp.Value;
                 *      PieceListMaterial.RemoveAt(i);
                 *  }
                 *  PieceListMaterial.Add(otherPoint);
                 * }
                 */

                //New Code: Trim all values below 5%,
                List <int> counter = new List <int>();

                CarboDataPoint otherPoint = new CarboDataPoint();
                otherPoint.Name = "Miscellaneous";

                for (int i = PieceListMaterial.Count - 1; i >= 0; i--)
                {
                    CarboDataPoint cp     = PieceListMaterial[i] as CarboDataPoint;
                    double         pecent = cp.Value / total;
                    if (pecent <= 0.05 && pecent > 0)
                    {
                        //The item is too small for the graph:
                        otherPoint.Value += cp.Value;
                        counter.Add(i);
                    }
                }

                //If used, add to the list, only if more than one materials / elements were merged.
                if (otherPoint.Value > 0 && counter.Count > 1)
                {
                    PieceListMaterial.Add(otherPoint);
                    //Remove the items from the list
                    foreach (int i in counter)
                    {
                        PieceListMaterial.RemoveAt(i);
                    }
                }



                //make positive if negative
                foreach (CarboDataPoint cp in PieceListMaterial)
                {
                    if (cp.Value < 0)
                    {
                        cp.Name  = "(Negative)" + cp.Name;
                        cp.Value = cp.Value * -1;
                    }
                }


                foreach (CarboDataPoint ppin in PieceListMaterial)
                {
                    PieSeries newSeries = new PieSeries
                    {
                        Title  = ppin.Name,
                        Values = new ChartValues <double> {
                            Math.Round(ppin.Value, 2)
                        },
                        PushOut    = 1,
                        DataLabels = true,
                        LabelPoint = labelPoint
                    };
                    newSeries.Foreground = Brushes.Black;
                    newSeries.FontWeight = FontWeights.Normal;
                    newSeries.FontStyle  = FontStyles.Normal;
                    newSeries.FontSize   = 12;

                    result.Add(newSeries);
                }
            }
            catch
            {
                return(null);
            }
            return(result);
        }
Esempio n. 28
0
        /// <summary>
        /// This returns the pie chart of the projects phases total A1-D and Mixed
        /// </summary>
        /// <param name="carboLifeProject"></param>
        /// <returns></returns>
        internal static SeriesCollection GetPieChartTotals(CarboProject carboLifeProject)
        {
            SeriesCollection result = new SeriesCollection();

            try
            {
                List <CarboDataPoint> PieceListLifePoint = new List <CarboDataPoint>();

                PieceListLifePoint = carboLifeProject.getPhaseTotals();

                //Remove the zero's
                for (int i = PieceListLifePoint.Count - 1; i >= 0; i--)
                {
                    CarboDataPoint cp = PieceListLifePoint[i] as CarboDataPoint;
                    if (cp.Value == 0)
                    {
                        PieceListLifePoint.RemoveAt(i);
                    }
                }

                //make positive if negative
                foreach (CarboDataPoint cp in PieceListLifePoint)
                {
                    if (cp.Value < 0)
                    {
                        cp.Name  = "(Negative)" + cp.Name;
                        cp.Value = cp.Value * -1;
                    }
                }


                Func <ChartPoint, string> labelPoint = chartPoint => string.Format("{0} tCO₂", chartPoint.Y, chartPoint.Participation);


                foreach (CarboDataPoint ppin in PieceListLifePoint)
                {
                    PieSeries newSeries = new PieSeries
                    {
                        Title  = ppin.Name,
                        Values = new ChartValues <double> {
                            Math.Round(ppin.Value / 1000, 2)
                        },
                        PushOut    = 1,
                        DataLabels = true,
                        LabelPoint = labelPoint
                    };

                    newSeries.Foreground = Brushes.Black;
                    newSeries.FontWeight = FontWeights.Normal;
                    newSeries.FontStyle  = FontStyles.Normal;
                    newSeries.FontSize   = 12;

                    result.Add(newSeries);
                }
            }
            catch
            {
                return(null);
            }
            return(result);
        }
Esempio n. 29
0
        private static string writeMaterialTable(CarboProject carboProject)
        {
            string html = "<H1><B>" + "Material Properties" + "</B></H1><BR>" + System.Environment.NewLine;

            html += "<TABLE border=1 cellpadding=0 cellspacing=0>";

            html += "<TR></TR>";
            //ResultTable in a table
            try
            {
                //Write Headers:

                html += "<TR>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "Material" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "Category" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "Description" + "</B></TD>" + System.Environment.NewLine;

                html += "<TD width=" + 50 + "><B>" + "Density" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "ECI" + "</B></TD>" + System.Environment.NewLine;

                html += "<TD width=" + 50 + "><B>" + "ECI A1-A3" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "ECI A4" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "ECI A5" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "ECI B1-B5" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "ECI C1-C4" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD width=" + 50 + "><B>" + "D" + "</B></TD>" + System.Environment.NewLine;

                html += "</TR>" + System.Environment.NewLine;
                //UNITS
                html += "<TR>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "" + "</B></TD>" + System.Environment.NewLine;

                html += "<TD align='middle'><B>" + "kg/m³" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;

                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;
                html += "<TD align='middle'><B>" + "kgCo<SUB>2</SUB>/kg" + "</B></TD>" + System.Environment.NewLine;

                html += "</TR>" + System.Environment.NewLine;

                //Write Data:

                ObservableCollection <CarboGroup> cglist = carboProject.getGroupList;
                cglist = new ObservableCollection <CarboGroup>(cglist.OrderBy(i => i.MaterialName));

                string material = "";

                foreach (CarboGroup cbg in cglist)
                {
                    if (cbg.MaterialName != material)
                    {
                        material = cbg.MaterialName;

                        html += "<TR>" + System.Environment.NewLine;

                        html += "<TD align='left' valign='middle'>" + cbg.Material.Name + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + cbg.Material.Category + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + cbg.Material.Description + "</td>" + System.Environment.NewLine;

                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Density, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.ECI, 2) + "</td>" + System.Environment.NewLine;

                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_A1A3, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_A4, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_A5, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_B1B5, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_C1C4, 2) + "</td>" + System.Environment.NewLine;
                        html += "<TD align='left' valign='middle'>" + Math.Round(cbg.Material.ECI_D, 2) + "</td>" + System.Environment.NewLine;

                        html += "</TR>" + System.Environment.NewLine;
                    }
                }
                html += "</TABLE>";
            }
            catch (Exception ex)
            {
            }

            return(html);
        }
Esempio n. 30
0
        public static void CreateReport(CarboProject carboProject)
        {
            //Create a File and save it as a HTML File
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Title            = "Specify report directory";
            saveDialog.Filter           = "HTML Files|*.html";
            saveDialog.FilterIndex      = 2;
            saveDialog.RestoreDirectory = true;

            saveDialog.ShowDialog();

            string Path = saveDialog.FileName;

            reportpath = Path;

            if (File.Exists(Path))
            {
                MessageBoxResult msgResult = System.Windows.MessageBox.Show("This file already exists, do you want to overwrite this file ?", "", MessageBoxButton.YesNo);

                if (msgResult == MessageBoxResult.Yes)
                {
                    using (var fs = File.Open(Path, FileMode.Open))
                    {
                        var canRead  = fs.CanRead;
                        var canWrite = fs.CanWrite;

                        if (canWrite == false)
                        {
                            System.Windows.MessageBox.Show("This file cannot be opened, please close the file and try again", "Warning", MessageBoxButton.OK);
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }

            //EXPORT IMAGES HERE:


            //HTML WRITING;
            report = writeHeader(carboProject);

            report += writeReportTable(carboProject);

            report += writeMaterialTable(carboProject);

            report += closeHTML();

            if (report != "")
            {
                using (StreamWriter sw = new StreamWriter(reportpath))
                {
                    sw.WriteLine(report);
                    sw.Close();
                }
            }

            if (File.Exists(reportpath))
            {
                System.Windows.MessageBox.Show("Report succesfully created!", "Success!", MessageBoxButton.OK);
                System.Diagnostics.Process.Start(reportpath);
            }
            //VOID
        }