public void AddLink(string title, string uri) { XmlDocument doc = new XmlDataDocument(); doc.Load("RssLinks.xml"); XmlNode rootNode = doc.SelectSingleNode("links"); XmlNode linkNode = doc.CreateElement("link"); XmlNode titleNode = doc.CreateElement("title"); XmlText titleText = doc.CreateTextNode(title); titleNode.AppendChild(titleText); XmlNode uriNode = doc.CreateElement("uri"); XmlText uriText = doc.CreateTextNode(uri); uriNode.AppendChild(uriText); XmlNode defaultshowNode = doc.CreateElement("defaultshow"); XmlText defaultshowText = doc.CreateTextNode("false"); defaultshowNode.AppendChild(defaultshowText); linkNode.AppendChild(titleNode); linkNode.AppendChild(uriNode); linkNode.AppendChild(defaultshowNode); rootNode.AppendChild(linkNode); doc.Save("RssLinks.xml"); }
public void FnLocationtoXml() { string Constring = System.Configuration.ConfigurationManager.ConnectionStrings["LoveJourney"].ConnectionString; SqlConnection con = new SqlConnection(Constring); try { con.Open(); SqlCommand cmd = new SqlCommand("Sp_IFReports", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@TableName", "DomAirportCodes"); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet DsLoc = new DataSet(); da.Fill(DsLoc); string DirectoryPath = Server.MapPath("~/App_Data"); DirectoryInfo dir = new DirectoryInfo(DirectoryPath); if (!dir.Exists) { dir.Create(); } string filepath = "~/App_Data/" + "Airports.xml"; string DirectoryPath1 = Server.MapPath(filepath); DirectoryInfo dir1 = new DirectoryInfo(DirectoryPath1); if (!dir1.Exists) { DataSet ds1 = new DataSet(); ds1.EnforceConstraints = false; XmlDataDocument XmlDoc = new XmlDataDocument(ds1); // Write down the XML declaration XmlDeclaration xmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element XmlElement rootNode = XmlDoc.CreateElement("Airports"); XmlDoc.InsertBefore(xmlDeclaration, XmlDoc.DocumentElement); XmlDoc.AppendChild(rootNode); XmlDoc.Save(Server.MapPath(filepath)); } StreamWriter XmlData = new StreamWriter(Server.MapPath("~/App_Data/" + "Airports.xml"), false); DsLoc.WriteXml(XmlData); XmlData.Close(); lblmsg.Visible = true; lblmsg.Text = " All flights list Uploaded to XML Successfully"; } finally { con.Close(); } }
/// <summary> /// Sets the application configuration setting. /// </summary> /// <param name="setting">Setting to be changed/added.</param> /// <param name="val">Value to change/add.</param> public static void SetValue(string setting, string val) { bool changed = false; System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly(); System.IO.FileInfo fi = new System.IO.FileInfo(asm.Location + ".config"); System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(); try { //Load the XML application configuration file doc.Load(fi.FullName); //Loops through the nodes to find the target node to change foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"]) { if (node.Name == "add") { //Set the key and value attributes if (node.Attributes.GetNamedItem("key").Value == setting) { node.Attributes.GetNamedItem("value").Value = val; //Flag the change as complete changed = true; } } } //If not changed yet then we assume it's a new key to be added if (!changed) { //create the new node and append it to the collection System.Xml.XmlNode node = doc["configuration"]["appSettings"]; System.Xml.XmlElement elem = doc.CreateElement("add"); System.Xml.XmlAttribute attrKey = doc.CreateAttribute("key"); System.Xml.XmlAttribute attrVal = doc.CreateAttribute("value"); elem.Attributes.SetNamedItem(attrKey).Value = setting; elem.Attributes.SetNamedItem(attrVal).Value = val; node.AppendChild(elem); } //Save the XML configuration file. doc.Save(fi.FullName); } catch { //There was an error loading or reading the config file...throw an error. throw new Exception("Unable to set the value. Check that the configuration file exists and contains the appSettings element."); } }
protected void Page_Load(object sender, EventArgs e) { XmlDocument xmldoc = new XmlDocument(); //读取用户参数 StreamReader streamreader = new StreamReader(this.Request.InputStream, Encoding.UTF8); try { xmldoc.LoadXml(streamreader.ReadToEnd()); } catch { }; string[] strParams = this.getStrParams(xmldoc); NameObjectList paramlist = BuildParamList.BuildParams(xmldoc); string unitName = BuildParamList.getValue(xmldoc, "UnitName"); if (unitName == "") return; string workItemName = BuildParamList.getValue(xmldoc, "WorkItem"); //得出workItemName对应的InitFilter=strParams[8]和PageSize=strParams[0] //for (int i = 0; i < unitItem.WorkItemList.Length; i++) // if (workItemName == unitItem.WorkItemList[i].ItemName) // { // workitem = unitItem.WorkItemList[i]; // strParams[8] = unitItem.WorkItemList[i].InitFilter; // if ("" != unitItem.WorkItemList[i].PageSize) // strParams[0] = unitItem.WorkItemList[i].PageSize; // break; // } QueryDataRes query = new QueryDataRes(paramlist["DataSrcFile"].ToString()); DataSet ds = new DataSet(unitName); ds.EnforceConstraints = false; string itemdata = paramlist["FilterData"].ToString(); string[] dataItemList = itemdata.Split(",".ToCharArray()); for (int i = 0; i < dataItemList.Length; i++) { if ("" == dataItemList[i]) continue; query.FillDataSet(dataItemList[i], paramlist, strParams, ds); } XmlDataDocument xmldocData = new XmlDataDocument(ds); this.Response.ContentType = "text/xml; charset=gb2312"; xmldocData.Save(this.Response.Output); }
/// <summary> /// Removes the application configuration setting. /// </summary> /// <param name="setting">Setting to be removed.</param> public static void RemoveSetting(string setting) { bool removed = false; System.Reflection.Assembly asm = System.Reflection.Assembly.GetEntryAssembly(); System.IO.FileInfo fi = new System.IO.FileInfo(asm.Location + ".config"); System.Xml.XmlDataDocument doc = new System.Xml.XmlDataDocument(); try { //Load the XML configuration file. doc.Load(fi.FullName); //Loop through the nodes to find the target node to be removed. foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"]) { if (node.Name == "add") { if (node.Attributes.GetNamedItem("key").Value == setting) { node.ParentNode.RemoveChild(node); removed = true; } } } //If not removed then the setting probably didn't exist...throw an error. if (!removed) { throw new Exception(); } //Save the results... doc.Save(fi.FullName); } catch { //There was an error loading or reading the config file...throw an error. throw new Exception("Unable to remove the value. Check that the configuration file exists and contains the appSettings element."); } }
static internal Dictionary<ulong, object> ReadDataID() { string filePath = Path.Combine(Path.GetDirectoryName(typeof(GXDLT645Property).Assembly.Location), "DLTProperties.xml"); XmlDataDocument myXmlDocument = new XmlDataDocument(); if (!File.Exists(filePath)) { myXmlDocument.LoadXml(Gurux.DLT645.AddIn.Properties.Resources.DLTProperties); try { using (XmlTextWriter writer = new XmlTextWriter(filePath, Encoding.Default)) { myXmlDocument.Save(writer); writer.Close(); } } catch (System.IO.IOException) { //This is probably due to insufficient file access rights. } } else { myXmlDocument.Load(filePath); } Dictionary<ulong, object> items = new Dictionary<ulong, object>(); foreach (XmlNode parentNode in myXmlDocument.DocumentElement.ChildNodes) { if (parentNode.Name == "Properties") { GetProperties(items, parentNode); } else if (parentNode.Name == "Tables") { foreach (XmlNode table in parentNode.ChildNodes) { GXDLT645TableTemplate item = new GXDLT645TableTemplate(table.Attributes["Name"].Value); items.Add(Convert.ToUInt64(table.Attributes["ID"].Value, 16), item); foreach (XmlNode prop in parentNode.ChildNodes) { GetColumns(item, prop); } } } } return items; }
private void save() { XmlDataDocument xml_doc = new XmlDataDocument (); XmlNode root = xml_doc.CreateElement ("vocab"); foreach (LessonNode l in LessonStore) { XmlNode lesson = xml_doc.CreateElement ("lesson"); XmlAttribute a_id = xml_doc.CreateAttribute ("id"); XmlAttribute a_description = xml_doc.CreateAttribute ("description"); a_id.Value = l.Id.ToString (); a_description.Value = l.Description; lesson.Attributes.Append (a_id); lesson.Attributes.Append (a_description); foreach (PairNode p in l.PairStore) { XmlNode pair = xml_doc.CreateElement ("pair"); XmlNode en = xml_doc.CreateElement ("en"); XmlNode de = xml_doc.CreateElement ("de"); en.InnerText = p.En; de.InnerText = p.De; pair.AppendChild (en); pair.AppendChild (de); lesson.AppendChild (pair); } root.AppendChild (lesson); } xml_doc.AppendChild (root); xml_doc.Save (xml_path); }
/// <summary> /// 查询数据 /// 如果未初始化页面的XmlLandData则补充 /// </summary> public void QueryData(string itemdata) { DataSet ds = new DataSet(unitItem.UnitName); ds.EnforceConstraints = false; string[] dataItemList = itemdata.Split(",".ToCharArray()); string[] strParams = this.getStrParams(this.xmlDocParam); int iStartRow = 0; if ("" != strParams[1]) try { iStartRow = Convert.ToInt16(strParams[1]); } catch { } for (int i = 0; i < dataItemList.Length; i++) { if ("" == dataItemList[i]) continue; query.FillDataSet(dataItemList[i], paramlist, strParams, ds); //增加行光标列 if (null != ds.Tables[dataItemList[i]] && !ds.Tables[dataItemList[i]].Columns.Contains("RowNum")) ds.Tables[dataItemList[i]].Columns.Add("RowNum", Type.GetType("System.Int32")); for (int j = 0; null != ds.Tables[dataItemList[i]] && j < ds.Tables[dataItemList[i]].Rows.Count; j++) ds.Tables[dataItemList[i]].Rows[j]["RowNum"] = iStartRow + j + 1; } //数字是0的,改为空值显示 for (int s = 0; s < ds.Tables.Count; s++) { DataTable tab = ds.Tables[s]; if (null == tab) continue; for (int i = 0; i < tab.Columns.Count; i++) { DataColumn col = tab.Columns[i]; if ("RowNum" == col.ColumnName) continue; if ("Decimal" != col.DataType.Name && "Double" != col.DataType.Name && "Int16" != col.DataType.Name && "Int32" != col.DataType.Name && "Int64" != col.DataType.Name && "Single" != col.DataType.Name && "UInt16" != col.DataType.Name && "UInt32" != col.DataType.Name && "UInt64" != col.DataType.Name) continue; DataRow[] drs = tab.Select(col.ColumnName + "=0"); for (int j = 0; j < drs.Length; j++) drs[j][i] = DBNull.Value; } } this.xmldocSchema.LoadXml(ds.GetXmlSchema()); XmlNamespaceManager xmlNsMgl = new XmlNamespaceManager(this.xmldocSchema.NameTable); XmlNode xmlRootEle = this.xmldocSchema.DocumentElement; for (int i = 0; i < xmlRootEle.Attributes.Count; i++) { string strPrefix = xmlRootEle.Attributes[i].Prefix; string strLocalName = xmlRootEle.Attributes[i].LocalName; string strURI = xmlRootEle.Attributes[i].Value; if ("xmlns" == strLocalName) xmlNsMgl.AddNamespace(string.Empty, strURI); if ("xmlns" != strPrefix) continue; xmlNsMgl.AddNamespace(strLocalName, strURI); } this._xmlNsMglSchema = xmlNsMgl; this.setSchema(ds); for (int i = 0; i < workitem.DictCol.Length; i++) { DictColumn dictcol = workitem.DictCol[i]; if (dictcol.DataSrc.Trim().Length > 0) { bool isContinue = false; for (int k = 0; k < i; k++) if (dictcol.DataSrc == workitem.DictCol[k].DataSrc) { isContinue = true; break; } if (isContinue) continue; try { string str = dictcol.DataSrc.Replace(" ", "_x0020_"); dictQuery.FillDataSet(str, paramlist, this._dictds); } catch { } } } XmlDataDocument xmldocData = new XmlDataDocument(ds); this.setFormatXmlLand(xmldocData, ds); this.Response.ContentType = "text/xml; charset=gb2312"; //如果结构未初始化,则建立数据包 //<XML id="MasterTab" itemname="建筑审批导航" typexml="Data"> //<XML id="MasterTab_Sum" typexml="Count" itemname="建筑审批导航"> string strXPath = "//P[@n='tpid' and @v='" + this.workitem.TempId + "']"; XmlNode xmlNodeif = this.xmlDocParam.SelectSingleNode(strXPath); if (xmlNodeif != null) xmldocData = buildXmlDoc(xmldocData); xmldocData.Save(this.Response.Output); }
public void Test2() { DataSet RegionDS = new DataSet(); DataRow RegionRow; RegionDS.ReadXmlSchema(new StringReader(RegionXsd)); Assert.Equal(1, RegionDS.Tables.Count); XmlDataDocument DataDoc = new XmlDataDocument(RegionDS); DataDoc.Load(new StringReader(RegionXml)); RegionRow = RegionDS.Tables[0].Rows[0]; RegionDS.AcceptChanges(); RegionRow["RegionDescription"] = "Reeeeeaalllly Far East!"; RegionDS.AcceptChanges(); TextWriter text = new StringWriter(); text.NewLine = "\n"; DataDoc.Save(text); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); //Assert.Equal ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal("<Root>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>1</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" <RegionDescription>Reeeeeaalllly Far East!</RegionDescription>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>2</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Western") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>3</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Northern") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>4</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Southern") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column1>12</Column1>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column2>Hi There</Column2>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column1>12</Column1>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column2>Hi There</Column2>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </MoreData>") != -1); }
public void CreateElement1() { XmlDataDocument doc = new XmlDataDocument(); doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd)); doc.Load(new StringReader(RegionXml)); XmlElement Element = doc.CreateElement("prefix", "localname", "namespaceURI"); Assert.Equal("prefix", Element.Prefix); Assert.Equal("localname", Element.LocalName); Assert.Equal("namespaceURI", Element.NamespaceURI); doc.ImportNode(Element, false); TextWriter text = new StringWriter(); doc.Save(text); string substring = string.Empty; string TextString = text.ToString(); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.True(substring.IndexOf("<Root>") != -1); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); Assert.True(substring.IndexOf(" <RegionID>1</RegionID>") != -1); for (int i = 0; i < 26; i++) { substring = TextString.Substring(0, TextString.IndexOf("\n")); TextString = TextString.Substring(TextString.IndexOf("\n") + 1); } substring = TextString.Substring(0, TextString.Length); Assert.True(substring.IndexOf("</Root>") != -1); }
public void Rows_With_Null_Values () { DataSet ds = new DataSet (); DataTable table = ds.Tables.Add ("table1"); table.Columns.Add ("col1", typeof (int)); table.Columns.Add ("col2", typeof (int)); XmlDataDocument doc = new XmlDataDocument (ds); table.Rows.Add (new object[] {1}); StringWriter sw = new StringWriter (); doc.Save (sw); DataSet ds1 = ds.Clone (); XmlDataDocument doc1 = new XmlDataDocument (ds1); StringReader sr = new StringReader (sw.ToString()); doc1.Load (sr); AssertEquals ("#1", 1, ds1.Tables [0].Rows [0][0]); AssertEquals ("#2", true, ds1.Tables [0].Rows [0].IsNull (1)); }
/// <summary> /// 查询数据 /// 如果未初始化页面的XmlLandData则补充 /// </summary> public void QueryData(string itemdata) { DataSet ds = new DataSet(this.paramlist["UnitName"].ToString()); ds.EnforceConstraints = false; string[] dataItemList = itemdata.Split(",".ToCharArray()); string[] strParams = this.getStrParams(this.xmlDocParam); int iStartRow = 0; if ("" != strParams[1]) try { iStartRow = Convert.ToInt16(strParams[1]); } catch { } for (int i = 0; i < dataItemList.Length; i++) { if ("" == dataItemList[i]) continue; query.FillDataSet(dataItemList[i], paramlist, strParams, ds); //增加行光标列 if (null != ds.Tables[dataItemList[i]] && !ds.Tables[dataItemList[i]].Columns.Contains("RowNum")) ds.Tables[dataItemList[i]].Columns.Add("RowNum", Type.GetType("System.Int32")); for (int j = 0; null != ds.Tables[dataItemList[i]] && j < ds.Tables[dataItemList[i]].Rows.Count; j++) ds.Tables[dataItemList[i]].Rows[j]["RowNum"] = iStartRow + j + 1; } //数字是0的,改为空值显示 for (int s = 0; s < ds.Tables.Count; s++) { DataTable tab = ds.Tables[s]; if (null == tab) continue; for (int i = 0; i < tab.Columns.Count; i++) { DataColumn col = tab.Columns[i]; if ("RowNum" == col.ColumnName) continue; if ("Decimal" != col.DataType.Name && "Double" != col.DataType.Name && "Int16" != col.DataType.Name && "Int32" != col.DataType.Name && "Int64" != col.DataType.Name && "Single" != col.DataType.Name && "UInt16" != col.DataType.Name && "UInt32" != col.DataType.Name && "UInt64" != col.DataType.Name) continue; DataRow[] drs = tab.Select(col.ColumnName + "=0"); for (int j = 0; j < drs.Length; j++) drs[j][i] = DBNull.Value; } } //NameObjectList lst = leofun.NameValueTag(this.paramlist["DictCol"].ToString()); //for (int i = 0; i < lst.Count; i++) //{ // try // { // string strdict = lst.AllStringValues[i].Split('+')[0]; // dictQuery.FillDataSet(strdict, paramlist, this._dictds); //this._dictds // } // catch { } //} XmlDataDocument xmldocData = new XmlDataDocument(ds); this.setFormatXmlLand(xmldocData, ds); this.Response.ContentType = "text/xml; charset=gb2312"; xmldocData.Save(this.Response.Output); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { bool close = false; this.TopMost = false; if (global.Enabled) { DisableWorkingUnit(); } /* if (e.CloseReason != CloseReason.WindowsShutDown) { DialogResult result = MessageBox.Show("Do you want to exit?", "AmbiLED", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { close = true; } } else { close = true; } */ close = true; if (close) { XmlDocument settings = new XmlDataDocument(); settings.Load(Application.StartupPath + "\\AmbiLED.xml"); XmlElement root = settings.DocumentElement; for (int I = 0; I < root.ChildNodes.Count; I++) { if (root.ChildNodes[I].Name == "comport") { root.ChildNodes[I].InnerText = txtPortname.Text; } else if (root.ChildNodes[I].Name == "baudrate") { root.ChildNodes[I].InnerText = serialPort1.BaudRate.ToString(); } else if (root.ChildNodes[I].Name == "color") { root.ChildNodes[I].InnerText = global.var_ColorSlider.ToString(); } else if (root.ChildNodes[I].Name == "expand") { if (radioButton1.Checked) root.ChildNodes[I].InnerText = "1"; else if (radioButton2.Checked) root.ChildNodes[I].InnerText = "2"; else root.ChildNodes[I].InnerText = "3"; } else if (root.ChildNodes[I].Name == "maxmultiply") { root.ChildNodes[I].InnerText = global.var_MaxMultiply.ToString(); } else if (root.ChildNodes[I].Name == "ProgressiveThreshold") { if (ProgressiveThreshold.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "DynamicSmoothRadius") { if (DynamicSmoothRadius.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "QuantizeLevel") { root.ChildNodes[I].InnerText = QuantizeLevel.Value.ToString(); } else if (root.ChildNodes[I].Name == "DarknessThreshold") { root.ChildNodes[I].InnerText = DarknessThreshold.Value.ToString(); } else if (root.ChildNodes[I].Name == "enabled") { if (global.Enabled == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "minimized") { if (this.WindowState == FormWindowState.Minimized) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "mode") { if (global.Mode == 0) { root.ChildNodes[I].InnerText = "movie"; } else if (global.Mode == 1) { root.ChildNodes[I].InnerText = "gaming"; } else if (global.Mode == 2) { root.ChildNodes[I].InnerText = "10*movie smooth"; } else if (global.Mode == 3) { root.ChildNodes[I].InnerText = "True-Cinema +Expansion"; } else if (global.Mode == 4) { root.ChildNodes[I].InnerText = "(temp1)"; } else if (global.Mode == 5) { root.ChildNodes[I].InnerText = "(temp2)"; } else if (global.Mode == 6) { root.ChildNodes[I].InnerText = "(temp3)"; } } else if (root.ChildNodes[I].Name == "DynamicControl") { if (global.in_DynamicControl == 0) { root.ChildNodes[I].InnerText = "(HSL)HSB.Brightness"; } else if (global.in_DynamicControl == 1) { root.ChildNodes[I].InnerText = "HSV.Value"; } else if (global.in_DynamicControl == 2) { root.ChildNodes[I].InnerText = "Scene Difference"; } } else if (root.ChildNodes[I].Name == "controller") { if (global.Controller == 0) { root.ChildNodes[I].InnerText = "v1 v2"; } else if (global.Controller == 1) { root.ChildNodes[I].InnerText = "v3"; } } else if (root.ChildNodes[I].Name == "GammaEvent") { root.ChildNodes[I].InnerText = global.var_GammaEvent.ToString(); } else if (root.ChildNodes[I].Name == "AggressiveThreshold") { root.ChildNodes[I].InnerText = global.var_AggressiveThreshold.ToString(); } else if (root.ChildNodes[I].Name == "MaxSmoothRadius") { root.ChildNodes[I].InnerText = global.var_MaxSmoothRadius.ToString(); } else if (root.ChildNodes[I].Name == "MinSmoothRadius") { root.ChildNodes[I].InnerText = global.var_MinSmoothRadius.ToString(); } else if (root.ChildNodes[I].Name == "SlideDelay") { root.ChildNodes[I].InnerText = global.var_SlideDelay.ToString(); } else if (root.ChildNodes[I].Name == "DarknessLimit") { root.ChildNodes[I].InnerText = global.var_DarknessLimit.ToString(); } else if (root.ChildNodes[I].Name == "DarknessLimitMethod") { if (global.in_DarknessLimitMethod == 0) { root.ChildNodes[I].InnerText = "HSB"; } else if (global.in_DarknessLimitMethod == 1) { root.ChildNodes[I].InnerText = "HSV"; } } else if (root.ChildNodes[I].Name == "RedLeft") root.ChildNodes[I].InnerText = RedLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTop") root.ChildNodes[I].InnerText = RedTop.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRight") root.ChildNodes[I].InnerText = RedRight.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeft") root.ChildNodes[I].InnerText = GreenLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTop") root.ChildNodes[I].InnerText = GreenTop.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRight") root.ChildNodes[I].InnerText = GreenRight.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeft") root.ChildNodes[I].InnerText = BlueLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTop") root.ChildNodes[I].InnerText = BlueTop.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRight") root.ChildNodes[I].InnerText = BlueRight.Value.ToString(); else if (root.ChildNodes[I].Name == "RedLeftOnStart") root.ChildNodes[I].InnerText = RedLeftOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTopOnStart") root.ChildNodes[I].InnerText = RedTopOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRightOnStart") root.ChildNodes[I].InnerText = RedRightOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeftOnStart") root.ChildNodes[I].InnerText = GreenLeftOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTopOnStart") root.ChildNodes[I].InnerText = GreenTopOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRightOnStart") root.ChildNodes[I].InnerText = GreenRightOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeftOnStart") root.ChildNodes[I].InnerText = BlueLeftOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTopOnStart") root.ChildNodes[I].InnerText = BlueTopOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRightOnStart") root.ChildNodes[I].InnerText = BlueRightOnStart.Value.ToString(); else if (root.ChildNodes[I].Name == "RedLeftOnExit") root.ChildNodes[I].InnerText = RedLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTopOnExit") root.ChildNodes[I].InnerText = RedTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRightOnExit") root.ChildNodes[I].InnerText = RedRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeftOnExit") root.ChildNodes[I].InnerText = GreenLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTopOnExit") root.ChildNodes[I].InnerText = GreenTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRightOnExit") root.ChildNodes[I].InnerText = GreenRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeftOnExit") root.ChildNodes[I].InnerText = BlueLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTopOnExit") root.ChildNodes[I].InnerText = BlueTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRightOnExit") root.ChildNodes[I].InnerText = BlueRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GammaLevel") root.ChildNodes[I].InnerText = global.var_GammaValueInt.ToString(); else if (root.ChildNodes[I].Name == "Interval") root.ChildNodes[I].InnerText = global.var_Interval.ToString(); else if (root.ChildNodes[I].Name == "AutoEnable") { if (AutoEnable.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "showoutput") { if (ShowOutput.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "ProcessName") { root.ChildNodes[I].InnerText = ProcessName.Text; } } settings.Save(Application.StartupPath + "\\AmbiLED.xml"); if (serialPort1.IsOpen == false) OpenSerial(); SendOnExit(); serialPort1.Close(); serialPort1.Dispose(); } else { e.Cancel = true; this.TopMost = true; } }
protected void btn_Click(object sender, EventArgs e) { try { DataSet DsSub = new DataSet(); string JourneyDate = txtDate.Text.ToString(); BitlaAPI objbitla = new BitlaAPI(); IBitlaAPILayer objBitlaAPILayer = null; objBitlaAPILayer = new BitlaAPILayer(); objBitlaAPILayer.URL = BitlaConstants.URL; objBitlaAPILayer.ApiKey = BitlaConstants.API_KEY; objBitlaAPILayer.Date = JourneyDate; DataSet dsBitlaAllAvailableRoutes = null; dsBitlaAllAvailableRoutes = objbitla.GetAllAvailableRoutes(objBitlaAPILayer.URL,objBitlaAPILayer.ApiKey, objBitlaAPILayer.Date); dsBitlaAllAvailableRoutes.WriteXml(Server.MapPath("~/Routes/" + JourneyDate + ".xml")); lblMsg.Text = " Submitted. "; XmlDataDocument XmlDocRef = new XmlDataDocument(); // StreamWriter XmlDataRef = new StreamWriter(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml"), false); XmlDocRef.Load(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml")); foreach (DataRow row in dsBitlaAllAvailableRoutes.Tables[1].Rows) { string DirectoryPath = Server.MapPath("~/App_Data/XMLfiles"); DirectoryInfo dir = new DirectoryInfo(DirectoryPath); if (!dir.Exists) { dir.Create(); } string filepath = "~/App_Data/XMLfiles/" + "RefCallback.xml"; string DirectoryPath1 = Server.MapPath(filepath); DirectoryInfo dir1 = new DirectoryInfo(DirectoryPath1); if (dir1.Exists == true) { DataSet ds1 = new DataSet(); DataTable dt = new DataTable("Refcal"); dt.Columns.Add("Date"); dt.Columns.Add("id"); dt.Columns.Add("travel_id"); dt.Columns.Add("reservation_id"); DataRow dr1; dr1 = dt.NewRow(); dr1["Date"] = JourneyDate; dr1["id"] = row["reservation_id"]; dr1["travel_id"] = row["travel_id"]; dr1["reservation_id"] = row["reservation_id"]; dt.Rows.Add(dr1); ds1.Tables.Add(dt); ds1.EnforceConstraints = false; XmlDataDocument XmlDoc = new XmlDataDocument(ds1); // Write down the XML declaration // XmlDeclaration xmlDeclaration = XmlDoc.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element //XmlElement rootNode = XmlDoc.CreateElement("CallBack"); //XmlDoc.InsertBefore(xmlDeclaration, XmlDoc.DocumentElement); // XmlDoc.AppendChild(rootNode); XmlDoc.Save(Server.MapPath(filepath)); } else { //create node and add value XmlNode node = XmlDocRef.CreateNode(XmlNodeType.Element, "Refcal", null); node.InnerXml = "<Date>" + JourneyDate + "</Date><id>" + row["id"] + "</id><travel_id>" + row["travel_id"] + "</travel_id><reservation_id>" + row["reservation_id"] + "</reservation_id>"; //add to elements collection XmlDocRef.DocumentElement.AppendChild(node); //DsSub.ReadXml(Server.MapPath("~/App_Data/XMLfiles/" + "RefCallback.xml")); //DataRow dr; //dr = DsSub.Tables[0].NewRow(); //dr["Date"] = JourneyDate; //dr["id"] = row["id"]; //dr["travel_id"] = row["travel_id"]; //dr["reservation_id"] = row["reservation_id"]; //DsSub.Tables[0].Rows.Add(dr); } } XmlDocRef.Save(Path.Combine(HttpRuntime.AppDomainAppPath, "App_Data\\XMLfiles\\" + "RefCallback.xml")); //DataSet ds2 = new DataSet(); //ds2.EnforceConstraints = false; //XmlDataDocument XmlDoc1 = new XmlDataDocument(ds2); //StreamWriter XmlData1 = new StreamWriter(Server.MapPath("~/App_Data/XMLfiles/" + "RefCallback.xml"), false); //DsSub.WriteXml(XmlData1); //XmlData1.Close(); } catch (Exception) { // throw; } }
/// <summary> /// Sets the application configuration setting. /// </summary> /// <param name="setting">Setting to be changed/added.</param> /// <param name="val">Value to change/add.</param> public static void SetValue(string setting, string val) { bool changed=false; System.Reflection.Assembly asm=System.Reflection.Assembly.GetEntryAssembly(); System.IO.FileInfo fi=new System.IO.FileInfo(asm.Location+".config"); System.Xml.XmlDataDocument doc= new System.Xml.XmlDataDocument(); try { //Load the XML application configuration file doc.Load(fi.FullName); //Loops through the nodes to find the target node to change foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"]) { if (node.Name=="add") { //Set the key and value attributes if (node.Attributes.GetNamedItem("key").Value==setting) { node.Attributes.GetNamedItem("value").Value=val; //Flag the change as complete changed=true; } } } //If not changed yet then we assume it's a new key to be added if (!changed) { //create the new node and append it to the collection System.Xml.XmlNode node=doc["configuration"]["appSettings"]; System.Xml.XmlElement elem=doc.CreateElement("add"); System.Xml.XmlAttribute attrKey=doc.CreateAttribute("key"); System.Xml.XmlAttribute attrVal=doc.CreateAttribute("value"); elem.Attributes.SetNamedItem(attrKey).Value=setting; elem.Attributes.SetNamedItem(attrVal).Value=val; node.AppendChild(elem); } //Save the XML configuration file. doc.Save(fi.FullName); } catch { //There was an error loading or reading the config file...throw an error. throw new Exception("Unable to set the value. Check that the configuration file exists and contains the appSettings element."); } }
/// <summary> /// Removes the application configuration setting. /// </summary> /// <param name="setting">Setting to be removed.</param> public static void RemoveSetting(string setting) { bool removed=false; System.Reflection.Assembly asm=System.Reflection.Assembly.GetEntryAssembly(); System.IO.FileInfo fi=new System.IO.FileInfo(asm.Location+".config"); System.Xml.XmlDataDocument doc= new System.Xml.XmlDataDocument(); try { //Load the XML configuration file. doc.Load(fi.FullName); //Loop through the nodes to find the target node to be removed. foreach (System.Xml.XmlNode node in doc["configuration"]["appSettings"]) { if (node.Name=="add") { if (node.Attributes.GetNamedItem("key").Value==setting) { node.ParentNode.RemoveChild(node); removed=true; } } } //If not removed then the setting probably didn't exist...throw an error. if (!removed) throw new Exception(); //Save the results... doc.Save(fi.FullName); } catch { //There was an error loading or reading the config file...throw an error. throw new Exception("Unable to remove the value. Check that the configuration file exists and contains the appSettings element."); } }
protected void Page_Load(object sender, System.EventArgs e) { if (Session["userid"] == null) { this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('您未正常登录,请登录后再使用,谢谢!')"); this.Response.Write("</script>"); this.Response.Redirect("index.htm"); } SqlConnection CN = new SqlConnection(); string strsql = ""; string exectype = ""; //try //{ //初始化连接字符串 string strCn = DataAccRes.DefaultDataConnInfo.Value; CN.ConnectionString=strCn; CN.Open(); XmlDocument xmldoc = new XmlDocument(); //读取用户参数 StreamReader streamreader = new StreamReader(this.Request.InputStream, Encoding.UTF8); string strxml = streamreader.ReadToEnd(); if (string.IsNullOrEmpty(strxml)) return; xmldoc.LoadXml(strxml); if(xmldoc==null) return; XmlNodeList cmnodes = xmldoc.SelectNodes("//all/command"); XmlNodeList sqlnodes = xmldoc.SelectNodes("//all/sql"); XmlNodeList prnnodes = xmldoc.SelectNodes("//all/print"); XmlNodeList prnnames = xmldoc.SelectNodes("//all/printname"); if (cmnodes == null || sqlnodes == null) return; strsql = sqlnodes[0].InnerText; string prncmd = ""; string prnname = ""; if (prnnodes != null && prnnodes.Count>0) prncmd = prnnodes[0].InnerText; if (prnnames != null && prnnames.Count > 0) prnname = prnnames[0].InnerText; exectype = cmnodes[0].InnerText; string item = ""; if (exectype == "undefined") exectype = ""; if (exectype.IndexOf("item.") > -1) { item = exectype.Replace("item.", ""); if (Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.UnitHash.Contains(item)) { Response.Clear(); Response.ContentType = "text/xml; charset=gb2312"; Response.Expires = -1; XmlDataDocument outdoc = new XmlDataDocument(); outdoc.LoadXml(Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.UnitHash[item].ToString()); outdoc.Save(Response.OutputStream); //Response.End(); return; } } if (exectype == "cache") { Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.IsCache = true; Estar.Common.Tools.UnitItem.IsCache = true; string xmlstr = "<table>ok</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "nocache") { Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.IsCache = false; Estar.Common.Tools.UnitItem.IsCache = false; string xmlstr = "<table>ok</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "htmlfiles") { string[] files = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("html")); string strs = ""; for (int i = 0; i < files.Length; i++) { string s1 = files[i].ToLower(); FileInfo fileinfo = new FileInfo(s1); strs = strs + "," + fileinfo.Name; } strs = strs.Substring(1, strs.Length - 1); string xmlstr = "<table>"+strs+"</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "prnfiles") { string[] files = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("DataSource\\ExcelTemplate")); string strs = ""; for (int i = 0; i < files.Length; i++) { string s1 = files[i].ToLower(); FileInfo fileinfo = new FileInfo(s1); strs = strs + "," + fileinfo.Name; } strs = strs.Substring(1, strs.Length - 1); string xmlstr = "<table>" + strs + "</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "iconfiles") { string[] files = Directory.GetFiles(System.Web.HttpContext.Current.Request.MapPath("html\\Images")); string strs = ""; for (int i = 0; i < files.Length; i++) { string s1 = files[i].ToLower(); FileInfo fileinfo = new FileInfo(s1); strs = strs + "," + fileinfo.Name; } strs = strs.Substring(1, strs.Length - 1); string xmlstr = "<table>" + strs + "</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "1") { strsql = strsql.Replace("\r\n", " "); SqlCommand command = new SqlCommand(strsql, CN); command.ExecuteNonQuery(); if (CN.State == ConnectionState.Open) CN.Close(); string xmlstr = "<table>ok</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } if (exectype == "xml") { strsql = sqlnodes[0].InnerXml; SqlCommand command = new SqlCommand(strsql, CN); command.ExecuteNonQuery(); if (CN.State == ConnectionState.Open) CN.Close(); string xmlstr = "<table>ok</table>"; Response.ContentType = "text/xml"; Response.Expires = -1; Response.Clear(); Response.Write("<?xml version='1.0' encoding='GB2312'?>"); Response.Write(xmlstr); //Response.End(); return; } DataSet ds = new DataSet(); SqlDataAdapter adp; if (strsql.ToLower().IndexOf("select ") < 0 && strsql.ToLower().IndexOf("exec ") < 0 && strsql.ToLower().IndexOf("execute ") < 0) { //按数据源方式 QueryDataRes query = new QueryDataRes(); NameObjectList paramlist = null; query.FillDataSet(strsql, paramlist, ds); if(ds.Tables!=null && ds.Tables.Count>0) ds.Tables[0].TableName = "table"; } else { adp = new SqlDataAdapter(strsql, CN); adp.Fill(ds,"table"); } if (prncmd == "prn") { string SourceFile = prnname; string TemplatePath = this.Server.MapPath(DataAccRes.AppSettings("TpFilePath")); //存放源文件的文件夹路径。 string SrcFile = TemplatePath + "\\" + SourceFile; //源文件名称 string DestFile = "print.XLS"; if (!File.Exists(SrcFile) == true) { if (!File.Exists(SrcFile) == true) { string strMSG = "打印模板 [" + SourceFile + "] 不存在,请联系系统管理员建立打印模板!"; this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('" + strMSG + "')"); this.Response.Write("</script>"); return; } } DataTable tab = ds.Tables[0]; XmlDocument xmlPrintDoc = csPrintData.makeprint(null, null, SourceFile, DestFile, tab, tab, 0, this.Session["userid"].ToString(), null); //csPrintData.outXML2ExcelDown(xmlPrintDoc, SourceFile,null); //csPrintData.outXML2Excel(xmlPrintDoc, SourceFile); //System.Web.HttpContext.Current.Response.Write("<script language='javascript'>window.open('" + xmlPrintDoc + "')</script>"); return; } string colnames = ""; string datatypes = ""; string datalens = ""; for (int i = 0; i < ds.Tables[0].Columns.Count; i++) { colnames = colnames + "," + ds.Tables[0].Columns[i].ColumnName; datatypes = datatypes + "," + ds.Tables[0].Columns[i].DataType.ToString(); datalens = datalens + "," + ds.Tables[0].Columns[i].MaxLength.ToString(); } string tablename = ds.Tables[0].TableName; colnames = colnames.Substring(1, colnames.Length - 1); datatypes = datatypes.Substring(1, datatypes.Length - 1); datalens = datalens.Substring(1, datalens.Length - 1); DataTable tbl = ds.Tables.Add("xstructs"); DataColumn col0 = tbl.Columns.Add("name"); DataColumn col1 = tbl.Columns.Add("datatype"); DataColumn col2 = tbl.Columns.Add("len"); DataRow row = ds.Tables["xstructs"].NewRow(); row["name"] = colnames; row["datatype"] = datatypes.Replace("System.", ""); row["len"] = datalens; ds.Tables["xstructs"].Rows.Add(row); Response.Clear(); Response.ContentType = "text/xml; charset=gb2312"; Response.Expires = -1; XmlDataDocument outdoc1 = new XmlDataDocument(ds); outdoc1.Save(Response.OutputStream); if (item != "" && Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.IsCache == true) { Estar.DataAccess.SqlClientDataAccess.SqlQueryDAO.UnitHash.Add(item, outdoc1.InnerXml); } //Response.Write("<?xml version='1.0' encoding='GB2312'?>"); //Response.Write(ds.GetXml().ToString()); //Response.End(); if (CN.State == ConnectionState.Open) CN.Close(); //} //catch (Exception ex) //{ // if (CN.State == ConnectionState.Open) CN.Close(); // this.Response.Write(""); // NameValueCollection errInfo = new NameValueCollection(); // errInfo["数据源"] = strsql; // errInfo["操作类型"] = exectype; // ExceptionManager.Publish(ex, errInfo); //} //finally //{ }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { bool close = false; this.TopMost = false; if (e.CloseReason != CloseReason.WindowsShutDown) { DialogResult result = MessageBox.Show("Do you want to exit?", "BobLight", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { close = true; } } else { close = true; } if (close) { XmlDocument settings = new XmlDataDocument(); settings.Load(Application.StartupPath + "\\settings.xml"); XmlElement root = settings.DocumentElement; for (int I = 0; I < root.ChildNodes.Count; I++) { if (root.ChildNodes[I].Name == "comport") { root.ChildNodes[I].InnerText = serialPort1.PortName; } else if (root.ChildNodes[I].Name == "baudrate") { root.ChildNodes[I].InnerText = serialPort1.BaudRate.ToString(); } else if (root.ChildNodes[I].Name == "color") { root.ChildNodes[I].InnerText = Colorslider.Value.ToString(); } else if (root.ChildNodes[I].Name == "enabled") { if (CaptureTimer.Enabled == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "minimized") { if (this.WindowState == FormWindowState.Minimized) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "mode") { if (GlobalVariables.mode == 0) { root.ChildNodes[I].InnerText = "movie"; } else if (GlobalVariables.mode == 1) { root.ChildNodes[I].InnerText = "gaming"; } } else if (root.ChildNodes[I].Name == "expand") { if (radioButton1.Checked) root.ChildNodes[I].InnerText = "1"; else if (radioButton2.Checked) root.ChildNodes[I].InnerText = "2"; else root.ChildNodes[I].InnerText = "3"; } else if (root.ChildNodes[I].Name == "maxmultiply") { root.ChildNodes[I].InnerText = numericUpDown1.Value.ToString(); } else if (root.ChildNodes[I].Name == "RedLeft") root.ChildNodes[I].InnerText = RedLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTop") root.ChildNodes[I].InnerText = RedTop.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRight") root.ChildNodes[I].InnerText = RedRight.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeft") root.ChildNodes[I].InnerText = GreenLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTop") root.ChildNodes[I].InnerText = GreenTop.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRight") root.ChildNodes[I].InnerText = GreenRight.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeft") root.ChildNodes[I].InnerText = BlueLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTop") root.ChildNodes[I].InnerText = BlueTop.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRight") root.ChildNodes[I].InnerText = BlueRight.Value.ToString(); else if (root.ChildNodes[I].Name == "LeftScanBegin") root.ChildNodes[I].InnerText = LeftBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "LeftScanEnd") root.ChildNodes[I].InnerText = LeftEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanBegin") root.ChildNodes[I].InnerText = TopBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanEnd") root.ChildNodes[I].InnerText = TopEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanBegin") root.ChildNodes[I].InnerText = RightBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanEnd") root.ChildNodes[I].InnerText = RightEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "Interval") root.ChildNodes[I].InnerText = CaptureTimer.Interval.ToString(); } settings.Save(Application.StartupPath + "\\settings.xml"); Array.Clear(GlobalVariables.SendByte, 0, 9); if (serialPort1.IsOpen) { serialPort1.Write(GlobalVariables.SendByte, 0, 9); //send 9 zero chars to turn off the lights while (serialPort1.BytesToWrite != 0)//wait for the serial port to finish sending { } serialPort1.Close();//close the serial port } serialPort1.Dispose(); } else { e.Cancel = true; this.TopMost = true; } }
// bug #54505 public void TypedDataDocument () { string xml = @"<top xmlns=""urn:test""> <foo> <s>first</s> <d>2004-02-14T10:37:03</d> </foo> <foo> <s>second</s> <d>2004-02-17T12:41:49</d> </foo> </top>"; string xmlschema = @"<xs:schema id=""webstore"" targetNamespace=""urn:test"" xmlns:xs=""http://www.w3.org/2001/XMLSchema""> <xs:element name=""top""> <xs:complexType> <xs:sequence maxOccurs=""unbounded""> <xs:element name=""foo""> <xs:complexType> <xs:sequence maxOccurs=""unbounded""> <xs:element name=""s"" type=""xs:string""/> <xs:element name=""d"" type=""xs:dateTime""/> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>"; XmlDataDocument doc = new XmlDataDocument (); doc.DataSet.ReadXmlSchema (new StringReader (xmlschema)); doc.LoadXml (xml); DataTable foo = doc.DataSet.Tables ["foo"]; DataRow newRow = foo.NewRow (); newRow ["s"] = "new"; newRow ["d"] = DateTime.Now; foo.Rows.Add (newRow); doc.Save (new StringWriter ()); }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { bool close = false; this.TopMost = false; /* if (e.CloseReason != CloseReason.WindowsShutDown) { DialogResult result = MessageBox.Show("Do you want to exit?", "epiLight", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { close = true; } } else { close = true; } */ close = true; if (close) { XmlDocument settings = new XmlDataDocument(); settings.Load(Application.StartupPath + "\\settings.xml"); XmlElement root = settings.DocumentElement; for (int I = 0; I < root.ChildNodes.Count; I++) { if (root.ChildNodes[I].Name == "comport") { root.ChildNodes[I].InnerText = txtPortname.Text; } else if (root.ChildNodes[I].Name == "baudrate") { root.ChildNodes[I].InnerText = serialPort1.BaudRate.ToString(); } else if (root.ChildNodes[I].Name == "CaptureEvery") { if (CaptureEvery.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "CaptureCycles") { root.ChildNodes[I].InnerText = CaptureCycles.Value.ToString(); } else if (root.ChildNodes[I].Name == "color") { root.ChildNodes[I].InnerText = Colorslider.Value.ToString(); } else if (root.ChildNodes[I].Name == "enabled") { if (CaptureTimer.Enabled == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "minimized") { if (this.WindowState == FormWindowState.Minimized) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "mode") { if (GlobalVariables.mode == 0) { root.ChildNodes[I].InnerText = "movie"; } else if (GlobalVariables.mode == 1) { root.ChildNodes[I].InnerText = "gaming"; } else if (GlobalVariables.mode == 2) { root.ChildNodes[I].InnerText = "10*movie smooth"; } else if (GlobalVariables.mode == 3) { root.ChildNodes[I].InnerText = "30*movie smooth"; } else if (GlobalVariables.mode == 4) { root.ChildNodes[I].InnerText = "10*movie smooth+fast scene"; } } else if (root.ChildNodes[I].Name == "fsr") { root.ChildNodes[I].InnerText = fsr.Value.ToString(); } else if (root.ChildNodes[I].Name == "aggressivelevel") { root.ChildNodes[I].InnerText = AggressiveLevel.Value.ToString(); } else if (root.ChildNodes[I].Name == "colorincsmooth") { root.ChildNodes[I].InnerText = ColorIncSmooth.Value.ToString(); } else if (root.ChildNodes[I].Name == "smoothdarkness") { if (SmoothDarkness.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "expand") { if (radioButton1.Checked) root.ChildNodes[I].InnerText = "1"; else if (radioButton2.Checked) root.ChildNodes[I].InnerText = "2"; else root.ChildNodes[I].InnerText = "3"; } else if (root.ChildNodes[I].Name == "maxmultiply") { root.ChildNodes[I].InnerText = numericUpDown1.Value.ToString(); } else if (root.ChildNodes[I].Name == "RedLeft") root.ChildNodes[I].InnerText = RedLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTop") root.ChildNodes[I].InnerText = RedTop.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRight") root.ChildNodes[I].InnerText = RedRight.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeft") root.ChildNodes[I].InnerText = GreenLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTop") root.ChildNodes[I].InnerText = GreenTop.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRight") root.ChildNodes[I].InnerText = GreenRight.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeft") root.ChildNodes[I].InnerText = BlueLeft.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTop") root.ChildNodes[I].InnerText = BlueTop.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRight") root.ChildNodes[I].InnerText = BlueRight.Value.ToString(); else if (root.ChildNodes[I].Name == "RedLeftOnExit") root.ChildNodes[I].InnerText = RedLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "RedTopOnExit") root.ChildNodes[I].InnerText = RedTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "RedRightOnExit") root.ChildNodes[I].InnerText = RedRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenLeftOnExit") root.ChildNodes[I].InnerText = GreenLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenTopOnExit") root.ChildNodes[I].InnerText = GreenTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "GreenRightOnExit") root.ChildNodes[I].InnerText = GreenRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueLeftOnExit") root.ChildNodes[I].InnerText = BlueLeftOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueTopOnExit") root.ChildNodes[I].InnerText = BlueTopOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "BlueRightOnExit") root.ChildNodes[I].InnerText = BlueRightOnExit.Value.ToString(); else if (root.ChildNodes[I].Name == "LeftScanBegin") root.ChildNodes[I].InnerText = LeftBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "LeftScanEnd") root.ChildNodes[I].InnerText = LeftEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanBegin") root.ChildNodes[I].InnerText = TopBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanEnd") root.ChildNodes[I].InnerText = TopEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanBegin") root.ChildNodes[I].InnerText = RightBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanEnd") root.ChildNodes[I].InnerText = RightEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "Interval") root.ChildNodes[I].InnerText = CaptureTimer.Interval.ToString(); else if (root.ChildNodes[I].Name == "Display") root.ChildNodes[I].InnerText = DisplaysBox.Text.Remove(0, 8); else if (root.ChildNodes[I].Name == "DivideLevel") root.ChildNodes[I].InnerText = DivideLevel.Value.ToString(); else if (root.ChildNodes[I].Name == "OffsetLevel") root.ChildNodes[I].InnerText = OffsetLevel.Value.ToString(); else if (root.ChildNodes[I].Name == "AutoEnable") { if (AutoEnable.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "ProcessName") { root.ChildNodes[I].InnerText = ProcessName.Text; } } settings.Save(Application.StartupPath + "\\settings.xml"); SendOnExit(); } else { e.Cancel = true; this.TopMost = true; } }
public void DataSet_ColumnNameWithSpaces () { DataSet ds = new DataSet ("New Data Set"); DataTable table1 = ds.Tables.Add ("New Table 1"); DataTable table2 = ds.Tables.Add ("New Table 2"); table1.Columns.Add ("col 1" , typeof (int)); table1.Columns.Add ("col 2" , typeof (int)); table1.PrimaryKey = new DataColumn[] {ds.Tables [0].Columns [0]}; // No exception shud be thrown XmlDataDocument doc = new XmlDataDocument (ds); // Should fail to save as there are no rows try { doc.Save (new StringWriter ()); Fail ("#1"); } catch (InvalidOperationException) { } table1.Rows.Add (new object[] {0}); table1.Rows.Add (new object[] {1}); table1.Rows.Add (new object[] {2}); // No exception shud be thrown StringWriter swriter = new StringWriter (); doc.Save (swriter); StringReader sreader = new StringReader (swriter.ToString ()); DataSet ds1 = ds.Clone (); XmlDataDocument doc1 = new XmlDataDocument (ds1); AssertEquals ("#2" , 0, ds1.Tables [0].Rows.Count); doc1.Load (sreader); AssertEquals ("#3" , 3, ds1.Tables [0].Rows.Count); }
protected void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 XmlDocument xmldoc=new XmlDocument(); //读取用户参数 StreamReader streamreader=new StreamReader(this.Request.InputStream,Encoding.UTF8); xmldoc.LoadXml(streamreader.ReadToEnd()); NameObjectList[] paramlist=BuildParamList.BuildParamsList(xmldoc); try { string unitName=paramlist[0]["UnitName"].ToString(); unitItem = new UnitItem(this.MapPath(DataAccRes.AppSettings("WorkConfig")), unitName); } catch ( Exception ex ) { ExceptionManager.Publish( ex ); return; } QueryDataRes query=new QueryDataRes(unitItem.DataSrcFile); DataSet ds=new DataSet(unitItem.UnitName); ds.EnforceConstraints=false; string itemdata=paramlist[0]["DataItem"].ToString(); string[] dataItemList=itemdata.Split(",".ToCharArray()); for(int i=0;i<dataItemList.Length;i++) { if(""==dataItemList[i]) continue; for(int j=0;j<paramlist.Length;j++) { DataTable tab = query.getTable(dataItemList[i], paramlist[j]); ds.Merge(tab); } } //增加行光标列 for (int i = 0; i < ds.Tables.Count; i++) { DataTable tab = ds.Tables[i]; if (null != tab && !tab.Columns.Contains("RowNum")) tab.Columns.Add("RowNum", Type.GetType("System.Int32")); for (int j = 0; null != tab && j < tab.Rows.Count; j++) tab.Rows[j]["RowNum"] = j + 1; } //数字是0的,改为空值显示 for (int s = 0; s < ds.Tables.Count; s++) { DataTable tab = ds.Tables[s]; if (null == tab) continue; for (int i = 0; i < tab.Columns.Count; i++) { DataColumn col = tab.Columns[i]; if ("RowNum" == col.ColumnName) continue; if ("Decimal" != col.DataType.Name && "Double" != col.DataType.Name && "Int16" != col.DataType.Name && "Int32" != col.DataType.Name && "Int64" != col.DataType.Name && "Single" != col.DataType.Name && "UInt16" != col.DataType.Name && "UInt32" != col.DataType.Name && "UInt64" != col.DataType.Name) continue; for (int j = 0; j < tab.Rows.Count; j++) { if (null == tab.Rows[j][i] || DBNull.Value == tab.Rows[j][i]) continue; decimal num = Convert.ToDecimal(tab.Rows[j][i]); if (0 == num) tab.Rows[j][i] = DBNull.Value; } } } this.xmldocSchema.LoadXml(ds.GetXmlSchema()); XmlNamespaceManager xmlNsMgl=new XmlNamespaceManager(this.xmldocSchema.NameTable); XmlNode xmlRootEle=this.xmldocSchema.DocumentElement; for(int i=0;i<xmlRootEle.Attributes.Count;i++) { string strPrefix=xmlRootEle.Attributes[i].Prefix; string strLocalName=xmlRootEle.Attributes[i].LocalName; string strURI=xmlRootEle.Attributes[i].Value; if("xmlns"==strLocalName) xmlNsMgl.AddNamespace(string.Empty,strURI); if("xmlns"!=strPrefix) continue; xmlNsMgl.AddNamespace(strLocalName,strURI); } this._xmlNsMglSchema=xmlNsMgl; this.setSchema(ds); QueryDataRes dictQuery=new QueryDataRes(unitItem.DictColSrcFile); WorkItem workitem=null; for(int i=0;i<unitItem.WorkItemList.Length;i++) if(unitItem.WorkItemList[i].ItemName==paramlist[0]["WorkItem"].ToString()) { workitem=unitItem.WorkItemList[i]; break; } for(int i=0;i<workitem.DictCol.Length;i++) { DictColumn dictcol=workitem.DictCol[i]; if (dictcol.DataSrc.Trim().Length > 0) { bool isContinue = false; for (int k = 0; k < i; k++) if (dictcol.DataSrc == workitem.DictCol[k].DataSrc) { isContinue = true; break; } if (isContinue) continue; dictQuery.FillDataSet(dictcol.DataSrc, paramlist, this._dictds); } } XmlDataDocument xmldocData=new XmlDataDocument(ds); this.setFormatXmlLand(xmldocData,ds); this.Response.ContentType = "text/xml; charset=gb2312"; xmldocData.Save(this.Response.Output); }
public void Test1() { //Create an XmlDataDocument. XmlDataDocument doc = new XmlDataDocument(); //Load the schema file. doc.DataSet.ReadXmlSchema(new StringReader(DataProvider.store)); //Load the XML data. doc.Load(new StringReader( @"<!--sample XML fragment--> <bookstore> <book genre='novel' ISBN='10-861003-324'> <title>The Handmaid's Tale</title> <price>19.95</price> </book> <book genre='novel' ISBN='1-861001-57-5'> <title>Pride And Prejudice</title> <price>24.95</price> </book> </bookstore>")); //Update the price on the first book using the DataSet methods. DataTable books = doc.DataSet.Tables["book"]; books.Rows[0]["price"] = "12.95"; //string outstring = ""; TextWriter text = new StringWriter(); text.NewLine = "\n"; doc.Save(text); //str.Read (bytes, 0, (int)str.Length); //String OutString = new String (bytes); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf("<?xml version=\"1.0\" encoding=\"utf-16\"?>") == 0); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf("<!--sample XML fragment-->") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf("<bookstore>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <book genre=\"novel\" ISBN=\"10-861003-324\">") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <title>The Handmaid's Tale</title>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" <price>12.95</price>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </book>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <book genre=\"novel\" ISBN=\"1-861001-57-5\">") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <title>Pride And Prejudice</title>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <price>24.95</price>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </book>") != -1); substring = TextString; Assert.True(substring.IndexOf("</bookstore>") != -1); }
public void CreateElement1 () { XmlDataDocument doc = new XmlDataDocument (); doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd"); doc.Load ("Test/System.Xml/region.xml"); XmlElement Element = doc.CreateElement ("prefix", "localname", "namespaceURI"); Assert.AreEqual ("prefix", Element.Prefix, "test#01"); Assert.AreEqual ("localname", Element.LocalName, "test#02"); Assert.AreEqual ("namespaceURI", Element.NamespaceURI, "test#03"); doc.ImportNode (Element, false); TextWriter text = new StringWriter (); doc.Save(text); string substring = string.Empty; string TextString = text.ToString (); substring = TextString.Substring (0, TextString.IndexOf("\n")); TextString = TextString.Substring (TextString.IndexOf("\n") + 1); substring = TextString.Substring (0, TextString.IndexOf("\n")); TextString = TextString.Substring (TextString.IndexOf("\n") + 1); Assert.IsTrue (substring.IndexOf ("<Root>") != -1, "test#05"); substring = TextString.Substring (0, TextString.IndexOf("\n")); TextString = TextString.Substring (TextString.IndexOf("\n") + 1); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "test#06"); substring = TextString.Substring (0, TextString.IndexOf("\n")); TextString = TextString.Substring (TextString.IndexOf("\n") + 1); Assert.IsTrue (substring.IndexOf (" <RegionID>1</RegionID>") != -1, "test#07"); for (int i = 0; i < 26; i++) { substring = TextString.Substring (0, TextString.IndexOf("\n")); TextString = TextString.Substring (TextString.IndexOf("\n") + 1); } substring = TextString.Substring (0, TextString.Length); Assert.IsTrue (substring.IndexOf ("</Root>") != -1, "test#08"); }
public void Test4() { DataSet RegionDS = new DataSet(); RegionDS.ReadXmlSchema(new StringReader(RegionXsd)); XmlDataDocument DataDoc = new XmlDataDocument(RegionDS); DataDoc.Load(new StringReader(RegionXml)); Assert.True(RegionDS.EnforceConstraints); DataTable table = DataDoc.DataSet.Tables["Region"]; DataRow newRow = table.NewRow(); newRow[0] = "new row"; newRow[1] = "new description"; table.Rows.Add(newRow); TextWriter text = new StringWriter(); text.NewLine = "\n"; DataDoc.Save(text); string TextString = text.ToString(); string substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf("<Root>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>1</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.Equal(" <RegionDescription>Eastern", substring); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.Equal(" </RegionDescription>", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>2</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Western") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>3</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>Northern") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>4</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOfAny(new[] { '\r', '\n' })); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.Equal(" <RegionDescription>Southern", substring); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column1>12</Column1>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column2>Hi There</Column2>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column1>12</Column1>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Column2>Hi There</Column2>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </MoreData>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <Region>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionID>new row</RegionID>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" <RegionDescription>new description</RegionDescription>") != -1); substring = TextString.Substring(0, TextString.IndexOf(s_EOL)); TextString = TextString.Substring(TextString.IndexOf(s_EOL) + s_EOL.Length); Assert.True(substring.IndexOf(" </Region>") != -1); substring = TextString.Substring(0, TextString.Length); Assert.True(substring.IndexOf("</Root>") != -1); }
static void Main(string[] args) { string city = string.Empty; string country = string.Empty; string latitude = string.Empty; string longitude = string.Empty; string la_dir = string.Empty; string lo_dir = string.Empty; string green = string.Empty; SortedDictionary<string, XmlNode> dic = new SortedDictionary<string, XmlNode>(); XmlDataDocument doc = new XmlDataDocument(); doc.Load("locdata.xml"); XmlNodeList nodes = doc.GetElementsByTagName("loctest"); foreach (XmlNode nd in nodes) { dic.Add(nd.ChildNodes[0].InnerText, nd); } XmlNodeList mainnodes = doc.GetElementsByTagName("DataSet1"); mainnodes[0].RemoveAll(); foreach (string s in dic.Keys) { mainnodes[0].AppendChild(dic[s]); } doc.Save("locdata2.xml"); bool readloc = false; StreamWriter writer = new StreamWriter("pagal.txt"); XmlTextReader reader = new XmlTextReader("locdata2.xml"); while (reader.Read()) { if ((reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement)) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "loctest") { readloc = true; } if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "loctest") { readloc = false; } if (readloc == false && reader.Name == "loctest") { writer.WriteLine(city + " - " + country + " - " + latitude + " - " + longitude + " - " + green); continue; } switch (reader.Name) { case "city": city = reader.ReadInnerXml(); break; case "country": country = reader.ReadInnerXml(); break; case "green": green = reader.ReadInnerXml(); break; case "latitude": latitude = reader.ReadInnerXml(); break; case "longitude": longitude = reader.ReadInnerXml(); break; case "la_dir": la_dir = reader.ReadInnerXml(); break; case "lo_dir": lo_dir = reader.ReadInnerXml(); break; } } } reader.Close(); writer.Close(); }
public void Test1() { //Create an XmlDataDocument. XmlDataDocument doc = new XmlDataDocument(); //Load the schema file. doc.DataSet.ReadXmlSchema("Test/System.Xml/store.xsd"); //Load the XML data. doc.Load("Test/System.Xml/2books.xml"); //Update the price on the first book using the DataSet methods. DataTable books = doc.DataSet.Tables["book"]; books.Rows[0]["price"] = "12.95"; //string outstring = ""; TextWriter text = new StringWriter (); text.NewLine = "\n"; doc.Save(text); //str.Read (bytes, 0, (int)str.Length); //String OutString = new String (bytes); string TextString = text.ToString (); string substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf ("<?xml version=\"1.0\" encoding=\"utf-16\"?>") == 0, "#A01"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf ("<!--sample XML fragment-->") != -1, "#A02"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf ("<bookstore>") != -1, "#A03"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <book genre=\"novel\" ISBN=\"10-861003-324\">") != -1, "#A04"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <title>The Handmaid's Tale</title>") != -1, "#A05"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" <price>12.95</price>", substring, "#A06"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </book>") != -1, "#A07"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <book genre=\"novel\" ISBN=\"1-861001-57-5\">") != -1, "#A08"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <title>Pride And Prejudice</title>") != -1, "#A09"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <price>24.95</price>") != -1, "#A10"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </book>") != -1, "#A11"); substring = TextString; Assert.IsTrue (substring.IndexOf ("</bookstore>") != -1, "#A12"); }
internal static bool VerifySqlProjFile(DataSet ds, string sqlProjPath) { DataTable dt = null; bool hasChanges = false; string ver = "2.6.0.0"; string asmName = "yukondeploy,version=2.6.0.0,culture=neutral,publickeytoken=837e5cc1726a2c56"; dt = ds.Tables["UsingTask"]; foreach (DataRow row in dt.Rows) { if (!row["AssemblyName"].ToString().Contains(ver)) { row["AssemblyName"] = asmName; hasChanges = true; } } //create the table which will hold the projfile with DataTable dtFile = new DataTable(); dtFile.Columns.Add(new DataColumn("TableName", typeof(string))); dtFile.Columns.Add(new DataColumn("ColumnName", typeof(string))); dtFile.Columns.Add(new DataColumn("TypeName", typeof(string))); dtFile.Columns.Add(new DataColumn("ObjectValue", typeof(object))); dtFile.Columns.Add(new DataColumn("MapType", typeof(MappingType))); //add values dtFile.Rows.Add(new object[] { "PropertyGroup", "Assemblyname", "System.String", "$(AssemblyName)", MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Alterassembly", "System.Boolean", false, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Uncheckeddata", "System.Boolean", false, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Permissionset", "System.Int32", 0, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "ConnectDatabase", "System.Boolean", true, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Connectionstring", "System.String", "server=localhost;database=[DB_NAME];Integrated Security='SSPI'", MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Infermethods", "System.Boolean", false, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "DropTable", "System.Boolean", true, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Uploadsource", "System.Boolean", false, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourceextension", "System.String", "cs", MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourcepath", "System.String", "$(MSBuildProjectDirectory)", MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Usedeployattributes", "System.Boolean", true, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Deploydbgsymbols", "System.Boolean", true, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Debugpath", "System.String", "$(TargetDir)$(TargetName).pdb", MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Castudtcolto", "System.Int32", 0, MappingType.Element }); dtFile.Rows.Add(new object[] { "PropertyGroup", "Serverversion", "System.Int32", 0, MappingType.Element }); dtFile.Rows.Add(new object[] { "DeployAssembly", "UsingDMDeployAttributes", "System.String", "$(Usedeployattributes)", MappingType.Attribute }); dtFile.Rows.Add(new object[] { "DeployAssembly", "DeployDebugSymbols", "System.String", "$(Deploydbgsymbols)", MappingType.Attribute }); dtFile.Rows.Add(new object[] { "DeployAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute }); dtFile.Rows.Add(new object[] { "DeployAssembly", "SqlServerVersion", "System.String", "$(Serverversion)", MappingType.Attribute }); dtFile.Rows.Add(new object[] { "DeployTypes", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute }); dtFile.Rows.Add(new object[] { "DropAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute }); bool ret = false; //read off the values and check against the proj-file foreach (DataRow r in dtFile.Rows) { ret = CheckDataSet2(ds, r["TableName"].ToString(), r["ColumnName"].ToString(), r["TypeName"].ToString(), (object)r["ObjectValue"], (MappingType)r["MapType"]); if (ret) hasChanges = true; } if (hasChanges) { ds.AcceptChanges(); DataSet dsUpdate = null; dsUpdate = ds.Copy(); XmlDataDocument doc = new XmlDataDocument(dsUpdate); doc.Save(sqlProjPath); ds.Clear(); ds.Dispose(); } return hasChanges; }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { DisableWorkingUnit(); bool close = true; this.TopMost = false; /* // exit dialog if (e.CloseReason != CloseReason.WindowsShutDown) { DialogResult result = MessageBox.Show("Do you want to exit?", "AmbiLEDd", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { close = true; } } else { close = true; } // */ if (close) { XmlDocument settings = new XmlDataDocument(); settings.Load(Application.StartupPath + "\\AmbiLEDd.xml"); XmlElement root = settings.DocumentElement; for (int I = 0; I < root.ChildNodes.Count; I++) { if (root.ChildNodes[I].Name == "enabled") { if (global.Enabled == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "minimized") { if (this.WindowState == FormWindowState.Minimized) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "LeftScanBegin") root.ChildNodes[I].InnerText = LeftBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "LeftScanEnd") root.ChildNodes[I].InnerText = LeftEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanBegin") root.ChildNodes[I].InnerText = TopBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "TopScanEnd") root.ChildNodes[I].InnerText = TopEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanBegin") root.ChildNodes[I].InnerText = RightBegin.Value.ToString(); else if (root.ChildNodes[I].Name == "RightScanEnd") root.ChildNodes[I].InnerText = RightEnd.Value.ToString(); else if (root.ChildNodes[I].Name == "Interval") root.ChildNodes[I].InnerText = global.var_Interval.ToString(); else if (root.ChildNodes[I].Name == "ReduceLevel") root.ChildNodes[I].InnerText = global.var_ReduceToWidth.ToString(); else if (root.ChildNodes[I].Name == "AutoEnable") { if (AutoEnable.Checked == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "DisableDWM") { if (global.DisableDWM == true) { root.ChildNodes[I].InnerText = "true"; } else { root.ChildNodes[I].InnerText = "false"; } } else if (root.ChildNodes[I].Name == "ProcessName") { root.ChildNodes[I].InnerText = ProcessName.Text; } else if (root.ChildNodes[I].Name == "VertexProcessing") { root.ChildNodes[I].InnerText = global.var_VertexMode.ToString(); } else if (root.ChildNodes[I].Name == "Display") root.ChildNodes[I].InnerText = global.SelectedDisplay.ToString(); } settings.Save(Application.StartupPath + "\\AmbiLEDd.xml"); } else { e.Cancel = true; this.TopMost = true; } }
public void Test2() { DataSet RegionDS = new DataSet (); DataRow RegionRow; RegionDS.ReadXmlSchema ("Test/System.Xml/region.xsd"); Assert.AreEqual (1, RegionDS.Tables.Count, "Was read correct?"); XmlDataDocument DataDoc = new XmlDataDocument (RegionDS); DataDoc.Load("Test/System.Xml/region.xml" ); RegionRow = RegionDS.Tables[0].Rows[0]; RegionDS.AcceptChanges (); RegionRow["RegionDescription"] = "Reeeeeaalllly Far East!"; RegionDS.AcceptChanges (); TextWriter text = new StringWriter (); text.NewLine = "\n"; DataDoc.Save (text); string TextString = text.ToString (); string substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); //Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\" standalone=\"yes\"?>", substring, "#B01"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual ("<Root>", substring, "#B02"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#B03"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>1</RegionID>") != -1, "#B04"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" <RegionDescription>Reeeeeaalllly Far East!</RegionDescription>", substring, "#B05"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#B06"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#B07"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>2</RegionID>") != -1, "#B08"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Western") != -1, "#B09"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#B10"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#B11"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#B12"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>3</RegionID>") != -1, "#B13"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Northern") != -1, "#B14"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#B15"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#B16"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#B17"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>4</RegionID>") != -1, "#B18"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Southern") != -1, "#B19"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#B20"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#B21"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <MoreData>") != -1, "#B22"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column1>12</Column1>") != -1, "#B23"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column2>Hi There</Column2>") != -1, "#B24"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </MoreData>") != -1, "#B25"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <MoreData>") != -1, "#B26"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column1>12</Column1>") != -1, "#B27"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column2>Hi There</Column2>") != -1, "#B28"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </MoreData>") != -1, "#B29"); }
protected void Page_Load(object sender, EventArgs e) { if (Session["userid"] == null) { this.Response.Write("<script language=\"javascript\">"); this.Response.Write("alert('您未正常登录,请登录后再使用,谢谢!')"); this.Response.Write("</script>"); this.Response.Redirect("index.htm"); } XmlDocument xmldoc = new XmlDocument(); //读取用户参数 StreamReader streamreader = new StreamReader(this.Request.InputStream, Encoding.UTF8); xmldoc.LoadXml(streamreader.ReadToEnd()); string[] strParams = this.getStrParams(xmldoc); NameObjectList paramlist = BuildParamList.BuildParams(xmldoc); try { string unitName = paramlist["UnitName"].ToString(); if (paramlist["DictSrcFile"]==null) unitItem = new UnitItem(DataAccRes.AppSettings("WorkConfig"), unitName); } catch (Exception ex) { ExceptionManager.Publish(ex); return; } string workItemName = ""; WorkItem workitem = null; QueryDataRes query; if (paramlist["DataSrcFile"]!=null) query = new QueryDataRes(paramlist["DictSrcFile"].ToString()); else query = new QueryDataRes(unitItem.DictColSrcFile); DataSet ds = new DataSet("Dict"); ds.EnforceConstraints = false; //htm页面控件字典或人工指定字典 string itemdatas = paramlist["htmldict"].ToString(); string itemdata = paramlist["htmldict"].ToString(); string itemtable = itemdata; if(itemdatas.IndexOf(";")>-1) { string[] arr = leofun.getArrayFromString(itemdatas,";"); itemdata = arr[0]; itemtable = arr[1]; } if (itemdata != "") { query.FillDataSet(itemdata, paramlist, strParams, ds); } else { for (int i = 0; i < unitItem.WorkItemList.Length; i++) { for (int j = 0; j < unitItem.WorkItemList[i].DictCol.Length; j++) { string dictsrcs = unitItem.WorkItemList[i].DictCol[j].DataSrc; string dictsrc = unitItem.WorkItemList[i].DictCol[j].DataSrc; itemtable = dictsrc; if (dictsrcs == "" || dictsrcs == null) continue; if (dictsrcs.IndexOf(";") > -1) { string[] arr = leofun.getArrayFromString(dictsrcs, ";"); dictsrc = arr[0]; itemtable = arr[1]; } query.FillDataSet(dictsrc, paramlist, strParams, ds); } } } if (ds.Tables.Count > 0 && itemtable != "") ds.Tables[0].TableName = itemtable; XmlDataDocument xmldocData = new XmlDataDocument(ds); this.Response.ContentType = "text/xml; charset=gb2312"; xmldocData.Save(this.Response.Output); }
public void Test4 () { DataSet RegionDS = new DataSet (); RegionDS.ReadXmlSchema ("Test/System.Xml/region.xsd"); XmlDataDocument DataDoc = new XmlDataDocument (RegionDS); DataDoc.Load ("Test/System.Xml/region.xml"); Assert.IsTrue (RegionDS.EnforceConstraints); DataTable table = DataDoc.DataSet.Tables ["Region"]; DataRow newRow = table.NewRow (); newRow [0] = "new row"; newRow [1] = "new description"; table.Rows.Add (newRow); TextWriter text = new StringWriter (); text.NewLine = "\n"; DataDoc.Save (text); string TextString = text.ToString (); string substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf ("<Root>") != -1, "#F02"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#F03"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>1</RegionID>") != -1, "#F04"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.AreEqual (" <RegionDescription>Eastern", substring, "#F05"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.AreEqual (" </RegionDescription>", substring, "#F06"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#F07"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#F08"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>2</RegionID>") != -1, "#F09"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Western") != -1, "#F10"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#F11"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#F12"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#F13"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>3</RegionID>") != -1, "#F14"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>Northern") != -1, "#F15"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#F16"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#F17"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#F18"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>4</RegionID>") != -1, "#F19"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); // Regardless of NewLine value, original xml contains CR // (but in the context of XML spec, it should be normalized) Assert.AreEqual (" <RegionDescription>Southern", substring, "#F20"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </RegionDescription>") != -1, "#F21"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#F22"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <MoreData>") != -1, "#F23"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column1>12</Column1>") != -1, "#F24"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column2>Hi There</Column2>") != -1, "#F25"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </MoreData>") != -1, "#F26"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <MoreData>") != -1, "#F27"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column1>12</Column1>") != -1, "#F28"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Column2>Hi There</Column2>") != -1, "#F29"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </MoreData>") != -1, "#F30"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <Region>") != -1, "#F31"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionID>new row</RegionID>") != -1, "#F32"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" <RegionDescription>new description</RegionDescription>") != -1, "#F33"); substring = TextString.Substring (0, TextString.IndexOf(EOL)); TextString = TextString.Substring (TextString.IndexOf(EOL) + EOL.Length); Assert.IsTrue (substring.IndexOf (" </Region>") != -1, "#F34"); substring = TextString.Substring (0, TextString.Length); Assert.IsTrue (substring.IndexOf ("</Root>") != -1, "#F35"); }