示例#1
0
        public AllXMLDataUDT GetUDTData(string UDTDataName)
        {
            AllXMLDataUDT udt = new AllXMLDataUDT();

            udt.Name      = UDTDataName;
            udt.RefUDT_ID = _GraUDT.UID;
            udt.StudentID = _GraUDT.StudentID;
            if (_XmlHelper != null)
            {
                udt.Content = _XmlHelper.BaseElement.OuterXml; //為何xml是null
            }
            return(udt);
        }
示例#2
0
        public List <AllXMLDataUDT> GenerateXml(string tableName, string fields, string forgeKey, string desc)
        {
            ParseTableName(tableName);
            ParseFieldName(fields);

            string forgeKeyName = "";

            foreach (FieldInfo field in Fields)
            {
                if (field.DBName == forgeKey)
                {
                    forgeKeyName = field.XmlName;
                    break;
                }
            }

            if (string.IsNullOrEmpty(forgeKeyName))
            {
                throw new ArgumentException(string.Format("{0} 不存在於Fields描述中。", forgeKey));
            }

            string sqlStr1 = "Select " + GetSelectFields() + " From " + DBTableName + " where " + UDT_S.PopOneCondition(forgeKey, StudentDics.Keys.ToList());

            DataTable dt = _queryhelper.Select(sqlStr1);

            //XmlHelper收集器
            Dictionary <string, List <DSXmlHelper> > HelperDic = new Dictionary <string, List <DSXmlHelper> >();

            foreach (DataRow row in dt.Rows)
            {
                string StudentID = "" + row[forgeKeyName];
                if (!HelperDic.ContainsKey(StudentID))
                {
                    HelperDic.Add(StudentID, new List <DSXmlHelper>());
                }

                //XmlTableName = RootElement ?
                DSXmlHelper h = new DSXmlHelper();
                h.AddElement(XmlTableName); //建立該筆資料的Element

                foreach (FieldInfo field in Fields)
                {
                    string RowValue = "" + row[field.XmlName];

                    //if (string.IsNullOrEmpty(RowValue))
                    //    continue;

                    if (field.IsAttribute)
                    {
                        h.SetAttribute(XmlTableName, field.XmlName, RowValue);
                    }
                    else
                    {
                        h.AddElement(XmlTableName, field.XmlName, RowValue, true);
                    }
                }

                HelperDic[StudentID].Add(h);
            }

            List <AllXMLDataUDT> aUDTList = new List <AllXMLDataUDT>();

            foreach (string each1 in HelperDic.Keys)
            {
                AllXMLDataUDT aUDT = new AllXMLDataUDT();
                aUDT.Name      = desc;
                aUDT.StudentID = each1;
                aUDT.RefUDT_ID = StudentDics[each1].UID;
                DSXmlHelper dh = new DSXmlHelper(XmlTableName + "List");
                foreach (DSXmlHelper each2 in HelperDic[each1])
                {
                    dh.AddXmlString(".", each2.BaseElement.InnerXml);
                }
                aUDT.Content = dh.BaseElement.OuterXml;

                aUDTList.Add(aUDT);
            }

            return(aUDTList);
        }