public LJVScanSummaryVM(DeviceLJVScanSummary scansummary)
 {
     //reselect it to avoid multiple references with IEntityChangeTracker thing
     TheLJVScanSummary = ctx.DeviceLJVScanSummaries.Where(x => x.DeviceLJVScanSummaryId == scansummary.DeviceLJVScanSummaryId).FirstOrDefault();
     PopulateVMPropertiesFromChildren();
     if (TheLJVScanSummary.StatsDataPath != null)
     {
         LoadStatsDataIntoList(TheLJVScanSummary.StatsDataPath);
     }
 }
 public LJVScanSummaryVM()
 {
     TheLJVScanSummary = new DeviceLJVScanSummary();
 }
 public LJVScanSummaryVM(DeviceBatchContext context) : base(context)
 {
     System.Diagnostics.Debug.WriteLine("LJVScanSummaryVM instantiated");
     TheLJVScanSummary = new DeviceLJVScanSummary();
 }
        public static void GenerateLJVScanSummary(DeviceLJVScanSummary scanSummary)
        {
            Debug.WriteLine("Generating summary spreadsheet for " + scanSummary.Device.Label + " in directory: " + scanSummary.SpreadsheetReportPath);

            List <PropertyInfo> ignoredProps = new List <PropertyInfo>()
            {
                typeof(LJVScan).GetProperty("LJVScanId"),
                typeof(DeviceLJVScanSummary).GetProperty("DeviceLJVScanSummaryId"),
                typeof(ELSpectrum).GetProperty("ELSpectrumId"),
                typeof(LJVScan).GetProperty("FilePath"),
                typeof(DeviceLJVScanSummary).GetProperty("FilePath"),
                typeof(ELSpectrum).GetProperty("FilePath"),
                typeof(LJVScan).GetProperty("Pixel"),
                typeof(ELSpectrum).GetProperty("Pixel"),
                typeof(LJVScan).GetProperty("DeviceLJVScanSummary"),
                typeof(ELSpectrum).GetProperty("DeviceLJVScanSummary"),
                typeof(LJVScan).GetProperty("Image"),
                typeof(LJVScan).GetProperty("LJVScanSpec"),
                typeof(DeviceLJVScanSummary).GetProperty("Device"),
                typeof(DeviceLJVScanSummary).GetProperty("TestCondition"),
                typeof(ELSpectrum).GetProperty("QDBatch"),
                typeof(DeviceLJVScanSummary).GetProperty("ELSpectras"),
                typeof(DeviceLJVScanSummary).GetProperty("LJVScans"),
                typeof(DeviceLJVScanSummary).GetProperty("Images")
            };
            var singleScanPropsList  = new List <PropertyInfo>(typeof(LJVScan).GetProperties());
            var ELSpecPropsList      = new List <PropertyInfo>(typeof(ELSpectrum).GetProperties());
            var scanSummaryPropsList = new List <PropertyInfo>(typeof(DeviceLJVScanSummary).GetProperties());

            //remove ignored properties
            foreach (PropertyInfo p in ignoredProps)
            {
                if (p != null)
                {
                    for (int i = singleScanPropsList.Count - 1; i >= 0; i--)
                    {
                        if (singleScanPropsList[i].Name == p.Name)
                        {
                            singleScanPropsList.RemoveAt(i);
                        }
                    }
                    for (int i = scanSummaryPropsList.Count - 1; i >= 0; i--)
                    {
                        if (scanSummaryPropsList[i].Name == p.Name)
                        {
                            scanSummaryPropsList.RemoveAt(i);
                        }
                    }
                    for (int i = ELSpecPropsList.Count - 1; i >= 0; i--)
                    {
                        if (ELSpecPropsList[i].Name == p.Name)
                        {
                            ELSpecPropsList.RemoveAt(i);
                        }
                    }
                }
            }
            using (var p = new ExcelPackage())
            {
                string deviceName = scanSummary.Device.Label;
                //make a new workbook
                var ws = p.Workbook.Worksheets.Add(deviceName);
                //iterate over each LJVScan, then each property of LJVScan to populate ws cells
                int scanCounter = 1;
                //int propCounter = 2;
                ws.Cells[1, 1].Value = "Property Name";
                for (int i = 2; i <= singleScanPropsList.Count + 1; i++)
                {
                    ws.Cells[i, 1].Value = singleScanPropsList[i - 2].Name;
                }
                for (int i = 0; i <= ELSpecPropsList.Count - 1; i++)
                {
                    ws.Cells[i + singleScanPropsList.Count + 2, 1].Value = ELSpecPropsList[i].Name;
                }
                foreach (LJVScan l in scanSummary.LJVScans)
                {
                    try
                    {
                        ws.Cells[1, scanCounter + 1].Value = l.Pixel.Site;
                        for (int i = 2; i <= singleScanPropsList.Count + 1; i++)
                        {
                            ws.Cells[i, scanCounter + 1].Value = singleScanPropsList[i - 2].GetValue(l);
                        }
                        //match spectra to LJVscans by pixel name
                        foreach (ELSpectrum es in scanSummary.ELSpectrums)
                        {
                            if (es.Pixel.Site == l.Pixel.Site)
                            {
                                for (int i = 0; i <= ELSpecPropsList.Count - 1; i++)
                                {
                                    ws.Cells[i + singleScanPropsList.Count + 2, scanCounter + 1].Value = ELSpecPropsList[i].GetValue(es);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }
                    scanCounter++;
                }
                ws.Cells[singleScanPropsList.Count + ELSpecPropsList.Count + 3, 1].Value = "Device stats";
                for (int i = 0; i <= scanSummaryPropsList.Count - 1; i++)
                {
                    ws.Cells[i + singleScanPropsList.Count + ELSpecPropsList.Count + 4, 1].Value = scanSummaryPropsList[i].Name;
                    ws.Cells[i + singleScanPropsList.Count + ELSpecPropsList.Count + 4, 2].Value = scanSummaryPropsList[i].GetValue(scanSummary);
                }
                ws.Cells.AutoFitColumns();
                p.SaveAs(new FileInfo(scanSummary.SpreadsheetReportPath));
            }
        }