GetXmlSchema() public method

public GetXmlSchema ( ) : string
return string
        //private void WriteHashTable(Hashtable hash)
        //{
        //    _output.Append("{");
        //    bool pendingSeparator = false;
        //    foreach (object entry in hash.Keys)
        //    {
        //        if (pendingSeparator)
        //            _output.Append(",");
        //        WriteValue(entry);
        //        _output.Append(":");
        //        WriteValue(hash[entry]);
        //        pendingSeparator = true;
        //    }
        //    _output.Append("}");
        //}
        private void WriteDataset(DataSet ds)
        {
            _output.Append("{");
            WritePair("$schema", ds.GetXmlSchema());
            _output.Append(",");

            foreach (DataTable table in ds.Tables)
            {
                _output.Append("\"");
                _output.Append(table.TableName);
                _output.Append("\":[");

                foreach (DataRow row in table.Rows)
                {
                    _output.Append("{");
                    foreach (DataColumn column in row.Table.Columns)
                    {
                        WritePair(column.ColumnName, row[column]);
                    }
                    _output.Append("}");
                }

                _output.Append("]");
            }
            // end dataset
            _output.Append("}");
        }
Esempio n. 2
0
        static void Main()
        {
            string strConn = "Data Source=localhost;Initial Catalog=booksourcedb;Integrated Security=True";
              string strSql = "SELECT * FROM book";
              SqlDataAdapter dataAdapter = new SqlDataAdapter(strSql, strConn);

              DataSet dataSet = new DataSet("booklist");
              dataAdapter.Fill(dataSet, "book");

              string strXml = dataSet.GetXml();
              string strSchema = dataSet.GetXmlSchema();

              Console.WriteLine("[DataSet 내용을 XML 문서로 쓰기]");
              Console.WriteLine("------------------------------------");
              Console.WriteLine(strXml);

              Console.WriteLine("\n[DataSet 구조를 Schema 문서로 쓰기]");
              Console.WriteLine("------------------------------------");
              Console.WriteLine(strSchema);
        }
Esempio n. 3
0
        public bool loadXMLAtom(channel ch, string rss)
        {
            using (DataSet rssData = new DataSet())
            {
                System.IO.StringReader sr = new System.IO.StringReader(rss);
                DataSet ds2 = new DataSet();
                rssData.ReadXml(sr, XmlReadMode.Auto);
                string str = rssData.GetXmlSchema();

                if (rssData.Tables.Contains("feed"))
                {
                    foreach (DataRow dataRow in rssData.Tables["feed"].Rows)
                    {
                        int c = rssData.Tables.Count;

                        if (rssData.Tables.Contains("link"))
                        {
                            foreach (DataRow dr in rssData.Tables["link"].Rows)
                            {
                                ch.link = dataRowContains("href", dr, rssData);
                                break;
                            }
                        }
                        //dataRowContains("title", dataRow, rssData);
                        //rss_sub.set_title(ch.title);
                        ch.description = dataRowContains("subtitle", dataRow, rssData);//Convert.ToString(dataRow["subtitle"]);
                        ch.pubDate = dataRowContains("updated", dataRow, rssData);//Convert.ToString(dataRow["updated"]);
                        int counter = 0;
                        if (rssData.Tables.Contains("entry"))
                        {
                            foreach (DataRow itemRow in rssData.Tables["entry"].Rows)
                            {
                                Item inside = new Item();
                                inside.titleI = dataRowContains("title", itemRow, rssData);//Convert.ToString(itemRow["title"]);
                                inside.descriptionI = dataRowContains("summary", itemRow, rssData);//Convert.ToString(itemRow["summary"]);
                                inside.linkI = dataRowContains("id", itemRow, rssData);//Convert.ToString(rssData.Tables["id"]);
                                inside.pubDateI = dataRowContains("updated", itemRow, rssData);//Convert.ToString(itemRow["updated"]);
                                if (inside.pubDateI == "")
                                {
                                    inside.pubDateI = dataRowContains("issued", itemRow, rssData);
                                }
                                inside.subscription = ch.title;
                                if (rssData.Tables.Contains("link"))
                                {
                                    foreach (DataRow dr in rssData.Tables["link"].Rows)
                                    {
                                        if (dr["href"].ToString().Contains(".html"))
                                        {
                                            inside.linkI = dr["href"].ToString();
                                        }
                                    }
                                }
                                if (rssData.Tables.Contains("author"))
                                {
                                    //foreach (DataRow authorRow in rssData.Tables["author"].Rows)
                                    DataRow authorRow = rssData.Tables["author"].Rows[0];
                                    //foreach (DataRow authorRow in itemRow["author"])
                                    {
                                        author auth = new author();
                                        auth.name = dataRowContains("name", authorRow, rssData);
                                        auth.email = dataRowContains("email", authorRow, rssData);
                                        inside.authors.Add(auth);
                                    }
                                }
                                ch.item.Add(inside);

                                counter++;
                                if (counter > ch.maxItems) { break; }
                            }
                        }
                        /*if (findChannelName(ch.title) == null)
                        {
                            channels.Add(ch);
                        }*/
                    }

                }
                return true;
            }
        }
		public void AutoIncrementStep ()
		{
			DataSet ds = new DataSet("testds");
			DataTable tbl = ds.Tables.Add("testtbl");
			DataColumn col = tbl.Columns.Add("id", typeof(int));
			col.AutoIncrement = true;
			col.AutoIncrementSeed = -1;
			col.AutoIncrementStep = -1;
			tbl.Columns.Add("data", typeof(string));
			Assert.IsTrue (ds.GetXmlSchema ().IndexOf ("AutoIncrementStep") > 0);
		}
Esempio n. 5
0
		private void CompareResults_Fill(DataSet dsResult,DataSet dsExpected ) {
			Exception exp = null;

			//			try
			//			{
			//				BeginCase("Compare Rows count");
			//				// ???????   Fill return count for first table only    ??????
			//				Compare(ExpectedRowsCount  ,ResultRowsCount );
			//			}
			//			catch(Exception ex)	{exp = ex;}
			//			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("Compare data");
				Compare(dsResult.GetXml() ,dsExpected.GetXml());
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}

			try {
				BeginCase("Compare schema");
				Compare(dsResult.GetXmlSchema() ,dsExpected.GetXmlSchema());
			}
			catch(Exception ex)	{exp = ex;}
			finally	{EndCase(exp); exp = null;}
		}
Esempio n. 6
0
 public string fGetXMlSchemaFromDataSet(DataSet DS)
 {
     string sXML;
     sXML = DS.GetXmlSchema();
     return sXML;
 }
Esempio n. 7
0
    public string CtrlDataBind(WorkItem workitem)
    {
        this.ViewState["sendpage"] = "";
        NameObjectList paramlist = BuildParamList.BuildParams(this.PgParamXmlDoc);
        string[] strParams = this.getStrParams();
        int iPageSize = 0, iRecordCount = 0;
        string workitemdrc = workitem.DataSrc;
        if (workitemdrc.IndexOf(":") > -1)
            workitemdrc = workitemdrc.Substring(workitemdrc.IndexOf(":")+1, workitemdrc.Length-workitemdrc.IndexOf(":")-1);
        //分页,汇总数据
        DataSet dsCount = new DataSet("汇总");
        dsCount.EnforceConstraints = false;
        if (null != workitem.CountDataSrc && string.Empty != workitem.CountDataSrc)
        {
            this.PgDictQuery.FillDataSet(workitem.CountDataSrc, paramlist, strParams, dsCount);
        }
        Xml CtrlXmlCount = new Xml();
        CtrlXmlCount.Document = new XmlDataDocument(dsCount);
        DataTable counttab = null;
        if (dsCount.Tables.Count > 0) counttab = dsCount.Tables[0];
        XmlDocument xmldocCount = CtrlXmlCount.Document;
        if (counttab != null)
        {
            if (null != workitem.PageSize && string.Empty != workitem.PageSize)
            {
                this.ViewState["PageSize" + workitemdrc] = workitem.PageSize;
                iPageSize = Convert.ToInt32(workitem.PageSize);
                if (counttab.Rows.Count == 0)
                {
                    this.ViewState["RecordCount" + workitemdrc] = null;
                    iRecordCount = 0;
                }
                else
                {
                    this.ViewState["RecordCount" + workitemdrc] = counttab.Rows[0]["记录数量"].ToString();
                    iRecordCount = Convert.ToInt32(counttab.Rows[0]["记录数量"]);
                }
                //考虑iRecordCount<=iPageSize,时,并且:this.ViewState["PageIndex" + workitem.DataSrc])>1,要刷新页面

                if (iPageSize > 0)
                {
                    if (this.ViewState["PageIndex" + workitemdrc] != null)
                    {
                        if (iRecordCount <= iPageSize && Convert.ToInt32(this.ViewState["PageIndex" + workitemdrc].ToString()) > 1)
                        {
                            this.ViewState["TotalPages" + workitemdrc] = 1;
                            this.ViewState["PageIndex" + workitemdrc] = 1;
                        }
                        else
                            this.ViewState["TotalPages" + workitemdrc] = (int)Math.Ceiling((double)iRecordCount / iPageSize);
                    }
                    else
                        this.ViewState["TotalPages" + workitemdrc] = (int)Math.Ceiling((double)iRecordCount / iPageSize);
                }
            }
        }
        else
            xmldocCount.LoadXml("<DataSet><DataTableCount/></DataSet>");
        if (xmldocCount.DocumentElement != null)
        {
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("id"));
            xmldocCount.DocumentElement.Attributes["id"].Value = workitemdrc + "Tab_Sum";
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("typexml"));
            xmldocCount.DocumentElement.Attributes["typexml"].Value = "Count";
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("itemname"));
            xmldocCount.DocumentElement.Attributes["itemname"].Value = workitem.ItemName;
        }
        
        //当前页数据
        DataSet ds = new DataSet("etpTemplate_" + workitemdrc + "Tab_xmlland");
        ds.EnforceConstraints = false;
        strParams = this.getStrParams();
        this.PgQuery.FillDataSet(workitem.DataSrc, paramlist, strParams, ds);
        DataTable drc = ds.Tables[workitem.DataSrc];
        if (drc == null) return "";

        //增加行光标列
        if (null != drc && !drc.Columns.Contains("RowNum"))
            drc.Columns.Add("RowNum", Type.GetType("System.Int32"));
        
        if (iPageSize < 1) iPageSize = 10;
        int iPageIndex = 1;
        if (null != this.ViewState["PageIndex" + workitemdrc])
            iPageIndex = Convert.ToInt32(this.ViewState["PageIndex" + workitemdrc]);
        for (int i = 0; null != drc && i < drc.Rows.Count; i++)
            drc.Rows[i]["RowNum"] = i + 1 + (iPageIndex - 1) * iPageSize;
        //如果是数字类型,值是0的,改为空的
        for (int i = 0; null != drc && i < drc.Columns.Count; i++)
        {
            DataColumn col = drc.Columns[i];
            if ("rownum" == col.ColumnName.ToLower()) 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 = drc.Select("["+col.ColumnName + "]=0");
            for (int j = 0; j < drs.Length; j++)
                drs[j][i] = DBNull.Value;
        }
        //生成数据文档
        this.CtrlXmlLand.Document = new XmlDataDocument(ds);
        XmlDocument CtrlDBXmlDoc = this.CtrlXmlLand.Document;
        XmlDocument xmldoc = this.CtrlXmlLand.Document;
        if (xmldoc.DocumentElement == null)
            xmldoc.AppendChild(xmldoc.CreateElement("etpTemplate_" + workitemdrc + "Tab_xmlland"));
        if (null == xmldoc.DocumentElement.Attributes["id"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("id"));
        if (null == xmldoc.DocumentElement.Attributes["itemname"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("itemname"));
        if (null == xmldoc.DocumentElement.Attributes["typexml"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("typexml"));
        xmldoc.DocumentElement.Attributes["id"].Value = workitemdrc + "Tab";
        xmldoc.DocumentElement.Attributes["itemname"].Value = workitem.ItemName;
        xmldoc.DocumentElement.Attributes["typexml"].Value = "Data";

        try
        {
            if (iRecordCount < drc.Rows.Count)
                iRecordCount = drc.Rows.Count;
        }
        catch
        {
            iRecordCount = 0;
        }
        //当前页码,行记录个数
        //在XmlCount数据岛增加TotalPage;PageIndex;PageSize,RecordCount数据
        XmlNode xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("TotalPage"));
        xmlNode.InnerText = (null == this.ViewState["TotalPages" + workitemdrc]) ? "1" : this.ViewState["TotalPages" + workitemdrc].ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageIndex"));
        xmlNode.InnerText = (null == this.ViewState["PageIndex" + workitemdrc]) ? "1" : this.ViewState["PageIndex" + workitemdrc].ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageSize"));
        xmlNode.InnerText = iPageSize.ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("RecordCount"));
        xmlNode.InnerText = iRecordCount.ToString();

        string _s = "";
        string xmlstr1 = "";
        XmlNode xmlcountNode = xmldocCount.SelectSingleNode("//DataSet");

        if (xmlcountNode == null)
        {
            xmlcountNode = xmldocCount.SelectSingleNode("//汇总");
            _s = (xmlcountNode == null) ? "" : xmlcountNode.InnerXml;
            xmlstr1 = string.Format("<XML id=\"{0}Tab_Sum\" typexml=\"Count\" itemname=\"{1}\"><汇总>{2}</汇总></XML>", workitemdrc, workitem.ItemName, _s);
        }
        else
        {
            _s = (xmlcountNode == null) ? "" : xmlcountNode.InnerXml;
            xmlstr1 = string.Format("<XML id=\"{0}Tab_Sum\" typexml=\"Count\" itemname=\"{1}\"><DataSet>{2}</DataSet></XML>", workitemdrc, workitem.ItemName, _s);
        }
        //删除区数据
        Xml CtrlXmlDelete = new Xml();
        CtrlXmlDelete.Document = new XmlDocument();
        XmlDocument xmldocDel = CtrlXmlDelete.Document;
        xmldocDel.AppendChild(xmldocDel.CreateElement(xmldoc.DocumentElement.LocalName));
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("id"));
        xmldocDel.DocumentElement.Attributes["id"].Value = workitemdrc + "Tab_Delete";
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("typexml"));
        xmldocDel.DocumentElement.Attributes["typexml"].Value = "Delete";
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("itemname"));
        xmldocDel.DocumentElement.Attributes["itemname"].Value = workitem.ItemName;


        string xmlstr2 = string.Format("<XML id=\"{0}Tab_Delete\" typexml=\"Delete\" itemname=\"{1}\"><etpTemplate_{2}Tab_xmlland></etpTemplate_{3}Tab_xmlland></XML>",
            workitemdrc, workitem.ItemName, workitemdrc, workitemdrc);

        //数据岛结构信息
        Xml CtrlXmlSchema = new Xml();
        CtrlXmlSchema.Document = new XmlDocument();
        CtrlXmlSchema.Document.LoadXml(ds.GetXmlSchema());
        XmlDocument CtrlDBSchema = CtrlXmlSchema.Document;
        this.setSchema(CtrlXmlSchema,workitem);
        
        //字典绑定
        Xml CtrlXmlDict = new Xml();
        DataSet CtrlDsDict = this.CtrlDataBindDict(workitem, ref CtrlXmlDict);
        
        string xmlstr3 = string.Format("<XML id=\"{0}Tab_dict\" typexml=\"Dict\" itemname=\"{1}\"></XML>",
            workitemdrc, workitem.ItemName);
        string xmlstr4 = string.Format("<XML id=\"{0}Tab\" typexml=\"Data\" itemname=\"{1}\"></XML>",
            workitemdrc, workitem.ItemName);
        //处理输出的字段格式
        XmlDocument XmlSchema = this.setFormatXmlLand(xmldoc, ds, CtrlXmlSchema, CtrlDsDict, CtrlXmlDict);

        string strXPath = "//xs:schema";
        string strschema = "<XML><xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">{0}</xs:schema></XML>";
        XmlDocument xmlLandSchema = new XmlDocument();
        xmlLandSchema.LoadXml(strschema);
        XmlNode _xmlschema = CtrlXmlSchema.Document.SelectSingleNode(strXPath, this._xmlNsMglSchema);
        string strdrc = (workitem.DataSrc).Replace(":", "_x003A_");
        _xmlschema.InnerXml = (_xmlschema.InnerXml).Replace(workitem.DataSrc,strdrc);
        int isep = 0;
        for (int i = 0; i < _xmlschema.Attributes.Count; i++)
        {
            if (_xmlschema.Attributes[i].Name.IndexOf("xmlns") > -1) continue;
            xmlLandSchema.DocumentElement.Attributes.Append(xmlLandSchema.CreateAttribute(_xmlschema.Attributes[i].Name));
            xmlLandSchema.DocumentElement.Attributes[isep].Value = _xmlschema.Attributes[i].Value;
            isep++;
        }


        strXPath = "//xs:element[@name='" + strdrc + "']//xs:sequence";
        _xmlschema = CtrlXmlSchema.Document.SelectSingleNode(strXPath, this._xmlNsMglSchema);
        string _ixml = _xmlschema.InnerXml.Replace("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"", "");
        _ixml = _ixml.Replace("minOccurs=\"0\"","");
        string xmlstr5 = string.Format(xmlLandSchema.InnerXml, _ixml);
        /*
        if (this.CtrlHiddenGrid)
        {
            this.GridDiv.Style["display"] = "none";
            return;
        }
        //读取Grid模板
        this._xmltpdoc.Load(this.Server.MapPath(this._tpGridFile));
        //设定标题列
        this.setTitle();
        //设定明细列
        this.setDetail();
        //设定脚注列
        this.setFoot();
         */
        return xmlstr1 + xmlstr2 + xmlstr3 + xmlstr4 + xmlstr5;
    }
Esempio n. 8
0
    /// <summary>
    /// 不需要提供数据环境的数据绑定
    /// </summary>
    public override void CtrlDataBind()
    {
        BasePage page = this.Page as BasePage;
        //if(!page.PgUserRight.HasRight(page.PgUnitName,OperationType.Selecte))
        //	return;
        this.ViewState["sendpage"] = "";
        this.hlbState.Value = "";
        NameObjectList paramlist = BuildParamList.BuildParams(page.PgParamXmlDoc);
        string[] strParams = this.getStrParams();
        int iPageSize = 0, iRecordCount = 0;
        //分页,汇总数据
        DataSet dsCount = new DataSet("汇总");
        dsCount.EnforceConstraints = false;
        if (null != this.CtrlWorkItem.CountDataSrc && string.Empty != this.CtrlWorkItem.CountDataSrc)
        {
            page.PgDictQuery.FillDataSet(this.CtrlWorkItem.CountDataSrc, paramlist, strParams, dsCount);
        }
        this.CtrlXmlCount.Document = new XmlDataDocument(dsCount);
        DataTable counttab = null;
        if (dsCount.Tables.Count > 0) counttab = dsCount.Tables[0];
        XmlDocument xmldocCount = this.CtrlXmlCount.Document;
        if (counttab != null)
        {
            if (null != this.CtrlWorkItem.PageSize && string.Empty != this.CtrlWorkItem.PageSize)
            {
                this.ViewState["PageSize" + CtrlWorkItem.DataSrc] = this.CtrlWorkItem.PageSize;
                iPageSize = Convert.ToInt32(this.CtrlWorkItem.PageSize);
                this.ViewState["RecordCount" + CtrlWorkItem.DataSrc] = counttab.Rows[0]["记录数量"].ToString();
                iRecordCount = Convert.ToInt32(counttab.Rows[0]["记录数量"]);

                //考虑iRecordCount<=iPageSize,时,并且:this.ViewState["PageIndex" + CtrlWorkItem.DataSrc])>1,要刷新页面

                if (iPageSize > 0)
                {
                    if (this.ViewState["PageIndex" + CtrlWorkItem.DataSrc] != null)
                    {
                        if (iRecordCount <= iPageSize && Convert.ToInt32(this.ViewState["PageIndex" + CtrlWorkItem.DataSrc].ToString()) > 1)
                        {
                            this.ViewState["TotalPages" + CtrlWorkItem.DataSrc] = 1;
                            this.ViewState["PageIndex" + CtrlWorkItem.DataSrc] = 1;
                        }
                        else
                            this.ViewState["TotalPages" + CtrlWorkItem.DataSrc] = (int)Math.Ceiling((double)iRecordCount / iPageSize);
                    }
                    else
                        this.ViewState["TotalPages" + CtrlWorkItem.DataSrc] = (int)Math.Ceiling((double)iRecordCount / iPageSize);
                }
            }
        }
        else
            xmldocCount.LoadXml("<DataSet><DataTableCount/></DataSet>");
        xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("id"));
        xmldocCount.DocumentElement.Attributes["id"].Value = this.CtrlXmlID + "_Sum";
        xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("typexml"));
        xmldocCount.DocumentElement.Attributes["typexml"].Value = "Count";
        xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("itemname"));
        xmldocCount.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;
        //当前页数据
        DataSet ds = new DataSet(this.CtrlXmlLand.ClientID);
        ds.EnforceConstraints = false;
        strParams = this.getStrParams();
        page.PgQuery.FillDataSet(this.CtrlWorkItem.DataSrc, paramlist, strParams, ds);
        this.CtrlDataSource = ds.Tables[this.CtrlWorkItem.DataSrc];
        //增加行光标列
        if (null != this.CtrlDataSource && !this.CtrlDataSource.Columns.Contains("RowNum"))
            this.CtrlDataSource.Columns.Add("RowNum", Type.GetType("System.Int32"));
        if (iPageSize < 1) iPageSize = 10;
        int iPageIndex = 1;
        if (null != this.ViewState["PageIndex" + CtrlWorkItem.DataSrc])
            iPageIndex = Convert.ToInt32(this.ViewState["PageIndex" + CtrlWorkItem.DataSrc]);
        for (int i = 0; null != this.CtrlDataSource && i < this.CtrlDataSource.Rows.Count; i++)
            this.CtrlDataSource.Rows[i]["RowNum"] = i + 1 + (iPageIndex - 1) * iPageSize;
        //如果是数字类型,值是0的,改为空的
        for (int i = 0; null != this.CtrlDataSource && i < this.CtrlDataSource.Columns.Count; i++)
        {
            DataColumn col = this.CtrlDataSource.Columns[i];
            if ("rownum" == col.ColumnName.ToLower()) 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 = this.CtrlDataSource.Select(col.ColumnName + "=0");
            for (int j = 0; j < drs.Length; j++)
                drs[j][i] = DBNull.Value;
        }
        //生成数据文档
        this.CtrlXmlLand.Document = new XmlDataDocument(ds);
        this.CtrlDBXmlDoc = this.CtrlXmlLand.Document;
        XmlDocument xmldoc = this.CtrlXmlLand.Document;
        if (xmldoc.DocumentElement == null)
            xmldoc.AppendChild(xmldoc.CreateElement(this.CtrlXmlLand.ClientID));
        if (null == xmldoc.DocumentElement.Attributes["id"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("id"));
        if (null == xmldoc.DocumentElement.Attributes["itemname"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("itemname"));
        if (null == xmldoc.DocumentElement.Attributes["typexml"])
            xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("typexml"));
        xmldoc.DocumentElement.Attributes["id"].Value = this.CtrlXmlID;
        xmldoc.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;
        xmldoc.DocumentElement.Attributes["typexml"].Value = "Data";
        if (iRecordCount < this.CtrlDataSource.Rows.Count)
            iRecordCount = this.CtrlDataSource.Rows.Count;
        //当前页码,行记录个数
        //在XmlCount数据岛增加TotalPage;PageIndex;PageSize,RecordCount数据
        XmlNode xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("TotalPage"));
        xmlNode.InnerText = (null == this.ViewState["TotalPages" + CtrlWorkItem.DataSrc]) ? "1" : this.ViewState["TotalPages" + CtrlWorkItem.DataSrc].ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageIndex"));
        xmlNode.InnerText = (null == this.ViewState["PageIndex" + CtrlWorkItem.DataSrc]) ? "1" : this.ViewState["PageIndex" + CtrlWorkItem.DataSrc].ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageSize"));
        xmlNode.InnerText = iPageSize.ToString();
        xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("RecordCount"));
        xmlNode.InnerText = iRecordCount.ToString();
        //删除区数据
        this.CtrlXmlDelete.Document = new XmlDocument();
        XmlDocument xmldocDel = this.CtrlXmlDelete.Document;
        xmldocDel.AppendChild(xmldocDel.CreateElement(xmldoc.DocumentElement.LocalName));
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("id"));
        xmldocDel.DocumentElement.Attributes["id"].Value = this.CtrlXmlID + "_Delete";
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("typexml"));
        xmldocDel.DocumentElement.Attributes["typexml"].Value = "Delete";
        xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("itemname"));
        xmldocDel.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;

        //数据岛结构信息
        this.CtrlXmlSchema.Document = new XmlDocument();
        this.CtrlXmlSchema.Document.LoadXml(ds.GetXmlSchema());
        this.CtrlDBSchema = this.CtrlXmlSchema.Document;
        this.setSchema();
        //字典绑定
        this.CtrlDataBindDict();
        //处理输出的字段格式
        this.setFormatXmlLand(xmldoc, ds);

        //读取控件模板,绑定树
        if(""!=this._tpGridFile)
            this._xmltpdoc.Load(this.Server.MapPath(this._tpGridFile));
        //
        for (int i = 0; i < this.CtrlXmlLand.Document.DocumentElement.ChildNodes.Count; i++)
            this.bindTree(this.CtrlXmlLand.Document.DocumentElement.ChildNodes[i]);
        this.trvLand.ExpandAll();
        return;
    }
Esempio n. 9
0
        /// <summary>
        /// Get XML Scheme of a table
        /// </summary>
        /// <param name="tablename"></param>
        /// <returns></returns>
        public string GetXMLSchema(string tablename)
        {
            using (SqlConnection conn = new SqlConnection(this.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(string.Format("SELECT TOP 1 * FROM {0};", tablename), conn);

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();

                // Get xml schema
                da.FillSchema(ds, SchemaType.Mapped, tablename);
                string xmlSchema = ds.GetXmlSchema();

                if ((xmlSchema != null) && (xmlSchema != ""))
                {
                    xmlSchema = xmlSchema.Replace("utf-16", "utf-8");
                }
                else
                {
                    xmlSchema = "";
                }

                return xmlSchema;
            }
        }
Esempio n. 10
0
 private void WriteDataset(DataSet ds)
 {
     _output.Append('{');
     if (useExtension)
     {
         WritePair("$schema", useMinimalDataSetSchema ? (object)GetSchema(ds) : ds.GetXmlSchema());
         _output.Append(',');
     }
     foreach (DataTable table in ds.Tables)
     {
         WriteDataTableData(table);
     }
     // end dataset
     _output.Append('}');
 }
Esempio n. 11
0
        private void WriteDataset(DataSet ds)
        {
            _output.Append('{');
            if (useExtension)
            {
                WritePair("$schema", useMinimalDataSetSchema ? (object)GetSchema(ds) : ds.GetXmlSchema());
                _output.Append(',');
            }
            foreach (DataTable table in ds.Tables)
            {
                _output.Append('\"');
                _output.Append(table.TableName);
                _output.Append("\":[");
                DataColumnCollection cols = table.Columns;
                foreach (DataRow row in table.Rows)
                {
                    _output.Append('[');

                    bool pendingSeperator = false;
                    foreach (DataColumn column in cols)
                    {
                        if (pendingSeperator) _output.Append(',');
                        WriteValue(row[column]);
                        pendingSeperator = true;
                    }
                    _output.Append(']');
                }

                _output.Append(']');
            }
            // end dataset
            _output.Append('}');
        }
 private static string GetDataSet(List<DataTable> dataTableList, string dataSetName)
 {
     DataSet ds = new DataSet(dataSetName);
     foreach (DataTable dataTable in dataTableList)
         ds.Merge(dataTable);
     return ds.GetXmlSchema();
 }
        /// <summary>
        /// 不需要提供数据环境的数据绑定
        /// </summary>
        public override void CtrlDataBind()
        {
            BasePage page = this.Page as BasePage;
            this.ViewState["sendpage"] = "";
            NameObjectList paramlist = BuildParamList.BuildParams(page.PgParamXmlDoc);
            string[] strParams = this.getStrParams();
            int iPageSize = 0, iRecordCount = 0;
            //分页,汇总数据
            DataSet dsCount = new DataSet("汇总");
            dsCount.EnforceConstraints = false;
            this.CtrlXmlCount.Document = new XmlDataDocument(dsCount);
            DataTable counttab = null;
            if (dsCount.Tables.Count > 0) counttab = dsCount.Tables[0];
            XmlDocument xmldocCount = this.CtrlXmlCount.Document;
            xmldocCount.LoadXml("<DataSet><DataTableCount/></DataSet>");
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("id"));
            xmldocCount.DocumentElement.Attributes["id"].Value = this.CtrlXmlID + "_Sum";
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("typexml"));
            xmldocCount.DocumentElement.Attributes["typexml"].Value = "Count";
            xmldocCount.DocumentElement.Attributes.Append(xmldocCount.CreateAttribute("itemname"));
            xmldocCount.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;
            //当前页数据
            DataSet ds = new DataSet(this.CtrlXmlLand.ClientID);
            ds.EnforceConstraints = false;
            strParams = this.getStrParams();
            page.PgQuery.FillDataSet(this.CtrlWorkItem.DataSrc, paramlist, strParams, ds);
            this.CtrlDataSource = ds.Tables[this.CtrlWorkItem.DataSrc];
            this.FillTabConfig(this.CtrlDataSource);
            if (this.CtrlDataSource == null) leofun.CreateLogFile("错误:" + this.CtrlWorkItem.DataSrc);
            //增加行光标列
            if(null!=this.CtrlDataSource && !this.CtrlDataSource.Columns.Contains("RowNum"))
                this.CtrlDataSource.Columns.Add("RowNum",Type.GetType("System.Int32"));
            if (iPageSize < 1) iPageSize = 10;
            int iPageIndex=1;
            if(null!=this.ViewState["PageIndex" + CtrlWorkItem.DataSrc])
                iPageIndex = Convert.ToInt32(this.ViewState["PageIndex" + CtrlWorkItem.DataSrc]);
            for (int i = 0; null != this.CtrlDataSource && i < this.CtrlDataSource.Rows.Count; i++)
                this.CtrlDataSource.Rows[i]["RowNum"] = i + 1+(iPageIndex-1)*iPageSize;
            //如果是数字类型,值是0的,改为空的
            for (int i = 0;null!=this.CtrlDataSource && i < this.CtrlDataSource.Columns.Count; i++)
            {
                DataColumn col = this.CtrlDataSource.Columns[i];
                if ("rownum" == col.ColumnName.ToLower()) 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 = this.CtrlDataSource.Select(col.ColumnName + "=0");
                for (int j = 0; j < drs.Length; j++)
                   drs[j][i] = DBNull.Value;
            }
            //生成数据文档
            this.CtrlXmlLand.Document = new XmlDataDocument(ds);
            this.CtrlDBXmlDoc = this.CtrlXmlLand.Document;
            XmlDocument xmldoc = this.CtrlXmlLand.Document;
            if (xmldoc.DocumentElement == null)
                xmldoc.AppendChild(xmldoc.CreateElement(this.CtrlXmlLand.ClientID));
            if (null == xmldoc.DocumentElement.Attributes["id"])
                xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("id"));
            if (null == xmldoc.DocumentElement.Attributes["itemname"])
                xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("itemname"));
            if (null == xmldoc.DocumentElement.Attributes["typexml"])
                xmldoc.DocumentElement.Attributes.Append(xmldoc.CreateAttribute("typexml"));
            xmldoc.DocumentElement.Attributes["id"].Value = this.CtrlXmlID;
            xmldoc.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;
            xmldoc.DocumentElement.Attributes["typexml"].Value = "Data";
            if (iRecordCount < this.CtrlDataSource.Rows.Count)
                iRecordCount = this.CtrlDataSource.Rows.Count;
            //当前页码,行记录个数
            //在XmlCount数据岛增加TotalPage;PageIndex;PageSize,RecordCount数据
            XmlNode xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("TotalPage"));
            xmlNode.InnerText = (null == this.ViewState["TotalPages" + CtrlWorkItem.DataSrc]) ? "1" : this.ViewState["TotalPages" + CtrlWorkItem.DataSrc].ToString();
            xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageIndex"));
            xmlNode.InnerText = (null == this.ViewState["PageIndex" + CtrlWorkItem.DataSrc]) ? "1" : this.ViewState["PageIndex" + CtrlWorkItem.DataSrc].ToString();
            xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("PageSize"));
            xmlNode.InnerText = iPageSize.ToString();
            xmlNode = xmldocCount.DocumentElement.FirstChild.AppendChild(xmldocCount.CreateElement("RecordCount"));
            xmlNode.InnerText = iRecordCount.ToString();
            //删除区数据
            this.CtrlXmlDelete.Document = new XmlDocument();
            XmlDocument xmldocDel = this.CtrlXmlDelete.Document;
            xmldocDel.AppendChild(xmldocDel.CreateElement(xmldoc.DocumentElement.LocalName));
            xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("id"));
            xmldocDel.DocumentElement.Attributes["id"].Value = this.CtrlXmlID + "_Delete";
            xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("typexml"));
            xmldocDel.DocumentElement.Attributes["typexml"].Value = "Delete";
            xmldocDel.DocumentElement.Attributes.Append(xmldocDel.CreateAttribute("itemname"));
            xmldocDel.DocumentElement.Attributes["itemname"].Value = this.CtrlItemName;

            //数据岛结构信息
            this.CtrlXmlSchema.Document = new XmlDocument();
            this.CtrlXmlSchema.Document.LoadXml(ds.GetXmlSchema());
            this.CtrlDBSchema = this.CtrlXmlSchema.Document;
            this.setSchema();
            //字典绑定
            this.CtrlDataBindDict();
            //处理输出的字段格式
            this.setFormatXmlLand(xmldoc, ds);

            if (this.CtrlHiddenGrid)
            {
                this.GridDiv.Style["display"] = "none";
                return;
            }
            //读取Grid模板
            this._xmltpdoc.Load(this.Server.MapPath(this._tpGridFile));
            //设定标题列
            this.setTitle();
            //设定明细列
            this.setDetail();
            //设定脚注列
            this.setFoot();
            return;
        }
Esempio n. 14
0
 private void WriteDataset(DataSet ds)
 {
     output.Append('{');
     if ( jsonParameters.UseExtensions)
     {
         WritePair("$schema", jsonParameters.UseOptimizedDatasetSchema ? (object)GetSchema(ds) : ds.GetXmlSchema());
         output.Append(',');
     }
     bool tablesep = false;
     foreach (DataTable table in ds.Tables)
     {
         if (tablesep) output.Append(",");
         tablesep = true;
         WriteDataTableData(table);
     }
     output.Append('}');
 }
Esempio n. 15
0
        public bool loadXMLRSS2_0(channel ch, string rss)
        {
            using (DataSet rssData = new DataSet())
            {
                System.IO.StringReader sr = new System.IO.StringReader(rss);
                DataSet ds2 = new DataSet();

                rssData.ReadXmlSchema("RSS-2_0-Schema.xsd");
                //rssData.InferXmlSchema(sr, null);
                rssData.EnforceConstraints = false;
                rssData.ReadXml(sr, XmlReadMode.Auto);
                string str = rssData.GetXmlSchema();
                if (rssData.Tables.Contains("channel"))
                {
                    foreach (DataRow dataRow in rssData.Tables["channel"].Rows)
                    {

                        //ch.title = dataRowContains("title", dataRow, rssData);//Convert.ToString(dataRow["title"]);

                        //rss_sub.set_title(ch.title);
                        ch.description = dataRowContains("description", dataRow, rssData);//Convert.ToString(dataRow["description"]);
                        ch.link = dataRowContains("link", dataRow, rssData);//Convert.ToString(dataRow["link"]);
                        ch.lastBuildDate = dataRowContains("lastBuildDate", dataRow, rssData);//Convert.ToString(dataRow["lastBuildDate"]);
                        ch.pubDate = dataRowContains("pubDate", dataRow, rssData);//Convert.ToString(dataRow["pubDate"]);
                        ch.ttl = dataRowContains("ttl", dataRow, rssData);//Convert.ToString(dataRow["ttl"]);

                        foreach (DataRow im in rssData.Tables["image"].Rows)
                        {
                            ch.imageUrl = im["url"].ToString();
                            ch.imageTitle = im["title"].ToString();
                        }

                        int counter = 0;
                        if (ch.pubDate.Length > 6)
                        {
                            ch.pubDate = ch.pubDate.Substring(0, ch.pubDate.Length - 6);
                        }
                        foreach (DataRow itemRow in rssData.Tables["item"].Rows)
                        {
                            Item inside = new Item();
                            inside.titleI = dataRowContains("title", itemRow, rssData);//Convert.ToString(itemRow["title"]);
                            string desc = dataRowContains("description", itemRow, rssData);// Convert.ToString(itemRow["description"]);
                            processDescription(desc, inside);
                            inside.linkI = dataRowContains("link", itemRow, rssData);//Convert.ToString(itemRow["link"]);
                            inside.guidI = dataRowContains("guid", itemRow, rssData);//Convert.ToString(itemRow["guid"]);
                            //inside.guidI = Convert.ToString(rssData.Tables["guid"].Rows[counter].ItemArray[1]);
                            inside.pubDateI = dataRowContains("pubDate", itemRow, rssData);//Convert.ToString(itemRow["pubDate"]);
                            if(inside.pubDateI.Length > 6)
                            {
                                inside.pubDateI = inside.pubDateI.Substring(0, inside.pubDateI.Length - 6);
                            }

                            inside.subscription = ch.title;
                            ch.item.Add(inside);
                            counter++;
                            if (counter > ch.maxItems) { break; }
                        }
                        /*channel rem = channels.Where(c => c.title == name).FirstOrDefault();
                        if (rem != null)
                        {
                            channels.Remove(rem);
                        }
                        if (findChannelName(ch.title) == null)
                        {

                            channels.Add(ch);
                        }
                        */
                    }
                }
                return true;
            }
        }
Esempio n. 16
0
		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);
		}
Esempio n. 17
0
		private void InitParentDataTableSchema(out XmlDocument schemaDocInit, out XmlNamespaceManager namespaceManagerToInit)
		{
			DataSet ds = new DataSet();
			ds.Tables.Add(DataProvider.CreateParentDataTable());
			string strXML = ds.GetXmlSchema();
			schemaDocInit = new XmlDocument();
			schemaDocInit.LoadXml(strXML);
			namespaceManagerToInit = new XmlNamespaceManager(schemaDocInit.NameTable);
			namespaceManagerToInit.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
			namespaceManagerToInit.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
		}
Esempio n. 18
0
		public void Bug420862 ()
		{
			DataSet ds = new DataSet ("d");
			DataTable dt = ds.Tables.Add ("t");
			dt.Columns.Add ("c", typeof (ushort));

			XmlSchema xs = XmlSchema.Read (new StringReader (ds.GetXmlSchema ()), null);
			xs.Compile (null);

			// follow the nesting of the schema in the foreach
			foreach (XmlSchemaElement d in xs.Items) {
				Assert.AreEqual ("d", d.Name);
				XmlSchemaChoice dsc = (XmlSchemaChoice) ((XmlSchemaComplexType) d.SchemaType).Particle;
				foreach (XmlSchemaElement t in dsc.Items) {
					Assert.AreEqual ("t", t.Name);
					XmlSchemaSequence tss = (XmlSchemaSequence) ((XmlSchemaComplexType) t.SchemaType).Particle;
					foreach (XmlSchemaElement c in tss.Items) {
						Assert.AreEqual ("c", c.Name);
						Assert.AreEqual ("unsignedShort", c.SchemaTypeName.Name);
						return;
					}
				}
			}
			Assert.Fail ();
		}
Esempio n. 19
0
 private void WriteDataset(DataSet ds)
 {
     _output.WriteByte(TOKENS.DOC_START);
     {
         WritePair("$schema", _params.UseOptimizedDatasetSchema ? (object)GetSchema(ds) : ds.GetXmlSchema());
         WriteComma();
     }
     bool tablesep = false;
     foreach (DataTable table in ds.Tables)
     {
         if (tablesep) WriteComma();
         tablesep = true;
         WriteDataTableData(table);
     }
     // end dataset
     _output.WriteByte(TOKENS.DOC_END);
 }
Esempio n. 20
0
        /// <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);
        }
Esempio n. 21
0
 private void WriteDataset(DataSet ds)
 {
     _output.Append('{');
     if (_params.UseExtensions)
     {
         WritePair("$schema", _params.UseOptimizedDatasetSchema ? (object)GetSchema(ds) : ds.GetXmlSchema());
         _output.Append(',');
     }
     bool tablesep = false;
     foreach (DataTable table in ds.Tables)
     {
         if (tablesep) _output.Append(',');
         tablesep = true;
         WriteDataTableData(table);
     }
     // end dataset
     _output.Append('}');
 }
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (IsPostBack)
			{
				try
				{
					DataSet ds = null;
					ExceptionHelper.TrueThrow(importFile.PostedFile.FileName.Trim() == string.Empty, "对不起,系统没有上传文件!");

					string strFileName, strFileExtension, strNewFileName;
					strFileName = Path.GetFileName(importFile.PostedFile.FileName);

					strFileExtension = System.IO.Path.GetExtension(strFileName);
					ExceptionHelper.TrueThrow(strFileExtension.ToUpper() != ".XLS", "对不起,您上传的文件格式不正确,请上传标准Excel文件!");

					string strTempPath = Path.GetTempPath();
					strNewFileName = Guid.NewGuid().ToString().Replace("-", "") + strFileExtension;
					try
					{
						importFile.PostedFile.SaveAs(strTempPath + strNewFileName);

						string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strTempPath + strNewFileName + ";Extended Properties=Excel 8.0;";
						OleDbConnection oConn = new OleDbConnection(strConn);
						try
						{
							oConn.Open();
							OleDbCommand oCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", oConn);
							OleDbDataAdapter oAdapter = new OleDbDataAdapter();
							oAdapter.SelectCommand = oCmdSelect;
							ds = new DataSet();
							oAdapter.Fill(ds, "XLData");
#if DEBUG
							Debug.WriteLine(ds.GetXmlSchema(), "");
							Debug.WriteLine(ds.GetXml(), "")  ;
#endif
						}
						finally
						{
							oConn.Close();
							oConn.Dispose();
						}
						using (TransactionScope scope = TransactionScopeFactory.Create())
						{
							DataCheckAndPutInDB(ds);
							scope.Complete();
						}
						middleTD.InnerHtml = "数据文件导入成功!";
					}
					finally
					{
						if (File.Exists(strTempPath + strNewFileName))
							File.Delete(strTempPath + strNewFileName);
					}
				}
				catch (Exception ex)
				{
					middleTD.InnerHtml = ex.Message;
				}
				finally
				{
					btnOK.Visible = false;
				}
			}
			else
			{
				CheckImportUserRole();
			}
		}