我对以下代码有疑问。如果它与之前创建的不同,我只需要创建一个新的 pcba 节点。如果该变量不变,我需要使用相同的变量。
foreach (XmlNode node in dc.DocumentElement.ChildNodes)
{
PCBA pcb = null;
if (serialPCB != node.Attributes["PCBpos"].Value.ToString())
pcb = new PCBA();
pcb.PCBA_Status = status;
long number = 0;
bool validation = false;
if (node.Attributes != null && node.Attributes["PCBpos"] != null)
{
validation = long.TryParse(node.Attributes["PCBpos"].Value, out number);
}
//bool validation = long.TryParse(node.Attributes["PCBpos"].Value, out number);
if (validation == true)
{
pcb.PCBA_POSITION = node.Attributes["PCBpos"].Value.ToString();
serialPCB = node.Attributes["PCBpos"].Value.ToString();
if (status != "PASS")
{
List<Group> groups = new List<Group>();
Group group = new Group();
group.Group_Name = node.Attributes["COMP_NAME"].Value.ToString();
group.Group_Status = status;
group.Group_FailureCode = node.Attributes["FaultName"].Value.ToString();
List<Measurement> measurements = new List<Measurement>();
Measurement measurement = new Measurement();
measurement.Measurement_Name = node.Attributes["COMP_NAME"].Value.ToString();
measurement.Measurement_Status = status;
DirectoryInfo di = new DirectoryInfo(dc.DocumentElement.Attributes["LOCATION"].Value.ToString());
var ruta = di.GetFiles(node.Attributes["COMP_NUMBER"].Value.ToString() + "-*");
if (ruta.Length > 0)
measurement.Measurement_ImagePath = di + "\\" + ruta[0].ToString();
measurements.Add(measurement);
group.Measurements = measurements;
groups.Add(group);
pcb.Groups = groups;
}
pcbas.Add(pcb);
}
}