/// <summary> /// The open tool strip button_ click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void openToolStripButton_Click(object sender, EventArgs e) { string fileName = string.Empty; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Setting Files (*.xml)|*.xml"; ofd.FileName = Application.StartupPath; DialogResult dr = ofd.ShowDialog(); if (dr == DialogResult.OK) { fileName = ofd.FileName; } else { return; } SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); try { doc.Load(fileName); XmlElement root = doc.DocumentElement; // adParamT_Epson2HeadV1 this.FromXML(root.ChildNodes[0].OuterXml); } catch (Exception ex) { Debug.Assert(false, ex.Message); } }
private void ImportMode_Click(object sender, EventArgs e) { System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.Filter = "Job Files (*.xml)|*.xml"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string fileName = openFileDialog.FileName; if (File.Exists(fileName)) { var doc = new SelfcheckXmlDocument(); doc.Load(fileName); JobModes importModes = (JobModes)PubFunc.SystemConvertFromXml(doc.InnerXml, typeof(JobModes)); for (int i = 0; i < importModes.Items.Count; i++) { foreach (JobMode item in m_LayerSettings.Items) { if (importModes.Items[i].Name.Trim().ToLower() == item.Name.Trim().ToLower()) { m_LayerSettings.Items.Remove(item); break; } } m_LayerSettings.Items.Add(importModes.Items[i]); } Bind(); } } }
private void LoadCameraBindXml() { string path = Path.Combine(Application.StartupPath, "camera_bind.xml"); if (File.Exists(path)) { SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); doc.Load(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); for (int j = 0; j < comboBoxLeftIp.Items.Count; j++) { if (ip.InnerText.Contains(comboBoxLeftIp.Items[j].ToString())) { comboBoxLeftIp.SelectedIndex = j; break; } } } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); for (int j = 0; j < comboBoxRightIp.Items.Count; j++) { if (ip.InnerText.Contains(comboBoxRightIp.Items[j].ToString())) { comboBoxRightIp.SelectedIndex = j; break; } } } } } }
private void SaveCameraBindXml() { string path = Path.Combine(Application.StartupPath, "camera_bind.xml"); SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); if (File.Exists(path)) { doc.Load(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxLeftIp.SelectedItem.ToString() + "\""; } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxRightIp.SelectedItem.ToString() + "\""; } } } else { XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "", ""); doc.AppendChild(declaration); XmlElement root = doc.CreateElement("opencv_storage"); XmlNode calibrationData = doc.CreateElement("calibrationData"); calibrationData.InnerText = DateTime.Now.ToLongDateString(); root.AppendChild(calibrationData); XmlNode camera = doc.CreateElement("Camera"); root.AppendChild(camera); XmlNode left = doc.CreateElement("_"); XmlNode leftName = doc.CreateElement("Name"); leftName.InnerText = "LeftCamera"; left.AppendChild(leftName); XmlNode leftIpAddress = doc.CreateElement("IPAddress"); leftIpAddress.InnerText = comboBoxLeftIp.SelectedItem.ToString(); left.AppendChild(leftIpAddress); camera.AppendChild(left); XmlNode right = doc.CreateElement("_"); XmlNode rightName = doc.CreateElement("Name"); rightName.InnerText = "RightCamera"; right.AppendChild(rightName); XmlNode rightIpAddress = doc.CreateElement("IPAddress"); rightIpAddress.InnerText = comboBoxRightIp.SelectedItem.ToString(); right.AppendChild(rightIpAddress); camera.AppendChild(right); doc.AppendChild(root); doc.Save(path); XmlNodeList nodes = doc.SelectNodes("//Camera/_"); for (int i = 0; i < nodes.Count; i++) { var selectSingleNode = nodes[i].SelectSingleNode("Name"); if (selectSingleNode != null && selectSingleNode.InnerText == "LeftCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxLeftIp.SelectedItem.ToString() + "\""; } if (selectSingleNode != null && selectSingleNode.InnerText == "RightCamera") { var ip = nodes[i].SelectSingleNode("IPAddress"); ip.InnerText = "\"" + comboBoxRightIp.SelectedItem.ToString() + "\""; } } } doc.Save(path); }
public bool LoadListFromXML() { string fileName = Application.StartupPath + Path.DirectorySeparatorChar + m_JobListFile; if (!File.Exists(fileName)) { if (Directory.Exists(sPreviewFolder)) { foreach (string d in Directory.GetDirectories(sPreviewFolder)) { modifyFile.DeleteFolder(d); } } return(false); } SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); try { if (!doc.Load(fileName)) { return(false); } XmlElement root = (XmlElement)doc.DocumentElement; m_PreviewList.Clear(); foreach (XmlNode xn in root.ChildNodes) { if (xn.Name == "PreviewForlder") { previewForlderStruct pfs = new previewForlderStruct(); pfs.JobForlderPath = xn.Attributes["JobForlderPath"].Value; pfs.PreviewForlderName = xn.Attributes["PreviewForlderName"].Value; if (!Directory.Exists(pfs.JobForlderPath)) { if (Directory.Exists(sPreviewFolder + pfs.PreviewForlderName)) { modifyFile.DeleteFolder(sPreviewFolder + pfs.PreviewForlderName); } } else { m_PreviewList.Add(pfs); } } } if (Directory.Exists(sPreviewFolder)) { foreach (string d in Directory.GetDirectories(sPreviewFolder)) { bool bDel = true; foreach (previewForlderStruct pfs in m_PreviewList) { string[] subpath = d.Split(Path.DirectorySeparatorChar); if (pfs.PreviewForlderName.ToLower() == subpath[subpath.Length - 1].ToLower()) { bDel = false; } } if (bDel == true) { modifyFile.DeleteFolder(d); } } } return(true); } catch (Exception e) { Debug.Assert(false, e.Message); return(false); } }
public void ReadXml(string filename) { if (!File.Exists(filename)) { return; } if (this.ReadStatusChanged != null) { this.ReadStatusChanged(this, strRead_start); } SelfcheckXmlDocument doc = new SelfcheckXmlDocument(); doc.Load(filename); XmlNode root = doc.FirstChild; foreach (XmlNode subnode in doc.ChildNodes) { if (subnode.Name.ToLower() == "headboardeepromdata") { root = subnode; } } AREAsFromXml.Clear(); AreaIndex = 0; foreach (XmlNode node in root.ChildNodes) { if (node.Name.ToLower() == "area") { AreaIndex++; AREA sub = new AREA(null); foreach (XmlAttribute attr in node.Attributes) { if (attr.Name.ToLower() == "name") { sub.Name = attr.Value; } else if (attr.Name.ToLower() == "type") { sub.type = Get_AREA_Type(attr.Value.ToLower()); } else if (attr.Name.ToLower() == "addr") { sub.ADDR = (short)GetValueByStr(attr.Value); } } int checkOder = 0; short AddrOffset = sub.ADDR; foreach (XmlNode item in node.ChildNodes) { if (item.Name.ToLower() != "item") { continue; } else { SubItemIndex++; } if (this.ReadStatusChanged != null) { this.ReadStatusChanged(this, string.Format(strRead_Commond, AreaIndex.ToString(), sub.type.ToString(), SubItemIndex.ToString())); } switch (sub.type) { case AREA_Type.none: sub.Items.Add(this.Get_CommondItem(item, checkOder)); //, ref AddrOffset)); break; case AREA_Type.map1: sub.Items.Add(this.Get_MAP_1_Item(item, checkOder)); //, ref AddrOffset)); break; case AREA_Type.map2: sub.Items.Add(this.Get_MAP_2_Item(item, checkOder)); //, ref AddrOffset)); break; case AREA_Type.map3: sub.Items.Add(this.Get_MAP_3_Item(item, checkOder)); //, ref AddrOffset)); break; case AREA_Type.map4: sub.Items.Add(this.Get_MAP_4_Item(item, checkOder)); //, ref AddrOffset)); break; default: { System.Diagnostics.Debug.Assert(false); break; } } checkOder++; } if (sub.type != AREA_Type.map3 && sub.type != AREA_Type.map4) { this.CalculatedAreaHeader(ref sub); } this.AREAsFromXml.Add(sub); } } if (this.ReadStatusChanged != null) { this.ReadStatusChanged(this, strRead_end); } }