private void TryToAssignPhysicalRoleFromString(Layer l, string s)
        {
            PhysicalRole roleToAssign  = ctx.PhysicalRoles.Where(x => x.ShortName == "UN").First();//unassigned role
            PhysicalRole roleFoundInDB = null;

            try
            {
                roleFoundInDB = ctx.PhysicalRoles.Where(x => x.ShortName == s | x.LongName == s).First();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }
            if (roleFoundInDB != null)
            {
                roleToAssign = roleFoundInDB;
                Debug.WriteLine("Assigned role: " + roleToAssign.ShortName);
            }
            l.PhysicalRole = roleToAssign;
        }
示例#2
0
 public PhysicalRoleVM()
 {
     ThePhysicalRole = new PhysicalRole();
 }
        public static void GenerateDeviceFabricationSpecification(DeviceBatch devBatch)
        {
            try
            {
                using (var p = new ExcelPackage())
                {
                    string batchName = string.Concat(devBatch.FabDate.ToString("MMddyy"), " ", devBatch.Name);
                    //make a new workbook
                    var ws = p.Workbook.Worksheets.Add(batchName);
                    //find the maximum number of layers of a particular physical role in each device
                    List <PhysicalRole> rolesList   = new List <PhysicalRole>();
                    HashSet <string> testConditions = new HashSet <string>();
                    foreach (Device d in devBatch.Devices)
                    {
                        foreach (DeviceLJVScanSummary ss in d.DeviceLJVScanSummaries)
                        {
                            testConditions.Add(ss.TestCondition);
                        }
                    }
                    List <string> testConditionsList = testConditions.ToList();
                    int testConditionCounter         = 0;
                    foreach (string condition in testConditions)
                    {
                        Debug.WriteLine("Found testCondition: " + condition);
                        testConditionCounter++;
                    }
                    testConditionsList.Sort();
                    foreach (Device d in devBatch.Devices)
                    {
                        PhysicalRole previousRole = new PhysicalRole();
                        int duplicatesCounter     = 0;
                        foreach (Layer l in d.Layers)
                        {
                            //if the physical role is not in the list, add it
                            if (!rolesList.Contains(l.PhysicalRole))
                            {
                                //if it's at the end of the present role list, add it
                                if (l.PositionIndex == rolesList.Count())
                                {
                                    rolesList.Add(l.PhysicalRole);
                                }
                                else //otherwise, find the index of previousRole in rolesList and insert l.PhysicalRole
                                {
                                    var previousRoleIndexInList = rolesList.IndexOf(previousRole);
                                    rolesList.Insert(previousRoleIndexInList + 1, l.PhysicalRole);
                                }

                                /*
                                 * else //else, insert it after the other layer with the same index
                                 *  rolesList.Insert(l.PositionIndex + duplicatesCounter, l.PhysicalRole);
                                 */
                            }
                            //if it's the same as the previous layer, add a duplicate (note that this causes problems if more than 2 layers share a physical role (unlikely scenario that I'm too lazy to figure out how to avoid))
                            if (l.PhysicalRole == previousRole)
                            {
                                int count = rolesList.Where(x => x.Equals(l.PhysicalRole)).Count();
                                if (count == 1)//don't keep adding the same layer for multiple bilayer devices
                                {
                                    int index = rolesList.IndexOf(previousRole);
                                    rolesList.Insert(index, l.PhysicalRole);
                                    duplicatesCounter++;
                                }
                            }
                            previousRole = l.PhysicalRole;
                        }
                    }
                    //add labels to the 2nd row of the spreadsheet (leaving space in first row for expansion)
                    ws.Cells[2, 1].Value = "Device #";
                    for (int i = 0; i < rolesList.Count; i++)
                    {
                        ws.Cells[2, i + 2].Value = rolesList[i].LongName;
                    }
                    //insert values from each layer into relevant cells
                    foreach (Device d in devBatch.Devices)
                    {
                        ws.Cells[d.BatchIndex + 2, 1].Value = d.BatchIndex;
                        int rolesListCounter = 0;
                        foreach (Layer l in d.Layers)
                        {
                            string cellString = "something weird happened";
                            //this is a lazy solution that needs to be fixed at some point since Patterned TCOs are not necessarilly produced via sputtering processes
                            if (l.DepositionMethod.Name == "TCO Substrate")
                            {
                                cellString =
                                    string.Concat(
                                        l.Material.Supplier,
                                        " ",
                                        l.Material.Name,
                                        " ",
                                        l.SheetResistance,
                                        "  Ω/□"
                                        );
                            }
                            else if (l.DepositionMethod.Name == "Spincoating")
                            {
                                cellString =
                                    string.Concat(
                                        l.Solution.Material.Name,
                                        " (",
                                        l.Solution.Solvent,
                                        ") ",
                                        l.Solution.Concentration,
                                        "mg/mL, ",
                                        l.RPM,
                                        "RPM, ",
                                        l.AnnealTemp,
                                        "C ",
                                        l.AnnealDuration,
                                        "m ",
                                        l.Comment
                                        );
                            }
                            else if (l.DepositionMethod.Name == "Thermal Evaporation")
                            {
                                cellString =
                                    string.Concat(
                                        l.Material.Name,
                                        " ",
                                        l.Thickness,
                                        "nm"
                                        );
                            }
                            else if (l.DepositionMethod.Name == "Manual Pipetting")
                            {
                                cellString =
                                    string.Concat(
                                        l.Material.Name,
                                        " ",
                                        l.CureCondition,
                                        " ",
                                        l.CureTime,
                                        "m"
                                        );
                            }
                            Debug.WriteLine("Physical role: " + l.PhysicalRole.LongName + " at index: " + rolesListCounter);
                            if (rolesListCounter < rolesList.Count() && l.PhysicalRole == rolesList[rolesListCounter])
                            {
                                ws.Cells[d.BatchIndex + 2, rolesListCounter + 2].Value = cellString;
                                rolesListCounter++;
                            }
                            else
                            {
                                while (rolesListCounter < rolesList.Count() && l.PhysicalRole != rolesList[rolesListCounter])
                                {
                                    rolesListCounter++;
                                    if (rolesListCounter < rolesList.Count && l.PhysicalRole == rolesList[rolesListCounter])
                                    {
                                        ws.Cells[d.BatchIndex + 2, rolesListCounter + 2].Value = cellString;
                                    }
                                }
                            }
                        }
                        ws.Cells[d.BatchIndex + 2, rolesList.Count + 2].Value = d.Label;
                        ws.Cells[d.BatchIndex + 2, rolesList.Count + 3].Value = d.Comment;
                        //data reporting section
                        for (int i = 0; i < testConditions.Count(); i++)
                        {
                            foreach (DeviceLJVScanSummary ss in d.DeviceLJVScanSummaries)
                            {
                                if (ss.TestCondition == testConditionsList[i])
                                {
                                    Debug.WriteLine("Adding data to cell for device " + d.BatchIndex + " with testCondition " + ss.TestCondition);
                                    decimal minEQE = ss.LJVScans.Where(x => x.MaxEQE == ss.LJVScans.Min(y => y.MaxEQE)).First().MaxEQE;
                                    decimal maxEQE = ss.MaxEQE;
                                    decimal minLuminanceAtPeakEQE = ss.LJVScans.Where(x => x.LuminanceAtMaxEQE == ss.LJVScans.Min(y => y.LuminanceAtMaxEQE)).First().LuminanceAtMaxEQE ?? default(int);
                                    decimal maxLuminanceAtPeakEQE = ss.LJVScans.Where(x => x.LuminanceAtMaxEQE == ss.LJVScans.Max(y => y.LuminanceAtMaxEQE)).First().LuminanceAtMaxEQE ?? default(int);
                                    decimal minAt1kNitsEQE        = ss.LJVScans.Where(x => x.At1kNitsEQE == ss.LJVScans.Min(y => y.At1kNitsEQE)).First().At1kNitsEQE;
                                    decimal maxAt1kNitsEQE        = ss.Max1kNitsEQE;
                                    string cellString             = string.Concat(
                                        minEQE,
                                        "-",
                                        maxEQE,
                                        "% ",
                                        minLuminanceAtPeakEQE,
                                        "-",
                                        maxLuminanceAtPeakEQE,
                                        "nits (1K, ",
                                        minAt1kNitsEQE,
                                        "-",
                                        maxAt1kNitsEQE,
                                        "%)"
                                        );
                                    ws.Cells[d.BatchIndex + 2, rolesList.Count + i + 4].Value = cellString; //+4 because i starts at 0 and d.comment is offset by 3 columns from rolesList.Count
                                }
                            }
                        }
                    }
                    ws.Cells[2, rolesList.Count + 2].Value = "Device Label";
                    ws.Cells[2, rolesList.Count + 3].Value = "Comment";
                    //label test conditions
                    for (int i = 1; i <= testConditionsList.Count(); i++)
                    {
                        ws.Cells[2, rolesList.Count + i + 3].Value = testConditionsList[i - 1];
                    }
                    //spreadsheet formatting section
                    ws.DefaultRowHeight = 45;
                    ws.DefaultColWidth  = 20;
                    ws.Row(1).Height    = 15;
                    ws.Row(2).Height    = 30;
                    ws.Column(1).Width  = 7;
                    ws.Column(2).Width  = 7;
                    ws.Column(rolesList.Count).Width             = 9;
                    ws.Column(rolesList.Count).Width             = 13;
                    ws.Cells["A1:Z33"].Style.WrapText            = true;
                    ws.Cells["A1:Z33"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                    ws.View.FreezePanes(1, 33);
                    Process.Start("net.exe", @"use Z: \\169.254.190.155\NPI Shared Data\"); //probably unnecessary but was having an error and this doesn't break anything
                    //string saveString = devBatch.FilePath.Replace(@"Z:\", @"\\169.254.190.155\NPI Shared Data\");
                    string saveString = devBatch.FilePath;
                    saveString = string.Concat(saveString, @"\", devBatch.Name, ".xlsx");
                    p.SaveAs(new FileInfo(saveString));
                }
            }

            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                //MessageBox.Show(e.ToString());
            }
        }