public static DataTable RetrieveFilterData(string filterPath) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Category", typeof(string))); dt.Columns.Add(new DataColumn("Name", typeof(string))); dt.Columns.Add(new DataColumn("Value", typeof(string))); DataSet ds = new DataSet(); ds.ReadXml(filterPath); XmlDataDocument xmlDataDoc = new XmlDataDocument(ds); string strXPathQuery = "/root/filter"; string category = string.Empty; string itemName = string.Empty; string itemValue = string.Empty; DataRow dr = null; foreach (XmlNode nodeDetail in xmlDataDoc.SelectNodes(strXPathQuery)) { category = nodeDetail.ChildNodes[0].InnerText.ToString(); itemName = nodeDetail.ChildNodes[1].InnerText.ToString(); itemValue = nodeDetail.ChildNodes[2].InnerText.ToString(); dr = dt.NewRow(); dr["Category"] = category; dr["Name"] = itemName; dr["Value"] = itemValue; dt.Rows.Add(dr); } return dt; }
/// <summary> /// 加载sql文件 /// </summary> /// <returns>0 成功 -1 失败</returns> public int LoadSql() { #region 加载SQL switch (mode) { case 0: System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(); try { doc.Load(FileName); } catch (Exception ex) { this.Err = ex.Message; this.ErrCode = "-1"; this.WriteErr(); return(-1); } XmlNodeList nodes; nodes = doc.SelectNodes(@"//SQL"); try { foreach (XmlNode node in nodes) { Neusoft.FrameWork.Models.NeuObject objValue = new Neusoft.FrameWork.Models.NeuObject(); objValue.ID = node.Attributes[0].Value.ToString(); objValue.Name = node.InnerText.ToString(); objValue.Name = objValue.Name.Replace("\r", " "); //objValue.Name=objValue.Name.Replace("\n"," "); objValue.Name = objValue.Name.Replace("\t", " "); try { objValue.Memo = node.Attributes[1].Value.ToString(); } catch {} this.alSql.Add(objValue); } } catch (Exception ex) { this.Err = ex.Message; this.ErrCode = "-1"; this.WriteErr(); return(-1); } break; default: for (int i = 0; i < table_name.Count; i++) { Neusoft.FrameWork.Models.NeuObject obj = table_name[i] as Neusoft.FrameWork.Models.NeuObject; if (obj.ID == "1") //开始时候加载 { //因为要增加对不同数据库的支持,不同数据库里的SQL语句存储的字段不同, 所以才这样 //{476364C9-195A-4ca8-A2D7-6782088016FA} string mySQL = string.Empty; if (Neusoft.FrameWork.Management.Connection.DBType == Connection.EnumDBType.ORACLE) { mySQL = string.Format("select id,name,memo from {0}", table_name[i].ToString()); } else if (Neusoft.FrameWork.Management.Connection.DBType == Connection.EnumDBType.DB2) { mySQL = string.Format("select id,db2_sql,memo from {0}", table_name[i].ToString()); } else //以后再用 { mySQL = string.Format("select id,name,memo from {0}", table_name[i].ToString()); } //end ; if (this.ExecQuery(mySQL) == -1) { return(-1); //表有问题 } while (this.Reader.Read()) { Neusoft.FrameWork.Models.NeuObject objValue = new Neusoft.FrameWork.Models.NeuObject(); objValue.ID = this.Reader[0].ToString(); objValue.Name = this.Reader[1].ToString(); objValue.Name = objValue.Name.Replace("\r", " "); //objValue.Name=objValue.Name.Replace("\n"," "); objValue.Name = objValue.Name.Replace("\t", " "); try { objValue.Memo = this.Reader[2].ToString(); } catch { } this.alSql.Add(objValue); } this.Reader.Close(); } } break; } #endregion return(0); }
private void button5_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); //create a dataset DataSet ds = new DataSet("XMLProducts"); //connect to the northwind database and //select all of the rows from products table and from suppliers table //make sure you connect string matches you server configuration SqlConnection conn = new SqlConnection(_connectString); SqlDataAdapter daProduct = new SqlDataAdapter("SELECT Name, StandardCost, ProductCategoryID FROM SalesLT.Product", conn); SqlDataAdapter daCategory = new SqlDataAdapter("SELECT ProductCategoryID, Name from SalesLT.ProductCategory", conn); //Fill DataSet from both SqlAdapters daProduct.Fill(ds, "Products"); daCategory.Fill(ds, "Categories"); //Add the relation ds.Relations.Add(ds.Tables["Categories"].Columns["ProductCategoryID"], ds.Tables["Products"].Columns["ProductCategoryID"]); //Write the Xml to a file so we can look at it later ds.WriteXml("Products.xml", XmlWriteMode.WriteSchema); //load data into grid dataGridView1.DataSource = ds.Tables[0]; //create the XmlDataDocument doc = new XmlDataDocument(ds); //Select the productname elements and load them in the grid XmlNodeList nodeLst = doc.SelectNodes("//XMLProducts/Products"); textBox1.Text = ""; foreach (XmlNode node in nodeLst) { textBox1.Text += node.InnerXml + "\r\n"; } }
static void Main(string[] args) { if (!Directory.Exists(@".\Reports")) { Directory.CreateDirectory(@".\Reports"); } File.Copy(resultFileName, @".\Reports\TestResult.xml", true); double totalTestcases; double totalPassed; double totalFailed; double totalError; XmlDataDocument xmldoc = new XmlDataDocument(); XmlNodeList xmlResultsnode; errors = new List<ErrorItem>(); sucess = new List<SuccessItem>(); try { //Analize test results file FileStream fstream = new FileStream(resultFileName, FileMode.Open, FileAccess.Read); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(fstream); LoadTestResults(xmlDoc.DocumentElement); } finally { fstream.Close(); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error occur: "); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(ex.Message); Console.Beep(); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(""); Console.WriteLine("Press any key to continue..."); Console.ReadKey(true); return; } CreatePlayBack playback = new CreatePlayBack(Directory.GetCurrentDirectory() + @"\Reports\"); playback.CreateReports(); FileStream fs = new FileStream(resultFileName, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlResultsnode = xmldoc.SelectNodes("//test-results[contains(@ignored,'0')]"); totalTestcases = Convert.ToDouble(xmlResultsnode[0].Attributes["total"].Value); totalFailed = Convert.ToDouble(xmlResultsnode[0].Attributes["failures"].Value); totalError = Convert.ToDouble(xmlResultsnode[0].Attributes["errors"].Value); totalPassed = totalTestcases - totalFailed - totalError; totalFailed = totalFailed + totalError; StringBuilder sb = new StringBuilder(); sb.AppendLine("<Html>"); CreateHtmlHeader(sb); sb.AppendLine("<body background=\"./img/background.jpg\">"); CreateHeadline(sb); CreateSummary(sb, "TCD Automation", totalTestcases, totalPassed, totalFailed); CreateBody(sb, sucess); CreateChartScript(sb, totalFailed, totalPassed); EndHtml(sb); FileStream f = new FileStream(htmlPath, FileMode.Create, FileAccess.Write); using (StreamWriter s = new StreamWriter(f)) s.WriteLine(sb.ToString()); if (File.Exists(htmlPath)) { Console.WriteLine("Report Generated"); } }
private void import(string filename) { try { XmlDataDocument xml_doc = new XmlDataDocument (); xml_doc.Load (filename); var lessonNodes = xml_doc.SelectNodes ("//lesson"); foreach (XmlNode ln in lessonNodes) { int id = Convert.ToInt32 (getAttributeOrDefault (ln, "id", "-1")); string description = getAttributeOrDefault (ln, "description", "No description set"); var lesson = new LessonNode (id, description); var pairNodes = ln.SelectNodes ("pair"); foreach (XmlNode pn in pairNodes) { lesson.PairStore.AddNode (new PairNode (SelectTextNode (pn, "en"), SelectTextNode (pn, "de"))); } LessonStore.AddNode (lesson); } } catch (FileNotFoundException) { } }